@vpmedia/phaser 1.120.0 → 1.121.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/index.js +499 -607
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/callback.d.ts +12 -0
- package/dist/phaser/core/callback.d.ts.map +1 -0
- package/dist/phaser/core/device.d.ts +1 -5
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +2 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts +3 -0
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +11 -9
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_event.d.ts +1 -1
- package/dist/phaser/core/input_event.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +3 -2
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +5 -4
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts +5 -4
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +14 -7
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +10 -10
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +3 -3
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +9 -3
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +19 -7
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +5 -4
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/timer_event.d.ts +3 -2
- package/dist/phaser/core/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +7 -6
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +2 -1
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts +31 -31
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +2 -1
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +8 -6
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +7 -3
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +1 -1
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +5 -0
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/geom/polygon.d.ts +11 -5
- package/dist/phaser/geom/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +1 -2
- package/src/phaser/core/animation_manager.ts +3 -11
- package/src/phaser/core/animation_parser.ts +2 -2
- package/src/phaser/core/array_set.ts +8 -10
- package/src/phaser/core/cache.ts +2 -2
- package/src/phaser/core/callback.ts +14 -0
- package/src/phaser/core/device.ts +24 -53
- package/src/phaser/core/device_util.ts +6 -6
- package/src/phaser/core/dom.ts +10 -7
- package/src/phaser/core/factory.ts +3 -2
- package/src/phaser/core/game.ts +4 -5
- package/src/phaser/core/input.ts +16 -12
- package/src/phaser/core/input_event.ts +1 -1
- package/src/phaser/core/input_handler.ts +21 -22
- package/src/phaser/core/input_mouse.ts +12 -17
- package/src/phaser/core/input_mspointer.ts +8 -11
- package/src/phaser/core/input_pointer.ts +22 -21
- package/src/phaser/core/input_touch.ts +16 -19
- package/src/phaser/core/loader.ts +75 -86
- package/src/phaser/core/loader_parser.ts +6 -6
- package/src/phaser/core/scale_manager.ts +34 -42
- package/src/phaser/core/scene_manager.ts +2 -1
- package/src/phaser/core/signal.ts +21 -13
- package/src/phaser/core/signal_binding.ts +20 -21
- package/src/phaser/core/sound.ts +9 -11
- package/src/phaser/core/sound_manager.ts +53 -47
- package/src/phaser/core/sound_sprite.ts +34 -21
- package/src/phaser/core/stage.ts +4 -4
- package/src/phaser/core/timer.ts +13 -30
- package/src/phaser/core/timer_event.ts +3 -2
- package/src/phaser/core/tween.ts +9 -8
- package/src/phaser/core/tween_data.ts +15 -41
- package/src/phaser/core/tween_easing.test.ts +35 -35
- package/src/phaser/core/tween_easing.ts +33 -33
- package/src/phaser/core/tween_manager.ts +77 -75
- package/src/phaser/display/bitmap_text.ts +7 -11
- package/src/phaser/display/button.ts +3 -2
- package/src/phaser/display/canvas/graphics.ts +7 -7
- package/src/phaser/display/canvas/pool.ts +5 -6
- package/src/phaser/display/canvas/renderer.ts +7 -4
- package/src/phaser/display/canvas/tinter.ts +9 -11
- package/src/phaser/display/canvas/util.test.ts +122 -0
- package/src/phaser/display/canvas/util.ts +34 -35
- package/src/phaser/display/display_object.ts +30 -43
- package/src/phaser/display/graphics.ts +30 -45
- package/src/phaser/display/group.ts +1 -1
- package/src/phaser/display/image.ts +9 -16
- package/src/phaser/display/sprite_util.ts +0 -1
- package/src/phaser/display/text.ts +27 -43
- package/src/phaser/display/webgl/base_texture.ts +3 -3
- package/src/phaser/display/webgl/earcut.ts +2 -3
- package/src/phaser/display/webgl/fast_sprite_batch.ts +1 -2
- package/src/phaser/display/webgl/filter_manager.ts +6 -18
- package/src/phaser/display/webgl/filter_texture.ts +3 -3
- package/src/phaser/display/webgl/graphics.ts +28 -38
- package/src/phaser/display/webgl/graphics_data.ts +0 -1
- package/src/phaser/display/webgl/render_texture.ts +4 -13
- package/src/phaser/display/webgl/renderer.ts +0 -1
- package/src/phaser/display/webgl/sprite_batch.ts +2 -9
- package/src/phaser/display/webgl/texture.ts +12 -15
- package/src/phaser/geom/point.ts +1 -1
- package/src/phaser/geom/polygon.test.ts +59 -0
- package/src/phaser/geom/polygon.ts +43 -45
- package/src/phaser/geom/rectangle.ts +3 -15
- package/src/phaser/geom/rounded_rectangle.ts +2 -4
- package/src/phaser/geom/util/point.ts +1 -1
- package/src/phaser/geom/util/rectangle.ts +2 -2
- package/src/phaser/util/math.ts +1 -5
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import type { Game } from './game.js';
|
|
2
|
+
import type { Sound } from './sound.js';
|
|
3
|
+
|
|
4
|
+
/** One region of a sound sprite, as the audio atlas describes it. */
|
|
5
|
+
export type SoundSpriteMarker = {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
loop?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** An audio atlas: the markers it carries and the one to start on. */
|
|
12
|
+
export type SoundSpriteConfig = {
|
|
13
|
+
spritemap: Record<string, SoundSpriteMarker>;
|
|
14
|
+
autoplay?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
2
17
|
export class SoundSprite {
|
|
3
18
|
public game!: Game;
|
|
4
|
-
public key!:
|
|
5
|
-
public config!:
|
|
6
|
-
public autoplayKey!:
|
|
7
|
-
public autoplay!:
|
|
8
|
-
public sounds!:
|
|
19
|
+
public key!: string;
|
|
20
|
+
public config!: SoundSpriteConfig;
|
|
21
|
+
public autoplayKey!: string | null;
|
|
22
|
+
public autoplay!: Sound | boolean;
|
|
23
|
+
public sounds!: Record<string, Sound>;
|
|
9
24
|
/**
|
|
10
25
|
* TBD.
|
|
11
26
|
* @param {Game} game - TBD.
|
|
@@ -14,21 +29,19 @@ export class SoundSprite {
|
|
|
14
29
|
public constructor(game: Game, key: string) {
|
|
15
30
|
this.game = game;
|
|
16
31
|
this.key = key;
|
|
17
|
-
this.config = this.game.cache.getJSON(`${key}-audioatlas`);
|
|
32
|
+
this.config = this.game.cache.getJSON<SoundSpriteConfig>(`${key}-audioatlas`);
|
|
18
33
|
this.autoplayKey = null;
|
|
19
34
|
this.autoplay = false;
|
|
20
|
-
/** @type {{[key: string]: Sound}} */
|
|
21
35
|
this.sounds = {};
|
|
22
|
-
for (const
|
|
23
|
-
const marker = this.config.spritemap[k];
|
|
36
|
+
for (const [markerKey, marker] of Object.entries(this.config.spritemap)) {
|
|
24
37
|
const sound = this.game.sound.add(this.key);
|
|
25
|
-
sound.addMarker(
|
|
26
|
-
this.sounds[
|
|
38
|
+
sound.addMarker(markerKey, marker.start, marker.end - marker.start, undefined, marker.loop);
|
|
39
|
+
this.sounds[markerKey] = sound;
|
|
27
40
|
}
|
|
28
41
|
if (this.config.autoplay) {
|
|
29
42
|
this.autoplayKey = this.config.autoplay;
|
|
30
43
|
this.play(this.autoplayKey);
|
|
31
|
-
this.autoplay = this.sounds[this.autoplayKey]
|
|
44
|
+
this.autoplay = this.sounds[this.autoplayKey]!;
|
|
32
45
|
}
|
|
33
46
|
}
|
|
34
47
|
|
|
@@ -38,8 +51,8 @@ export class SoundSprite {
|
|
|
38
51
|
* @param {number} volume - TBD.
|
|
39
52
|
* @returns {Sound} TBD.
|
|
40
53
|
*/
|
|
41
|
-
public play(marker: string, volume = 1) {
|
|
42
|
-
return this.sounds[marker]
|
|
54
|
+
public play(marker: string, volume = 1): Sound | undefined {
|
|
55
|
+
return this.sounds[marker]?.play(marker, undefined, volume);
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
/**
|
|
@@ -47,12 +60,12 @@ export class SoundSprite {
|
|
|
47
60
|
* @param {string} marker - TBD.
|
|
48
61
|
*/
|
|
49
62
|
public stop(marker: string): void {
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
if (marker) {
|
|
64
|
+
this.sounds[marker]?.stop();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
for (const sound of Object.values(this.sounds)) {
|
|
68
|
+
sound.stop();
|
|
56
69
|
}
|
|
57
70
|
}
|
|
58
71
|
|
|
@@ -61,7 +74,7 @@ export class SoundSprite {
|
|
|
61
74
|
* @param {string} marker - TBD.
|
|
62
75
|
* @returns {Sound} TBD.
|
|
63
76
|
*/
|
|
64
|
-
public get(marker: string) {
|
|
77
|
+
public get(marker: string): Sound | undefined {
|
|
65
78
|
return this.sounds[marker];
|
|
66
79
|
}
|
|
67
80
|
}
|
package/src/phaser/core/stage.ts
CHANGED
|
@@ -66,8 +66,8 @@ export class Stage extends DisplayObject {
|
|
|
66
66
|
public override preUpdate(): void {
|
|
67
67
|
this.currentRenderOrderID = 0;
|
|
68
68
|
// This can't loop in reverse, we need the renderOrderID to be in sequence
|
|
69
|
-
for (
|
|
70
|
-
|
|
69
|
+
for (const child of this.children) {
|
|
70
|
+
child.preUpdate();
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -86,8 +86,8 @@ export class Stage extends DisplayObject {
|
|
|
86
86
|
* Post-updates the stage and its children.
|
|
87
87
|
*/
|
|
88
88
|
public override postUpdate(): void {
|
|
89
|
-
for (
|
|
90
|
-
|
|
89
|
+
for (const child of this.children) {
|
|
90
|
+
child.postUpdate();
|
|
91
91
|
}
|
|
92
92
|
this.updateTransform();
|
|
93
93
|
}
|
package/src/phaser/core/timer.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Game } from './game.js';
|
|
2
2
|
import { Signal } from './signal.js';
|
|
3
3
|
import { TimerEvent } from './timer_event.js';
|
|
4
|
+
import type { AppliedCallback, Callback } from './callback.js';
|
|
4
5
|
|
|
5
6
|
export class Timer {
|
|
6
7
|
public game!: Game;
|
|
@@ -65,17 +66,13 @@ export class Timer {
|
|
|
65
66
|
delay: number,
|
|
66
67
|
loop: boolean,
|
|
67
68
|
repeatCount: number,
|
|
68
|
-
callback:
|
|
69
|
-
callbackContext: unknown
|
|
69
|
+
callback: Callback,
|
|
70
|
+
callbackContext: unknown = null,
|
|
70
71
|
args: any = []
|
|
71
72
|
): TimerEvent {
|
|
72
73
|
const roundedDelay = Math.round(delay);
|
|
73
74
|
let tick = roundedDelay;
|
|
74
|
-
|
|
75
|
-
tick += this.game.time.time;
|
|
76
|
-
} else {
|
|
77
|
-
tick += this._now;
|
|
78
|
-
}
|
|
75
|
+
tick += this._now === 0 ? this.game.time.time : this._now;
|
|
79
76
|
const event = new TimerEvent(this, roundedDelay, tick, repeatCount, loop, callback, callbackContext, args);
|
|
80
77
|
this.events.push(event);
|
|
81
78
|
this.order();
|
|
@@ -91,12 +88,7 @@ export class Timer {
|
|
|
91
88
|
* @param {...any} args - Arguments to pass to the callback function.
|
|
92
89
|
* @returns {TimerEvent} The created TimerEvent.
|
|
93
90
|
*/
|
|
94
|
-
public add(
|
|
95
|
-
delay: number,
|
|
96
|
-
callback: Function,
|
|
97
|
-
callbackContext: unknown | null = null,
|
|
98
|
-
...args: unknown[]
|
|
99
|
-
): TimerEvent {
|
|
91
|
+
public add(delay: number, callback: Callback, callbackContext: unknown = null, ...args: unknown[]): TimerEvent {
|
|
100
92
|
return this.create(delay, false, 0, callback, callbackContext, args);
|
|
101
93
|
}
|
|
102
94
|
|
|
@@ -127,8 +119,8 @@ export class Timer {
|
|
|
127
119
|
public repeat(
|
|
128
120
|
delay: number,
|
|
129
121
|
repeatCount: number,
|
|
130
|
-
callback:
|
|
131
|
-
callbackContext: unknown
|
|
122
|
+
callback: Callback,
|
|
123
|
+
callbackContext: unknown = null,
|
|
132
124
|
...args: unknown[]
|
|
133
125
|
): TimerEvent {
|
|
134
126
|
return this.create(delay, false, repeatCount, callback, callbackContext, args);
|
|
@@ -142,12 +134,7 @@ export class Timer {
|
|
|
142
134
|
* @param {...any} args - Arguments to pass to the callback function.
|
|
143
135
|
* @returns {TimerEvent} The created TimerEvent.
|
|
144
136
|
*/
|
|
145
|
-
public loop(
|
|
146
|
-
delay: number,
|
|
147
|
-
callback: Function,
|
|
148
|
-
callbackContext: unknown | null = null,
|
|
149
|
-
...args: unknown[]
|
|
150
|
-
): TimerEvent {
|
|
137
|
+
public loop(delay: number, callback: Callback, callbackContext: unknown = null, ...args: unknown[]): TimerEvent {
|
|
151
138
|
return this.create(delay, true, 0, callback, callbackContext, args);
|
|
152
139
|
}
|
|
153
140
|
|
|
@@ -199,7 +186,7 @@ export class Timer {
|
|
|
199
186
|
if (this.events.length > 0) {
|
|
200
187
|
// Sort the events so the one with the lowest tick is first
|
|
201
188
|
this.events.sort(this.sortHandler);
|
|
202
|
-
const first = this.events
|
|
189
|
+
const [first] = this.events;
|
|
203
190
|
if (first) {
|
|
204
191
|
this.nextTick = first.tick;
|
|
205
192
|
}
|
|
@@ -271,15 +258,15 @@ export class Timer {
|
|
|
271
258
|
}
|
|
272
259
|
if (event.loop) {
|
|
273
260
|
event.tick = this._newTick;
|
|
274
|
-
event.callback.apply(event.callbackContext, event.args);
|
|
261
|
+
(event.callback as AppliedCallback).apply(event.callbackContext, event.args);
|
|
275
262
|
} else if (event.repeatCount > 0) {
|
|
276
263
|
event.repeatCount -= 1;
|
|
277
264
|
event.tick = this._newTick;
|
|
278
|
-
event.callback.apply(event.callbackContext, event.args);
|
|
265
|
+
(event.callback as AppliedCallback).apply(event.callbackContext, event.args);
|
|
279
266
|
} else {
|
|
280
267
|
this._marked += 1;
|
|
281
268
|
event.pendingDelete = true;
|
|
282
|
-
event.callback.apply(event.callbackContext, event.args);
|
|
269
|
+
(event.callback as AppliedCallback).apply(event.callbackContext, event.args);
|
|
283
270
|
}
|
|
284
271
|
this._i += 1;
|
|
285
272
|
} else {
|
|
@@ -343,11 +330,7 @@ export class Timer {
|
|
|
343
330
|
}
|
|
344
331
|
}
|
|
345
332
|
const d = this.nextTick - baseTime;
|
|
346
|
-
|
|
347
|
-
this.nextTick = this._now;
|
|
348
|
-
} else {
|
|
349
|
-
this.nextTick = this._now + d;
|
|
350
|
-
}
|
|
333
|
+
this.nextTick = d < 0 ? this._now : this._now + d;
|
|
351
334
|
}
|
|
352
335
|
|
|
353
336
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Timer } from './timer.js';
|
|
2
|
+
import type { Callback } from './callback.js';
|
|
2
3
|
|
|
3
4
|
export class TimerEvent {
|
|
4
5
|
public timer: Timer;
|
|
@@ -6,7 +7,7 @@ export class TimerEvent {
|
|
|
6
7
|
public tick: number;
|
|
7
8
|
public repeatCount: number;
|
|
8
9
|
public loop: boolean;
|
|
9
|
-
public callback:
|
|
10
|
+
public callback: Callback;
|
|
10
11
|
public callbackContext: unknown;
|
|
11
12
|
public args: unknown[];
|
|
12
13
|
public pendingDelete: boolean;
|
|
@@ -17,7 +18,7 @@ export class TimerEvent {
|
|
|
17
18
|
tick: number,
|
|
18
19
|
repeatCount: number,
|
|
19
20
|
loop: boolean,
|
|
20
|
-
callback:
|
|
21
|
+
callback: Callback,
|
|
21
22
|
callbackContext: unknown,
|
|
22
23
|
args: unknown[]
|
|
23
24
|
) {
|
package/src/phaser/core/tween.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { Signal } from './signal.js';
|
|
|
5
5
|
import { TweenData } from './tween_data.js';
|
|
6
6
|
import type { Game } from './game.js';
|
|
7
7
|
import type { TweenManager } from './tween_manager.js';
|
|
8
|
+
import type { AppliedCallback, Callback, EasingFunction, InterpolationFunction } from './callback.js';
|
|
8
9
|
|
|
9
10
|
export class Tween {
|
|
10
11
|
public game!: Game;
|
|
@@ -25,7 +26,7 @@ export class Tween {
|
|
|
25
26
|
public properties!: any;
|
|
26
27
|
public chainedTween!: Tween | null;
|
|
27
28
|
public isPaused!: boolean;
|
|
28
|
-
public _onUpdateCallback!:
|
|
29
|
+
public _onUpdateCallback!: Callback | null;
|
|
29
30
|
public _onUpdateCallbackContext!: unknown;
|
|
30
31
|
public _pausedTime!: number;
|
|
31
32
|
public _codePaused!: boolean;
|
|
@@ -93,7 +94,7 @@ export class Tween {
|
|
|
93
94
|
public to(
|
|
94
95
|
properties: any,
|
|
95
96
|
duration = 1000,
|
|
96
|
-
ease: string |
|
|
97
|
+
ease: string | EasingFunction = 'Linear',
|
|
97
98
|
autoStart = false,
|
|
98
99
|
delay = 0,
|
|
99
100
|
repeat = 0,
|
|
@@ -126,7 +127,7 @@ export class Tween {
|
|
|
126
127
|
public from(
|
|
127
128
|
properties: any,
|
|
128
129
|
duration = 1000,
|
|
129
|
-
ease: string |
|
|
130
|
+
ease: string | EasingFunction = 'Linear',
|
|
130
131
|
autoStart = false,
|
|
131
132
|
delay = 0,
|
|
132
133
|
repeat = 0,
|
|
@@ -282,7 +283,7 @@ export class Tween {
|
|
|
282
283
|
* @param {number} index - The index in the timeline to apply easing to.
|
|
283
284
|
* @returns {Tween} This Tween object for chaining.
|
|
284
285
|
*/
|
|
285
|
-
public easing(ease: string |
|
|
286
|
+
public easing(ease: string | EasingFunction, index: number): this {
|
|
286
287
|
if (typeof ease === 'string' && this.manager.easeMap[ease]) {
|
|
287
288
|
ease = this.manager.easeMap[ease]!;
|
|
288
289
|
}
|
|
@@ -296,7 +297,7 @@ export class Tween {
|
|
|
296
297
|
* @param {number} index - The index in the timeline to apply interpolation to.
|
|
297
298
|
* @returns {Tween} This Tween object for chaining.
|
|
298
299
|
*/
|
|
299
|
-
public interpolation(interpolation:
|
|
300
|
+
public interpolation(interpolation: InterpolationFunction, context: unknown = MathUtils, index = 0): this {
|
|
300
301
|
this.updateTweenData('interpolationFunction', interpolation, index);
|
|
301
302
|
return this.updateTweenData('interpolationContext', context, index);
|
|
302
303
|
}
|
|
@@ -345,7 +346,7 @@ export class Tween {
|
|
|
345
346
|
* @param {object} callbackContext - The context in which to call the callback.
|
|
346
347
|
* @returns {Tween} This Tween object for chaining.
|
|
347
348
|
*/
|
|
348
|
-
public onUpdateCallback(callback:
|
|
349
|
+
public onUpdateCallback(callback: Callback, callbackContext: unknown): this {
|
|
349
350
|
this._onUpdateCallback = callback;
|
|
350
351
|
this._onUpdateCallbackContext = callbackContext;
|
|
351
352
|
return this;
|
|
@@ -415,7 +416,7 @@ export class Tween {
|
|
|
415
416
|
this._hasStarted = true;
|
|
416
417
|
}
|
|
417
418
|
if (this._onUpdateCallback !== null) {
|
|
418
|
-
this._onUpdateCallback.call(
|
|
419
|
+
(this._onUpdateCallback as AppliedCallback).call(
|
|
419
420
|
this._onUpdateCallbackContext,
|
|
420
421
|
this,
|
|
421
422
|
this.timeline[this.current]!.value,
|
|
@@ -504,7 +505,7 @@ export class Tween {
|
|
|
504
505
|
tweenData.loadValues();
|
|
505
506
|
}
|
|
506
507
|
for (const tweenData of this.timeline) {
|
|
507
|
-
data = data
|
|
508
|
+
data = [...data, ...tweenData.generateData(frameRate)];
|
|
508
509
|
}
|
|
509
510
|
return data;
|
|
510
511
|
}
|
|
@@ -2,6 +2,7 @@ import type { Game } from './game.js';
|
|
|
2
2
|
import * as MathUtils from '../util/math.js';
|
|
3
3
|
import { TWEEN_COMPLETE, TWEEN_LOOPED, TWEEN_PENDING, TWEEN_RUNNING } from './const.js';
|
|
4
4
|
import type { Tween } from './tween.js';
|
|
5
|
+
import type { InterpolationFunction } from './callback.js';
|
|
5
6
|
|
|
6
7
|
export class TweenData {
|
|
7
8
|
public parent!: Tween;
|
|
@@ -24,7 +25,7 @@ export class TweenData {
|
|
|
24
25
|
public dt!: number;
|
|
25
26
|
public startTime!: number | null;
|
|
26
27
|
public easingFunction!: (k: number) => number;
|
|
27
|
-
public interpolationFunction!:
|
|
28
|
+
public interpolationFunction!: InterpolationFunction;
|
|
28
29
|
public interpolationContext!: unknown;
|
|
29
30
|
public isRunning!: boolean;
|
|
30
31
|
public isFrom!: boolean;
|
|
@@ -108,16 +109,8 @@ export class TweenData {
|
|
|
108
109
|
*/
|
|
109
110
|
public start(): this {
|
|
110
111
|
this.startTime = this.game.time.time + this.delay;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} else {
|
|
114
|
-
this.dt = 0;
|
|
115
|
-
}
|
|
116
|
-
if (this.delay > 0) {
|
|
117
|
-
this.isRunning = false;
|
|
118
|
-
} else {
|
|
119
|
-
this.isRunning = true;
|
|
120
|
-
}
|
|
112
|
+
this.dt = this.parent.reverse ? this.duration : 0;
|
|
113
|
+
this.isRunning = this.delay <= 0;
|
|
121
114
|
if (this.isFrom) {
|
|
122
115
|
// Reverse them all and instant set them
|
|
123
116
|
const keys = Object.keys(this.vStartCache);
|
|
@@ -145,12 +138,11 @@ export class TweenData {
|
|
|
145
138
|
// Check if an Array was provided as property value
|
|
146
139
|
if (Array.isArray(this.vEnd[property])) {
|
|
147
140
|
if (this.vEnd[property].length === 0) {
|
|
148
|
-
//
|
|
149
|
-
// TODO: this was continue;
|
|
141
|
+
// an empty end array leaves the property untouched for this step
|
|
150
142
|
} else if (this.percent === 0) {
|
|
151
143
|
// Put the start value at the beginning of the array
|
|
152
144
|
// but we only want to do this once, if the Tween hasn't run before
|
|
153
|
-
this.vEnd[property] = [this.vStart[property]
|
|
145
|
+
this.vEnd[property] = [this.vStart[property], ...this.vEnd[property]];
|
|
154
146
|
}
|
|
155
147
|
}
|
|
156
148
|
if (this.vEnd[property] !== undefined) {
|
|
@@ -199,15 +191,9 @@ export class TweenData {
|
|
|
199
191
|
for (const property of keys) {
|
|
200
192
|
const start = this.vStart[property];
|
|
201
193
|
const end = this.vEnd[property];
|
|
202
|
-
|
|
203
|
-
(this.
|
|
204
|
-
|
|
205
|
-
end,
|
|
206
|
-
this.value
|
|
207
|
-
);
|
|
208
|
-
} else {
|
|
209
|
-
(this.parent.target as unknown as Record<string, any>)[property] = start + (end - start) * this.value;
|
|
210
|
-
}
|
|
194
|
+
(this.parent.target as unknown as Record<string, any>)[property] = Array.isArray(end)
|
|
195
|
+
? this.interpolationFunction.call(this.interpolationContext, end, this.value)
|
|
196
|
+
: start + (end - start) * this.value;
|
|
211
197
|
}
|
|
212
198
|
if ((!this.parent.reverse && this.percent === 1) || (this.parent.reverse && this.percent === 0)) {
|
|
213
199
|
return this.repeat();
|
|
@@ -221,11 +207,7 @@ export class TweenData {
|
|
|
221
207
|
* @returns {object[]} An array of tween data points.
|
|
222
208
|
*/
|
|
223
209
|
public generateData(frameRate: number): Record<string, number>[] {
|
|
224
|
-
|
|
225
|
-
this.dt = this.duration;
|
|
226
|
-
} else {
|
|
227
|
-
this.dt = 0;
|
|
228
|
-
}
|
|
210
|
+
this.dt = this.parent.reverse ? this.duration : 0;
|
|
229
211
|
let data = [];
|
|
230
212
|
let complete = false;
|
|
231
213
|
const fps = (1 / frameRate) * 1000;
|
|
@@ -244,11 +226,9 @@ export class TweenData {
|
|
|
244
226
|
for (const property of keys) {
|
|
245
227
|
const start = this.vStart[property];
|
|
246
228
|
const end = this.vEnd[property];
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
blob[property] = start + (end - start) * this.value;
|
|
251
|
-
}
|
|
229
|
+
blob[property] = Array.isArray(end)
|
|
230
|
+
? this.interpolationFunction(end, this.value)
|
|
231
|
+
: start + (end - start) * this.value;
|
|
252
232
|
}
|
|
253
233
|
data.push(blob);
|
|
254
234
|
if ((!this.parent.reverse && this.percent === 1) || (this.parent.reverse && this.percent === 0)) {
|
|
@@ -256,9 +236,7 @@ export class TweenData {
|
|
|
256
236
|
}
|
|
257
237
|
} while (!complete);
|
|
258
238
|
if (this.yoyo) {
|
|
259
|
-
|
|
260
|
-
reversed.reverse();
|
|
261
|
-
data = data.concat(reversed);
|
|
239
|
+
data = [...data, ...data.toReversed()];
|
|
262
240
|
}
|
|
263
241
|
return data;
|
|
264
242
|
}
|
|
@@ -311,11 +289,7 @@ export class TweenData {
|
|
|
311
289
|
} else if (!this.inReverse) {
|
|
312
290
|
this.startTime += this.repeatDelay;
|
|
313
291
|
}
|
|
314
|
-
|
|
315
|
-
this.dt = this.duration;
|
|
316
|
-
} else {
|
|
317
|
-
this.dt = 0;
|
|
318
|
-
}
|
|
292
|
+
this.dt = this.parent.reverse ? this.duration : 0;
|
|
319
293
|
return TWEEN_LOOPED;
|
|
320
294
|
}
|
|
321
295
|
}
|
|
@@ -4,79 +4,79 @@ import * as Easing from './tween_easing.js';
|
|
|
4
4
|
const SAMPLE_POINTS = [0, 0.1, 0.25, 0.4, 0.5, 0.6, 0.75, 0.9, 1];
|
|
5
5
|
|
|
6
6
|
const EXPECTED: Record<string, number[]> = {
|
|
7
|
-
|
|
7
|
+
backIn: [
|
|
8
8
|
-0, -0.014314220000000002, -0.06413656250000001, -0.09935168000000003, -0.08769750000000004, -0.02902752000000009,
|
|
9
9
|
0.1825903124999999, 0.5911720199999999, 0.9999999999999998,
|
|
10
10
|
],
|
|
11
|
-
|
|
11
|
+
backInOut: [
|
|
12
12
|
-0, -0.037518552000000004, -0.09968184375, 0.0899257920000001, 0.5, 0.9100742079999999, 1.09968184375,
|
|
13
13
|
1.0375185519999999, 1,
|
|
14
14
|
],
|
|
15
|
-
|
|
15
|
+
backOut: [
|
|
16
16
|
2.220446049250313e-16, 0.4088279800000001, 0.8174096875000001, 1.02902752, 1.0876975, 1.09935168, 1.0641365625,
|
|
17
17
|
1.01431422, 1,
|
|
18
18
|
],
|
|
19
|
-
|
|
19
|
+
bounceIn: [
|
|
20
20
|
0, 0.01187500000000008, 0.02734375, 0.22750000000000004, 0.234375, 0.09000000000000019, 0.52734375,
|
|
21
21
|
0.9243750000000001, 1,
|
|
22
22
|
],
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
bounceInOut: [0, 0.030000000000000027, 0.1171875, 0.34875000000000006, 0.5, 0.6512499999999999, 0.8828125, 0.97, 1],
|
|
24
|
+
bounceOut: [
|
|
25
25
|
0, 0.07562500000000001, 0.47265625, 0.9099999999999998, 0.765625, 0.7725, 0.97265625, 0.9881249999999999, 1,
|
|
26
26
|
],
|
|
27
|
-
|
|
27
|
+
circularIn: [
|
|
28
28
|
0, 0.005012562893380035, 0.031754163448145745, 0.08348486100883201, 0.1339745962155614, 0.19999999999999996,
|
|
29
29
|
0.3385621722338523, 0.5641101056459328, 1,
|
|
30
30
|
],
|
|
31
|
-
|
|
31
|
+
circularInOut: [
|
|
32
32
|
-0, 0.010102051443364402, 0.0669872981077807, 0.20000000000000007, 0.5, 0.7999999999999999, 0.9330127018922193,
|
|
33
33
|
0.9898979485566356, 1,
|
|
34
34
|
],
|
|
35
|
-
|
|
35
|
+
circularOut: [
|
|
36
36
|
0, 0.4358898943540673, 0.6614378277661477, 0.8, 0.8660254037844386, 0.916515138991168, 0.9682458365518543,
|
|
37
37
|
0.99498743710662, 1,
|
|
38
38
|
],
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
cubicIn: [0, 0.0010000000000000002, 0.015625, 0.06400000000000002, 0.125, 0.216, 0.421875, 0.7290000000000001, 1],
|
|
40
|
+
cubicInOut: [0, 0.004000000000000001, 0.0625, 0.25600000000000006, 0.5, 0.744, 0.9375, 0.996, 1],
|
|
41
|
+
cubicOut: [0, 0.2709999999999999, 0.578125, 0.784, 0.875, 0.9359999999999999, 0.984375, 0.999, 1],
|
|
42
|
+
elasticIn: [
|
|
43
43
|
0, 1.1959441397923372e-18, 0.0039062499999999952, -0.015625, 1.1481063742006436e-17, 0.0625, -0.12500000000000003,
|
|
44
44
|
6.123233995736767e-17, 1,
|
|
45
45
|
],
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
elasticInOut: [0, 0.001953125, 5.740531871003218e-18, -0.12500000000000003, 0.5, 1.125, 1, 0.998046875, 1],
|
|
47
|
+
elasticOut: [0, 1, 1.125, 0.9375, 1, 1.015625, 0.99609375, 1, 1],
|
|
48
|
+
exponentialIn: [
|
|
49
49
|
0, 0.0019531249999999998, 0.005524271728019903, 0.015625000000000003, 0.03125, 0.06249999999999999,
|
|
50
50
|
0.1767766952966369, 0.5000000000000001, 1,
|
|
51
51
|
],
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
exponentialInOut: [0, 0.0019531249999999993, 0.015625, 0.12500000000000003, 0.5, 0.875, 0.984375, 0.998046875, 1],
|
|
53
|
+
exponentialOut: [0, 0.5, 0.8232233047033631, 0.9375, 0.96875, 0.984375, 0.99447572827198, 0.998046875, 1],
|
|
54
|
+
linearNone: [0, 0.1, 0.25, 0.4, 0.5, 0.6, 0.75, 0.9, 1],
|
|
55
|
+
quadraticIn: [0, 0.010000000000000002, 0.0625, 0.16000000000000003, 0.25, 0.36, 0.5625, 0.81, 1],
|
|
56
|
+
quadraticInOut: [0, 0.020000000000000004, 0.125, 0.32000000000000006, 0.5, 0.6799999999999999, 0.875, 0.98, 1],
|
|
57
|
+
quadraticOut: [0, 0.19, 0.4375, 0.6400000000000001, 0.75, 0.84, 0.9375, 0.9900000000000001, 1],
|
|
58
|
+
quarticIn: [
|
|
59
59
|
0, 0.00010000000000000003, 0.00390625, 0.025600000000000008, 0.0625, 0.1296, 0.31640625, 0.6561000000000001, 1,
|
|
60
60
|
],
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
quarticInOut: [0, 0.0008000000000000003, 0.03125, 0.20480000000000007, 0.5, 0.7951999999999999, 0.96875, 0.9992, 1],
|
|
62
|
+
quarticOut: [0, 0.3438999999999999, 0.68359375, 0.8704000000000001, 0.9375, 0.9744, 0.99609375, 0.9999, 1],
|
|
63
|
+
quinticIn: [
|
|
64
64
|
0, 0.000010000000000000004, 0.0009765625, 0.010240000000000004, 0.03125, 0.07776, 0.2373046875, 0.5904900000000002,
|
|
65
65
|
1,
|
|
66
66
|
],
|
|
67
|
-
|
|
67
|
+
quinticInOut: [
|
|
68
68
|
0, 0.00016000000000000007, 0.015625, 0.16384000000000007, 0.5, 0.8361599999999999, 0.984375, 0.99984, 1,
|
|
69
69
|
],
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
quinticOut: [0, 0.4095099999999998, 0.7626953125, 0.92224, 0.96875, 0.98976, 0.9990234375, 0.99999, 1],
|
|
71
|
+
sinusoidalIn: [
|
|
72
72
|
0, 0.01231165940486223, 0.07612046748871326, 0.19098300562505255, 0.2928932188134524, 0.41221474770752686,
|
|
73
73
|
0.6173165676349102, 0.843565534959769, 1,
|
|
74
74
|
],
|
|
75
|
-
|
|
75
|
+
sinusoidalInOut: [
|
|
76
76
|
0, 0.024471741852423234, 0.1464466094067262, 0.3454915028125263, 0.49999999999999994, 0.6545084971874737,
|
|
77
77
|
0.8535533905932737, 0.9755282581475768, 1,
|
|
78
78
|
],
|
|
79
|
-
|
|
79
|
+
sinusoidalOut: [
|
|
80
80
|
0, 0.15643446504023087, 0.3826834323650898, 0.5877852522924731, 0.7071067811865475, 0.8090169943749475,
|
|
81
81
|
0.9238795325112867, 0.9876883405951378, 1,
|
|
82
82
|
],
|
|
@@ -86,9 +86,9 @@ describe('tween_easing', () => {
|
|
|
86
86
|
it.each(Object.keys(EXPECTED))('%s matches its reference curve', (name) => {
|
|
87
87
|
const fn = (Easing as unknown as Record<string, (k: number) => number>)[name]!;
|
|
88
88
|
const actual = SAMPLE_POINTS.map((k) => fn(k));
|
|
89
|
-
actual.
|
|
89
|
+
for (const [index, value] of actual.entries()) {
|
|
90
90
|
expect(value).toBeCloseTo(EXPECTED[name]![index]!, 12);
|
|
91
|
-
}
|
|
91
|
+
}
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it.each(Object.keys(EXPECTED))('%s is anchored at both ends', (name) => {
|
|
@@ -99,8 +99,8 @@ describe('tween_easing', () => {
|
|
|
99
99
|
|
|
100
100
|
it.each(Object.keys(EXPECTED))('%s does not mutate beyond its return value', (name) => {
|
|
101
101
|
const fn = (Easing as unknown as Record<string, (k: number) => number>)[name]!;
|
|
102
|
-
|
|
102
|
+
for (const k of SAMPLE_POINTS) {
|
|
103
103
|
expect(fn(k)).toBe(fn(k));
|
|
104
|
-
}
|
|
104
|
+
}
|
|
105
105
|
});
|
|
106
106
|
});
|