@vpmedia/phaser 1.115.0 → 1.117.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 (193) hide show
  1. package/dist/index.js +56 -96
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts.map +1 -1
  4. package/dist/phaser/core/animation_manager.d.ts +15 -14
  5. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  6. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  7. package/dist/phaser/core/array_set.d.ts.map +1 -1
  8. package/dist/phaser/core/cache.d.ts +10 -9
  9. package/dist/phaser/core/cache.d.ts.map +1 -1
  10. package/dist/phaser/core/device_util.d.ts.map +1 -1
  11. package/dist/phaser/core/dom.d.ts.map +1 -1
  12. package/dist/phaser/core/factory.d.ts.map +1 -1
  13. package/dist/phaser/core/game.d.ts.map +1 -1
  14. package/dist/phaser/core/input.d.ts +20 -20
  15. package/dist/phaser/core/input.d.ts.map +1 -1
  16. package/dist/phaser/core/input_handler.d.ts +11 -13
  17. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  18. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  19. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  20. package/dist/phaser/core/input_pointer.d.ts +19 -8
  21. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  22. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  23. package/dist/phaser/core/loader.d.ts.map +1 -1
  24. package/dist/phaser/core/raf.d.ts.map +1 -1
  25. package/dist/phaser/core/scale_manager.d.ts +38 -13
  26. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  27. package/dist/phaser/core/scene.d.ts.map +1 -1
  28. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  29. package/dist/phaser/core/signal.d.ts.map +1 -1
  30. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  31. package/dist/phaser/core/sound.d.ts +2 -2
  32. package/dist/phaser/core/sound.d.ts.map +1 -1
  33. package/dist/phaser/core/sound_manager.d.ts +24 -22
  34. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  35. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  36. package/dist/phaser/core/stage.d.ts.map +1 -1
  37. package/dist/phaser/core/time.d.ts.map +1 -1
  38. package/dist/phaser/core/timer.d.ts +1 -1
  39. package/dist/phaser/core/timer.d.ts.map +1 -1
  40. package/dist/phaser/core/tween.d.ts.map +1 -1
  41. package/dist/phaser/core/tween_data.d.ts +26 -26
  42. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  43. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  44. package/dist/phaser/core/world.d.ts.map +1 -1
  45. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  46. package/dist/phaser/display/button.d.ts.map +1 -1
  47. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  48. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  49. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  50. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  51. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  52. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  53. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  54. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  55. package/dist/phaser/display/display_object.d.ts.map +1 -1
  56. package/dist/phaser/display/graphics.d.ts.map +1 -1
  57. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  58. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  59. package/dist/phaser/display/group.d.ts.map +1 -1
  60. package/dist/phaser/display/image.d.ts +2 -2
  61. package/dist/phaser/display/image.d.ts.map +1 -1
  62. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  63. package/dist/phaser/display/text.d.ts.map +1 -1
  64. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  65. package/dist/phaser/display/webgl/base_texture.d.ts +12 -10
  66. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  67. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  68. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  69. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +13 -12
  70. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  71. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  72. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  73. package/dist/phaser/display/webgl/graphics.d.ts +9 -7
  74. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  76. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  77. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  78. package/dist/phaser/display/webgl/renderer.d.ts +12 -10
  79. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  80. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  81. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  82. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  84. package/dist/phaser/display/webgl/texture.d.ts +18 -33
  85. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  86. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  88. package/dist/phaser/geom/circle.d.ts.map +1 -1
  89. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  90. package/dist/phaser/geom/line.d.ts.map +1 -1
  91. package/dist/phaser/geom/matrix.d.ts +1 -1
  92. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  93. package/dist/phaser/geom/point.d.ts.map +1 -1
  94. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  95. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  96. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  97. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  98. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  99. package/dist/phaser/geom/util/line.d.ts +5 -4
  100. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  101. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  102. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  103. package/dist/phaser/geom/util/polygon.d.ts.map +1 -1
  104. package/dist/phaser/geom/util/rectangle.d.ts +10 -1
  105. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  106. package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
  107. package/package.json +1 -1
  108. package/src/phaser/core/animation.ts +20 -20
  109. package/src/phaser/core/animation_manager.ts +27 -24
  110. package/src/phaser/core/animation_parser.ts +2 -2
  111. package/src/phaser/core/array_set.ts +7 -7
  112. package/src/phaser/core/cache.ts +55 -51
  113. package/src/phaser/core/callback_context.test.ts +70 -0
  114. package/src/phaser/core/device_util.ts +13 -13
  115. package/src/phaser/core/dom.ts +26 -22
  116. package/src/phaser/core/factory.ts +6 -6
  117. package/src/phaser/core/game.ts +10 -10
  118. package/src/phaser/core/input.ts +37 -39
  119. package/src/phaser/core/input_handler.ts +90 -93
  120. package/src/phaser/core/input_mouse.ts +19 -19
  121. package/src/phaser/core/input_mspointer.ts +15 -15
  122. package/src/phaser/core/input_pointer.ts +37 -28
  123. package/src/phaser/core/input_touch.ts +17 -17
  124. package/src/phaser/core/loader.ts +52 -52
  125. package/src/phaser/core/loader_parser.ts +3 -3
  126. package/src/phaser/core/raf.ts +3 -3
  127. package/src/phaser/core/scale_manager.ts +86 -67
  128. package/src/phaser/core/scene.ts +7 -7
  129. package/src/phaser/core/scene_manager.ts +16 -16
  130. package/src/phaser/core/signal.ts +29 -19
  131. package/src/phaser/core/signal_binding.ts +4 -4
  132. package/src/phaser/core/sound.ts +17 -17
  133. package/src/phaser/core/sound_manager.ts +71 -72
  134. package/src/phaser/core/sound_sprite.ts +1 -1
  135. package/src/phaser/core/stage.ts +7 -7
  136. package/src/phaser/core/time.ts +16 -16
  137. package/src/phaser/core/timer.ts +36 -26
  138. package/src/phaser/core/tween.ts +23 -23
  139. package/src/phaser/core/tween_data.ts +41 -37
  140. package/src/phaser/core/tween_manager.ts +11 -11
  141. package/src/phaser/core/world.ts +1 -1
  142. package/src/phaser/display/bitmap_text.ts +13 -13
  143. package/src/phaser/display/button.ts +13 -13
  144. package/src/phaser/display/canvas/buffer.ts +3 -3
  145. package/src/phaser/display/canvas/graphics.ts +3 -3
  146. package/src/phaser/display/canvas/masker.ts +2 -2
  147. package/src/phaser/display/canvas/pool.ts +6 -6
  148. package/src/phaser/display/canvas/renderer.ts +6 -6
  149. package/src/phaser/display/canvas/tinter.ts +39 -8
  150. package/src/phaser/display/canvas/util.ts +15 -9
  151. package/src/phaser/display/display_object.ts +38 -38
  152. package/src/phaser/display/graphics.ts +30 -30
  153. package/src/phaser/display/graphics_data.ts +1 -1
  154. package/src/phaser/display/graphics_data_util.ts +1 -1
  155. package/src/phaser/display/group.ts +16 -16
  156. package/src/phaser/display/image.ts +30 -26
  157. package/src/phaser/display/sprite_util.ts +12 -4
  158. package/src/phaser/display/text.ts +55 -55
  159. package/src/phaser/display/webgl/abstract_filter.ts +1 -1
  160. package/src/phaser/display/webgl/base_texture.ts +22 -18
  161. package/src/phaser/display/webgl/blend_manager.ts +3 -3
  162. package/src/phaser/display/webgl/earcut.ts +3 -3
  163. package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
  164. package/src/phaser/display/webgl/filter_manager.ts +7 -7
  165. package/src/phaser/display/webgl/filter_texture.ts +3 -3
  166. package/src/phaser/display/webgl/graphics.ts +43 -41
  167. package/src/phaser/display/webgl/graphics_data.ts +2 -2
  168. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  169. package/src/phaser/display/webgl/render_texture.ts +6 -6
  170. package/src/phaser/display/webgl/renderer.ts +20 -25
  171. package/src/phaser/display/webgl/shader/normal.ts +3 -3
  172. package/src/phaser/display/webgl/shader_manager.ts +2 -2
  173. package/src/phaser/display/webgl/sprite_batch.ts +9 -9
  174. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  175. package/src/phaser/display/webgl/texture.ts +23 -42
  176. package/src/phaser/display/webgl/texture_util.ts +2 -2
  177. package/src/phaser/display/webgl/util.ts +11 -7
  178. package/src/phaser/geom/circle.ts +21 -21
  179. package/src/phaser/geom/ellipse.ts +7 -7
  180. package/src/phaser/geom/line.ts +29 -29
  181. package/src/phaser/geom/matrix.ts +13 -13
  182. package/src/phaser/geom/point.ts +36 -30
  183. package/src/phaser/geom/polygon.ts +6 -6
  184. package/src/phaser/geom/rectangle.ts +42 -42
  185. package/src/phaser/geom/rounded_rectangle.ts +2 -2
  186. package/src/phaser/geom/util/circle.ts +7 -7
  187. package/src/phaser/geom/util/ellipse.ts +1 -1
  188. package/src/phaser/geom/util/line.ts +13 -5
  189. package/src/phaser/geom/util/matrix.ts +3 -3
  190. package/src/phaser/geom/util/point.ts +20 -20
  191. package/src/phaser/geom/util/polygon.ts +1 -1
  192. package/src/phaser/geom/util/rectangle.ts +34 -17
  193. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
