bard-legends-framework 0.10.7 → 0.10.9

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 (54) hide show
  1. package/dist/game-entities/base/attachable.d.ts +10 -3
  2. package/dist/game-entities/base/attachable.js +50 -18
  3. package/dist/game-entities/base/attachable.test.js +81 -95
  4. package/dist/game-entities/base/helpers/attachable.store.d.ts +2 -8
  5. package/dist/game-entities/base/helpers/attachable.store.js +46 -17
  6. package/dist/game-entities/base/helpers/attachable.store.test.d.ts +1 -0
  7. package/dist/game-entities/base/helpers/attachable.store.test.js +234 -0
  8. package/dist/game-entities/base/helpers/decorate-actions-lib.d.ts +3 -3
  9. package/dist/game-entities/base/helpers/decorate-actions-lib.js +5 -5
  10. package/dist/game-entities/base/helpers/referance-variable.d.ts +2 -2
  11. package/dist/game-entities/base/helpers/referance-variable.js +2 -2
  12. package/dist/game-entities/entity/entity.d.ts +3 -4
  13. package/dist/game-entities/entity/entity.js +7 -9
  14. package/dist/game-entities/entity/entity.test.js +25 -23
  15. package/dist/game-entities/index.d.ts +0 -2
  16. package/dist/game-entities/index.js +1 -18
  17. package/dist/game-entities/scene/scene.d.ts +2 -2
  18. package/dist/game-entities/scene/scene.js +2 -2
  19. package/dist/game-entities/scene/scene.test.js +10 -4
  20. package/dist/game-entities/view/view.d.ts +3 -3
  21. package/dist/game-entities/view/view.js +12 -9
  22. package/dist/game-entities/view/view.test.js +30 -12
  23. package/dist/physics/entity-types/physics-entity.d.ts +1 -1
  24. package/dist/physics/entity-types/physics-entity.js +7 -5
  25. package/dist/pixi/components/helpers/smooth-scroller.d.ts +1 -2
  26. package/dist/pixi/components/helpers/smooth-scroller.js +1 -3
  27. package/dist/pixi/components/helpers/smooth-scroller.test.js +5 -5
  28. package/dist/pixi/components/mouse-wheel-listener.ui.d.ts +1 -1
  29. package/dist/pixi/components/mouse-wheel-listener.ui.js +6 -4
  30. package/dist/pixi/components/scroll-area.ui.d.ts +0 -1
  31. package/dist/pixi/components/scroll-area.ui.js +1 -4
  32. package/dist/pixi/display-object/container-attributes.d.ts +2 -2
  33. package/dist/pixi/display-object/container-attributes.js +1 -1
  34. package/dist/pixi/display-object/container.d.ts +3 -4
  35. package/dist/pixi/display-object/container.js +6 -8
  36. package/dist/pixi/display-object/objects/graphics/graphics.d.ts +1 -1
  37. package/dist/pixi/display-object/objects/graphics/graphics.js +5 -3
  38. package/dist/pixi/display-object/objects/placeholder.d.ts +1 -1
  39. package/dist/pixi/display-object/objects/placeholder.js +5 -3
  40. package/dist/pixi/display-object/objects/sprite/sprite.d.ts +1 -1
  41. package/dist/pixi/display-object/objects/sprite/sprite.js +12 -10
  42. package/dist/pixi/display-object/objects/text/text.d.ts +1 -1
  43. package/dist/pixi/display-object/objects/text/text.js +5 -3
  44. package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.d.ts +1 -1
  45. package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.js +5 -3
  46. package/dist/utilities/libraries/animator/animator.d.ts +3 -5
  47. package/dist/utilities/libraries/animator/animator.js +17 -19
  48. package/dist/utilities/libraries/animator/state-animation/slide-state-animation.d.ts +2 -2
  49. package/dist/utilities/libraries/animator/state-animation/slide-state-animation.js +1 -1
  50. package/dist/utilities/libraries/animator/state-animation/state-animation.d.ts +2 -2
  51. package/dist/utilities/libraries/animator/state-animation/state-animation.js +1 -1
  52. package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.d.ts +2 -2
  53. package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.js +1 -1
  54. package/package.json +7 -5
@@ -1,11 +1,18 @@
1
1
  import { Action } from 'actions-lib';
