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,10 @@
1
+ import { IAttachmentTarget } from './attachment-target';
2
+ import { Destroyable } from './destroyable';
3
+ export declare class AttachableBehavior extends Destroyable {
4
+ private _attachIsCalled;
5
+ private _attachedTarget;
6
+ constructor();
7
+ destroy(): void;
8
+ attach(parent: IAttachmentTarget | string): this;
9
+ attachToRoot(): this;
10
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachableBehavior = void 0;
4
+ const attachable_store_1 = require("./attachable.store");
5
+ const destroyable_1 = require("./destroyable");
6
+ class AttachableBehavior extends destroyable_1.Destroyable {
7
+ constructor() {
8
+ super();
9
+ this._attachIsCalled = false;
10
+ setTimeout(() => {
11
+ if (!this.destroyed && !this._attachIsCalled) {
12
+ throw new Error(`AttachableBehavior: The object is not attached to anything!`);
13
+ }
14
+ });
15
+ }
16
+ destroy() {
17
+ if (!this.destroyed) {
18
+ this._attachedTarget?.attachmentTargetBehavior.removeAttachment(this);
19
+ this._attachedTarget = undefined;
20
+ super.destroy();
21
+ }
22
+ }
23
+ attach(parent) {
24
+ if (this._attachIsCalled) {
25
+ throw new Error(`AttachableBehavior: The object is already attached to something!`);
26
+ }
27
+ this._attachIsCalled = true;
28
+ if (!this.destroyed) {
29
+ let target = attachable_store_1.AttachableStore.findAttachmentTarget(parent);
30
+ if (target === this) {
31
+ throw new Error(`Objects cannot be attach to itself! entity: "${this.constructor.name}"`);
32
+ }
33
+ this._attachedTarget = target;
34
+ target.attachmentTargetBehavior.setAttachment(this);
35
+ }
36
+ return this;
37
+ }
38
+ attachToRoot() {
39
+ if (this._attachIsCalled) {
40
+ throw new Error(`AttachableBehavior: The object is already attached to something!`);
41
+ }
42
+ this._attachIsCalled = true;
43
+ return this;
44
+ }
45
+ }
46
+ exports.AttachableBehavior = AttachableBehavior;
47
+ //# sourceMappingURL=attachable.js.map
@@ -0,0 +1,8 @@
1
+ import { IAttachmentTarget } from './attachment-target';
2
+ export declare class AttachableStore {
3
+ private static nextAvailableIds;
4
+ private static attachmentTargets;
5
+ static registerAttachmentTarget(target: IAttachmentTarget): string;
6
+ static unregisterAttachmentTarget(target: IAttachmentTarget): void;
7
+ static findAttachmentTarget(targetCandidate: IAttachmentTarget | string): IAttachmentTarget;
8
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachableStore = void 0;
4
+ const helpers_lib_1 = require("helpers-lib");
5
+ const update_cycle_1 = require("../update-cycle");
6
+ class AttachableStore {
7
+ static { this.nextAvailableIds = new Map(); }
8
+ static { this.attachmentTargets = new Map(); }
9
+ static registerAttachmentTarget(target) {
10
+ let numberPartOfTheId = AttachableStore.nextAvailableIds.get(target.constructor.name) || 1;
11
+ AttachableStore.nextAvailableIds.set(target.constructor.name, numberPartOfTheId + 1);
12
+ let id = `${target.constructor.name}:${numberPartOfTheId}`;
13
+ AttachableStore.attachmentTargets.set(id, target);
14
+ return id;
15
+ }
16
+ static unregisterAttachmentTarget(target) {
17
+ AttachableStore.attachmentTargets.delete(target.attachmentTargetBehavior.id);
18
+ }
19
+ static findAttachmentTarget(targetCandidate) {
20
+ let target;
21
+ if (helpers_lib_1.Comparator.isString(targetCandidate)) {
22
+ if (!this.attachmentTargets.has(targetCandidate)) {
23
+ throw new Error(`Attachable: attachable not found by id! id: ${targetCandidate}`);
24
+ }
25
+ else {
26
+ target = this.attachmentTargets.get(targetCandidate);
27
+ }
28
+ }
29
+ else if (targetCandidate.attachmentTargetBehavior) {
30
+ target = targetCandidate;
31
+ }
32
+ else {
33
+ throw new Error(`Attachable: attachable is not an AttachableBehavior! Attachable: "${targetCandidate}"`);
34
+ }
35
+ return target;
36
+ }
37
+ }
38
+ exports.AttachableStore = AttachableStore;
39
+ update_cycle_1.UpdateCycle.hardResetAction.subscribe(() => {
40
+ AttachableStore['nextAvailableIds'].clear();
41
+ AttachableStore['attachmentTargets'].clear();
42
+ });
43
+ //# sourceMappingURL=attachable.store.js.map
@@ -0,0 +1,16 @@
1
+ import { Destroyable } from './destroyable';
2
+ import { Attachable } from './interfaces';
3
+ export interface IAttachmentTarget {
4
+ readonly attachmentTargetBehavior: AttachmentTargetBehavior;
5
+ }
6
+ export declare class AttachmentTargetBehavior {
7
+ private base;
8
+ private _destroyed;
9
+ private _attachments;
10
+ readonly id: string;
11
+ constructor(base: Destroyable & IAttachmentTarget);
12
+ destroy(): void;
13
+ setAttachment(child: Attachable): void;
14
+ removeAttachment(child: Attachable): void;
15
+ private destroyAttachment;
16
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachmentTargetBehavior = void 0;
4
+ const helpers_lib_1 = require("helpers-lib");
5
+ const attachable_store_1 = require("./attachable.store");
6
+ class AttachmentTargetBehavior {
7
+ constructor(base) {
8
+ this.base = base;
9
+ this._destroyed = false;
10
+ this._attachments = [];
11
+ this.id = '';
12
+ this.id = attachable_store_1.AttachableStore.registerAttachmentTarget(this.base);
13
+ }
14
+ destroy() {
15
+ if (!this._destroyed) {
16
+ attachable_store_1.AttachableStore.unregisterAttachmentTarget(this.base);
17
+ let attachedEntities = [...this._attachments];
18
+ attachedEntities.forEach(item => this.destroyAttachment(item));
19
+ this._attachments = [];
20
+ this._destroyed = true;
21
+ }
22
+ }
23
+ setAttachment(child) {
24
+ if (this._destroyed) {
25
+ this.destroyAttachment(child);
26
+ }
27
+ else {
28
+ this._attachments.push(child);
29
+ }
30
+ }
31
+ removeAttachment(child) {
32
+ let index = this._attachments.indexOf(child);
33
+ if (index >= 0) {
34
+ this._attachments.splice(index, 1);
35
+ }
36
+ }
37
+ destroyAttachment(object) {
38
+ if (helpers_lib_1.Comparator.isObject(object)) {
39
+ let item = object;
40
+ if (helpers_lib_1.Comparator.isFunction(item.destroy)) {
41
+ item.destroy();
42
+ return;
43
+ }
44
+ else if (helpers_lib_1.Comparator.isFunction(item.unsubscribe)) {
45
+ item.unsubscribe();
46
+ return;
47
+ }
48
+ }
49
+ throw new Error(`Destroyable: destroyAttachment is used with not supperted type! Target: "${object}"`);
50
+ }
51
+ }
52
+ exports.AttachmentTargetBehavior = AttachmentTargetBehavior;
53
+ //# sourceMappingURL=attachment-target.js.map
@@ -0,0 +1,3 @@
1
+ export declare class DestroyableBehavior {
2
+ destroy(): void;
3
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DestroyableBehavior = void 0;
4
+ class DestroyableBehavior {
5
+ destroy() {
6
+ throw new Error('Method not implemented.');
7
+ }
8
+ }
9
+ exports.DestroyableBehavior = DestroyableBehavior;
10
+ //# sourceMappingURL=destroyable.js.map
@@ -0,0 +1,3 @@
1
+ export interface IDestroyable {
2
+ destroy(): void;
3
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1,22 @@
1
+ export declare abstract class Destroyable {
2
+ private _destroyed;
3
+ destroy(): void;
4
+ }
5
+ export declare abstract class Attachable {
6
+ private _attached;
7
+ attach(): void;
8
+ }
9
+ type AbstractConstructor<T = object> = abstract new (...args: any[]) => T;
10
+ export declare function AttachmentTarget<BaseType extends AbstractConstructor>(Base: BaseType): (abstract new (...args: any[]) => {
11
+ readonly id: string;
12
+ destroy(): void;
13
+ }) & BaseType;
14
+ export declare function WithDestroyableTarget<BaseType extends AbstractConstructor<Destroyable>>(Base: BaseType): BaseType;
15
+ declare const Foo_base: (abstract new (...args: any[]) => {
16
+ readonly id: string;
17
+ destroy(): void;
18
+ }) & typeof Destroyable;
19
+ export declare class Foo extends Foo_base {
20
+ constructor();
21
+ }
22
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Foo = exports.WithDestroyableTarget = exports.AttachmentTarget = exports.Attachable = exports.Destroyable = void 0;
4
+ class Destroyable {
5
+ constructor() {
6
+ this._destroyed = false;
7
+ }
8
+ destroy() {
9
+ if (!this._destroyed) {
10
+ this._destroyed = true;
11
+ }
12
+ console.log('Destroyable destroy');
13
+ }
14
+ }
15
+ exports.Destroyable = Destroyable;
16
+ class Attachable {
17
+ constructor() {
18
+ this._attached = false;
19
+ }
20
+ attach() {
21
+ if (!this._attached) {
22
+ this._attached = true;
23
+ }
24
+ }
25
+ }
26
+ exports.Attachable = Attachable;
27
+ function AttachmentTarget(Base) {
28
+ class AttachmentTarget extends Base {
29
+ constructor() {
30
+ super(...arguments);
31
+ this.id = '';
32
+ }
33
+ destroy() {
34
+ // some destroy logic
35
+ console.log('AttachmentTarget destroy');
36
+ }
37
+ }
38
+ return AttachmentTarget;
39
+ }
40
+ exports.AttachmentTarget = AttachmentTarget;
41
+ function WithDestroyableTarget(Base) {
42
+ class WithDestroyableTarget extends Base {
43
+ destroy() {
44
+ // I don't want to repeat the "some destroy logic" here
45
+ super.destroy();
46
+ console.log('WithDestroyableTarget destroy');
47
+ }
48
+ }
49
+ return WithDestroyableTarget;
50
+ }
51
+ exports.WithDestroyableTarget = WithDestroyableTarget;
52
+ class Foo extends WithDestroyableTarget(AttachmentTarget(Destroyable)) {
53
+ constructor() {
54
+ super();
55
+ }
56
+ }
57
+ exports.Foo = Foo;
58
+ let foo = new Foo();
59
+ foo.destroy();
60
+ //# sourceMappingURL=mixins.js.map
@@ -1,10 +1,11 @@
1
- import { Destroyable } from './destroyable';
2
- import { CanBeAttached, IAttachable } from './interfaces';
3
- export declare abstract class Attachable extends Destroyable implements IAttachable {
4
- readonly id: string;
5
- private attachments;
1
+ import { Action } from 'actions-lib';
2
+ export declare abstract class Attachable {
3
+ private attachedParent;
4
+ private _attachIsCalled;
5
+ private _destroyed;
6
+ get destroyed(): boolean;
7
+ readonly onDestroy: Action<void>;
6
8
  constructor();
9
+ protected afterDestroy(): void;
7
10
  protected destroySelf(): void;
8
- setAttachment(child: CanBeAttached): void;
9
- removeAttachment(child: CanBeAttached): void;
10
11
  }
@@ -1,35 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Attachable = void 0;
4
- const destroyable_1 = require("./destroyable");
5
- const attachable_store_1 = require("./helpers/attachable.store");
6
- class Attachable extends destroyable_1.Destroyable {
4
+ const actions_lib_1 = require("actions-lib");
5
+ const attachment_target_store_1 = require("./helpers/attachment-target.store");
6
+ class Attachable {
7
+ get destroyed() {
8
+ return this._destroyed;
9
+ }
7
10
  constructor() {
8
- super();
9
- this.id = '';
10
- this.attachments = [];
11
- this.id = attachable_store_1.AttachableStore.registerAttachable(this);
11
+ this._attachIsCalled = false;
12
+ this._destroyed = false;
13
+ this.onDestroy = new actions_lib_1.Action();
14
+ setTimeout(() => {
15
+ if (!this._destroyed && !this._attachIsCalled) {
16
+ throw new Error(`Attachable: The object is not attached to anything!`);
17
+ }
18
+ });
19
+ }
20
+ /** @internal */
21
+ destroy() {
22
+ if (!this._destroyed) {
23
+ // Destroy self is needed to ensure the "afterDestroy" is called after all child destroy functions are called
24
+ this.destroySelf();
25
+ this.afterDestroy();
26
+ this._destroyed = true;
27
+ }
12
28
  }
29
+ afterDestroy() { }
13
30
  destroySelf() {
14
- super.destroySelf();
15
- attachable_store_1.AttachableStore.unregisterAttachable(this);
16
- let attachedEntities = [...this.attachments];
17
- attachedEntities.forEach(item => this.destroyAttachment(item));
18
- this.attachments = [];
31
+ this.onDestroy.trigger();
32
+ this.attachedParent?.removeAttachment(this);
33
+ this.attachedParent = undefined;
19
34
  }
20
- setAttachment(child) {
21
- if (this.destroyed) {
22
- this.destroyAttachment(child);
35
+ /** @internal */
36
+ attach(parent) {
37
+ if (this._attachIsCalled) {
38
+ throw new Error(`Attachable: The object is already attached to something!`);
23
39
  }
24
- else {
25
- this.attachments.push(child);
40
+ this._attachIsCalled = true;
41
+ if (!this._destroyed) {
42
+ let parentEntity = attachment_target_store_1.AttachmentTargetStore.findAttachableParent(parent);
43
+ // @ts-ignore
44
+ if (parentEntity === this) {
45
+ throw new Error(`Entity cannot be attach to itself! entity: "${this.constructor.name}"`);
46
+ }
47
+ this.attachedParent = parentEntity;
48
+ parentEntity.setAttachment(this);
26
49
  }
50
+ return this;
27
51
  }
28
- removeAttachment(child) {
29
- let index = this.attachments.indexOf(child);
30
- if (index >= 0) {
31
- this.attachments.splice(index, 1);
52
+ /** @internal */
53
+ attachToRoot() {
54
+ if (this._attachIsCalled) {
55
+ throw new Error(`Attachable: The object is already attached to something!`);
32
56
  }
57
+ this._attachIsCalled = true;
58
+ return this;
33
59
  }
34
60
  }
35
61
  exports.Attachable = Attachable;
@@ -0,0 +1,9 @@
1
+ import { Attachable } from './attachable';
2
+ import { IAttachmentTarget } from './interfaces';
3
+ export declare abstract class AttachmentTarget extends Attachable implements IAttachmentTarget {
4
+ readonly id: string;
5
+ private attachments;
6
+ constructor();
7
+ protected destroySelf(): void;
8
+ private destroyAttachment;
9
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AttachmentTarget = void 0;
4
+ const helpers_lib_1 = require("helpers-lib");
5
+ const attachable_1 = require("./attachable");
6
+ const attachment_target_store_1 = require("./helpers/attachment-target.store");
7
+ class AttachmentTarget extends attachable_1.Attachable {
8
+ constructor() {
9
+ super();
10
+ this.id = '';
11
+ this.attachments = [];
12
+ this.id = attachment_target_store_1.AttachmentTargetStore.registerAttachable(this);
13
+ }
14
+ destroySelf() {
15
+ super.destroySelf();
16
+ attachment_target_store_1.AttachmentTargetStore.unregisterAttachable(this);
17
+ let attachedEntities = [...this.attachments];
18
+ attachedEntities.forEach(item => this.destroyAttachment(item));
19
+ this.attachments = [];
20
+ }
21
+ /** @internal */
22
+ setAttachment(child) {
23
+ if (this.destroyed) {
24
+ this.destroyAttachment(child);
25
+ }
26
+ else {
27
+ this.attachments.push(child);
28
+ }
29
+ }
30
+ /** @internal */
31
+ removeAttachment(child) {
32
+ let index = this.attachments.indexOf(child);
33
+ if (index >= 0) {
34
+ this.attachments.splice(index, 1);
35
+ }
36
+ }
37
+ destroyAttachment(object) {
38
+ if (helpers_lib_1.Comparator.isObject(object)) {
39
+ let item = object;
40
+ if (helpers_lib_1.Comparator.isFunction(item.destroy)) {
41
+ item.destroy();
42
+ return;
43
+ }
44
+ else if (helpers_lib_1.Comparator.isFunction(item.unsubscribe)) {
45
+ item.unsubscribe();
46
+ return;
47
+ }
48
+ }
49
+ throw new Error(`AttachmentTarget: destroyAttachment is used with not supperted type! Target: "${object}"`);
50
+ }
51
+ }
52
+ exports.AttachmentTarget = AttachmentTarget;
53
+ //# sourceMappingURL=attachment-target.js.map
@@ -0,0 +1,131 @@
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
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ 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
+ var __metadata = (this && this.__metadata) || function (k, v) {
32
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ const ActionsLib = __importStar(require("actions-lib"));
36
+ const actions_lib_1 = require("actions-lib");
37
+ const vitest_1 = require("vitest");
38
+ const entity_1 = require("../entity/entity");
39
+ const scene_1 = require("../scene/scene");
40
+ const update_cycle_1 = require("../update-cycle");
41
+ const attachable_1 = require("./attachable");
42
+ const decorate_actions_lib_1 = require("./helpers/decorate-actions-lib");
43
+ decorate_actions_lib_1.ActionsLibDecorator.decorate(ActionsLib);
44
+ (0, vitest_1.describe)('ATTACHMENT_TARGET', () => {
45
+ (0, vitest_1.beforeEach)(() => {
46
+ update_cycle_1.UpdateCycle.hardResetAction.trigger();
47
+ let SampleScene = class SampleScene extends scene_1.Scene {
48
+ async init() { }
49
+ update() { }
50
+ async prepareToClose() { }
51
+ };
52
+ SampleScene = __decorate([
53
+ (0, scene_1.SceneDecorator)()
54
+ ], SampleScene);
55
+ SampleScene.open();
56
+ });
57
+ (0, vitest_1.test)('dummy', () => {
58
+ (0, vitest_1.expect)(true).toBeTruthy();
59
+ });
60
+ (0, vitest_1.test)('attachable', async () => {
61
+ let Sample = class Sample extends entity_1.Entity {
62
+ };
63
+ Sample = __decorate([
64
+ (0, entity_1.EntityDecorator)()
65
+ ], Sample);
66
+ class Foo extends attachable_1.Attachable {
67
+ }
68
+ let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
69
+ let foo = new Foo();
70
+ sample.setAttachment(foo);
71
+ sample.destroy();
72
+ await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
73
+ (0, vitest_1.expect)(foo.destroyed).toBeTruthy();
74
+ });
75
+ (0, vitest_1.test)('attachable, delayed', async () => {
76
+ let Sample = class Sample extends entity_1.Entity {
77
+ };
78
+ Sample = __decorate([
79
+ (0, entity_1.EntityDecorator)()
80
+ ], Sample);
81
+ class Foo extends attachable_1.Attachable {
82
+ }
83
+ let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
84
+ let foo = new Foo();
85
+ sample.setAttachment(foo);
86
+ sample.destroy();
87
+ await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
88
+ (0, vitest_1.expect)(foo.destroyed).toBeTruthy();
89
+ });
90
+ (0, vitest_1.test)('subscription', async () => {
91
+ let Sample = class Sample extends entity_1.Entity {
92
+ };
93
+ Sample = __decorate([
94
+ (0, entity_1.EntityDecorator)()
95
+ ], Sample);
96
+ let foo = new actions_lib_1.Variable();
97
+ let sample = new Sample().attach(scene_1.Scene.getActiveSceneOrFail());
98
+ (0, vitest_1.expect)(foo.listenerCount).toEqual(0);
99
+ foo.subscribe(() => { }).attach(sample);
100
+ (0, vitest_1.expect)(foo.listenerCount).toEqual(1);
101
+ sample.destroy();
102
+ await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
103
+ (0, vitest_1.expect)(foo.listenerCount).toEqual(0);
104
+ });
105
+ (0, vitest_1.test)('entity attachment in constructor', async () => {
106
+ let childDestoyIsCalled = false;
107
+ let Parent = class Parent extends entity_1.Entity {
108
+ constructor() {
109
+ super();
110
+ new Child().attach(this);
111
+ }
112
+ };
113
+ Parent = __decorate([
114
+ (0, entity_1.EntityDecorator)(),
115
+ __metadata("design:paramtypes", [])
116
+ ], Parent);
117
+ let Child = class Child extends entity_1.Entity {
118
+ afterDestroy() {
119
+ childDestoyIsCalled = true;
120
+ }
121
+ };
122
+ Child = __decorate([
123
+ (0, entity_1.EntityDecorator)()
124
+ ], Child);
125
+ let parent = new Parent().attach(scene_1.Scene.getActiveSceneOrFail());
126
+ parent.destroy();
127
+ await update_cycle_1.UpdateCycle.triggerUpdateTick(1); // Update cycle should take place to destroy functions to be called
128
+ (0, vitest_1.expect)(childDestoyIsCalled).toBeTruthy();
129
+ });
130
+ });
131
+ //# sourceMappingURL=attachment-target.test.js.map
@@ -1,5 +1,5 @@
1
1
  import { Action } from 'actions-lib';
2
- import { CanBeAttached, IAttachable } from './interfaces';
2
+ import { IAttachmentTarget } from './interfaces';
3
3
  export declare abstract class Destroyable {
4
4
  private attachedParent;
5
5
  private _attachIsCalled;
@@ -11,7 +11,6 @@ export declare abstract class Destroyable {
11
11
  destroy(): void;
12
12
  protected afterDestroy(): void;
13
13
  protected destroySelf(): void;
14
- attach(parent: IAttachable | string): this;
14
+ attach(parent: IAttachmentTarget | string): this;
15
15
  attachToRoot(): this;
16
- protected destroyAttachment(object: CanBeAttached): void;
17
16
  }
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Destroyable = void 0;
4
4
  const actions_lib_1 = require("actions-lib");
5
- const helpers_lib_1 = require("helpers-lib");
6
5
  const attachable_store_1 = require("./helpers/attachable.store");
7
6
  class Destroyable {
8
7
  get attachIsCalled() {
@@ -57,26 +56,6 @@ class Destroyable {
57
56
  this._attachIsCalled = true;
58
57
  return this;
59
58
  }
60
- destroyAttachment(object) {
61
- if (object instanceof actions_lib_1.Variable) {
62
- this.destroyAttachment(object.value);
63
- }
64
- else if (object instanceof Array) {
65
- object.forEach((item) => this.destroyAttachment(item));
66
- }
67
- else if (helpers_lib_1.Comparator.isObject(object)) {
68
- let item = object;
69
- if (helpers_lib_1.Comparator.isFunction(item.destroy)) {
70
- item.destroy();
71
- }
72
- else if (helpers_lib_1.Comparator.isFunction(item.unsubscribe)) {
73
- item.unsubscribe();
74
- }
75
- }
76
- else {
77
- throw new Error(`Destroyable: destroyAttachment is used with not supperted type! Target: "${object}"`);
78
- }
79
- }
80
59
  }
81
60
  exports.Destroyable = Destroyable;
82
61
  //# sourceMappingURL=destroyable.js.map
@@ -1,8 +1,8 @@
1
- import { IAttachable } from '../interfaces';
1
+ import { IAttachmentTarget } from '../interfaces';
2
2
  export declare class AttachableStore {
3
3
  private static nextAvailableIds;
4
4
  private static attachables;
5
- static findAttachableParent(attachableCandidate: IAttachable | string): IAttachable;
6
- static registerAttachable(attachable: IAttachable): string;
7
- static unregisterAttachable(attachable: IAttachable): void;
5
+ static findAttachableParent(attachableCandidate: IAttachmentTarget | string): IAttachmentTarget;
6
+ static registerAttachable(attachable: IAttachmentTarget): string;
7
+ static unregisterAttachable(attachable: IAttachmentTarget): void;
8
8
  }