bard-legends-framework 0.10.9 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +8 -6
- package/dist/game-entities/entity/entity.js +5 -7
- package/dist/game-entities/entity/entity.test.js +40 -134
- 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 -3
- package/dist/game-entities/index.js +3 -7
- package/dist/game-entities/scene/scene.d.ts +3 -3
- package/dist/game-entities/scene/scene.js +31 -25
- package/dist/game-entities/scene/scene.test.js +4 -32
- 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 +5 -6
- package/dist/game-entities/view/view.js +5 -17
- package/dist/game-entities/view/view.test.js +36 -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 +2 -1
- package/dist/physics/entity-types/physics-entity.js +3 -2
- 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/mouse-wheel-listener.ui.d.ts +2 -1
- package/dist/pixi/components/mouse-wheel-listener.ui.js +4 -3
- package/dist/pixi/display-object/container-attributes.d.ts +2 -3
- package/dist/pixi/display-object/container-attributes.js +2 -3
- package/dist/pixi/display-object/container.d.ts +0 -3
- package/dist/pixi/display-object/container.js +0 -10
- package/dist/pixi/display-object/objects/sprite/glow-sprite-generator.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.js +1 -1
- 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/package.json +3 -3
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const game_entities_1 = require("../../../game-entities");
|
|
5
|
+
const state_animation_1 = require("./state-animation");
|
|
6
|
+
(0, vitest_1.describe)('StateAnimation', () => {
|
|
7
|
+
let stateAnimation;
|
|
8
|
+
let heap = [];
|
|
9
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
10
|
+
if (stateAnimation) {
|
|
11
|
+
stateAnimation.destroy();
|
|
12
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
13
|
+
}
|
|
14
|
+
heap = [];
|
|
15
|
+
stateAnimation = new state_animation_1.StateAnimation({ duration: 4 })
|
|
16
|
+
.onStateChange((state, nextState) => heap.push({ state, nextState }))
|
|
17
|
+
.onValueChange(value => heap.push(value))
|
|
18
|
+
.attachToRoot();
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.describe)('Creation', () => {
|
|
21
|
+
(0, vitest_1.test)('default values', () => {
|
|
22
|
+
(0, vitest_1.expect)(heap).toEqual([]);
|
|
23
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
24
|
+
value: 0,
|
|
25
|
+
state: undefined,
|
|
26
|
+
nextState: undefined,
|
|
27
|
+
queuedState: undefined,
|
|
28
|
+
animationState: 'idle'
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.test)('initial values', () => {
|
|
32
|
+
stateAnimation.setState('A');
|
|
33
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'A', nextState: undefined }, 0]);
|
|
34
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
35
|
+
value: 0,
|
|
36
|
+
state: 'A',
|
|
37
|
+
nextState: undefined,
|
|
38
|
+
queuedState: undefined,
|
|
39
|
+
animationState: 'idle'
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.test)('initial value as nullish', () => {
|
|
43
|
+
stateAnimation.setState('');
|
|
44
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: '', nextState: undefined }, 0]);
|
|
45
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
46
|
+
value: 0,
|
|
47
|
+
state: '',
|
|
48
|
+
nextState: undefined,
|
|
49
|
+
queuedState: undefined,
|
|
50
|
+
animationState: 'idle'
|
|
51
|
+
});
|
|
52
|
+
heap = [];
|
|
53
|
+
stateAnimation.setState('B');
|
|
54
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: '', nextState: 'B' }, 0]);
|
|
55
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
56
|
+
value: 0,
|
|
57
|
+
state: '',
|
|
58
|
+
nextState: 'B',
|
|
59
|
+
queuedState: undefined,
|
|
60
|
+
animationState: 'transitioning'
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
(0, vitest_1.describe)('Transitioning', () => {
|
|
65
|
+
(0, vitest_1.beforeEach)(() => {
|
|
66
|
+
stateAnimation.setState('A');
|
|
67
|
+
heap = [];
|
|
68
|
+
});
|
|
69
|
+
(0, vitest_1.test)('initial values', () => {
|
|
70
|
+
stateAnimation.setState('B');
|
|
71
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'A', nextState: 'B' }, 0]);
|
|
72
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
73
|
+
value: 0,
|
|
74
|
+
state: 'A',
|
|
75
|
+
nextState: 'B',
|
|
76
|
+
queuedState: undefined,
|
|
77
|
+
animationState: 'transitioning'
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
(0, vitest_1.test)('animation in the middle', async () => {
|
|
81
|
+
stateAnimation.setState('B');
|
|
82
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
83
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'A', nextState: 'B' }, 0, 0.25]);
|
|
84
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
85
|
+
value: 0.25,
|
|
86
|
+
state: 'A',
|
|
87
|
+
nextState: 'B',
|
|
88
|
+
queuedState: undefined,
|
|
89
|
+
animationState: 'transitioning'
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.test)('animation end', async () => {
|
|
93
|
+
stateAnimation.setState('B');
|
|
94
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(4);
|
|
95
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'A', nextState: 'B' }, 0, { state: 'B', nextState: undefined }, 0]);
|
|
96
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
97
|
+
value: 0,
|
|
98
|
+
state: 'B',
|
|
99
|
+
nextState: undefined,
|
|
100
|
+
queuedState: undefined,
|
|
101
|
+
animationState: 'idle'
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
(0, vitest_1.test)('instant from beggining', async () => {
|
|
105
|
+
stateAnimation.setState('B', { instant: true });
|
|
106
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'B', nextState: undefined }, 0]);
|
|
107
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
108
|
+
value: 0,
|
|
109
|
+
state: 'B',
|
|
110
|
+
nextState: undefined,
|
|
111
|
+
queuedState: undefined,
|
|
112
|
+
animationState: 'idle'
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
(0, vitest_1.test)('instant from middle', async () => {
|
|
116
|
+
stateAnimation.setState('B');
|
|
117
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
118
|
+
heap = [];
|
|
119
|
+
stateAnimation.setState('B', { instant: true });
|
|
120
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'B', nextState: undefined }, 0]);
|
|
121
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
122
|
+
value: 0,
|
|
123
|
+
state: 'B',
|
|
124
|
+
nextState: undefined,
|
|
125
|
+
queuedState: undefined,
|
|
126
|
+
animationState: 'idle'
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
(0, vitest_1.describe)('Queued State', () => {
|
|
131
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
132
|
+
stateAnimation.setState('A');
|
|
133
|
+
stateAnimation.setState('B');
|
|
134
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
135
|
+
heap = [];
|
|
136
|
+
});
|
|
137
|
+
(0, vitest_1.test)('initial values', () => {
|
|
138
|
+
stateAnimation.setState('C');
|
|
139
|
+
(0, vitest_1.expect)(heap).toEqual([]);
|
|
140
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
141
|
+
value: 0.5,
|
|
142
|
+
state: 'A',
|
|
143
|
+
nextState: 'B',
|
|
144
|
+
queuedState: 'C',
|
|
145
|
+
animationState: 'transitioning'
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
(0, vitest_1.test)('animation in the middle', async () => {
|
|
149
|
+
stateAnimation.setState('C');
|
|
150
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
151
|
+
(0, vitest_1.expect)(heap).toEqual([0.75]);
|
|
152
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
153
|
+
value: 0.75,
|
|
154
|
+
state: 'A',
|
|
155
|
+
nextState: 'B',
|
|
156
|
+
queuedState: 'C',
|
|
157
|
+
animationState: 'transitioning'
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
(0, vitest_1.test)('transition start', async () => {
|
|
161
|
+
stateAnimation.setState('C');
|
|
162
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
163
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'B', nextState: 'C' }, 0]);
|
|
164
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
165
|
+
value: 0,
|
|
166
|
+
state: 'B',
|
|
167
|
+
nextState: 'C',
|
|
168
|
+
queuedState: undefined,
|
|
169
|
+
animationState: 'transitioning'
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
(0, vitest_1.test)('transition middle', async () => {
|
|
173
|
+
stateAnimation.setState('C');
|
|
174
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
175
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
176
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'B', nextState: 'C' }, 0, 0.5]);
|
|
177
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
178
|
+
value: 0.5,
|
|
179
|
+
state: 'B',
|
|
180
|
+
nextState: 'C',
|
|
181
|
+
queuedState: undefined,
|
|
182
|
+
animationState: 'transitioning'
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
(0, vitest_1.test)('transition end', async () => {
|
|
186
|
+
stateAnimation.setState('C');
|
|
187
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
188
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(4);
|
|
189
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'B', nextState: 'C' }, 0, { state: 'C', nextState: undefined }, 0]);
|
|
190
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
191
|
+
value: 0,
|
|
192
|
+
state: 'C',
|
|
193
|
+
nextState: undefined,
|
|
194
|
+
queuedState: undefined,
|
|
195
|
+
animationState: 'idle'
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
(0, vitest_1.test)('queued value during reverting', async () => {
|
|
199
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
200
|
+
stateAnimation.setState('A');
|
|
201
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
202
|
+
stateAnimation.setState('C');
|
|
203
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
204
|
+
(0, vitest_1.expect)(heap).toEqual([0.75, 0.5, 0.25]);
|
|
205
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
206
|
+
value: 0.25,
|
|
207
|
+
state: 'A',
|
|
208
|
+
nextState: 'B',
|
|
209
|
+
queuedState: 'C',
|
|
210
|
+
animationState: 'reverting'
|
|
211
|
+
});
|
|
212
|
+
heap = [];
|
|
213
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
214
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'A', nextState: 'C' }, 0]);
|
|
215
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
216
|
+
value: 0,
|
|
217
|
+
state: 'A',
|
|
218
|
+
nextState: 'C',
|
|
219
|
+
queuedState: undefined,
|
|
220
|
+
animationState: 'transitioning'
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
(0, vitest_1.test)('instant', async () => {
|
|
224
|
+
stateAnimation.setState('C', { instant: true });
|
|
225
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'C', nextState: undefined }, 0]);
|
|
226
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
227
|
+
value: 0,
|
|
228
|
+
state: 'C',
|
|
229
|
+
nextState: undefined,
|
|
230
|
+
queuedState: undefined,
|
|
231
|
+
animationState: 'idle'
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
(0, vitest_1.test)('edge case, setting zero', async () => {
|
|
235
|
+
let stateAnimationNumber = new state_animation_1.StateAnimation({ duration: 4 }).attachToRoot();
|
|
236
|
+
stateAnimationNumber.setState(2, { instant: true });
|
|
237
|
+
stateAnimationNumber.setState(1);
|
|
238
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
239
|
+
stateAnimationNumber.setState(0);
|
|
240
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
241
|
+
(0, vitest_1.expect)(stateAnimationNumber.currentState).toEqual({
|
|
242
|
+
value: 0,
|
|
243
|
+
state: 1,
|
|
244
|
+
nextState: 0,
|
|
245
|
+
queuedState: undefined,
|
|
246
|
+
animationState: 'transitioning'
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
(0, vitest_1.describe)('Reverting', () => {
|
|
251
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
252
|
+
stateAnimation.setState('A');
|
|
253
|
+
stateAnimation.setState('B');
|
|
254
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(3);
|
|
255
|
+
heap = [];
|
|
256
|
+
});
|
|
257
|
+
(0, vitest_1.test)('initial values', () => {
|
|
258
|
+
stateAnimation.setState('A');
|
|
259
|
+
(0, vitest_1.expect)(heap).toEqual([]);
|
|
260
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
261
|
+
value: 0.75,
|
|
262
|
+
state: 'A',
|
|
263
|
+
nextState: 'B',
|
|
264
|
+
queuedState: undefined,
|
|
265
|
+
animationState: 'reverting'
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
(0, vitest_1.test)('animation in the middle', async () => {
|
|
269
|
+
stateAnimation.setState('A');
|
|
270
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
271
|
+
(0, vitest_1.expect)(heap).toEqual([0.5]);
|
|
272
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
273
|
+
value: 0.5,
|
|
274
|
+
state: 'A',
|
|
275
|
+
nextState: 'B',
|
|
276
|
+
queuedState: undefined,
|
|
277
|
+
animationState: 'reverting'
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
(0, vitest_1.test)('animation end', async () => {
|
|
281
|
+
stateAnimation.setState('A');
|
|
282
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(3);
|
|
283
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'A', nextState: undefined }, 0]);
|
|
284
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
285
|
+
value: 0,
|
|
286
|
+
state: 'A',
|
|
287
|
+
nextState: undefined,
|
|
288
|
+
queuedState: undefined,
|
|
289
|
+
animationState: 'idle'
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
(0, vitest_1.test)('re-reverting', async () => {
|
|
293
|
+
stateAnimation.setState('A');
|
|
294
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
295
|
+
stateAnimation.setState('B');
|
|
296
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(1);
|
|
297
|
+
(0, vitest_1.expect)(heap).toEqual([0.5, 0.75]);
|
|
298
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
299
|
+
value: 0.75,
|
|
300
|
+
state: 'A',
|
|
301
|
+
nextState: 'B',
|
|
302
|
+
queuedState: undefined,
|
|
303
|
+
animationState: 'transitioning'
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
(0, vitest_1.test)('instant', async () => {
|
|
307
|
+
stateAnimation.setState('A', { instant: true });
|
|
308
|
+
(0, vitest_1.expect)(heap).toEqual([{ state: 'A', nextState: undefined }, 0]);
|
|
309
|
+
(0, vitest_1.expect)(stateAnimation.currentState).toEqual({
|
|
310
|
+
value: 0,
|
|
311
|
+
state: 'A',
|
|
312
|
+
nextState: undefined,
|
|
313
|
+
queuedState: undefined,
|
|
314
|
+
animationState: 'idle'
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
(0, vitest_1.test)('edge case, setting zero', async () => {
|
|
318
|
+
let stateAnimationNumber = new state_animation_1.StateAnimation({ duration: 4 }).attachToRoot();
|
|
319
|
+
stateAnimationNumber.setState(2, { instant: true });
|
|
320
|
+
stateAnimationNumber.setState(1);
|
|
321
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
322
|
+
stateAnimationNumber.setState(2);
|
|
323
|
+
stateAnimationNumber.setState(0);
|
|
324
|
+
await game_entities_1.UpdateCycle.triggerUpdateTick(2);
|
|
325
|
+
(0, vitest_1.expect)(stateAnimationNumber.currentState).toEqual({
|
|
326
|
+
value: 0,
|
|
327
|
+
state: 2,
|
|
328
|
+
nextState: 0,
|
|
329
|
+
queuedState: undefined,
|
|
330
|
+
animationState: 'transitioning'
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
//# sourceMappingURL=state-animation.test.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Attachable } from 'actions-lib';
|
|
2
|
+
import { StateAnimationOptions } from './state-animation';
|
|
3
|
+
type AnimationState = 'hidden' | 'visible' | 'appearing' | 'disappearing' | 'disappearToChange';
|
|
4
|
+
export declare class VisitDisappearStateAnimation<T> extends Attachable {
|
|
5
|
+
private animator;
|
|
6
|
+
private options;
|
|
7
|
+
private value;
|
|
8
|
+
private state;
|
|
9
|
+
private queuedState;
|
|
10
|
+
private animationState;
|
|
11
|
+
get currentState(): {
|
|
12
|
+
value: number;
|
|
13
|
+
state: T | undefined;
|
|
14
|
+
queuedState: T | undefined;
|
|
15
|
+
animationState: AnimationState;
|
|
16
|
+
};
|
|
17
|
+
constructor(partialOptions?: Partial<StateAnimationOptions>);
|
|
18
|
+
/**
|
|
19
|
+
* @param state - The new state to set. Keep in mind falsy values are also considered as a new state. To set the state to "disappear" use undefined.
|
|
20
|
+
* @param options - Optional options.
|
|
21
|
+
* @param options.instant - If true, the state will be set immediately.
|
|
22
|
+
*/
|
|
23
|
+
setState(state: T | undefined, options?: {
|
|
24
|
+
instant?: boolean;
|
|
25
|
+
}): void;
|
|
26
|
+
private onComplete;
|
|
27
|
+
private onStateChangeAction;
|
|
28
|
+
private onValueChangeAction;
|
|
29
|
+
onStateChange(callback: (state: T | undefined) => void): this;
|
|
30
|
+
onValueChange(callback: (value: number) => void): this;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VisitDisappearStateAnimation = void 0;
|
|
4
|
+
const actions_lib_1 = require("actions-lib");
|
|
5
|
+
const animations_1 = require("../animations");
|
|
6
|
+
const animator_1 = require("../animator");
|
|
7
|
+
class VisitDisappearStateAnimation extends actions_lib_1.Attachable {
|
|
8
|
+
get currentState() {
|
|
9
|
+
return {
|
|
10
|
+
value: this.value,
|
|
11
|
+
state: this.state,
|
|
12
|
+
queuedState: this.queuedState,
|
|
13
|
+
animationState: this.animationState
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
constructor(partialOptions) {
|
|
17
|
+
super();
|
|
18
|
+
this.animationState = 'hidden';
|
|
19
|
+
this.onStateChangeAction = new actions_lib_1.Action();
|
|
20
|
+
this.onValueChangeAction = new actions_lib_1.Action();
|
|
21
|
+
this.options = { duration: 500, animation: new animations_1.AnimationLineer(), ...partialOptions };
|
|
22
|
+
this.value = 0;
|
|
23
|
+
this.animator = new animator_1.Animator(this, 'value', {
|
|
24
|
+
duration: this.options.duration,
|
|
25
|
+
animation: this.options.animation,
|
|
26
|
+
reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious,
|
|
27
|
+
completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
|
|
28
|
+
})
|
|
29
|
+
.onComplete((key, value) => this.onComplete(value))
|
|
30
|
+
.onChange(() => this.onValueChangeAction.trigger(this.value))
|
|
31
|
+
.attach(this);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @param state - The new state to set. Keep in mind falsy values are also considered as a new state. To set the state to "disappear" use undefined.
|
|
35
|
+
* @param options - Optional options.
|
|
36
|
+
* @param options.instant - If true, the state will be set immediately.
|
|
37
|
+
*/
|
|
38
|
+
setState(state, options) {
|
|
39
|
+
if (options?.instant) {
|
|
40
|
+
this.animator.completeAnimations();
|
|
41
|
+
this.animationState = state !== undefined ? 'visible' : 'hidden';
|
|
42
|
+
this.queuedState = undefined;
|
|
43
|
+
let value = state !== undefined ? 1 : 0;
|
|
44
|
+
let differentState = this.state !== state;
|
|
45
|
+
if (differentState) {
|
|
46
|
+
this.state = state;
|
|
47
|
+
this.onStateChangeAction.trigger(this.state);
|
|
48
|
+
}
|
|
49
|
+
if (differentState || this.value !== value) {
|
|
50
|
+
this.value = value;
|
|
51
|
+
this.onValueChangeAction.trigger(this.value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
switch (this.animationState) {
|
|
56
|
+
case 'hidden':
|
|
57
|
+
if (state !== undefined) {
|
|
58
|
+
this.animationState = 'appearing';
|
|
59
|
+
this.queuedState = undefined;
|
|
60
|
+
this.state = state;
|
|
61
|
+
this.onStateChangeAction.trigger(this.state);
|
|
62
|
+
this.animator.animate({ value: 1 });
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
case 'visible':
|
|
66
|
+
if (state === undefined) {
|
|
67
|
+
this.animationState = 'disappearing';
|
|
68
|
+
this.queuedState = undefined;
|
|
69
|
+
this.animator.animate({ value: 0 });
|
|
70
|
+
}
|
|
71
|
+
else if (state !== this.state) {
|
|
72
|
+
this.animationState = 'disappearToChange';
|
|
73
|
+
this.queuedState = state;
|
|
74
|
+
this.animator.animate({ value: 0 });
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case 'appearing':
|
|
78
|
+
if (state === undefined) {
|
|
79
|
+
this.animationState = 'disappearing';
|
|
80
|
+
this.queuedState = undefined;
|
|
81
|
+
this.animator.animate({ value: 0 }, { duration: this.value * this.options.duration });
|
|
82
|
+
}
|
|
83
|
+
else if (state !== this.state) {
|
|
84
|
+
if (this.value > 0) {
|
|
85
|
+
this.animationState = 'disappearToChange';
|
|
86
|
+
this.queuedState = state;
|
|
87
|
+
this.animator.animate({ value: 0 }, { duration: this.value * this.options.duration });
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.queuedState = undefined;
|
|
91
|
+
this.state = state;
|
|
92
|
+
this.onStateChangeAction.trigger(this.state);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
break;
|
|
96
|
+
case 'disappearing':
|
|
97
|
+
if (state === this.state) {
|
|
98
|
+
this.animationState = 'appearing';
|
|
99
|
+
this.animator.animate({ value: 1 }, { duration: (1 - this.value) * this.options.duration });
|
|
100
|
+
}
|
|
101
|
+
else if (state !== undefined) {
|
|
102
|
+
this.animationState = 'disappearToChange';
|
|
103
|
+
this.queuedState = state;
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case 'disappearToChange':
|
|
107
|
+
if (state === undefined) {
|
|
108
|
+
this.animationState = 'disappearing';
|
|
109
|
+
this.queuedState = undefined;
|
|
110
|
+
}
|
|
111
|
+
else if (state === this.state) {
|
|
112
|
+
this.animationState = 'appearing';
|
|
113
|
+
this.queuedState = undefined;
|
|
114
|
+
this.animator.animate({ value: 1 }, { duration: (1 - this.value) * this.options.duration });
|
|
115
|
+
}
|
|
116
|
+
else if (state !== this.queuedState) {
|
|
117
|
+
this.queuedState = state;
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
onComplete(value) {
|
|
124
|
+
switch (this.animationState) {
|
|
125
|
+
case 'appearing':
|
|
126
|
+
if (value === 1) {
|
|
127
|
+
this.animationState = 'visible';
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
case 'disappearing':
|
|
131
|
+
if (this.queuedState !== undefined) {
|
|
132
|
+
throw new Error('VisitDisappearStateAnimation: Unexpected state, disappearing should not have a queued value');
|
|
133
|
+
}
|
|
134
|
+
if (value === 0) {
|
|
135
|
+
this.animationState = 'hidden';
|
|
136
|
+
this.state = undefined;
|
|
137
|
+
this.onStateChangeAction.trigger(this.state);
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case 'disappearToChange':
|
|
141
|
+
if (this.queuedState === undefined) {
|
|
142
|
+
throw new Error('VisitDisappearStateAnimation: Unexpected state, disappearToChange should always have a queued value');
|
|
143
|
+
}
|
|
144
|
+
if (value === 0) {
|
|
145
|
+
this.animationState = 'appearing';
|
|
146
|
+
this.state = this.queuedState;
|
|
147
|
+
this.queuedState = undefined;
|
|
148
|
+
this.onStateChangeAction.trigger(this.state);
|
|
149
|
+
this.animator.animate({ value: 1 });
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case 'hidden':
|
|
153
|
+
case 'visible':
|
|
154
|
+
// Do nothing
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
onStateChange(callback) {
|
|
159
|
+
this.onStateChangeAction.subscribe(value => callback(value)).attach(this);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
onValueChange(callback) {
|
|
163
|
+
this.onValueChangeAction.subscribe(value => callback(value)).attach(this);
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.VisitDisappearStateAnimation = VisitDisappearStateAnimation;
|
|
168
|
+
//# sourceMappingURL=visit-disappear-state-animation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|