bard-legends-framework 0.10.9 → 0.11.0

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 (109) hide show
  1. package/dist/game-entities/controller/controller.d.ts +0 -1
  2. package/dist/game-entities/controller/controller.js +1 -0
  3. package/dist/game-entities/controller/controller.test.js +2 -2
  4. package/dist/game-entities/entity/entity.d.ts +8 -6
  5. package/dist/game-entities/entity/entity.js +5 -7
  6. package/dist/game-entities/entity/entity.test.js +40 -134
  7. package/dist/game-entities/entity/helpers/entity-store.helper.d.ts +6 -9
  8. package/dist/game-entities/entity/helpers/entity-store.helper.js +22 -57
  9. package/dist/game-entities/entity/helpers/entity-store.helper.test.d.ts +1 -0
  10. package/dist/game-entities/entity/helpers/entity-store.helper.test.js +136 -0
  11. package/dist/game-entities/entity/helpers/entity-views.helper.d.ts +1 -1
  12. package/dist/game-entities/entity/helpers/entity-views.helper.js +5 -3
  13. package/dist/game-entities/entity/singleton-entity.d.ts +3 -3
  14. package/dist/game-entities/entity/singleton-entity.js +1 -1
  15. package/dist/game-entities/entity/singleton-entity.test.js +2 -29
  16. package/dist/game-entities/index.d.ts +1 -3
  17. package/dist/game-entities/index.js +3 -7
  18. package/dist/game-entities/scene/scene.d.ts +3 -3
  19. package/dist/game-entities/scene/scene.js +31 -25
  20. package/dist/game-entities/scene/scene.test.js +4 -32
  21. package/dist/game-entities/service/service.js +5 -3
  22. package/dist/game-entities/service/service.test.js +2 -28
  23. package/dist/game-entities/unit-test.helper.d.ts +5 -0
  24. package/dist/game-entities/unit-test.helper.js +14 -0
  25. package/dist/game-entities/update-cycle.d.ts +15 -4
  26. package/dist/game-entities/update-cycle.js +14 -9
  27. package/dist/game-entities/view/view.d.ts +5 -6
  28. package/dist/game-entities/view/view.js +5 -17
  29. package/dist/game-entities/view/view.test.js +36 -244
  30. package/dist/physics/entity-types/immovable-physics-entity.d.ts +1 -3
  31. package/dist/physics/entity-types/immovable-physics-entity.js +1 -3
  32. package/dist/physics/entity-types/movable-entity.js +4 -4
  33. package/dist/physics/entity-types/movable-physics-entity.d.ts +2 -3
  34. package/dist/physics/entity-types/movable-physics-entity.js +5 -6
  35. package/dist/physics/entity-types/physics-entity.d.ts +2 -1
  36. package/dist/physics/entity-types/physics-entity.js +3 -2
  37. package/dist/physics/interfaces.d.ts +1 -1
  38. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.d.ts +3 -3
  39. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.d.ts +1 -1
  40. package/dist/physics/module//342/232/234/357/270/217gateways/physics-internal.gateway.d.ts +3 -3
  41. package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.d.ts +1 -1
  42. package/dist/physics/module//360/237/223/220services/creation/physics-world.service.js +2 -2
  43. package/dist/physics/module//360/237/223/220services/path-finding/availability-grid.service.js +1 -1
  44. package/dist/physics/module//360/237/223/220services/path-finding/path-finder.service.js +1 -1
  45. package/dist/physics/module//360/237/223/220services/query/physics-query.service.d.ts +3 -3
  46. package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +17 -7
  47. package/dist/physics/module//360/237/247/212entities/physics-world.entity.js +2 -2
  48. package/dist/pixi/components/mouse-wheel-listener.ui.d.ts +2 -1
  49. package/dist/pixi/components/mouse-wheel-listener.ui.js +4 -3
  50. package/dist/pixi/display-object/container-attributes.d.ts +2 -3
  51. package/dist/pixi/display-object/container-attributes.js +2 -3
  52. package/dist/pixi/display-object/container.d.ts +0 -3
  53. package/dist/pixi/display-object/container.js +0 -10
  54. package/dist/pixi/display-object/objects/sprite/glow-sprite-generator.js +5 -3
  55. package/dist/pixi/game.d.ts +6 -2
  56. package/dist/pixi/game.js +14 -5
  57. package/dist/pixi/modules/CAMERA//360/237/247/212entities/camera.entity.js +4 -4
  58. package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.js +1 -1
  59. package/dist/pixi/services/keyboard/keyboard.d.ts +4 -2
  60. package/dist/pixi/services/keyboard/keyboard.js +6 -4
  61. package/dist/pixi/services/mouse/mouse-target-focus.service.d.ts +2 -1
  62. package/dist/pixi/services/mouse/mouse-target-focus.service.js +6 -5
  63. package/dist/pixi/services/mouse/mouse.service.d.ts +15 -5
  64. package/dist/pixi/services/mouse/mouse.service.js +38 -18
  65. package/dist/utilities/animator/animating-content/fade-in-content.d.ts +18 -0
  66. package/dist/utilities/animator/animating-content/fade-in-content.js +37 -0
  67. package/dist/utilities/animator/animating-content/slide-in-content.d.ts +37 -0
  68. package/dist/utilities/animator/animating-content/slide-in-content.js +99 -0
  69. package/dist/utilities/animator/animations.d.ts +37 -0
  70. package/dist/utilities/animator/animations.js +88 -0
  71. package/dist/utilities/animator/animator.d.ts +61 -0
  72. package/dist/utilities/animator/animator.js +315 -0
  73. package/dist/utilities/animator/animator.test.d.ts +1 -0
  74. package/dist/utilities/animator/animator.test.js +867 -0
  75. package/dist/utilities/animator/index.d.ts +7 -0
  76. package/dist/utilities/animator/index.js +24 -0
  77. package/dist/utilities/animator/state-animation/slide-state-animation.d.ts +24 -0
  78. package/dist/utilities/animator/state-animation/slide-state-animation.js +130 -0
  79. package/dist/utilities/animator/state-animation/slide-state-animation.test.d.ts +1 -0
  80. package/dist/utilities/animator/state-animation/slide-state-animation.test.js +301 -0
  81. package/dist/utilities/animator/state-animation/state-animation.d.ts +33 -0
  82. package/dist/utilities/animator/state-animation/state-animation.js +146 -0
  83. package/dist/utilities/animator/state-animation/state-animation.test.d.ts +1 -0
  84. package/dist/utilities/animator/state-animation/state-animation.test.js +335 -0
  85. package/dist/utilities/animator/state-animation/visit-disappear-state-animation.d.ts +32 -0
  86. package/dist/utilities/animator/state-animation/visit-disappear-state-animation.js +168 -0
  87. package/dist/utilities/animator/state-animation/visit-disappear-state-animation.test.d.ts +1 -0
  88. package/dist/utilities/animator/state-animation/visit-disappear-state-animation.test.js +431 -0
  89. package/dist/utilities/data-structures/vector-set/vector-set.d.ts +7 -0
  90. package/dist/utilities/data-structures/vector-set/vector-set.js +26 -0
  91. package/dist/utilities/delta-time/delta-time.d.ts +3 -0
  92. package/dist/utilities/delta-time/delta-time.js +10 -0
  93. package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.d.ts +6 -0
  94. package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.js +55 -0
  95. package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.test.d.ts +1 -0
  96. package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.test.js +100 -0
  97. package/dist/utilities/grid-algorithms/path-finder/path-finder.d.ts +8 -0
  98. package/dist/utilities/grid-algorithms/path-finder/path-finder.js +98 -0
  99. package/dist/utilities/grid-algorithms/path-finder/path-finder.test.d.ts +1 -0
  100. package/dist/utilities/grid-algorithms/path-finder/path-finder.test.js +155 -0
  101. package/dist/utilities/grid-algorithms/position-to-grid-position-converter.d.ts +6 -0
  102. package/dist/utilities/grid-algorithms/position-to-grid-position-converter.js +17 -0
  103. package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.d.ts +18 -0
  104. package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.js +129 -0
  105. package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.test.d.ts +1 -0
  106. package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.test.js +254 -0
  107. package/dist/utilities/index.d.ts +6 -6
  108. package/dist/utilities/index.js +6 -6
  109. package/package.json +3 -3
