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