@vpmedia/phaser 1.112.0 → 1.113.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 +1261 -1314
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +14 -10
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +10 -8
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +5 -4
- 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 +4 -3
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/const.d.ts.map +1 -1
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +3 -2
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/event_manager.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +8 -6
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +40 -30
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +3 -2
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +3 -2
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +6 -4
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +3 -2
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +4 -3
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +9 -8
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +3 -2
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/registry.d.ts +7 -0
- package/dist/phaser/core/registry.d.ts.map +1 -0
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +0 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +0 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +4 -3
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +6 -4
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -2
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +5 -4
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +3 -2
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts +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/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +10 -7
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +3 -2
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +3 -2
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts +3 -2
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +3 -2
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +3 -2
- 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 +7 -6
- package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +10 -8
- 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 +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +14 -12
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +8 -5
- 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 +4 -3
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +13 -10
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_batch.d.ts +3 -2
- package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +18 -15
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +11 -9
- 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.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +7 -6
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +16 -11
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
- package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
- package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +3 -2
- 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 +4 -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 +1 -1
- package/dist/phaser/geom/line.d.ts.map +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 +3 -2
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts +2 -2
- 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/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/phaser/core/animation.ts +64 -60
- package/src/phaser/core/animation_manager.ts +50 -53
- package/src/phaser/core/animation_parser.ts +9 -9
- package/src/phaser/core/array_set.ts +16 -17
- package/src/phaser/core/cache.ts +92 -93
- package/src/phaser/core/const.ts +1 -1
- package/src/phaser/core/device.ts +24 -29
- package/src/phaser/core/device_util.ts +22 -26
- package/src/phaser/core/dom.ts +54 -65
- package/src/phaser/core/event_manager.ts +64 -94
- package/src/phaser/core/factory.ts +14 -14
- package/src/phaser/core/frame.ts +28 -28
- package/src/phaser/core/frame_data.test.ts +100 -0
- package/src/phaser/core/frame_data.ts +24 -24
- package/src/phaser/core/frame_util.ts +2 -2
- package/src/phaser/core/game.ts +47 -48
- package/src/phaser/core/input.ts +104 -110
- package/src/phaser/core/input_handler.test.ts +113 -0
- package/src/phaser/core/input_handler.ts +199 -218
- package/src/phaser/core/input_mouse.ts +71 -54
- package/src/phaser/core/input_mspointer.ts +52 -39
- package/src/phaser/core/input_pointer.ts +81 -80
- package/src/phaser/core/input_touch.ts +49 -36
- package/src/phaser/core/loader.ts +173 -152
- package/src/phaser/core/loader_parser.ts +39 -57
- package/src/phaser/core/raf.ts +8 -7
- package/src/phaser/core/registry.test.ts +31 -0
- package/src/phaser/core/registry.ts +9 -0
- package/src/phaser/core/scale_manager.ts +156 -152
- package/src/phaser/core/scene.ts +9 -13
- package/src/phaser/core/scene_manager.ts +47 -47
- package/src/phaser/core/signal.test.ts +4 -4
- package/src/phaser/core/signal.ts +41 -52
- package/src/phaser/core/signal_binding.ts +26 -25
- package/src/phaser/core/signal_dispatch.test.ts +180 -0
- package/src/phaser/core/sound.ts +75 -83
- package/src/phaser/core/sound_manager.ts +52 -51
- package/src/phaser/core/sound_sprite.ts +17 -16
- package/src/phaser/core/stage.ts +25 -24
- package/src/phaser/core/time.ts +52 -52
- package/src/phaser/core/timer.test.ts +187 -0
- package/src/phaser/core/timer.ts +82 -69
- package/src/phaser/core/timer_event.ts +10 -10
- package/src/phaser/core/tween.ts +90 -93
- package/src/phaser/core/tween_data.ts +45 -51
- package/src/phaser/core/tween_easing.test.ts +106 -0
- package/src/phaser/core/tween_easing.ts +151 -123
- package/src/phaser/core/tween_manager.ts +19 -18
- package/src/phaser/core/world.ts +4 -3
- package/src/phaser/display/bitmap_text.ts +56 -64
- package/src/phaser/display/button.ts +33 -32
- package/src/phaser/display/canvas/buffer.ts +8 -8
- package/src/phaser/display/canvas/graphics.ts +36 -37
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.test.ts +106 -0
- package/src/phaser/display/canvas/pool.ts +25 -27
- package/src/phaser/display/canvas/renderer.ts +32 -31
- package/src/phaser/display/canvas/tinter.ts +25 -25
- package/src/phaser/display/canvas/util.ts +7 -10
- package/src/phaser/display/display_object.ts +114 -118
- package/src/phaser/display/graphics.ts +121 -119
- package/src/phaser/display/graphics_data.ts +12 -12
- package/src/phaser/display/graphics_data_util.ts +2 -3
- package/src/phaser/display/group.ts +50 -57
- package/src/phaser/display/image.ts +55 -52
- package/src/phaser/display/sprite_batch.ts +3 -2
- package/src/phaser/display/sprite_util.ts +48 -54
- package/src/phaser/display/text.ts +199 -204
- package/src/phaser/display/webgl/abstract_filter.ts +9 -9
- package/src/phaser/display/webgl/base_texture.ts +21 -24
- package/src/phaser/display/webgl/blend_manager.ts +6 -10
- package/src/phaser/display/webgl/earcut.ts +73 -37
- package/src/phaser/display/webgl/earcut_node.ts +10 -10
- package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
- package/src/phaser/display/webgl/filter_manager.ts +13 -12
- package/src/phaser/display/webgl/filter_texture.ts +14 -13
- package/src/phaser/display/webgl/graphics.ts +51 -57
- package/src/phaser/display/webgl/graphics_data.ts +15 -14
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +26 -25
- package/src/phaser/display/webgl/renderer.ts +57 -62
- package/src/phaser/display/webgl/shader/complex.ts +28 -12
- package/src/phaser/display/webgl/shader/fast.ts +30 -12
- package/src/phaser/display/webgl/shader/normal.ts +70 -57
- package/src/phaser/display/webgl/shader/primitive.ts +26 -11
- package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
- package/src/phaser/display/webgl/shader/strip.ts +27 -12
- package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
- package/src/phaser/display/webgl/shader_manager.ts +26 -34
- package/src/phaser/display/webgl/sprite_batch.ts +67 -61
- package/src/phaser/display/webgl/stencil_manager.ts +23 -34
- package/src/phaser/display/webgl/texture.ts +43 -50
- package/src/phaser/display/webgl/texture_util.ts +2 -3
- package/src/phaser/display/webgl/util.ts +26 -25
- package/src/phaser/geom/circle.test.ts +2 -3
- package/src/phaser/geom/circle.ts +36 -36
- package/src/phaser/geom/ellipse.test.ts +73 -71
- package/src/phaser/geom/ellipse.ts +14 -14
- package/src/phaser/geom/line.test.ts +5 -5
- package/src/phaser/geom/line.ts +35 -35
- package/src/phaser/geom/matrix.test.ts +1 -1
- package/src/phaser/geom/matrix.ts +27 -27
- package/src/phaser/geom/point.test.ts +1 -2
- package/src/phaser/geom/point.ts +35 -35
- package/src/phaser/geom/polygon.test.ts +82 -0
- package/src/phaser/geom/polygon.ts +16 -16
- package/src/phaser/geom/rectangle.test.ts +14 -14
- package/src/phaser/geom/rectangle.ts +83 -75
- package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
- package/src/phaser/geom/rounded_rectangle.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +25 -23
- package/src/phaser/geom/util/circle.ts +9 -18
- package/src/phaser/geom/util/ellipse.test.ts +7 -5
- package/src/phaser/geom/util/ellipse.ts +3 -2
- package/src/phaser/geom/util/line.test.ts +10 -8
- package/src/phaser/geom/util/line.ts +6 -16
- package/src/phaser/geom/util/matrix.test.ts +20 -18
- package/src/phaser/geom/util/matrix.ts +8 -15
- package/src/phaser/geom/util/point.test.ts +8 -6
- package/src/phaser/geom/util/point.ts +24 -28
- package/src/phaser/geom/util/polygon.test.ts +12 -10
- package/src/phaser/geom/util/polygon.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +10 -8
- package/src/phaser/geom/util/rectangle.ts +18 -37
- package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
- package/src/phaser/util/math.test.ts +11 -11
- package/src/phaser/util/math.ts +29 -46
package/src/phaser/core/scene.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
export class Scene {
|
|
2
|
-
game
|
|
3
|
-
key
|
|
2
|
+
public game: any = null;
|
|
3
|
+
public key: any = '';
|
|
4
4
|
/**
|
|
5
5
|
* Creates a new Scene instance.
|
|
6
6
|
*/
|
|
7
|
-
constructor() {
|
|
8
|
-
this.game = null;
|
|
9
|
-
this.key = '';
|
|
10
|
-
}
|
|
11
7
|
|
|
12
8
|
/**
|
|
13
9
|
* Initialize the scene.
|
|
14
10
|
* This method is called before preload() and create().
|
|
15
11
|
*/
|
|
16
|
-
init() {
|
|
12
|
+
public init() {
|
|
17
13
|
// inherit
|
|
18
14
|
}
|
|
19
15
|
|
|
@@ -21,7 +17,7 @@ export class Scene {
|
|
|
21
17
|
* Load assets for the scene.
|
|
22
18
|
* This method is called after init() and before create().
|
|
23
19
|
*/
|
|
24
|
-
preload() {
|
|
20
|
+
public preload() {
|
|
25
21
|
// inherit
|
|
26
22
|
}
|
|
27
23
|
|
|
@@ -29,7 +25,7 @@ export class Scene {
|
|
|
29
25
|
* Create the scene.
|
|
30
26
|
* This method is called after preload() and is where you create your game objects.
|
|
31
27
|
*/
|
|
32
|
-
create() {
|
|
28
|
+
public create() {
|
|
33
29
|
// inherit
|
|
34
30
|
}
|
|
35
31
|
|
|
@@ -37,7 +33,7 @@ export class Scene {
|
|
|
37
33
|
* Update the scene.
|
|
38
34
|
* This method is called every frame while the scene is active.
|
|
39
35
|
*/
|
|
40
|
-
update() {
|
|
36
|
+
public update() {
|
|
41
37
|
// inherit
|
|
42
38
|
}
|
|
43
39
|
|
|
@@ -46,7 +42,7 @@ export class Scene {
|
|
|
46
42
|
* @param {number} _width - The new width of the scene.
|
|
47
43
|
* @param {number} _height - The new height of the scene.
|
|
48
44
|
*/
|
|
49
|
-
resize(_width: number, _height: number) {
|
|
45
|
+
public resize(_width: number, _height: number) {
|
|
50
46
|
// inherit
|
|
51
47
|
}
|
|
52
48
|
|
|
@@ -54,7 +50,7 @@ export class Scene {
|
|
|
54
50
|
* Update the scene while paused.
|
|
55
51
|
* This method is called every frame while the scene is paused.
|
|
56
52
|
*/
|
|
57
|
-
pauseUpdate() {
|
|
53
|
+
public pauseUpdate() {
|
|
58
54
|
// inherit
|
|
59
55
|
}
|
|
60
56
|
|
|
@@ -62,7 +58,7 @@ export class Scene {
|
|
|
62
58
|
* Shutdown the scene.
|
|
63
59
|
* This method is called when the scene is about to be destroyed.
|
|
64
60
|
*/
|
|
65
|
-
shutdown() {
|
|
61
|
+
public shutdown() {
|
|
66
62
|
// inherit
|
|
67
63
|
}
|
|
68
64
|
}
|
|
@@ -2,32 +2,32 @@ import type { Game } from './game.js';
|
|
|
2
2
|
import { Scene } from './scene.js';
|
|
3
3
|
|
|
4
4
|
export class SceneManager {
|
|
5
|
-
game!: any;
|
|
6
|
-
states!: any;
|
|
7
|
-
_pendingState!: any;
|
|
8
|
-
_clearWorld!: any;
|
|
9
|
-
_clearCache!: any;
|
|
10
|
-
_created!: any;
|
|
11
|
-
_args!: any;
|
|
12
|
-
current!: string;
|
|
13
|
-
onInitCallback!: any;
|
|
14
|
-
onPreloadCallback!: any;
|
|
15
|
-
onCreateCallback!: any;
|
|
16
|
-
onUpdateCallback!: any;
|
|
17
|
-
onResizeCallback!: any;
|
|
18
|
-
onPauseUpdateCallback!: any;
|
|
19
|
-
onShutDownCallback!: any;
|
|
20
|
-
callbackContext!: any;
|
|
5
|
+
public game!: any;
|
|
6
|
+
public states!: any;
|
|
7
|
+
public _pendingState!: any;
|
|
8
|
+
public _clearWorld!: any;
|
|
9
|
+
public _clearCache!: any;
|
|
10
|
+
public _created!: any;
|
|
11
|
+
public _args!: any;
|
|
12
|
+
public current!: string;
|
|
13
|
+
public onInitCallback!: any;
|
|
14
|
+
public onPreloadCallback!: any;
|
|
15
|
+
public onCreateCallback!: any;
|
|
16
|
+
public onUpdateCallback!: any;
|
|
17
|
+
public onResizeCallback!: any;
|
|
18
|
+
public onPauseUpdateCallback!: any;
|
|
19
|
+
public onShutDownCallback!: any;
|
|
20
|
+
public callbackContext!: any;
|
|
21
21
|
/**
|
|
22
22
|
* Creates a new SceneManager instance.
|
|
23
|
-
* @param {
|
|
23
|
+
* @param {Game} game - The game instance this manager belongs to.
|
|
24
24
|
* @param {string} pendingState - The state to load when the game boots.
|
|
25
25
|
*/
|
|
26
|
-
constructor(game: Game, pendingState: string) {
|
|
26
|
+
public constructor(game: Game, pendingState: string) {
|
|
27
27
|
this.game = game;
|
|
28
28
|
this.states = {};
|
|
29
29
|
this._pendingState = null;
|
|
30
|
-
if (
|
|
30
|
+
if (pendingState !== undefined && pendingState !== null) {
|
|
31
31
|
this._pendingState = pendingState;
|
|
32
32
|
}
|
|
33
33
|
this._clearWorld = false;
|
|
@@ -48,7 +48,7 @@ export class SceneManager {
|
|
|
48
48
|
* Initialize the scene manager.
|
|
49
49
|
* This method is called when the game boots and sets up the initial state.
|
|
50
50
|
*/
|
|
51
|
-
boot() {
|
|
51
|
+
public boot() {
|
|
52
52
|
if (this._pendingState !== null && typeof this._pendingState !== 'string') {
|
|
53
53
|
this.add('default', this._pendingState, true);
|
|
54
54
|
}
|
|
@@ -61,7 +61,7 @@ export class SceneManager {
|
|
|
61
61
|
* @param {boolean} autoStart - Whether to start this state immediately.
|
|
62
62
|
* @returns {Scene|object} The created scene or state object.
|
|
63
63
|
*/
|
|
64
|
-
add(key: string, state: any, autoStart
|
|
64
|
+
public add(key: string, state: any, autoStart = false) {
|
|
65
65
|
let newState = null;
|
|
66
66
|
if (state instanceof Scene) {
|
|
67
67
|
newState = state;
|
|
@@ -86,7 +86,7 @@ export class SceneManager {
|
|
|
86
86
|
* Remove a scene state from the manager.
|
|
87
87
|
* @param {string} key - The unique key for the state to remove.
|
|
88
88
|
*/
|
|
89
|
-
remove(key: string) {
|
|
89
|
+
public remove(key: string) {
|
|
90
90
|
if (this.current === key) {
|
|
91
91
|
this.callbackContext = null;
|
|
92
92
|
this.onInitCallback = null;
|
|
@@ -107,14 +107,14 @@ export class SceneManager {
|
|
|
107
107
|
* @param {boolean} clearCache - Whether to clear the cache before starting.
|
|
108
108
|
* @param {...any} args - Additional arguments to pass to the state.
|
|
109
109
|
*/
|
|
110
|
-
start(key: string, clearWorld
|
|
110
|
+
public start(key: string, clearWorld = true, clearCache = false, ...args: any[]) {
|
|
111
111
|
if (this.checkState(key)) {
|
|
112
112
|
// Place the state in the queue. It will be started the next time the game loop begins.
|
|
113
113
|
this._pendingState = key;
|
|
114
114
|
this._clearWorld = clearWorld;
|
|
115
115
|
this._clearCache = clearCache;
|
|
116
116
|
if (args && args.length > 0) {
|
|
117
|
-
this._args = args
|
|
117
|
+
this._args = [...args];
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -125,12 +125,12 @@ export class SceneManager {
|
|
|
125
125
|
* @param {boolean} clearCache - Whether to clear the cache before restarting.
|
|
126
126
|
* @param {...any} args - Additional arguments to pass to the state.
|
|
127
127
|
*/
|
|
128
|
-
restart(clearWorld
|
|
128
|
+
public restart(clearWorld = true, clearCache = false, ...args: any[]) {
|
|
129
129
|
this._pendingState = this.current;
|
|
130
130
|
this._clearWorld = clearWorld;
|
|
131
131
|
this._clearCache = clearCache;
|
|
132
132
|
if (args && args.length > 0) {
|
|
133
|
-
this._args = args
|
|
133
|
+
this._args = [...args];
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -138,7 +138,7 @@ export class SceneManager {
|
|
|
138
138
|
* Pre-update the scene manager.
|
|
139
139
|
* This method is called before the game loop updates.
|
|
140
140
|
*/
|
|
141
|
-
preUpdate() {
|
|
141
|
+
public preUpdate() {
|
|
142
142
|
if (this._pendingState && this.game.isBooted) {
|
|
143
143
|
// var previousStateKey = this.current;
|
|
144
144
|
// Already got a state running?
|
|
@@ -173,7 +173,7 @@ export class SceneManager {
|
|
|
173
173
|
* Clear the current scene state.
|
|
174
174
|
* This method is called when switching scenes to clean up the previous scene.
|
|
175
175
|
*/
|
|
176
|
-
clearCurrentState() {
|
|
176
|
+
public clearCurrentState() {
|
|
177
177
|
if (this.current) {
|
|
178
178
|
if (this.onShutDownCallback) {
|
|
179
179
|
this.onShutDownCallback.call(this.callbackContext, this.game);
|
|
@@ -196,7 +196,7 @@ export class SceneManager {
|
|
|
196
196
|
* @param {string} key - The unique key for the state to check.
|
|
197
197
|
* @returns {boolean} True if the scene exists, false otherwise.
|
|
198
198
|
*/
|
|
199
|
-
checkState(key: string) {
|
|
199
|
+
public checkState(key: string) {
|
|
200
200
|
if (this.states[key]) {
|
|
201
201
|
if (this.states[key].preload || this.states[key].create || this.states[key].update || this.states[key].render) {
|
|
202
202
|
return true;
|
|
@@ -210,7 +210,7 @@ export class SceneManager {
|
|
|
210
210
|
* Link a scene state to the manager.
|
|
211
211
|
* @param {string} key - The unique key for the state to link.
|
|
212
212
|
*/
|
|
213
|
-
link(key: string) {
|
|
213
|
+
public link(key: string) {
|
|
214
214
|
this.states[key].game = this.game;
|
|
215
215
|
this.states[key].key = key;
|
|
216
216
|
}
|
|
@@ -219,7 +219,7 @@ export class SceneManager {
|
|
|
219
219
|
* Unlink a scene state from the manager.
|
|
220
220
|
* @param {string} key - The unique key for the state to unlink.
|
|
221
221
|
*/
|
|
222
|
-
unlink(key: string) {
|
|
222
|
+
public unlink(key: string) {
|
|
223
223
|
if (this.states[key]) {
|
|
224
224
|
this.states[key].game = null;
|
|
225
225
|
}
|
|
@@ -229,17 +229,17 @@ export class SceneManager {
|
|
|
229
229
|
* Set the current scene state.
|
|
230
230
|
* @param {string} key - The unique key for the state to set as current.
|
|
231
231
|
*/
|
|
232
|
-
setCurrentState(key: string) {
|
|
232
|
+
public setCurrentState(key: string) {
|
|
233
233
|
this.callbackContext = this.states[key];
|
|
234
234
|
this.link(key);
|
|
235
235
|
// Used when the state is set as being the current active state
|
|
236
|
-
this.onInitCallback = this.callbackContext.init
|
|
237
|
-
this.onPreloadCallback = this.callbackContext.preload
|
|
238
|
-
this.onCreateCallback = this.callbackContext.create
|
|
239
|
-
this.onUpdateCallback = this.callbackContext.update
|
|
240
|
-
this.onResizeCallback = this.callbackContext.resize
|
|
241
|
-
this.onPauseUpdateCallback = this.callbackContext.pauseUpdate
|
|
242
|
-
this.onShutDownCallback = this.callbackContext.shutdown
|
|
236
|
+
this.onInitCallback = this.callbackContext.init ?? this.dummy;
|
|
237
|
+
this.onPreloadCallback = this.callbackContext.preload ?? null;
|
|
238
|
+
this.onCreateCallback = this.callbackContext.create ?? null;
|
|
239
|
+
this.onUpdateCallback = this.callbackContext.update ?? null;
|
|
240
|
+
this.onResizeCallback = this.callbackContext.resize ?? null;
|
|
241
|
+
this.onPauseUpdateCallback = this.callbackContext.pauseUpdate ?? null;
|
|
242
|
+
this.onShutDownCallback = this.callbackContext.shutdown ?? this.dummy;
|
|
243
243
|
this.current = key;
|
|
244
244
|
this._created = false;
|
|
245
245
|
this.onInitCallback.apply(this.callbackContext, this._args);
|
|
@@ -254,7 +254,7 @@ export class SceneManager {
|
|
|
254
254
|
* @template T
|
|
255
255
|
* @returns {T} The current scene state.
|
|
256
256
|
*/
|
|
257
|
-
getCurrentState<T = Partial<Scene>>(): T {
|
|
257
|
+
public getCurrentState<T = Partial<Scene>>(): T {
|
|
258
258
|
return this.states[this.current];
|
|
259
259
|
}
|
|
260
260
|
|
|
@@ -262,7 +262,7 @@ export class SceneManager {
|
|
|
262
262
|
* Handle loading completion.
|
|
263
263
|
* This method is called when scene loading is complete.
|
|
264
264
|
*/
|
|
265
|
-
loadComplete() {
|
|
265
|
+
public loadComplete() {
|
|
266
266
|
if (this._created === false && this.onCreateCallback) {
|
|
267
267
|
this._created = true;
|
|
268
268
|
this.onCreateCallback.call(this.callbackContext, this.game);
|
|
@@ -275,7 +275,7 @@ export class SceneManager {
|
|
|
275
275
|
* Update the scene manager.
|
|
276
276
|
* This method is called every frame while the game is running.
|
|
277
277
|
*/
|
|
278
|
-
update() {
|
|
278
|
+
public update() {
|
|
279
279
|
if (this._created && this.onUpdateCallback) {
|
|
280
280
|
this.onUpdateCallback.call(this.callbackContext, this.game);
|
|
281
281
|
}
|
|
@@ -285,7 +285,7 @@ export class SceneManager {
|
|
|
285
285
|
* Pause the scene manager updates.
|
|
286
286
|
* This method is called when the game is paused.
|
|
287
287
|
*/
|
|
288
|
-
pauseUpdate() {
|
|
288
|
+
public pauseUpdate() {
|
|
289
289
|
if (this._created && this.onPauseUpdateCallback) {
|
|
290
290
|
this.onPauseUpdateCallback.call(this.callbackContext, this.game);
|
|
291
291
|
}
|
|
@@ -296,7 +296,7 @@ export class SceneManager {
|
|
|
296
296
|
* @param {number} width - The new width of the scene.
|
|
297
297
|
* @param {number} height - The new height of the scene.
|
|
298
298
|
*/
|
|
299
|
-
resize(width: number, height: number) {
|
|
299
|
+
public resize(width: number, height: number) {
|
|
300
300
|
if (this.onResizeCallback) {
|
|
301
301
|
this.onResizeCallback.call(this.callbackContext, width, height);
|
|
302
302
|
}
|
|
@@ -306,7 +306,7 @@ export class SceneManager {
|
|
|
306
306
|
* Destroy the scene manager.
|
|
307
307
|
* This method is called when the scene manager is about to be destroyed.
|
|
308
308
|
*/
|
|
309
|
-
destroy() {
|
|
309
|
+
public destroy() {
|
|
310
310
|
this._clearWorld = true;
|
|
311
311
|
this._clearCache = true;
|
|
312
312
|
this.clearCurrentState();
|
|
@@ -327,7 +327,7 @@ export class SceneManager {
|
|
|
327
327
|
* Dummy function for callbacks.
|
|
328
328
|
* This is a placeholder function used when no callback is defined.
|
|
329
329
|
*/
|
|
330
|
-
dummy() {
|
|
330
|
+
public dummy() {
|
|
331
331
|
// pass
|
|
332
332
|
}
|
|
333
333
|
|
|
@@ -335,7 +335,7 @@ export class SceneManager {
|
|
|
335
335
|
* Get whether the scene has been created.
|
|
336
336
|
* @returns {boolean} True if the scene has been created, false otherwise.
|
|
337
337
|
*/
|
|
338
|
-
get created() {
|
|
338
|
+
public get created() {
|
|
339
339
|
return this._created;
|
|
340
340
|
}
|
|
341
341
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { expect } from 'vitest';
|
|
1
|
+
import { expect, describe, it } from 'vitest';
|
|
2
2
|
import { Signal } from './signal.js';
|
|
3
3
|
|
|
4
4
|
describe('Signal', () => {
|
|
5
5
|
describe('core', () => {
|
|
6
|
-
it('', () => {
|
|
6
|
+
it('adds, dispatches to and removes listeners', () => {
|
|
7
7
|
const signal = new Signal();
|
|
8
|
-
const listener = (arg) => {
|
|
8
|
+
const listener = (arg: number) => {
|
|
9
9
|
expect(arg).toBe(1);
|
|
10
10
|
};
|
|
11
|
-
const listenerOnce = (arg) => {
|
|
11
|
+
const listenerOnce = (arg: number) => {
|
|
12
12
|
expect(arg).toBe(1);
|
|
13
13
|
};
|
|
14
14
|
signal.add(listener);
|
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
import { SignalBinding } from './signal_binding.js';
|
|
2
2
|
|
|
3
3
|
export class Signal {
|
|
4
|
-
_bindings: SignalBinding[] | null;
|
|
5
|
-
_prevParams: unknown[] | null;
|
|
6
|
-
memorize
|
|
7
|
-
_shouldPropagate
|
|
8
|
-
active
|
|
9
|
-
_boundDispatch: ((...args: unknown[]) => void) | null;
|
|
4
|
+
public _bindings: SignalBinding[] | null = null;
|
|
5
|
+
public _prevParams: unknown[] | null = null;
|
|
6
|
+
public memorize = false;
|
|
7
|
+
public _shouldPropagate = true;
|
|
8
|
+
public active = true;
|
|
9
|
+
public _boundDispatch: ((...args: unknown[]) => void) | null = null;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates a new Signal instance.
|
|
13
13
|
* A Signal is a simple event system that allows you to dispatch events and listen for them.
|
|
14
14
|
*/
|
|
15
|
-
constructor() {
|
|
16
|
-
this._bindings = null;
|
|
17
|
-
this._prevParams = null;
|
|
18
|
-
this.memorize = false;
|
|
19
|
-
this._shouldPropagate = true;
|
|
20
|
-
this.active = true;
|
|
21
|
-
this._boundDispatch = null;
|
|
22
|
-
}
|
|
23
15
|
|
|
24
16
|
/**
|
|
25
17
|
* Validates that a listener is a function.
|
|
@@ -27,7 +19,7 @@ export class Signal {
|
|
|
27
19
|
* @param {string} fnName - The name of the function this validation is for.
|
|
28
20
|
* @throws {Error} If the listener is not a function.
|
|
29
21
|
*/
|
|
30
|
-
validateListener(listener: Function, fnName: string) {
|
|
22
|
+
public validateListener(listener: Function, fnName: string) {
|
|
31
23
|
if (typeof listener !== 'function') {
|
|
32
24
|
throw new TypeError(
|
|
33
25
|
'Signal: listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName)
|
|
@@ -45,17 +37,18 @@ export class Signal {
|
|
|
45
37
|
* @returns {SignalBinding} The binding for this listener.
|
|
46
38
|
* @throws {Error} If the listener is already registered with a different once setting.
|
|
47
39
|
*/
|
|
48
|
-
_registerListener(
|
|
40
|
+
public _registerListener(
|
|
49
41
|
listener: Function,
|
|
50
|
-
isOnce
|
|
42
|
+
isOnce = false,
|
|
51
43
|
listenerContext: any | null = null,
|
|
52
|
-
priority
|
|
44
|
+
priority = 0,
|
|
53
45
|
args: any = null
|
|
54
46
|
) {
|
|
55
47
|
const prevIndex = this._indexOfListener(listener, listenerContext);
|
|
56
48
|
let binding;
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const existing = prevIndex !== -1 && this._bindings ? this._bindings[prevIndex] : undefined;
|
|
50
|
+
if (existing) {
|
|
51
|
+
binding = existing;
|
|
59
52
|
if (binding.isOnce() !== isOnce) {
|
|
60
53
|
throw new Error(
|
|
61
54
|
`You cannot add${isOnce ? '' : 'Once'}() then add${
|
|
@@ -77,15 +70,13 @@ export class Signal {
|
|
|
77
70
|
* Add a binding to the list of listeners.
|
|
78
71
|
* @param {SignalBinding} binding - The binding to add.
|
|
79
72
|
*/
|
|
80
|
-
_addBinding(binding: SignalBinding) {
|
|
81
|
-
|
|
82
|
-
this._bindings = [];
|
|
83
|
-
}
|
|
73
|
+
public _addBinding(binding: SignalBinding) {
|
|
74
|
+
this._bindings ??= [];
|
|
84
75
|
// Simplified insertion sort
|
|
85
76
|
let n = this._bindings.length;
|
|
86
77
|
do {
|
|
87
78
|
n -= 1;
|
|
88
|
-
} while (this._bindings[n] && binding._priority <= this._bindings[n]
|
|
79
|
+
} while (this._bindings[n] && binding._priority <= this._bindings[n]!._priority);
|
|
89
80
|
this._bindings.splice(n + 1, 0, binding);
|
|
90
81
|
}
|
|
91
82
|
|
|
@@ -95,7 +86,7 @@ export class Signal {
|
|
|
95
86
|
* @param {object} context - The context of the listener.
|
|
96
87
|
* @returns {number} The index of the listener in the bindings array, or -1 if not found.
|
|
97
88
|
*/
|
|
98
|
-
_indexOfListener(listener: Function, context: any | null = null) {
|
|
89
|
+
public _indexOfListener(listener: Function, context: any | null = null) {
|
|
99
90
|
if (!this._bindings) {
|
|
100
91
|
return -1;
|
|
101
92
|
}
|
|
@@ -103,7 +94,7 @@ export class Signal {
|
|
|
103
94
|
let cur;
|
|
104
95
|
while (n) {
|
|
105
96
|
n -= 1;
|
|
106
|
-
cur = this._bindings[n]
|
|
97
|
+
cur = this._bindings[n]!;
|
|
107
98
|
if (cur._listener === listener && cur.context === context) {
|
|
108
99
|
return n;
|
|
109
100
|
}
|
|
@@ -117,7 +108,7 @@ export class Signal {
|
|
|
117
108
|
* @param {object} context - The context of the listener.
|
|
118
109
|
* @returns {boolean} True if the listener is registered, false otherwise.
|
|
119
110
|
*/
|
|
120
|
-
has(listener: Function, context: any | null = null) {
|
|
111
|
+
public has(listener: Function, context: any | null = null) {
|
|
121
112
|
return this._indexOfListener(listener, context) !== -1;
|
|
122
113
|
}
|
|
123
114
|
|
|
@@ -129,7 +120,7 @@ export class Signal {
|
|
|
129
120
|
* @param {...any} args - Additional arguments to pass to the listener.
|
|
130
121
|
* @returns {SignalBinding} The binding for this listener.
|
|
131
122
|
*/
|
|
132
|
-
add(listener: Function, listenerContext: any | null = null, priority
|
|
123
|
+
public add(listener: Function, listenerContext: any | null = null, priority = 0, ...args: any[]) {
|
|
133
124
|
this.validateListener(listener, 'add');
|
|
134
125
|
return this._registerListener(listener, false, listenerContext, priority, args);
|
|
135
126
|
}
|
|
@@ -142,7 +133,7 @@ export class Signal {
|
|
|
142
133
|
* @param {...any} args - Additional arguments to pass to the listener.
|
|
143
134
|
* @returns {SignalBinding} The binding for this listener.
|
|
144
135
|
*/
|
|
145
|
-
addOnce(listener: Function, listenerContext: any | null = null, priority
|
|
136
|
+
public addOnce(listener: Function, listenerContext: any | null = null, priority = 0, ...args: any[]) {
|
|
146
137
|
this.validateListener(listener, 'addOnce');
|
|
147
138
|
return this._registerListener(listener, true, listenerContext, priority, args);
|
|
148
139
|
}
|
|
@@ -153,12 +144,12 @@ export class Signal {
|
|
|
153
144
|
* @param {object} context - The context of the listener.
|
|
154
145
|
* @returns {Function} The removed listener function.
|
|
155
146
|
*/
|
|
156
|
-
remove(listener: Function, context: any | null = null) {
|
|
147
|
+
public remove(listener: Function, context: any | null = null) {
|
|
157
148
|
this.validateListener(listener, 'remove');
|
|
158
149
|
const i = this._indexOfListener(listener, context);
|
|
159
150
|
if (i !== -1 && this._bindings) {
|
|
160
151
|
// no reason to a SignalBinding exist if it isn't attached to a signal
|
|
161
|
-
this._bindings[i]
|
|
152
|
+
this._bindings[i]!._destroy();
|
|
162
153
|
this._bindings.splice(i, 1);
|
|
163
154
|
}
|
|
164
155
|
return listener;
|
|
@@ -168,7 +159,7 @@ export class Signal {
|
|
|
168
159
|
* Remove all listeners from the signal, or only those in a specific context.
|
|
169
160
|
* @param {object} context - The context to filter listeners by, or null to remove all.
|
|
170
161
|
*/
|
|
171
|
-
removeAll(context: any | null = null) {
|
|
162
|
+
public removeAll(context: any | null = null) {
|
|
172
163
|
if (!this._bindings) {
|
|
173
164
|
return;
|
|
174
165
|
}
|
|
@@ -176,12 +167,12 @@ export class Signal {
|
|
|
176
167
|
while (n) {
|
|
177
168
|
n -= 1;
|
|
178
169
|
if (context) {
|
|
179
|
-
if (this._bindings[n]
|
|
180
|
-
this._bindings[n]
|
|
170
|
+
if (this._bindings[n]!.context === context) {
|
|
171
|
+
this._bindings[n]!._destroy();
|
|
181
172
|
this._bindings.splice(n, 1);
|
|
182
173
|
}
|
|
183
174
|
} else {
|
|
184
|
-
this._bindings[n]
|
|
175
|
+
this._bindings[n]!._destroy();
|
|
185
176
|
}
|
|
186
177
|
}
|
|
187
178
|
if (!context) {
|
|
@@ -193,7 +184,7 @@ export class Signal {
|
|
|
193
184
|
* Get the number of listeners registered with the signal.
|
|
194
185
|
* @returns {number} The number of registered listeners.
|
|
195
186
|
*/
|
|
196
|
-
getNumListeners() {
|
|
187
|
+
public getNumListeners() {
|
|
197
188
|
return this._bindings ? this._bindings.length : 0;
|
|
198
189
|
}
|
|
199
190
|
|
|
@@ -201,7 +192,7 @@ export class Signal {
|
|
|
201
192
|
* Stop the signal from propagating to other listeners.
|
|
202
193
|
* This method prevents any remaining listeners from being called.
|
|
203
194
|
*/
|
|
204
|
-
halt() {
|
|
195
|
+
public halt() {
|
|
205
196
|
this._shouldPropagate = false;
|
|
206
197
|
}
|
|
207
198
|
|
|
@@ -209,11 +200,11 @@ export class Signal {
|
|
|
209
200
|
* Dispatch the signal to all registered listeners.
|
|
210
201
|
* @param {...any} args - Arguments to pass to the listeners.
|
|
211
202
|
*/
|
|
212
|
-
dispatch(...args: any[]) {
|
|
203
|
+
public dispatch(...args: any[]) {
|
|
213
204
|
if (!this.active || !this._bindings) {
|
|
214
205
|
return;
|
|
215
206
|
}
|
|
216
|
-
const paramsArr = args
|
|
207
|
+
const paramsArr = [...args];
|
|
217
208
|
let n = this._bindings.length;
|
|
218
209
|
|
|
219
210
|
if (this.memorize) {
|
|
@@ -223,21 +214,21 @@ export class Signal {
|
|
|
223
214
|
// Should come after memorize
|
|
224
215
|
return;
|
|
225
216
|
}
|
|
226
|
-
const bindings = this._bindings
|
|
217
|
+
const bindings = [...this._bindings]; // clone array in case add/remove items during dispatch
|
|
227
218
|
this._shouldPropagate = true; // in case `halt` was called before dispatch or during the previous dispatch.
|
|
228
219
|
|
|
229
220
|
// execute all callbacks until end of the list or until a callback returns `false` or stops propagation
|
|
230
221
|
// reverse loop since listeners with higher priority will be added at the end of the list
|
|
231
222
|
do {
|
|
232
223
|
n -= 1;
|
|
233
|
-
} while (bindings[n] && this._shouldPropagate && bindings[n]
|
|
224
|
+
} while (bindings[n] && this._shouldPropagate && bindings[n]!.execute(paramsArr) !== false);
|
|
234
225
|
}
|
|
235
226
|
|
|
236
227
|
/**
|
|
237
228
|
* Clear any previously memorized arguments.
|
|
238
229
|
* This removes the stored arguments from a previous dispatch.
|
|
239
230
|
*/
|
|
240
|
-
forget() {
|
|
231
|
+
public forget() {
|
|
241
232
|
if (this._prevParams) {
|
|
242
233
|
this._prevParams = null;
|
|
243
234
|
}
|
|
@@ -247,7 +238,7 @@ export class Signal {
|
|
|
247
238
|
* Dispose of the signal and clean up all resources.
|
|
248
239
|
* This method removes all listeners and clears internal state.
|
|
249
240
|
*/
|
|
250
|
-
dispose() {
|
|
241
|
+
public dispose() {
|
|
251
242
|
this.removeAll();
|
|
252
243
|
this.forget();
|
|
253
244
|
this._bindings = null;
|
|
@@ -257,7 +248,7 @@ export class Signal {
|
|
|
257
248
|
* Get a string representation of the signal.
|
|
258
249
|
* @returns {string} A string representation of the signal.
|
|
259
250
|
*/
|
|
260
|
-
toString() {
|
|
251
|
+
public toString() {
|
|
261
252
|
return `[Signal active:${this.active} numListeners:${this.getNumListeners()}]`;
|
|
262
253
|
}
|
|
263
254
|
|
|
@@ -265,13 +256,11 @@ export class Signal {
|
|
|
265
256
|
* Get a bound version of the dispatch function.
|
|
266
257
|
* @returns {Function} A function that will dispatch the signal with the correct context.
|
|
267
258
|
*/
|
|
268
|
-
get boundDispatch() {
|
|
259
|
+
public get boundDispatch() {
|
|
269
260
|
const _this = this;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
};
|
|
274
|
-
}
|
|
261
|
+
this._boundDispatch ??= (...rest: unknown[]) => {
|
|
262
|
+
_this.dispatch(...rest);
|
|
263
|
+
};
|
|
275
264
|
return this._boundDispatch;
|
|
276
265
|
}
|
|
277
266
|
|
|
@@ -279,7 +268,7 @@ export class Signal {
|
|
|
279
268
|
* Promisify the Signal.
|
|
280
269
|
* @returns {Promise<any>} The resolved result.
|
|
281
270
|
*/
|
|
282
|
-
toPromise() {
|
|
271
|
+
public toPromise() {
|
|
283
272
|
return new Promise((resolve) => {
|
|
284
273
|
this.addOnce((...args: unknown[]) => {
|
|
285
274
|
resolve(args.length <= 1 ? args[0] : args);
|