@vpmedia/phaser 1.116.0 → 1.118.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 +195 -229
- 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 +16 -15
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +76 -47
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +17 -17
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +11 -13
- 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 +8 -7
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +19 -8
- 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 +30 -1
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +24 -4
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts +37 -12
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +15 -5
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +24 -22
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +3 -3
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +26 -26
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +8 -6
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +13 -8
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +3 -2
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +2 -2
- 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.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts +12 -10
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.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 +13 -12
- 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/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +9 -7
- 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/mask_manager.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 +12 -10
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +18 -33
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts +1 -1
- package/dist/phaser/geom/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/point.d.ts.map +1 -1
- 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/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts +5 -4
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +10 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +20 -20
- package/src/phaser/core/animation_manager.ts +27 -24
- package/src/phaser/core/animation_parser.ts +2 -2
- package/src/phaser/core/array_set.ts +7 -7
- package/src/phaser/core/cache.test.ts +201 -0
- package/src/phaser/core/cache.ts +174 -130
- package/src/phaser/core/device_util.ts +13 -13
- package/src/phaser/core/dom.ts +26 -22
- package/src/phaser/core/factory.ts +6 -6
- package/src/phaser/core/game.ts +10 -10
- package/src/phaser/core/input.ts +36 -38
- package/src/phaser/core/input_handler.ts +90 -93
- package/src/phaser/core/input_mouse.ts +19 -19
- package/src/phaser/core/input_mspointer.ts +25 -28
- package/src/phaser/core/input_pointer.ts +37 -28
- package/src/phaser/core/input_touch.ts +17 -17
- package/src/phaser/core/loader.ts +132 -92
- package/src/phaser/core/loader_parser.test.ts +115 -0
- package/src/phaser/core/loader_parser.ts +66 -38
- package/src/phaser/core/raf.ts +3 -3
- package/src/phaser/core/scale_manager.ts +86 -67
- package/src/phaser/core/scene.ts +7 -7
- package/src/phaser/core/scene_manager.ts +16 -16
- package/src/phaser/core/signal.ts +29 -19
- package/src/phaser/core/signal_binding.ts +4 -4
- package/src/phaser/core/sound.ts +45 -33
- package/src/phaser/core/sound_manager.ts +72 -73
- package/src/phaser/core/sound_sprite.ts +1 -1
- package/src/phaser/core/stage.ts +7 -7
- package/src/phaser/core/time.ts +16 -16
- package/src/phaser/core/timer.ts +36 -26
- package/src/phaser/core/tween.ts +29 -29
- package/src/phaser/core/tween_data.ts +41 -37
- package/src/phaser/core/tween_manager.ts +50 -43
- package/src/phaser/core/world.ts +1 -1
- package/src/phaser/display/bitmap_text.test.ts +212 -0
- package/src/phaser/display/bitmap_text.ts +52 -37
- package/src/phaser/display/button.ts +13 -13
- package/src/phaser/display/canvas/buffer.ts +3 -3
- package/src/phaser/display/canvas/graphics.ts +3 -3
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.ts +6 -6
- package/src/phaser/display/canvas/renderer.ts +6 -6
- package/src/phaser/display/canvas/tinter.ts +39 -8
- package/src/phaser/display/canvas/util.ts +15 -9
- package/src/phaser/display/display_object.ts +38 -38
- package/src/phaser/display/graphics.ts +30 -30
- package/src/phaser/display/graphics_data.ts +1 -1
- package/src/phaser/display/graphics_data_util.ts +1 -1
- package/src/phaser/display/group.ts +16 -16
- package/src/phaser/display/image.ts +30 -26
- package/src/phaser/display/sprite_util.ts +12 -4
- package/src/phaser/display/text.ts +55 -55
- package/src/phaser/display/webgl/abstract_filter.ts +1 -1
- package/src/phaser/display/webgl/base_texture.ts +22 -18
- package/src/phaser/display/webgl/blend_manager.ts +3 -3
- package/src/phaser/display/webgl/earcut.ts +3 -3
- package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
- package/src/phaser/display/webgl/filter_manager.ts +7 -7
- package/src/phaser/display/webgl/filter_texture.ts +3 -3
- package/src/phaser/display/webgl/graphics.ts +43 -41
- package/src/phaser/display/webgl/graphics_data.ts +2 -2
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +6 -6
- package/src/phaser/display/webgl/renderer.ts +20 -25
- package/src/phaser/display/webgl/shader/normal.ts +3 -3
- package/src/phaser/display/webgl/shader_manager.ts +2 -2
- package/src/phaser/display/webgl/sprite_batch.ts +9 -9
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture.ts +23 -42
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +11 -7
- package/src/phaser/geom/circle.ts +21 -21
- package/src/phaser/geom/ellipse.ts +7 -7
- package/src/phaser/geom/line.ts +29 -29
- package/src/phaser/geom/matrix.ts +13 -13
- package/src/phaser/geom/point.ts +36 -30
- package/src/phaser/geom/polygon.ts +6 -6
- package/src/phaser/geom/rectangle.ts +42 -42
- package/src/phaser/geom/rounded_rectangle.ts +2 -2
- package/src/phaser/geom/util/circle.ts +7 -7
- package/src/phaser/geom/util/ellipse.ts +1 -1
- package/src/phaser/geom/util/line.ts +13 -5
- package/src/phaser/geom/util/matrix.ts +3 -3
- package/src/phaser/geom/util/point.ts +20 -20
- package/src/phaser/geom/util/polygon.ts +1 -1
- package/src/phaser/geom/util/rectangle.ts +34 -17
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
|
@@ -59,7 +59,7 @@ export class SceneManager {
|
|
|
59
59
|
* Initialize the scene manager.
|
|
60
60
|
* This method is called when the game boots and sets up the initial state.
|
|
61
61
|
*/
|
|
62
|
-
public boot() {
|
|
62
|
+
public boot(): void {
|
|
63
63
|
if (this._pendingState !== null && typeof this._pendingState !== 'string') {
|
|
64
64
|
this.add('default', this._pendingState, true);
|
|
65
65
|
}
|
|
@@ -97,7 +97,7 @@ export class SceneManager {
|
|
|
97
97
|
* Remove a scene state from the manager.
|
|
98
98
|
* @param {string} key - The unique key for the state to remove.
|
|
99
99
|
*/
|
|
100
|
-
public remove(key: string) {
|
|
100
|
+
public remove(key: string): void {
|
|
101
101
|
if (this.current === key) {
|
|
102
102
|
this.onInitCallback = null;
|
|
103
103
|
this.onShutDownCallback = null;
|
|
@@ -117,7 +117,7 @@ export class SceneManager {
|
|
|
117
117
|
* @param {boolean} clearCache - Whether to clear the cache before starting.
|
|
118
118
|
* @param {...any} args - Additional arguments to pass to the state.
|
|
119
119
|
*/
|
|
120
|
-
public start(key: string, clearWorld = true, clearCache = false, ...args: unknown[]) {
|
|
120
|
+
public start(key: string, clearWorld = true, clearCache = false, ...args: unknown[]): void {
|
|
121
121
|
if (this.checkState(key)) {
|
|
122
122
|
// Place the state in the queue. It will be started the next time the game loop begins.
|
|
123
123
|
this._pendingState = key;
|
|
@@ -135,7 +135,7 @@ export class SceneManager {
|
|
|
135
135
|
* @param {boolean} clearCache - Whether to clear the cache before restarting.
|
|
136
136
|
* @param {...any} args - Additional arguments to pass to the state.
|
|
137
137
|
*/
|
|
138
|
-
public restart(clearWorld = true, clearCache = false, ...args: unknown[]) {
|
|
138
|
+
public restart(clearWorld = true, clearCache = false, ...args: unknown[]): void {
|
|
139
139
|
this._pendingState = this.current;
|
|
140
140
|
this._clearWorld = clearWorld;
|
|
141
141
|
this._clearCache = clearCache;
|
|
@@ -148,7 +148,7 @@ export class SceneManager {
|
|
|
148
148
|
* Pre-update the scene manager.
|
|
149
149
|
* This method is called before the game loop updates.
|
|
150
150
|
*/
|
|
151
|
-
public preUpdate() {
|
|
151
|
+
public preUpdate(): void {
|
|
152
152
|
if (this._pendingState && this.game.isBooted) {
|
|
153
153
|
// var previousStateKey = this.current;
|
|
154
154
|
// Already got a state running?
|
|
@@ -183,7 +183,7 @@ export class SceneManager {
|
|
|
183
183
|
* Clear the current scene state.
|
|
184
184
|
* This method is called when switching scenes to clean up the previous scene.
|
|
185
185
|
*/
|
|
186
|
-
public clearCurrentState() {
|
|
186
|
+
public clearCurrentState(): void {
|
|
187
187
|
if (this.current) {
|
|
188
188
|
if (this.onShutDownCallback) {
|
|
189
189
|
this.onShutDownCallback.call(this.callbackContext, this.game);
|
|
@@ -206,7 +206,7 @@ export class SceneManager {
|
|
|
206
206
|
* @param {string} key - The unique key for the state to check.
|
|
207
207
|
* @returns {boolean} True if the scene exists, false otherwise.
|
|
208
208
|
*/
|
|
209
|
-
public checkState(key: string) {
|
|
209
|
+
public checkState(key: string): boolean {
|
|
210
210
|
if (this.states[key]) {
|
|
211
211
|
if (this.states[key].preload || this.states[key].create || this.states[key].update || this.states[key].render) {
|
|
212
212
|
return true;
|
|
@@ -220,7 +220,7 @@ export class SceneManager {
|
|
|
220
220
|
* Link a scene state to the manager.
|
|
221
221
|
* @param {string} key - The unique key for the state to link.
|
|
222
222
|
*/
|
|
223
|
-
public link(key: string) {
|
|
223
|
+
public link(key: string): void {
|
|
224
224
|
this.states[key].game = this.game;
|
|
225
225
|
this.states[key].key = key;
|
|
226
226
|
}
|
|
@@ -229,7 +229,7 @@ export class SceneManager {
|
|
|
229
229
|
* Unlink a scene state from the manager.
|
|
230
230
|
* @param {string} key - The unique key for the state to unlink.
|
|
231
231
|
*/
|
|
232
|
-
public unlink(key: string) {
|
|
232
|
+
public unlink(key: string): void {
|
|
233
233
|
if (this.states[key]) {
|
|
234
234
|
this.states[key].game = null;
|
|
235
235
|
}
|
|
@@ -239,7 +239,7 @@ export class SceneManager {
|
|
|
239
239
|
* Set the current scene state.
|
|
240
240
|
* @param {string} key - The unique key for the state to set as current.
|
|
241
241
|
*/
|
|
242
|
-
public setCurrentState(key: string) {
|
|
242
|
+
public setCurrentState(key: string): void {
|
|
243
243
|
this.callbackContext = this.states[key];
|
|
244
244
|
this.link(key);
|
|
245
245
|
// Used when the state is set as being the current active state
|
|
@@ -272,7 +272,7 @@ export class SceneManager {
|
|
|
272
272
|
* Handle loading completion.
|
|
273
273
|
* This method is called when scene loading is complete.
|
|
274
274
|
*/
|
|
275
|
-
public loadComplete() {
|
|
275
|
+
public loadComplete(): void {
|
|
276
276
|
if (this._created === false && this.onCreateCallback) {
|
|
277
277
|
this._created = true;
|
|
278
278
|
this.onCreateCallback.call(this.callbackContext, this.game);
|
|
@@ -285,7 +285,7 @@ export class SceneManager {
|
|
|
285
285
|
* Update the scene manager.
|
|
286
286
|
* This method is called every frame while the game is running.
|
|
287
287
|
*/
|
|
288
|
-
public update() {
|
|
288
|
+
public update(): void {
|
|
289
289
|
if (this._created && this.onUpdateCallback) {
|
|
290
290
|
this.onUpdateCallback.call(this.callbackContext, this.game);
|
|
291
291
|
}
|
|
@@ -295,7 +295,7 @@ export class SceneManager {
|
|
|
295
295
|
* Pause the scene manager updates.
|
|
296
296
|
* This method is called when the game is paused.
|
|
297
297
|
*/
|
|
298
|
-
public pauseUpdate() {
|
|
298
|
+
public pauseUpdate(): void {
|
|
299
299
|
if (this._created && this.onPauseUpdateCallback) {
|
|
300
300
|
this.onPauseUpdateCallback.call(this.callbackContext, this.game);
|
|
301
301
|
}
|
|
@@ -306,7 +306,7 @@ export class SceneManager {
|
|
|
306
306
|
* @param {number} width - The new width of the scene.
|
|
307
307
|
* @param {number} height - The new height of the scene.
|
|
308
308
|
*/
|
|
309
|
-
public resize(width: number, height: number) {
|
|
309
|
+
public resize(width: number, height: number): void {
|
|
310
310
|
if (this.onResizeCallback) {
|
|
311
311
|
this.onResizeCallback.call(this.callbackContext, width, height);
|
|
312
312
|
}
|
|
@@ -316,7 +316,7 @@ export class SceneManager {
|
|
|
316
316
|
* Destroy the scene manager.
|
|
317
317
|
* This method is called when the scene manager is about to be destroyed.
|
|
318
318
|
*/
|
|
319
|
-
public destroy() {
|
|
319
|
+
public destroy(): void {
|
|
320
320
|
this._clearWorld = true;
|
|
321
321
|
this._clearCache = true;
|
|
322
322
|
this.clearCurrentState();
|
|
@@ -335,7 +335,7 @@ export class SceneManager {
|
|
|
335
335
|
* Dummy function for callbacks.
|
|
336
336
|
* This is a placeholder function used when no callback is defined.
|
|
337
337
|
*/
|
|
338
|
-
public dummy() {
|
|
338
|
+
public dummy(): void {
|
|
339
339
|
// pass
|
|
340
340
|
}
|
|
341
341
|
|
|
@@ -19,7 +19,7 @@ export class Signal {
|
|
|
19
19
|
* @param {string} fnName - The name of the function this validation is for.
|
|
20
20
|
* @throws {Error} If the listener is not a function.
|
|
21
21
|
*/
|
|
22
|
-
public validateListener(listener: Function, fnName: string) {
|
|
22
|
+
public validateListener(listener: Function, fnName: string): void {
|
|
23
23
|
if (typeof listener !== 'function') {
|
|
24
24
|
throw new TypeError(
|
|
25
25
|
'Signal: listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)
|
|
@@ -43,7 +43,7 @@ export class Signal {
|
|
|
43
43
|
listenerContext: unknown | null = null,
|
|
44
44
|
priority = 0,
|
|
45
45
|
args: any = null
|
|
46
|
-
) {
|
|
46
|
+
): SignalBinding {
|
|
47
47
|
const prevIndex = this._indexOfListener(listener, listenerContext);
|
|
48
48
|
let binding;
|
|
49
49
|
const existing = prevIndex !== -1 && this._bindings ? this._bindings[prevIndex] : undefined;
|
|
@@ -70,7 +70,7 @@ export class Signal {
|
|
|
70
70
|
* Add a binding to the list of listeners.
|
|
71
71
|
* @param {SignalBinding} binding - The binding to add.
|
|
72
72
|
*/
|
|
73
|
-
public _addBinding(binding: SignalBinding) {
|
|
73
|
+
public _addBinding(binding: SignalBinding): void {
|
|
74
74
|
this._bindings ??= [];
|
|
75
75
|
// Simplified insertion sort
|
|
76
76
|
let n = this._bindings.length;
|
|
@@ -86,7 +86,7 @@ export class Signal {
|
|
|
86
86
|
* @param {object} context - The context of the listener.
|
|
87
87
|
* @returns {number} The index of the listener in the bindings array, or -1 if not found.
|
|
88
88
|
*/
|
|
89
|
-
public _indexOfListener(listener: Function, context: unknown = null) {
|
|
89
|
+
public _indexOfListener(listener: Function, context: unknown = null): number {
|
|
90
90
|
if (!this._bindings) {
|
|
91
91
|
return -1;
|
|
92
92
|
}
|
|
@@ -108,7 +108,7 @@ export class Signal {
|
|
|
108
108
|
* @param {object} context - The context of the listener.
|
|
109
109
|
* @returns {boolean} True if the listener is registered, false otherwise.
|
|
110
110
|
*/
|
|
111
|
-
public has(listener: Function, context: unknown = null) {
|
|
111
|
+
public has(listener: Function, context: unknown = null): boolean {
|
|
112
112
|
return this._indexOfListener(listener, context) !== -1;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -120,7 +120,12 @@ export class Signal {
|
|
|
120
120
|
* @param {...any} args - Additional arguments to pass to the listener.
|
|
121
121
|
* @returns {SignalBinding} The binding for this listener.
|
|
122
122
|
*/
|
|
123
|
-
public add(
|
|
123
|
+
public add(
|
|
124
|
+
listener: Function,
|
|
125
|
+
listenerContext: unknown | null = null,
|
|
126
|
+
priority = 0,
|
|
127
|
+
...args: unknown[]
|
|
128
|
+
): SignalBinding {
|
|
124
129
|
this.validateListener(listener, 'add');
|
|
125
130
|
return this._registerListener(listener, false, listenerContext, priority, args);
|
|
126
131
|
}
|
|
@@ -133,7 +138,12 @@ export class Signal {
|
|
|
133
138
|
* @param {...any} args - Additional arguments to pass to the listener.
|
|
134
139
|
* @returns {SignalBinding} The binding for this listener.
|
|
135
140
|
*/
|
|
136
|
-
public addOnce(
|
|
141
|
+
public addOnce(
|
|
142
|
+
listener: Function,
|
|
143
|
+
listenerContext: unknown | null = null,
|
|
144
|
+
priority = 0,
|
|
145
|
+
...args: unknown[]
|
|
146
|
+
): SignalBinding {
|
|
137
147
|
this.validateListener(listener, 'addOnce');
|
|
138
148
|
return this._registerListener(listener, true, listenerContext, priority, args);
|
|
139
149
|
}
|
|
@@ -144,7 +154,7 @@ export class Signal {
|
|
|
144
154
|
* @param {object} context - The context of the listener.
|
|
145
155
|
* @returns {Function} The removed listener function.
|
|
146
156
|
*/
|
|
147
|
-
public remove(listener: Function, context: unknown = null) {
|
|
157
|
+
public remove(listener: Function, context: unknown = null): Function {
|
|
148
158
|
this.validateListener(listener, 'remove');
|
|
149
159
|
const i = this._indexOfListener(listener, context);
|
|
150
160
|
if (i !== -1 && this._bindings) {
|
|
@@ -159,7 +169,7 @@ export class Signal {
|
|
|
159
169
|
* Remove all listeners from the signal, or only those in a specific context.
|
|
160
170
|
* @param {object} context - The context to filter listeners by, or null to remove all.
|
|
161
171
|
*/
|
|
162
|
-
public removeAll(context: unknown = null) {
|
|
172
|
+
public removeAll(context: unknown = null): void {
|
|
163
173
|
if (!this._bindings) {
|
|
164
174
|
return;
|
|
165
175
|
}
|
|
@@ -184,7 +194,7 @@ export class Signal {
|
|
|
184
194
|
* Get the number of listeners registered with the signal.
|
|
185
195
|
* @returns {number} The number of registered listeners.
|
|
186
196
|
*/
|
|
187
|
-
public getNumListeners() {
|
|
197
|
+
public getNumListeners(): number {
|
|
188
198
|
return this._bindings ? this._bindings.length : 0;
|
|
189
199
|
}
|
|
190
200
|
|
|
@@ -192,7 +202,7 @@ export class Signal {
|
|
|
192
202
|
* Stop the signal from propagating to other listeners.
|
|
193
203
|
* This method prevents any remaining listeners from being called.
|
|
194
204
|
*/
|
|
195
|
-
public halt() {
|
|
205
|
+
public halt(): void {
|
|
196
206
|
this._shouldPropagate = false;
|
|
197
207
|
}
|
|
198
208
|
|
|
@@ -200,7 +210,7 @@ export class Signal {
|
|
|
200
210
|
* Dispatch the signal to all registered listeners.
|
|
201
211
|
* @param {...any} args - Arguments to pass to the listeners.
|
|
202
212
|
*/
|
|
203
|
-
public dispatch(...args: unknown[]) {
|
|
213
|
+
public dispatch(...args: unknown[]): void {
|
|
204
214
|
if (!this.active || !this._bindings) {
|
|
205
215
|
return;
|
|
206
216
|
}
|
|
@@ -228,7 +238,7 @@ export class Signal {
|
|
|
228
238
|
* Clear any previously memorized arguments.
|
|
229
239
|
* This removes the stored arguments from a previous dispatch.
|
|
230
240
|
*/
|
|
231
|
-
public forget() {
|
|
241
|
+
public forget(): void {
|
|
232
242
|
if (this._prevParams) {
|
|
233
243
|
this._prevParams = null;
|
|
234
244
|
}
|
|
@@ -238,7 +248,7 @@ export class Signal {
|
|
|
238
248
|
* Dispose of the signal and clean up all resources.
|
|
239
249
|
* This method removes all listeners and clears internal state.
|
|
240
250
|
*/
|
|
241
|
-
public dispose() {
|
|
251
|
+
public dispose(): void {
|
|
242
252
|
this.removeAll();
|
|
243
253
|
this.forget();
|
|
244
254
|
this._bindings = null;
|
|
@@ -248,7 +258,7 @@ export class Signal {
|
|
|
248
258
|
* Get a string representation of the signal.
|
|
249
259
|
* @returns {string} A string representation of the signal.
|
|
250
260
|
*/
|
|
251
|
-
public toString() {
|
|
261
|
+
public toString(): string {
|
|
252
262
|
return `[Signal active:${this.active} numListeners:${this.getNumListeners()}]`;
|
|
253
263
|
}
|
|
254
264
|
|
|
@@ -258,7 +268,7 @@ export class Signal {
|
|
|
258
268
|
*/
|
|
259
269
|
public get boundDispatch() {
|
|
260
270
|
const _this = this;
|
|
261
|
-
this._boundDispatch ??= (...rest: unknown[]) => {
|
|
271
|
+
this._boundDispatch ??= (...rest: unknown[]): void => {
|
|
262
272
|
_this.dispatch(...rest);
|
|
263
273
|
};
|
|
264
274
|
return this._boundDispatch;
|
|
@@ -268,9 +278,9 @@ export class Signal {
|
|
|
268
278
|
* Promisify the Signal.
|
|
269
279
|
* @returns {Promise<any>} The resolved result.
|
|
270
280
|
*/
|
|
271
|
-
public toPromise() {
|
|
272
|
-
return new Promise((resolve) => {
|
|
273
|
-
this.addOnce((...args: unknown[]) => {
|
|
281
|
+
public toPromise(): Promise<unknown> {
|
|
282
|
+
return new Promise((resolve): void => {
|
|
283
|
+
this.addOnce((...args: unknown[]): void => {
|
|
274
284
|
resolve(args.length <= 1 ? args[0] : args);
|
|
275
285
|
}, this);
|
|
276
286
|
});
|
|
@@ -72,7 +72,7 @@ export class SignalBinding {
|
|
|
72
72
|
* TBD.
|
|
73
73
|
* @returns {boolean} TBD.
|
|
74
74
|
*/
|
|
75
|
-
public isBound() {
|
|
75
|
+
public isBound(): boolean {
|
|
76
76
|
return Boolean(this._signal) && Boolean(this._listener);
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -80,7 +80,7 @@ export class SignalBinding {
|
|
|
80
80
|
* TBD.
|
|
81
81
|
* @returns {boolean} TBD.
|
|
82
82
|
*/
|
|
83
|
-
public isOnce() {
|
|
83
|
+
public isOnce(): boolean {
|
|
84
84
|
return this._isOnce;
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -103,7 +103,7 @@ export class SignalBinding {
|
|
|
103
103
|
/**
|
|
104
104
|
* TBD.
|
|
105
105
|
*/
|
|
106
|
-
public _destroy() {
|
|
106
|
+
public _destroy(): void {
|
|
107
107
|
delete this._signal;
|
|
108
108
|
delete this._listener;
|
|
109
109
|
delete this.context;
|
|
@@ -113,7 +113,7 @@ export class SignalBinding {
|
|
|
113
113
|
* TBD.
|
|
114
114
|
* @returns {string} TBD.
|
|
115
115
|
*/
|
|
116
|
-
public toString() {
|
|
116
|
+
public toString(): string {
|
|
117
117
|
return `[SignalBinding isOnce:${this._isOnce}, isBound:${this.isBound()}, active:${this.active}]`;
|
|
118
118
|
}
|
|
119
119
|
}
|
package/src/phaser/core/sound.ts
CHANGED
|
@@ -2,13 +2,24 @@ import { Signal } from './signal.js';
|
|
|
2
2
|
import type { Game } from './game.js';
|
|
3
3
|
import type { Tween } from './tween.js';
|
|
4
4
|
|
|
5
|
+
/** A named span within a sound file. */
|
|
6
|
+
export type SoundMarker = {
|
|
7
|
+
name: string;
|
|
8
|
+
start: number;
|
|
9
|
+
stop: number;
|
|
10
|
+
volume: number;
|
|
11
|
+
duration: number;
|
|
12
|
+
durationMS: number;
|
|
13
|
+
loop: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
5
16
|
export class Sound {
|
|
6
|
-
public _paused!:
|
|
17
|
+
public _paused!: boolean;
|
|
7
18
|
public game!: Game;
|
|
8
19
|
public name!: string;
|
|
9
20
|
public key!: string;
|
|
10
21
|
public loop!: boolean;
|
|
11
|
-
public markers!:
|
|
22
|
+
public markers!: Record<string, SoundMarker>;
|
|
12
23
|
public context!: AudioContext | null;
|
|
13
24
|
public autoplay!: boolean;
|
|
14
25
|
public totalDuration!: number;
|
|
@@ -122,10 +133,12 @@ export class Sound {
|
|
|
122
133
|
* Callback when a sound has been unlocked.
|
|
123
134
|
* @param {string} key - The key of the sound that was unlocked.
|
|
124
135
|
*/
|
|
125
|
-
public soundHasUnlocked(key: string) {
|
|
136
|
+
public soundHasUnlocked(key: string): void {
|
|
126
137
|
if (key === this.key) {
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
// Unlocking parks the decoded buffer in _sound; play() replaces it with a real source node.
|
|
139
|
+
const buffer = this.game.cache.getSoundData(this.key) as AudioBuffer;
|
|
140
|
+
this._sound = buffer as unknown as AudioBufferSourceNode;
|
|
141
|
+
this.totalDuration = buffer.duration;
|
|
129
142
|
}
|
|
130
143
|
}
|
|
131
144
|
|
|
@@ -137,7 +150,7 @@ export class Sound {
|
|
|
137
150
|
* @param {number} volume - The volume level (0.0 to 1.0) of the marker.
|
|
138
151
|
* @param {boolean} loop - Whether the marker should loop.
|
|
139
152
|
*/
|
|
140
|
-
public addMarker(name: string, start: number, duration = 1, volume = 1, loop = false) {
|
|
153
|
+
public addMarker(name: string, start: number, duration = 1, volume = 1, loop = false): void {
|
|
141
154
|
this.markers[name] = {
|
|
142
155
|
name,
|
|
143
156
|
start,
|
|
@@ -153,14 +166,14 @@ export class Sound {
|
|
|
153
166
|
* Removes a marker from the sound.
|
|
154
167
|
* @param {string} name - The name of the marker to remove.
|
|
155
168
|
*/
|
|
156
|
-
public removeMarker(name: string) {
|
|
169
|
+
public removeMarker(name: string): void {
|
|
157
170
|
delete this.markers[name];
|
|
158
171
|
}
|
|
159
172
|
|
|
160
173
|
/**
|
|
161
174
|
* Handler for when the sound ends.
|
|
162
175
|
*/
|
|
163
|
-
public onEndedHandler() {
|
|
176
|
+
public onEndedHandler(): void {
|
|
164
177
|
this._sound.onended = null;
|
|
165
178
|
this.isPlaying = false;
|
|
166
179
|
this.currentTime = this.durationMS;
|
|
@@ -194,7 +207,7 @@ export class Sound {
|
|
|
194
207
|
/**
|
|
195
208
|
* Updates the sound state.
|
|
196
209
|
*/
|
|
197
|
-
public update() {
|
|
210
|
+
public update(): void {
|
|
198
211
|
if (!this.game.cache.checkSoundKey(this.key)) {
|
|
199
212
|
this.destroy();
|
|
200
213
|
return;
|
|
@@ -233,7 +246,7 @@ export class Sound {
|
|
|
233
246
|
* @param {number} volume - The volume level (0.0 to 1.0) to play at.
|
|
234
247
|
* @returns {Sound} This Sound instance for chaining.
|
|
235
248
|
*/
|
|
236
|
-
public loopFull(volume: number) {
|
|
249
|
+
public loopFull(volume: number): this {
|
|
237
250
|
return this.play(null, 0, volume, true);
|
|
238
251
|
}
|
|
239
252
|
|
|
@@ -246,7 +259,7 @@ export class Sound {
|
|
|
246
259
|
* @param {boolean} forceRestart - Whether to force restarting the sound even if it's already playing.
|
|
247
260
|
* @returns {Sound} This Sound instance for chaining.
|
|
248
261
|
*/
|
|
249
|
-
public play(marker:
|
|
262
|
+
public play(marker: string | false | null = '', position = 0, volume = 1, loop = false, forceRestart = true): this {
|
|
250
263
|
if (marker === undefined || marker === false || marker === null) {
|
|
251
264
|
marker = '';
|
|
252
265
|
}
|
|
@@ -274,15 +287,16 @@ export class Sound {
|
|
|
274
287
|
// We should never play the entire thing
|
|
275
288
|
return this;
|
|
276
289
|
}
|
|
290
|
+
const markerData = marker === '' ? undefined : this.markers[marker];
|
|
277
291
|
if (marker !== '') {
|
|
278
|
-
if (
|
|
292
|
+
if (markerData) {
|
|
279
293
|
this.currentMarker = marker;
|
|
280
294
|
// Playing a marker? Then we default to the marker values
|
|
281
|
-
this.position =
|
|
282
|
-
this.volume =
|
|
283
|
-
this.loop =
|
|
284
|
-
this.duration =
|
|
285
|
-
this.durationMS =
|
|
295
|
+
this.position = markerData.start;
|
|
296
|
+
this.volume = markerData.volume;
|
|
297
|
+
this.loop = markerData.loop;
|
|
298
|
+
this.duration = markerData.duration;
|
|
299
|
+
this.durationMS = markerData.durationMS;
|
|
286
300
|
if (volume !== undefined) {
|
|
287
301
|
this.volume = volume;
|
|
288
302
|
}
|
|
@@ -298,10 +312,8 @@ export class Sound {
|
|
|
298
312
|
return this;
|
|
299
313
|
}
|
|
300
314
|
} else {
|
|
301
|
-
position
|
|
302
|
-
|
|
303
|
-
volume = this._volume;
|
|
304
|
-
}
|
|
315
|
+
position ??= 0;
|
|
316
|
+
volume ??= this._volume;
|
|
305
317
|
if (loop === undefined) {
|
|
306
318
|
({ loop } = this);
|
|
307
319
|
}
|
|
@@ -323,7 +335,7 @@ export class Sound {
|
|
|
323
335
|
} else {
|
|
324
336
|
this._sound.connect(this.gainNode);
|
|
325
337
|
}
|
|
326
|
-
this._buffer = this.game.cache.getSoundData(this.key);
|
|
338
|
+
this._buffer = this.game.cache.getSoundData(this.key) as AudioBuffer | null;
|
|
327
339
|
this._sound.buffer = this._buffer;
|
|
328
340
|
if (this.loop && marker === '') {
|
|
329
341
|
this._sound.loop = true;
|
|
@@ -351,7 +363,7 @@ export class Sound {
|
|
|
351
363
|
this.onPlay.dispatch(this);
|
|
352
364
|
} else {
|
|
353
365
|
this.pendingPlayback = true;
|
|
354
|
-
if (this.game.cache.getSound(this.key)
|
|
366
|
+
if (this.game.cache.getSound(this.key)?.isDecoding === false) {
|
|
355
367
|
this.game.sound.decode(this.key);
|
|
356
368
|
}
|
|
357
369
|
}
|
|
@@ -365,14 +377,14 @@ export class Sound {
|
|
|
365
377
|
* @param {number} volume - The volume level (0.0 to 1.0) to play at.
|
|
366
378
|
* @param {boolean} loop - Whether the sound should loop.
|
|
367
379
|
*/
|
|
368
|
-
public restart(marker = '', position = 0, volume = 1, loop = false) {
|
|
380
|
+
public restart(marker = '', position = 0, volume = 1, loop = false): void {
|
|
369
381
|
this.play(marker, position, volume, loop, true);
|
|
370
382
|
}
|
|
371
383
|
|
|
372
384
|
/**
|
|
373
385
|
* Pauses the sound.
|
|
374
386
|
*/
|
|
375
|
-
public pause() {
|
|
387
|
+
public pause(): void {
|
|
376
388
|
if (this.isPlaying && this._sound) {
|
|
377
389
|
this.paused = true;
|
|
378
390
|
this.pausedPosition = this.currentTime;
|
|
@@ -386,7 +398,7 @@ export class Sound {
|
|
|
386
398
|
/**
|
|
387
399
|
* Resumes the sound.
|
|
388
400
|
*/
|
|
389
|
-
public resume() {
|
|
401
|
+
public resume(): void {
|
|
390
402
|
if (this.paused && this._sound) {
|
|
391
403
|
const p = Math.max(0, this.position + this.pausedPosition / 1000);
|
|
392
404
|
this._sound = this.context!.createBufferSource();
|
|
@@ -418,7 +430,7 @@ export class Sound {
|
|
|
418
430
|
/**
|
|
419
431
|
* Stops the sound.
|
|
420
432
|
*/
|
|
421
|
-
public stop() {
|
|
433
|
+
public stop(): void {
|
|
422
434
|
if (this.isPlaying && this._sound) {
|
|
423
435
|
if (this._sound.stop === undefined) {
|
|
424
436
|
(this._sound as any).noteOff(0);
|
|
@@ -452,7 +464,7 @@ export class Sound {
|
|
|
452
464
|
* @param {boolean} loop - Whether the sound should loop.
|
|
453
465
|
* @param {string} marker - The name of the marker to fade in, or empty string to use current marker.
|
|
454
466
|
*/
|
|
455
|
-
public fadeIn(duration: number, loop = false, marker: string = this.currentMarker) {
|
|
467
|
+
public fadeIn(duration: number, loop = false, marker: string = this.currentMarker): void {
|
|
456
468
|
if (this.paused) {
|
|
457
469
|
return;
|
|
458
470
|
}
|
|
@@ -464,7 +476,7 @@ export class Sound {
|
|
|
464
476
|
* Fades out the sound to silence.
|
|
465
477
|
* @param {number} duration - The fade-out duration (in milliseconds).
|
|
466
478
|
*/
|
|
467
|
-
public fadeOut(duration: number) {
|
|
479
|
+
public fadeOut(duration: number): void {
|
|
468
480
|
this.fadeTo(duration, 0);
|
|
469
481
|
}
|
|
470
482
|
|
|
@@ -473,7 +485,7 @@ export class Sound {
|
|
|
473
485
|
* @param {number} duration - The fade duration (in milliseconds).
|
|
474
486
|
* @param {number} volume - The target volume level (0.0 to 1.0).
|
|
475
487
|
*/
|
|
476
|
-
public fadeTo(duration = 100, volume = 0) {
|
|
488
|
+
public fadeTo(duration = 100, volume = 0): void {
|
|
477
489
|
if (!this.isPlaying || this.paused || volume === this.volume) {
|
|
478
490
|
return;
|
|
479
491
|
}
|
|
@@ -484,7 +496,7 @@ export class Sound {
|
|
|
484
496
|
/**
|
|
485
497
|
* Callback when fade completes.
|
|
486
498
|
*/
|
|
487
|
-
public fadeComplete() {
|
|
499
|
+
public fadeComplete(): void {
|
|
488
500
|
this.onFadeComplete.dispatch(this, this.volume);
|
|
489
501
|
if (this.volume === 0) {
|
|
490
502
|
this.stop();
|
|
@@ -495,7 +507,7 @@ export class Sound {
|
|
|
495
507
|
* Destroys the sound and cleans up resources.
|
|
496
508
|
* @param {boolean} remove - Whether to remove the sound from the SoundManager.
|
|
497
509
|
*/
|
|
498
|
-
public destroy(remove = true) {
|
|
510
|
+
public destroy(remove = true): void {
|
|
499
511
|
this._markedToDelete = true;
|
|
500
512
|
this._removeFromSoundManager = remove;
|
|
501
513
|
this.stop();
|
|
@@ -548,7 +560,7 @@ export class Sound {
|
|
|
548
560
|
* Gets the volume of the sound.
|
|
549
561
|
* @returns {number} The volume level (0.0 to 1.0).
|
|
550
562
|
*/
|
|
551
|
-
public get volume() {
|
|
563
|
+
public get volume(): number {
|
|
552
564
|
return this._volume;
|
|
553
565
|
}
|
|
554
566
|
|