bard-legends-framework 0.10.5 → 0.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/game-entities/_base/attachable.d.ts +10 -0
  2. package/dist/game-entities/_base/attachable.js +47 -0
  3. package/dist/game-entities/_base/attachable.store.d.ts +8 -0
  4. package/dist/game-entities/_base/attachable.store.js +43 -0
  5. package/dist/game-entities/_base/attachment-target.d.ts +16 -0
  6. package/dist/game-entities/_base/attachment-target.js +53 -0
  7. package/dist/game-entities/_base/destroyable.d.ts +3 -0
  8. package/dist/game-entities/_base/destroyable.js +10 -0
  9. package/dist/game-entities/_base/interfaces.d.ts +3 -0
  10. package/dist/game-entities/_base/interfaces.js +3 -0
  11. package/dist/game-entities/_base/mixins.d.ts +22 -0
  12. package/dist/game-entities/_base/mixins.js +60 -0
  13. package/dist/game-entities/base/attachable.d.ts +8 -7
  14. package/dist/game-entities/base/attachable.js +47 -21
  15. package/dist/game-entities/base/attachment-target.d.ts +9 -0
  16. package/dist/game-entities/base/attachment-target.js +53 -0
  17. package/dist/game-entities/base/attachment-target.test.d.ts +1 -0
  18. package/dist/game-entities/base/attachment-target.test.js +131 -0
  19. package/dist/game-entities/base/destroyable.d.ts +2 -3
  20. package/dist/game-entities/base/destroyable.js +0 -21
  21. package/dist/game-entities/base/helpers/attachable.store.d.ts +4 -4
  22. package/dist/game-entities/base/helpers/attachment-target.store.d.ts +1 -0
  23. package/dist/game-entities/base/helpers/attachment-target.store.js +40 -0
  24. package/dist/game-entities/base/helpers/decorate-actions-lib.d.ts +3 -3
  25. package/dist/game-entities/base/helpers/decorate-actions-lib.js +3 -3
  26. package/dist/game-entities/base/helpers/referance-variable.d.ts +2 -2
  27. package/dist/game-entities/base/helpers/referance-variable.js +2 -2
  28. package/dist/game-entities/base/interfaces.d.ts +8 -8
  29. package/dist/game-entities/entity/entity.d.ts +4 -4
  30. package/dist/game-entities/entity/entity.js +9 -2
  31. package/dist/game-entities/entity/entity.test.js +14 -3
  32. package/dist/game-entities/entity/singleton-entity.d.ts +0 -9
  33. package/dist/game-entities/entity/singleton-entity.js +0 -55
  34. package/dist/game-entities/entity/singleton-entity.test.js +4 -1
  35. package/dist/game-entities/index.d.ts +1 -1
  36. package/dist/game-entities/index.js +3 -3
  37. package/dist/game-entities/scene/scene.d.ts +22 -15
  38. package/dist/game-entities/scene/scene.js +56 -40
  39. package/dist/game-entities/scene/scene.test.js +45 -37
  40. package/dist/game-entities/service/service.test.js +20 -5
  41. package/dist/game-entities/view/view.d.ts +2 -3
  42. package/dist/game-entities/view/view.js +4 -4
  43. package/dist/game-entities/view/view.test.js +5 -2
  44. package/dist/pixi/components/helpers/smooth-scroller.d.ts +2 -2
  45. package/dist/pixi/components/helpers/smooth-scroller.js +1 -1
  46. package/dist/pixi/display-object/container-attributes.d.ts +2 -2
  47. package/dist/pixi/display-object/container-attributes.js +1 -1
  48. package/dist/pixi/display-object/container.d.ts +1 -0
  49. package/dist/pixi/display-object/container.js +4 -0
  50. package/dist/pixi/game.d.ts +2 -1
  51. package/dist/pixi/game.js +2 -0
  52. package/dist/utilities/libraries/animator/animator.d.ts +3 -2
  53. package/dist/utilities/libraries/animator/animator.js +9 -2
  54. package/dist/utilities/libraries/animator/animator.test.js +12 -3
  55. package/dist/utilities/libraries/animator/state-animation/slide-state-animation.d.ts +2 -2
  56. package/dist/utilities/libraries/animator/state-animation/slide-state-animation.js +1 -1
  57. package/dist/utilities/libraries/animator/state-animation/state-animation.d.ts +2 -2
  58. package/dist/utilities/libraries/animator/state-animation/state-animation.js +1 -1
  59. package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.d.ts +2 -2
  60. package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.js +1 -1
  61. package/package.json +5 -12
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachmentTargetStore = void 0;
4
+ const helpers_lib_1 = require("helpers-lib");
5
+ const update_cycle_1 = require("../../update-cycle");
6
+ /** @internal */
7
+ class AttachmentTargetStore {
8
+ static { this.nextAvailableIds = new Map(); }
9
+ static { this.attachmentTargets = new Map(); }
10
+ static findAttachableParent(attachableCandidate) {
11
+ let attachmentTarget;
12
+ if (helpers_lib_1.Comparator.isString(attachableCandidate)) {
13
+ let attachableId = attachableCandidate;
14
+ attachmentTarget = this.attachmentTargets.get(attachableId);
15
+ if (!attachmentTarget) {
16
+ throw new Error(`Attachable: attachable not found by id! id: ${attachableId}`);
17
+ }
18
+ }
19
+ else {
20
+ attachmentTarget = attachableCandidate;
21
+ }
22
+ return attachmentTarget;
23
+ }
24
+ static registerAttachable(attachmentTarget) {
25
+ let numberPartOfTheId = AttachmentTargetStore.nextAvailableIds.get(attachmentTarget.constructor.name) || 1;
26
+ AttachmentTargetStore.nextAvailableIds.set(attachmentTarget.constructor.name, numberPartOfTheId + 1);
27
+ let id = `${attachmentTarget.constructor.name}:${numberPartOfTheId}`;
28
+ AttachmentTargetStore.attachmentTargets.set(id, attachmentTarget);
29
+ return id;
30
+ }
31
+ static unregisterAttachable(attachmentTarget) {
32
+ AttachmentTargetStore.attachmentTargets.delete(attachmentTarget.id);
33
+ }
34
+ }
35
+ exports.AttachmentTargetStore = AttachmentTargetStore;
36
+ update_cycle_1.UpdateCycle.hardResetAction.subscribe(() => {
37
+ AttachmentTargetStore['nextAvailableIds'].clear();
38
+ AttachmentTargetStore['attachmentTargets'].clear();
39
+ });
40
+ //# sourceMappingURL=attachment-target.store.js.map
@@ -1,12 +1,12 @@
1
- import { Attachable } from '../attachable';
1
+ import { AttachmentTarget } from '../attachment-target';
2
2
  declare module 'actions-lib' {
3
3
  interface ActionSubscription {
4
- attach(parent: Attachable | string): ActionSubscription;
4
+ attach(parent: AttachmentTarget | string): ActionSubscription;
5
5
  attachToRoot(): ActionSubscription;
6
6
  decorateActionSubscription(): ActionSubscription;
7
7
  }
8
8
  interface ReducerEffectChannel<EffectType, ResponseType> {
9
- attach(parent: Attachable | string): ReducerEffectChannel<EffectType, ResponseType>;
9
+ attach(parent: AttachmentTarget | 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 attachable_store_1 = require("./attachable.store");
28
+ const attachment_target_store_1 = require("./attachment-target.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 = attachable_store_1.AttachableStore.findAttachableParent(parent);
41
+ let parentEntity = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(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 = attachable_store_1.AttachableStore.findAttachableParent(parent);
64
+ let parentEntity = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(parent);
65
65
  parentEntity['setAttachment'](this);
66
66
  this.$meta = { attachIsCalled: true, attachedParent: parentEntity };
67
67
  return this;
@@ -1,5 +1,5 @@
1
1
  import { ActionListenerCallbackFunction, ActionSubscription, IVariable } from 'actions-lib';
2
- import { Attachable } from '../attachable';
2
+ import { AttachmentTarget } from '../attachment-target';
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: Attachable;
11
+ attachTo: AttachmentTarget;
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 attachable_store_1 = require("./attachable.store");
5
+ const attachment_target_store_1 = require("./attachment-target.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 = attachable_store_1.AttachableStore.findAttachableParent(data)
25
+ this.destroySubscription = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(data)
26
26
  .onDestroy.subscribe(() => {
27
27
  this.set(undefined);
28
28
  })
@@ -1,14 +1,14 @@
1
- import { Action, Variable } from 'actions-lib';
2
- export interface IDestroyable {
3
- destroy(): void;
4
- }
5
- export interface IAttachable {
1
+ import { Action } from 'actions-lib';
2
+ export interface IAttachmentTarget {
6
3
  readonly id: string;
7
4
  readonly onDestroy: Action<void>;
8
- setAttachment(child: CanBeAttached): void;
9
- removeAttachment(child: CanBeAttached): void;
5
+ setAttachment(child: IAttachable): void;
6
+ removeAttachment(child: IAttachable): void;
7
+ }
8
+ export interface IDestroyable {
9
+ destroy(): void;
10
10
  }
11
11
  export interface IUnsubscribable {
12
12
  unsubscribe(...args: any[]): void;
13
13
  }
14
- export type CanBeAttached = IDestroyable | IUnsubscribable | CanBeAttached[] | Variable<CanBeAttached>;
14
+ export type IAttachable = IDestroyable | IUnsubscribable;
@@ -1,14 +1,14 @@
1
- import { Attachable } from '../base/attachable';
1
+ import { AttachmentTarget } from '../base/attachment-target';
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 Attachable {
4
+ export declare abstract class Entity extends AttachmentTarget {
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
+ destroy(): void;
10
11
  protected destroySelf(): void;
11
- attach(parent: Attachable | string): this;
12
+ attach(parent: AttachmentTarget | string): this;
12
13
  attachToRoot(): this;
13
- update(time: number, delta: number): void;
14
14
  }
@@ -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 attachment_target_1 = require("../base/attachment-target");
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 attachable_1.Attachable {
17
+ class Entity extends attachment_target_1.AttachmentTarget {
18
18
  static getInstanceById(entityId) {
19
19
  if (entityId) {
20
20
  return entity_store_helper_1.EntityStoreHelper.getIdToEntityMap(this).get(entityId);
@@ -43,21 +43,28 @@ class Entity extends attachable_1.Attachable {
43
43
  })
44
44
  .attach(this);
45
45
  }
46
+ // make the destroy function non-internal
47
+ destroy() {
48
+ super.destroy();
49
+ }
46
50
  destroySelf() {
47
51
  super.destroySelf();
48
52
  this.viewCreationHelper.destroyViews();
49
53
  entity_store_helper_1.EntityStoreHelper.unregisterEntity(this.constructor.name, this.id);
50
54
  }
55
+ // make the destroy function non-internal
51
56
  attach(parent) {
52
57
  super.attach(parent);
53
58
  this.viewCreationHelper.createViews();
54
59
  return this;
55
60
  }
61
+ // make the destroy function non-internal
56
62
  attachToRoot() {
57
63
  super.attachToRoot();
58
64
  this.viewCreationHelper.createViews();
59
65
  return this;
60
66
  }
67
+ /** @internal */
61
68
  update(time, delta) { }
62
69
  }
63
70
  exports.Entity = Entity;
@@ -45,11 +45,14 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
45
45
  (0, vitest_1.beforeEach)(() => {
46
46
  update_cycle_1.UpdateCycle.hardResetAction.trigger();
47
47
  let SampleScene = class SampleScene extends scene_1.Scene {
48
+ async init() { }
49
+ update() { }
50
+ async prepareToClose() { }
48
51
  };
49
52
  SampleScene = __decorate([
50
53
  (0, scene_1.SceneDecorator)()
51
54
  ], SampleScene);
52
- SampleScene.open(undefined);
55
+ SampleScene.open();
53
56
  });
54
57
  (0, vitest_1.test)('entities should have ids', () => {
55
58
  let Sample = class Sample extends entity_1.Entity {
@@ -191,15 +194,18 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
191
194
  (0, vitest_1.expect)(Sample.getEntities()).toEqual([sample1, sample2]);
192
195
  });
193
196
  (0, vitest_1.test)('lifecycle events', async () => {
197
+ scene_1.Scene.activeScene.set(undefined);
194
198
  let callStack = [];
195
199
  let SampleScene = class SampleScene extends scene_1.Scene {
196
200
  constructor() {
197
201
  super();
198
202
  callStack.push('scene constructor');
199
203
  }
204
+ async init() { }
200
205
  update() {
201
206
  callStack.push('scene update');
202
207
  }
208
+ async prepareToClose() { }
203
209
  afterDestroy() {
204
210
  callStack.push('scene destroy');
205
211
  }
@@ -209,6 +215,9 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
209
215
  __metadata("design:paramtypes", [])
210
216
  ], SampleScene);
211
217
  let OtherScene = class OtherScene extends scene_1.Scene {
218
+ async init() { }
219
+ update() { }
220
+ async prepareToClose() { }
212
221
  };
213
222
  OtherScene = __decorate([
214
223
  (0, scene_1.SceneDecorator)()
@@ -245,13 +254,15 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
245
254
  (0, view_1.ViewDecorator)({ entity: Sample }),
246
255
  __metadata("design:paramtypes", [Sample])
247
256
  ], _SampleView);
248
- SampleScene.open(undefined);
257
+ SampleScene.open();
249
258
  await (0, helpers_lib_1.Wait)(); // Wait for the async scene open to be done
250
259
  await update_cycle_1.UpdateCycle.triggerUpdateTick(1);
251
260
  new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
252
261
  await (0, helpers_lib_1.Wait)(); // Wait for the async view init to expect the update call
253
262
  await update_cycle_1.UpdateCycle.triggerUpdateTick(1);
254
- OtherScene.open(undefined);
263
+ SampleScene.getInstanceOrFail().close();
264
+ await (0, helpers_lib_1.Wait)(); // Wait for the async scene close to be done
265
+ OtherScene.open();
255
266
  await (0, helpers_lib_1.Wait)(); // Wait for the async scene open to be done
256
267
  await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
257
268
  (0, vitest_1.expect)(callStack).toEqual([
@@ -1,15 +1,6 @@
1
- import { ActionSubscription } from 'actions-lib';
2
1
  import { Entity } from './entity';
3
2
  export declare abstract class SingletonEntity extends Entity {
4
- private static onSingletonCreated;
5
3
  static getInstance<T extends SingletonEntity>(this: new (...args: any[]) => T): T | undefined;
6
4
  static getInstanceOrFail<T extends SingletonEntity>(this: new (...args: any[]) => T): T;
7
- static getInstanceAsync<T extends SingletonEntity>(this: new (...args: any[]) => T): Promise<T>;
8
- /**
9
- * Listens the singleton entity continuesly.
10
- * The subscribe function should return the subscription made to the entity, becaues it needs to be destroyed each time entity gets destroyed.
11
- * Use ActionSubscription.combine([...]) if there are more than one subscription.
12
- */
13
- static continuesSubscription<T extends SingletonEntity>(this: new (...args: any[]) => T, subscribeFunction: (entity: T) => ActionSubscription): ActionSubscription;
14
5
  constructor();
15
6
  }
@@ -1,67 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SingletonEntity = void 0;
4
- const actions_lib_1 = require("actions-lib");
5
4
  const entity_1 = require("./entity");
6
5
  const entity_store_helper_1 = require("./helpers/entity-store.helper");
7
6
  class SingletonEntity extends entity_1.Entity {
8
- static { this.onSingletonCreated = new actions_lib_1.Action(); }
9
7
  static getInstance() {
10
8
  return entity_store_helper_1.EntityStoreHelper.getSingleton(this);
11
9
  }
12
10
  static getInstanceOrFail() {
13
11
  return entity_store_helper_1.EntityStoreHelper.getSingletonOrFail(this);
14
12
  }
15
- static async getInstanceAsync() {
16
- let entity = entity_store_helper_1.EntityStoreHelper.getSingleton(this);
17
- if (entity && !entity.destroyed) {
18
- return entity;
19
- }
20
- else {
21
- return new Promise(resolve => {
22
- let subscription = SingletonEntity.onSingletonCreated
23
- .subscribe(createdEntity => {
24
- if (createdEntity instanceof this) {
25
- subscription.unsubscribe();
26
- resolve(createdEntity);
27
- }
28
- })
29
- .attachToRoot();
30
- });
31
- }
32
- }
33
- /**
34
- * Listens the singleton entity continuesly.
35
- * The subscribe function should return the subscription made to the entity, becaues it needs to be destroyed each time entity gets destroyed.
36
- * Use ActionSubscription.combine([...]) if there are more than one subscription.
37
- */
38
- static continuesSubscription(subscribeFunction) {
39
- let unsubscribed = false;
40
- let subscription;
41
- let onDestroySubscription;
42
- let subscribe = () => {
43
- this.getSingletonAsync().then((entity) => {
44
- if (!unsubscribed) {
45
- subscription = subscribeFunction(entity);
46
- onDestroySubscription = entity.onDestroy
47
- .subscribe(() => {
48
- if (!unsubscribed) {
49
- subscription?.unsubscribe();
50
- onDestroySubscription?.unsubscribe();
51
- subscribe();
52
- }
53
- })
54
- .attachToRoot();
55
- }
56
- });
57
- };
58
- subscribe();
59
- return new actions_lib_1.ActionSubscription(() => {
60
- unsubscribed = true;
61
- subscription?.unsubscribe();
62
- onDestroySubscription?.unsubscribe();
63
- }).decorateActionSubscription();
64
- }
65
13
  constructor() {
66
14
  super();
67
15
  let entities = this.constructor.getEntities();
@@ -69,9 +17,6 @@ class SingletonEntity extends entity_1.Entity {
69
17
  this.attachToRoot();
70
18
  throw new Error(`SingletonEntity: entity is decorated as singleton but multiple instances are created! Name: "${this.constructor.name}"`);
71
19
  }
72
- else {
73
- SingletonEntity.onSingletonCreated.trigger(this);
74
- }
75
20
  }
76
21
  }
77
22
  exports.SingletonEntity = SingletonEntity;
@@ -41,11 +41,14 @@ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
41
41
  (0, vitest_1.beforeEach)(() => {
42
42
  update_cycle_1.UpdateCycle.hardResetAction.trigger();
43
43
  let SampleScene = class SampleScene extends scene_1.Scene {
44
+ async init() { }
45
+ update() { }
46
+ async prepareToClose() { }
44
47
  };
45
48
  SampleScene = __decorate([
46
49
  (0, scene_1.SceneDecorator)()
47
50
  ], SampleScene);
48
- SampleScene.open(undefined);
51
+ SampleScene.open();
49
52
  });
50
53
  (0, vitest_1.test)('select singleton sample', () => {
51
54
  let Sample = class Sample extends singleton_entity_1.SingletonEntity {
@@ -1,5 +1,5 @@
1
1
  export { Attachable } from './base/attachable';
2
- export { Destroyable } from './base/destroyable';
2
+ export { AttachmentTarget } from './base/attachment-target';
3
3
  export { ActionsLibDecorator } from './base/helpers/decorate-actions-lib';
4
4
  export { ReferanceVariable } from './base/helpers/referance-variable';
5
5
  export * from './base/interfaces';
@@ -14,11 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  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.Destroyable = exports.Attachable = void 0;
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;
18
18
  var attachable_1 = require("./base/attachable");
19
19
  Object.defineProperty(exports, "Attachable", { enumerable: true, get: function () { return attachable_1.Attachable; } });
20
- var destroyable_1 = require("./base/destroyable");
21
- Object.defineProperty(exports, "Destroyable", { enumerable: true, get: function () { return destroyable_1.Destroyable; } });
20
+ var attachment_target_1 = require("./base/attachment-target");
21
+ Object.defineProperty(exports, "AttachmentTarget", { enumerable: true, get: function () { return attachment_target_1.AttachmentTarget; } });
22
22
  var decorate_actions_lib_1 = require("./base/helpers/decorate-actions-lib");
23
23
  Object.defineProperty(exports, "ActionsLibDecorator", { enumerable: true, get: function () { return decorate_actions_lib_1.ActionsLibDecorator; } });
24
24
  var referance_variable_1 = require("./base/helpers/referance-variable");
@@ -1,20 +1,27 @@
1
1
  import { Variable } from 'actions-lib';
2
- import { Attachable } from '../base/attachable';
3
- export type SceneClassType = new (...services: any[]) => Scene<any>;
2
+ import { AttachmentTarget } from '../base/attachment-target';
3
+ export type SceneClassType = new (...services: unknown[]) => Scene<unknown, unknown>;
4
+ type SceneInput<T> = T extends Scene<infer I, any> ? I : never;
5
+ type SceneOutput<T> = T extends Scene<any, infer O> ? O : never;
4
6
  export declare function SceneDecorator(): (SceneClass: SceneClassType) => any;
5
- export declare abstract class Scene<InputType> extends Attachable {
6
- private static sceneInstance?;
7
+ export declare abstract class Scene<InputType, OutputType> extends AttachmentTarget {
7
8
  private static sceneTransitioning;
8
- static activeScene: Variable<Scene<any> | undefined>;
9
- static getActiveSceneOrFail(): Scene<any>;
10
- static isActive<T extends Scene<any>>(this: new (...args: any[]) => T): boolean;
11
- static getInstance<T extends Scene<any>>(this: new (...args: any[]) => T): T | undefined;
12
- static getInstanceOrFail<T extends Scene<any>>(this: new (...args: any[]) => T): T;
13
- static open<InputType>(this: new (...args: any[]) => Scene<InputType>, input: InputType): Promise<void>;
14
- static close(): Promise<void>;
9
+ static activeScene: Variable<Scene<unknown, unknown> | undefined>;
10
+ static getActiveScene(this: typeof Scene): Scene<unknown, unknown> | undefined;
11
+ static getActiveSceneOrFail(this: typeof Scene): Scene<unknown, unknown>;
12
+ static isActive<T extends Scene<unknown, unknown>>(this: new (...args: unknown[]) => T): boolean;
13
+ static getInstance<T extends Scene<unknown, unknown>>(this: new (...args: unknown[]) => T): T | undefined;
14
+ static getInstanceOrFail<T extends Scene<unknown, unknown>>(this: new (...args: unknown[]) => T): T;
15
+ static open<T extends Scene<any, any>>(this: new (...args: unknown[]) => T, ...args: T extends Scene<void, any> ? [] : [SceneInput<T>]): {
16
+ readonly onOpen: Promise<void>;
17
+ readonly onClose: Promise<SceneOutput<T>>;
18
+ };
19
+ private closePromise;
20
+ private resolveClosePromise;
15
21
  constructor();
16
- protected destroySelf(): void;
17
- protected init(input: InputType): Promise<void>;
18
- protected update(time: number, delta: number): void;
19
- protected prepareToClose(): Promise<void>;
22
+ close(...args: OutputType extends void ? [] : [OutputType]): Promise<void>;
23
+ protected abstract init(input: InputType): Promise<void>;
24
+ protected abstract update(time: number, delta: number): void;
25
+ protected abstract prepareToClose(): Promise<void>;
20
26
  }
27
+ export {};
@@ -2,71 +2,77 @@
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 attachable_1 = require("../base/attachable");
5
+ const attachment_target_1 = require("../base/attachment-target");
6
6
  const service_1 = require("../service/service");
7
7
  const update_cycle_1 = require("../update-cycle");
8
8
  function SceneDecorator() {
9
9
  return function (SceneClass) {
10
10
  SceneClass.$meta = {
11
- paramtypes: service_1.Service.getParametersMeta(SceneClass),
11
+ paramtypes: service_1.Service['getParametersMeta'](SceneClass),
12
12
  type: 'scene'
13
13
  };
14
14
  return SceneClass;
15
15
  };
16
16
  }
17
17
  exports.SceneDecorator = SceneDecorator;
18
- class Scene extends attachable_1.Attachable {
18
+ class Scene extends attachment_target_1.AttachmentTarget {
19
19
  static { this.sceneTransitioning = false; }
20
20
  static { this.activeScene = new actions_lib_1.Variable(); }
21
+ static getActiveScene() {
22
+ return Scene.activeScene.value;
23
+ }
21
24
  static getActiveSceneOrFail() {
22
- if (!Scene.sceneInstance) {
25
+ if (!Scene.activeScene.value) {
23
26
  throw new Error(`Scene: getActiveSceneOrFail is called when there is no active scene!`);
24
27
  }
25
- return Scene.sceneInstance;
28
+ return Scene.activeScene.value;
26
29
  }
27
30
  static isActive() {
28
- return Scene.sceneInstance instanceof this;
31
+ return Scene.activeScene.value instanceof this;
29
32
  }
30
33
  static getInstance() {
31
- return Scene.sceneInstance instanceof this ? Scene.sceneInstance : undefined;
34
+ return Scene.activeScene.value instanceof this ? Scene.activeScene.value : undefined;
32
35
  }
33
36
  static getInstanceOrFail() {
34
- if (!Scene.sceneInstance) {
37
+ if (!Scene.activeScene.value) {
35
38
  throw new Error(`Scene: getInstance is called when there is no active scene!`);
36
39
  }
37
- if (!(Scene.sceneInstance instanceof this)) {
38
- throw new Error(`Scene: getInstance is called while "${this.name}" was not the active scene. Current scene is: "${Scene.sceneInstance.constructor.name}"!`);
40
+ if (!(Scene.activeScene.value instanceof this)) {
41
+ throw new Error(`Scene: getInstance is called while "${this.name}" was not the active scene. Current scene is: "${Scene.activeScene.value.constructor.name}"!`);
39
42
  }
40
- return Scene.sceneInstance;
43
+ return Scene.activeScene.value;
41
44
  }
42
- static async open(input) {
43
- if (!Scene.sceneTransitioning) {
44
- Scene.sceneTransitioning = true;
45
- if (Scene.sceneInstance) {
46
- await Scene.sceneInstance.prepareToClose();
47
- Scene.sceneInstance.destroy();
48
- Scene.sceneInstance = undefined;
49
- Scene.activeScene.set(undefined);
50
- }
51
- let resolvedArgs = service_1.Service.resolveParameters([], this.$meta.paramtypes);
52
- let scene = new this(...resolvedArgs);
53
- Scene.sceneInstance = scene;
54
- Scene.activeScene.set(scene);
55
- await scene.init(input);
56
- Scene.sceneTransitioning = false;
45
+ static open(...args) {
46
+ if (Scene.sceneTransitioning) {
47
+ throw new Error('Scene: you cannot open a scene while a scene is transitioning!');
57
48
  }
58
- }
59
- static async close() {
60
- if (Scene.sceneInstance) {
61
- await Scene.sceneInstance.prepareToClose();
62
- Scene.sceneInstance.destroy();
63
- Scene.sceneInstance = undefined;
64
- Scene.activeScene.set(undefined);
49
+ else if (Scene.activeScene.value) {
50
+ throw new Error('Scene: you cannot open a scene while there is already another active scene!');
65
51
  }
52
+ let input = args[0];
53
+ let onOpenResolve;
54
+ let onCloseResolve;
55
+ let onOpen = new Promise((resolve, reject) => {
56
+ onOpenResolve = resolve;
57
+ });
58
+ let onClose = new Promise((resolve, reject) => {
59
+ onCloseResolve = resolve;
60
+ });
61
+ Scene.sceneTransitioning = true;
62
+ let resolvedArgs = service_1.Service['resolveParameters']([], this.$meta.paramtypes);
63
+ let scene = new this(...resolvedArgs).attachToRoot();
64
+ Scene.activeScene.set(scene);
65
+ scene.init(input).then(() => {
66
+ Scene.sceneTransitioning = false;
67
+ onOpenResolve();
68
+ });
69
+ scene.closePromise.then(output => {
70
+ onCloseResolve(output);
71
+ });
72
+ return { onOpen, onClose };
66
73
  }
67
74
  constructor() {
68
75
  super();
69
- this.attachToRoot(); // Scene is always attached to itself
70
76
  update_cycle_1.UpdateCycle.sceneUpdateAction
71
77
  .subscribe(updateData => {
72
78
  if (!this.destroyed) {
@@ -74,16 +80,26 @@ class Scene extends attachable_1.Attachable {
74
80
  }
75
81
  })
76
82
  .attach(this);
83
+ this.closePromise = new Promise(resolve => (this.resolveClosePromise = resolve));
77
84
  }
78
- destroySelf() {
79
- super.destroySelf();
85
+ async close(...args) {
86
+ if (Scene.sceneTransitioning) {
87
+ throw new Error('Scene: you cannot close a scene while a scene is transitioning!');
88
+ }
89
+ else if (Scene.activeScene.value !== this) {
90
+ throw new Error('Internal Error: Scene instance is accessed while it is not the active scene!');
91
+ }
92
+ let output = args[0];
93
+ Scene.sceneTransitioning = true;
94
+ await this.prepareToClose();
95
+ super.destroy();
96
+ Scene.activeScene.set(undefined);
97
+ this.resolveClosePromise(output);
98
+ Scene.sceneTransitioning = false;
80
99
  }
81
- async init(input) { }
82
- update(time, delta) { }
83
- async prepareToClose() { }
84
100
  }
85
101
  exports.Scene = Scene;
86
102
  update_cycle_1.UpdateCycle.hardResetAction.subscribe(() => {
87
- Scene['sceneInstance'] = undefined;
103
+ Scene.activeScene.set(undefined);
88
104
  });
89
105
  //# sourceMappingURL=scene.js.map