@vpmedia/phaser 1.94.0 → 1.96.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/CHANGELOG.md +41 -0
- package/package.json +11 -11
- package/src/phaser/core/animation.js +79 -56
- package/src/phaser/core/animation_manager.js +55 -55
- package/src/phaser/core/animation_parser.js +2 -2
- package/src/phaser/core/cache.js +154 -154
- package/src/phaser/core/device.js +2 -1
- package/src/phaser/core/device_util.js +27 -27
- package/src/phaser/core/dom.js +43 -43
- package/src/phaser/core/event_manager.js +63 -63
- package/src/phaser/core/factory.js +47 -47
- package/src/phaser/core/frame.js +30 -30
- package/src/phaser/core/frame_data.js +30 -28
- package/src/phaser/core/frame_util.js +8 -8
- package/src/phaser/core/game.js +35 -19
- package/src/phaser/core/input_pointer.js +18 -0
- package/src/phaser/core/loader.js +171 -171
- package/src/phaser/core/loader_parser.js +22 -22
- package/src/phaser/core/raf.js +1 -1
- package/src/phaser/core/scale_manager.js +3 -2
- package/src/phaser/core/scene.js +16 -10
- package/src/phaser/core/scene_manager.js +51 -43
- package/src/phaser/core/signal.js +56 -52
- package/src/phaser/core/sound.js +54 -54
- package/src/phaser/core/sound_manager.js +49 -49
- package/src/phaser/core/stage.js +16 -16
- package/src/phaser/core/time.js +54 -30
- package/src/phaser/core/timer.js +82 -64
- package/src/phaser/core/timer_event.js +9 -9
- package/src/phaser/core/tween.js +106 -90
- package/src/phaser/core/tween_data.js +30 -30
- package/src/phaser/core/tween_manager.js +32 -24
- package/src/phaser/core/world.js +4 -3
- package/src/phaser/display/bitmap_text.js +72 -54
- package/src/phaser/display/button.js +48 -47
- package/src/phaser/display/canvas/buffer.js +8 -8
- package/src/phaser/display/canvas/graphics.js +8 -8
- package/src/phaser/display/canvas/masker.js +5 -5
- package/src/phaser/display/canvas/pool.js +18 -18
- package/src/phaser/display/canvas/renderer.js +17 -16
- package/src/phaser/display/canvas/tinter.js +22 -22
- package/src/phaser/display/canvas/util.js +42 -42
- package/src/phaser/display/display_object.js +119 -108
- package/src/phaser/display/graphics.js +129 -112
- package/src/phaser/display/graphics_data.js +10 -10
- package/src/phaser/display/graphics_data_util.js +3 -3
- package/src/phaser/display/group.js +63 -50
- package/src/phaser/display/image.js +68 -50
- package/src/phaser/display/sprite_batch.js +2 -2
- package/src/phaser/display/sprite_util.js +19 -19
- package/src/phaser/display/text.js +217 -187
- package/src/phaser/display/webgl/abstract_filter.js +4 -4
- package/src/phaser/display/webgl/base_texture.js +9 -9
- package/src/phaser/display/webgl/blend_manager.js +7 -7
- package/src/phaser/display/webgl/earcut.js +95 -95
- package/src/phaser/display/webgl/earcut_node.js +4 -4
- package/src/phaser/display/webgl/fast_sprite_batch.js +15 -15
- package/src/phaser/display/webgl/filter_manager.js +9 -9
- package/src/phaser/display/webgl/filter_texture.js +10 -10
- package/src/phaser/display/webgl/graphics.js +37 -37
- package/src/phaser/display/webgl/graphics_data.js +4 -4
- package/src/phaser/display/webgl/mask_manager.js +6 -6
- package/src/phaser/display/webgl/render_texture.js +16 -16
- package/src/phaser/display/webgl/renderer.js +21 -20
- package/src/phaser/display/webgl/shader/complex.js +4 -4
- package/src/phaser/display/webgl/shader/fast.js +4 -4
- package/src/phaser/display/webgl/shader/normal.js +8 -8
- package/src/phaser/display/webgl/shader/primitive.js +4 -4
- package/src/phaser/display/webgl/shader/strip.js +4 -4
- package/src/phaser/display/webgl/shader_manager.js +9 -9
- package/src/phaser/display/webgl/sprite_batch.js +18 -18
- package/src/phaser/display/webgl/stencil_manager.js +16 -16
- package/src/phaser/display/webgl/texture.js +13 -13
- package/src/phaser/display/webgl/texture_util.js +8 -8
- package/src/phaser/display/webgl/util.js +25 -25
- package/src/phaser/geom/circle.js +74 -69
- package/src/phaser/geom/ellipse.js +33 -28
- package/src/phaser/geom/line.js +96 -93
- package/src/phaser/geom/matrix.js +61 -54
- package/src/phaser/geom/point.js +99 -96
- package/src/phaser/geom/polygon.js +27 -22
- package/src/phaser/geom/rectangle.js +137 -132
- package/src/phaser/geom/rounded_rectangle.js +12 -12
- package/src/phaser/geom/util/circle.js +33 -33
- package/src/phaser/geom/util/ellipse.js +5 -5
- package/src/phaser/geom/util/line.js +26 -26
- package/src/phaser/geom/util/matrix.js +8 -8
- package/src/phaser/geom/util/point.js +97 -97
- package/src/phaser/geom/util/polygon.js +4 -4
- package/src/phaser/geom/util/rectangle.js +74 -74
- package/src/phaser/geom/util/rounded_rectangle.js +4 -4
- package/src/phaser/util/math.js +81 -81
- package/types/phaser/core/animation.d.ts +79 -56
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +55 -55
- package/types/phaser/core/animation_parser.d.ts +3 -2
- package/types/phaser/core/animation_parser.d.ts.map +1 -1
- package/types/phaser/core/cache.d.ts +154 -154
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +51 -44
- package/types/phaser/core/dom.d.ts.map +1 -1
- package/types/phaser/core/event_manager.d.ts +63 -63
- package/types/phaser/core/factory.d.ts +47 -47
- package/types/phaser/core/frame.d.ts +30 -30
- package/types/phaser/core/frame_data.d.ts +28 -27
- package/types/phaser/core/frame_data.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts +54 -21
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/input_pointer.d.ts +18 -0
- package/types/phaser/core/input_pointer.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +175 -172
- package/types/phaser/core/loader.d.ts.map +1 -1
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +1 -1
- package/types/phaser/core/scale_manager.d.ts +6 -5
- package/types/phaser/core/scale_manager.d.ts.map +1 -1
- package/types/phaser/core/scene.d.ts +15 -9
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +51 -43
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +54 -51
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +54 -54
- package/types/phaser/core/sound_manager.d.ts +49 -49
- package/types/phaser/core/stage.d.ts +10 -10
- package/types/phaser/core/time.d.ts +54 -30
- package/types/phaser/core/time.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +82 -64
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/core/timer_event.d.ts +9 -9
- package/types/phaser/core/tween.d.ts +106 -90
- package/types/phaser/core/tween.d.ts.map +1 -1
- package/types/phaser/core/tween_data.d.ts +30 -30
- package/types/phaser/core/tween_manager.d.ts +35 -67
- package/types/phaser/core/tween_manager.d.ts.map +1 -1
- package/types/phaser/core/world.d.ts +4 -3
- package/types/phaser/core/world.d.ts.map +1 -1
- package/types/phaser/display/bitmap_text.d.ts +76 -53
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +47 -46
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts +8 -8
- package/types/phaser/display/canvas/graphics.d.ts +3 -3
- package/types/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/types/phaser/display/canvas/pool.d.ts +6 -3
- package/types/phaser/display/canvas/pool.d.ts.map +1 -1
- package/types/phaser/display/canvas/renderer.d.ts +18 -17
- package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts +6 -6
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +119 -108
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +118 -102
- package/types/phaser/display/graphics.d.ts.map +1 -1
- package/types/phaser/display/graphics_data.d.ts +10 -10
- package/types/phaser/display/group.d.ts +59 -47
- package/types/phaser/display/group.d.ts.map +1 -1
- package/types/phaser/display/image.d.ts +58 -45
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +237 -188
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/abstract_filter.d.ts +4 -4
- package/types/phaser/display/webgl/base_texture.d.ts +10 -10
- package/types/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/blend_manager.d.ts +6 -6
- package/types/phaser/display/webgl/earcut.d.ts +95 -95
- package/types/phaser/display/webgl/earcut_node.d.ts +4 -4
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +15 -15
- package/types/phaser/display/webgl/filter_manager.d.ts +8 -8
- package/types/phaser/display/webgl/filter_texture.d.ts +10 -10
- package/types/phaser/display/webgl/graphics.d.ts +2 -2
- package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics_data.d.ts +4 -4
- package/types/phaser/display/webgl/render_texture.d.ts +16 -16
- package/types/phaser/display/webgl/renderer.d.ts +21 -20
- package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +4 -4
- package/types/phaser/display/webgl/shader/fast.d.ts +4 -4
- package/types/phaser/display/webgl/shader/normal.d.ts +8 -8
- package/types/phaser/display/webgl/shader/primitive.d.ts +4 -4
- package/types/phaser/display/webgl/shader/strip.d.ts +4 -4
- package/types/phaser/display/webgl/shader_manager.d.ts +8 -8
- package/types/phaser/display/webgl/sprite_batch.d.ts +17 -17
- package/types/phaser/display/webgl/stencil_manager.d.ts +15 -15
- package/types/phaser/display/webgl/texture.d.ts +12 -12
- package/types/phaser/display/webgl/texture_util.d.ts +4 -2
- package/types/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/types/phaser/geom/circle.d.ts +74 -69
- package/types/phaser/geom/circle.d.ts.map +1 -1
- package/types/phaser/geom/ellipse.d.ts +33 -28
- package/types/phaser/geom/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/line.d.ts +96 -93
- package/types/phaser/geom/line.d.ts.map +1 -1
- package/types/phaser/geom/matrix.d.ts +61 -54
- package/types/phaser/geom/matrix.d.ts.map +1 -1
- package/types/phaser/geom/point.d.ts +99 -96
- package/types/phaser/geom/point.d.ts.map +1 -1
- package/types/phaser/geom/polygon.d.ts +29 -23
- package/types/phaser/geom/polygon.d.ts.map +1 -1
- package/types/phaser/geom/rectangle.d.ts +137 -132
- package/types/phaser/geom/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
- package/types/phaser/geom/util/point.d.ts +1 -1
- package/types/phaser/geom/util/point.d.ts.map +1 -1
- package/pnpm-workspace.yaml +0 -4
|
@@ -2,10 +2,10 @@ import { Texture } from '../display/webgl/texture.js';
|
|
|
2
2
|
import { Rectangle } from '../geom/rectangle.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture -
|
|
7
|
-
* @param {object} bitmapFontData -
|
|
8
|
-
* @returns {object}
|
|
5
|
+
* Finalizes bitmap font data by attaching textures to characters.
|
|
6
|
+
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture - The base texture for the font.
|
|
7
|
+
* @param {object} bitmapFontData - The bitmap font data to finalize.
|
|
8
|
+
* @returns {object} The finalized bitmap font data.
|
|
9
9
|
*/
|
|
10
10
|
export const finalizeBitmapFont = (baseTexture, bitmapFontData) => {
|
|
11
11
|
Object.keys(bitmapFontData.chars).forEach((charCode) => {
|
|
@@ -16,12 +16,12 @@ export const finalizeBitmapFont = (baseTexture, bitmapFontData) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param {object} xml -
|
|
21
|
-
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture -
|
|
22
|
-
* @param {number} xSpacing -
|
|
23
|
-
* @param {number} ySpacing -
|
|
24
|
-
* @returns {object}
|
|
19
|
+
* Parses XML bitmap font data.
|
|
20
|
+
* @param {object} xml - The XML document containing the bitmap font data.
|
|
21
|
+
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture - The base texture for the font.
|
|
22
|
+
* @param {number} xSpacing - Horizontal spacing between characters.
|
|
23
|
+
* @param {number} ySpacing - Vertical spacing between characters.
|
|
24
|
+
* @returns {object} The parsed bitmap font data.
|
|
25
25
|
*/
|
|
26
26
|
export const xmlBitmapFont = (xml, baseTexture, xSpacing, ySpacing) => {
|
|
27
27
|
const data = {};
|
|
@@ -56,24 +56,24 @@ export const xmlBitmapFont = (xml, baseTexture, xSpacing, ySpacing) => {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param {object} xml -
|
|
61
|
-
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture -
|
|
62
|
-
* @param {number} xSpacing -
|
|
63
|
-
* @param {number} ySpacing -
|
|
64
|
-
* @returns {object}
|
|
59
|
+
* Parses XML bitmap font data (alias for xmlBitmapFont).
|
|
60
|
+
* @param {object} xml - The XML document containing the bitmap font data.
|
|
61
|
+
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture - The base texture for the font.
|
|
62
|
+
* @param {number} xSpacing - Horizontal spacing between characters.
|
|
63
|
+
* @param {number} ySpacing - Vertical spacing between characters.
|
|
64
|
+
* @returns {object} The parsed bitmap font data.
|
|
65
65
|
*/
|
|
66
66
|
export const bitmapFont = (xml, baseTexture, xSpacing, ySpacing) => {
|
|
67
67
|
return xmlBitmapFont(xml, baseTexture, xSpacing, ySpacing);
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @param {object} json -
|
|
73
|
-
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture -
|
|
74
|
-
* @param {number} xSpacing -
|
|
75
|
-
* @param {number} ySpacing -
|
|
76
|
-
* @returns {object}
|
|
71
|
+
* Parses JSON bitmap font data.
|
|
72
|
+
* @param {object} json - The JSON object containing the bitmap font data.
|
|
73
|
+
* @param {import('../display/webgl/base_texture.js').BaseTexture} baseTexture - The base texture for the font.
|
|
74
|
+
* @param {number} xSpacing - Horizontal spacing between characters.
|
|
75
|
+
* @param {number} ySpacing - Vertical spacing between characters.
|
|
76
|
+
* @returns {object} The parsed bitmap font data.
|
|
77
77
|
*/
|
|
78
78
|
export const jsonBitmapFont = (json, baseTexture, xSpacing, ySpacing) => {
|
|
79
79
|
const data = {
|
package/src/phaser/core/raf.js
CHANGED
|
@@ -24,7 +24,7 @@ export class RequestAnimationFrame {
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Performs an animation frame request.
|
|
27
|
-
* @param {number} rafTime -
|
|
27
|
+
* @param {number} rafTime - The timestamp provided by the browser's animation frame.
|
|
28
28
|
*/
|
|
29
29
|
update = (rafTime) => {
|
|
30
30
|
this.game.update(rafTime);
|
|
@@ -49,6 +49,7 @@ export class ScaleManager {
|
|
|
49
49
|
this.bounds = new Rectangle();
|
|
50
50
|
this.aspectRatio = 0;
|
|
51
51
|
this.sourceAspectRatio = 0;
|
|
52
|
+
/** @type {Event | null | undefined} */
|
|
52
53
|
this.event = null;
|
|
53
54
|
this.windowConstraints = {
|
|
54
55
|
right: 'layout',
|
|
@@ -840,7 +841,7 @@ export class ScaleManager {
|
|
|
840
841
|
|
|
841
842
|
/**
|
|
842
843
|
* TBD.
|
|
843
|
-
* @param {Event} event - TBD.
|
|
844
|
+
* @param {Event} [event] - TBD.
|
|
844
845
|
*/
|
|
845
846
|
fullScreenError(event) {
|
|
846
847
|
this.event = event;
|
|
@@ -870,7 +871,7 @@ export class ScaleManager {
|
|
|
870
871
|
|
|
871
872
|
/**
|
|
872
873
|
* TBD.
|
|
873
|
-
* @returns {
|
|
874
|
+
* @returns {ParentNode | null} TBD.
|
|
874
875
|
*/
|
|
875
876
|
get boundingParent() {
|
|
876
877
|
if (this.parentIsWindow || (this.isFullScreen && this.hasPhaserSetFullScreen && !this._createdFullScreenTarget)) {
|
package/src/phaser/core/scene.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export class Scene {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Creates a new Scene instance.
|
|
4
4
|
*/
|
|
5
5
|
constructor() {
|
|
6
6
|
this.game = null;
|
|
@@ -8,51 +8,57 @@ export class Scene {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Initialize the scene.
|
|
12
|
+
* This method is called before preload() and create().
|
|
12
13
|
*/
|
|
13
14
|
init() {
|
|
14
15
|
// inherit
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* Load assets for the scene.
|
|
20
|
+
* This method is called after init() and before create().
|
|
19
21
|
*/
|
|
20
22
|
preload() {
|
|
21
23
|
// inherit
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
27
|
+
* Create the scene.
|
|
28
|
+
* This method is called after preload() and is where you create your game objects.
|
|
26
29
|
*/
|
|
27
30
|
create() {
|
|
28
31
|
// inherit
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
|
-
*
|
|
35
|
+
* Update the scene.
|
|
36
|
+
* This method is called every frame while the scene is active.
|
|
33
37
|
*/
|
|
34
38
|
update() {
|
|
35
39
|
// inherit
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param {number} width -
|
|
41
|
-
* @param {number} height -
|
|
43
|
+
* Handle scene resize.
|
|
44
|
+
* @param {number} width - The new width of the scene.
|
|
45
|
+
* @param {number} height - The new height of the scene.
|
|
42
46
|
*/
|
|
43
47
|
resize(width, height) {
|
|
44
48
|
// inherit
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
/**
|
|
48
|
-
*
|
|
52
|
+
* Update the scene while paused.
|
|
53
|
+
* This method is called every frame while the scene is paused.
|
|
49
54
|
*/
|
|
50
55
|
pauseUpdate() {
|
|
51
56
|
// inherit
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/**
|
|
55
|
-
*
|
|
60
|
+
* Shutdown the scene.
|
|
61
|
+
* This method is called when the scene is about to be destroyed.
|
|
56
62
|
*/
|
|
57
63
|
shutdown() {
|
|
58
64
|
// inherit
|
|
@@ -2,9 +2,9 @@ import { Scene } from './scene.js';
|
|
|
2
2
|
|
|
3
3
|
export class SceneManager {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {import('./game.js').Game} game -
|
|
7
|
-
* @param {string} pendingState -
|
|
5
|
+
* Creates a new SceneManager instance.
|
|
6
|
+
* @param {import('./game.js').Game} game - The game instance this manager belongs to.
|
|
7
|
+
* @param {string} pendingState - The state to load when the game boots.
|
|
8
8
|
*/
|
|
9
9
|
constructor(game, pendingState) {
|
|
10
10
|
this.game = game;
|
|
@@ -28,7 +28,8 @@ export class SceneManager {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Initialize the scene manager.
|
|
32
|
+
* This method is called when the game boots and sets up the initial state.
|
|
32
33
|
*/
|
|
33
34
|
boot() {
|
|
34
35
|
if (this._pendingState !== null && typeof this._pendingState !== 'string') {
|
|
@@ -37,11 +38,11 @@ export class SceneManager {
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param {string} key -
|
|
42
|
-
* @param {object} state -
|
|
43
|
-
* @param {boolean} autoStart -
|
|
44
|
-
* @returns {Scene|object}
|
|
41
|
+
* Add a new scene state to the manager.
|
|
42
|
+
* @param {string} key - The unique key for this state.
|
|
43
|
+
* @param {object} state - The scene state to add.
|
|
44
|
+
* @param {boolean} autoStart - Whether to start this state immediately.
|
|
45
|
+
* @returns {Scene|object} The created scene or state object.
|
|
45
46
|
*/
|
|
46
47
|
add(key, state, autoStart = false) {
|
|
47
48
|
let newState = null;
|
|
@@ -65,8 +66,8 @@ export class SceneManager {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {string} key -
|
|
69
|
+
* Remove a scene state from the manager.
|
|
70
|
+
* @param {string} key - The unique key for the state to remove.
|
|
70
71
|
*/
|
|
71
72
|
remove(key) {
|
|
72
73
|
if (this.current === key) {
|
|
@@ -83,11 +84,11 @@ export class SceneManager {
|
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
|
-
*
|
|
87
|
-
* @param {string} key -
|
|
88
|
-
* @param {boolean} clearWorld -
|
|
89
|
-
* @param {boolean} clearCache -
|
|
90
|
-
* @param {...any} args -
|
|
87
|
+
* Start a scene state.
|
|
88
|
+
* @param {string} key - The unique key for the state to start.
|
|
89
|
+
* @param {boolean} clearWorld - Whether to clear the world before starting.
|
|
90
|
+
* @param {boolean} clearCache - Whether to clear the cache before starting.
|
|
91
|
+
* @param {...any} args - Additional arguments to pass to the state.
|
|
91
92
|
*/
|
|
92
93
|
start(key, clearWorld = true, clearCache = false, ...args) {
|
|
93
94
|
if (this.checkState(key)) {
|
|
@@ -102,10 +103,10 @@ export class SceneManager {
|
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
/**
|
|
105
|
-
*
|
|
106
|
-
* @param {boolean} clearWorld -
|
|
107
|
-
* @param {boolean} clearCache -
|
|
108
|
-
* @param {...any} args -
|
|
106
|
+
* Restart the current scene state.
|
|
107
|
+
* @param {boolean} clearWorld - Whether to clear the world before restarting.
|
|
108
|
+
* @param {boolean} clearCache - Whether to clear the cache before restarting.
|
|
109
|
+
* @param {...any} args - Additional arguments to pass to the state.
|
|
109
110
|
*/
|
|
110
111
|
restart(clearWorld = true, clearCache = false, ...args) {
|
|
111
112
|
this._pendingState = this.current;
|
|
@@ -117,7 +118,8 @@ export class SceneManager {
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
/**
|
|
120
|
-
*
|
|
121
|
+
* Pre-update the scene manager.
|
|
122
|
+
* This method is called before the game loop updates.
|
|
121
123
|
*/
|
|
122
124
|
preUpdate() {
|
|
123
125
|
if (this._pendingState && this.game.isBooted) {
|
|
@@ -151,7 +153,8 @@ export class SceneManager {
|
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
/**
|
|
154
|
-
*
|
|
156
|
+
* Clear the current scene state.
|
|
157
|
+
* This method is called when switching scenes to clean up the previous scene.
|
|
155
158
|
*/
|
|
156
159
|
clearCurrentState() {
|
|
157
160
|
if (this.current) {
|
|
@@ -172,9 +175,9 @@ export class SceneManager {
|
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
/**
|
|
175
|
-
*
|
|
176
|
-
* @param {string} key -
|
|
177
|
-
* @returns {boolean}
|
|
178
|
+
* Check if a scene state exists.
|
|
179
|
+
* @param {string} key - The unique key for the state to check.
|
|
180
|
+
* @returns {boolean} True if the scene exists, false otherwise.
|
|
178
181
|
*/
|
|
179
182
|
checkState(key) {
|
|
180
183
|
if (this.states[key]) {
|
|
@@ -187,8 +190,8 @@ export class SceneManager {
|
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
/**
|
|
190
|
-
*
|
|
191
|
-
* @param {string} key -
|
|
193
|
+
* Link a scene state to the manager.
|
|
194
|
+
* @param {string} key - The unique key for the state to link.
|
|
192
195
|
*/
|
|
193
196
|
link(key) {
|
|
194
197
|
this.states[key].game = this.game;
|
|
@@ -196,8 +199,8 @@ export class SceneManager {
|
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
/**
|
|
199
|
-
*
|
|
200
|
-
* @param {string} key -
|
|
202
|
+
* Unlink a scene state from the manager.
|
|
203
|
+
* @param {string} key - The unique key for the state to unlink.
|
|
201
204
|
*/
|
|
202
205
|
unlink(key) {
|
|
203
206
|
if (this.states[key]) {
|
|
@@ -206,8 +209,8 @@ export class SceneManager {
|
|
|
206
209
|
}
|
|
207
210
|
|
|
208
211
|
/**
|
|
209
|
-
*
|
|
210
|
-
* @param {string} key -
|
|
212
|
+
* Set the current scene state.
|
|
213
|
+
* @param {string} key - The unique key for the state to set as current.
|
|
211
214
|
*/
|
|
212
215
|
setCurrentState(key) {
|
|
213
216
|
this.callbackContext = this.states[key];
|
|
@@ -230,15 +233,16 @@ export class SceneManager {
|
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
/**
|
|
233
|
-
*
|
|
234
|
-
* @returns {Scene}
|
|
236
|
+
* Get the current scene state.
|
|
237
|
+
* @returns {Scene} The current scene state.
|
|
235
238
|
*/
|
|
236
239
|
getCurrentState() {
|
|
237
240
|
return this.states[this.current];
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
/**
|
|
241
|
-
*
|
|
244
|
+
* Handle loading completion.
|
|
245
|
+
* This method is called when scene loading is complete.
|
|
242
246
|
*/
|
|
243
247
|
loadComplete() {
|
|
244
248
|
if (this._created === false && this.onCreateCallback) {
|
|
@@ -250,7 +254,8 @@ export class SceneManager {
|
|
|
250
254
|
}
|
|
251
255
|
|
|
252
256
|
/**
|
|
253
|
-
*
|
|
257
|
+
* Update the scene manager.
|
|
258
|
+
* This method is called every frame while the game is running.
|
|
254
259
|
*/
|
|
255
260
|
update() {
|
|
256
261
|
if (this._created && this.onUpdateCallback) {
|
|
@@ -259,7 +264,8 @@ export class SceneManager {
|
|
|
259
264
|
}
|
|
260
265
|
|
|
261
266
|
/**
|
|
262
|
-
*
|
|
267
|
+
* Pause the scene manager updates.
|
|
268
|
+
* This method is called when the game is paused.
|
|
263
269
|
*/
|
|
264
270
|
pauseUpdate() {
|
|
265
271
|
if (this._created && this.onPauseUpdateCallback) {
|
|
@@ -268,9 +274,9 @@ export class SceneManager {
|
|
|
268
274
|
}
|
|
269
275
|
|
|
270
276
|
/**
|
|
271
|
-
*
|
|
272
|
-
* @param {number} width -
|
|
273
|
-
* @param {number} height -
|
|
277
|
+
* Handle scene resize.
|
|
278
|
+
* @param {number} width - The new width of the scene.
|
|
279
|
+
* @param {number} height - The new height of the scene.
|
|
274
280
|
*/
|
|
275
281
|
resize(width, height) {
|
|
276
282
|
if (this.onResizeCallback) {
|
|
@@ -279,7 +285,8 @@ export class SceneManager {
|
|
|
279
285
|
}
|
|
280
286
|
|
|
281
287
|
/**
|
|
282
|
-
*
|
|
288
|
+
* Destroy the scene manager.
|
|
289
|
+
* This method is called when the scene manager is about to be destroyed.
|
|
283
290
|
*/
|
|
284
291
|
destroy() {
|
|
285
292
|
this._clearWorld = true;
|
|
@@ -299,15 +306,16 @@ export class SceneManager {
|
|
|
299
306
|
}
|
|
300
307
|
|
|
301
308
|
/**
|
|
302
|
-
*
|
|
309
|
+
* Dummy function for callbacks.
|
|
310
|
+
* This is a placeholder function used when no callback is defined.
|
|
303
311
|
*/
|
|
304
312
|
dummy() {
|
|
305
313
|
// pass
|
|
306
314
|
}
|
|
307
315
|
|
|
308
316
|
/**
|
|
309
|
-
*
|
|
310
|
-
* @returns {boolean}
|
|
317
|
+
* Get whether the scene has been created.
|
|
318
|
+
* @returns {boolean} True if the scene has been created, false otherwise.
|
|
311
319
|
*/
|
|
312
320
|
get created() {
|
|
313
321
|
return this._created;
|
|
@@ -2,7 +2,8 @@ import { SignalBinding } from './signal_binding.js';
|
|
|
2
2
|
|
|
3
3
|
export class Signal {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Creates a new Signal instance.
|
|
6
|
+
* A Signal is a simple event system that allows you to dispatch events and listen for them.
|
|
6
7
|
*/
|
|
7
8
|
constructor() {
|
|
8
9
|
this._bindings = null;
|
|
@@ -14,10 +15,10 @@ export class Signal {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {Function} listener -
|
|
19
|
-
* @param {string} fnName -
|
|
20
|
-
* @throws {Error}
|
|
18
|
+
* Validates that a listener is a function.
|
|
19
|
+
* @param {Function} listener - The listener to validate.
|
|
20
|
+
* @param {string} fnName - The name of the function this validation is for.
|
|
21
|
+
* @throws {Error} If the listener is not a function.
|
|
21
22
|
*/
|
|
22
23
|
validateListener(listener, fnName) {
|
|
23
24
|
if (typeof listener !== 'function') {
|
|
@@ -28,14 +29,14 @@ export class Signal {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
-
* @param {Function} listener -
|
|
33
|
-
* @param {boolean} isOnce -
|
|
34
|
-
* @param {object} listenerContext -
|
|
35
|
-
* @param {number} priority -
|
|
36
|
-
* @param {...any} args -
|
|
37
|
-
* @returns {SignalBinding}
|
|
38
|
-
* @throws {Error}
|
|
32
|
+
* Register a new listener with the signal.
|
|
33
|
+
* @param {Function} listener - The function to call when the signal is dispatched.
|
|
34
|
+
* @param {boolean} isOnce - Whether the listener should only be called once.
|
|
35
|
+
* @param {object} listenerContext - The context to apply when calling the listener.
|
|
36
|
+
* @param {number} priority - The priority of this listener (higher numbers execute first).
|
|
37
|
+
* @param {...any} args - Additional arguments to pass to the listener.
|
|
38
|
+
* @returns {SignalBinding} The binding for this listener.
|
|
39
|
+
* @throws {Error} If the listener is already registered with a different once setting.
|
|
39
40
|
*/
|
|
40
41
|
_registerListener(listener, isOnce = false, listenerContext = null, priority = 0, args = null) {
|
|
41
42
|
const prevIndex = this._indexOfListener(listener, listenerContext);
|
|
@@ -60,8 +61,8 @@ export class Signal {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @param {SignalBinding} binding -
|
|
64
|
+
* Add a binding to the list of listeners.
|
|
65
|
+
* @param {SignalBinding} binding - The binding to add.
|
|
65
66
|
*/
|
|
66
67
|
_addBinding(binding) {
|
|
67
68
|
if (!this._bindings) {
|
|
@@ -76,10 +77,10 @@ export class Signal {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @param {Function} listener -
|
|
81
|
-
* @param {object} context -
|
|
82
|
-
* @returns {number}
|
|
80
|
+
* Find the index of a listener in the bindings array.
|
|
81
|
+
* @param {Function} listener - The listener to find.
|
|
82
|
+
* @param {object} context - The context of the listener.
|
|
83
|
+
* @returns {number} The index of the listener in the bindings array, or -1 if not found.
|
|
83
84
|
*/
|
|
84
85
|
_indexOfListener(listener, context = null) {
|
|
85
86
|
if (!this._bindings) {
|
|
@@ -98,22 +99,22 @@ export class Signal {
|
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {Function} listener -
|
|
103
|
-
* @param {object} context -
|
|
104
|
-
* @returns {boolean}
|
|
102
|
+
* Check if a listener is registered with the signal.
|
|
103
|
+
* @param {Function} listener - The listener to check.
|
|
104
|
+
* @param {object} context - The context of the listener.
|
|
105
|
+
* @returns {boolean} True if the listener is registered, false otherwise.
|
|
105
106
|
*/
|
|
106
107
|
has(listener, context = null) {
|
|
107
108
|
return this._indexOfListener(listener, context) !== -1;
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
/**
|
|
111
|
-
*
|
|
112
|
-
* @param {Function} listener -
|
|
113
|
-
* @param {object} listenerContext -
|
|
114
|
-
* @param {number} priority -
|
|
115
|
-
* @param {...any} args -
|
|
116
|
-
* @returns {SignalBinding}
|
|
112
|
+
* Add a listener that will be called every time the signal is dispatched.
|
|
113
|
+
* @param {Function} listener - The function to call when the signal is dispatched.
|
|
114
|
+
* @param {object} listenerContext - The context to apply when calling the listener.
|
|
115
|
+
* @param {number} priority - The priority of this listener (higher numbers execute first).
|
|
116
|
+
* @param {...any} args - Additional arguments to pass to the listener.
|
|
117
|
+
* @returns {SignalBinding} The binding for this listener.
|
|
117
118
|
*/
|
|
118
119
|
add(listener, listenerContext = null, priority = 0, ...args) {
|
|
119
120
|
this.validateListener(listener, 'add');
|
|
@@ -121,12 +122,12 @@ export class Signal {
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
/**
|
|
124
|
-
*
|
|
125
|
-
* @param {Function} listener -
|
|
126
|
-
* @param {object} listenerContext -
|
|
127
|
-
* @param {number} priority -
|
|
128
|
-
* @param {...any} args -
|
|
129
|
-
* @returns {SignalBinding}
|
|
125
|
+
* Add a listener that will be called only once when the signal is dispatched.
|
|
126
|
+
* @param {Function} listener - The function to call when the signal is dispatched.
|
|
127
|
+
* @param {object} listenerContext - The context to apply when calling the listener.
|
|
128
|
+
* @param {number} priority - The priority of this listener (higher numbers execute first).
|
|
129
|
+
* @param {...any} args - Additional arguments to pass to the listener.
|
|
130
|
+
* @returns {SignalBinding} The binding for this listener.
|
|
130
131
|
*/
|
|
131
132
|
addOnce(listener, listenerContext = null, priority = 0, ...args) {
|
|
132
133
|
this.validateListener(listener, 'addOnce');
|
|
@@ -134,10 +135,10 @@ export class Signal {
|
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @param {Function} listener -
|
|
139
|
-
* @param {object} context -
|
|
140
|
-
* @returns {Function}
|
|
138
|
+
* Remove a listener from the signal.
|
|
139
|
+
* @param {Function} listener - The listener to remove.
|
|
140
|
+
* @param {object} context - The context of the listener.
|
|
141
|
+
* @returns {Function} The removed listener function.
|
|
141
142
|
*/
|
|
142
143
|
remove(listener, context = null) {
|
|
143
144
|
this.validateListener(listener, 'remove');
|
|
@@ -151,8 +152,8 @@ export class Signal {
|
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
/**
|
|
154
|
-
*
|
|
155
|
-
* @param {object} context -
|
|
155
|
+
* Remove all listeners from the signal, or only those in a specific context.
|
|
156
|
+
* @param {object} context - The context to filter listeners by, or null to remove all.
|
|
156
157
|
*/
|
|
157
158
|
removeAll(context = null) {
|
|
158
159
|
if (!this._bindings) {
|
|
@@ -176,23 +177,24 @@ export class Signal {
|
|
|
176
177
|
}
|
|
177
178
|
|
|
178
179
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @returns {number}
|
|
180
|
+
* Get the number of listeners registered with the signal.
|
|
181
|
+
* @returns {number} The number of registered listeners.
|
|
181
182
|
*/
|
|
182
183
|
getNumListeners() {
|
|
183
184
|
return this._bindings ? this._bindings.length : 0;
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
/**
|
|
187
|
-
*
|
|
188
|
+
* Stop the signal from propagating to other listeners.
|
|
189
|
+
* This method prevents any remaining listeners from being called.
|
|
188
190
|
*/
|
|
189
191
|
halt() {
|
|
190
192
|
this._shouldPropagate = false;
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @param {...any} args -
|
|
196
|
+
* Dispatch the signal to all registered listeners.
|
|
197
|
+
* @param {...any} args - Arguments to pass to the listeners.
|
|
196
198
|
*/
|
|
197
199
|
dispatch(...args) {
|
|
198
200
|
if (!this.active || !this._bindings) {
|
|
@@ -219,7 +221,8 @@ export class Signal {
|
|
|
219
221
|
}
|
|
220
222
|
|
|
221
223
|
/**
|
|
222
|
-
*
|
|
224
|
+
* Clear any previously memorized arguments.
|
|
225
|
+
* This removes the stored arguments from a previous dispatch.
|
|
223
226
|
*/
|
|
224
227
|
forget() {
|
|
225
228
|
if (this._prevParams) {
|
|
@@ -228,7 +231,8 @@ export class Signal {
|
|
|
228
231
|
}
|
|
229
232
|
|
|
230
233
|
/**
|
|
231
|
-
*
|
|
234
|
+
* Dispose of the signal and clean up all resources.
|
|
235
|
+
* This method removes all listeners and clears internal state.
|
|
232
236
|
*/
|
|
233
237
|
dispose() {
|
|
234
238
|
this.removeAll();
|
|
@@ -237,16 +241,16 @@ export class Signal {
|
|
|
237
241
|
}
|
|
238
242
|
|
|
239
243
|
/**
|
|
240
|
-
*
|
|
241
|
-
* @returns {string}
|
|
244
|
+
* Get a string representation of the signal.
|
|
245
|
+
* @returns {string} A string representation of the signal.
|
|
242
246
|
*/
|
|
243
247
|
toString() {
|
|
244
248
|
return `[Signal active:${this.active} numListeners:${this.getNumListeners()}]`;
|
|
245
249
|
}
|
|
246
250
|
|
|
247
251
|
/**
|
|
248
|
-
*
|
|
249
|
-
* @returns {Function}
|
|
252
|
+
* Get a bound version of the dispatch function.
|
|
253
|
+
* @returns {Function} A function that will dispatch the signal with the correct context.
|
|
250
254
|
*/
|
|
251
255
|
get boundDispatch() {
|
|
252
256
|
const _this = this;
|