2
- export declare abstract class Attachable {
2
+ export declare class Attachable {
3
+ readonly id: string;
3
4
  private attachedParent;
5
+ private attachments;
4
6
  private _attachIsCalled;
5
7
  private _destroyed;
6
8
  get destroyed(): boolean;
7
9
  readonly onDestroy: Action<void>;
8
10
  constructor();
9
- protected afterDestroy(): void;
10
- protected destroySelf(): void;
11
+ destroy(): void;
12
+ attach(parent: Attachable | string): this;
13
+ attachToRoot(): this;
14
+ private setAttachment;
15
+ private removeAttachment;
16
+ private checkCircularAttachment;
17
+ private destroyAttachment;
11
18
  }
@@ -2,12 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Attachable = void 0;
4
4
  const actions_lib_1 = require("actions-lib");
5
- const attachment_target_store_1 = require("./helpers/attachment-target.store");
5
+ const helpers_lib_1 = require("helpers-lib");
6
+ const attachable_store_1 = require("./helpers/attachable.store");
6
7
  class Attachable {
7
8
  get destroyed() {
8
9
  return this._destroyed;
9
10
  }
10
11
  constructor() {
12
+ this.id = attachable_store_1.AttachableStore.registerAttachmentTarget(this);
13
+ this.attachments = [];
11
14
  this._attachIsCalled = false;
12
15
  this._destroyed = false;
13
16
  this.onDestroy = new actions_lib_1.Action();
@@ -17,39 +20,32 @@ class Attachable {
17
20
  }
18
21
  });
19
22
  }
20
- /** @internal */
21
23
  destroy() {
22
24
  if (!this._destroyed) {
23
- // Destroy self is needed to ensure the "afterDestroy" is called after all child destroy functions are called
24
- this.destroySelf();
25
- this.afterDestroy();
25
+ this.attachedParent?.removeAttachment(this);
26
+ this.attachedParent = undefined;
27
+ attachable_store_1.AttachableStore.unregisterAttachmentTarget(this);
28
+ let onDestroyListeners = [...this.onDestroy['notificationHandler']['listenersMap'].values()];
29
+ let attachedEntities = [...this.attachments];
30
+ attachedEntities.forEach(item => this.destroyAttachment(item));
31
+ this.attachments = [];
26
32
  this._destroyed = true;
33
+ onDestroyListeners.forEach(listener => listener());
27
34
  }
28
35
  }
29
- afterDestroy() { }
30
- destroySelf() {
31
- this.onDestroy.trigger();
32
- this.attachedParent?.removeAttachment(this);
33
- this.attachedParent = undefined;
34
- }
35
- /** @internal */
36
36
  attach(parent) {
37
37
  if (this._attachIsCalled) {
38
38
  throw new Error(`Attachable: The object is already attached to something!`);
39
39
  }
40
40
  this._attachIsCalled = true;
41
41
  if (!this._destroyed) {
42
- let parentEntity = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(parent);
43
- // @ts-ignore
44
- if (parentEntity === this) {
45
- throw new Error(`Entity cannot be attach to itself! entity: "${this.constructor.name}"`);
46
- }
42
+ let parentEntity = attachable_store_1.AttachableStore.findAttachmentTarget(parent);
43
+ this.checkCircularAttachment(parentEntity);
47
44
  this.attachedParent = parentEntity;
48
45
  parentEntity.setAttachment(this);
49
46
  }
50
47
  return this;
51
48
  }