@@ -27,7 +27,7 @@ export class ArraySet {
27
27
  * @param {object} item - TBD.
28
28
  * @returns {number} TBD.
29
29
  */
30
- public getIndex(item: any) {
30
+ public getIndex(item: any): number {
31
31
  return this.list.indexOf(item);
32
32
  }
33
33
 
@@ -53,14 +53,14 @@ export class ArraySet {
53
53
  * @param {object} item - TBD.
54
54
  * @returns {boolean} TBD.
55
55
  */
56
- public exists(item: any) {
56
+ public exists(item: any): boolean {
57
57
  return this.list.includes(item);
58
58
  }
59
59
 
60
60
  /**
61
61
  * TBD.
62
62
  */
63
- public reset() {
63
+ public reset(): void {
64
64
  this.list.length = 0;
65
65
  }
66
66
 
@@ -83,7 +83,7 @@ export class ArraySet {
83
83
  * @param {string} key - TBD.
84
84
  * @param {object} value - TBD.
85
85
  */
86
- public setAll(key: string, value: any) {
86
+ public setAll(key: string, value: any): void {
87
87
  let i = this.list.length;
88
88
  while (i) {
89
89
  i -= 1;
@@ -98,7 +98,7 @@ export class ArraySet {
98
98
  * @param {string} key - TBD.
99
99
  * @param {...any} args - TBD.
100
100
  */
101
- public callAll(key: string, ...args: unknown[]) {
101
+ public callAll(key: string, ...args: unknown[]): void {
102
102
  let i = this.list.length;
103
103
  while (i) {
104
104
  i -= 1;
@@ -112,7 +112,7 @@ export class ArraySet {
112
112
  * TBD.
113
113
  * @param {boolean} destroy - TBD.
114
114
  */
115
- public removeAll(destroy = false) {
115
+ public removeAll(destroy = false): void {
116
116
  let i = this.list.length;
117
117
  while (i) {
118
118
  i -= 1;
@@ -131,7 +131,7 @@ export class ArraySet {
131
131
  * TBD.
132
132
  * @returns {number} TBD.
133
133
  */
134
- public get total() {
134
+ public get total(): number {
135
135
  return this.list.length;
136
136
  }
137
137
 
@@ -33,12 +33,12 @@ interface CacheBuckets {
33
33
 
34
34
  export class Cache {
35
35
  public game!: Game;
36
- public autoResolveURL!: any;
36
+ public autoResolveURL!: boolean;
37
37
  public _cache!: CacheBuckets;
38
- public _urlMap!: any;
39
- public _urlResolver!: any;
40
- public _urlTemp!: any;
41
- public onSoundUnlock!: any;
38
+ public _urlMap!: Record<string, unknown> | null;
39
+ public _urlResolver!: HTMLImageElement | null;
40
+ public _urlTemp!: string | null;
41
+ public onSoundUnlock!: Signal;
42
42
  public _cacheMap!: Record<string, any>[];
43
43
  /**
44
44
  * Creates a new Cache instance.
@@ -81,7 +81,7 @@ export class Cache {
81
81
  /**
82
82
  * Adds the default image to the cache.
83
83
  */
84
- public addDefaultImage() {
84
+ public addDefaultImage(): void {
85
85
  const img = new Image();
86
86
  img.src =
87
87
  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==';
@@ -93,7 +93,7 @@ export class Cache {
93
93
  /**
94
94
  * Adds the missing image to the cache.
95
95
  */
96
- public addMissingImage() {
96
+ public addMissingImage(): void {
97
97
  const img = new Image();
98
98
  img.src =
99
99
  'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==';
@@ -150,7 +150,7 @@ export class Cache {
150
150
  frameMax = -1,
151
151
  margin = 0,
152
152
  spacing = 0
153
- ) {
153
+ ): void {
154
154
  const obj = {
155
155
  key,
156
156
  url,
@@ -169,7 +169,7 @@ export class Cache {
169
169
  * @param {HTMLCanvasElement} data - The canvas data for the atlas.
170
170
  * @param {object} atlasData - The atlas data to cache.
171
171
  */
172
- public addTextureAtlas(key: string, url: string, data: HTMLCanvasElement, atlasData: any) {
172
+ public addTextureAtlas(key: string, url: string, data: HTMLCanvasElement, atlasData: any): void {
173
173
  const obj: any = {
174
174
  key,
175
175
  url,
@@ -187,7 +187,7 @@ export class Cache {
187
187
  * @param {string} url - The URL the sound was loaded from.
188
188
  * @param {object} data - The sound data to cache.
189
189
  */
190
- public addSound(key: string, url: string, data: any) {
190
+ public addSound(key: string, url: string, data: any): void {
191
191
  this._cache.sound[key] = {
192
192
  url,
193
193
  data,
@@ -203,7 +203,7 @@ export class Cache {
203
203
  * @param {string} url - The URL the text was loaded from.
204
204
  * @param {string} data - The text data to cache.
205
205
  */
206
- public addText(key: string, url: string, data: string) {
206
+ public addText(key: string, url: string, data: string): void {
207
207
  this._cache.text[key] = { url, data };
208
208
  this._resolveURL(url, this._cache.text[key]);
209
209
  }
@@ -226,7 +226,7 @@ export class Cache {
226
226
  atlasType: string,
227
227
  xSpacing = 0,
228
228
  ySpacing = 0
229
- ) {
229
+ ): void {
230
230
  const obj: { url: string; data: unknown; font: object | null; base: BaseTexture } = {
231
231
  url,
232
232
  data,
@@ -248,7 +248,7 @@ export class Cache {
248
248
  * @param {string} url - The URL the JSON was loaded from.
249
249
  * @param {object} data - The JSON data to cache.
250
250
  */
251
- public addJSON(key: string, url: string, data: any) {
251
+ public addJSON(key: string, url: string, data: any): void {
252
252
  this._cache.json[key] = { url, data };
253
253
  this._resolveURL(url, this._cache.json[key]);
254
254
  }
@@ -259,7 +259,7 @@ export class Cache {
259
259
  * @param {string} url - The URL the XML was loaded from.
260
260
  * @param {XMLDocument} data - The XML data to cache.
261
261
  */
262
- public addXML(key: string, url: string, data: XMLDocument) {
262
+ public addXML(key: string, url: string, data: XMLDocument): void {
263
263
  this._cache.xml[key] = { url, data };
264
264
  this._resolveURL(url, this._cache.xml[key]);
265
265
  }
@@ -272,7 +272,7 @@ export class Cache {
272
272
  * @param {string} property - The property to update.
273
273
  * @param {any} value - The new value for the property.
274
274
  */
275
- public updateSound(key: string, property: string, value: any) {
275
+ public updateSound(key: string, property: string, value: any): void {
276
276
  const sound = this.getSound(key);
277
277
  if (sound) {
278
278
  sound[property] = value;
@@ -284,7 +284,7 @@ export class Cache {
284
284
  * @param {string} key - The unique key for the cached sound.
285
285
  * @param {AudioBuffer} data - The decoded audio buffer.
286
286
  */
287
- public decodedSound(key: string, data: AudioBuffer) {
287
+ public decodedSound(key: string, data: AudioBuffer): void {
288
288
  const sound = this.getSound(key);
289
289
  sound.data = data;
290
290
  sound.decoded = true;
@@ -325,7 +325,7 @@ export class Cache {
325
325
  * @param {string} key - The unique key for the cache entry.
326
326
  * @returns {boolean} True if the entry exists, false otherwise.
327
327
  */
328
- public checkKey(cache: number, key: string) {
328
+ public checkKey(cache: number, key: string): boolean {
329
329
  if (this._cacheMap[cache]?.[key]) {
330
330
  return true;
331
331
  }
@@ -337,8 +337,9 @@ export class Cache {
337
337
  * @param {string} url - The URL to check.
338
338
  * @returns {boolean} True if the URL has been resolved and cached, false otherwise.
339
339
  */
340
- public checkURL(url: string) {
341
- if (this._urlMap[this._resolveURL(url)]) {
340
+ public checkURL(url: string): boolean {
341
+ const resolved = this._resolveURL(url);
342
+ if (resolved && this._urlMap?.[resolved]) {
342
343
  return true;
343
344
  }
344
345
  return false;
@@ -349,7 +350,7 @@ export class Cache {
349
350
  * @param {string} key - The unique key for the cache entry.
350
351
  * @returns {boolean} True if the entry exists, false otherwise.
351
352
  */
352
- public checkCanvasKey(key: string) {
353
+ public checkCanvasKey(key: string): boolean {
353
354
  return this.checkKey(CANVAS, key);
354
355
  }
355
356
 
@@ -358,7 +359,7 @@ export class Cache {
358
359
  * @param {string} key - The unique key for the cache entry.
359
360
  * @returns {boolean} True if the entry exists, false otherwise.
360
361
  */
361
- public checkImageKey(key: string) {
362
+ public checkImageKey(key: string): boolean {
362
363
  return this.checkKey(IMAGE, key);
363
364
  }
364
365
 
@@ -367,7 +368,7 @@ export class Cache {
367
368
  * @param {string} key - The unique key for the cache entry.
368
369
  * @returns {boolean} True if the entry exists, false otherwise.
369
370
  */
370
- public checkTextureKey(key: string) {
371
+ public checkTextureKey(key: string): boolean {
371
372
  return this.checkKey(TEXTURE, key);
372
373
  }
373
374
 
@@ -376,7 +377,7 @@ export class Cache {
376
377
  * @param {string} key - The unique key for the cache entry.
377
378
  * @returns {boolean} True if the entry exists, false otherwise.
378
379
  */
379
- public checkSoundKey(key: string) {
380
+ public checkSoundKey(key: string): boolean {
380
381
  return this.checkKey(SOUND, key);
381
382
  }
382
383
 
@@ -385,7 +386,7 @@ export class Cache {
385
386
  * @param {string} key - The unique key for the cache entry.
386
387
  * @returns {boolean} True if the entry exists, false otherwise.
387
388
  */
388
- public checkTextKey(key: string) {
389
+ public checkTextKey(key: string): boolean {
389
390
  return this.checkKey(TEXT, key);
390
391
  }
391
392
 
@@ -394,7 +395,7 @@ export class Cache {
394
395
  * @param {string} key - The unique key for the cache entry.
395
396
  * @returns {boolean} True if the entry exists, false otherwise.
396
397
  */
397
- public checkBitmapDataKey(key: string) {
398
+ public checkBitmapDataKey(key: string): boolean {
398
399
  return this.checkKey(BITMAPDATA, key);
399
400
  }
400
401
 
@@ -403,7 +404,7 @@ export class Cache {
403
404
  * @param {string} key - The unique key for the cache entry.
404
405
  * @returns {boolean} True if the entry exists, false otherwise.
405
406
  */
406
- public checkBitmapFontKey(key: string) {
407
+ public checkBitmapFontKey(key: string): boolean {
407
408
  return this.checkKey(BITMAPFONT, key);
408
409
  }
409
410
 
@@ -412,7 +413,7 @@ export class Cache {
412
413
  * @param {string} key - The unique key for the cache entry.
413
414
  * @returns {boolean} True if the entry exists, false otherwise.
414
415
  */
415
- public checkJSONKey(key: string) {
416
+ public checkJSONKey(key: string): boolean {
416
417
  return this.checkKey(JSONDATA, key);
417
418
  }
418
419
 
@@ -421,7 +422,7 @@ export class Cache {
421
422
  * @param {string} key - The unique key for the cache entry.
422
423
  * @returns {boolean} True if the entry exists, false otherwise.
423
424
  */
424
- public checkXMLKey(key: string) {
425
+ public checkXMLKey(key: string): boolean {
425
426
  return this.checkKey(XML, key);
426
427
  }
427
428
 
@@ -461,8 +462,8 @@ export class Cache {
461
462
  * @param {boolean} full - TBD.
462
463
  * @returns {HTMLImageElement} TBD.
463
464
  */
464
- public getImage(key: any = '__default', full = false) {
465
- let img = this.getItem(key, IMAGE, 'getImage');
465
+ public getImage(key: string | number = '__default', full = false) {
466
+ let img = this.getItem(String(key), IMAGE, 'getImage');
466
467
  if (img === null) {
467
468
  img = this.getItem('__missing', IMAGE, 'getImage');
468
469
  }
@@ -584,7 +585,7 @@ export class Cache {
584
585
  * @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
585
586
  * @returns {number} The number of frames.
586
587
  */
587
- public getFrameCount(key: string, cache: number = IMAGE) {
588
+ public getFrameCount(key: string, cache: number = IMAGE): number {
588
589
  const data = this.getFrameData(key, cache);
589
590
  if (data) {
590
591
  return data.total;
@@ -608,7 +609,7 @@ export class Cache {
608
609
  * @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
609
610
  * @returns {boolean} True if the entry has frame data, false otherwise.
610
611
  */
611
- public hasFrameData(key: string, cache: number = IMAGE) {
612
+ public hasFrameData(key: string, cache: number = IMAGE): boolean {
612
613
  return this.getItem(key, cache, '', 'frameData') !== null;
613
614
  }
614
615
 
@@ -618,7 +619,7 @@ export class Cache {
618
619
  * @param {FrameData} frameData - The new frame data.
619
620
  * @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
620
621
  */
621
- public updateFrameData(key: string, frameData: FrameData, cache: number = IMAGE) {
622
+ public updateFrameData(key: string, frameData: FrameData, cache: number = IMAGE): void {
622
623
  const entry = this._cacheMap[cache]?.[key];
623
624
  if (entry) {
624
625
  entry.frameData = frameData;
@@ -632,7 +633,7 @@ export class Cache {
632
633
  * @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
633
634
  * @returns {Frame} The frame at the specified index.
634
635
  */
635
- public getFrameByIndex(key: string, index: number, cache: number = IMAGE) {
636
+ public getFrameByIndex(key: string, index: number, cache: number = IMAGE): Frame | null {
636
637
  const data = this.getFrameData(key, cache);
637
638
  if (data) {
638
639
  return data.getFrame(index);
@@ -647,7 +648,7 @@ export class Cache {
647
648
  * @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
648
649
  * @returns {Frame} The frame with the specified name.
649
650
  */
650
- public getFrameByName(key: string, name: string, cache: number = IMAGE) {
651
+ public getFrameByName(key: string, name: string, cache: number = IMAGE): Frame | null {
651
652
  const data = this.getFrameData(key, cache);
652
653
  if (data) {
653
654
  return data.getFrameByName(name);
@@ -663,7 +664,7 @@ export class Cache {
663
664
  public getURL(url: string) {
664
665
  const resolvedURL = this._resolveURL(url);
665
666
  if (resolvedURL) {
666
- return this._urlMap[resolvedURL];
667
+ return this._urlMap?.[resolvedURL] ?? null;
667
668
  }
668
669
  this.game.logger.warn('Cache invalid url', { resolvedURL });
669
670
  return null;
@@ -674,7 +675,7 @@ export class Cache {
674
675
  * @param {object} cache - The cache type (CANVAS, IMAGE, etc.).
675
676
  * @returns {string[]} An array of cache keys.
676
677
  */
677
- public getKeys(cache: any = IMAGE) {
678
+ public getKeys(cache: number = IMAGE): string[] {
678
679
  const result = [];
679
680
  if (this._cacheMap[cache]) {
680
681
  const keys = Object.keys(this._cacheMap[cache]);
@@ -693,7 +694,7 @@ export class Cache {
693
694
  * Removes a canvas cache entry.
694
695
  * @param {string} key - The unique key for the cache entry to remove.
695
696
  */
696
- public removeCanvas(key: string) {
697
+ public removeCanvas(key: string): void {
697
698
  delete this._cache.canvas[key];
698
699
  }
699
700
 
@@ -702,7 +703,7 @@ export class Cache {
702
703
  * @param {string} key - The unique key for the cache entry to remove.
703
704
  * @param {boolean} destroyBaseTexture - Whether to destroy the base texture (default: true).
704
705
  */
705
- public removeImage(key: string, destroyBaseTexture = true) {
706
+ public removeImage(key: string, destroyBaseTexture = true): void {
706
707
  const img = this.getImage(key, true);
707
708
  if (destroyBaseTexture && img.base) {
708
709
  img.base.destroy();
@@ -714,7 +715,7 @@ export class Cache {
714
715
  * Removes a sound cache entry.
715
716
  * @param {string} key - The unique key for the cache entry to remove.
716
717
  */
717
- public removeSound(key: string) {
718
+ public removeSound(key: string): void {
718
719
  delete this._cache.sound[key];
719
720
  }
720
721
 
@@ -722,7 +723,7 @@ export class Cache {
722
723
  * Removes a text cache entry.
723
724
  * @param {string} key - The unique key for the cache entry to remove.
724
725
  */
725
- public removeText(key: string) {
726
+ public removeText(key: string): void {
726
727
  delete this._cache.text[key];
727
728
  }
728
729
 
@@ -730,7 +731,7 @@ export class Cache {
730
731
  * Removes a bitmap data cache entry.
731
732
  * @param {string} key - The unique key for the cache entry to remove.
732
733
  */
733
- public removeBitmapData(key: string) {
734
+ public removeBitmapData(key: string): void {
734
735
  delete this._cache.bitmapData[key];
735
736
  }
736
737
 
@@ -738,7 +739,7 @@ export class Cache {
738
739
  * Removes a bitmap font cache entry.
739
740
  * @param {string} key - The unique key for the cache entry to remove.
740
741
  */
741
- public removeBitmapFont(key: string) {
742
+ public removeBitmapFont(key: string): void {
742
743
  delete this._cache.bitmapFont[key];
743
744
  }
744
745
 
@@ -746,7 +747,7 @@ export class Cache {
746
747
  * Removes a JSON cache entry.
747
748
  * @param {string} key - The unique key for the cache entry to remove.
748
749
  */
749
- public removeJSON(key: string) {
750
+ public removeJSON(key: string): void {
750
751
  delete this._cache.json[key];
751
752
  }
752
753
 
@@ -754,7 +755,7 @@ export class Cache {
754
755
  * Removes an XML cache entry.
755
756
  * @param {string} key - The unique key for the cache entry to remove.
756
757
  */
757
- public removeXML(key: string) {
758
+ public removeXML(key: string): void {
758
759
  delete this._cache.xml[key];
759
760
  }
760
761
 
@@ -762,7 +763,7 @@ export class Cache {
762
763
  * Removes a render texture cache entry.
763
764
  * @param {string} key - The unique key for the cache entry to remove.
764
765
  */
765
- public removeRenderTexture(key: string) {
766
+ public removeRenderTexture(key: string): void {
766
767
  delete this._cache.renderTexture[key];
767
768
  }
768
769
 
@@ -770,7 +771,7 @@ export class Cache {
770
771
  * Removes a sprite sheet cache entry.
771
772
  * @param {string} key - The unique key for the cache entry to remove.
772
773
  */
773
- public removeSpriteSheet(key: string) {
774
+ public removeSpriteSheet(key: string): void {
774
775
  delete this._cache.image[key];
775
776
  }
776
777
 
@@ -778,14 +779,14 @@ export class Cache {
778
779
  * Removes a texture atlas cache entry.
779
780
  * @param {string} key - The unique key for the cache entry to remove.
780
781
  */
781
- public removeTextureAtlas(key: string) {
782
+ public removeTextureAtlas(key: string): void {
782
783
  delete this._cache.image[key];
783
784
  }
784
785
 
785
786
  /**
786
787
  * Clears all GL textures from the cache.
787
788
  */
788
- public clearGLTextures() {
789
+ public clearGLTextures(): void {
789
790
  const keys = Object.keys(this._cache.image);
790
791
  for (const key of keys) {
791
792
  this._cache.image[key].base._glTextures = [];
@@ -802,12 +803,15 @@ export class Cache {
802
803
  if (!this.autoResolveURL) {
803
804
  return null;
804
805
  }
806
+ if (!this._urlResolver) {
807
+ return null;
808
+ }
805
809
  this._urlResolver.src = this.game.load.baseURL + url;
806
810
  this._urlTemp = this._urlResolver.src;
807
811
  // Ensure no request is actually made
808
812
  this._urlResolver.src = '';
809
813
  // Record the URL to the map
810
- if (data) {
814
+ if (data && this._urlMap) {
811
815
  this._urlMap[this._urlTemp] = data;
812
816
  }
813
817
  return this._urlTemp;
@@ -816,7 +820,7 @@ export class Cache {
816
820
  /**
817
821
  * Destroys the cache and cleans up resources.
818
822
  */
819
- public destroy() {
823
+ public destroy(): void {
820
824
  for (const cache of this._cacheMap) {
821
825
  const keys = cache ? Object.keys(cache) : [];
822
826
  for (const key of keys) {
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { Signal } from './signal.js';
3
+
4
+ /**
5
+ * Callers register callbacks with `this` as the receiver, so every callback-taking API has to
6
+ * accept an arbitrary object as its context. Narrowing one of these to a concrete type compiles
7
+ * inside the engine and only breaks at the call site, so these tests pass a class instance the way
8
+ * a consumer would.
9
+ */
10
+ class Consumer {
11
+ public seen: unknown = null;
12
+
13
+ public handler(value: unknown): void {
14
+ this.seen = value;
15
+ }
16
+ }
17
+
18
+ describe('callback contexts', () => {
19
+ describe('Signal', () => {
20
+ it('accepts an arbitrary receiver on add', () => {
21
+ const signal = new Signal();
22
+ const consumer = new Consumer();
23
+ signal.add(consumer.handler, consumer);
24
+ signal.dispatch('payload');
25
+ expect(consumer.seen).toBe('payload');
26
+ });
27
+
28
+ it('accepts an arbitrary receiver on addOnce', () => {
29
+ const signal = new Signal();
30
+ const consumer = new Consumer();
31
+ signal.addOnce(consumer.handler, consumer);
32
+ signal.dispatch('once');
33
+ expect(consumer.seen).toBe('once');
34
+ });
35
+
36
+ it('matches the receiver on remove', () => {
37
+ const signal = new Signal();
38
+ const consumer = new Consumer();
39
+ signal.add(consumer.handler, consumer);
40
+ signal.remove(consumer.handler, consumer);
41
+ expect(signal.getNumListeners()).toBe(0);
42
+ });
43
+
44
+ it('matches the receiver on removeAll', () => {
45
+ const signal = new Signal();
46
+ const consumer = new Consumer();
47
+ signal.add(consumer.handler, consumer);
48
+ signal.add(vi.fn(), new Consumer());
49
+ signal.removeAll(consumer);
50
+ expect(signal.getNumListeners()).toBe(1);
51
+ });
52
+
53
+ it('reports whether a listener is bound to a receiver', () => {
54
+ const signal = new Signal();
55
+ const consumer = new Consumer();
56
+ signal.add(consumer.handler, consumer);
57
+ expect(signal.has(consumer.handler, consumer)).toBe(true);
58
+ expect(signal.has(consumer.handler, new Consumer())).toBe(false);
59
+ });
60
+
61
+ it('keeps separate bindings per receiver', () => {
62
+ const signal = new Signal();
63
+ const first = new Consumer();
64
+ const second = new Consumer();
65
+ signal.add(first.handler, first);
66
+ signal.add(first.handler, second);
67
+ expect(signal.getNumListeners()).toBe(2);
68
+ });
69
+ });
70
+ });
@@ -9,13 +9,13 @@ const logger = getLogger(['phaser', 'device']);
9
9
  * @param {string} type - The audio format type to check.
10
10
  * @returns {boolean} True if the device can play this audio format, false otherwise.
11
11
  */
12
- export const canPlayAudio = (device: Device, type: string) => device.supportedAudioFormats[type] === true;
12
+ export const canPlayAudio = (device: Device, type: string): boolean => device.supportedAudioFormats[type] === true;
13
13
 
14
14
  /**
15
15
  * Detect the operating system of the device.
16
16
  * @param {Device} device - The device instance to update.
17
17
  */
18
- export const checkOS = (device: Device) => {
18
+ export const checkOS = (device: Device): void => {
19
19
  const ua = navigator.userAgent;
20
20
  if (ua.includes('Android')) {
21
21
  device.android = true;
@@ -52,7 +52,7 @@ export const checkOS = (device: Device) => {
52
52
  * Detect input capabilities of the device.
53
53
  * @param {Device} device - The device instance to update.
54
54
  */
55
- export const checkInput = (device: Device) => {
55
+ export const checkInput = (device: Device): void => {
56
56
  if (
57
57
  'ontouchstart' in document.documentElement ||
58
58
  (globalThis.navigator.maxTouchPoints && globalThis.navigator.maxTouchPoints >= 1)
@@ -72,7 +72,7 @@ export const checkInput = (device: Device) => {
72
72
  * Check for fullscreen support capabilities.
73
73
  * @param {Device} device - The device instance to update.
74
74
  */
75
- export const checkFullScreenSupport = (device: Device) => {
75
+ export const checkFullScreenSupport = (device: Device): void => {
76
76
  const fs = [
77
77
  'requestFullscreen',
78
78
  'requestFullScreen',
@@ -121,7 +121,7 @@ export const checkFullScreenSupport = (device: Device) => {
121
121
  * Detect the browser type.
122
122
  * @param {Device} device - The device instance to update.
123
123
  */
124
- export const checkBrowser = (device: Device) => {
124
+ export const checkBrowser = (device: Device): void => {
125
125
  const ua = navigator.userAgent;
126
126
  if (/Edge\/\d+/.test(ua)) {
127
127
  device.edge = true;
@@ -140,7 +140,7 @@ export const checkBrowser = (device: Device) => {
140
140
  * @param {string} type - The codec type to check.
141
141
  * @returns {boolean} True if the codec is supported, false otherwise.
142
142
  */
143
- export const canPlayType = (audioElement: HTMLAudioElement, type: string) => {
143
+ export const canPlayType = (audioElement: HTMLAudioElement, type: string): boolean => {
144
144
  try {
145
145
  const canPlayResult = audioElement.canPlayType(type);
146
146
  return canPlayResult === 'maybe' || canPlayResult === 'probably';
@@ -156,7 +156,7 @@ export const canPlayType = (audioElement: HTMLAudioElement, type: string) => {
156
156
  * @param {string} type - The media source type to check.
157
157
  * @returns {boolean} True if the media source type is supported, false otherwise.
158
158
  */
159
- export const isMediaSourceTypeSupported = (type: string) => {
159
+ export const isMediaSourceTypeSupported = (type: string): boolean => {
160
160
  if ('MediaSource' in globalThis) {
161
161
  try {
162
162
  return MediaSource.isTypeSupported(type);
@@ -176,7 +176,7 @@ export const isMediaSourceTypeSupported = (type: string) => {
176
176
  * @see https://developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
177
177
  * @see https://bit.ly/iphoneoscodecs
178
178
  */
179
- export const checkAudio = (device: Device) => {
179
+ export const checkAudio = (device: Device): void => {
180
180
  const audioElement = document.createElement('audio');
181
181
  const formats = [
182
182
  { type: 'ogg', codecs: ['audio/ogg; codecs="vorbis"'] },
@@ -208,12 +208,12 @@ export const checkAudio = (device: Device) => {
208
208
  * Check for supported image formats on the device.
209
209
  * @param {Device} device - The device instance to update with image format support.
210
210
  */
211
- export const checkImage = (device: Device) => {
211
+ export const checkImage = (device: Device): void => {
212
212
  try {
213
213
  const avif = new Image();
214
214
  avif.src =
215
215
  'data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A=';
216
- avif.onload = function onload() {
216
+ avif.onload = function onload(): void {
217
217
  device.supportedImageFormats['avif'] = true;
218
218
  };
219
219
  } catch (error) {
@@ -223,7 +223,7 @@ export const checkImage = (device: Device) => {
223
223
  try {
224
224
  const webp = new Image();
225
225
  webp.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=';
226
- webp.onload = function onload() {
226
+ webp.onload = function onload(): void {
227
227
  device.supportedImageFormats['webp'] = true;
228
228
  };
229
229
  } catch (error) {
@@ -236,7 +236,7 @@ export const checkImage = (device: Device) => {
236
236
  * Initialize device capabilities detection.
237
237
  * @param {Device} device - The device instance to initialize.
238
238
  */
239
- export const initialize = (device: Device) => {
239
+ export const initialize = (device: Device): void => {
240
240
  logger.info('initialize');
241
241
  checkOS(device);
242
242
  checkBrowser(device);
@@ -250,4 +250,4 @@ export const initialize = (device: Device) => {
250
250
  * Create a new Device instance.
251
251
  * @returns {Device} A new Device instance.
252
252
  */
253
- export const createDevice = () => new Device();
253
+ export const createDevice = (): Device => new Device();