bard-legends-framework 0.10.4 → 0.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/game-entities/_base/attachable.d.ts +10 -0
  2. package/dist/game-entities/_base/attachable.js +47 -0
  3. package/dist/game-entities/_base/attachable.store.d.ts +8 -0
  4. package/dist/game-entities/_base/attachable.store.js +43 -0
  5. package/dist/game-entities/_base/attachment-target.d.ts +16 -0
  6. package/dist/game-entities/_base/attachment-target.js +53 -0
  7. package/dist/game-entities/_base/destroyable.d.ts +3 -0
  8. package/dist/game-entities/_base/destroyable.js +10 -0
  9. package/dist/game-entities/_base/interfaces.d.ts +3 -0
  10. package/dist/game-entities/_base/interfaces.js +3 -0
  11. package/dist/game-entities/_base/mixins.d.ts +22 -0
  12. package/dist/game-entities/_base/mixins.js +60 -0
  13. package/dist/game-entities/base/attachable.d.ts +8 -7
  14. package/dist/game-entities/base/attachable.js +47 -21
  15. package/dist/game-entities/base/attachment-target.d.ts +9 -0
  16. package/dist/game-entities/base/attachment-target.js +53 -0
  17. package/dist/game-entities/base/attachment-target.test.d.ts +1 -0
  18. package/dist/game-entities/base/attachment-target.test.js +131 -0
  19. package/dist/game-entities/base/destroyable.d.ts +2 -3
  20. package/dist/game-entities/base/destroyable.js +0 -21
  21. package/dist/game-entities/base/helpers/attachable.store.d.ts +4 -4
  22. package/dist/game-entities/base/helpers/attachment-target.store.d.ts +1 -0
  23. package/dist/game-entities/base/helpers/attachment-target.store.js +40 -0
  24. package/dist/game-entities/base/helpers/decorate-actions-lib.d.ts +3 -3
  25. package/dist/game-entities/base/helpers/decorate-actions-lib.js +3 -3
  26. package/dist/game-entities/base/helpers/referance-variable.d.ts +2 -2
  27. package/dist/game-entities/base/helpers/referance-variable.js +2 -2
  28. package/dist/game-entities/base/interfaces.d.ts +8 -8
  29. package/dist/game-entities/entity/entity.d.ts +4 -4
  30. package/dist/game-entities/entity/entity.js +9 -2
  31. package/dist/game-entities/entity/entity.test.js +14 -3
  32. package/dist/game-entities/entity/singleton-entity.d.ts +0 -9
  33. package/dist/game-entities/entity/singleton-entity.js +0 -55
  34. package/dist/game-entities/entity/singleton-entity.test.js +4 -1
  35. package/dist/game-entities/index.d.ts +1 -1
  36. package/dist/game-entities/index.js +3 -3
  37. package/dist/game-entities/scene/scene.d.ts +22 -15
  38. package/dist/game-entities/scene/scene.js +56 -40
  39. package/dist/game-entities/scene/scene.test.js +45 -37
  40. package/dist/game-entities/service/service.test.js +20 -5
  41. package/dist/game-entities/view/view.d.ts +2 -3
  42. package/dist/game-entities/view/view.js +4 -4
  43. package/dist/game-entities/view/view.test.js +5 -2
  44. package/dist/pixi/components/helpers/smooth-scroller.d.ts +2 -2
  45. package/dist/pixi/components/helpers/smooth-scroller.js +1 -1
  46. package/dist/pixi/display-object/container-attributes.d.ts +2 -2
  47. package/dist/pixi/display-object/container-attributes.js +1 -1
  48. package/dist/pixi/display-object/container.d.ts +1 -0
  49. package/dist/pixi/display-object/container.js +4 -0
  50. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/pixi-text-style-converter.d.ts +7 -3
  51. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/pixi-text-style-converter.js +6 -3
  52. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.d.ts +2 -3
  53. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.js +5 -4
  54. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.test.js +8 -32
  55. package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.test.js +1 -1
  56. package/dist/pixi/display-object/objects/text/text.d.ts +5 -2
  57. package/dist/pixi/display-object/objects/text/text.js +40 -6
  58. package/dist/pixi/game.d.ts +2 -1
  59. package/dist/pixi/game.js +2 -0
  60. package/dist/utilities/libraries/animator/animator.d.ts +3 -2
  61. package/dist/utilities/libraries/animator/animator.js +9 -2
  62. package/dist/utilities/libraries/animator/animator.test.js +12 -3
  63. package/dist/utilities/libraries/animator/state-animation/slide-state-animation.d.ts +2 -2
  64. package/dist/utilities/libraries/animator/state-animation/slide-state-animation.js +1 -1
  65. package/dist/utilities/libraries/animator/state-animation/state-animation.d.ts +2 -2
  66. package/dist/utilities/libraries/animator/state-animation/state-animation.js +1 -1
  67. package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.d.ts +2 -2
  68. package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.js +1 -1
  69. package/package.json +5 -12
