@vpmedia/phaser 1.95.0 → 1.97.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 +51 -0
- package/package.json +10 -10
- package/src/phaser/core/animation.js +61 -56
- package/src/phaser/core/animation_manager.js +55 -55
- 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 +34 -18
- package/src/phaser/core/loader.js +170 -170
- package/src/phaser/core/loader_parser.js +22 -22
- package/src/phaser/core/raf.js +1 -1
- package/src/phaser/core/scene.js +16 -10
- package/src/phaser/core/scene_manager.js +51 -43
- package/src/phaser/core/signal.js +68 -52
- package/src/phaser/core/signal.test.js +37 -0
- 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 +30 -30
- package/src/phaser/core/timer.js +79 -64
- package/src/phaser/core/timer_event.js +9 -9
- package/src/phaser/core/tween.js +90 -90
- package/src/phaser/core/tween_data.js +30 -30
- package/src/phaser/core/tween_manager.js +29 -24
- package/src/phaser/core/world.js +4 -3
- package/src/phaser/display/bitmap_text.js +61 -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 +16 -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 +112 -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 +50 -50
- package/src/phaser/display/image.js +54 -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 +212 -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 +20 -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 +69 -69
- package/src/phaser/geom/circle.test.js +1 -0
- package/src/phaser/geom/ellipse.js +28 -28
- package/src/phaser/geom/ellipse.test.js +1 -0
- package/src/phaser/geom/line.js +93 -93
- package/src/phaser/geom/line.test.js +1 -0
- package/src/phaser/geom/matrix.js +54 -54
- package/src/phaser/geom/matrix.test.js +1 -0
- package/src/phaser/geom/point.js +96 -96
- package/src/phaser/geom/point.test.js +1 -0
- package/src/phaser/geom/polygon.js +22 -22
- package/src/phaser/geom/rectangle.js +132 -132
- package/src/phaser/geom/rectangle.test.js +1 -0
- package/src/phaser/geom/rounded_rectangle.js +12 -12
- package/src/phaser/geom/rounded_rectangle.test.js +1 -0
- package/src/phaser/geom/util/circle.js +33 -33
- package/src/phaser/geom/util/circle.test.js +1 -0
- package/src/phaser/geom/util/ellipse.js +5 -5
- package/src/phaser/geom/util/ellipse.test.js +1 -0
- package/src/phaser/geom/util/line.js +26 -26
- package/src/phaser/geom/util/line.test.js +1 -0
- package/src/phaser/geom/util/matrix.js +8 -8
- package/src/phaser/geom/util/matrix.test.js +1 -0
- package/src/phaser/geom/util/point.js +97 -97
- package/src/phaser/geom/util/point.test.js +1 -0
- package/src/phaser/geom/util/polygon.js +4 -4
- package/src/phaser/geom/util/polygon.test.js +1 -0
- package/src/phaser/geom/util/rectangle.js +74 -74
- package/src/phaser/geom/util/rectangle.test.js +1 -0
- package/src/phaser/geom/util/rounded_rectangle.js +4 -4
- package/src/phaser/geom/util/rounded_rectangle.test.js +1 -0
- package/src/phaser/util/math.js +81 -81
- package/src/phaser/util/math.test.js +1 -0
- package/types/phaser/core/animation.d.ts +61 -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/cache.d.ts +154 -154
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +43 -43
- 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 +52 -19
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +170 -170
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +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 +30 -30
- package/types/phaser/core/timer.d.ts +64 -64
- package/types/phaser/core/timer_event.d.ts +9 -9
- package/types/phaser/core/tween.d.ts +90 -90
- package/types/phaser/core/tween_data.d.ts +30 -30
- package/types/phaser/core/tween_manager.d.ts +29 -24
- 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 +59 -52
- 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/renderer.d.ts +16 -16
- 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 +101 -101
- package/types/phaser/display/graphics_data.d.ts +10 -10
- package/types/phaser/display/group.d.ts +47 -47
- package/types/phaser/display/image.d.ts +42 -40
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +207 -184
- 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 +9 -9
- 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_data.d.ts +4 -4
- package/types/phaser/display/webgl/render_texture.d.ts +16 -16
- package/types/phaser/display/webgl/renderer.d.ts +20 -20
- 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/geom/circle.d.ts +69 -69
- package/types/phaser/geom/ellipse.d.ts +28 -28
- package/types/phaser/geom/line.d.ts +93 -93
- package/types/phaser/geom/matrix.d.ts +54 -54
- package/types/phaser/geom/point.d.ts +96 -96
- package/types/phaser/geom/polygon.d.ts +22 -22
- package/types/phaser/geom/rectangle.d.ts +132 -132
- package/types/phaser/geom/rounded_rectangle.d.ts +12 -12
- package/pnpm-workspace.yaml +0 -4
package/src/phaser/core/time.js
CHANGED
|
@@ -2,8 +2,8 @@ import { Timer } from './timer.js';
|
|
|
2
2
|
|
|
3
3
|
export class Time {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {import('./game.js').Game} game -
|
|
5
|
+
* Creates a new Time instance.
|
|
6
|
+
* @param {import('./game.js').Game} game - Reference to the Phaser Game instance.
|
|
7
7
|
*/
|
|
8
8
|
constructor(game) {
|
|
9
9
|
this.game = game;
|
|
@@ -61,7 +61,7 @@ export class Time {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Initializes the time manager and starts tracking time.
|
|
65
65
|
*/
|
|
66
66
|
boot() {
|
|
67
67
|
this._started = Date.now();
|
|
@@ -71,9 +71,9 @@ export class Time {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
75
|
-
* @param {Timer} timer -
|
|
76
|
-
* @returns {Timer}
|
|
74
|
+
* Adds a Timer to the Time manager.
|
|
75
|
+
* @param {Timer} timer - The Timer to add.
|
|
76
|
+
* @returns {Timer} The added Timer object.
|
|
77
77
|
*/
|
|
78
78
|
add(timer) {
|
|
79
79
|
this._timers.push(timer);
|
|
@@ -81,9 +81,9 @@ export class Time {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
85
|
-
* @param {boolean} autoDestroy -
|
|
86
|
-
* @returns {Timer}
|
|
84
|
+
* Creates a new Timer and adds it to the Time manager.
|
|
85
|
+
* @param {boolean} autoDestroy - Whether the timer should be automatically destroyed when it completes.
|
|
86
|
+
* @returns {Timer} The created Timer object.
|
|
87
87
|
*/
|
|
88
88
|
create(autoDestroy = true) {
|
|
89
89
|
const timer = new Timer(this.game, autoDestroy);
|
|
@@ -92,7 +92,7 @@ export class Time {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* Removes all timers from the Time manager.
|
|
96
96
|
*/
|
|
97
97
|
removeAll() {
|
|
98
98
|
for (let i = 0; i < this._timers.length; i += 1) {
|
|
@@ -103,7 +103,7 @@ export class Time {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Refreshes the time tracking values.
|
|
107
107
|
*/
|
|
108
108
|
refresh() {
|
|
109
109
|
const previousDateNow = this.time;
|
|
@@ -114,8 +114,8 @@ export class Time {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @param {number} time -
|
|
117
|
+
* Updates the Time manager with a new timestamp.
|
|
118
|
+
* @param {number} time - The new timestamp to use for updating.
|
|
119
119
|
*/
|
|
120
120
|
update(time) {
|
|
121
121
|
const previousDateNow = this.time;
|
|
@@ -144,7 +144,7 @@ export class Time {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
*
|
|
147
|
+
* Updates all timers managed by the Time manager.
|
|
148
148
|
*/
|
|
149
149
|
updateTimers() {
|
|
150
150
|
let i = 0;
|
|
@@ -161,7 +161,7 @@ export class Time {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
|
-
*
|
|
164
|
+
* Updates the advanced timing values.
|
|
165
165
|
*/
|
|
166
166
|
updateAdvancedTiming() {
|
|
167
167
|
// count the number of time.update calls
|
|
@@ -187,7 +187,7 @@ export class Time {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
/**
|
|
190
|
-
*
|
|
190
|
+
* Handles game pause event.
|
|
191
191
|
*/
|
|
192
192
|
gamePaused() {
|
|
193
193
|
this._pauseStarted = Date.now();
|
|
@@ -200,7 +200,7 @@ export class Time {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
203
|
+
* Handles game resume event.
|
|
204
204
|
*/
|
|
205
205
|
gameResumed() {
|
|
206
206
|
this.time = Date.now();
|
|
@@ -214,33 +214,33 @@ export class Time {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
/**
|
|
217
|
-
*
|
|
218
|
-
* @returns {number}
|
|
217
|
+
* Gets the total elapsed time in seconds since the game started.
|
|
218
|
+
* @returns {number} The total elapsed time in seconds.
|
|
219
219
|
*/
|
|
220
220
|
totalElapsedSeconds() {
|
|
221
221
|
return (this.time - this._started) * 0.001;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
/**
|
|
225
|
-
*
|
|
226
|
-
* @param {number} since -
|
|
227
|
-
* @returns {number}
|
|
225
|
+
* Gets the elapsed time in milliseconds since a given timestamp.
|
|
226
|
+
* @param {number} since - The timestamp to calculate elapsed time from.
|
|
227
|
+
* @returns {number} The elapsed time in milliseconds.
|
|
228
228
|
*/
|
|
229
229
|
elapsedSince(since) {
|
|
230
230
|
return this.time - since;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
|
-
*
|
|
235
|
-
* @param {number} since -
|
|
236
|
-
* @returns {number}
|
|
234
|
+
* Gets the elapsed time in seconds since a given timestamp.
|
|
235
|
+
* @param {number} since - The timestamp to calculate elapsed time from.
|
|
236
|
+
* @returns {number} The elapsed time in seconds.
|
|
237
237
|
*/
|
|
238
238
|
elapsedSecondsSince(since) {
|
|
239
239
|
return (this.time - since) * 0.001;
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
/**
|
|
243
|
-
*
|
|
243
|
+
* Resets the time tracking values.
|
|
244
244
|
*/
|
|
245
245
|
reset() {
|
|
246
246
|
this._started = this.time;
|
|
@@ -248,22 +248,22 @@ export class Time {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
|
-
*
|
|
251
|
+
* Destroys the Time manager and cleans up resources.
|
|
252
252
|
*/
|
|
253
253
|
destroy() {
|
|
254
254
|
this.reset();
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
/**
|
|
258
|
-
*
|
|
259
|
-
* @returns {number}
|
|
258
|
+
* Gets the desired frames per second.
|
|
259
|
+
* @returns {number} The desired frames per second.
|
|
260
260
|
*/
|
|
261
261
|
get desiredFps() {
|
|
262
262
|
return this._desiredFps;
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
|
-
*
|
|
266
|
+
* Sets the desired frames per second.
|
|
267
267
|
*/
|
|
268
268
|
set desiredFps(value) {
|
|
269
269
|
this._desiredFps = value;
|
package/src/phaser/core/timer.js
CHANGED
|
@@ -3,9 +3,9 @@ import { TimerEvent } from './timer_event.js';
|
|
|
3
3
|
|
|
4
4
|
export class Timer {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {import('./game.js').Game} game -
|
|
8
|
-
* @param {boolean} autoDestroy -
|
|
6
|
+
* Creates a new Timer instance.
|
|
7
|
+
* @param {import('./game.js').Game} game - The game instance.
|
|
8
|
+
* @param {boolean} autoDestroy - Whether to automatically destroy the timer when it completes.
|
|
9
9
|
*/
|
|
10
10
|
constructor(game, autoDestroy = false) {
|
|
11
11
|
this.game = game;
|
|
@@ -50,14 +50,14 @@ export class Timer {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
* @param {number} delay -
|
|
55
|
-
* @param {boolean} loop -
|
|
56
|
-
* @param {number} repeatCount -
|
|
57
|
-
* @param {Function} callback -
|
|
58
|
-
* @param {object} callbackContext -
|
|
59
|
-
* @param {...any} args -
|
|
60
|
-
* @returns {TimerEvent}
|
|
53
|
+
* Creates a new TimerEvent.
|
|
54
|
+
* @param {number} delay - The delay in milliseconds before the event fires.
|
|
55
|
+
* @param {boolean} loop - Whether the event should loop indefinitely.
|
|
56
|
+
* @param {number} repeatCount - The number of times to repeat the event (0 = infinite).
|
|
57
|
+
* @param {Function} callback - The function to call when the event fires.
|
|
58
|
+
* @param {object} callbackContext - The context in which to call the callback.
|
|
59
|
+
* @param {...any} args - Arguments to pass to the callback function.
|
|
60
|
+
* @returns {TimerEvent} The created TimerEvent.
|
|
61
61
|
*/
|
|
62
62
|
create(delay, loop, repeatCount, callback, callbackContext = null, args) {
|
|
63
63
|
const roundedDelay = Math.round(delay);
|
|
@@ -75,45 +75,60 @@ export class Timer {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
79
|
-
* @param {number} delay -
|
|
80
|
-
* @param {Function} callback -
|
|
81
|
-
* @param {object} callbackContext -
|
|
82
|
-
* @param {...any} args -
|
|
83
|
-
* @returns {TimerEvent}
|
|
78
|
+
* Creates a new TimerEvent that runs once.
|
|
79
|
+
* @param {number} delay - The delay in milliseconds before the event fires.
|
|
80
|
+
* @param {Function} callback - The function to call when the event fires.
|
|
81
|
+
* @param {object} callbackContext - The context in which to call the callback.
|
|
82
|
+
* @param {...any} args - Arguments to pass to the callback function.
|
|
83
|
+
* @returns {TimerEvent} The created TimerEvent.
|
|
84
84
|
*/
|
|
85
85
|
add(delay, callback, callbackContext = null, ...args) {
|
|
86
86
|
return this.create(delay, false, 0, callback, callbackContext, args);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
*
|
|
91
|
-
* @
|
|
92
|
-
* @param {number}
|
|
93
|
-
* @param {
|
|
94
|
-
* @
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
* Creates a new async TimerEvent that runs once.
|
|
91
|
+
* @template T
|
|
92
|
+
* @param {number} delay - The delay in milliseconds before the promise resolves.
|
|
93
|
+
* @param {...T} args - Arguments to pass to the resolve function.
|
|
94
|
+
* @returns {Promise<T | T[]>} The created Promise.
|
|
95
|
+
*/
|
|
96
|
+
wait(delay, ...args) {
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
this.create(delay, false, 0, () => {
|
|
99
|
+
resolve(args.length <= 1 ? args[0] : args);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates a new TimerEvent that repeats a specified number of times.
|
|
106
|
+
* @param {number} delay - The delay in milliseconds before the event fires.
|
|
107
|
+
* @param {number} repeatCount - The number of times to repeat the event (0 = infinite).
|
|
108
|
+
* @param {Function} callback - The function to call when the event fires.
|
|
109
|
+
* @param {object} callbackContext - The context in which to call the callback.
|
|
110
|
+
* @param {...any} args - Arguments to pass to the callback function.
|
|
111
|
+
* @returns {TimerEvent} The created TimerEvent.
|
|
97
112
|
*/
|
|
98
113
|
repeat(delay, repeatCount, callback, callbackContext = null, ...args) {
|
|
99
114
|
return this.create(delay, false, repeatCount, callback, callbackContext, args);
|
|
100
115
|
}
|
|
101
116
|
|
|
102
117
|
/**
|
|
103
|
-
*
|
|
104
|
-
* @param {number} delay -
|
|
105
|
-
* @param {Function} callback -
|
|
106
|
-
* @param {object} callbackContext -
|
|
107
|
-
* @param {...any} args -
|
|
108
|
-
* @returns {TimerEvent}
|
|
118
|
+
* Creates a new TimerEvent that loops indefinitely.
|
|
119
|
+
* @param {number} delay - The delay in milliseconds before the event fires.
|
|
120
|
+
* @param {Function} callback - The function to call when the event fires.
|
|
121
|
+
* @param {object} callbackContext - The context in which to call the callback.
|
|
122
|
+
* @param {...any} args - Arguments to pass to the callback function.
|
|
123
|
+
* @returns {TimerEvent} The created TimerEvent.
|
|
109
124
|
*/
|
|
110
125
|
loop(delay, callback, callbackContext = null, ...args) {
|
|
111
126
|
return this.create(delay, true, 0, callback, callbackContext, args);
|
|
112
127
|
}
|
|
113
128
|
|
|
114
129
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param {number} delay -
|
|
130
|
+
* Starts the timer.
|
|
131
|
+
* @param {number} delay - The delay in milliseconds before starting (optional).
|
|
117
132
|
*/
|
|
118
133
|
start(delay = 0) {
|
|
119
134
|
if (this.running) {
|
|
@@ -127,8 +142,8 @@ export class Timer {
|
|
|
127
142
|
}
|
|
128
143
|
|
|
129
144
|
/**
|
|
130
|
-
*
|
|
131
|
-
* @param {boolean} clearEvents -
|
|
145
|
+
* Stops the timer.
|
|
146
|
+
* @param {boolean} clearEvents - Whether to clear all events (default: true).
|
|
132
147
|
*/
|
|
133
148
|
stop(clearEvents = true) {
|
|
134
149
|
this.running = false;
|
|
@@ -138,9 +153,9 @@ export class Timer {
|
|
|
138
153
|
}
|
|
139
154
|
|
|
140
155
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @param {TimerEvent | null | undefined} event -
|
|
143
|
-
* @returns {boolean}
|
|
156
|
+
* Removes a TimerEvent from the timer.
|
|
157
|
+
* @param {TimerEvent | null | undefined} event - The TimerEvent to remove.
|
|
158
|
+
* @returns {boolean} True if the event was removed, false otherwise.
|
|
144
159
|
*/
|
|
145
160
|
remove(event) {
|
|
146
161
|
for (let i = 0; i < this.events.length; i += 1) {
|
|
@@ -153,7 +168,7 @@ export class Timer {
|
|
|
153
168
|
}
|
|
154
169
|
|
|
155
170
|
/**
|
|
156
|
-
*
|
|
171
|
+
* Orders the timer events by their next tick time.
|
|
157
172
|
*/
|
|
158
173
|
order() {
|
|
159
174
|
if (this.events.length > 0) {
|
|
@@ -164,10 +179,10 @@ export class Timer {
|
|
|
164
179
|
}
|
|
165
180
|
|
|
166
181
|
/**
|
|
167
|
-
*
|
|
168
|
-
* @param {TimerEvent} a -
|
|
169
|
-
* @param {TimerEvent} b -
|
|
170
|
-
* @returns {number}
|
|
182
|
+
* Sorts TimerEvents by their tick time.
|
|
183
|
+
* @param {TimerEvent} a - First TimerEvent to compare.
|
|
184
|
+
* @param {TimerEvent} b - Second TimerEvent to compare.
|
|
185
|
+
* @returns {number} Comparison result (-1, 0, or 1).
|
|
171
186
|
*/
|
|
172
187
|
sortHandler(a, b) {
|
|
173
188
|
if (a.tick < b.tick) {
|
|
@@ -179,7 +194,7 @@ export class Timer {
|
|
|
179
194
|
}
|
|
180
195
|
|
|
181
196
|
/**
|
|
182
|
-
*
|
|
197
|
+
* Clears pending events from the timer.
|
|
183
198
|
*/
|
|
184
199
|
clearPendingEvents() {
|
|
185
200
|
this._i = this.events.length;
|
|
@@ -194,9 +209,9 @@ export class Timer {
|
|
|
194
209
|
}
|
|
195
210
|
|
|
196
211
|
/**
|
|
197
|
-
*
|
|
198
|
-
* @param {number} time -
|
|
199
|
-
* @returns {boolean}
|
|
212
|
+
* Updates the timer state at a given time.
|
|
213
|
+
* @param {number} time - The current time in milliseconds.
|
|
214
|
+
* @returns {boolean} True if the timer should continue running, false if it should be destroyed.
|
|
200
215
|
*/
|
|
201
216
|
update(time) {
|
|
202
217
|
if (this.paused) {
|
|
@@ -254,7 +269,7 @@ export class Timer {
|
|
|
254
269
|
}
|
|
255
270
|
|
|
256
271
|
/**
|
|
257
|
-
*
|
|
272
|
+
* Pauses the timer.
|
|
258
273
|
*/
|
|
259
274
|
pause() {
|
|
260
275
|
if (!this.running) {
|
|
@@ -269,7 +284,7 @@ export class Timer {
|
|
|
269
284
|
}
|
|
270
285
|
|
|
271
286
|
/**
|
|
272
|
-
*
|
|
287
|
+
* Internal pause method for the timer.
|
|
273
288
|
*/
|
|
274
289
|
_pause() {
|
|
275
290
|
if (this.paused || !this.running) {
|
|
@@ -280,8 +295,8 @@ export class Timer {
|
|
|
280
295
|
}
|
|
281
296
|
|
|
282
297
|
/**
|
|
283
|
-
*
|
|
284
|
-
* @param {number} baseTime -
|
|
298
|
+
* Adjusts timer events when time has jumped (e.g., when tab is switched).
|
|
299
|
+
* @param {number} baseTime - The time to adjust from.
|
|
285
300
|
*/
|
|
286
301
|
adjustEvents(baseTime) {
|
|
287
302
|
for (let i = 0; i < this.events.length; i += 1) {
|
|
@@ -304,7 +319,7 @@ export class Timer {
|
|
|
304
319
|
}
|
|
305
320
|
|
|
306
321
|
/**
|
|
307
|
-
*
|
|
322
|
+
* Resumes the timer.
|
|
308
323
|
*/
|
|
309
324
|
resume() {
|
|
310
325
|
if (!this.paused) {
|
|
@@ -319,7 +334,7 @@ export class Timer {
|
|
|
319
334
|
}
|
|
320
335
|
|
|
321
336
|
/**
|
|
322
|
-
*
|
|
337
|
+
* Internal resume method for the timer.
|
|
323
338
|
*/
|
|
324
339
|
_resume() {
|
|
325
340
|
if (this._codePaused) {
|
|
@@ -329,7 +344,7 @@ export class Timer {
|
|
|
329
344
|
}
|
|
330
345
|
|
|
331
346
|
/**
|
|
332
|
-
*
|
|
347
|
+
* Removes all events from the timer.
|
|
333
348
|
*/
|
|
334
349
|
removeAll() {
|
|
335
350
|
this.onComplete.removeAll();
|
|
@@ -339,7 +354,7 @@ export class Timer {
|
|
|
339
354
|
}
|
|
340
355
|
|
|
341
356
|
/**
|
|
342
|
-
*
|
|
357
|
+
* Destroys the timer and cleans up resources.
|
|
343
358
|
*/
|
|
344
359
|
destroy() {
|
|
345
360
|
this.onComplete.removeAll();
|
|
@@ -350,16 +365,16 @@ export class Timer {
|
|
|
350
365
|
}
|
|
351
366
|
|
|
352
367
|
/**
|
|
353
|
-
*
|
|
354
|
-
* @returns {number}
|
|
368
|
+
* Gets the next tick time for the timer.
|
|
369
|
+
* @returns {number} The next tick time in milliseconds.
|
|
355
370
|
*/
|
|
356
371
|
get next() {
|
|
357
372
|
return this.nextTick;
|
|
358
373
|
}
|
|
359
374
|
|
|
360
375
|
/**
|
|
361
|
-
*
|
|
362
|
-
* @returns {number}
|
|
376
|
+
* Gets the duration until the next event.
|
|
377
|
+
* @returns {number} The duration in milliseconds.
|
|
363
378
|
*/
|
|
364
379
|
get duration() {
|
|
365
380
|
if (this.running && this.nextTick > this._now) {
|
|
@@ -369,16 +384,16 @@ export class Timer {
|
|
|
369
384
|
}
|
|
370
385
|
|
|
371
386
|
/**
|
|
372
|
-
*
|
|
373
|
-
* @returns {number}
|
|
387
|
+
* Gets the number of active events in the timer.
|
|
388
|
+
* @returns {number} The number of events.
|
|
374
389
|
*/
|
|
375
390
|
get length() {
|
|
376
391
|
return this.events.length;
|
|
377
392
|
}
|
|
378
393
|
|
|
379
394
|
/**
|
|
380
|
-
*
|
|
381
|
-
* @returns {number}
|
|
395
|
+
* Gets the elapsed time since the timer started.
|
|
396
|
+
* @returns {number} The elapsed time in milliseconds.
|
|
382
397
|
*/
|
|
383
398
|
get ms() {
|
|
384
399
|
if (this.running) {
|
|
@@ -388,8 +403,8 @@ export class Timer {
|
|
|
388
403
|
}
|
|
389
404
|
|
|
390
405
|
/**
|
|
391
|
-
*
|
|
392
|
-
* @returns {number}
|
|
406
|
+
* Gets the elapsed time in seconds since the timer started.
|
|
407
|
+
* @returns {number} The elapsed time in seconds.
|
|
393
408
|
*/
|
|
394
409
|
get seconds() {
|
|
395
410
|
if (this.running) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export class TimerEvent {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param {import('./timer.js').Timer} timer -
|
|
5
|
-
* @param {number} delay -
|
|
6
|
-
* @param {number} tick -
|
|
7
|
-
* @param {number} repeatCount -
|
|
8
|
-
* @param {boolean} loop -
|
|
9
|
-
* @param {Function} callback -
|
|
10
|
-
* @param {object} callbackContext -
|
|
11
|
-
* @param {...any} args -
|
|
3
|
+
* Creates a new TimerEvent instance.
|
|
4
|
+
* @param {import('./timer.js').Timer} timer - Reference to the parent Timer.
|
|
5
|
+
* @param {number} delay - The delay (in milliseconds) before the event should occur.
|
|
6
|
+
* @param {number} tick - The tick (in milliseconds) at which the event should occur.
|
|
7
|
+
* @param {number} repeatCount - The number of times the event should repeat.
|
|
8
|
+
* @param {boolean} loop - Whether the event should loop.
|
|
9
|
+
* @param {Function} callback - The function to call when the event occurs.
|
|
10
|
+
* @param {object} callbackContext - The context in which to call the callback function.
|
|
11
|
+
* @param {...any} args - Arguments to pass to the callback function.
|
|
12
12
|
*/
|
|
13
13
|
constructor(timer, delay, tick, repeatCount, loop, callback, callbackContext, args) {
|
|
14
14
|
this.timer = timer;
|