bard-legends-framework 0.10.8 → 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 +5 -5
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const attachable_1 = require("../attachable");
5
+ const attachable_store_1 = require("./attachable.store");
6
+ (0, vitest_1.describe)('AttachableStore', () => {
7
+ (0, vitest_1.beforeEach)(() => {
8
+ attachable_store_1.AttachableStore.hardReset();
9
+ });
10
+ (0, vitest_1.describe)('registerAttachmentTarget', () => {
11
+ (0, vitest_1.test)('generates unique id for single instance', () => {
12
+ class TestClass extends attachable_1.Attachable {
13
+ }
14
+ let instance = new TestClass().attachToRoot();
15
+ let id = instance.id;
16
+ (0, vitest_1.expect)(id).toBe('1:1');
17
+ });
18
+ (0, vitest_1.test)('generates sequential ids for multiple instances of same class', () => {
19
+ class TestClass extends attachable_1.Attachable {
20
+ }
21
+ let instance1 = new TestClass().attachToRoot();
22
+ let instance2 = new TestClass().attachToRoot();
23
+ let instance3 = new TestClass().attachToRoot();
24
+ (0, vitest_1.expect)([instance1.id, instance2.id, instance3.id]).toEqual(['1:1', '1:2', '1:3']);
25
+ });
26
+ (0, vitest_1.test)('generates different class ids for different classes', () => {
27
+ class TestClass1 extends attachable_1.Attachable {
28
+ }
29
+ class TestClass2 extends attachable_1.Attachable {
30
+ }
31
+ let instance1 = new TestClass1().attachToRoot();
32
+ let instance2 = new TestClass2().attachToRoot();
33
+ (0, vitest_1.expect)(instance1.id).toBe('1:1');
34
+ (0, vitest_1.expect)(instance2.id).toBe('2:1');
35
+ });
36
+ (0, vitest_1.test)('maintains separate numbering for different classes', () => {
37
+ class TestClass1 extends attachable_1.Attachable {
38
+ }
39
+ class TestClass2 extends attachable_1.Attachable {
40
+ }
41
+ let instance1a = new TestClass1().attachToRoot();
42
+ let instance2a = new TestClass2().attachToRoot();
43
+ let instance1b = new TestClass1().attachToRoot();
44
+ let instance2b = new TestClass2().attachToRoot();
45
+ (0, vitest_1.expect)([instance1a.id, instance2a.id, instance1b.id, instance2b.id]).toEqual(['1:1', '2:1', '1:2', '2:2']);
46
+ });
47
+ });
48
+ (0, vitest_1.describe)('findAttachmentTarget', () => {
49
+ (0, vitest_1.test)('finds registered attachable by string id', () => {
50
+ class TestClass extends attachable_1.Attachable {
51
+ }
52
+ let instance = new TestClass().attachToRoot();
53
+ let found = attachable_store_1.AttachableStore.findAttachmentTarget(instance.id);
54
+ (0, vitest_1.expect)(found).toBe(instance);
55
+ });
56
+ (0, vitest_1.test)('returns same object when passed an Attachable instance', () => {
57
+ class TestClass extends attachable_1.Attachable {
58
+ }
59
+ let instance = new TestClass().attachToRoot();
60
+ let found = attachable_store_1.AttachableStore.findAttachmentTarget(instance);
61
+ (0, vitest_1.expect)(found).toBe(instance);
62
+ });
63
+ (0, vitest_1.test)('throws error for non-existent id', () => {
64
+ (0, vitest_1.expect)(() => {
65
+ attachable_store_1.AttachableStore.findAttachmentTarget('999:999');
66
+ }).toThrow('Attachable: attachable not found by id! id: 999:999');
67
+ });
68
+ (0, vitest_1.test)('throws error for empty string id', () => {
69
+ (0, vitest_1.expect)(() => {
70
+ attachable_store_1.AttachableStore.findAttachmentTarget('');
71
+ }).toThrow('Attachable: attachable not found by id! id: ');
72
+ });
73
+ });
74
+ (0, vitest_1.describe)('unregisterAttachmentTarget', () => {
75
+ (0, vitest_1.test)('removes attachable from store', () => {
76
+ class TestClass extends attachable_1.Attachable {
77
+ }
78
+ let instance = new TestClass().attachToRoot();
79
+ let id = instance.id;
80
+ attachable_store_1.AttachableStore.unregisterAttachmentTarget(instance);
81
+ (0, vitest_1.expect)(() => {
82
+ attachable_store_1.AttachableStore.findAttachmentTarget(id);
83
+ }).toThrow(`Attachable: attachable not found by id! id: ${id}`);
84
+ });
85
+ (0, vitest_1.test)('allows reusing id after unregister and hardReset', () => {
86
+ class TestClass extends attachable_1.Attachable {
87
+ }
88
+ let instance1 = new TestClass().attachToRoot();
89
+ let firstId = instance1.id;
90
+ attachable_store_1.AttachableStore.unregisterAttachmentTarget(instance1);
91
+ attachable_store_1.AttachableStore.hardReset();
92
+ let instance2 = new TestClass().attachToRoot();
93
+ let secondId = instance2.id;
94
+ (0, vitest_1.expect)(secondId).toBe(firstId);
95
+ });
96
+ });
97
+ (0, vitest_1.describe)('validateIdForClass', () => {
98
+ (0, vitest_1.test)('returns true for matching class', () => {
99
+ class TestClass extends attachable_1.Attachable {
100
+ }
101
+ let instance = new TestClass().attachToRoot();
102
+ let isValid = attachable_store_1.AttachableStore.validateIdForClass(instance.id, TestClass);
103
+ (0, vitest_1.expect)(isValid).toBe(true);
104
+ });
105
+ (0, vitest_1.test)('returns false for non-matching class', () => {
106
+ class TestClass1 extends attachable_1.Attachable {
107
+ }
108
+ class TestClass2 extends attachable_1.Attachable {
109
+ }
110
+ let instance = new TestClass1().attachToRoot();
111
+ let isValid = attachable_store_1.AttachableStore.validateIdForClass(instance.id, TestClass2);
112
+ (0, vitest_1.expect)(isValid).toBe(false);
113
+ });
114
+ (0, vitest_1.test)('returns false for non-existent id', () => {
115
+ class TestClass extends attachable_1.Attachable {
116
+ }
117
+ let isValid = attachable_store_1.AttachableStore.validateIdForClass('999:999', TestClass);
118
+ (0, vitest_1.expect)(isValid).toBe(false);
119
+ });
120
+ (0, vitest_1.test)('validates correctly for derived classes', () => {
121
+ class BaseClass extends attachable_1.Attachable {
122
+ }
123
+ class DerivedClass extends BaseClass {
124
+ }
125
+ let instance = new DerivedClass().attachToRoot();
126
+ let isValidForDerived = attachable_store_1.AttachableStore.validateIdForClass(instance.id, DerivedClass);
127
+ let isValidForBase = attachable_store_1.AttachableStore.validateIdForClass(instance.id, BaseClass);
128
+ (0, vitest_1.expect)(isValidForDerived).toBe(true);
129
+ (0, vitest_1.expect)(isValidForBase).toBe(false);
130
+ });
131
+ });
132
+ (0, vitest_1.describe)('hardReset', () => {
133
+ (0, vitest_1.test)('resets class id counter', () => {
134
+ class TestClass1 extends attachable_1.Attachable {
135
+ }
136
+ class TestClass2 extends attachable_1.Attachable {
137
+ }
138
+ new TestClass1().attachToRoot();
139
+ new TestClass2().attachToRoot();
140
+ attachable_store_1.AttachableStore.hardReset();
141
+ class TestClass3 extends attachable_1.Attachable {
142
+ }
143
+ let instance = new TestClass3().attachToRoot();
144
+ (0, vitest_1.expect)(instance.id).toBe('1:1');
145
+ });
146
+ (0, vitest_1.test)('resets instance id counters', () => {
147
+ class TestClass extends attachable_1.Attachable {
148
+ }
149
+ new TestClass().attachToRoot();
150
+ new TestClass().attachToRoot();
151
+ attachable_store_1.AttachableStore.hardReset();
152
+ let instance = new TestClass().attachToRoot();
153
+ (0, vitest_1.expect)(instance.id).toBe('1:1');
154
+ });
155
+ (0, vitest_1.test)('clears all registered attachables', () => {
156
+ class TestClass extends attachable_1.Attachable {
157
+ }
158
+ let instance = new TestClass().attachToRoot();
159
+ let id = instance.id;
160
+ attachable_store_1.AttachableStore.hardReset();
161
+ (0, vitest_1.expect)(() => {
162
+ attachable_store_1.AttachableStore.findAttachmentTarget(id);
163
+ }).toThrow(`Attachable: attachable not found by id! id: ${id}`);
164
+ });
165
+ (0, vitest_1.test)('clears class validation data', () => {
166
+ class TestClass extends attachable_1.Attachable {
167
+ }
168
+ let instance = new TestClass().attachToRoot();
169
+ let id = instance.id;
170
+ attachable_store_1.AttachableStore.hardReset();
171
+ let isValid = attachable_store_1.AttachableStore.validateIdForClass(id, TestClass);
172
+ (0, vitest_1.expect)(isValid).toBe(false);
173
+ });
174
+ });
175
+ (0, vitest_1.describe)('multiple classes interaction', () => {
176
+ (0, vitest_1.test)('handles multiple classes with multiple instances each', () => {
177
+ class ClassA extends attachable_1.Attachable {
178
+ }
179
+ class ClassB extends attachable_1.Attachable {
180
+ }
181
+ class ClassC extends attachable_1.Attachable {
182
+ }
183
+ let a1 = new ClassA().attachToRoot();
184
+ let a2 = new ClassA().attachToRoot();
185
+ let b1 = new ClassB().attachToRoot();
186
+ let c1 = new ClassC().attachToRoot();
187
+ let c2 = new ClassC().attachToRoot();
188
+ let c3 = new ClassC().attachToRoot();
189
+ (0, vitest_1.expect)([a1.id, a2.id, b1.id, c1.id, c2.id, c3.id]).toEqual(['1:1', '1:2', '2:1', '3:1', '3:2', '3:3']);
190
+ });
191
+ (0, vitest_1.test)('finds correct instances after complex registration', () => {
192
+ class ClassA extends attachable_1.Attachable {
193
+ }
194
+ class ClassB extends attachable_1.Attachable {
195
+ }
196
+ let a1 = new ClassA().attachToRoot();
197
+ let b1 = new ClassB().attachToRoot();
198
+ let a2 = new ClassA().attachToRoot();
199
+ let foundA1 = attachable_store_1.AttachableStore.findAttachmentTarget(a1.id);
200
+ let foundB1 = attachable_store_1.AttachableStore.findAttachmentTarget(b1.id);
201
+ let foundA2 = attachable_store_1.AttachableStore.findAttachmentTarget(a2.id);
202
+ (0, vitest_1.expect)(foundA1).toBe(a1);
203
+ (0, vitest_1.expect)(foundB1).toBe(b1);
204
+ (0, vitest_1.expect)(foundA2).toBe(a2);
205
+ });
206
+ });
207
+ (0, vitest_1.describe)('edge cases', () => {
208
+ (0, vitest_1.test)('handles rapid registration and unregistration', () => {
209
+ class TestClass extends attachable_1.Attachable {
210
+ }
211
+ let instance1 = new TestClass().attachToRoot();
212
+ let id1 = instance1.id;
213
+ attachable_store_1.AttachableStore.unregisterAttachmentTarget(instance1);
214
+ let instance2 = new TestClass().attachToRoot();
215
+ let id2 = instance2.id;
216
+ (0, vitest_1.expect)(id2).toBe('1:2');
217
+ (0, vitest_1.expect)(() => {
218
+ attachable_store_1.AttachableStore.findAttachmentTarget(id1);
219
+ }).toThrow();
220
+ });
221
+ (0, vitest_1.test)('validates after partial unregistration', () => {
222
+ class TestClass extends attachable_1.Attachable {
223
+ }
224
+ let instance1 = new TestClass().attachToRoot();
225
+ let instance2 = new TestClass().attachToRoot();
226
+ attachable_store_1.AttachableStore.unregisterAttachmentTarget(instance1);
227
+ let isValid1 = attachable_store_1.AttachableStore.validateIdForClass(instance1.id, TestClass);
228
+ let isValid2 = attachable_store_1.AttachableStore.validateIdForClass(instance2.id, TestClass);
229
+ (0, vitest_1.expect)(isValid1).toBe(false);
230
+ (0, vitest_1.expect)(isValid2).toBe(true);
231
+ });
232
+ });
233
+ });
234
+ //# sourceMappingURL=attachable.store.test.js.map
@@ -1,12 +1,12 @@
1
- import { AttachmentTarget } from '../attachment-target';
1
+ import { Attachable } from '../attachable';
2
2
  declare module 'actions-lib' {
3
3
  interface ActionSubscription {
4
- attach(parent: AttachmentTarget | string): ActionSubscription;
4
+ attach(parent: Attachable | string): ActionSubscription;
5
5
  attachToRoot(): ActionSubscription;
6
6
  decorateActionSubscription(): ActionSubscription;
7
7
  }
8
8
  interface ReducerEffectChannel<EffectType, ResponseType> {
9
- attach(parent: AttachmentTarget | string): ReducerEffectChannel<EffectType, ResponseType>;
9
+ attach(parent: Attachable | string): ReducerEffectChannel<EffectType, ResponseType>;
10
10
  attachToRoot(): ReducerEffectChannel<EffectType, ResponseType>;
11
11
  decorateEffectChannel(): ReducerEffectChannel<EffectType, ResponseType>;
12
12
  }
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ActionsLibDecorator = void 0;
27
27
  const ActionsLib = __importStar(require("actions-lib"));
28
- const attachment_target_store_1 = require("./attachment-target.store");
28
+ const attachable_store_1 = require("./attachable.store");
29
29
  class ActionsLibDecorator {
30
30
  static decorate(actionsLib) {
31
31
  this.decorateAttachFunctions(actionsLib);
@@ -38,7 +38,7 @@ class ActionsLibDecorator {
38
38
  }
39
39
  static decorateAttachFunctions(actionsLib) {
40
40
  actionsLib.ActionSubscription.prototype.attach = function (parent) {
41
- let parentEntity = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(parent);
41
+ let parentEntity = attachable_store_1.AttachableStore.findAttachmentTarget(parent);
42
42
  parentEntity['setAttachment'](this);
43
43
  this.$meta = { attachIsCalled: true, attachedParent: parentEntity };
44
44
  return this;
@@ -61,7 +61,7 @@ class ActionsLibDecorator {
61
61
  return originalCombine(subscriptions);
62
62
  };
63
63
  actionsLib.ReducerEffectChannel.prototype.attach = function (parent) {
64
- let parentEntity = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(parent);
64
+ let parentEntity = attachable_store_1.AttachableStore.findAttachmentTarget(parent);
65
65
  parentEntity['setAttachment'](this);
66
66
  this.$meta = { attachIsCalled: true, attachedParent: parentEntity };
67
67
  return this;
@@ -84,7 +84,7 @@ class ActionsLibDecorator {
84
84
  actionsLib.ActionSubscription.prototype.unsubscribe = function () {
85
85
  let parentEntity = this.$meta?.attachedParent;
86
86
  if (parentEntity) {
87
- parentEntity['removeAttachment'](this);
87
+ parentEntity.removeAttachment(this);
88
88
  this.$meta.attachedParent = undefined;
89
89
  }
90
90
  originalUnsubscribe.call(this);
@@ -93,7 +93,7 @@ class ActionsLibDecorator {
93
93
  actionsLib.ReducerEffectChannel.prototype.unsubscribe = function () {
94
94
  let parentEntity = this.$meta?.attachedParent;
95
95
  if (parentEntity) {
96
- parentEntity['removeAttachment'](this);
96
+ parentEntity.removeAttachment(this);
97
97
  this.$meta.attachedParent = undefined;
98
98
  }
99
99
  originalEffectUnsubscribe.call(this);
@@ -1,5 +1,5 @@
1
1
  import { ActionListenerCallbackFunction, ActionSubscription, IVariable } from 'actions-lib';
2
- import { AttachmentTarget } from '../attachment-target';
2
+ import { Attachable } from '../attachable';
3
3
  export declare class ReferanceVariable implements IVariable<string | undefined> {
4
4
  private options;
5
5
  private variable;
@@ -8,7 +8,7 @@ export declare class ReferanceVariable implements IVariable<string | undefined>
8
8
  set value(value: string | undefined);
9
9
  get listenerCount(): number;
10
10
  constructor(options: {
11
- attachTo: AttachmentTarget;
11
+ attachTo: Attachable;
12
12
  });
13
13
  set(data: string | undefined): this;
14
14
  subscribe(callback: ActionListenerCallbackFunction<string | undefined>): ActionSubscription;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReferanceVariable = void 0;
4
4
  const actions_lib_1 = require("actions-lib");
5
- const attachment_target_store_1 = require("./attachment-target.store");
5
+ const attachable_store_1 = require("./attachable.store");
6
6
  class ReferanceVariable {
7
7
  get value() {
8
8
  return this.variable.value;
@@ -22,7 +22,7 @@ class ReferanceVariable {
22
22
  this.destroySubscription?.unsubscribe();
23
23
  this.destroySubscription = undefined;
24
24
  if (data) {
25
- this.destroySubscription = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(data)
25
+ this.destroySubscription = attachable_store_1.AttachableStore.findAttachmentTarget(data)
26
26
  .onDestroy.subscribe(() => {
27
27
  this.set(undefined);
28
28
  })
@@ -1,14 +1,13 @@
1
- import { AttachmentTarget } from '../base/attachment-target';
1
+ import { Attachable } from '../base/attachable';
2
2
  export type EntityClassType = new (...args: any[]) => Entity;
3
3
  export declare function EntityDecorator(): (EntityClass: EntityClassType) => any;
4
- export declare abstract class Entity extends AttachmentTarget {
4
+ export declare abstract class Entity extends Attachable {
5
5
  static getInstanceById<T extends Entity>(this: new (...args: any[]) => T, entityId: string | undefined): T | undefined;
6
6
  static getInstanceByIdOrFail<T extends Entity>(this: new (...args: any[]) => T, entityId: string): T;
7
7
  static getEntities<T extends Entity>(this: new (...args: any[]) => T): T[];
8
8
  private viewCreationHelper;
9
9
  constructor();
10
10
  destroy(): void;
11
- protected destroySelf(): void;
12
- attach(parent: AttachmentTarget | string): this;
11
+ attach(parent: Attachable | string): this;
13
12
  attachToRoot(): this;
14
13
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Entity = exports.EntityDecorator = void 0;
4
- const attachment_target_1 = require("../base/attachment-target");
4
+ const attachable_1 = require("../base/attachable");
5
5
  const update_cycle_1 = require("../update-cycle");
6
6
  const entity_store_helper_1 = require("./helpers/entity-store.helper");
7
7
  const entity_views_helper_1 = require("./helpers/entity-views.helper");
@@ -14,7 +14,7 @@ function EntityDecorator() {
14
14
  };
15
15
  }
16
16
  exports.EntityDecorator = EntityDecorator;
17
- class Entity extends attachment_target_1.AttachmentTarget {
17
+ class Entity extends attachable_1.Attachable {
18
18
  static getInstanceById(entityId) {
19
19
  if (entityId) {
20
20
  return entity_store_helper_1.EntityStoreHelper.getIdToEntityMap(this).get(entityId);
@@ -43,14 +43,12 @@ class Entity extends attachment_target_1.AttachmentTarget {
43
43
  })
44
44
  .attach(this);
45
45
  }
46
- // make the destroy function non-internal
47
46
  destroy() {
48
- super.destroy();
49
- }
50
- destroySelf() {
51
- super.destroySelf();
52
- this.viewCreationHelper.destroyViews();
53
- entity_store_helper_1.EntityStoreHelper.unregisterEntity(this.constructor.name, this.id);
47
+ if (!this.destroyed) {
48
+ this.viewCreationHelper.destroyViews();
49
+ entity_store_helper_1.EntityStoreHelper.unregisterEntity(this.constructor.name, this.id);
50
+ super.destroy();
51
+ }
54
52
  }
55
53
  // make the destroy function non-internal
56
54
  attach(parent) {
@@ -107,8 +107,11 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
107
107
  let Child = class Child extends entity_1.Entity {
108
108
  static { Child_1 = this; }
109
109
  static { this.destroyCalled = false; }
110
- afterDestroy() {
111
- Child_1.destroyCalled = true;
110
+ destroy() {
111
+ if (!this.destroyed) {
112
+ Child_1.destroyCalled = true;
113
+ super.destroy();
114
+ }
112
115
  }
113
116
  };
114
117
  Child = Child_1 = __decorate([
@@ -120,17 +123,6 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
120
123
  await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
121
124
  (0, vitest_1.expect)(Child.destroyCalled).toBeTruthy();
122
125
  });
123
- (0, vitest_1.test)(`attach to self should throw error`, () => {
124
- let Sample = class Sample extends entity_1.Entity {
125
- };
126
- Sample = __decorate([
127
- (0, entity_1.EntityDecorator)()
128
- ], Sample);
129
- let sample = new Sample();
130
- (0, vitest_1.expect)(() => {
131
- sample.attach(sample);
132
- }).toThrow(`Entity cannot be attach to itself!`);
133
- });
134
126
  (0, vitest_1.test)('decorator should not effect static variables', () => {
135
127
  let Sample = class Sample extends entity_1.Entity {
136
128
  static { this.test = 'test'; }
@@ -200,14 +192,18 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
200
192
  constructor() {
201
193
  super();
202
194
  callStack.push('scene constructor');
195
+ this.onDestroy
196
+ .subscribe(() => {
197
+ callStack.push('scene destroy');
198
+ })
199
+ .attach(this);
203
200
  }
204
201
  async init() { }
205
202
  update() {
206
203
  callStack.push('scene update');
207
204
  }
208
- async prepareToClose() { }
209
- afterDestroy() {
210
- callStack.push('scene destroy');
205
+ async prepareToClose() {
206
+ callStack.push('scene prepare to close');
211
207
  }
212
208
  };
213
209
  SampleScene = __decorate([
@@ -226,13 +222,16 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
226
222
  constructor() {
227
223
  super();
228
224
  callStack.push('entity constructor');
225
+ this.onDestroy
226
+ .subscribe(() => {
227
+ console.log('entity destroy');
228
+ callStack.push('entity destroy');
229
+ })
230
+ .attach(this);
229
231
  }
230
232
  update() {
231
233
  callStack.push('entity update');
232
234
  }
233
- afterDestroy() {
234
- callStack.push('entity destroy');
235
- }
236
235
  };
237
236
  Sample = __decorate([
238
237
  (0, entity_1.EntityDecorator)(),
@@ -242,13 +241,15 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
242
241
  constructor(entity) {
243
242
  super();
244
243
  callStack.push('view constructor');
244
+ this.onDestroy
245
+ .subscribe(() => {
246
+ callStack.push('view destroy');
247
+ })
248
+ .attach(this);
245
249
  }
246
250
  update() {
247
251
  callStack.push('view update');
248
252
  }
249
- afterDestroy() {
250
- callStack.push('view destroy');
251
- }
252
253
  };
253
254
  _SampleView = __decorate([
254
255
  (0, view_1.ViewDecorator)({ entity: Sample }),
@@ -257,7 +258,7 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
257
258
  SampleScene.open();
258
259
  await (0, helpers_lib_1.Wait)(); // Wait for the async scene open to be done
259
260
  await update_cycle_1.UpdateCycle.triggerUpdateTick(1);
260
- new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
261
+ new Sample().attach(SampleScene.getInstanceOrFail());
261
262
  await (0, helpers_lib_1.Wait)(); // Wait for the async view init to expect the update call
262
263
  await update_cycle_1.UpdateCycle.triggerUpdateTick(1);
263
264
  SampleScene.getInstanceOrFail().close();
@@ -273,6 +274,7 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
273
274
  'scene update',
274
275
  'entity update',
275
276
  'view update',
277
+ 'scene prepare to close',
276
278
  'view destroy',
277
279
  'entity destroy',
278
280
  'scene destroy'
@@ -1,8 +1,6 @@
1
1
  export { Attachable } from './base/attachable';
2
- export { AttachmentTarget } from './base/attachment-target';
3
2
  export { ActionsLibDecorator } from './base/helpers/decorate-actions-lib';
4
3
  export { ReferanceVariable } from './base/helpers/referance-variable';
5
- export * from './base/interfaces';
6
4
  export { ControllerDecorator, ControllerDecoratorMeta, ControllerLink } from './controller/controller';
7
5
  export { Entity, EntityDecorator } from './entity/entity';
8
6
  export { SingletonEntity } from './entity/singleton-entity';
@@ -1,29 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ViewDecorator = exports.View = exports.UpdateCycle = exports.ServiceDecorator = exports.Service = exports.SceneDecorator = exports.Scene = exports.SingletonEntity = exports.EntityDecorator = exports.Entity = exports.ControllerLink = exports.ControllerDecorator = exports.ReferanceVariable = exports.ActionsLibDecorator = exports.AttachmentTarget = exports.Attachable = void 0;
3
+ exports.ViewDecorator = exports.View = exports.UpdateCycle = exports.ServiceDecorator = exports.Service = exports.SceneDecorator = exports.Scene = exports.SingletonEntity = exports.EntityDecorator = exports.Entity = exports.ControllerLink = exports.ControllerDecorator = exports.ReferanceVariable = exports.ActionsLibDecorator = exports.Attachable = void 0;
18
4
  var attachable_1 = require("./base/attachable");
19
5
  Object.defineProperty(exports, "Attachable", { enumerable: true, get: function () { return attachable_1.Attachable; } });
20
- var attachment_target_1 = require("./base/attachment-target");
21
- Object.defineProperty(exports, "AttachmentTarget", { enumerable: true, get: function () { return attachment_target_1.AttachmentTarget; } });
22
6
  var decorate_actions_lib_1 = require("./base/helpers/decorate-actions-lib");
23
7
  Object.defineProperty(exports, "ActionsLibDecorator", { enumerable: true, get: function () { return decorate_actions_lib_1.ActionsLibDecorator; } });
24
8
  var referance_variable_1 = require("./base/helpers/referance-variable");
25
9
  Object.defineProperty(exports, "ReferanceVariable", { enumerable: true, get: function () { return referance_variable_1.ReferanceVariable; } });
26
- __exportStar(require("./base/interfaces"), exports);
27
10
  var controller_1 = require("./controller/controller");
28
11
  Object.defineProperty(exports, "ControllerDecorator", { enumerable: true, get: function () { return controller_1.ControllerDecorator; } });
29
12
  Object.defineProperty(exports, "ControllerLink", { enumerable: true, get: function () { return controller_1.ControllerLink; } });
@@ -1,10 +1,10 @@
1
1
  import { Variable } from 'actions-lib';
2
- import { AttachmentTarget } from '../base/attachment-target';
2
+ import { Attachable } from '../base/attachable';
3
3
  export type SceneClassType = new (...services: unknown[]) => Scene<unknown, unknown>;
4
4
  type SceneInput<T> = T extends Scene<infer I, any> ? I : never;
5
5
  type SceneOutput<T> = T extends Scene<any, infer O> ? O : never;
6
6
  export declare function SceneDecorator(): (SceneClass: SceneClassType) => any;
7
- export declare abstract class Scene<InputType, OutputType> extends AttachmentTarget {
7
+ export declare abstract class Scene<InputType, OutputType> extends Attachable {
8
8
  private static sceneTransitioning;
9
9
  static activeScene: Variable<Scene<unknown, unknown> | undefined>;
10
10
  static getActiveScene(this: typeof Scene): Scene<unknown, unknown> | undefined;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Scene = exports.SceneDecorator = void 0;
4
4
  const actions_lib_1 = require("actions-lib");
5
- const attachment_target_1 = require("../base/attachment-target");
5
+ const attachable_1 = require("../base/attachable");
6
6
  const service_1 = require("../service/service");
7
7
  const update_cycle_1 = require("../update-cycle");
8
8
  function SceneDecorator() {
@@ -15,7 +15,7 @@ function SceneDecorator() {
15
15
  };
16
16
  }
17
17
  exports.SceneDecorator = SceneDecorator;
18
- class Scene extends attachment_target_1.AttachmentTarget {
18
+ class Scene extends attachable_1.Attachable {
19
19
  static { this.sceneTransitioning = false; }
20
20
  static { this.activeScene = new actions_lib_1.Variable(); }
21
21
  static getActiveScene() {
@@ -155,8 +155,11 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
155
155
  let SampleEntity = class SampleEntity extends entity_1.Entity {
156
156
  static { SampleEntity_1 = this; }
157
157
  static { this.entityDestroyCalled = false; }
158
- afterDestroy() {
159
- SampleEntity_1.entityDestroyCalled = true;
158
+ destroy() {
159
+ if (!this.destroyed) {
160
+ SampleEntity_1.entityDestroyCalled = true;
161
+ super.destroy();
162
+ }
160
163
  }
161
164
  };
162
165
  SampleEntity = SampleEntity_1 = __decorate([
@@ -164,8 +167,11 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
164
167
  ], SampleEntity);
165
168
  let viewDestroyCalled = false;
166
169
  let _SampleView = class _SampleView extends view_1.View {
167
- afterDestroy() {
168
- viewDestroyCalled = true;
170
+ destroy() {
171
+ if (!this.destroyed) {
172
+ viewDestroyCalled = true;
173
+ super.destroy();
174
+ }
169
175
  }
170
176
  };
171
177
  _SampleView = __decorate([
@@ -1,17 +1,17 @@
1
- import { AttachmentTarget } from '../base/attachment-target';
1
+ import { Attachable } from '../base/attachable';
2
2
  import { Entity } from '../entity/entity';
3
3
  export type ViewClassType<EntityType> = new (entity: EntityType, ...services: any[]) => View;
4
4
  export interface ViewDecoratorMeta<EntityType> {
5
5
  entity: new (...args: any[]) => EntityType;
6
6
  }
7
7
  export declare function ViewDecorator<EntityType extends Entity>(meta: ViewDecoratorMeta<EntityType>): (ViewClass: ViewClassType<EntityType>) => any;
8
- export declare abstract class View extends AttachmentTarget {
8
+ export declare abstract class View extends Attachable {
9
9
  private static viewClassNames;
10
10
  static getInstance<T extends View>(this: new (...args: any[]) => T, entityId: string): T | undefined;
11
11
  static getInstanceOrFail<T extends View>(this: new (...args: any[]) => T, entityId: string): T;
12
12
  private _entityId;
13
13
  constructor();
14
- protected destroySelf(): void;
14
+ destroy(): void;
15
15
  update(time: number, delta: number): void;
16
16
  private getViewInstances;
17
17
  }