52
- /** @internal */
53
49
  attachToRoot() {
54
50
  if (this._attachIsCalled) {
55
51
  throw new Error(`Attachable: The object is already attached to something!`);
@@ -57,6 +53,42 @@ class Attachable {
57
53
  this._attachIsCalled = true;
58
54
  return this;
59
55
  }
56
+ setAttachment(child) {
57
+ if (this.destroyed) {
58
+ this.destroyAttachment(child);
59
+ }
60
+ else {
61
+ this.attachments.push(child);
62
+ }
63
+ }
64
+ removeAttachment(child) {
65
+ let index = this.attachments.indexOf(child);
66
+ if (index >= 0) {
67
+ this.attachments.splice(index, 1);
68
+ }
69
+ }
70
+ checkCircularAttachment(parentEntity) {
71
+ while (parentEntity) {
72
+ if (parentEntity === this) {
73
+ throw new Error(`Circular attachment detected!`);
74
+ }
75
+ parentEntity = parentEntity.attachedParent;
76
+ }
77
+ }
78
+ destroyAttachment(object) {
79
+ if (helpers_lib_1.Comparator.isObject(object)) {
80
+ let item = object;
81
+ if (helpers_lib_1.Comparator.isFunction(item.destroy)) {
82
+ item.destroy();
83
+ return;
84
+ }
85
+ else if (helpers_lib_1.Comparator.isFunction(item.unsubscribe)) {
86
+ item.unsubscribe();
87
+ return;
88
+ }
89
+ }
90
+ throw new Error(`AttachmentTarget: destroyAttachment is used with not supperted type! Target: "${object}"`);
91
+ }
60
92
  }
61
93
  exports.Attachable = Attachable;
62
94
  //# sourceMappingURL=attachable.js.map
@@ -15,12 +15,6 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
18
  var __importStar = (this && this.__importStar) || function (mod) {
25
19
  if (mod && mod.__esModule) return mod;
26
20
  var result = {};
@@ -28,112 +22,104 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
22
  __setModuleDefault(result, mod);
29
23
  return result;
30
24
  };
31
- var __metadata = (this && this.__metadata) || function (k, v) {
32
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
- };
34
25
  Object.defineProperty(exports, "__esModule", { value: true });
35
26
  const ActionsLib = __importStar(require("actions-lib"));
36
- const actions_lib_1 = require("actions-lib");
37
27
  const vitest_1 = require("vitest");
38
- const entity_1 = require("../entity/entity");
39
- const scene_1 = require("../scene/scene");
40
- const update_cycle_1 = require("../update-cycle");
28
+ const attachable_1 = require("./attachable");
29
+ const attachable_store_1 = require("./helpers/attachable.store");
41
30
  const decorate_actions_lib_1 = require("./helpers/decorate-actions-lib");
42
31
  decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
43
- (0, vitest_1.describe)('ATTACHABLE', () => {
32
+ (0, vitest_1.describe)('Attachable', () => {
44
33
  (0, vitest_1.beforeEach)(() => {
45
- update_cycle_1.UpdateCycle.hardResetAction.trigger();
46
- let SampleScene = class SampleScene extends scene_1.Scene {
47
- };
48
- SampleScene = __decorate([
49
- (0, scene_1.SceneDecorator)()
50
- ], SampleScene);
51
- SampleScene.open(undefined);
34
+ attachable_store_1.AttachableStore.hardReset();
52
35
  });
53
- (0, vitest_1.test)('dummy', () => {
54
- (0, vitest_1.expect)(true).toBeTruthy();
36
+ (0, vitest_1.test)('attach to self should throw error', () => {
37
+ class Sample extends attachable_1.Attachable {
38
+ }
39
+ let sample = new Sample();
40
+ (0, vitest_1.expect)(() => {
41
+ sample.attach(sample);
42
+ }).toThrow('Circular attachment detected!');
55
43
  });
56
- (0, vitest_1.test)('destroyable', async () => {
57
- let Sample = class Sample extends entity_1.Entity {
58
- };
59
- Sample = __decorate([
60
- (0, entity_1.EntityDecorator)()
61
- ], Sample);
62
- class Foo {
63
- constructor() {
64
- this.destroyed = false;
65
- }
66
- destroy() {
67
- this.destroyed = true;
68
- }
44
+ (0, vitest_1.test)('circular attachment should throw error', () => {
45
+ class Sample extends attachable_1.Attachable {
69
46
  }
70
- let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
71
- let foo = new Foo();
72
- sample['setAttachment'](foo);
73
- sample.destroy();
74
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
75
- (0, vitest_1.expect)(foo.destroyed).toBeTruthy();
47
+ let sample1 = new Sample();
48
+ let sample2 = new Sample();
49
+ (0, vitest_1.expect)(() => {
50
+ sample2.attach(sample1);
51
+ sample1.attach(sample2);
52
+ }).toThrow('Circular attachment detected!');
53
+ });
54
+ (0, vitest_1.test)('when attachment target is destroyed, it should destroy its attachments', () => {
55
+ class Target extends attachable_1.Attachable {
56
+ }
57
+ class Attachment extends attachable_1.Attachable {
58
+ }
59
+ let target = new Target();
60
+ let attachment = new Attachment().attach(target);
61
+ target.destroy();
62
+ (0, vitest_1.expect)(attachment.destroyed).toBeTruthy();
76
63
  });
77
- (0, vitest_1.test)('destroyable, delayed', async () => {
78
- let Sample = class Sample extends entity_1.Entity {
79
- };
80
- Sample = __decorate([
81
- (0, entity_1.EntityDecorator)()
82
- ], Sample);
83
- class Foo {
64
+ (0, vitest_1.test)('attached on constructor', () => {
65
+ let child;
66
+ class Target extends attachable_1.Attachable {
84
67
  constructor() {
85
- this.destroyed = false;
86
- }
87
- destroy() {
88
- this.destroyed = true;
68
+ super();
69
+ child = new Attachment().attach(this);
89
70
  }
90
71
  }
91
- let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
92
- let foo = new Foo();
93
- sample['setAttachment'](foo);
72
+ class Attachment extends attachable_1.Attachable {
73
+ }
74
+ let parent = new Target().attachToRoot();
75
+ parent.destroy();
76
+ (0, vitest_1.expect)(child?.destroyed).toBeTruthy();
77
+ });
78
+ (0, vitest_1.test)('onDestroy should be triggered when destroy is called', () => {
79
+ class Sample extends attachable_1.Attachable {
80
+ }
81
+ let parent = new Sample().attachToRoot();
82
+ let sample = new Sample().attachToRoot();
83
+ let destroyCalled = false;
84
+ sample.onDestroy
85
+ .subscribe(() => {
86
+ destroyCalled = true;
87
+ })
88
+ .attach(parent);
94
89
  sample.destroy();
95
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
96
- (0, vitest_1.expect)(foo.destroyed).toBeTruthy();
90
+ (0, vitest_1.expect)(destroyCalled).toBeTruthy();
97
91
  });
98
- (0, vitest_1.test)('subscription', async () => {
99
- let Sample = class Sample extends entity_1.Entity {
100
- };
101
- Sample = __decorate([
102
- (0, entity_1.EntityDecorator)()
103
- ], Sample);
104
- let foo = new actions_lib_1.Variable();
105
- let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
106
- (0, vitest_1.expect)(foo.listenerCount).toEqual(0);
107
- foo.subscribe(() => { }).attach(sample);
108
- (0, vitest_1.expect)(foo.listenerCount).toEqual(1);
92
+ (0, vitest_1.test)('onDestroy should be triggered when destroy listener is attached to itself', () => {
93
+ class Sample extends attachable_1.Attachable {
94
+ }
95
+ let sample = new Sample().attachToRoot();
96
+ let destroyCalled = false;
97
+ sample.onDestroy
98
+ .subscribe(() => {
99
+ destroyCalled = true;
100
+ })
101
+ .attach(sample);
109
102
  sample.destroy();
110
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
111
- (0, vitest_1.expect)(foo.listenerCount).toEqual(0);
103
+ (0, vitest_1.expect)(destroyCalled).toBeTruthy();
112
104
  });
113
- (0, vitest_1.test)('entity attachment in constructor', async () => {
114
- let childDestoyIsCalled = false;
115
- let Parent = class Parent extends entity_1.Entity {
116
- constructor() {
117
- super();
118
- new Child().attach(this);
119
- }
120
- };
121
- Parent = __decorate([
122
- (0, entity_1.EntityDecorator)(),
123
- __metadata("design:paramtypes", [])
124
- ], Parent);
125
- let Child = class Child extends entity_1.Entity {
126
- afterDestroy() {
127
- childDestoyIsCalled = true;
128
- }
129
- };
130
- Child = __decorate([
131
- (0, entity_1.EntityDecorator)()
132
- ], Child);
133
- let parent = new Parent().attach(scene_1.Scene.getActiveSceneOrFail());
134
- parent.destroy();
135
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
136
- (0, vitest_1.expect)(childDestoyIsCalled).toBeTruthy();
105
+ (0, vitest_1.test)('onDestroy calls should be executed attached first then parent', () => {
106
+ class Sample extends attachable_1.Attachable {
107
+ }
108
+ let sample1 = new Sample().attachToRoot();
109
+ let sample2 = new Sample().attach(sample1);
110
+ let heap = [];
111
+ sample1.onDestroy
112
+ .subscribe(() => {
113
+ heap.push('sample1');
114
+ })
115
+ .attach(sample1);
116
+ sample2.onDestroy
117
+ .subscribe(() => {
118
+ heap.push('sample2');
119
+ })
120
+ .attach(sample2);
121
+ sample1.destroy();
122
+ (0, vitest_1.expect)(heap).toEqual(['sample2', 'sample1']);
137
123
  });
138
124
  });
139
125
  //# sourceMappingURL=attachable.test.js.map
@@ -1,8 +1,2 @@
1
- import { IAttachmentTarget } from '../interfaces';
2
- export declare class AttachableStore {
3
- private static nextAvailableIds;
4
- private static attachables;
5
- static findAttachableParent(attachableCandidate: IAttachmentTarget | string): IAttachmentTarget;
6
- static registerAttachable(attachable: IAttachmentTarget): string;
7
- static unregisterAttachable(attachable: IAttachmentTarget): void;
8
- }
1
+ import { Attachable } from '../attachable';
2
+ export type AttachableConstructor = new (...args: any[]) => Attachable;
@@ -3,37 +3,66 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AttachableStore = void 0;
4
4
  const helpers_lib_1 = require("helpers-lib");
5
5
  const update_cycle_1 = require("../../update-cycle");
6
+ /** @internal */
6
7
  class AttachableStore {
7
- static { this.nextAvailableIds = new Map(); }
8
- static { this.attachables = new Map(); }
9
- static findAttachableParent(attachableCandidate) {
10
- let attachable;
8
+ static { this.nextClassId = 1; }
9
+ static { this.classToClassId = new WeakMap(); }
10
+ static { this.nextAvailableIds = new WeakMap(); }
11
+ static { this.idToAttachmentTarget = new Map(); }
12
+ static { this.idToAttachmentTargetClass = new Map(); }
13
+ static findAttachmentTarget(attachableCandidate) {
14
+ let attachmentTarget;
11
15
  if (helpers_lib_1.Comparator.isString(attachableCandidate)) {
12
16
  let attachableId = attachableCandidate;
13
- attachable = this.attachables.get(attachableId);
14
- if (!attachable) {
17
+ attachmentTarget = this.idToAttachmentTarget.get(attachableId);
18
+ if (!attachmentTarget) {
15
19
  throw new Error(`Attachable: attachable not found by id! id: ${attachableId}`);
16
20
  }
17
21
  }
18
22
  else {
19
- attachable = attachableCandidate;
23
+ attachmentTarget = attachableCandidate;
20
24
  }
21
- return attachable;
25
+ return attachmentTarget;
22
26
  }
23
- static registerAttachable(attachable) {
24
- let numberPartOfTheId = AttachableStore.nextAvailableIds.get(attachable.constructor.name) || 1;
25
- AttachableStore.nextAvailableIds.set(attachable.constructor.name, numberPartOfTheId + 1);
26
- let id = `${attachable.constructor.name}:${numberPartOfTheId}`;
27
- AttachableStore.attachables.set(id, attachable);
27
+ static registerAttachmentTarget(attachmentTarget) {
28
+ let Class = attachmentTarget.constructor;
29
+ let numberPartOfTheId = this.nextAvailableIds.get(Class) || 1;
30
+ this.nextAvailableIds.set(Class, numberPartOfTheId + 1);
31
+ let classId = this.getClassId(Class);
32
+ let id = `${classId}:${numberPartOfTheId}`;
33
+ this.idToAttachmentTarget.set(id, attachmentTarget);
34
+ this.idToAttachmentTargetClass.set(id, Class);
28
35
  return id;
29
36
  }
30
- static unregisterAttachable(attachable) {
31
- AttachableStore.attachables.delete(attachable.id);
37
+ static unregisterAttachmentTarget(attachmentTarget) {
38
+ this.idToAttachmentTarget.delete(attachmentTarget.id);
39
+ this.idToAttachmentTargetClass.delete(attachmentTarget.id);
40
+ }
41
+ static validateIdForClass(id, expectedConstructor) {
42
+ let actualConstructor = this.idToAttachmentTargetClass.get(id);
43
+ return actualConstructor === expectedConstructor;
44
+ }
45
+ /**
46
+ * Required to be called before or after each unit test to reset the store
47
+ */
48
+ static hardReset() {
49
+ this.nextClassId = 1;
50
+ this.classToClassId = new WeakMap();
51
+ this.nextAvailableIds = new WeakMap();
52
+ this.idToAttachmentTarget.clear();
53
+ this.idToAttachmentTargetClass.clear();
54
+ }
55
+ static getClassId(Class) {
56
+ let id = this.classToClassId.get(Class);
57
+ if (!id) {
58
+ id = `${this.nextClassId++}`;
59
+ this.classToClassId.set(Class, id);
60
+ }
61
+ return id;
32
62
  }
33
63
  }
34
64
  exports.AttachableStore = AttachableStore;
35
65
  update_cycle_1.UpdateCycle.hardResetAction.subscribe(() => {
36
- AttachableStore['nextAvailableIds'].clear();
37
- AttachableStore['attachables'].clear();
66
+ AttachableStore.hardReset();
38
67
  });
39
68
  //# sourceMappingURL=attachable.store.js.map