bard-legends-framework 0.10.1 → 0.10.3

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 (38) hide show
  1. package/dist/game-entities/base/destroyable.d.ts +1 -1
  2. package/dist/game-entities/base/destroyable.js +1 -1
  3. package/dist/game-entities/base/helpers/decorate-actions-lib.d.ts +2 -2
  4. package/dist/game-entities/base/helpers/decorate-actions-lib.js +3 -3
  5. package/dist/game-entities/entity/entity.d.ts +2 -9
  6. package/dist/game-entities/entity/entity.js +13 -21
  7. package/dist/game-entities/entity/helpers/entity-views.helper.d.ts +1 -0
  8. package/dist/game-entities/entity/helpers/entity-views.helper.js +8 -11
  9. package/dist/game-entities/entity/singleton-entity.js +3 -3
  10. package/dist/game-entities/scene/scene.d.ts +0 -4
  11. package/dist/game-entities/scene/scene.js +2 -19
  12. package/dist/game-entities/update-cycle.js +1 -1
  13. package/dist/game-entities/view/view.d.ts +3 -8
  14. package/dist/game-entities/view/view.js +18 -57
  15. package/dist/game-entities/view/view.test.js +50 -109
  16. package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +6 -6
  17. package/dist/pixi/components/helpers/smooth-scroller.test.js +5 -5
  18. package/dist/pixi/display-object/objects/graphics/graphics.js +1 -1
  19. package/dist/pixi/game.js +1 -2
  20. package/dist/pixi/modules/CAMERA/camera.d.ts +0 -1
  21. package/dist/pixi/modules/CAMERA/camera.js +1 -4
  22. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/camera-view.gateway.d.ts +1 -1
  23. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/camera-view.gateway.js +1 -1
  24. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/controllers/camera-view.controller.d.ts +1 -1
  25. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/controllers/camera-view.controller.js +3 -3
  26. package/dist/pixi/modules/CAMERA//360/237/223/220services/camera.service.js +2 -1
  27. package/dist/pixi/modules/CAMERA//360/237/247/212entities/camera.entity.js +1 -1
  28. package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.d.ts +0 -1
  29. package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.js +0 -2
  30. package/dist/pixi/services/keyboard/keyboard.js +1 -1
  31. package/dist/pixi/services/mouse/mouse-target-focus.service.js +1 -1
  32. package/dist/pixi/services/mouse/mouse.service.js +2 -2
  33. package/dist/utilities/libraries/animator/animator.js +9 -9
  34. package/dist/utilities/libraries/animator/animator.test.js +66 -66
  35. package/dist/utilities/libraries/animator/state-animation/slide-state-animation.test.js +1 -1
  36. package/dist/utilities/libraries/animator/state-animation/state-animation.test.js +3 -3
  37. package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.test.js +1 -1
  38. package/package.json +1 -1
@@ -12,6 +12,6 @@ export declare abstract class Destroyable {
12
12
  protected afterDestroy(): void;
13
13
  protected destroySelf(): void;
14
14
  attach(parent: IAttachable | string): this;
15
- skipAttachCheck(): this;
15
+ attachToRoot(): this;
16
16
  protected destroyAttachment(object: CanBeAttached): void;
17
17
  }
@@ -50,7 +50,7 @@ class Destroyable {
50
50
  }
51
51
  return this;
52
52
  }
