@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
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
## [1.96.0] - 2025-12-17
|
|
2
|
+
|
|
3
|
+
### 💼 Other
|
|
4
|
+
|
|
5
|
+
- *(deps)* Bump dependency versions
|
|
6
|
+
|
|
7
|
+
### 📚 Documentation
|
|
8
|
+
|
|
9
|
+
- Improve jsdocs
|
|
10
|
+
- Improve jsdoc comments
|
|
11
|
+
- Improve jsdoc comments
|
|
12
|
+
- Improve jsdoc comments
|
|
13
|
+
- Improve jsdoc comments
|
|
14
|
+
- Improve jsdoc comments
|
|
15
|
+
- Improve jsdoc comments
|
|
16
|
+
- Improve jsdoc comments
|
|
17
|
+
- Regenerated types
|
|
18
|
+
- Improve jsdoc comments
|
|
19
|
+
- Improve jsdoc comments
|
|
20
|
+
- Improved jsdoc comments
|
|
21
|
+
- Improve jsdoc comments
|
|
22
|
+
- Improve jsdoc comments
|
|
23
|
+
- Improve jsdoc comments
|
|
24
|
+
- Improve jsdoc comments
|
|
25
|
+
|
|
26
|
+
### ⚙️ Miscellaneous Tasks
|
|
27
|
+
|
|
28
|
+
- Release
|
|
29
|
+
- *(release)* V1.96.0
|
|
30
|
+
## [1.95.0] - 2025-12-16
|
|
31
|
+
|
|
32
|
+
### 💼 Other
|
|
33
|
+
|
|
34
|
+
- *(deps)* Bump dependency versions
|
|
35
|
+
- *(deps)* Bump dependency versions
|
|
36
|
+
|
|
37
|
+
### ⚙️ Miscellaneous Tasks
|
|
38
|
+
|
|
39
|
+
- Release
|
|
40
|
+
- Improve type checking
|
|
41
|
+
- *(release)* V1.95.0
|
|
1
42
|
## [1.94.0] - 2025-12-11
|
|
2
43
|
|
|
3
44
|
### ⚙️ Miscellaneous Tasks
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vpmedia/phaser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.96.0",
|
|
4
4
|
"description": "@vpmedia/phaser is the modern ECMAScript port of the popular Phaser game engine v2.6.2",
|
|
5
5
|
"author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,27 +23,27 @@
|
|
|
23
23
|
"types": "./types/index.d.ts",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@vpmedia/simplify": "^1.
|
|
26
|
+
"@vpmedia/simplify": "^1.52.0",
|
|
27
27
|
"uuid": "^13.0.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@commitlint/cli": "^20.2.0",
|
|
31
31
|
"@commitlint/config-conventional": "^20.2.0",
|
|
32
|
-
"@eslint/js": "^9.39.
|
|
33
|
-
"@types/node": "^
|
|
34
|
-
"@vitest/coverage-v8": "^4.0.
|
|
35
|
-
"eslint": "^9.39.
|
|
32
|
+
"@eslint/js": "^9.39.2",
|
|
33
|
+
"@types/node": "^25.0.3",
|
|
34
|
+
"@vitest/coverage-v8": "^4.0.16",
|
|
35
|
+
"eslint": "^9.39.2",
|
|
36
36
|
"eslint-plugin-jsdoc": "^61.5.0",
|
|
37
|
-
"eslint-plugin-oxlint": "^1.
|
|
37
|
+
"eslint-plugin-oxlint": "^1.33.0",
|
|
38
38
|
"eslint-plugin-unicorn": "^62.0.0",
|
|
39
39
|
"globals": "^16.5.0",
|
|
40
40
|
"jsdom": "^27.3.0",
|
|
41
|
-
"oxlint": "^1.
|
|
42
|
-
"oxlint-tsgolint": "^0.
|
|
41
|
+
"oxlint": "^1.33.0",
|
|
42
|
+
"oxlint-tsgolint": "^0.9.1",
|
|
43
43
|
"prettier": "^3.7.4",
|
|
44
44
|
"typescript": "^5.9.3",
|
|
45
|
-
"typescript-eslint": "^8.
|
|
46
|
-
"vitest": "^4.0.
|
|
45
|
+
"typescript-eslint": "^8.50.0",
|
|
46
|
+
"vitest": "^4.0.16"
|
|
47
47
|
},
|
|
48
48
|
"browserslist": [
|
|
49
49
|
"> 0.5%",
|
|
@@ -2,37 +2,55 @@ import { Signal } from './signal.js';
|
|
|
2
2
|
|
|
3
3
|
export class Animation {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {import('./game.js').Game} game -
|
|
7
|
-
* @param {import('../display/image.js').Image} parent -
|
|
8
|
-
* @param {string} name -
|
|
9
|
-
* @param {import('./frame_data.js').FrameData} frameData -
|
|
10
|
-
* @param {string[]|number[]} frames -
|
|
11
|
-
* @param {number} frameRate -
|
|
12
|
-
* @param {boolean} loop -
|
|
5
|
+
* Creates a new Animation instance.
|
|
6
|
+
* @param {import('./game.js').Game} game - The game instance this animation belongs to.
|
|
7
|
+
* @param {import('../display/image.js').Image} parent - The Image object that owns this animation.
|
|
8
|
+
* @param {string} name - The unique name of this animation.
|
|
9
|
+
* @param {import('./frame_data.js').FrameData} frameData - The FrameData object that contains the frames for this animation.
|
|
10
|
+
* @param {string[]|number[]} frames - An array of frame identifiers (names or indices) to use in this animation.
|
|
11
|
+
* @param {number} frameRate - The frame rate at which this animation should play (frames per second).
|
|
12
|
+
* @param {boolean} loop - Whether the animation should loop when it completes.
|
|
13
13
|
*/
|
|
14
14
|
constructor(game, parent, name, frameData, frames, frameRate, loop = false) {
|
|
15
|
+
/** @type {import('./game.js').Game} */
|
|
15
16
|
this.game = game;
|
|
16
17
|
this._parent = parent;
|
|
18
|
+
/** @type {import('./frame_data.js').FrameData} */
|
|
17
19
|
this._frameData = frameData;
|
|
20
|
+
/** @type {string} */
|
|
18
21
|
this.name = name;
|
|
19
22
|
this._frames = [];
|
|
20
23
|
this._frames = this._frames.concat(frames);
|
|
24
|
+
/** @type {number} */
|
|
21
25
|
this.delay = 1000 / frameRate;
|
|
26
|
+
/** @type {boolean} */
|
|
22
27
|
this.loop = loop;
|
|
28
|
+
/** @type {number} */
|
|
23
29
|
this.loopCount = 0;
|
|
30
|
+
/** @type {boolean} */
|
|
24
31
|
this.isFinished = false;
|
|
32
|
+
/** @type {boolean} */
|
|
25
33
|
this.isPlaying = false;
|
|
34
|
+
/** @type {boolean} */
|
|
26
35
|
this.isPaused = false;
|
|
36
|
+
/** @type {number} */
|
|
27
37
|
this._pauseStartTime = 0;
|
|
38
|
+
/** @type {number} */
|
|
28
39
|
this._frameIndex = 0;
|
|
40
|
+
/** @type {number} */
|
|
29
41
|
this._frameDiff = 0;
|
|
42
|
+
/** @type {number} */
|
|
30
43
|
this._frameSkip = 1;
|
|
31
44
|
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
|
45
|
+
/** @type {Signal} */
|
|
32
46
|
this.onStart = new Signal();
|
|
47
|
+
/** @type {Signal} */
|
|
33
48
|
this.onUpdate = null;
|
|
49
|
+
/** @type {Signal} */
|
|
34
50
|
this.onComplete = new Signal();
|
|
51
|
+
/** @type {Signal} */
|
|
35
52
|
this.onLoop = new Signal();
|
|
53
|
+
/** @type {boolean} */
|
|
36
54
|
this.isReversed = false;
|
|
37
55
|
// Set-up some event listeners
|
|
38
56
|
this.game.onPause.add(this.onPause, this);
|
|
@@ -40,10 +58,10 @@ export class Animation {
|
|
|
40
58
|
}
|
|
41
59
|
|
|
42
60
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param {number} frameRate -
|
|
45
|
-
* @param {boolean} loop -
|
|
46
|
-
* @returns {Animation}
|
|
61
|
+
* Plays this animation.
|
|
62
|
+
* @param {number} frameRate - The new frame rate to use for this animation (if null, uses the original frame rate).
|
|
63
|
+
* @param {boolean} loop - Whether to loop this animation (if null, uses the original loop setting).
|
|
64
|
+
* @returns {Animation} This Animation instance for chaining.
|
|
47
65
|
*/
|
|
48
66
|
play(frameRate = null, loop = null) {
|
|
49
67
|
if (typeof frameRate === 'number') {
|
|
@@ -70,7 +88,7 @@ export class Animation {
|
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
/**
|
|
73
|
-
*
|
|
91
|
+
* Restarts this animation from the beginning.
|
|
74
92
|
*/
|
|
75
93
|
restart() {
|
|
76
94
|
this.isPlaying = true;
|
|
@@ -88,8 +106,8 @@ export class Animation {
|
|
|
88
106
|
}
|
|
89
107
|
|
|
90
108
|
/**
|
|
91
|
-
*
|
|
92
|
-
* @returns {Animation}
|
|
109
|
+
* Reverses the direction of this animation.
|
|
110
|
+
* @returns {Animation} This Animation instance for chaining.
|
|
93
111
|
*/
|
|
94
112
|
reverse() {
|
|
95
113
|
this.reversed = !this.reversed;
|
|
@@ -97,8 +115,8 @@ export class Animation {
|
|
|
97
115
|
}
|
|
98
116
|
|
|
99
117
|
/**
|
|
100
|
-
*
|
|
101
|
-
* @returns {Animation}
|
|
118
|
+
* Reverses the animation direction once, then returns to normal direction.
|
|
119
|
+
* @returns {Animation} This Animation instance for chaining.
|
|
102
120
|
*/
|
|
103
121
|
reverseOnce() {
|
|
104
122
|
this.onComplete.addOnce(this.reverse, this);
|
|
@@ -106,9 +124,9 @@ export class Animation {
|
|
|
106
124
|
}
|
|
107
125
|
|
|
108
126
|
/**
|
|
109
|
-
*
|
|
110
|
-
* @param {string|number} frameId -
|
|
111
|
-
* @param {boolean} useLocalFrameIndex -
|
|
127
|
+
* Sets the current frame of this animation.
|
|
128
|
+
* @param {string|number} frameId - The identifier (name or index) of the frame to set.
|
|
129
|
+
* @param {boolean} useLocalFrameIndex - If true, treats frameId as an index into the local frames array.
|
|
112
130
|
*/
|
|
113
131
|
setFrame(frameId, useLocalFrameIndex = false) {
|
|
114
132
|
let frameIndex;
|
|
@@ -140,9 +158,9 @@ export class Animation {
|
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param {boolean} resetFrame -
|
|
145
|
-
* @param {boolean} dispatchComplete -
|
|
161
|
+
* Stops this animation.
|
|
162
|
+
* @param {boolean} resetFrame - If true, resets to the first frame.
|
|
163
|
+
* @param {boolean} dispatchComplete - If true, dispatches the onComplete signal.
|
|
146
164
|
*/
|
|
147
165
|
stop(resetFrame = false, dispatchComplete = false) {
|
|
148
166
|
this.isPlaying = false;
|
|
@@ -161,7 +179,7 @@ export class Animation {
|
|
|
161
179
|
}
|
|
162
180
|
|
|
163
181
|
/**
|
|
164
|
-
*
|
|
182
|
+
* Called when the game is paused.
|
|
165
183
|
*/
|
|
166
184
|
onPause() {
|
|
167
185
|
if (this.isPlaying) {
|
|
@@ -170,7 +188,7 @@ export class Animation {
|
|
|
170
188
|
}
|
|
171
189
|
|
|
172
190
|
/**
|
|
173
|
-
*
|
|
191
|
+
* Called when the game is resumed.
|
|
174
192
|
*/
|
|
175
193
|
onResume() {
|
|
176
194
|
if (this.isPlaying) {
|
|
@@ -179,8 +197,8 @@ export class Animation {
|
|
|
179
197
|
}
|
|
180
198
|
|
|
181
199
|
/**
|
|
182
|
-
*
|
|
183
|
-
* @returns {boolean}
|
|
200
|
+
* Updates this animation.
|
|
201
|
+
* @returns {boolean} True if the animation was updated, false otherwise.
|
|
184
202
|
*/
|
|
185
203
|
update() {
|
|
186
204
|
if (this.isPaused) {
|
|
@@ -238,10 +256,10 @@ export class Animation {
|
|
|
238
256
|
}
|
|
239
257
|
|
|
240
258
|
/**
|
|
241
|
-
*
|
|
242
|
-
* @param {boolean} signalUpdate -
|
|
243
|
-
* @param {boolean} fromPlay -
|
|
244
|
-
* @returns {boolean}
|
|
259
|
+
* Updates the current frame of this animation.
|
|
260
|
+
* @param {boolean} signalUpdate - Whether to signal the update event.
|
|
261
|
+
* @param {boolean} fromPlay - Whether this call is from play().
|
|
262
|
+
* @returns {boolean} True if the frame was updated, false otherwise.
|
|
245
263
|
*/
|
|
246
264
|
updateCurrentFrame(signalUpdate, fromPlay = false) {
|
|
247
265
|
if (!this._frameData || !this.currentFrame) {
|
|
@@ -263,8 +281,8 @@ export class Animation {
|
|
|
263
281
|
}
|
|
264
282
|
|
|
265
283
|
/**
|
|
266
|
-
*
|
|
267
|
-
* @param {number} quantity -
|
|
284
|
+
* Advances the animation to the next frame(s).
|
|
285
|
+
* @param {number} quantity - The number of frames to advance by.
|
|
268
286
|
*/
|
|
269
287
|
next(quantity = 1) {
|
|
270
288
|
let frame = this._frameIndex + quantity;
|
|
@@ -282,8 +300,8 @@ export class Animation {
|
|
|
282
300
|
}
|
|
283
301
|
|
|
284
302
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @param {number} quantity -
|
|
303
|
+
* Moves the animation to the previous frame(s).
|
|
304
|
+
* @param {number} quantity - The number of frames to move back by.
|
|
287
305
|
*/
|
|
288
306
|
previous(quantity = 1) {
|
|
289
307
|
let frame = this._frameIndex - quantity;
|
|
@@ -301,8 +319,8 @@ export class Animation {
|
|
|
301
319
|
}
|
|
302
320
|
|
|
303
321
|
/**
|
|
304
|
-
*
|
|
305
|
-
* @param {import('./frame_data.js').FrameData} frameData -
|
|
322
|
+
* Updates the frame data used by this animation.
|
|
323
|
+
* @param {import('./frame_data.js').FrameData} frameData - The new FrameData object to use.
|
|
306
324
|
*/
|
|
307
325
|
updateFrameData(frameData) {
|
|
308
326
|
this._frameData = frameData;
|
|
@@ -312,7 +330,7 @@ export class Animation {
|
|
|
312
330
|
}
|
|
313
331
|
|
|
314
332
|
/**
|
|
315
|
-
*
|
|
333
|
+
* Destroys this animation and cleans up resources.
|
|
316
334
|
*/
|
|
317
335
|
destroy() {
|
|
318
336
|
if (!this._frameData) {
|
|
@@ -336,7 +354,7 @@ export class Animation {
|
|
|
336
354
|
}
|
|
337
355
|
|
|
338
356
|
/**
|
|
339
|
-
*
|
|
357
|
+
* Completes this animation, setting it to the final frame.
|
|
340
358
|
*/
|
|
341
359
|
complete() {
|
|
342
360
|
this._frameIndex = this._frames.length - 1;
|
|
@@ -349,15 +367,16 @@ export class Animation {
|
|
|
349
367
|
}
|
|
350
368
|
|
|
351
369
|
/**
|
|
352
|
-
*
|
|
353
|
-
* @returns {boolean}
|
|
370
|
+
* Gets whether this animation is currently paused.
|
|
371
|
+
* @returns {boolean} True if the animation is paused, false otherwise.
|
|
354
372
|
*/
|
|
355
373
|
get paused() {
|
|
356
374
|
return this.isPaused;
|
|
357
375
|
}
|
|
358
376
|
|
|
359
377
|
/**
|
|
360
|
-
*
|
|
378
|
+
* Sets whether this animation is currently paused.
|
|
379
|
+
* @param {boolean} value - True to pause the animation, false to resume it.
|
|
361
380
|
*/
|
|
362
381
|
set paused(value) {
|
|
363
382
|
this.isPaused = value;
|
|
@@ -369,31 +388,32 @@ export class Animation {
|
|
|
369
388
|
}
|
|
370
389
|
|
|
371
390
|
/**
|
|
372
|
-
*
|
|
373
|
-
* @returns {boolean}
|
|
391
|
+
* Gets whether this animation is currently reversed.
|
|
392
|
+
* @returns {boolean} True if the animation is reversed, false otherwise.
|
|
374
393
|
*/
|
|
375
394
|
get reversed() {
|
|
376
395
|
return this.isReversed;
|
|
377
396
|
}
|
|
378
397
|
|
|
379
398
|
/**
|
|
380
|
-
*
|
|
399
|
+
* Sets whether this animation is currently reversed.
|
|
400
|
+
* @param {boolean} value - True to reverse the animation, false to normal direction.
|
|
381
401
|
*/
|
|
382
402
|
set reversed(value) {
|
|
383
403
|
this.isReversed = value;
|
|
384
404
|
}
|
|
385
405
|
|
|
386
406
|
/**
|
|
387
|
-
*
|
|
388
|
-
* @returns {number}
|
|
407
|
+
* Gets the total number of frames in this animation.
|
|
408
|
+
* @returns {number} The total number of frames.
|
|
389
409
|
*/
|
|
390
410
|
get frameTotal() {
|
|
391
411
|
return this._frames.length;
|
|
392
412
|
}
|
|
393
413
|
|
|
394
414
|
/**
|
|
395
|
-
*
|
|
396
|
-
* @returns {number}
|
|
415
|
+
* Gets the current frame index.
|
|
416
|
+
* @returns {number} The current frame index.
|
|
397
417
|
*/
|
|
398
418
|
get frame() {
|
|
399
419
|
if (this.currentFrame !== null) {
|
|
@@ -403,7 +423,8 @@ export class Animation {
|
|
|
403
423
|
}
|
|
404
424
|
|
|
405
425
|
/**
|
|
406
|
-
*
|
|
426
|
+
* Sets the current frame index.
|
|
427
|
+
* @param {number} value - The new frame index to set.
|
|
407
428
|
*/
|
|
408
429
|
set frame(value) {
|
|
409
430
|
this.currentFrame = this._frameData.getFrame(this._frames[value]);
|
|
@@ -417,15 +438,16 @@ export class Animation {
|
|
|
417
438
|
}
|
|
418
439
|
|
|
419
440
|
/**
|
|
420
|
-
*
|
|
421
|
-
* @returns {number}
|
|
441
|
+
* Gets the current animation speed (frame rate).
|
|
442
|
+
* @returns {number} The frame rate in frames per second.
|
|
422
443
|
*/
|
|
423
444
|
get speed() {
|
|
424
445
|
return 1000 / this.delay;
|
|
425
446
|
}
|
|
426
447
|
|
|
427
448
|
/**
|
|
428
|
-
*
|
|
449
|
+
* Sets the animation speed (frame rate).
|
|
450
|
+
* @param {number} value - The new frame rate in frames per second.
|
|
429
451
|
*/
|
|
430
452
|
set speed(value) {
|
|
431
453
|
if (value > 0) {
|
|
@@ -434,15 +456,16 @@ export class Animation {
|
|
|
434
456
|
}
|
|
435
457
|
|
|
436
458
|
/**
|
|
437
|
-
*
|
|
438
|
-
* @returns {boolean}
|
|
459
|
+
* Gets whether the update signal is enabled.
|
|
460
|
+
* @returns {boolean} True if the update signal is enabled, false otherwise.
|
|
439
461
|
*/
|
|
440
462
|
get enableUpdate() {
|
|
441
463
|
return this.onUpdate !== null;
|
|
442
464
|
}
|
|
443
465
|
|
|
444
466
|
/**
|
|
445
|
-
*
|
|
467
|
+
* Sets whether the update signal is enabled.
|
|
468
|
+
* @param {boolean} value - True to enable the update signal, false to disable it.
|
|
446
469
|
*/
|
|
447
470
|
set enableUpdate(value) {
|
|
448
471
|
if (value && this.onUpdate === null) {
|
|
@@ -3,8 +3,8 @@ import { ENGINE_ERROR_CANNOT_SET_FRAME, ENGINE_ERROR_CANNOT_SET_FRAME_NAME } fro
|
|
|
3
3
|
|
|
4
4
|
export class AnimationManager {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {import('../display/image.js').Image} sprite -
|
|
6
|
+
* Creates a new AnimationManager instance.
|
|
7
|
+
* @param {import('../display/image.js').Image} sprite - Reference to the parent Sprite.
|
|
8
8
|
*/
|
|
9
9
|
constructor(sprite) {
|
|
10
10
|
this.sprite = sprite;
|
|
@@ -24,7 +24,7 @@ export class AnimationManager {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Destroys the AnimationManager and cleans up resources.
|
|
28
28
|
*/
|
|
29
29
|
destroy() {
|
|
30
30
|
const keys = Object.keys(this._anims);
|
|
@@ -41,10 +41,10 @@ export class AnimationManager {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @param {import('./frame_data.js').FrameData} frameData -
|
|
46
|
-
* @param {string|number} frame -
|
|
47
|
-
* @returns {boolean}
|
|
44
|
+
* Loads frame data into the AnimationManager.
|
|
45
|
+
* @param {import('./frame_data.js').FrameData} frameData - The FrameData to load.
|
|
46
|
+
* @param {string|number} frame - The frame index or name to set as current.
|
|
47
|
+
* @returns {boolean} True if the frame data was loaded successfully, false otherwise.
|
|
48
48
|
*/
|
|
49
49
|
loadFrameData(frameData, frame) {
|
|
50
50
|
if (!frameData) {
|
|
@@ -71,10 +71,10 @@ export class AnimationManager {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @param {import('./frame_data.js').FrameData} frameData -
|
|
76
|
-
* @param {string|number} frame -
|
|
77
|
-
* @returns {boolean}
|
|
74
|
+
* Copies frame data into the AnimationManager.
|
|
75
|
+
* @param {import('./frame_data.js').FrameData} frameData - The FrameData to copy.
|
|
76
|
+
* @param {string|number} frame - The frame index or name to set as current.
|
|
77
|
+
* @returns {boolean} True if the frame data was copied successfully, false otherwise.
|
|
78
78
|
*/
|
|
79
79
|
copyFrameData(frameData, frame) {
|
|
80
80
|
this._frameData = frameData.clone();
|
|
@@ -98,13 +98,13 @@ export class AnimationManager {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
102
|
-
* @param {string} name -
|
|
103
|
-
* @param {number[] | string[] | null | undefined} frameList -
|
|
104
|
-
* @param {number} frameRate -
|
|
105
|
-
* @param {boolean} loop -
|
|
106
|
-
* @param {boolean | undefined} useNumericIndex -
|
|
107
|
-
* @returns {Animation}
|
|
101
|
+
* Adds a new animation to the AnimationManager.
|
|
102
|
+
* @param {string} name - The name of the animation.
|
|
103
|
+
* @param {number[] | string[] | null | undefined} frameList - The list of frames to include in the animation.
|
|
104
|
+
* @param {number} frameRate - The frame rate of the animation (frames per second).
|
|
105
|
+
* @param {boolean} loop - Whether the animation should loop.
|
|
106
|
+
* @param {boolean | undefined} useNumericIndex - Whether to treat frameList as numeric indices.
|
|
107
|
+
* @returns {Animation} The created Animation object.
|
|
108
108
|
*/
|
|
109
109
|
add(name, frameList, frameRate = 60, loop = false, useNumericIndex = undefined) {
|
|
110
110
|
const frames = frameList || [];
|
|
@@ -135,10 +135,10 @@ export class AnimationManager {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
139
|
-
* @param {string[] | number[]} frames -
|
|
140
|
-
* @param {boolean} useNumericIndex -
|
|
141
|
-
* @returns {boolean}
|
|
138
|
+
* Validates a list of frames against the current frame data.
|
|
139
|
+
* @param {string[] | number[]} frames - The list of frames to validate.
|
|
140
|
+
* @param {boolean} useNumericIndex - Whether to treat frameList as numeric indices.
|
|
141
|
+
* @returns {boolean} True if all frames are valid, false otherwise.
|
|
142
142
|
*/
|
|
143
143
|
validateFrames(frames, useNumericIndex = false) {
|
|
144
144
|
for (let i = 0; i < frames.length; i += 1) {
|
|
@@ -154,11 +154,11 @@ export class AnimationManager {
|
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
158
|
-
* @param {string} name -
|
|
159
|
-
* @param {number} frameRate -
|
|
160
|
-
* @param {boolean} loop -
|
|
161
|
-
* @returns {Animation}
|
|
157
|
+
* Plays an animation by name.
|
|
158
|
+
* @param {string} name - The name of the animation to play.
|
|
159
|
+
* @param {number} frameRate - The frame rate (frames per second) to play at, or null to use the animation's default.
|
|
160
|
+
* @param {boolean} loop - Whether the animation should loop, or null to use the animation's default.
|
|
161
|
+
* @returns {Animation} The Animation object that was played, or null if not found.
|
|
162
162
|
*/
|
|
163
163
|
play(name, frameRate = null, loop = null) {
|
|
164
164
|
if (this._anims[name]) {
|
|
@@ -181,9 +181,9 @@ export class AnimationManager {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
*
|
|
185
|
-
* @param {string} name -
|
|
186
|
-
* @param {boolean} resetFrame -
|
|
184
|
+
* Stops an animation by name.
|
|
185
|
+
* @param {string} name - The name of the animation to stop, or null to stop the current animation.
|
|
186
|
+
* @param {boolean} resetFrame - Whether to reset the frame to the first frame of the animation.
|
|
187
187
|
*/
|
|
188
188
|
stop(name = null, resetFrame = false) {
|
|
189
189
|
if (this.currentAnim && (typeof name !== 'string' || name === this.currentAnim.name)) {
|
|
@@ -192,8 +192,8 @@ export class AnimationManager {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
|
-
*
|
|
196
|
-
* @returns {boolean}
|
|
195
|
+
* Updates the animation manager state.
|
|
196
|
+
* @returns {boolean} True if an animation was updated, false otherwise.
|
|
197
197
|
*/
|
|
198
198
|
update() {
|
|
199
199
|
if (this.updateIfVisible && !this.sprite.visible) {
|
|
@@ -207,8 +207,8 @@ export class AnimationManager {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @param {number} quantity -
|
|
210
|
+
* Advances the current animation by a specified number of frames.
|
|
211
|
+
* @param {number} quantity - The number of frames to advance by.
|
|
212
212
|
*/
|
|
213
213
|
next(quantity) {
|
|
214
214
|
if (this.currentAnim) {
|
|
@@ -218,8 +218,8 @@ export class AnimationManager {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
|
-
*
|
|
222
|
-
* @param {number} quantity -
|
|
221
|
+
* Moves the current animation back by a specified number of frames.
|
|
222
|
+
* @param {number} quantity - The number of frames to move back by.
|
|
223
223
|
*/
|
|
224
224
|
previous(quantity) {
|
|
225
225
|
if (this.currentAnim) {
|
|
@@ -229,9 +229,9 @@ export class AnimationManager {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
|
-
*
|
|
233
|
-
* @param {string} name -
|
|
234
|
-
* @returns {Animation}
|
|
232
|
+
* Gets an animation by name.
|
|
233
|
+
* @param {string} name - The name of the animation to retrieve.
|
|
234
|
+
* @returns {Animation} The Animation object, or null if not found.
|
|
235
235
|
*/
|
|
236
236
|
getAnimation(name) {
|
|
237
237
|
if (name && this._anims[name]) {
|
|
@@ -241,7 +241,7 @@ export class AnimationManager {
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
/**
|
|
244
|
-
*
|
|
244
|
+
* Refreshes the current frame texture (not implemented).
|
|
245
245
|
*/
|
|
246
246
|
refreshFrame() {
|
|
247
247
|
// TODO
|
|
@@ -250,39 +250,39 @@ export class AnimationManager {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
/**
|
|
253
|
-
*
|
|
254
|
-
* @returns {import('./frame_data.js').FrameData}
|
|
253
|
+
* Gets the frame data used by this AnimationManager.
|
|
254
|
+
* @returns {import('./frame_data.js').FrameData} The FrameData object.
|
|
255
255
|
*/
|
|
256
256
|
get frameData() {
|
|
257
257
|
return this._frameData;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
/**
|
|
261
|
-
*
|
|
262
|
-
* @returns {number}
|
|
261
|
+
* Gets the total number of frames in the frame data.
|
|
262
|
+
* @returns {number} The total number of frames.
|
|
263
263
|
*/
|
|
264
264
|
get frameTotal() {
|
|
265
265
|
return this._frameData.total;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
/**
|
|
269
|
-
*
|
|
270
|
-
* @returns {boolean}
|
|
269
|
+
* Gets the paused state of the current animation.
|
|
270
|
+
* @returns {boolean} True if the current animation is paused, false otherwise.
|
|
271
271
|
*/
|
|
272
272
|
get paused() {
|
|
273
273
|
return this.currentAnim.isPaused;
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
/**
|
|
277
|
-
*
|
|
277
|
+
* Sets the paused state of the current animation.
|
|
278
278
|
*/
|
|
279
279
|
set paused(value) {
|
|
280
280
|
this.currentAnim.paused = value;
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
/**
|
|
284
|
-
*
|
|
285
|
-
* @returns {string}
|
|
284
|
+
* Gets the name of the current animation.
|
|
285
|
+
* @returns {string} The name of the current animation, or null if no animation is active.
|
|
286
286
|
*/
|
|
287
287
|
get name() {
|
|
288
288
|
if (this.currentAnim) {
|
|
@@ -292,8 +292,8 @@ export class AnimationManager {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
/**
|
|
295
|
-
*
|
|
296
|
-
* @returns {number}
|
|
295
|
+
* Gets the current frame index.
|
|
296
|
+
* @returns {number} The current frame index.
|
|
297
297
|
*/
|
|
298
298
|
get frame() {
|
|
299
299
|
if (this.currentFrame) {
|
|
@@ -303,7 +303,7 @@ export class AnimationManager {
|
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
/**
|
|
306
|
-
*
|
|
306
|
+
* Sets the current frame index.
|
|
307
307
|
*/
|
|
308
308
|
set frame(value) {
|
|
309
309
|
if (typeof value === 'number' && this._frameData && this._frameData.getFrame(value) !== null) {
|
|
@@ -319,8 +319,8 @@ export class AnimationManager {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
/**
|
|
322
|
-
*
|
|
323
|
-
* @returns {string}
|
|
322
|
+
* Gets the current frame name.
|
|
323
|
+
* @returns {string} The current frame name, or null if no frame is set.
|
|
324
324
|
*/
|
|
325
325
|
get frameName() {
|
|
326
326
|
if (this.currentFrame) {
|
|
@@ -330,7 +330,7 @@ export class AnimationManager {
|
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
/**
|
|
333
|
-
*
|
|
333
|
+
* Sets the current frame by name.
|
|
334
334
|
*/
|
|
335
335
|
set frameName(value) {
|
|
336
336
|
if (typeof value === 'string' && this._frameData && this._frameData.getFrameByName(value) !== null) {
|