@vpmedia/phaser 1.112.0 → 1.114.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 +12 -10
- 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.test.ts +110 -0
- 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
|
@@ -2,24 +2,24 @@ import type { DisplayObject } from '../display/display_object.js';
|
|
|
2
2
|
import { Signal } from './signal.js';
|
|
3
3
|
|
|
4
4
|
export class EventManager {
|
|
5
|
-
parent: DisplayObject | null;
|
|
6
|
-
_onAddedToGroup: Signal | null;
|
|
7
|
-
_onRemovedFromGroup: Signal | null;
|
|
8
|
-
_onDestroy: Signal | null;
|
|
9
|
-
_onOutOfBounds: Signal | null;
|
|
10
|
-
_onEnterBounds: Signal | null;
|
|
11
|
-
_onInputOver: Signal | null;
|
|
12
|
-
_onInputOut: Signal | null;
|
|
13
|
-
_onInputDown: Signal | null;
|
|
14
|
-
_onInputUp: Signal | null;
|
|
15
|
-
_onDragStart: Signal | null;
|
|
16
|
-
_onDragUpdate: Signal | null;
|
|
17
|
-
_onDragStop: Signal | null;
|
|
18
|
-
_onAnimationStart: Signal | null;
|
|
19
|
-
_onAnimationComplete: Signal | null;
|
|
20
|
-
_onAnimationLoop: Signal | null;
|
|
21
|
-
|
|
22
|
-
constructor(sprite: DisplayObject) {
|
|
5
|
+
public parent: DisplayObject | null;
|
|
6
|
+
public _onAddedToGroup: Signal | null;
|
|
7
|
+
public _onRemovedFromGroup: Signal | null;
|
|
8
|
+
public _onDestroy: Signal | null;
|
|
9
|
+
public _onOutOfBounds: Signal | null;
|
|
10
|
+
public _onEnterBounds: Signal | null;
|
|
11
|
+
public _onInputOver: Signal | null;
|
|
12
|
+
public _onInputOut: Signal | null;
|
|
13
|
+
public _onInputDown: Signal | null;
|
|
14
|
+
public _onInputUp: Signal | null;
|
|
15
|
+
public _onDragStart: Signal | null;
|
|
16
|
+
public _onDragUpdate: Signal | null;
|
|
17
|
+
public _onDragStop: Signal | null;
|
|
18
|
+
public _onAnimationStart: Signal | null;
|
|
19
|
+
public _onAnimationComplete: Signal | null;
|
|
20
|
+
public _onAnimationLoop: Signal | null;
|
|
21
|
+
|
|
22
|
+
public constructor(sprite: DisplayObject) {
|
|
23
23
|
this.parent = sprite;
|
|
24
24
|
this._onAddedToGroup = null;
|
|
25
25
|
this._onRemovedFromGroup = null;
|
|
@@ -38,7 +38,7 @@ export class EventManager {
|
|
|
38
38
|
this._onAnimationLoop = null;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
destroy(): void {
|
|
41
|
+
public destroy(): void {
|
|
42
42
|
this.parent = null;
|
|
43
43
|
if (this._onDestroy) {
|
|
44
44
|
this._onDestroy.dispose();
|
|
@@ -87,181 +87,151 @@ export class EventManager {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
get onAddedToGroup(): Signal {
|
|
91
|
-
|
|
92
|
-
this._onAddedToGroup = new Signal();
|
|
93
|
-
}
|
|
90
|
+
public get onAddedToGroup(): Signal {
|
|
91
|
+
this._onAddedToGroup ??= new Signal();
|
|
94
92
|
return this._onAddedToGroup;
|
|
95
93
|
}
|
|
96
|
-
onAddedToGroup$dispatch(...args: unknown[]): void {
|
|
94
|
+
public onAddedToGroup$dispatch(...args: unknown[]): void {
|
|
97
95
|
if (this._onAddedToGroup) {
|
|
98
96
|
this._onAddedToGroup.dispatch(...args);
|
|
99
97
|
}
|
|
100
98
|
}
|
|
101
99
|
|
|
102
|
-
get onRemovedFromGroup(): Signal {
|
|
103
|
-
|
|
104
|
-
this._onRemovedFromGroup = new Signal();
|
|
105
|
-
}
|
|
100
|
+
public get onRemovedFromGroup(): Signal {
|
|
101
|
+
this._onRemovedFromGroup ??= new Signal();
|
|
106
102
|
return this._onRemovedFromGroup;
|
|
107
103
|
}
|
|
108
|
-
onRemovedFromGroup$dispatch(...args: unknown[]): void {
|
|
104
|
+
public onRemovedFromGroup$dispatch(...args: unknown[]): void {
|
|
109
105
|
if (this._onRemovedFromGroup) {
|
|
110
106
|
this._onRemovedFromGroup.dispatch(...args);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
113
109
|
|
|
114
|
-
get onDestroy(): Signal {
|
|
115
|
-
|
|
116
|
-
this._onDestroy = new Signal();
|
|
117
|
-
}
|
|
110
|
+
public get onDestroy(): Signal {
|
|
111
|
+
this._onDestroy ??= new Signal();
|
|
118
112
|
return this._onDestroy;
|
|
119
113
|
}
|
|
120
|
-
onDestroy$dispatch(...args: unknown[]): void {
|
|
114
|
+
public onDestroy$dispatch(...args: unknown[]): void {
|
|
121
115
|
if (this._onDestroy) {
|
|
122
116
|
this._onDestroy.dispatch(...args);
|
|
123
117
|
}
|
|
124
118
|
}
|
|
125
119
|
|
|
126
|
-
get onOutOfBounds(): Signal {
|
|
127
|
-
|
|
128
|
-
this._onOutOfBounds = new Signal();
|
|
129
|
-
}
|
|
120
|
+
public get onOutOfBounds(): Signal {
|
|
121
|
+
this._onOutOfBounds ??= new Signal();
|
|
130
122
|
return this._onOutOfBounds;
|
|
131
123
|
}
|
|
132
|
-
onOutOfBounds$dispatch(...args: unknown[]): void {
|
|
124
|
+
public onOutOfBounds$dispatch(...args: unknown[]): void {
|
|
133
125
|
if (this._onOutOfBounds) {
|
|
134
126
|
this._onOutOfBounds.dispatch(...args);
|
|
135
127
|
}
|
|
136
128
|
}
|
|
137
129
|
|
|
138
|
-
get onEnterBounds(): Signal {
|
|
139
|
-
|
|
140
|
-
this._onEnterBounds = new Signal();
|
|
141
|
-
}
|
|
130
|
+
public get onEnterBounds(): Signal {
|
|
131
|
+
this._onEnterBounds ??= new Signal();
|
|
142
132
|
return this._onEnterBounds;
|
|
143
133
|
}
|
|
144
|
-
onEnterBounds$dispatch(...args: unknown[]): void {
|
|
134
|
+
public onEnterBounds$dispatch(...args: unknown[]): void {
|
|
145
135
|
if (this._onEnterBounds) {
|
|
146
136
|
this._onEnterBounds.dispatch(...args);
|
|
147
137
|
}
|
|
148
138
|
}
|
|
149
139
|
|
|
150
|
-
get onInputOver(): Signal {
|
|
151
|
-
|
|
152
|
-
this._onInputOver = new Signal();
|
|
153
|
-
}
|
|
140
|
+
public get onInputOver(): Signal {
|
|
141
|
+
this._onInputOver ??= new Signal();
|
|
154
142
|
return this._onInputOver;
|
|
155
143
|
}
|
|
156
|
-
onInputOver$dispatch(...args: unknown[]): void {
|
|
144
|
+
public onInputOver$dispatch(...args: unknown[]): void {
|
|
157
145
|
if (this._onInputOver) {
|
|
158
146
|
this._onInputOver.dispatch(...args);
|
|
159
147
|
}
|
|
160
148
|
}
|
|
161
149
|
|
|
162
|
-
get onInputOut(): Signal {
|
|
163
|
-
|
|
164
|
-
this._onInputOut = new Signal();
|
|
165
|
-
}
|
|
150
|
+
public get onInputOut(): Signal {
|
|
151
|
+
this._onInputOut ??= new Signal();
|
|
166
152
|
return this._onInputOut;
|
|
167
153
|
}
|
|
168
|
-
onInputOut$dispatch(...args: unknown[]): void {
|
|
154
|
+
public onInputOut$dispatch(...args: unknown[]): void {
|
|
169
155
|
if (this._onInputOut) {
|
|
170
156
|
this._onInputOut.dispatch(...args);
|
|
171
157
|
}
|
|
172
158
|
}
|
|
173
159
|
|
|
174
|
-
get onInputDown(): Signal {
|
|
175
|
-
|
|
176
|
-
this._onInputDown = new Signal();
|
|
177
|
-
}
|
|
160
|
+
public get onInputDown(): Signal {
|
|
161
|
+
this._onInputDown ??= new Signal();
|
|
178
162
|
return this._onInputDown;
|
|
179
163
|
}
|
|
180
|
-
onInputDown$dispatch(...args: unknown[]): void {
|
|
164
|
+
public onInputDown$dispatch(...args: unknown[]): void {
|
|
181
165
|
if (this._onInputDown) {
|
|
182
166
|
this._onInputDown.dispatch(...args);
|
|
183
167
|
}
|
|
184
168
|
}
|
|
185
169
|
|
|
186
|
-
get onInputUp(): Signal {
|
|
187
|
-
|
|
188
|
-
this._onInputUp = new Signal();
|
|
189
|
-
}
|
|
170
|
+
public get onInputUp(): Signal {
|
|
171
|
+
this._onInputUp ??= new Signal();
|
|
190
172
|
return this._onInputUp;
|
|
191
173
|
}
|
|
192
|
-
onInputUp$dispatch(...args: unknown[]): void {
|
|
174
|
+
public onInputUp$dispatch(...args: unknown[]): void {
|
|
193
175
|
if (this._onInputUp) {
|
|
194
176
|
this._onInputUp.dispatch(...args);
|
|
195
177
|
}
|
|
196
178
|
}
|
|
197
179
|
|
|
198
|
-
get onDragStart(): Signal {
|
|
199
|
-
|
|
200
|
-
this._onDragStart = new Signal();
|
|
201
|
-
}
|
|
180
|
+
public get onDragStart(): Signal {
|
|
181
|
+
this._onDragStart ??= new Signal();
|
|
202
182
|
return this._onDragStart;
|
|
203
183
|
}
|
|
204
|
-
onDragStart$dispatch(...args: unknown[]): void {
|
|
184
|
+
public onDragStart$dispatch(...args: unknown[]): void {
|
|
205
185
|
if (this._onDragStart) {
|
|
206
186
|
this._onDragStart.dispatch(...args);
|
|
207
187
|
}
|
|
208
188
|
}
|
|
209
189
|
|
|
210
|
-
get onDragUpdate(): Signal {
|
|
211
|
-
|
|
212
|
-
this._onDragUpdate = new Signal();
|
|
213
|
-
}
|
|
190
|
+
public get onDragUpdate(): Signal {
|
|
191
|
+
this._onDragUpdate ??= new Signal();
|
|
214
192
|
return this._onDragUpdate;
|
|
215
193
|
}
|
|
216
|
-
onDragUpdate$dispatch(...args: unknown[]): void {
|
|
194
|
+
public onDragUpdate$dispatch(...args: unknown[]): void {
|
|
217
195
|
if (this._onDragUpdate) {
|
|
218
196
|
this._onDragUpdate.dispatch(...args);
|
|
219
197
|
}
|
|
220
198
|
}
|
|
221
199
|
|
|
222
|
-
get onDragStop(): Signal {
|
|
223
|
-
|
|
224
|
-
this._onDragStop = new Signal();
|
|
225
|
-
}
|
|
200
|
+
public get onDragStop(): Signal {
|
|
201
|
+
this._onDragStop ??= new Signal();
|
|
226
202
|
return this._onDragStop;
|
|
227
203
|
}
|
|
228
|
-
onDragStop$dispatch(...args: unknown[]): void {
|
|
204
|
+
public onDragStop$dispatch(...args: unknown[]): void {
|
|
229
205
|
if (this._onDragStop) {
|
|
230
206
|
this._onDragStop.dispatch(...args);
|
|
231
207
|
}
|
|
232
208
|
}
|
|
233
209
|
|
|
234
|
-
get onAnimationStart(): Signal {
|
|
235
|
-
|
|
236
|
-
this._onAnimationStart = new Signal();
|
|
237
|
-
}
|
|
210
|
+
public get onAnimationStart(): Signal {
|
|
211
|
+
this._onAnimationStart ??= new Signal();
|
|
238
212
|
return this._onAnimationStart;
|
|
239
213
|
}
|
|
240
|
-
onAnimationStart$dispatch(...args: unknown[]): void {
|
|
214
|
+
public onAnimationStart$dispatch(...args: unknown[]): void {
|
|
241
215
|
if (this._onAnimationStart) {
|
|
242
216
|
this._onAnimationStart.dispatch(...args);
|
|
243
217
|
}
|
|
244
218
|
}
|
|
245
219
|
|
|
246
|
-
get onAnimationComplete(): Signal {
|
|
247
|
-
|
|
248
|
-
this._onAnimationComplete = new Signal();
|
|
249
|
-
}
|
|
220
|
+
public get onAnimationComplete(): Signal {
|
|
221
|
+
this._onAnimationComplete ??= new Signal();
|
|
250
222
|
return this._onAnimationComplete;
|
|
251
223
|
}
|
|
252
|
-
onAnimationComplete$dispatch(...args: unknown[]): void {
|
|
224
|
+
public onAnimationComplete$dispatch(...args: unknown[]): void {
|
|
253
225
|
if (this._onAnimationComplete) {
|
|
254
226
|
this._onAnimationComplete.dispatch(...args);
|
|
255
227
|
}
|
|
256
228
|
}
|
|
257
229
|
|
|
258
|
-
get onAnimationLoop(): Signal {
|
|
259
|
-
|
|
260
|
-
this._onAnimationLoop = new Signal();
|
|
261
|
-
}
|
|
230
|
+
public get onAnimationLoop(): Signal {
|
|
231
|
+
this._onAnimationLoop ??= new Signal();
|
|
262
232
|
return this._onAnimationLoop;
|
|
263
233
|
}
|
|
264
|
-
onAnimationLoop$dispatch(...args: unknown[]): void {
|
|
234
|
+
public onAnimationLoop$dispatch(...args: unknown[]): void {
|
|
265
235
|
if (this._onAnimationLoop) {
|
|
266
236
|
this._onAnimationLoop.dispatch(...args);
|
|
267
237
|
}
|
|
@@ -7,12 +7,12 @@ import { Text } from '../display/text.js';
|
|
|
7
7
|
import type { Game } from './game.js';
|
|
8
8
|
|
|
9
9
|
export class GameObjectFactory {
|
|
10
|
-
game!: Game;
|
|
10
|
+
public game!: Game;
|
|
11
11
|
/**
|
|
12
12
|
* Creates a new GameObjectFactory instance.
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {Game} game - The game instance this factory belongs to.
|
|
14
14
|
*/
|
|
15
|
-
constructor(game: Game) {
|
|
15
|
+
public constructor(game: Game) {
|
|
16
16
|
this.game = game;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -25,7 +25,7 @@ export class GameObjectFactory {
|
|
|
25
25
|
* @param {Group} group - The parent group for the image.
|
|
26
26
|
* @returns {Image} The created Image object.
|
|
27
27
|
*/
|
|
28
|
-
image(x: number, y: number, key: string, frame: any, group: Group | null = null) {
|
|
28
|
+
public image(x: number, y: number, key: string, frame: any, group: Group | null = null) {
|
|
29
29
|
const target = group ?? this.game.world;
|
|
30
30
|
return target.add(new Image(this.game, x, y, key, frame));
|
|
31
31
|
}
|
|
@@ -37,7 +37,7 @@ export class GameObjectFactory {
|
|
|
37
37
|
* @param {boolean} addToStage - Whether to add the group to the stage.
|
|
38
38
|
* @returns {Group} The created Group object.
|
|
39
39
|
*/
|
|
40
|
-
group(parent: Group | null = null, name: string | null = null, addToStage
|
|
40
|
+
public group(parent: Group | null = null, name: string | null = null, addToStage = false) {
|
|
41
41
|
return new Group(this.game, parent, name, addToStage);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -50,8 +50,8 @@ export class GameObjectFactory {
|
|
|
50
50
|
* @param {Group | null} group - The parent group for the text.
|
|
51
51
|
* @returns {Text} The created Text object.
|
|
52
52
|
*/
|
|
53
|
-
text(x: number, y: number, text: any, style: any, group: Group | null = null) {
|
|
54
|
-
const parent = group
|
|
53
|
+
public text(x: number, y: number, text: any, style: any, group: Group | null = null) {
|
|
54
|
+
const parent = group ?? this.game.world;
|
|
55
55
|
return parent.add(new Text(this.game, x, y, text, style));
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -69,7 +69,7 @@ export class GameObjectFactory {
|
|
|
69
69
|
* @param {Group | null} group - The parent group for the button.
|
|
70
70
|
* @returns {Button} The created Button object.
|
|
71
71
|
*/
|
|
72
|
-
button(
|
|
72
|
+
public button(
|
|
73
73
|
x: number,
|
|
74
74
|
y: number,
|
|
75
75
|
key: string,
|
|
@@ -81,7 +81,7 @@ export class GameObjectFactory {
|
|
|
81
81
|
upFrame: string | null = null,
|
|
82
82
|
group: Group | null = null
|
|
83
83
|
) {
|
|
84
|
-
const parent = group
|
|
84
|
+
const parent = group ?? this.game.world;
|
|
85
85
|
return parent.add(
|
|
86
86
|
new Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame)
|
|
87
87
|
);
|
|
@@ -94,8 +94,8 @@ export class GameObjectFactory {
|
|
|
94
94
|
* @param {Group | null} group - The parent group for the graphics object.
|
|
95
95
|
* @returns {Graphics} The created Graphics object.
|
|
96
96
|
*/
|
|
97
|
-
graphics(x
|
|
98
|
-
const parent = group
|
|
97
|
+
public graphics(x = 0, y = 0, group: Group | null = null) {
|
|
98
|
+
const parent = group ?? this.game.world;
|
|
99
99
|
return parent.add(new Graphics(this.game, x, y));
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -110,16 +110,16 @@ export class GameObjectFactory {
|
|
|
110
110
|
* @param {string} align - The alignment of the text.
|
|
111
111
|
* @returns {BitmapText} The created BitmapText object.
|
|
112
112
|
*/
|
|
113
|
-
bitmapText(
|
|
113
|
+
public bitmapText(
|
|
114
114
|
x: number,
|
|
115
115
|
y: number,
|
|
116
116
|
font: string,
|
|
117
117
|
text: string,
|
|
118
118
|
size: number,
|
|
119
119
|
group: Group | null = null,
|
|
120
|
-
align
|
|
120
|
+
align = 'left'
|
|
121
121
|
) {
|
|
122
|
-
const parent = group
|
|
122
|
+
const parent = group ?? this.game.world;
|
|
123
123
|
return parent.add(new BitmapText(this.game, x, y, font, text, size, align));
|
|
124
124
|
}
|
|
125
125
|
}
|
package/src/phaser/core/frame.ts
CHANGED
|
@@ -3,38 +3,38 @@ import { distance } from '../util/math.js';
|
|
|
3
3
|
import { cloneFrame } from './frame_util.js';
|
|
4
4
|
|
|
5
5
|
export class Frame {
|
|
6
|
-
index!: number;
|
|
7
|
-
x!: number;
|
|
8
|
-
y!: number;
|
|
9
|
-
width!: number;
|
|
10
|
-
height!: number;
|
|
11
|
-
name!: string;
|
|
12
|
-
centerX!: number;
|
|
13
|
-
centerY!: number;
|
|
14
|
-
distance!: number;
|
|
15
|
-
rotated!: boolean;
|
|
16
|
-
rotationDirection!: 'cw' | 'ccw';
|
|
17
|
-
trimmed!: boolean;
|
|
18
|
-
sourceSizeW!: number;
|
|
19
|
-
sourceSizeH!: number;
|
|
20
|
-
spriteSourceSizeX!: number;
|
|
21
|
-
spriteSourceSizeY!: number;
|
|
22
|
-
spriteSourceSizeW!: number;
|
|
23
|
-
spriteSourceSizeH!: number;
|
|
24
|
-
right!: number;
|
|
25
|
-
bottom!: number;
|
|
6
|
+
public index!: number;
|
|
7
|
+
public x!: number;
|
|
8
|
+
public y!: number;
|
|
9
|
+
public width!: number;
|
|
10
|
+
public height!: number;
|
|
11
|
+
public name!: string;
|
|
12
|
+
public centerX!: number;
|
|
13
|
+
public centerY!: number;
|
|
14
|
+
public distance!: number;
|
|
15
|
+
public rotated!: boolean;
|
|
16
|
+
public rotationDirection!: 'cw' | 'ccw';
|
|
17
|
+
public trimmed!: boolean;
|
|
18
|
+
public sourceSizeW!: number;
|
|
19
|
+
public sourceSizeH!: number;
|
|
20
|
+
public spriteSourceSizeX!: number;
|
|
21
|
+
public spriteSourceSizeY!: number;
|
|
22
|
+
public spriteSourceSizeW!: number;
|
|
23
|
+
public spriteSourceSizeH!: number;
|
|
24
|
+
public right!: number;
|
|
25
|
+
public bottom!: number;
|
|
26
26
|
|
|
27
|
-
constructor(index: number, x: number, y: number, width: number, height: number, name?: string) {
|
|
27
|
+
public constructor(index: number, x: number, y: number, width: number, height: number, name?: string) {
|
|
28
28
|
this.initialize(index, x, y, width, height, name);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
initialize(index: number, x: number, y: number, width: number, height: number, name?: string): void {
|
|
31
|
+
public initialize(index: number, x: number, y: number, width: number, height: number, name?: string): void {
|
|
32
32
|
this.index = index;
|
|
33
33
|
this.x = x;
|
|
34
34
|
this.y = y;
|
|
35
35
|
this.width = width;
|
|
36
36
|
this.height = height;
|
|
37
|
-
this.name = name
|
|
37
|
+
this.name = name!;
|
|
38
38
|
this.centerX = Math.floor(width / 2);
|
|
39
39
|
this.centerY = Math.floor(height / 2);
|
|
40
40
|
this.distance = distance(0, 0, width, height);
|
|
@@ -51,7 +51,7 @@ export class Frame {
|
|
|
51
51
|
this.bottom = this.y + this.height;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
resize(width: number, height: number): void {
|
|
54
|
+
public resize(width: number, height: number): void {
|
|
55
55
|
this.width = width;
|
|
56
56
|
this.height = height;
|
|
57
57
|
this.centerX = Math.floor(width / 2);
|
|
@@ -63,7 +63,7 @@ export class Frame {
|
|
|
63
63
|
this.bottom = this.y + height;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
setTrim(
|
|
66
|
+
public setTrim(
|
|
67
67
|
trimmed: boolean,
|
|
68
68
|
actualWidth: number,
|
|
69
69
|
actualHeight: number,
|
|
@@ -85,12 +85,12 @@ export class Frame {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
clone(): Frame {
|
|
88
|
+
public clone(): Frame {
|
|
89
89
|
return cloneFrame(this);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
getRect(output: Rectangle | null = null): Rectangle {
|
|
93
|
-
const result = output
|
|
92
|
+
public getRect(output: Rectangle | null = null): Rectangle {
|
|
93
|
+
const result = output ?? new Rectangle();
|
|
94
94
|
result.setTo(this.x, this.y, this.width, this.height);
|
|
95
95
|
return result;
|
|
96
96
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { Frame } from './frame.js';
|
|
3
|
+
import { FrameData } from './frame_data.js';
|
|
4
|
+
|
|
5
|
+
const seed = (names: string[]): FrameData => {
|
|
6
|
+
const data = new FrameData();
|
|
7
|
+
for (const [i, name] of names.entries()) {
|
|
8
|
+
data.addFrame(new Frame(i, i * 10, 0, 10, 10, name));
|
|
9
|
+
}
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('FrameData', () => {
|
|
14
|
+
describe('addFrame', () => {
|
|
15
|
+
it('assigns a sequential index and registers the name', () => {
|
|
16
|
+
const data = seed(['a', 'b']);
|
|
17
|
+
expect(data._frames.map((frame) => frame.index)).toStrictEqual([0, 1]);
|
|
18
|
+
expect(data._frameNames).toStrictEqual({ a: 0, b: 1 });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('does not register an empty name', () => {
|
|
22
|
+
const data = new FrameData();
|
|
23
|
+
data.addFrame(new Frame(0, 0, 0, 10, 10, ''));
|
|
24
|
+
expect(data._frameNames).toStrictEqual({});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('getFrame', () => {
|
|
29
|
+
it('returns the frame at the index', () => {
|
|
30
|
+
const data = seed(['a', 'b', 'c']);
|
|
31
|
+
expect(data.getFrame(1).name).toBe('b');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('falls back to the first frame when the index is out of range', () => {
|
|
35
|
+
const data = seed(['a', 'b']);
|
|
36
|
+
expect(data.getFrame(9).name).toBe('a');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('getFrameByName', () => {
|
|
41
|
+
it('finds a registered frame', () => {
|
|
42
|
+
const data = seed(['a', 'b']);
|
|
43
|
+
expect(data.getFrameByName('b')?.index).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns null for an unknown name', () => {
|
|
47
|
+
const data = seed(['a']);
|
|
48
|
+
expect(data.getFrameByName('missing')).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('returns null when the name maps to a frame that is gone', () => {
|
|
52
|
+
const data = seed(['a']);
|
|
53
|
+
data._frames.length = 0;
|
|
54
|
+
expect(data.getFrameByName('a')).toBeNull();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('checkFrameName', () => {
|
|
59
|
+
it('distinguishes known from unknown names', () => {
|
|
60
|
+
const data = seed(['a']);
|
|
61
|
+
expect(data.checkFrameName('a')).toBe(true);
|
|
62
|
+
expect(data.checkFrameName('b')).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('getFrameRange', () => {
|
|
67
|
+
it('collects the inclusive range', () => {
|
|
68
|
+
const data = seed(['a', 'b', 'c', 'd']);
|
|
69
|
+
expect(data.getFrameRange(1, 2).map((frame) => frame.name)).toStrictEqual(['b', 'c']);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('appends into a supplied output array', () => {
|
|
73
|
+
const data = seed(['a', 'b']);
|
|
74
|
+
const output = [data.getFrame(0)];
|
|
75
|
+
expect(data.getFrameRange(1, 1, output)).toHaveLength(2);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('getFrameIndexes', () => {
|
|
80
|
+
it('maps numeric indexes through', () => {
|
|
81
|
+
const data = seed(['a', 'b', 'c']);
|
|
82
|
+
expect(data.getFrameIndexes([0, 2])).toStrictEqual([0, 2]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('maps names when numeric indexing is off', () => {
|
|
86
|
+
const data = seed(['a', 'b', 'c']);
|
|
87
|
+
expect(data.getFrameIndexes(['c', 'a'], false)).toStrictEqual([2, 0]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('skips names that do not resolve', () => {
|
|
91
|
+
const data = seed(['a']);
|
|
92
|
+
expect(data.getFrameIndexes(['a', 'missing'], false)).toStrictEqual([0]);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('returns every index when given no frames', () => {
|
|
96
|
+
const data = seed(['a', 'b', 'c']);
|
|
97
|
+
expect(data.getFrameIndexes([])).toStrictEqual([0, 1, 2]);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -2,15 +2,15 @@ import type { Frame } from './frame.js';
|
|
|
2
2
|
import { cloneFrameData } from './frame_util.js';
|
|
3
3
|
|
|
4
4
|
export class FrameData {
|
|
5
|
-
_frames: Frame[];
|
|
6
|
-
_frameNames: Record<string, number>;
|
|
5
|
+
public _frames: Frame[];
|
|
6
|
+
public _frameNames: Record<string, number>;
|
|
7
7
|
|
|
8
|
-
constructor() {
|
|
8
|
+
public constructor() {
|
|
9
9
|
this._frames = [];
|
|
10
10
|
this._frameNames = {};
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
addFrame(frame: Frame): Frame {
|
|
13
|
+
public addFrame(frame: Frame): Frame {
|
|
14
14
|
frame.index = this._frames.length;
|
|
15
15
|
this._frames.push(frame);
|
|
16
16
|
if (frame.name !== '') {
|
|
@@ -19,50 +19,50 @@ export class FrameData {
|
|
|
19
19
|
return frame;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
getFrame(index
|
|
22
|
+
public getFrame(index = 0): Frame {
|
|
23
23
|
if (index >= this._frames.length) {
|
|
24
24
|
index = 0;
|
|
25
25
|
}
|
|
26
|
-
return this._frames[index]
|
|
26
|
+
return this._frames[index]!;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
getFrameByName(name: string): Frame | null {
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
public getFrameByName(name: string): Frame | null {
|
|
30
|
+
const index = this._frameNames[name];
|
|
31
|
+
if (typeof index === 'number') {
|
|
32
|
+
return this._frames[index] ?? null;
|
|
32
33
|
}
|
|
33
34
|
return null;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
checkFrameName(name: string): boolean {
|
|
37
|
+
public checkFrameName(name: string): boolean {
|
|
37
38
|
if (this._frameNames[name] == null) {
|
|
38
39
|
return false;
|
|
39
40
|
}
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
clone(): FrameData {
|
|
44
|
+
public clone(): FrameData {
|
|
44
45
|
return cloneFrameData(this);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
getFrameRange(start: number, end: number, output: Frame[] | null = null): Frame[] {
|
|
48
|
-
const result = output
|
|
48
|
+
public getFrameRange(start: number, end: number, output: Frame[] | null = null): Frame[] {
|
|
49
|
+
const result = output ?? [];
|
|
49
50
|
for (let i = start; i <= end; i += 1) {
|
|
50
|
-
result.push(this._frames[i]);
|
|
51
|
+
result.push(this._frames[i]!);
|
|
51
52
|
}
|
|
52
53
|
return result;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
getFrameIndexes(
|
|
56
|
+
public getFrameIndexes(
|
|
56
57
|
frames: (number | string)[],
|
|
57
|
-
useNumericIndex
|
|
58
|
+
useNumericIndex = true,
|
|
58
59
|
output: number[] | null = null
|
|
59
60
|
): number[] {
|
|
60
|
-
const result = output
|
|
61
|
+
const result = output ?? [];
|
|
61
62
|
if (frames && frames.length > 0) {
|
|
62
|
-
for (
|
|
63
|
-
const f = frames[i];
|
|
63
|
+
for (const f of frames) {
|
|
64
64
|
if (useNumericIndex && this._frames[f as number]) {
|
|
65
|
-
result.push(this._frames[f as number]
|
|
65
|
+
result.push(this._frames[f as number]!.index);
|
|
66
66
|
} else {
|
|
67
67
|
const found = this.getFrameByName(f as string);
|
|
68
68
|
if (found) {
|
|
@@ -71,19 +71,19 @@ export class FrameData {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
} else {
|
|
74
|
-
for (
|
|
75
|
-
result.push(
|
|
74
|
+
for (const frame of this._frames) {
|
|
75
|
+
result.push(frame.index);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
return result;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
destroy(): void {
|
|
81
|
+
public destroy(): void {
|
|
82
82
|
this._frames = null as unknown as Frame[];
|
|
83
83
|
this._frameNames = null as unknown as Record<string, number>;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
get total(): number {
|
|
86
|
+
public get total(): number {
|
|
87
87
|
return this._frames.length;
|
|
88
88
|
}
|
|
89
89
|
}
|