53
- skipAttachCheck() {
53
+ attachToRoot() {
54
54
  if (this._attachIsCalled) {
55
55
  throw new Error(`Destroyable: The object is already attached to something!`);
56
56
  }
@@ -2,12 +2,12 @@ import { Attachable } from '../attachable';
2
2
  declare module 'actions-lib' {
3
3
  interface ActionSubscription {
4
4
  attach(parent: Attachable | string): ActionSubscription;
5
- skipAttachCheck(): ActionSubscription;
5
+ attachToRoot(): ActionSubscription;
6
6
  decorateActionSubscription(): ActionSubscription;
7
7
  }
8
8
  interface ReducerEffectChannel<EffectType, ResponseType> {
9
9
  attach(parent: Attachable | string): ReducerEffectChannel<EffectType, ResponseType>;
10
- skipAttachCheck(): ReducerEffectChannel<EffectType, ResponseType>;
10
+ attachToRoot(): ReducerEffectChannel<EffectType, ResponseType>;
11
11
  decorateEffectChannel(): ReducerEffectChannel<EffectType, ResponseType>;
12
12
  }
13
13
  }
@@ -43,7 +43,7 @@ class ActionsLibDecorator {
43
43
  this.$meta = { attachIsCalled: true, attachedParent: parentEntity };
44
44
  return this;
45
45
  };
46
- actionsLib.ActionSubscription.prototype.skipAttachCheck = function () {
46
+ actionsLib.ActionSubscription.prototype.attachToRoot = function () {
47
47
  this.$meta = { attachIsCalled: true };
48
48
  return this;
49
49
  };
@@ -57,7 +57,7 @@ class ActionsLibDecorator {
57
57
  };
58
58
  let originalCombine = actionsLib.ActionSubscription.combine;
59
59
  actionsLib.ActionSubscription.combine = function (subscriptions) {
60
- subscriptions.forEach(subscription => subscription.skipAttachCheck());
60
+ subscriptions.forEach(subscription => subscription.attachToRoot());
61
61
  return originalCombine(subscriptions);
62
62
  };
63
63
  actionsLib.ReducerEffectChannel.prototype.attach = function (parent) {
@@ -66,7 +66,7 @@ class ActionsLibDecorator {
66
66
  this.$meta = { attachIsCalled: true, attachedParent: parentEntity };
67
67
  return this;
68
68
  };
69
- actionsLib.ReducerEffectChannel.prototype.skipAttachCheck = function () {
69
+ actionsLib.ReducerEffectChannel.prototype.attachToRoot = function () {
70
70
  this.$meta = { attachIsCalled: true };
71
71
  return this;
72
72
  };
@@ -1,12 +1,6 @@
1
1
  import { Attachable } from '../base/attachable';
2
2
  export type EntityClassType = new (...args: any[]) => Entity;
3
- /**
4
- * @param destroyOnSceneClose - Default: true. If true, the entity will be destroyed when the scene is closed.
5
- */
6
- export interface EntityDecoratorMeta {
7
- destroyOnSceneClose: boolean;
8
- }
9
- export declare function EntityDecorator(meta?: EntityDecoratorMeta): (EntityClass: EntityClassType) => any;
3
+ export declare function EntityDecorator(): (EntityClass: EntityClassType) => any;
10
4
  export declare abstract class Entity extends Attachable {
11
5
  static getInstanceById<T extends Entity>(this: new (...args: any[]) => T, entityId: string | undefined): T | undefined;
12
6
  static getInstanceByIdOrFail<T extends Entity>(this: new (...args: any[]) => T, entityId: string): T;
@@ -15,7 +9,6 @@ export declare abstract class Entity extends Attachable {
15
9
  constructor();
16
10
  protected destroySelf(): void;
17
11
  attach(parent: Attachable | string): this;
18
- skipAttachCheck(): this;
12
+ attachToRoot(): this;
19
13
  update(time: number, delta: number): void;
20
- private updateTick;
21
14
  }
@@ -2,14 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Entity = exports.EntityDecorator = void 0;
4
4
  const attachable_1 = require("../base/attachable");
5
- const scene_1 = require("../scene/scene");
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");
8
- function EntityDecorator(meta) {
8
+ function EntityDecorator() {
9
9
  return function (EntityClass) {
10
10
  EntityClass.$meta = {
11
- type: 'entity',
12
- destroyOnSceneClose: meta?.destroyOnSceneClose ?? true
11
+ type: 'entity'
13
12
  };
14
13
  entity_store_helper_1.EntityStoreHelper.registerEntityClass(EntityClass);
15
14
  };
@@ -34,19 +33,19 @@ class Entity extends attachable_1.Attachable {
34
33
  constructor() {
35
34
  super();
36
35
  this.viewCreationHelper = new entity_views_helper_1.EntityViewsHelper(this);
37
- let destroyOnSceneClose = this.constructor.$meta.destroyOnSceneClose;
38
- if (destroyOnSceneClose) {
39
- scene_1.Scene['registerEntity'](this);
40
- }
41
36
  entity_store_helper_1.EntityStoreHelper.registerEntity(this);
37
+ update_cycle_1.UpdateCycle.sceneUpdateAction
38
+ .subscribe(updateData => {
39
+ if (!this.destroyed) {
40
+ this.update(updateData.time, updateData.delta);
41
+ this.viewCreationHelper.updateViews(updateData.time, updateData.delta);
42
+ }
43
+ })
44
+ .attach(this);
42
45
  }
43
46
  destroySelf() {
44
47
  super.destroySelf();
45
48
  this.viewCreationHelper.destroyViews();
46
- let destroyOnSceneClose = this.constructor.$meta.destroyOnSceneClose;
47
- if (destroyOnSceneClose) {
48
- scene_1.Scene['unregisterEntity'](this);
49
- }
50
49
  entity_store_helper_1.EntityStoreHelper.unregisterEntity(this.constructor.name, this.id);
51
50
  }
52
51
  attach(parent) {
@@ -54,19 +53,12 @@ class Entity extends attachable_1.Attachable {
54
53
  this.viewCreationHelper.createViews();
55
54
  return this;
56
55
  }
57
- skipAttachCheck() {
58
- super.skipAttachCheck();
56
+ attachToRoot() {
57
+ super.attachToRoot();
59
58
  this.viewCreationHelper.createViews();
60
59
  return this;
61
60
  }
62
61
  update(time, delta) { }
63
- // Triggered by Scene
64
- updateTick(time, delta) {
65
- if (!this.destroyed) {
66
- this.update(time, delta);
67
- this.viewCreationHelper.updateViews(time, delta);
68
- }
69
- }
70
62
  }
71
63
  exports.Entity = Entity;
72
64
  //# sourceMappingURL=entity.js.map
@@ -3,6 +3,7 @@ import { Entity, EntityClassType } from '../entity';
3
3
  export declare class EntityViewsHelper {
4
4
  private entity;
5
5
  private static viewRegistries;
6
+ static currentEntityId: string;
6
7
  static registerView<T>(ViewClass: ViewClassType<T>, EntityClass: EntityClassType): void;
7
8
  private static createView;
8
9
  private views;
@@ -18,19 +18,17 @@ class EntityViewsHelper {
18
18
  });
19
19
  }
20
20
  static createView(entity, ViewClass) {
21
- let timeout = setTimeout(() => {
22
- console.warn(`View - createView: view init is taking too long! entity: "${ViewClass.name}"`);
23
- }, 1000);
24
21
  try {
25
22
  let resolvedViewArgs = service_1.Service.resolveParameters([this], ViewClass.$meta.paramtypes);
23
+ EntityViewsHelper.currentEntityId = entity.id;
26
24
  let view = new ViewClass(entity, ...resolvedViewArgs.slice(1));
27
- view['_entityId'] = entity.id;
28
- view['_entityIsDestroyed'] = false;
29
- view['init']().then(() => {
30
- clearTimeout(timeout);
31
- view['afterInit']();
32
- });
33
- entity['viewCreationHelper'].views.push(view);
25
+ if (entity.destroyed) {
26
+ // Created view might destroy its entity in constructor, which should also destroy the view
27
+ view.destroy();
28
+ }
29
+ else {
30
+ entity['viewCreationHelper'].views.push(view);
31
+ }
34
32
  }
35
33
  catch (e) {
36
34
  console.error(e);
@@ -57,7 +55,6 @@ class EntityViewsHelper {
57
55
  }
58
56
  destroyViews() {
59
57
  this.views.forEach(view => {
60
- view['_entityIsDestroyed'] = true;
61
58
  view.destroy();
62
59
  });
63
60
  }
@@ -26,7 +26,7 @@ class SingletonEntity extends entity_1.Entity {
26
26
  resolve(createdEntity);
27
27
  }
28
28
  })
29
- .skipAttachCheck();
29
+ .attachToRoot();
30
30
  });
31
31
  }
32
32
  }
@@ -51,7 +51,7 @@ class SingletonEntity extends entity_1.Entity {
51
51
  subscribe();
52
52
  }
53
53
  })
54
- .skipAttachCheck();
54
+ .attachToRoot();
55
55
  }
56
56
  });