@@ -2,7 +2,6 @@ export declare class ControllerLink {
2
2
  private controllers;
3
3
  private registeredFunctionNames;
4
4
  trigger<T>(functionName: string, ...args: any[]): T;
5
- private registerController;
6
5
  }
7
6
  export interface ControllerDecoratorMeta {
8
7
  controllerLink: ControllerLink;
@@ -16,6 +16,7 @@ class ControllerLink {
16
16
  return correspondingController[functionName](...args);
17
17
  }
18
18
  }
19
+ /** @internal */
19
20
  registerController(controller) {
20
21
  Reflect.ownKeys(controller.constructor.prototype)
21
22
  .filter(functionName => functionName !== 'constructor')
@@ -8,11 +8,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  const vitest_1 = require("vitest");
10
10
  const service_1 = require("../service/service");
11
- const update_cycle_1 = require("../update-cycle");
11
+ const unit_test_helper_1 = require("../unit-test.helper");
12
12
  const controller_1 = require("./controller");
13
13
  (0, vitest_1.describe)('CONTROLLER', () => {
14
14
  (0, vitest_1.beforeEach)(() => {
15
- update_cycle_1.UpdateCycle.hardResetAction.trigger();
15
+ unit_test_helper_1.UnitTestHelper.hardReset();
16
16
  });
17
17
  (0, vitest_1.test)('when gateway triggers service link, it should trigger the controller function', () => {
18
18
  let sampleLink = new controller_1.ControllerLink();
@@ -1,10 +1,12 @@
1
- import { Attachable } from '../base/attachable';
2
- export type EntityClassType = new (...args: any[]) => Entity;
3
- export declare function EntityDecorator(): (EntityClass: EntityClassType) => any;
1
+ import { Attachable } from 'actions-lib';
2
+ export type EntityClassType<T extends Entity = Entity> = (new (...args: any[]) => T) & {
3
+ id: string;
4
+ };
5
+ export declare function EntityDecorator(): <T extends Entity>(EntityClass: EntityClassType<T>) => any;
4
6
  export declare abstract class Entity extends Attachable {
5
- static getInstanceById<T extends Entity>(this: new (...args: any[]) => T, entityId: string | undefined): T | undefined;
6
- static getInstanceByIdOrFail<T extends Entity>(this: new (...args: any[]) => T, entityId: string): T;
7
- static getEntities<T extends Entity>(this: new (...args: any[]) => T): T[];
7
+ static getInstanceById<T extends Entity>(this: EntityClassType<T>, entityId: string | undefined): T | undefined;
8
+ static getInstanceByIdOrFail<T extends Entity>(this: EntityClassType<T>, entityId: string): T;
9
+ static getEntities<T extends Entity>(this: EntityClassType<T>): T[];
8
10
  private viewCreationHelper;
9
11
  constructor();
10
12
  destroy(): void;
@@ -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 attachable_1 = require("../base/attachable");
4
+ const actions_lib_1 = require("actions-lib");
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,14 +14,14 @@ function EntityDecorator() {
14
14
  };
15
15
  }
16
16
  exports.EntityDecorator = EntityDecorator;
17
- class Entity extends attachable_1.Attachable {
17
+ class Entity extends actions_lib_1.Attachable {
18
18
  static getInstanceById(entityId) {
19
19
  if (entityId) {
20
- return entity_store_helper_1.EntityStoreHelper.getIdToEntityMap(this).get(entityId);
20
+ return entity_store_helper_1.EntityStoreHelper.getEntity(this, entityId);
21
21
  }
22
22
  }
23
23
  static getInstanceByIdOrFail(entityId) {
24
- let entity = entity_store_helper_1.EntityStoreHelper.getIdToEntityMap(this).get(entityId);
24
+ let entity = entity_store_helper_1.EntityStoreHelper.getEntity(this, entityId);
25
25
  if (!entity) {
26
26
  throw new Error(`Entity: entity is not found! Name: "${this.name}", id: "${entityId}"`);
27
27
  }
@@ -46,17 +46,15 @@ class Entity extends attachable_1.Attachable {
46
46
  destroy() {
47
47
  if (!this.destroyed) {
48
48
  this.viewCreationHelper.destroyViews();
49
- entity_store_helper_1.EntityStoreHelper.unregisterEntity(this.constructor.name, this.id);
49
+ entity_store_helper_1.EntityStoreHelper.unregisterEntity(this.constructor, this.id);
50
50
  super.destroy();
51
51
  }
52
52
  }
53
- // make the destroy function non-internal
54
53
  attach(parent) {
55
54
  super.attach(parent);
56
55
  this.viewCreationHelper.createViews();
57
56
  return this;
58
57
  }
59
- // make the destroy function non-internal
60
58
  attachToRoot() {
61
59
  super.attachToRoot();
62
60
  this.viewCreationHelper.createViews();
@@ -1,49 +1,23 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
5
  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
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
7
  };
24
- var __importStar = (this && this.__importStar) || function (mod) {
25
- if (mod && mod.__esModule) return mod;
26
- var result = {};
27
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28
- __setModuleDefault(result, mod);
29
- return result;
30
- };
31
8
  var __metadata = (this && this.__metadata) || function (k, v) {
32
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
10
  };
34
11
  Object.defineProperty(exports, "__esModule", { value: true });
35
- const ActionsLib = __importStar(require("actions-lib"));
36
- const helpers_lib_1 = require("helpers-lib");
37
12
  const vitest_1 = require("vitest");
38
- const decorate_actions_lib_1 = require("../base/helpers/decorate-actions-lib");
39
13
  const scene_1 = require("../scene/scene");
14
+ const unit_test_helper_1 = require("../unit-test.helper");
40
15
  const update_cycle_1 = require("../update-cycle");
41
16
  const view_1 = require("../view/view");
42
17
  const entity_1 = require("./entity");
43
- decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
44
18
  (0, vitest_1.describe)('ENTITY', () => {
45
19
  (0, vitest_1.beforeEach)(() => {
46
- update_cycle_1.UpdateCycle.hardResetAction.trigger();
20
+ unit_test_helper_1.UnitTestHelper.hardReset();
47
21
  let SampleScene = class SampleScene extends scene_1.Scene {
48
22
  async init() { }
49
23
  update() { }
@@ -54,84 +28,6 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
54
28
  ], SampleScene);
55
29
  SampleScene.open();
56
30
  });
57
- (0, vitest_1.test)('entities should have ids', () => {
58
- let Sample = class Sample extends entity_1.Entity {
59
- };
60
- Sample = __decorate([
61
- (0, entity_1.EntityDecorator)()
62
- ], Sample);
63
- let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
64
- (0, vitest_1.expect)(sample.id).toBeDefined();
65
- });
66
- (0, vitest_1.test)('entities ids should be unique', () => {
67
- let BaseEntity = class BaseEntity extends entity_1.Entity {
68
- };
69
- BaseEntity = __decorate([
70
- (0, entity_1.EntityDecorator)()
71
- ], BaseEntity);
72
- let baseEntity = new BaseEntity().attach(scene_1.Scene.getActiveSceneOrFail());
73
- let Sample = class Sample extends entity_1.Entity {
74
- };
75
- Sample = __decorate([
76
- (0, entity_1.EntityDecorator)()
77
- ], Sample);
78
- let sample1 = new Sample().attach(baseEntity);
79
- let sample2 = new Sample().attach(baseEntity);
80
- (0, vitest_1.expect)(sample1.id !== sample2.id).toBeTruthy();
81
- });
82
- (0, vitest_1.test)('class names should be unique', () => {
83
- (0, vitest_1.expect)(() => {
84
- {
85
- let _Sample = class _Sample extends entity_1.Entity {
86
- };
87
- _Sample = __decorate([
88
- (0, entity_1.EntityDecorator)()
89
- ], _Sample);
90
- }
91
- {
92
- let _Sample = class _Sample extends entity_1.Entity {
93
- };
94
- _Sample = __decorate([
95
- (0, entity_1.EntityDecorator)()
96
- ], _Sample);
97
- }
98
- }).toThrow();
99
- });
100
- (0, vitest_1.test)('attach', async () => {
101
- var Child_1;
102
- let Parent = class Parent extends entity_1.Entity {
103
- };
104
- Parent = __decorate([
105
- (0, entity_1.EntityDecorator)()
106
- ], Parent);
107
- let Child = class Child extends entity_1.Entity {
108
- static { Child_1 = this; }
109
- static { this.destroyCalled = false; }
110
- destroy() {
111
- if (!this.destroyed) {
112
- Child_1.destroyCalled = true;
113
- super.destroy();
114
- }
115
- }
116
- };
117
- Child = Child_1 = __decorate([
118
- (0, entity_1.EntityDecorator)()
119
- ], Child);
120
- let parent = new Parent().attach(scene_1.Scene.getActiveSceneOrFail());
121
- new Child().attach(parent);
122
- parent.destroy();
123
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
124
- (0, vitest_1.expect)(Child.destroyCalled).toBeTruthy();
125
- });
126
- (0, vitest_1.test)('decorator should not effect static variables', () => {
127
- let Sample = class Sample extends entity_1.Entity {
128
- static { this.test = 'test'; }
129
- };
130
- Sample = __decorate([
131
- (0, entity_1.EntityDecorator)()
132
- ], Sample);
133
- (0, vitest_1.expect)(Sample.test).toEqual('test');
134
- });
135
31
  (0, vitest_1.test)('get entity by id basic sample', () => {
136
32
  let Sample = class Sample extends entity_1.Entity {
137
33
  };
@@ -143,17 +39,28 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
143
39
  });
144
40
  (0, vitest_1.test)('get entity by id or fail should return error', () => {
145
41
  let Sample1 = class Sample1 extends entity_1.Entity {
42
+ constructor(foo) {
43
+ super();
44
+ this.foo = foo;
45
+ }
146
46
  };
147
47
  Sample1 = __decorate([
148
- (0, entity_1.EntityDecorator)()
48
+ (0, entity_1.EntityDecorator)(),
49
+ __metadata("design:paramtypes", [String])
149
50
  ], Sample1);
150
51
  let Sample2 = class Sample2 extends entity_1.Entity {
52
+ constructor(foo) {
53
+ super();
54
+ this.foo = foo;
55
+ }
151
56
  };
152
57
  Sample2 = __decorate([
153
- (0, entity_1.EntityDecorator)()
58
+ (0, entity_1.EntityDecorator)(),
59
+ __metadata("design:paramtypes", [String])
154
60
  ], Sample2);
155
- let sample1 = new Sample1().attach(scene_1.Scene.getActiveSceneOrFail());
156
- new Sample2().attach(sample1);
61
+ // Foo is added to see that there should not be type complaining about the constructor parameters
62
+ let sample1 = new Sample1('foo').attach(scene_1.Scene.getActiveSceneOrFail());
63
+ new Sample2('foo').attach(sample1);
157
64
  (0, vitest_1.expect)(() => Sample2.getInstanceByIdOrFail(sample1.id)).toThrow();
158
65
  (0, vitest_1.expect)(() => Sample2.getInstanceByIdOrFail('notValidId')).toThrow();
159
66
  });
@@ -166,7 +73,6 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
166
73
  let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
167
74
  (0, vitest_1.expect)(Sample.getInstanceById(sample.id)).toBeDefined();
168
75
  sample.destroy();
169
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
170
76
  (0, vitest_1.expect)(Sample.getInstanceById(sample.id)).toBeUndefined();
171
77
  });
172
78
  (0, vitest_1.test)('select entities', () => {
@@ -185,18 +91,28 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
185
91
  let sample2 = new Sample().attach(baseEntity);
186
92
  (0, vitest_1.expect)(Sample.getEntities()).toEqual([sample1, sample2]);
187
93
  });
94
+ (0, vitest_1.test)('decorator should not complain aboutentity with constructor parameters', () => {
95
+ let _Sample = class _Sample extends entity_1.Entity {
96
+ constructor(test) {
97
+ super();
98
+ this.test = test;
99
+ }
100
+ };
101
+ _Sample = __decorate([
102
+ (0, entity_1.EntityDecorator)(),
103
+ __metadata("design:paramtypes", [String])
104
+ ], _Sample);
105
+ });
188
106
  (0, vitest_1.test)('lifecycle events', async () => {
189
- scene_1.Scene.activeScene.set(undefined);
107
+ scene_1.Scene['_activeScene'].set(undefined);
190
108
  let callStack = [];
191
109
  let SampleScene = class SampleScene extends scene_1.Scene {
192
110
  constructor() {
193
111
  super();
194
112
  callStack.push('scene constructor');
195
- this.onDestroy
196
- .subscribe(() => {
113
+ this.onDestroy(() => {
197
114
  callStack.push('scene destroy');
198
- })
199
- .attach(this);
115
+ }).attach(this);
200
116
  }
201
117
  async init() { }
202
118
  update() {
@@ -222,12 +138,9 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
222
138
  constructor() {
223
139
  super();
224
140
  callStack.push('entity constructor');
225
- this.onDestroy
226
- .subscribe(() => {
227
- console.log('entity destroy');
141
+ this.onDestroy(() => {
228
142
  callStack.push('entity destroy');
229
- })
230
- .attach(this);
143
+ }).attach(this);
231
144
  }
232
145
  update() {
233
146
  callStack.push('entity update');
@@ -241,11 +154,9 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
241
154
  constructor(entity) {
242
155
  super();
243
156
  callStack.push('view constructor');
244
- this.onDestroy
245
- .subscribe(() => {
157
+ this.onDestroy(() => {
246
158
  callStack.push('view destroy');
247
- })
248
- .attach(this);
159
+ }).attach(this);
249
160
  }
250
161
  update() {
251
162
  callStack.push('view update');
@@ -255,17 +166,12 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
255
166
  (0, view_1.ViewDecorator)({ entity: Sample }),
256
167
  __metadata("design:paramtypes", [Sample])
257
168
  ], _SampleView);
258
- SampleScene.open();
259
- await (0, helpers_lib_1.Wait)(); // Wait for the async scene open to be done
260
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1);
169
+ await SampleScene.open().onOpen;
170
+ await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // make scene update to be triggered before any entity or view being created
261
171
  new Sample().attach(SampleScene.getInstanceOrFail());
262
- await (0, helpers_lib_1.Wait)(); // Wait for the async view init to expect the update call
263
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1);
264
- SampleScene.getInstanceOrFail().close();
265
- await (0, helpers_lib_1.Wait)(); // Wait for the async scene close to be done
172
+ await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // make update calls of scene entity and view to be triggered
173
+ await SampleScene.getInstanceOrFail().close();
266
174
  OtherScene.open();
267
- await (0, helpers_lib_1.Wait)(); // Wait for the async scene open to be done
268
- await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
269
175
  (0, vitest_1.expect)(callStack).toEqual([
270
176
  'scene constructor',
271
177
  'scene update',
@@ -1,14 +1,11 @@
1
1
  import { Entity, EntityClassType } from '../entity';
2
2
  export declare class EntityStoreHelper {
3
- private static entities;
3
+ private static classIdToEntityIdToEntity;
4
4
  static registerEntityClass(entityClass: EntityClassType): void;
5
5
  static registerEntity(entity: Entity): void;
6
- static unregisterEntity(entityClassName: string, entityId: string): void;
7
- static getIdToEntityMap<T extends Entity>(EntityClass: new (...args: any[]) => T): Map<string, T>;
8
- static getSingleton<T extends Entity>(EntityClass: new (...args: any[]) => T): T | undefined;
9
- static getSingletonOrFail<T extends Entity>(EntityClass: new (...args: any[]) => T): T;
10
- static getEntities<T extends Entity>(EntityClass: new (...args: any[]) => T): T[];
11
- static getEntityById<T extends Entity>(entityId: string, EntityClass: new (...args: any[]) => T): T | undefined;
12
- private static getEntityByParsingId;
13
- private static getClassNameFromEntityId;
6
+ static unregisterEntity(Class: EntityClassType, entityId: string): void;
7
+ static getEntity<T extends Entity>(Class: EntityClassType<T>, entityId: string): T | undefined;
8
+ static getSingleton<T extends Entity>(EntityClass: EntityClassType<T>): T | undefined;
9
+ static getSingletonOrFail<T extends Entity>(EntityClass: EntityClassType<T>): T;
10
+ static getEntities<T extends Entity>(EntityClass: EntityClassType<T>): T[];
14
11
  }
@@ -1,81 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EntityStoreHelper = void 0;
4
- const update_cycle_1 = require("../../update-cycle");
4
+ const unit_test_helper_1 = require("../../unit-test.helper");
5
5
  class EntityStoreHelper {
6
- static { this.entities = new Map(); }
6
+ static { this.classIdToEntityIdToEntity = new Map(); }
7
7
  static registerEntityClass(entityClass) {
8
- if (this.entities.has(entityClass.name)) {
9
- throw new Error(`EntityStoreHelper: Entity class names should be unique! This entity name is already taken. name: "${entityClass.name}"`);
10
- }
11
- else {
12
- this.entities.set(entityClass.name, new Map());
13
- }
8
+ this.classIdToEntityIdToEntity.set(entityClass.id, new Map());
14
9
  }
15
10
  static registerEntity(entity) {
16
- let idToEntityMap = this.entities.get(entity.constructor.name);
11
+ let idToEntityMap = this.classIdToEntityIdToEntity.get(entity.classId);
17
12
  idToEntityMap.set(entity.id, entity);
18
13
  }
19
- static unregisterEntity(entityClassName, entityId) {
20
- this.entities.get(entityClassName)?.delete(entityId);
14
+ static unregisterEntity(Class, entityId) {
15
+ let classId = Class.id;
16
+ this.classIdToEntityIdToEntity.get(classId)?.delete(entityId);
21
17
  }
22
- static getIdToEntityMap(EntityClass) {
23
- return this.entities.get(EntityClass.name);
18
+ static getEntity(Class, entityId) {
19
+ return this.classIdToEntityIdToEntity.get(Class.id)?.get(entityId);
24
20
  }
25
21
  static getSingleton(EntityClass) {
26
- let entities = EntityStoreHelper.getEntities(EntityClass);
27
- return entities[0];
28
- }
29
- static getSingletonOrFail(EntityClass) {
30
22
  let entities = EntityStoreHelper.getEntities(EntityClass);
31
23
  if (entities.length > 1) {
32
24
  throw new Error(`EntityStoreHelper: selectSingleton is called with an entity that has multiple instances! Name: "${this.name}"`);
33
25
  }
34
- else if (entities.length === 0) {
26
+ return entities[0];
27
+ }
28
+ static getSingletonOrFail(EntityClass) {
29
+ let entity = this.getSingleton(EntityClass);
30
+ if (!entity) {
35
31
  throw new Error(`EntityStoreHelper: selectSingleton is called with an entity that has no instance! Name: "${this.name}"`);
36
32
  }
37
- else {
38
- return entities[0];
39
- }
33
+ return entity;
40
34
  }
41
35
  static getEntities(EntityClass) {
42
- let idToEntityMap = this.entities.get(EntityClass.name);
43
- let entities = Array.from(idToEntityMap.values());
44
- return entities.filter(entity => !entity['destroyed']);
45
- }
46
- static getEntityById(entityId, EntityClass) {
47
- let entity = this.getEntityByParsingId(entityId);
48
- if (entity) {
49
- if (entity instanceof EntityClass) {
50
- return entity;
51
- }
52
- else {
53
- throw new Error(`EntityStoreHelper: The given id: "${entityId}", is not belonging to the class: "${EntityClass.name}"`);
54
- }
55
- }
56
- }
57
- static getEntityByParsingId(entityId) {
58
- try {
59
- let className = this.getClassNameFromEntityId(entityId);
60
- return this.entities.get(className)?.get(entityId);
61
- }
62
- catch {
63
- throw new Error(`EntityStoreHelper.getEntityByIdWithoutType(): invalid entity id: "${entityId}"`);
64
- }
65
- }
66
- static getClassNameFromEntityId(entityId) {
67
- if (!entityId) {
68
- throw new Error(`EntityStoreHelper: getClassNameFromEntityId called with no id: "${entityId}"`);
69
- }
70
- let index = entityId.indexOf(':');
71
- if (index === -1) {
72
- throw new Error(`EntityStoreHelper: invalid entity id: "${entityId}"`);
73
- }
74
- return entityId.substring(0, index);
36
+ let idToEntityMap = this.classIdToEntityIdToEntity.get(EntityClass.id);
37
+ return Array.from(idToEntityMap.values());
75
38
  }
76
39
  }
77
40
  exports.EntityStoreHelper = EntityStoreHelper;
78
- update_cycle_1.UpdateCycle.hardResetAction.subscribe(() => {
79
- EntityStoreHelper['entities'].clear();
80
- });
41
+ unit_test_helper_1.UnitTestHelper.onHardReset
42
+ .subscribe(() => {
43
+ EntityStoreHelper['classIdToEntityIdToEntity'].clear();
44
+ })
45
+ .attachToRoot();
81
46
  //# sourceMappingURL=entity-store.helper.js.map
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const vitest_1 = require("vitest");
10
+ const unit_test_helper_1 = require("../../unit-test.helper");
11
+ const entity_1 = require("../entity");
12
+ const singleton_entity_1 = require("../singleton-entity");
13
+ const entity_store_helper_1 = require("./entity-store.helper");
14
+ (0, vitest_1.describe)('EntityStoreHelper', () => {
15
+ (0, vitest_1.beforeEach)(() => {
16
+ unit_test_helper_1.UnitTestHelper.hardReset();
17
+ });
18
+ (0, vitest_1.describe)('registering entity class', () => {
19
+ (0, vitest_1.test)('should register entity class', () => {
20
+ let Sample = class Sample extends entity_1.Entity {
21
+ };
22
+ Sample = __decorate([
23
+ (0, entity_1.EntityDecorator)()
24
+ ], Sample);
25
+ entity_store_helper_1.EntityStoreHelper.registerEntityClass(Sample);
26
+ let classId = Sample.id;
27
+ (0, vitest_1.expect)(classId).toBeDefined();
28
+ if (classId) {
29
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper['classIdToEntityIdToEntity'].get(classId)).toBeDefined();
30
+ }
31
+ });
32
+ (0, vitest_1.test)('should register entity class with different class ids', () => {
33
+ let Sample1 = class Sample1 extends entity_1.Entity {
34
+ };
35
+ Sample1 = __decorate([
36
+ (0, entity_1.EntityDecorator)()
37
+ ], Sample1);
38
+ let Sample2 = class Sample2 extends entity_1.Entity {
39
+ };
40
+ Sample2 = __decorate([
41
+ (0, entity_1.EntityDecorator)()
42
+ ], Sample2);
43
+ entity_store_helper_1.EntityStoreHelper.registerEntityClass(Sample1);
44
+ entity_store_helper_1.EntityStoreHelper.registerEntityClass(Sample2);
45
+ let classId1 = entity_store_helper_1.EntityStoreHelper['classIdToEntityIdToEntity'].get(Sample1.id);
46
+ let classId2 = entity_store_helper_1.EntityStoreHelper['classIdToEntityIdToEntity'].get(Sample2.id);
47
+ (0, vitest_1.expect)(classId1).toBeDefined();
48
+ (0, vitest_1.expect)(classId2).toBeDefined();
49
+ (0, vitest_1.expect)(classId1).not.toBe(classId2);
50
+ });
51
+ });
52
+ (0, vitest_1.describe)('crud operations on entity', () => {
53
+ (0, vitest_1.test)('register entity', () => {
54
+ let Sample = class Sample extends entity_1.Entity {
55
+ };
56
+ Sample = __decorate([
57
+ (0, entity_1.EntityDecorator)()
58
+ ], Sample);
59
+ let entity = new Sample().attachToRoot();
60
+ entity_store_helper_1.EntityStoreHelper.registerEntity(entity);
61
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper.getEntity(Sample, entity.id)).toBeDefined();
62
+ });
63
+ (0, vitest_1.test)('unregister entity', () => {
64
+ let Sample = class Sample extends entity_1.Entity {
65
+ };
66
+ Sample = __decorate([
67
+ (0, entity_1.EntityDecorator)()
68
+ ], Sample);
69
+ let entity = new Sample().attachToRoot();
70
+ entity_store_helper_1.EntityStoreHelper.registerEntity(entity);
71
+ entity_store_helper_1.EntityStoreHelper.unregisterEntity(Sample, entity.id);
72
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper.getEntity(Sample, entity.id)).toBeUndefined();
73
+ });
74
+ (0, vitest_1.test)('get entity', () => {
75
+ let Sample = class Sample extends entity_1.Entity {
76
+ };
77
+ Sample = __decorate([
78
+ (0, entity_1.EntityDecorator)()
79
+ ], Sample);
80
+ let entity = new Sample().attachToRoot();
81
+ entity_store_helper_1.EntityStoreHelper.registerEntity(entity);
82
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper.getEntity(Sample, entity.id)).toBe(entity);
83
+ });
84
+ (0, vitest_1.test)('get entities', () => {
85
+ let Sample = class Sample extends entity_1.Entity {
86
+ };
87
+ Sample = __decorate([
88
+ (0, entity_1.EntityDecorator)()
89
+ ], Sample);
90
+ let entity1 = new Sample().attachToRoot();
91
+ let entity2 = new Sample().attachToRoot();
92
+ entity_store_helper_1.EntityStoreHelper.registerEntity(entity1);
93
+ entity_store_helper_1.EntityStoreHelper.registerEntity(entity2);
94
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper.getEntities(Sample)).toEqual([entity1, entity2]);
95
+ });
96
+ });
97
+ (0, vitest_1.describe)('singleton operations', () => {
98
+ (0, vitest_1.test)('get singleton with success', () => {
99
+ let Sample = class Sample extends singleton_entity_1.SingletonEntity {
100
+ };
101
+ Sample = __decorate([
102
+ (0, entity_1.EntityDecorator)()
103
+ ], Sample);
104
+ let entity = new Sample().attachToRoot();
105
+ entity_store_helper_1.EntityStoreHelper.registerEntity(entity);
106
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper.getSingleton(Sample)).toBe(entity);
107
+ });
108
+ (0, vitest_1.test)('get singleton with error', () => {
109
+ let Sample = class Sample extends singleton_entity_1.SingletonEntity {
110
+ };
111
+ Sample = __decorate([
112
+ (0, entity_1.EntityDecorator)()
113
+ ], Sample);
114
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper.getSingleton(Sample)).toBeUndefined();
115
+ });
116
+ (0, vitest_1.test)('get singleton or fail with success', () => {
117
+ let Sample = class Sample extends singleton_entity_1.SingletonEntity {
118
+ };
119
+ Sample = __decorate([
120
+ (0, entity_1.EntityDecorator)()
121
+ ], Sample);
122
+ let entity = new Sample().attachToRoot();
123
+ entity_store_helper_1.EntityStoreHelper.registerEntity(entity);
124
+ (0, vitest_1.expect)(entity_store_helper_1.EntityStoreHelper.getSingletonOrFail(Sample)).toBe(entity);
125
+ });
126
+ (0, vitest_1.test)('get singleton or fail with error', () => {
127
+ let Sample = class Sample extends singleton_entity_1.SingletonEntity {
128
+ };
129
+ Sample = __decorate([
130
+ (0, entity_1.EntityDecorator)()
131
+ ], Sample);
132
+ (0, vitest_1.expect)(() => entity_store_helper_1.EntityStoreHelper.getSingletonOrFail(Sample)).toThrow();
133
+ });
134
+ });
135
+ });
136
+ //# sourceMappingURL=entity-store.helper.test.js.map
@@ -4,7 +4,7 @@ export declare class EntityViewsHelper {
4
4
  private entity;
5
5
  private static viewRegistries;
6
6
  static currentEntityId: string;
7
- static registerView<T>(ViewClass: ViewClassType<T>, EntityClass: EntityClassType): void;
7
+ static registerView<T extends Entity>(ViewClass: ViewClassType<T>, EntityClass: EntityClassType<T>): void;
8
8
  private static createView;
9
9
  private views;
10
10
  constructor(entity: Entity);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EntityViewsHelper = void 0;
4
4
  const service_1 = require("../../service/service");
5
- const update_cycle_1 = require("../../update-cycle");
5
+ const unit_test_helper_1 = require("../../unit-test.helper");
6
6
  const entity_store_helper_1 = require("./entity-store.helper");
7
7
  class EntityViewsHelper {
8
8
  static { this.viewRegistries = new Map(); }
@@ -60,7 +60,9 @@ class EntityViewsHelper {
60
60
  }
61
61
  }
62
62
  exports.EntityViewsHelper = EntityViewsHelper;
63
- update_cycle_1.UpdateCycle.hardResetAction.subscribe(() => {
63
+ unit_test_helper_1.UnitTestHelper.onHardReset
64
+ .subscribe(() => {
64
65
  EntityViewsHelper['viewRegistries'] = new Map();
65
- });
66
+ })
67
+ .attachToRoot();
66
68
  //# sourceMappingURL=entity-views.helper.js.map