bard-legends-framework 0.10.8 → 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.
- package/dist/game-entities/base/attachable.d.ts +10 -3
- package/dist/game-entities/base/attachable.js +50 -18
- package/dist/game-entities/base/attachable.test.js +81 -95
- package/dist/game-entities/base/helpers/attachable.store.d.ts +2 -8
- package/dist/game-entities/base/helpers/attachable.store.js +46 -17
- package/dist/game-entities/base/helpers/attachable.store.test.d.ts +1 -0
- package/dist/game-entities/base/helpers/attachable.store.test.js +234 -0
- package/dist/game-entities/base/helpers/decorate-actions-lib.d.ts +3 -3
- package/dist/game-entities/base/helpers/decorate-actions-lib.js +5 -5
- package/dist/game-entities/base/helpers/referance-variable.d.ts +2 -2
- package/dist/game-entities/base/helpers/referance-variable.js +2 -2
- package/dist/game-entities/controller/controller.d.ts +0 -1
- package/dist/game-entities/controller/controller.js +1 -0
- package/dist/game-entities/controller/controller.test.js +2 -2
- package/dist/game-entities/entity/entity.d.ts +10 -9
- package/dist/game-entities/entity/entity.js +9 -13
- package/dist/game-entities/entity/entity.test.js +47 -139
- package/dist/game-entities/entity/helpers/entity-store.helper.d.ts +6 -9
- package/dist/game-entities/entity/helpers/entity-store.helper.js +22 -57
- package/dist/game-entities/entity/helpers/entity-store.helper.test.d.ts +1 -0
- package/dist/game-entities/entity/helpers/entity-store.helper.test.js +136 -0
- package/dist/game-entities/entity/helpers/entity-views.helper.d.ts +1 -1
- package/dist/game-entities/entity/helpers/entity-views.helper.js +5 -3
- package/dist/game-entities/entity/singleton-entity.d.ts +3 -3
- package/dist/game-entities/entity/singleton-entity.js +1 -1
- package/dist/game-entities/entity/singleton-entity.test.js +2 -29
- package/dist/game-entities/index.d.ts +1 -5
- package/dist/game-entities/index.js +3 -24
- package/dist/game-entities/scene/scene.d.ts +4 -4
- package/dist/game-entities/scene/scene.js +31 -25
- package/dist/game-entities/scene/scene.test.js +14 -36
- package/dist/game-entities/service/service.js +5 -3
- package/dist/game-entities/service/service.test.js +2 -28
- package/dist/game-entities/unit-test.helper.d.ts +5 -0
- package/dist/game-entities/unit-test.helper.js +14 -0
- package/dist/game-entities/update-cycle.d.ts +15 -4
- package/dist/game-entities/update-cycle.js +14 -9
- package/dist/game-entities/view/view.d.ts +7 -8
- package/dist/game-entities/view/view.js +12 -21
- package/dist/game-entities/view/view.test.js +54 -244
- package/dist/physics/entity-types/immovable-physics-entity.d.ts +1 -3
- package/dist/physics/entity-types/immovable-physics-entity.js +1 -3
- package/dist/physics/entity-types/movable-entity.js +4 -4
- package/dist/physics/entity-types/movable-physics-entity.d.ts +2 -3
- package/dist/physics/entity-types/movable-physics-entity.js +5 -6
- package/dist/physics/entity-types/physics-entity.d.ts +3 -2
- package/dist/physics/entity-types/physics-entity.js +10 -7
- package/dist/physics/interfaces.d.ts +1 -1
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.d.ts +3 -3
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.d.ts +1 -1
- package/dist/physics/module//342/232/234/357/270/217gateways/physics-internal.gateway.d.ts +3 -3
- package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.d.ts +1 -1
- package/dist/physics/module//360/237/223/220services/creation/physics-world.service.js +2 -2
- package/dist/physics/module//360/237/223/220services/path-finding/availability-grid.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/path-finding/path-finder.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/query/physics-query.service.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +17 -7
- package/dist/physics/module//360/237/247/212entities/physics-world.entity.js +2 -2
- package/dist/pixi/components/helpers/smooth-scroller.d.ts +1 -2
- package/dist/pixi/components/helpers/smooth-scroller.js +1 -3
- package/dist/pixi/components/helpers/smooth-scroller.test.js +5 -5
- package/dist/pixi/components/mouse-wheel-listener.ui.d.ts +3 -2
- package/dist/pixi/components/mouse-wheel-listener.ui.js +10 -7
- package/dist/pixi/components/scroll-area.ui.d.ts +0 -1
- package/dist/pixi/components/scroll-area.ui.js +1 -4
- package/dist/pixi/display-object/container-attributes.d.ts +3 -4
- package/dist/pixi/display-object/container-attributes.js +2 -3
- package/dist/pixi/display-object/container.d.ts +0 -4
- package/dist/pixi/display-object/container.js +5 -17
- package/dist/pixi/display-object/objects/graphics/graphics.d.ts +1 -1
- package/dist/pixi/display-object/objects/graphics/graphics.js +5 -3
- package/dist/pixi/display-object/objects/placeholder.d.ts +1 -1
- package/dist/pixi/display-object/objects/placeholder.js +5 -3
- package/dist/pixi/display-object/objects/sprite/glow-sprite-generator.js +5 -3
- package/dist/pixi/display-object/objects/sprite/sprite.d.ts +1 -1
- package/dist/pixi/display-object/objects/sprite/sprite.js +12 -10
- package/dist/pixi/display-object/objects/text/text.d.ts +1 -1
- package/dist/pixi/display-object/objects/text/text.js +5 -3
- package/dist/pixi/game.d.ts +6 -2
- package/dist/pixi/game.js +14 -5
- package/dist/pixi/modules/CAMERA//360/237/247/212entities/camera.entity.js +4 -4
- package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.d.ts +1 -1
- package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.js +6 -4
- package/dist/pixi/services/keyboard/keyboard.d.ts +4 -2
- package/dist/pixi/services/keyboard/keyboard.js +6 -4
- package/dist/pixi/services/mouse/mouse-target-focus.service.d.ts +2 -1
- package/dist/pixi/services/mouse/mouse-target-focus.service.js +6 -5
- package/dist/pixi/services/mouse/mouse.service.d.ts +15 -5
- package/dist/pixi/services/mouse/mouse.service.js +38 -18
- package/dist/utilities/animator/animating-content/fade-in-content.d.ts +18 -0
- package/dist/utilities/animator/animating-content/fade-in-content.js +37 -0
- package/dist/utilities/animator/animating-content/slide-in-content.d.ts +37 -0
- package/dist/utilities/animator/animating-content/slide-in-content.js +99 -0
- package/dist/utilities/animator/animations.d.ts +37 -0
- package/dist/utilities/animator/animations.js +88 -0
- package/dist/utilities/animator/animator.d.ts +61 -0
- package/dist/utilities/animator/animator.js +315 -0
- package/dist/utilities/animator/animator.test.d.ts +1 -0
- package/dist/utilities/animator/animator.test.js +867 -0
- package/dist/utilities/animator/index.d.ts +7 -0
- package/dist/utilities/animator/index.js +24 -0
- package/dist/utilities/animator/state-animation/slide-state-animation.d.ts +24 -0
- package/dist/utilities/animator/state-animation/slide-state-animation.js +130 -0
- package/dist/utilities/animator/state-animation/slide-state-animation.test.d.ts +1 -0
- package/dist/utilities/animator/state-animation/slide-state-animation.test.js +301 -0
- package/dist/utilities/animator/state-animation/state-animation.d.ts +33 -0
- package/dist/utilities/animator/state-animation/state-animation.js +146 -0
- package/dist/utilities/animator/state-animation/state-animation.test.d.ts +1 -0
- package/dist/utilities/animator/state-animation/state-animation.test.js +335 -0
- package/dist/utilities/animator/state-animation/visit-disappear-state-animation.d.ts +32 -0
- package/dist/utilities/animator/state-animation/visit-disappear-state-animation.js +168 -0
- package/dist/utilities/animator/state-animation/visit-disappear-state-animation.test.d.ts +1 -0
- package/dist/utilities/animator/state-animation/visit-disappear-state-animation.test.js +431 -0
- package/dist/utilities/data-structures/vector-set/vector-set.d.ts +7 -0
- package/dist/utilities/data-structures/vector-set/vector-set.js +26 -0
- package/dist/utilities/delta-time/delta-time.d.ts +3 -0
- package/dist/utilities/delta-time/delta-time.js +10 -0
- package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.d.ts +6 -0
- package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.js +55 -0
- package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.test.d.ts +1 -0
- package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.test.js +100 -0
- package/dist/utilities/grid-algorithms/path-finder/path-finder.d.ts +8 -0
- package/dist/utilities/grid-algorithms/path-finder/path-finder.js +98 -0
- package/dist/utilities/grid-algorithms/path-finder/path-finder.test.d.ts +1 -0
- package/dist/utilities/grid-algorithms/path-finder/path-finder.test.js +155 -0
- package/dist/utilities/grid-algorithms/position-to-grid-position-converter.d.ts +6 -0
- package/dist/utilities/grid-algorithms/position-to-grid-position-converter.js +17 -0
- package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.d.ts +18 -0
- package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.js +129 -0
- package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.test.d.ts +1 -0
- package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.test.js +254 -0
- package/dist/utilities/index.d.ts +6 -6
- package/dist/utilities/index.js +6 -6
- package/dist/utilities/libraries/animator/animator.d.ts +3 -5
- package/dist/utilities/libraries/animator/animator.js +17 -19
- package/dist/utilities/libraries/animator/state-animation/slide-state-animation.d.ts +2 -2
- package/dist/utilities/libraries/animator/state-animation/slide-state-animation.js +1 -1
- package/dist/utilities/libraries/animator/state-animation/state-animation.d.ts +2 -2
- package/dist/utilities/libraries/animator/state-animation/state-animation.js +1 -1
- package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.d.ts +2 -2
- package/dist/utilities/libraries/animator/state-animation/visit-disappear-state-animation.js +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helpers_lib_1 = require("helpers-lib");
|
|
4
|
+
const vitest_1 = require("vitest");
|
|
5
|
+
const game_entities_1 = require("../../game-entities");
|
|
6
|
+
const animations_1 = require("./animations");
|
|
7
|
+
const animator_1 = require("./animator");
|
|
8
|
+
(0, vitest_1.describe)('ANIMATOR', () => {
|
|
9
|
+
(0, vitest_1.describe)('Setup', () => {
|
|
10
|
+
(0, vitest_1.test)('constructor should throw error if target is not an object', () => {
|
|
11
|
+
let obj = 'string';
|
|
12
|
+
(0, vitest_1.expect)(() => {
|
|
13
|
+
new animator_1.Animator(obj, 'x').attachToRoot();
|
|
14
|
+
}).toThrow('Animator: target is not an object! Target: "string"');
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.test)('constructor should throw error if target does not have all target properties', () => {
|
|
17
|
+
let obj = { x: 1, y: 2, z: 3 };
|
|
18
|
+
(0, vitest_1.expect)(() => {
|
|
19
|
+
new animator_1.Animator(obj, ['x', 't']).attachToRoot();
|
|
20
|
+
}).toThrow('Animator: target does not have property. Target property: "t"');
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.test)('constructor should throw error if target property is not a number', () => {
|
|
23
|
+
let obj = { x: 'fail' };
|
|
24
|
+
(0, vitest_1.expect)(() => {
|
|
25
|
+
new animator_1.Animator(obj, ['x']).attachToRoot();
|
|
26
|
+
}).toThrow('Animator: target property is not a number. Target property: "x"');
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.test)('animate should throw error if non effected property tried to animate', () => {
|
|
29
|
+
(0, vitest_1.expect)(() => {
|
|
30
|
+
let obj = { x: 0, y: 0 };
|
|
31
|
+
let animator = new animator_1.Animator(obj, ['x', 't']).attachToRoot();
|
|
32
|
+
animator.animate({ x: 5, y: 5 });
|
|
33
|
+
}).toThrow('Animator: target does not have property. Target property: "t"');
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.test)('should throw error if multiple animators decorate the same property', () => {
|
|
36
|
+
(0, vitest_1.expect)(() => {
|
|
37
|
+
let obj = { x: 0 };
|
|
38
|
+
new animator_1.Animator(obj, 'x').attachToRoot();
|
|
39
|
+
new animator_1.Animator(obj, 'x').attachToRoot();
|
|
40
|
+
}).toThrow(`Animator: target property is already animated! Target: "{\n "x": 0\n}", Property: "x"`);
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.test)('setting multiple update callbacks should throw error', () => {
|
|
43
|
+
(0, vitest_1.expect)(() => {
|
|
44
|
+
let obj = { x: 0 };
|
|
45
|
+
new animator_1.Animator(obj, 'x')
|
|
46
|
+
.onChange(() => { })
|
|
47
|
+
.onChange(() => { })
|
|
48
|
+
.attachToRoot();
|
|
49
|
+
}).toThrow('Animator: onChangeCallback is already set!');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
(0, vitest_1.describe)('Animate', () => {
|
|
53
|
+
(0, vitest_1.test)('animate should not change the value before the update ticks', () => {
|
|
54
|
+
let obj = { x: 0 };
|
|
55
|
+
let animator = new animator_1.Animator(obj, 'x').attachToRoot();
|
|
56
|
+
animator.animate({ x: 5 });
|
|
57
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
58
|
+
});
|
|
59
|
+
(0, vitest_1.test)('animate should not take action if the target value is the same', () => {
|
|
60
|
+
let obj = { x: 0 };
|
|
61
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4 }).attachToRoot();
|
|
62
|
+
animator.animate({ x: 0 });
|
|
63
|
+
animator['update'](1);
|
|
64
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
65
|
+
(0, vitest_1.expect)(animator.isAnimating).toEqual(false);
|
|
66
|
+
});
|
|
67
|
+
(0, vitest_1.test)('animate should take action if the target value is the same and the animation is loop', () => {
|
|
68
|
+
let obj = { x: 0 };
|
|
69
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, loop: true }).attachToRoot();
|
|
70
|
+
animator.animate({ x: 0 });
|
|
71
|
+
animator['update'](1);
|
|
72
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
73
|
+
(0, vitest_1.expect)(animator.isAnimating).toEqual(true);
|
|
74
|
+
});
|
|
75
|
+
(0, vitest_1.test)('animate to target in lineer', () => {
|
|
76
|
+
let obj = { x: 0 };
|
|
77
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
78
|
+
animator.animate({ x: 4 });
|
|
79
|
+
animator['update'](1);
|
|
80
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
81
|
+
animator['update'](1);
|
|
82
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
83
|
+
animator['update'](1);
|
|
84
|
+
(0, vitest_1.expect)(obj.x).toEqual(3);
|
|
85
|
+
animator['update'](1);
|
|
86
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
87
|
+
});
|
|
88
|
+
(0, vitest_1.test)('animate to target with overriden duration', () => {
|
|
89
|
+
let obj = { x: 0 };
|
|
90
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
91
|
+
animator.animate({ x: 4 }, { duration: 2 });
|
|
92
|
+
animator['update'](1);
|
|
93
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
94
|
+
});
|
|
95
|
+
(0, vitest_1.test)('animate to target with overriden instant duration', () => {
|
|
96
|
+
let obj = { x: 0 };
|
|
97
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
98
|
+
animator.animate({ x: 4 }, { duration: 0 });
|
|
99
|
+
animator['update'](1);
|
|
100
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.test)('animate only one property should not effect the other', () => {
|
|
103
|
+
let obj = { x: 0, y: 0 };
|
|
104
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
105
|
+
animator.animate({ x: 4 });
|
|
106
|
+
animator['update'](1);
|
|
107
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 0 });
|
|
108
|
+
animator['update'](1);
|
|
109
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
110
|
+
animator['update'](1);
|
|
111
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 0 });
|
|
112
|
+
animator['update'](1);
|
|
113
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 4, y: 0 });
|
|
114
|
+
});
|
|
115
|
+
(0, vitest_1.test)('animate with custom values should override the default settings', () => {
|
|
116
|
+
let obj = { x: 0 };
|
|
117
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 10, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
118
|
+
animator.animate({ x: 10 }, { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
119
|
+
animator['update'](1);
|
|
120
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25 });
|
|
121
|
+
animator['update'](1);
|
|
122
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5 });
|
|
123
|
+
animator['update'](1);
|
|
124
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75 });
|
|
125
|
+
animator['update'](1);
|
|
126
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10 });
|
|
127
|
+
});
|
|
128
|
+
(0, vitest_1.test)('animate to target in easeInOut starting from zero', () => {
|
|
129
|
+
let obj = { x: 0 };
|
|
130
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() }).attachToRoot();
|
|
131
|
+
animator.animate({ x: 10 });
|
|
132
|
+
animator['update'](1);
|
|
133
|
+
(0, vitest_1.expect)(obj.x).toEqual(1.25);
|
|
134
|
+
animator['update'](1);
|
|
135
|
+
(0, vitest_1.expect)(obj.x).toEqual(5);
|
|
136
|
+
animator['update'](1);
|
|
137
|
+
(0, vitest_1.expect)(obj.x).toEqual(8.75);
|
|
138
|
+
animator['update'](1);
|
|
139
|
+
(0, vitest_1.expect)(obj.x).toEqual(10);
|
|
140
|
+
});
|
|
141
|
+
(0, vitest_1.test)('animate to target in easeInOut starting from different value than zero', () => {
|
|
142
|
+
let obj = { x: 10 };
|
|
143
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() }).attachToRoot();
|
|
144
|
+
animator.animate({ x: 20 });
|
|
145
|
+
animator['update'](1);
|
|
146
|
+
(0, vitest_1.expect)(obj.x).toEqual(11.25);
|
|
147
|
+
animator['update'](1);
|
|
148
|
+
(0, vitest_1.expect)(obj.x).toEqual(15);
|
|
149
|
+
animator['update'](1);
|
|
150
|
+
(0, vitest_1.expect)(obj.x).toEqual(18.75);
|
|
151
|
+
animator['update'](1);
|
|
152
|
+
(0, vitest_1.expect)(obj.x).toEqual(20);
|
|
153
|
+
});
|
|
154
|
+
(0, vitest_1.test)('animate to target and return back', () => {
|
|
155
|
+
let obj = { x: 0 };
|
|
156
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
157
|
+
animator.animate({ x: 4 });
|
|
158
|
+
animator['update'](1);
|
|
159
|
+
animator.animate({ x: 0 });
|
|
160
|
+
animator['update'](1);
|
|
161
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
162
|
+
});
|
|
163
|
+
(0, vitest_1.test)('animate onChange callbacks', () => {
|
|
164
|
+
let obj = { x: 0 };
|
|
165
|
+
let valueFromOnStep = 0;
|
|
166
|
+
let onStepCallCount = 0;
|
|
167
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() })
|
|
168
|
+
.onChange(item => {
|
|
169
|
+
valueFromOnStep = item.x;
|
|
170
|
+
onStepCallCount++;
|
|
171
|
+
})
|
|
172
|
+
.attachToRoot();
|
|
173
|
+
animator.animate({ x: 10 });
|
|
174
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(0);
|
|
175
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
176
|
+
animator['update'](1);
|
|
177
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(1);
|
|
178
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(1.25);
|
|
179
|
+
animator['update'](1);
|
|
180
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(2);
|
|
181
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(5);
|
|
182
|
+
animator['update'](1);
|
|
183
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(3);
|
|
184
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(8.75);
|
|
185
|
+
animator['update'](1);
|
|
186
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(4);
|
|
187
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(10);
|
|
188
|
+
animator['update'](1);
|
|
189
|
+
animator['update'](1);
|
|
190
|
+
animator['update'](1);
|
|
191
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(4);
|
|
192
|
+
});
|
|
193
|
+
(0, vitest_1.test)('animate onChange should not be triggered before starting the animation', () => {
|
|
194
|
+
let onStepCallCount = 0;
|
|
195
|
+
let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 4, animation: new animations_1.AnimationEaseInOut() })
|
|
196
|
+
.onChange(() => {
|
|
197
|
+
onStepCallCount++;
|
|
198
|
+
})
|
|
199
|
+
.attachToRoot();
|
|
200
|
+
animator['update'](1);
|
|
201
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
202
|
+
});
|
|
203
|
+
(0, vitest_1.test)('animation complete promise', async () => {
|
|
204
|
+
let obj = { x: 0 };
|
|
205
|
+
let completed = false;
|
|
206
|
+
let animator = new animator_1.Animator(obj, 'x').attachToRoot();
|
|
207
|
+
animator.animate({ x: 1 }, { duration: 2 }).then(() => {
|
|
208
|
+
completed = true;
|
|
209
|
+
});
|
|
210
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
211
|
+
animator['update'](1);
|
|
212
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
213
|
+
animator['update'](1);
|
|
214
|
+
await (0, helpers_lib_1.Wait)();
|
|
215
|
+
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
216
|
+
});
|
|
217
|
+
(0, vitest_1.test)('animate getter/setter property', () => {
|
|
218
|
+
class Foo {
|
|
219
|
+
constructor() {
|
|
220
|
+
this._x = 10;
|
|
221
|
+
}
|
|
222
|
+
get x() {
|
|
223
|
+
return this._x;
|
|
224
|
+
}
|
|
225
|
+
set x(value) {
|
|
226
|
+
this._x = value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let obj = new Foo();
|
|
230
|
+
let animator = new animator_1.Animator(obj, ['x'], { duration: 4, animation: new animations_1.AnimationEaseInOut() }).attachToRoot();
|
|
231
|
+
animator.animate({ x: 20 });
|
|
232
|
+
animator['update'](1);
|
|
233
|
+
(0, vitest_1.expect)(obj.x).toEqual(11.25);
|
|
234
|
+
animator['update'](1);
|
|
235
|
+
(0, vitest_1.expect)(obj.x).toEqual(15);
|
|
236
|
+
animator['update'](1);
|
|
237
|
+
(0, vitest_1.expect)(obj.x).toEqual(18.75);
|
|
238
|
+
animator['update'](1);
|
|
239
|
+
(0, vitest_1.expect)(obj.x).toEqual(20);
|
|
240
|
+
});
|
|
241
|
+
(0, vitest_1.test)('is animating should return true if it is animating', () => {
|
|
242
|
+
let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
243
|
+
animator.animate({ x: 1 });
|
|
244
|
+
(0, vitest_1.expect)(animator.isAnimating).toBeTruthy();
|
|
245
|
+
});
|
|
246
|
+
(0, vitest_1.test)('is animating should return false if it is not animating', () => {
|
|
247
|
+
let obj = { x: 0 };
|
|
248
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
249
|
+
(0, vitest_1.expect)(animator.isAnimating).toBeFalsy();
|
|
250
|
+
animator.animate({ x: 1 });
|
|
251
|
+
animator['update'](1);
|
|
252
|
+
(0, vitest_1.expect)(animator.isAnimating).toBeFalsy();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
(0, vitest_1.describe)('Animation Cycle Changes', () => {
|
|
256
|
+
(0, vitest_1.test)('pause animations should halt the progress', async () => {
|
|
257
|
+
let obj = { x: 0 };
|
|
258
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
259
|
+
animator.animate({ x: 4 });
|
|
260
|
+
animator['update'](1);
|
|
261
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1 });
|
|
262
|
+
animator['update'](1);
|
|
263
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
264
|
+
animator.pauseAnimations();
|
|
265
|
+
animator['update'](1);
|
|
266
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
267
|
+
animator['update'](1);
|
|
268
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
269
|
+
animator.resumeAnimations();
|
|
270
|
+
animator['update'](1);
|
|
271
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3 });
|
|
272
|
+
animator['update'](1);
|
|
273
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 4 });
|
|
274
|
+
});
|
|
275
|
+
(0, vitest_1.test)('new animations should not proceed while the animations are paused', async () => {
|
|
276
|
+
let obj = { x: 0 };
|
|
277
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 2, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
278
|
+
animator.pauseAnimations();
|
|
279
|
+
animator.animate({ x: 2 });
|
|
280
|
+
animator['update'](1);
|
|
281
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0 });
|
|
282
|
+
animator['update'](1);
|
|
283
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0 });
|
|
284
|
+
animator.resumeAnimations();
|
|
285
|
+
animator['update'](1);
|
|
286
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1 });
|
|
287
|
+
animator['update'](1);
|
|
288
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2 });
|
|
289
|
+
});
|
|
290
|
+
(0, vitest_1.test)('animation loop', async () => {
|
|
291
|
+
let obj = { x: 0 };
|
|
292
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 2, animation: new animations_1.AnimationLineer(), loop: true }).attachToRoot();
|
|
293
|
+
animator.animate({ x: 2 }, { duration: 2 });
|
|
294
|
+
animator['update'](1);
|
|
295
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
296
|
+
animator['update'](1);
|
|
297
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
298
|
+
animator['update'](1);
|
|
299
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
300
|
+
animator['update'](0.8);
|
|
301
|
+
(0, vitest_1.expect)(obj.x).toEqual(1.8);
|
|
302
|
+
animator['update'](0.7);
|
|
303
|
+
(0, vitest_1.expect)(obj.x).toEqual(0.5);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
(0, vitest_1.describe)('Animation Type Switch', () => {
|
|
307
|
+
(0, vitest_1.test)('re-animation handling option throw error should throw error', async () => {
|
|
308
|
+
let obj = { x: 0 };
|
|
309
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
310
|
+
duration: 4,
|
|
311
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.throwError
|
|
312
|
+
}).attachToRoot();
|
|
313
|
+
animator.animate({ x: 1 });
|
|
314
|
+
await (0, vitest_1.expect)(animator.animate({ x: 0 })).rejects.toThrow();
|
|
315
|
+
animator['update'](1);
|
|
316
|
+
await (0, vitest_1.expect)(animator.animate({ x: 0 })).rejects.toThrow();
|
|
317
|
+
});
|
|
318
|
+
(0, vitest_1.test)('re-animation handling option ignore should ignore new animation', () => {
|
|
319
|
+
let obj = { x: 0 };
|
|
320
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
321
|
+
duration: 1,
|
|
322
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.ignoreNewAnimation
|
|
323
|
+
}).attachToRoot();
|
|
324
|
+
animator.animate({ x: 1 });
|
|
325
|
+
animator.animate({ x: 2 });
|
|
326
|
+
animator['update'](1);
|
|
327
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
328
|
+
});
|
|
329
|
+
(0, vitest_1.test)('re-animation handling option ignore should ignore multiple property animation', () => {
|
|
330
|
+
let obj = { x: 0, y: 0 };
|
|
331
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
332
|
+
duration: 1,
|
|
333
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.ignoreNewAnimation
|
|
334
|
+
}).attachToRoot();
|
|
335
|
+
animator.animate({ x: 1 });
|
|
336
|
+
animator.animate({ x: 2, y: 1 });
|
|
337
|
+
animator['update'](1);
|
|
338
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 1 });
|
|
339
|
+
});
|
|
340
|
+
(0, vitest_1.test)('animate switch after finishes to a different animation type should not throw error', () => {
|
|
341
|
+
let obj = { x: 1 };
|
|
342
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 1 }).attachToRoot();
|
|
343
|
+
animator.animate({ x: 0 }, { animation: new animations_1.AnimationLineer() });
|
|
344
|
+
animator['update'](1);
|
|
345
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
346
|
+
animator.animate({ x: 10 }, { duration: 4, animation: new animations_1.AnimationEaseInOut() });
|
|
347
|
+
animator['update'](1);
|
|
348
|
+
(0, vitest_1.expect)(obj.x).toEqual(1.25);
|
|
349
|
+
animator['update'](1);
|
|
350
|
+
(0, vitest_1.expect)(obj.x).toEqual(5);
|
|
351
|
+
animator['update'](1);
|
|
352
|
+
(0, vitest_1.expect)(obj.x).toEqual(8.75);
|
|
353
|
+
animator['update'](1);
|
|
354
|
+
(0, vitest_1.expect)(obj.x).toEqual(10);
|
|
355
|
+
});
|
|
356
|
+
(0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing animation', () => {
|
|
357
|
+
let obj = { x: 0 };
|
|
358
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
359
|
+
duration: 1,
|
|
360
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
|
|
361
|
+
}).attachToRoot();
|
|
362
|
+
animator.animate({ x: 1 });
|
|
363
|
+
animator.animate({ x: 2 });
|
|
364
|
+
animator['update'](1);
|
|
365
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
366
|
+
});
|
|
367
|
+
(0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing multiple property animation', () => {
|
|
368
|
+
let obj = { x: 0, y: 0 };
|
|
369
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], {
|
|
370
|
+
duration: 1,
|
|
371
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
|
|
372
|
+
}).attachToRoot();
|
|
373
|
+
animator.animate({ x: 1 });
|
|
374
|
+
animator.animate({ x: 2, y: 1 });
|
|
375
|
+
animator['update'](1);
|
|
376
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 1 });
|
|
377
|
+
});
|
|
378
|
+
(0, vitest_1.test)('re-animation handling option canceling should cancel the animation with keeping the current value', () => {
|
|
379
|
+
let obj = { x: 0 };
|
|
380
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
381
|
+
duration: 2,
|
|
382
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
|
|
383
|
+
}).attachToRoot();
|
|
384
|
+
animator.animate({ x: 2 });
|
|
385
|
+
animator['update'](1);
|
|
386
|
+
animator.animate({ x: 3 });
|
|
387
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
388
|
+
animator['update'](1);
|
|
389
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
390
|
+
animator['update'](1);
|
|
391
|
+
(0, vitest_1.expect)(obj.x).toEqual(3);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
(0, vitest_1.describe)('Set', () => {
|
|
395
|
+
(0, vitest_1.test)('it should throw error if it is animating', () => {
|
|
396
|
+
let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1 }).attachToRoot();
|
|
397
|
+
animator.animate({ x: 1 });
|
|
398
|
+
(0, vitest_1.expect)(() => {
|
|
399
|
+
animator.set({ x: 0 });
|
|
400
|
+
}).toThrow();
|
|
401
|
+
});
|
|
402
|
+
(0, vitest_1.test)('it should throw error if the property is not valid', () => {
|
|
403
|
+
let animator = new animator_1.Animator({ x: 0 }, 'x').attachToRoot();
|
|
404
|
+
(0, vitest_1.expect)(() => {
|
|
405
|
+
animator.set({ t: 0 });
|
|
406
|
+
}).toThrow();
|
|
407
|
+
});
|
|
408
|
+
(0, vitest_1.test)('it should change the original value', () => {
|
|
409
|
+
let obj = { x: 0, y: 1, z: 2 };
|
|
410
|
+
let animator = new animator_1.Animator(obj, ['x', 'y', 'z']).attachToRoot();
|
|
411
|
+
animator.set({ x: 3, y: 4 });
|
|
412
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 4, z: 2 });
|
|
413
|
+
});
|
|
414
|
+
(0, vitest_1.test)('it should trigger onChange', () => {
|
|
415
|
+
let obj = { x: 0 };
|
|
416
|
+
let valueFromOnStep = 0;
|
|
417
|
+
let onStepCallCount = 0;
|
|
418
|
+
let animator = new animator_1.Animator(obj, 'x')
|
|
419
|
+
.onChange(item => {
|
|
420
|
+
valueFromOnStep = item.x;
|
|
421
|
+
onStepCallCount++;
|
|
422
|
+
})
|
|
423
|
+
.attachToRoot();
|
|
424
|
+
animator.set({ x: 1 });
|
|
425
|
+
(0, vitest_1.expect)(valueFromOnStep).toEqual(1);
|
|
426
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(1);
|
|
427
|
+
});
|
|
428
|
+
(0, vitest_1.test)('it should not trigger onChange if the value is the same', () => {
|
|
429
|
+
let obj = { x: 0 };
|
|
430
|
+
let onStepCallCount = 0;
|
|
431
|
+
let animator = new animator_1.Animator(obj, 'x')
|
|
432
|
+
.onChange(() => {
|
|
433
|
+
onStepCallCount++;
|
|
434
|
+
})
|
|
435
|
+
.attachToRoot();
|
|
436
|
+
animator.set({ x: 0 });
|
|
437
|
+
(0, vitest_1.expect)(onStepCallCount).toEqual(0);
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
(0, vitest_1.describe)('Reanimate', () => {
|
|
441
|
+
(0, vitest_1.test)('reanimate ignore new animation', () => {
|
|
442
|
+
let obj = { x: 0 };
|
|
443
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
444
|
+
duration: 4,
|
|
445
|
+
animation: new animations_1.AnimationLineer(),
|
|
446
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.ignoreNewAnimation
|
|
447
|
+
}).attachToRoot();
|
|
448
|
+
animator.animate({ x: 1 });
|
|
449
|
+
animator['update'](1);
|
|
450
|
+
(0, vitest_1.expect)(obj.x).toEqual(0.25);
|
|
451
|
+
animator.animate({ x: 0 });
|
|
452
|
+
animator['update'](1);
|
|
453
|
+
(0, vitest_1.expect)(obj.x).toEqual(0.5);
|
|
454
|
+
});
|
|
455
|
+
(0, vitest_1.test)('reanimate start new animation', () => {
|
|
456
|
+
let obj = { x: 0 };
|
|
457
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
458
|
+
duration: 4,
|
|
459
|
+
animation: new animations_1.AnimationLineer(),
|
|
460
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious,
|
|
461
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
|
|
462
|
+
}).attachToRoot();
|
|
463
|
+
animator.animate({ x: 1 });
|
|
464
|
+
animator['update'](1);
|
|
465
|
+
(0, vitest_1.expect)(obj.x).toEqual(0.25);
|
|
466
|
+
animator.animate({ x: 0 });
|
|
467
|
+
animator['update'](1);
|
|
468
|
+
(0, vitest_1.expect)(obj.x).toEqual(0.1875);
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
(0, vitest_1.describe)('Complete Animations', () => {
|
|
472
|
+
(0, vitest_1.test)('when animation is done it should respect the complete animaitons option', () => {
|
|
473
|
+
let obj = { x: 0 };
|
|
474
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
475
|
+
duration: 1,
|
|
476
|
+
animation: new animations_1.AnimationLineer(),
|
|
477
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
478
|
+
}).attachToRoot();
|
|
479
|
+
animator.animate({ x: 1 });
|
|
480
|
+
animator['update'](1);
|
|
481
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
482
|
+
});
|
|
483
|
+
(0, vitest_1.test)('complete animations should finalize the ongoing animation', async () => {
|
|
484
|
+
let obj = { x: 0 };
|
|
485
|
+
let completed = false;
|
|
486
|
+
let animator = new animator_1.Animator(obj, 'x').attachToRoot();
|
|
487
|
+
animator.animate({ x: 1 }, { duration: 4 }).then(() => {
|
|
488
|
+
completed = true;
|
|
489
|
+
});
|
|
490
|
+
animator['update'](1);
|
|
491
|
+
await (0, helpers_lib_1.Wait)();
|
|
492
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
493
|
+
animator.completeAnimations();
|
|
494
|
+
await (0, helpers_lib_1.Wait)();
|
|
495
|
+
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
496
|
+
});
|
|
497
|
+
(0, vitest_1.test)('complete animations should finalize the all ongoing animations', async () => {
|
|
498
|
+
let completed1 = false;
|
|
499
|
+
let completed2 = false;
|
|
500
|
+
let obj = { x: 0, y: 0 };
|
|
501
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationEaseInOut() }).attachToRoot();
|
|
502
|
+
animator.animate({ y: 10 }, { loop: true }).then(() => {
|
|
503
|
+
completed1 = true;
|
|
504
|
+
});
|
|
505
|
+
animator['update'](1);
|
|
506
|
+
animator.animate({ x: 10 }).then(() => {
|
|
507
|
+
completed2 = true;
|
|
508
|
+
});
|
|
509
|
+
animator['update'](1);
|
|
510
|
+
await (0, helpers_lib_1.Wait)();
|
|
511
|
+
(0, vitest_1.expect)(completed1).toBeFalsy();
|
|
512
|
+
(0, vitest_1.expect)(completed2).toBeFalsy();
|
|
513
|
+
animator.completeAnimations();
|
|
514
|
+
await (0, helpers_lib_1.Wait)();
|
|
515
|
+
(0, vitest_1.expect)(completed1).toBeTruthy();
|
|
516
|
+
(0, vitest_1.expect)(completed2).toBeTruthy();
|
|
517
|
+
});
|
|
518
|
+
(0, vitest_1.test)('complete animations stay in current state', async () => {
|
|
519
|
+
let obj = { x: 0 };
|
|
520
|
+
let animator = new animator_1.Animator(obj, 'x').attachToRoot();
|
|
521
|
+
animator.animate({ x: 4 }, {
|
|
522
|
+
duration: 4,
|
|
523
|
+
animation: new animations_1.AnimationLineer(),
|
|
524
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
|
|
525
|
+
});
|
|
526
|
+
animator['update'](1);
|
|
527
|
+
await (0, helpers_lib_1.Wait)();
|
|
528
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
529
|
+
animator.completeAnimations();
|
|
530
|
+
animator['update'](1);
|
|
531
|
+
await (0, helpers_lib_1.Wait)();
|
|
532
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
533
|
+
});
|
|
534
|
+
(0, vitest_1.test)('complete animations jump to end', async () => {
|
|
535
|
+
let obj = { x: 0 };
|
|
536
|
+
let animator = new animator_1.Animator(obj, 'x').attachToRoot();
|
|
537
|
+
animator.animate({ x: 4 }, {
|
|
538
|
+
duration: 4,
|
|
539
|
+
animation: new animations_1.AnimationLineer(),
|
|
540
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
541
|
+
});
|
|
542
|
+
animator['update'](1);
|
|
543
|
+
await (0, helpers_lib_1.Wait)();
|
|
544
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
545
|
+
animator.completeAnimations();
|
|
546
|
+
animator['update'](1);
|
|
547
|
+
await (0, helpers_lib_1.Wait)();
|
|
548
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
549
|
+
});
|
|
550
|
+
(0, vitest_1.test)('complete animations return to original', async () => {
|
|
551
|
+
let obj = { x: 0 };
|
|
552
|
+
let animator = new animator_1.Animator(obj, 'x').attachToRoot();
|
|
553
|
+
animator.animate({ x: 4 }, {
|
|
554
|
+
duration: 4,
|
|
555
|
+
animation: new animations_1.AnimationLineer(),
|
|
556
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
557
|
+
});
|
|
558
|
+
animator['update'](1);
|
|
559
|
+
await (0, helpers_lib_1.Wait)();
|
|
560
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
561
|
+
animator.completeAnimations();
|
|
562
|
+
animator['update'](1);
|
|
563
|
+
await (0, helpers_lib_1.Wait)();
|
|
564
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
565
|
+
});
|
|
566
|
+
(0, vitest_1.test)('complete animations options overriden in animate', async () => {
|
|
567
|
+
let obj = { x: 0 };
|
|
568
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
569
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
570
|
+
}).attachToRoot();
|
|
571
|
+
animator.animate({ x: 4 }, {
|
|
572
|
+
duration: 4,
|
|
573
|
+
animation: new animations_1.AnimationLineer(),
|
|
574
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
575
|
+
});
|
|
576
|
+
animator['update'](1);
|
|
577
|
+
await (0, helpers_lib_1.Wait)();
|
|
578
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
579
|
+
animator.completeAnimations();
|
|
580
|
+
animator['update'](1);
|
|
581
|
+
await (0, helpers_lib_1.Wait)();
|
|
582
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
583
|
+
});
|
|
584
|
+
(0, vitest_1.test)('complete animations options overriden in complete animations funciton', async () => {
|
|
585
|
+
let obj = { x: 0 };
|
|
586
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
587
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
588
|
+
}).attachToRoot();
|
|
589
|
+
animator.animate({ x: 4 }, {
|
|
590
|
+
duration: 4,
|
|
591
|
+
animation: new animations_1.AnimationLineer(),
|
|
592
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
|
|
593
|
+
});
|
|
594
|
+
animator['update'](1);
|
|
595
|
+
await (0, helpers_lib_1.Wait)();
|
|
596
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
597
|
+
animator.completeAnimations(animator_1.CompleteAnimationsHandlingType.stayInCurrentState);
|
|
598
|
+
animator['update'](1);
|
|
599
|
+
await (0, helpers_lib_1.Wait)();
|
|
600
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
601
|
+
});
|
|
602
|
+
(0, vitest_1.test)('complete animations should not trigger onChange at stay in current state', async () => {
|
|
603
|
+
let obj = { x: 0 };
|
|
604
|
+
let heap = [];
|
|
605
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
606
|
+
duration: 4,
|
|
607
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
|
|
608
|
+
})
|
|
609
|
+
.onChange(value => heap.push(value.x))
|
|
610
|
+
.attachToRoot();
|
|
611
|
+
animator.animate({ x: 1 });
|
|
612
|
+
animator['update'](1);
|
|
613
|
+
await (0, helpers_lib_1.Wait)();
|
|
614
|
+
heap = [];
|
|
615
|
+
animator.completeAnimations();
|
|
616
|
+
await (0, helpers_lib_1.Wait)();
|
|
617
|
+
(0, vitest_1.expect)(heap).toEqual([]);
|
|
618
|
+
});
|
|
619
|
+
(0, vitest_1.test)('complete animations should trigger onChange jump to end', async () => {
|
|
620
|
+
let obj = { x: 0 };
|
|
621
|
+
let heap = [];
|
|
622
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd })
|
|
623
|
+
.onChange(value => heap.push(value.x))
|
|
624
|
+
.attachToRoot();
|
|
625
|
+
animator.animate({ x: 1 });
|
|
626
|
+
animator['update'](1);
|
|
627
|
+
await (0, helpers_lib_1.Wait)();
|
|
628
|
+
heap = [];
|
|
629
|
+
animator.completeAnimations();
|
|
630
|
+
await (0, helpers_lib_1.Wait)();
|
|
631
|
+
(0, vitest_1.expect)(heap).toEqual([1]);
|
|
632
|
+
});
|
|
633
|
+
(0, vitest_1.test)('complete animations should trigger onChange return to original', async () => {
|
|
634
|
+
let obj = { x: 0 };
|
|
635
|
+
let heap = [];
|
|
636
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
637
|
+
duration: 4,
|
|
638
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
|
|
639
|
+
})
|
|
640
|
+
.onChange(value => heap.push(value.x))
|
|
641
|
+
.attachToRoot();
|
|
642
|
+
animator.animate({ x: 1 });
|
|
643
|
+
animator['update'](1);
|
|
644
|
+
await (0, helpers_lib_1.Wait)();
|
|
645
|
+
heap = [];
|
|
646
|
+
animator.completeAnimations();
|
|
647
|
+
await (0, helpers_lib_1.Wait)();
|
|
648
|
+
(0, vitest_1.expect)(heap).toEqual([0]);
|
|
649
|
+
});
|
|
650
|
+
(0, vitest_1.test)('complete animations should not trigger on change if it is not animating', async () => {
|
|
651
|
+
let completed = false;
|
|
652
|
+
let animator = new animator_1.Animator({ x: 0 }, 'x')
|
|
653
|
+
.onChange(() => {
|
|
654
|
+
completed = true;
|
|
655
|
+
})
|
|
656
|
+
.attachToRoot();
|
|
657
|
+
animator.completeAnimations();
|
|
658
|
+
await (0, helpers_lib_1.Wait)();
|
|
659
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
660
|
+
});
|
|
661
|
+
(0, vitest_1.test)('complete animations should not trigger on change if the value change is already triggered', async () => {
|
|
662
|
+
let obj = { x: 0 };
|
|
663
|
+
let heap = [];
|
|
664
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 2 }).onChange(value => heap.push(value.x)).attachToRoot();
|
|
665
|
+
animator.animate({ x: 1 });
|
|
666
|
+
animator['update'](1);
|
|
667
|
+
await (0, helpers_lib_1.Wait)();
|
|
668
|
+
animator.completeAnimations();
|
|
669
|
+
await (0, helpers_lib_1.Wait)();
|
|
670
|
+
(0, vitest_1.expect)(heap).toEqual([0.5]);
|
|
671
|
+
});
|
|
672
|
+
(0, vitest_1.test)('complete animations options should take effect with set', async () => {
|
|
673
|
+
let obj = { x: 0 };
|
|
674
|
+
let animator = new animator_1.Animator(obj, 'x', {
|
|
675
|
+
duration: 4,
|
|
676
|
+
animation: new animations_1.AnimationLineer(),
|
|
677
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
|
|
678
|
+
}).attachToRoot();
|
|
679
|
+
animator.animate({ x: 4 });
|
|
680
|
+
animator['update'](1);
|
|
681
|
+
await (0, helpers_lib_1.Wait)();
|
|
682
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
683
|
+
animator.set({ x: 1 });
|
|
684
|
+
animator['update'](1);
|
|
685
|
+
await (0, helpers_lib_1.Wait)();
|
|
686
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
(0, vitest_1.describe)('Compete Callback', () => {
|
|
690
|
+
(0, vitest_1.test)('complete callback should trigger when the animation is done', async () => {
|
|
691
|
+
let obj = { x: 0 };
|
|
692
|
+
let completed = false;
|
|
693
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 1 }).onComplete(() => (completed = true)).attachToRoot();
|
|
694
|
+
animator.animate({ x: 1 });
|
|
695
|
+
animator['update'](1);
|
|
696
|
+
await (0, helpers_lib_1.Wait)();
|
|
697
|
+
(0, vitest_1.expect)(completed).toBeTruthy();
|
|
698
|
+
});
|
|
699
|
+
(0, vitest_1.test)('complete callback should not trigger when the animation is not done', async () => {
|
|
700
|
+
let completed = false;
|
|
701
|
+
let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1 }).onComplete(() => (completed = true)).attachToRoot();
|
|
702
|
+
animator.animate({ x: 1 });
|
|
703
|
+
(0, vitest_1.expect)(completed).toBeFalsy();
|
|
704
|
+
});
|
|
705
|
+
(0, vitest_1.test)('re-animate should take action in complete callback', async () => {
|
|
706
|
+
let obj = { x: 0 };
|
|
707
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 2 }).attachToRoot();
|
|
708
|
+
animator.onComplete(() => {
|
|
709
|
+
animator.animate({ x: 0 });
|
|
710
|
+
});
|
|
711
|
+
animator.animate({ x: 1 });
|
|
712
|
+
animator['update'](2);
|
|
713
|
+
await (0, helpers_lib_1.Wait)();
|
|
714
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
715
|
+
animator['update'](1);
|
|
716
|
+
await (0, helpers_lib_1.Wait)();
|
|
717
|
+
(0, vitest_1.expect)(obj.x).toEqual(0.5);
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
(0, vitest_1.describe)('Mixing Different Configurations', () => {
|
|
721
|
+
(0, vitest_1.test)('animate multiple properties without mixing animation type', () => {
|
|
722
|
+
let obj = { x: 0, y: 10 };
|
|
723
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationEaseInOut() }).attachToRoot();
|
|
724
|
+
animator.animate({ x: 10, y: 0 });
|
|
725
|
+
animator['update'](1);
|
|
726
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 8.75 });
|
|
727
|
+
animator['update'](1);
|
|
728
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 5 });
|
|
729
|
+
animator['update'](1);
|
|
730
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 1.25 });
|
|
731
|
+
animator['update'](1);
|
|
732
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 0 });
|
|
733
|
+
});
|
|
734
|
+
(0, vitest_1.test)('animate multiple properties with mixing animation type', () => {
|
|
735
|
+
let obj = { x: 0, y: 4 };
|
|
736
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4 }).attachToRoot();
|
|
737
|
+
animator.animate({ x: 10 }, { animation: new animations_1.AnimationEaseInOut() });
|
|
738
|
+
animator.animate({ y: 0 }, { animation: new animations_1.AnimationLineer() });
|
|
739
|
+
animator['update'](1);
|
|
740
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 3 });
|
|
741
|
+
animator['update'](1);
|
|
742
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 2 });
|
|
743
|
+
animator['update'](1);
|
|
744
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 1 });
|
|
745
|
+
animator['update'](1);
|
|
746
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 0 });
|
|
747
|
+
});
|
|
748
|
+
(0, vitest_1.test)('animate multiple properties async', () => {
|
|
749
|
+
let obj = { x: 0, y: 0 };
|
|
750
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationEaseInOut() }).attachToRoot();
|
|
751
|
+
animator.animate({ y: 10 });
|
|
752
|
+
animator['update'](1);
|
|
753
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0, y: 1.25 });
|
|
754
|
+
animator.animate({ x: 10 });
|
|
755
|
+
animator['update'](1);
|
|
756
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 5 });
|
|
757
|
+
animator['update'](1);
|
|
758
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 8.75 });
|
|
759
|
+
animator['update'](1);
|
|
760
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 10 });
|
|
761
|
+
animator['update'](1);
|
|
762
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 10 });
|
|
763
|
+
});
|
|
764
|
+
(0, vitest_1.test)('animate multiple properties mixed with loop', () => {
|
|
765
|
+
let obj = { x: 0, y: 0 };
|
|
766
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationEaseInOut() }).attachToRoot();
|
|
767
|
+
animator.animate({ y: 10 }, { loop: true });
|
|
768
|
+
animator['update'](1);
|
|
769
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 0, y: 1.25 });
|
|
770
|
+
animator.animate({ x: 10 });
|
|
771
|
+
animator['update'](1);
|
|
772
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 5 });
|
|
773
|
+
animator['update'](1);
|
|
774
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 5, y: 8.75 });
|
|
775
|
+
animator['update'](1);
|
|
776
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 0 });
|
|
777
|
+
animator['update'](1);
|
|
778
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 1.25 });
|
|
779
|
+
animator['update'](1);
|
|
780
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 10, y: 5 });
|
|
781
|
+
});
|
|
782
|
+
(0, vitest_1.test)('animate multiple properties complete promise', async () => {
|
|
783
|
+
let completed1 = false;
|
|
784
|
+
let completed2 = false;
|
|
785
|
+
let obj = { x: 0, y: 0 };
|
|
786
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4 }).attachToRoot();
|
|
787
|
+
animator.animate({ y: 10 }).then(() => {
|
|
788
|
+
completed1 = true;
|
|
789
|
+
});
|
|
790
|
+
animator['update'](1);
|
|
791
|
+
animator.animate({ x: 10 }).then(() => {
|
|
792
|
+
completed2 = true;
|
|
793
|
+
});
|
|
794
|
+
animator['update'](2);
|
|
795
|
+
await (0, helpers_lib_1.Wait)();
|
|
796
|
+
(0, vitest_1.expect)(completed1).toBeFalsy();
|
|
797
|
+
(0, vitest_1.expect)(completed2).toBeFalsy();
|
|
798
|
+
animator['update'](1);
|
|
799
|
+
await (0, helpers_lib_1.Wait)();
|
|
800
|
+
(0, vitest_1.expect)(completed1).toBeTruthy();
|
|
801
|
+
(0, vitest_1.expect)(completed2).toBeFalsy();
|
|
802
|
+
animator['update'](1);
|
|
803
|
+
await (0, helpers_lib_1.Wait)();
|
|
804
|
+
(0, vitest_1.expect)(completed1).toBeTruthy();
|
|
805
|
+
(0, vitest_1.expect)(completed2).toBeTruthy();
|
|
806
|
+
});
|
|
807
|
+
(0, vitest_1.test)('pause animations with mixed commands', async () => {
|
|
808
|
+
let obj = { x: 0, y: 0 };
|
|
809
|
+
let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
810
|
+
animator.resumeAnimations();
|
|
811
|
+
animator.animate({ x: 4 });
|
|
812
|
+
animator['update'](1);
|
|
813
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 1, y: 0 });
|
|
814
|
+
animator['update'](1);
|
|
815
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
816
|
+
animator.pauseAnimations();
|
|
817
|
+
animator['update'](1);
|
|
818
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
819
|
+
animator.pauseAnimations();
|
|
820
|
+
animator.animate({ y: 4 });
|
|
821
|
+
animator['update'](1);
|
|
822
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
|
|
823
|
+
animator.resumeAnimations();
|
|
824
|
+
animator['update'](1);
|
|
825
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 3, y: 1 });
|
|
826
|
+
animator.resumeAnimations();
|
|
827
|
+
animator['update'](1);
|
|
828
|
+
(0, vitest_1.expect)(obj).toEqual({ x: 4, y: 2 });
|
|
829
|
+
});
|
|
830
|
+
});
|
|
831
|
+
(0, vitest_1.describe)('Update Cycle', () => {
|
|
832
|
+
(0, vitest_1.test)('testing with update cycle', async () => {
|
|
833
|
+
let obj = { x: 0 };
|
|
834
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
835
|
+
animator.animate({ x: 4 });
|
|
836
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
837
|
+
(0, vitest_1.expect)(obj.x).toEqual(1);
|
|
838
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
839
|
+
(0, vitest_1.expect)(obj.x).toEqual(2);
|
|
840
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
841
|
+
(0, vitest_1.expect)(obj.x).toEqual(3);
|
|
842
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
843
|
+
(0, vitest_1.expect)(obj.x).toEqual(4);
|
|
844
|
+
});
|
|
845
|
+
});
|
|
846
|
+
(0, vitest_1.describe)('Destroyed Animator', () => {
|
|
847
|
+
(0, vitest_1.test)('destroyed animator should not animate', async () => {
|
|
848
|
+
let obj = { x: 0 };
|
|
849
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
850
|
+
animator.destroy();
|
|
851
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
852
|
+
animator.animate({ x: 1 });
|
|
853
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
854
|
+
(0, vitest_1.expect)(obj.x).toEqual(0);
|
|
855
|
+
});
|
|
856
|
+
(0, vitest_1.test)('destroyed animators animation promises should not get stuck', async () => {
|
|
857
|
+
return new Promise(done => {
|
|
858
|
+
let obj = { x: 0 };
|
|
859
|
+
let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: new animations_1.AnimationLineer() }).attachToRoot();
|
|
860
|
+
let promise = animator.animate({ x: 1 });
|
|
861
|
+
animator.destroy();
|
|
862
|
+
promise.then(() => done());
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
//# sourceMappingURL=animator.test.js.map
|