57
57
  };
@@ -66,7 +66,7 @@ class SingletonEntity extends entity_1.Entity {
66
66
  super();
67
67
  let entities = this.constructor.getEntities();
68
68
  if (entities.length > 1) {
69
- this.skipAttachCheck();
69
+ this.attachToRoot();
70
70
  throw new Error(`SingletonEntity: entity is decorated as singleton but multiple instances are created! Name: "${this.constructor.name}"`);
71
71
  }
72
72
  else {
@@ -9,12 +9,8 @@ export declare abstract class Scene<InputType> extends Attachable {
9
9
  static isActive<T extends Scene<any>>(this: new (...args: any[]) => T): boolean;
10
10
  static getInstance<T extends Scene<any>>(this: new (...args: any[]) => T): T | undefined;
11
11
  static getInstanceOrFail<T extends Scene<any>>(this: new (...args: any[]) => T): T;
12
- private static registerEntity;
13
- private static unregisterEntity;
14
12
  static open<InputType>(this: new (...args: any[]) => Scene<InputType>, input: InputType): Promise<void>;
15
13
  static close(): Promise<void>;
16
- private entities;
17
- private updateSubscription;
18
14
  constructor();
19
15
  protected destroySelf(): void;
20
16
  protected init(input: InputType): Promise<void>;
@@ -40,18 +40,6 @@ class Scene extends attachable_1.Attachable {
40
40
  }
41
41
  return Scene.sceneInstance;
42
42
  }
43
- static registerEntity(entity) {
44
- if (!Scene.activeScene) {
45
- throw new Error(`Scene: registerEntity is called when there is no active scene!`);
46
- }
47
- Scene.activeScene.entities.add(entity);
48
- }
49
- static unregisterEntity(entity) {
50
- if (!Scene.activeScene) {
51
- throw new Error(`Scene: unregisterEntity is called when there is no active scene!`);
52
- }
53
- Scene.activeScene.entities.delete(entity);
54
- }
55
43
  static async open(input) {
56
44
  if (!Scene.sceneTransitioning) {
57
45
  Scene.sceneTransitioning = true;
@@ -76,22 +64,17 @@ class Scene extends attachable_1.Attachable {
76
64
  }
77
65
  constructor() {
78
66
  super();
79
- this.entities = new Set();
80
- this.skipAttachCheck(); // Scene is always attached to itself
81
- this.updateSubscription = update_cycle_1.UpdateCycle.sceneUpdateAction
67
+ this.attachToRoot(); // Scene is always attached to itself
68
+ update_cycle_1.UpdateCycle.sceneUpdateAction
82
69
  .subscribe(updateData => {
83
70
  if (!this.destroyed) {
84
71
  this.update(updateData.time, updateData.delta);
85
- this.entities.forEach(entity => entity['updateTick'](updateData.time, updateData.delta));
86
72
  }
87
73
  })
88
74
  .attach(this);
89
75
  }
90
76
  destroySelf() {
91
77
  super.destroySelf();
92
- this.updateSubscription.unsubscribe();
93
- this.entities.forEach(entity => entity.destroy());
94
- this.entities = new Set();
95
78
  }
96
79
  async init(input) { }
97
80
  update(time, delta) { }
@@ -18,7 +18,7 @@ class UpdateCycle {
18
18
  resolve();
19
19
  }
20
20
  })
21
- .skipAttachCheck();
21
+ .attachToRoot();
22
22
  });
