@vpmedia/phaser 1.112.0 → 1.113.0

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