@@ -33,7 +33,7 @@ const FONT_SIZE_MULTIPLIER_INVERSE = 1 / FONT_SIZE_MULTIPLIER;
33
33
  class Text extends container_1.Container {
34
34
  get textMetrics() {
35
35
  if (!this._textMetrics) {
36
- let pixiTextStyle = new PIXI.TextStyle(this.style);
36
+ let pixiTextStyle = new PIXI.TextStyle(this.pixiTextStyle);
37
37
  this._textMetrics = PIXI.TextMetrics.measureText(this.text, pixiTextStyle);
38
38
  }
39
39
  return this._textMetrics;
@@ -43,7 +43,8 @@ class Text extends container_1.Container {
43
43
  }
44
44
  constructor(text, partialOptions) {
45
45
  super();
46
- this.style = pixi_text_style_converter_1.PixiTextStyleConverter.getPixiTextStyle(partialOptions);
46
+ this.partialOptions = partialOptions;
47
+ this.pixiTextStyle = pixi_text_style_converter_1.TextStyleConverter.getPixiTextStyle(partialOptions);
47
48
  this.setText(text);
48
49
  }
49
50
  destroySelf() {
@@ -62,7 +63,7 @@ class Text extends container_1.Container {
62
63
  }
63
64
  setPosition(value, options) {
64
65
  if (options?.holdFrom) {
65
- let blurDistance = this.style.dropShadowDistance ?? 0;
66
+ let blurDistance = this.pixiTextStyle.dropShadowDistance ?? 0;
66
67
  let shadowOffset = new helpers_lib_1.Vector(options.holdFrom.x * blurDistance, options.holdFrom.y * blurDistance);
67
68
  value = value.add(shadowOffset);
68
69
  }
@@ -78,19 +79,52 @@ class Text extends container_1.Container {
78
79
  }
79
80
  setColor(color) {
80
81
  let colorHex = helpers_lib_1.ColorHelper.rgbToHex(color);
81
- if (this.style.fill !== colorHex) {
82
- this.style.fill = colorHex;
82
+ if (this.pixiTextStyle.fill !== colorHex) {
83
+ this.pixiTextStyle.fill = colorHex;
83
84
  this.regeneratePixiText();
84
85
  }
85
86
  return this;
86
87
  }
87
88
  regeneratePixiText() {
88
89
  this.pixiText?.destroy();
90
+ this.strikethroughGraphics?.destroy();
91
+ this.strikethroughGraphics = undefined;
89
92
  this._textMetrics = undefined;
90
- let pixiTextStyle = new PIXI.TextStyle(this.style);
93
+ let pixiTextStyle = new PIXI.TextStyle(this.pixiTextStyle);
91
94
  this.pixiText = new PIXI.Text(this.text, pixiTextStyle);
92
95
  this.pixiText.scale.set(FONT_SIZE_MULTIPLIER_INVERSE, FONT_SIZE_MULTIPLIER_INVERSE);
93
96
  this.pixiContainer.addChild(this.pixiText);
97
+ if (this.pixiTextStyle.lineThrough) {
98
+ this.strikethroughGraphics = this.addStrikethroughToText(this.pixiText, this.pixiTextStyle.fill);
99
+ this.pixiContainer.addChild(this.strikethroughGraphics);
100
+ }
101
+ }
102
+ addStrikethroughToText(pixiText, lineColor) {
103
+ let textMetrics = PIXI.TextMetrics.measureText(pixiText.text, pixiText.style);
104
+ let lineThickness = Math.max(1, Math.round(textMetrics.lineHeight * 0.07));
105
+ let lineOffset = (lineThickness % 2) * 0.5;
106
+ let strikethroughGraphics = new PIXI.Graphics();
107
+ strikethroughGraphics.lineStyle(lineThickness, lineColor);
108
+ let currentY = 0;
109
+ textMetrics.lines.forEach((line, index) => {
110
+ let lineMetrics = PIXI.TextMetrics.measureText(line, pixiText.style);
111
+ let lineY = Math.round(currentY +
112
+ (lineMetrics.fontProperties.ascent - lineMetrics.fontProperties.descent) * 0.6 +
113
+ lineMetrics.fontProperties.descent) + lineOffset;
114
+ let lineX = 0;
115
+ if (pixiText.style.align === 'center') {
116
+ lineX = 0 + (pixiText.width - lineMetrics.width) * 0.5;
117
+ }
118
+ else if (pixiText.style.align === 'right') {
119
+ lineX = 0 + pixiText.width - lineMetrics.width;
120
+ }
121
+ lineX = Math.floor(lineX);
122
+ strikethroughGraphics.moveTo(Math.floor(lineX), lineY);
123
+ strikethroughGraphics.lineTo(Math.floor(lineX + lineMetrics.width), lineY);
124
+ currentY += lineMetrics.lineHeight;
125
+ });
126
+ strikethroughGraphics.endFill();
127
+ return strikethroughGraphics;
94
128
  }
95
129
  }
96
130
  exports.Text = Text;
@@ -1,4 +1,4 @@
1
- import { Variable } from 'actions-lib';
1
+ import { Reducer, Variable } from 'actions-lib';
2
2
  import { RGBColor, Vector } from 'helpers-lib';
3
3
  import * as PIXI from 'pixi.js';
4
4
  import { AssetDefinition, Container } from '.';
@@ -15,6 +15,7 @@ export interface GameConfiguration {
15
15
  export declare class Game {
16
16
  private static _instance;
17
17
  static get instance(): Game;
18
+ static readonly pause: Reducer<boolean, boolean>;
18
19
  private static _camera;
19
20
  static get camera(): Camera;
20
21
  static get time(): number;
package/dist/pixi/game.js CHANGED
@@ -37,6 +37,7 @@ class Game {
37
37
  static get instance() {
38
38
  return this._instance;
39
39
  }
40
+ static { this.pause = actions_lib_1.Reducer.createOr(); }
40
41
  static get camera() {
41
42
  return this._camera;
42
43
  }
@@ -90,6 +91,7 @@ class Game {
90
91
  setTimeout(() => this.setScreenSize());
91
92
  });
92
93
  Game._camera = new camera_1.Camera();
94
+ // Reminder: If the game should be paused or destroyed, all promises has to be resolved, that relies on update cycle
93
95
  this.pixiApp.start();
94
96
  this.pixiApp.ticker.add(() => {
95
97
  update_cycle_1.UpdateCycle.triggerUpdateTick(this.pixiApp.ticker.deltaMS);
@@ -1,4 +1,4 @@
1
- import { Destroyable } from '../../../game-entities/base/destroyable';
1
+ import { Attachable } from '../../../game-entities/base/attachable';
2
2
  import { AnimatorAnimation } from './animations';
3
3
  export interface AnimationState {
4
4
  duration: number;
@@ -25,7 +25,7 @@ export interface AnimationOptions {
25
25
  reAnimateHandling?: ReAnimateHandlingType;
26
26
  completeAnimationsHandling?: CompleteAnimationsHandlingType;
27
27
  }
28
- export declare class Animator<T> extends Destroyable {
28
+ export declare class Animator<T> extends Attachable {
29
29
  private target;
30
30
  private static animatedObjects;
31
31
  private effectOn;
@@ -39,6 +39,7 @@ export declare class Animator<T> extends Destroyable {
39
39
  private running;
40
40
  private propertyStates;
41
41
  private updateCycleSubscription;
42
+ private allResolvers;
42
43
  get isAnimating(): boolean;
43
44
  constructor(target: T, effectOn: string | string[], options?: AnimationOptions);
44
45
  onChange(callback: (target: T) => void): Animator<T>;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Animator = exports.CompleteAnimationsHandlingType = exports.ReAnimateHandlingType = void 0;
4
4
  const helpers_lib_1 = require("helpers-lib");
5
- const destroyable_1 = require("../../../game-entities/base/destroyable");
5
+ const attachable_1 = require("../../../game-entities/base/attachable");
6
6
  const update_cycle_1 = require("../../../game-entities/update-cycle");
7
7
  const animations_1 = require("./animations");
8
8
  var ReAnimateHandlingType;
@@ -22,7 +22,7 @@ const DEFAULT_ANIMATION = new animations_1.AnimationLineer();
22
22
  const DEFAULT_LOOP = false;
23
23
  const DEFAULT_RE_ANIMATE_HANDLING = ReAnimateHandlingType.throwError;
24
24
  const DEFAULT_COMPLETE_ANIMATIONS_HANDLING = CompleteAnimationsHandlingType.stayInCurrentState;
25
- class Animator extends destroyable_1.Destroyable {
25
+ class Animator extends attachable_1.Attachable {
26
26
  static { this.animatedObjects = new Map(); }
27
27
  get isAnimating() {
28
28
  return this.propertyStates.size > 0;
@@ -33,6 +33,7 @@ class Animator extends destroyable_1.Destroyable {
33
33
  this.effectOn = new Set();
34
34
  this.running = true;
35
35
  this.propertyStates = new Map();
36
+ this.allResolvers = new Set();
36
37
  if (!helpers_lib_1.Comparator.isObject(target)) {
37
38
  this.attachToRoot();
38
39
  throw new Error(`Animator: target is not an object! Target: "${target}"`);
@@ -93,6 +94,9 @@ class Animator extends destroyable_1.Destroyable {
93
94
  if (animatedObjectProperties.size <= 0) {
94
95
  Animator.animatedObjects.delete(this.target);
95
96
  }
97
+ this.target = undefined;
98
+ this.allResolvers.forEach(resolver => resolver());
99
+ this.allResolvers.clear();
96
100
  }
97
101
  getAnimationStateOfKey(key) {
98
102
  let propertyState = this.propertyStates.get(key);
@@ -155,6 +159,7 @@ class Animator extends destroyable_1.Destroyable {
155
159
  });
156
160
  this.checkOngoingAnimations(values, options.reAnimateHandling);
157
161
  return new Promise(resolveAll => {
162
+ this.allResolvers.add(resolveAll);
158
163
  Promise.all(Object.keys(values).map(key => new Promise(resolve => {
159
164
  let duration = options.duration ?? this.defaultDuration;
160
165
  let animation = options.animation ?? this.defaultAnimation;
@@ -184,9 +189,11 @@ class Animator extends destroyable_1.Destroyable {
184
189
  }
185
190
  catch {
186
191
  resolveAll();
192
+ this.allResolvers.delete(resolveAll);
187
193
  }
188
194
  }))).then(() => {
189
195
  resolveAll();
196
+ this.allResolvers.delete(resolveAll);
190
197
  });
191
198
  this.subscribeUpdateCycle();
192
199
  });
@@ -330,16 +330,16 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
330
330
  });
331
331
  });
332
332
  (0, vitest_1.describe)('Animation Type Switch', () => {
333
- (0, vitest_1.test)('re-animation handling option throw error should throw error', () => {
333
+ (0, vitest_1.test)('re-animation handling option throw error should throw error', async () => {
334
334
  let obj = { x: 0 };
335
335
  let animator = new animator_1.Animator(obj, 'x', {
336
336
  duration: 4,
337
337
  reAnimateHandling: animator_1.ReAnimateHandlingType.throwError
338
338
  }).attachToRoot();
339
339
  animator.animate({ x: 1 });
340
- (0, vitest_1.expect)(async () => await animator.animate({ x: 0 })).rejects.toThrow();
340
+ await (0, vitest_1.expect)(animator.animate({ x: 0 })).rejects.toThrow();
341
341
  animator['update'](1);
342
- (0, vitest_1.expect)(async () => await animator.animate({ x: 0 })).rejects.toThrow();
342
+ await (0, vitest_1.expect)(animator.animate({ x: 0 })).rejects.toThrow();
343
343
  });
344
344
  (0, vitest_1.test)('re-animation handling option ignore should ignore new animation', () => {
345
345
  let obj = { x: 0 };
@@ -879,6 +879,15 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
879
879
  await game_entities_1.UpdateCycle.triggerUpdateTick(1);
880
880
  (0, vitest_1.expect)(obj.x).toEqual(0);
881
881
  });
882
+ (0, vitest_1.test)('destroyed animators animation promises should not get stuck', async () => {
883
+ return new Promise(done => {
884
+ let obj = { x: 0 };
885
+ let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: new animations_1.AnimationLineer() }).attachToRoot();
886
+ let promise = animator.animate({ x: 1 });
887
+ animator.destroy();
888
+ promise.then(() => done());
889
+ });
890
+ });
882
891
  });
883
892
  });
884
893
  //# sourceMappingURL=animator.test.js.map
@@ -1,10 +1,10 @@
1
- import { Attachable } from '../../../../game-entities';
1
+ import { AttachmentTarget } from '../../../../game-entities';
2
2
  import { StateAnimationOptions } from './state-animation';
3
3
  export declare enum SlideStateAnimationState {
4
4
  appear = "appear",
5
5
  disappear = "disappear"
6
6
  }
7
- export declare class SlideStateAnimation extends Attachable {
7
+ export declare class SlideStateAnimation extends AttachmentTarget {
8
8
  private stateAnimation;
9
9
  private options;
10
10
  private index;
@@ -11,7 +11,7 @@ var SlideStateAnimationState;
11
11
  SlideStateAnimationState["appear"] = "appear";
12
12
  SlideStateAnimationState["disappear"] = "disappear";
13
13
  })(SlideStateAnimationState || (exports.SlideStateAnimationState = SlideStateAnimationState = {}));
14
- class SlideStateAnimation extends game_entities_1.Attachable {
14
+ class SlideStateAnimation extends game_entities_1.AttachmentTarget {
15
15
  constructor(partialOptions) {
16
16
  super();
17
17
  this.animationState = 'idle';
@@ -1,11 +1,11 @@
1
- import { Attachable } from '../../../../game-entities';
1
+ import { AttachmentTarget } from '../../../../game-entities';
2
2
  import { AnimatorAnimation } from '../animations';
3
3
  export interface StateAnimationOptions {
4
4
  readonly duration: number;
5
5
  readonly animation: AnimatorAnimation;
6
6
  }
7
7
  type AnimationState = 'idle' | 'transitioning' | 'reverting';
8
- export declare class StateAnimation<T> extends Attachable {
8
+ export declare class StateAnimation<T> extends AttachmentTarget {
9
9
  private animator;
10
10
  private options;
11
11
  private value;
@@ -5,7 +5,7 @@ const actions_lib_1 = require("actions-lib");
5
5
  const game_entities_1 = require("../../../../game-entities");
6
6
  const animations_1 = require("../animations");
7
7
  const animator_1 = require("../animator");
8
- class StateAnimation extends game_entities_1.Attachable {
8
+ class StateAnimation extends game_entities_1.AttachmentTarget {
9
9
  get currentState() {
10
10
  return {
11
11
  value: this.value,
@@ -1,7 +1,7 @@
1
- import { Attachable } from '../../../../game-entities';
1
+ import { AttachmentTarget } from '../../../../game-entities';
2
2
  import { StateAnimationOptions } from './state-animation';
3
3
  type AnimationState = 'hidden' | 'visible' | 'appearing' | 'disappearing' | 'disappearToChange';
4
- export declare class VisitDisappearStateAnimation<T> extends Attachable {
4
+ export declare class VisitDisappearStateAnimation<T> extends AttachmentTarget {
5
5
  private animator;
6
6
  private options;
7
7
  private value;
@@ -5,7 +5,7 @@ const actions_lib_1 = require("actions-lib");
5
5
  const game_entities_1 = require("../../../../game-entities");
6
6
  const animations_1 = require("../animations");
7
7
  const animator_1 = require("../animator");
8
- class VisitDisappearStateAnimation extends game_entities_1.Attachable {
8
+ class VisitDisappearStateAnimation extends game_entities_1.AttachmentTarget {
9
9
  get currentState() {
10
10
  return {
11
11
  value: this.value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bard-legends-framework",
3
- "version": "0.10.4",
3
+ "version": "0.10.6",
4
4
  "description": "Bard Legends Framework",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -20,19 +20,12 @@
20
20
  "bugs": {
21
21
  "url": "https://github.com/sefabaser/Bard-Legends-Framework/issues"
22
22
  },
23
- "prettier": {
24
- "printWidth": 130,
25
- "tabWidth": 2,
26
- "semicolons": true,
27
- "singleQuote": true,
28
- "trailingComma": "none",
29
- "arrowParens": "avoid"
30
- },
31
23
  "homepage": "https://github.com/sefabaser/Bard-Legends-Framework#readme",
32
24
  "scripts": {
33
- "clean-install": "cls && rm -rf node_modules && rm -rf package-lock.json && npm cache clean --force && npm install",
25
+ "clean-install": "cls && rm -rf node_modules && rm -rf package-lock.json && npm run i",
26
+ "i": "npm cache clean --force && npm install",
34
27
  "pretest": "cls",
35
- "test": "vitest",
28
+ "test": "vitest run",
36
29
  "build": "tsc",
37
30
  "lint": "biome check . --write --max-diagnostics=1",
38
31
  "deploy": "vitest run && npm run build && npm publish",
@@ -54,7 +47,7 @@
54
47
  "rollup-plugin-swc": "0.2.1",
55
48
  "tslib": "2.6.2",
56
49
  "typescript": "5.3.3",
57
- "vitest": "1.6.0"
50
+ "vitest": "3.2.4"
58
51
  },
59
52
  "types": "dist/index.d.ts"
60
53
  }