23
23
  }
24
24
  static registerUpdateModifier(callback) {
@@ -7,17 +7,12 @@ export interface ViewDecoratorMeta<EntityType> {
7
7
  export declare function ViewDecorator<EntityType extends Entity>(meta: ViewDecoratorMeta<EntityType>): (ViewClass: ViewClassType<EntityType>) => any;
8
8
  export declare abstract class View extends Attachable {
9
9
  private static viewClassNames;
10
- static getInstanceSync<T extends View>(this: new (...args: any[]) => T, entityId: string): T | undefined;
11
- static getInstance<T extends View>(this: new (...args: any[]) => T, entityId: string): Promise<T | undefined>;
12
- static getInstanceOrFail<T extends View>(this: new (...args: any[]) => T, entityId: string): Promise<T>;
10
+ static getInstance<T extends View>(this: new (...args: any[]) => T, entityId: string): T | undefined;
11
+ static getInstanceOrFail<T extends View>(this: new (...args: any[]) => T, entityId: string): T;
13
12
  protected childUpdate: (time: number, delta: number) => void;
14
- private created;
15
- private viewsCreated;
16
13
  private _entityId;
17
- private _entityIsDestroyed;
18
14
  constructor();
19
15
  protected destroySelf(): void;
20
- protected init(): Promise<void>;
21
16
  update(time: number, delta: number): void;
22
- protected afterInit(): void;
17
+ private getViewInstances;
23
18
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.View = exports.ViewDecorator = void 0;
4
- const actions_lib_1 = require("actions-lib");
5
4
  const attachable_1 = require("../base/attachable");
6
5
  const entity_views_helper_1 = require("../entity/helpers/entity-views.helper");
7
6
  const service_1 = require("../service/service");
@@ -16,7 +15,7 @@ function ViewDecorator(meta) {
16
15
  }
17
16
  ViewClass.$meta = {
18
17
  paramtypes: service_1.Service.getParametersMeta(ViewClass),
19
- viewsCreated: new actions_lib_1.ObservableMap(),
18
+ viewInstances: new Map(),
20
19
  entityName: meta.entity.name,
21
20
  type: 'view'
22
21
  };
@@ -26,81 +25,43 @@ function ViewDecorator(meta) {
26
25
  exports.ViewDecorator = ViewDecorator;
27
26
  class View extends attachable_1.Attachable {
28
27
  static { this.viewClassNames = new Set(); }
29
- static getInstanceSync(entityId) {
28
+ static getInstance(entityId) {
30
29
  if (entityId.substring(0, entityId.indexOf(':')) !== this.$meta.entityName) {
31
30
  return undefined;
32
31
  }
33
- let observableMap = this.$meta.viewsCreated;
34
- return observableMap.get(entityId);
32
+ let viewInstances = this.$meta.viewInstances;
33
+ return viewInstances.get(entityId);
35
34
  }
36
- static async getInstance(entityId) {
37
- return new Promise(resolve => {
38
- let timeout = setTimeout(() => {
39
- resolve(undefined);
40
- }, 1000);
41
- if (entityId.substring(0, entityId.indexOf(':')) !== this.$meta.entityName) {
42
- clearTimeout(timeout);
43
- resolve(undefined);
44
- }
45
- let observableMap = this.$meta.viewsCreated;
46
- observableMap.waitUntilAddedSync(entityId, response => {
47
- clearTimeout(timeout);
48
- if (response._entityIsDestroyed) {
49
- resolve(undefined);
50
- }
51
- else {
52
- resolve(response);
53
- }
54
- });
55
- });
56
- }
57
- static async getInstanceOrFail(entityId) {
58
- let timeout = setTimeout(() => {
59
- console.warn(`View: getInstance is taking too long! View: ${View.name}, entityId: "${entityId}"`);
60
- }, 1000);
35
+ static getInstanceOrFail(entityId) {
61
36
  if (entityId.substring(0, entityId.indexOf(':')) !== this.$meta.entityName) {
62
- clearTimeout(timeout);
63
37
  throw new Error(`View: getInstance is called with entity id: "${entityId}", that is not belonging to the class: "${this.$meta.entityName}"`);
64
38
  }
65
- return new Promise((resolve, reject) => {
66
- let observableMap = this.$meta.viewsCreated;
67
- observableMap.waitUntilAddedSync(entityId, response => {
68
- clearTimeout(timeout);
69
- if (response._entityIsDestroyed) {
70
- reject(new Error(`View: getInstanceOrFail is called with destroyed entity id: "${entityId}". Consider using getInstance instead.`));
71
- }
72
- else {
73
- resolve(response);
74
- }
75
- });
76
- });
39
+ let viewInstances = this.$meta.viewInstances;
40
+ let view = viewInstances.get(entityId);
41
+ if (!view) {
42
+ throw new Error(`View: getInstanceOrFail is called with entity id: "${entityId}", that is not found!`);
43
+ }
44
+ return view;
77
45
  }
78
46
  constructor() {
79
47
  super();
80
48
  this.childUpdate = this.update.bind(this);
81
- this.created = false;
82
- this.skipAttachCheck(); // View is always attached to its entity
83
- this.viewsCreated = this.constructor.$meta.viewsCreated;
49
+ this.attachToRoot(); // View is always attached to its entity
50
+ this._entityId = entity_views_helper_1.EntityViewsHelper.currentEntityId;
51
+ this.getViewInstances().set(this._entityId, this);
84
52
  this.update = function (time, delta) {
85
- if (!this.destroyed && this.created) {
53
+ if (!this.destroyed) {
86
54
  this.childUpdate(time, delta);
87
55
  }
88
56
  };
89
57
  }
90
58
  destroySelf() {
91
59
  super.destroySelf();
92
- this.viewsCreated.remove(this._entityId);
60
+ this.getViewInstances().delete(this._entityId);
93
61
  }
94
- async init() { }
95
62
  update(time, delta) { }
96
- // Called by view-creation.helper.ts
97
- afterInit() {
98
- this.created = true;
99
- let observableMap = this.constructor.$meta.viewsCreated;
100
- observableMap.set(this._entityId, this);
101
- if (this.destroyed) {
102
- this.viewsCreated.remove(this._entityId);
103
- }
63
+ getViewInstances() {
64
+ return this.constructor.$meta.viewInstances;
104
65
  }
105
66
  }
106
67
  exports.View = View;