@vpmedia/phaser 1.116.0 → 1.118.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 (202) hide show
  1. package/dist/index.js +195 -229
  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 +16 -15
  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 +76 -47
  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 +17 -17
  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 +8 -7
  20. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  21. package/dist/phaser/core/input_pointer.d.ts +19 -8
  22. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  23. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  24. package/dist/phaser/core/loader.d.ts +30 -1
  25. package/dist/phaser/core/loader.d.ts.map +1 -1
  26. package/dist/phaser/core/loader_parser.d.ts +24 -4
  27. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  28. package/dist/phaser/core/raf.d.ts.map +1 -1
  29. package/dist/phaser/core/scale_manager.d.ts +37 -12
  30. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  31. package/dist/phaser/core/scene.d.ts.map +1 -1
  32. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  33. package/dist/phaser/core/signal.d.ts.map +1 -1
  34. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  35. package/dist/phaser/core/sound.d.ts +15 -5
  36. package/dist/phaser/core/sound.d.ts.map +1 -1
  37. package/dist/phaser/core/sound_manager.d.ts +24 -22
  38. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  39. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  40. package/dist/phaser/core/stage.d.ts.map +1 -1
  41. package/dist/phaser/core/time.d.ts.map +1 -1
  42. package/dist/phaser/core/timer.d.ts +1 -1
  43. package/dist/phaser/core/timer.d.ts.map +1 -1
  44. package/dist/phaser/core/tween.d.ts +3 -3
  45. package/dist/phaser/core/tween.d.ts.map +1 -1
  46. package/dist/phaser/core/tween_data.d.ts +26 -26
  47. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  48. package/dist/phaser/core/tween_manager.d.ts +8 -6
  49. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  50. package/dist/phaser/core/world.d.ts.map +1 -1
  51. package/dist/phaser/display/bitmap_text.d.ts +13 -8
  52. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  53. package/dist/phaser/display/button.d.ts.map +1 -1
  54. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  55. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  56. package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
  57. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  58. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  59. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  60. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  61. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  62. package/dist/phaser/display/display_object.d.ts.map +1 -1
  63. package/dist/phaser/display/graphics.d.ts.map +1 -1
  64. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  65. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  66. package/dist/phaser/display/group.d.ts.map +1 -1
  67. package/dist/phaser/display/image.d.ts +2 -2
  68. package/dist/phaser/display/image.d.ts.map +1 -1
  69. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  70. package/dist/phaser/display/text.d.ts.map +1 -1
  71. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  72. package/dist/phaser/display/webgl/base_texture.d.ts +12 -10
  73. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  74. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  75. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  76. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +13 -12
  77. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  78. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  79. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  80. package/dist/phaser/display/webgl/graphics.d.ts +9 -7
  81. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  82. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  83. package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  84. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  85. package/dist/phaser/display/webgl/renderer.d.ts +12 -10
  86. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  87. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  88. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  89. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  90. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  91. package/dist/phaser/display/webgl/texture.d.ts +18 -33
  92. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  93. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  94. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  95. package/dist/phaser/geom/circle.d.ts.map +1 -1
  96. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  97. package/dist/phaser/geom/line.d.ts.map +1 -1
  98. package/dist/phaser/geom/matrix.d.ts +1 -1
  99. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  100. package/dist/phaser/geom/point.d.ts.map +1 -1
  101. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  102. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  103. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  104. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  105. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  106. package/dist/phaser/geom/util/line.d.ts +5 -4
  107. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  108. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  109. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  110. package/dist/phaser/geom/util/polygon.d.ts.map +1 -1
  111. package/dist/phaser/geom/util/rectangle.d.ts +10 -1
  112. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  113. package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
  114. package/package.json +1 -1
  115. package/src/phaser/core/animation.ts +20 -20
  116. package/src/phaser/core/animation_manager.ts +27 -24
  117. package/src/phaser/core/animation_parser.ts +2 -2
  118. package/src/phaser/core/array_set.ts +7 -7
  119. package/src/phaser/core/cache.test.ts +201 -0
  120. package/src/phaser/core/cache.ts +174 -130
  121. package/src/phaser/core/device_util.ts +13 -13
  122. package/src/phaser/core/dom.ts +26 -22
  123. package/src/phaser/core/factory.ts +6 -6
  124. package/src/phaser/core/game.ts +10 -10
  125. package/src/phaser/core/input.ts +36 -38
  126. package/src/phaser/core/input_handler.ts +90 -93
  127. package/src/phaser/core/input_mouse.ts +19 -19
  128. package/src/phaser/core/input_mspointer.ts +25 -28
  129. package/src/phaser/core/input_pointer.ts +37 -28
  130. package/src/phaser/core/input_touch.ts +17 -17
  131. package/src/phaser/core/loader.ts +132 -92
  132. package/src/phaser/core/loader_parser.test.ts +115 -0
  133. package/src/phaser/core/loader_parser.ts +66 -38
  134. package/src/phaser/core/raf.ts +3 -3
  135. package/src/phaser/core/scale_manager.ts +86 -67
  136. package/src/phaser/core/scene.ts +7 -7
  137. package/src/phaser/core/scene_manager.ts +16 -16
  138. package/src/phaser/core/signal.ts +29 -19
  139. package/src/phaser/core/signal_binding.ts +4 -4
  140. package/src/phaser/core/sound.ts +45 -33
  141. package/src/phaser/core/sound_manager.ts +72 -73
  142. package/src/phaser/core/sound_sprite.ts +1 -1
  143. package/src/phaser/core/stage.ts +7 -7
  144. package/src/phaser/core/time.ts +16 -16
  145. package/src/phaser/core/timer.ts +36 -26
  146. package/src/phaser/core/tween.ts +29 -29
  147. package/src/phaser/core/tween_data.ts +41 -37
  148. package/src/phaser/core/tween_manager.ts +50 -43
  149. package/src/phaser/core/world.ts +1 -1
  150. package/src/phaser/display/bitmap_text.test.ts +212 -0
  151. package/src/phaser/display/bitmap_text.ts +52 -37
  152. package/src/phaser/display/button.ts +13 -13
  153. package/src/phaser/display/canvas/buffer.ts +3 -3
  154. package/src/phaser/display/canvas/graphics.ts +3 -3
  155. package/src/phaser/display/canvas/masker.ts +2 -2
  156. package/src/phaser/display/canvas/pool.ts +6 -6
  157. package/src/phaser/display/canvas/renderer.ts +6 -6
  158. package/src/phaser/display/canvas/tinter.ts +39 -8
  159. package/src/phaser/display/canvas/util.ts +15 -9
  160. package/src/phaser/display/display_object.ts +38 -38
  161. package/src/phaser/display/graphics.ts +30 -30
  162. package/src/phaser/display/graphics_data.ts +1 -1
  163. package/src/phaser/display/graphics_data_util.ts +1 -1
  164. package/src/phaser/display/group.ts +16 -16
  165. package/src/phaser/display/image.ts +30 -26
  166. package/src/phaser/display/sprite_util.ts +12 -4
  167. package/src/phaser/display/text.ts +55 -55
  168. package/src/phaser/display/webgl/abstract_filter.ts +1 -1
  169. package/src/phaser/display/webgl/base_texture.ts +22 -18
  170. package/src/phaser/display/webgl/blend_manager.ts +3 -3
  171. package/src/phaser/display/webgl/earcut.ts +3 -3
  172. package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
  173. package/src/phaser/display/webgl/filter_manager.ts +7 -7
  174. package/src/phaser/display/webgl/filter_texture.ts +3 -3
  175. package/src/phaser/display/webgl/graphics.ts +43 -41
  176. package/src/phaser/display/webgl/graphics_data.ts +2 -2
  177. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  178. package/src/phaser/display/webgl/render_texture.ts +6 -6
  179. package/src/phaser/display/webgl/renderer.ts +20 -25
  180. package/src/phaser/display/webgl/shader/normal.ts +3 -3
  181. package/src/phaser/display/webgl/shader_manager.ts +2 -2
  182. package/src/phaser/display/webgl/sprite_batch.ts +9 -9
  183. package/src/phaser/display/webgl/stencil_manager.ts +4 -4
  184. package/src/phaser/display/webgl/texture.ts +23 -42
  185. package/src/phaser/display/webgl/texture_util.ts +2 -2
  186. package/src/phaser/display/webgl/util.ts +11 -7
  187. package/src/phaser/geom/circle.ts +21 -21
  188. package/src/phaser/geom/ellipse.ts +7 -7
  189. package/src/phaser/geom/line.ts +29 -29
  190. package/src/phaser/geom/matrix.ts +13 -13
  191. package/src/phaser/geom/point.ts +36 -30
  192. package/src/phaser/geom/polygon.ts +6 -6
  193. package/src/phaser/geom/rectangle.ts +42 -42
  194. package/src/phaser/geom/rounded_rectangle.ts +2 -2
  195. package/src/phaser/geom/util/circle.ts +7 -7
  196. package/src/phaser/geom/util/ellipse.ts +1 -1
  197. package/src/phaser/geom/util/line.ts +13 -5
  198. package/src/phaser/geom/util/matrix.ts +3 -3
  199. package/src/phaser/geom/util/point.ts +20 -20
  200. package/src/phaser/geom/util/polygon.ts +1 -1
  201. package/src/phaser/geom/util/rectangle.ts +34 -17
  202. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
@@ -8,6 +8,37 @@ import { Signal } from './signal.js';
8
8
 
9
9
  const TEXTURE_ATLAS_JSON_HASH = 1;
10
10
 
11
+ /**
12
+ * What a completed load carries. Which member applies is decided by the file's type, so the
13
+ * completion handlers narrow before handing it to the cache.
14
+ */
15
+ /** One entry in a pack manifest: the arguments for the loader call it stands for. */
16
+ export type PackEntry = {
17
+ type: string;
18
+ key: string;
19
+ url?: string;
20
+ overwrite?: boolean;
21
+ frameWidth?: number;
22
+ frameHeight?: number;
23
+ frameMax?: number;
24
+ margin?: number;
25
+ spacing?: number;
26
+ urls?: string[] | string;
27
+ autoDecode?: boolean;
28
+ textureURL?: string;
29
+ atlasURL?: string;
30
+ atlasData?: unknown;
31
+ audioURL?: string;
32
+ jsonURL?: string;
33
+ jsonData?: unknown;
34
+ fontDataURL?: string;
35
+ xSpacing?: number;
36
+ ySpacing?: number;
37
+ format?: unknown;
38
+ };
39
+
40
+ export type LoaderFileData = HTMLImageElement | XMLDocument | ArrayBuffer | string | Record<string, unknown> | null;
41
+
11
42
  /** An audio source, either a plain URL or a URL paired with its format. */
12
43
  export type AudioSource = string | { uri: string; type?: string };
13
44
 
@@ -21,7 +52,7 @@ export type LoaderFile = {
21
52
  path: string;
22
53
  url: string | AudioSource[];
23
54
  syncPoint: boolean;
24
- data: any;
55
+ data: LoaderFileData;
25
56
  loading: boolean;
26
57
  loaded: boolean;
27
58
  error: boolean;
@@ -124,7 +155,7 @@ export class Loader {
124
155
  * @param {Image} sprite - The image to use as the preload sprite.
125
156
  * @param {number} direction - The direction of the progress (0 = horizontal, 1 = vertical).
126
157
  */
127
- public setPreloadSprite(sprite: Image, direction = 0) {
158
+ public setPreloadSprite(sprite: Image, direction = 0): void {
128
159
  this.preloadSprite = {
129
160
  sprite,
130
161
  direction,
@@ -146,7 +177,7 @@ export class Loader {
146
177
  /**
147
178
  * Resizes the preload sprite when the window is resized.
148
179
  */
149
- public resize() {
180
+ public resize(): void {
150
181
  if (this.preloadSprite && this.preloadSprite.height !== this.preloadSprite.sprite.height) {
151
182
  this.preloadSprite.rect.height = this.preloadSprite.sprite.height;
152
183
  }
@@ -158,7 +189,7 @@ export class Loader {
158
189
  * @param {string} key - The key of the file to check for.
159
190
  * @returns {boolean} True if the file exists, false otherwise.
160
191
  */
161
- public checkKeyExists(type: string, key: string) {
192
+ public checkKeyExists(type: string, key: string): boolean {
162
193
  return this.getAssetIndex(type, key) > -1;
163
194
  }
164
195
 
@@ -168,7 +199,7 @@ export class Loader {
168
199
  * @param {string} key - The key of the file to find.
169
200
  * @returns {number} The index of the file in the list, or -1 if not found.
170
201
  */
171
- public getAssetIndex(type: string, key: string) {
202
+ public getAssetIndex(type: string, key: string): number {
172
203
  let bestFound = -1;
173
204
  for (let i = 0; i < this._fileList.length; i += 1) {
174
205
  const file = this._fileList[i]!;
@@ -203,7 +234,7 @@ export class Loader {
203
234
  * @param {boolean} hard - Whether to perform a hard reset (clears preload sprite).
204
235
  * @param {boolean} clearEvents - Whether to clear event listeners.
205
236
  */
206
- public reset(hard = false, clearEvents = false) {
237
+ public reset(hard = false, clearEvents = false): void {
207
238
  if (hard) {
208
239
  this.preloadSprite = null;
209
240
  }
@@ -243,7 +274,7 @@ export class Loader {
243
274
  properties: Partial<LoaderFile> | null = null,
244
275
  overwrite = false,
245
276
  extension: string | null = null
246
- ) {
277
+ ): this {
247
278
  if (key === undefined || key === '') {
248
279
  this.game.logger.warn(`Loader: Invalid or no key given of type ${type}`);
249
280
  return this;
@@ -292,7 +323,7 @@ export class Loader {
292
323
  * @param {object} properties - The new properties for the file.
293
324
  * @returns {Loader} This Loader instance for chaining.
294
325
  */
295
- public replaceInFileList(type: string, key: string, url: string, properties: Partial<LoaderFile>) {
326
+ public replaceInFileList(type: string, key: string, url: string, properties: Partial<LoaderFile>): this {
296
327
  return this.addToFileList(type, key, url, properties, true);
297
328
  }
298
329
 
@@ -304,14 +335,14 @@ export class Loader {
304
335
  * @param {object} callbackContext - The context in which to call the callback.
305
336
  * @returns {Loader} This Loader instance for chaining.
306
337
  */
307
- public pack(key: string, url: string, data: unknown, callbackContext: unknown) {
338
+ public pack(key: string, url: string, data: unknown, callbackContext: unknown): this {
308
339
  const pack = {
309
340
  type: 'packfile',
310
341
  key,
311
342
  url,
312
343
  path: this.path,
313
344
  syncPoint: true,
314
- data: null as unknown,
345
+ data: null as LoaderFileData,
315
346
  loading: false,
316
347
  loaded: false,
317
348
  error: false,
@@ -321,7 +352,7 @@ export class Loader {
321
352
  if (typeof data === 'string') {
322
353
  data = JSON.parse(data);
323
354
  }
324
- pack.data = data ?? {};
355
+ pack.data = (data ?? {}) as LoaderFileData;
325
356
  pack.loaded = true;
326
357
  }
327
358
  for (let i = 0; i < this._fileList.length + 1; i += 1) {
@@ -342,7 +373,7 @@ export class Loader {
342
373
  * @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
343
374
  * @returns {Loader} This Loader instance for chaining.
344
375
  */
345
- public image(key: string, url?: string, overwrite = false) {
376
+ public image(key: string, url?: string, overwrite = false): this {
346
377
  return this.addToFileList('image', key, url, undefined, overwrite, '.png');
347
378
  }
348
379
 
@@ -352,7 +383,7 @@ export class Loader {
352
383
  * @param {string[]} urls - The URLs of the image files to load.
353
384
  * @returns {Loader} This Loader instance for chaining.
354
385
  */
355
- public images(keys: string[], urls: string[]) {
386
+ public images(keys: string[], urls: string[]): this {
356
387
  if (Array.isArray(urls)) {
357
388
  for (let i = 0; i < keys.length; i += 1) {
358
389
  this.image(keys[i]!, urls[i]);
@@ -372,7 +403,7 @@ export class Loader {
372
403
  * @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
373
404
  * @returns {Loader} This Loader instance for chaining.
374
405
  */
375
- public text(key: string, url: string, overwrite = false) {
406
+ public text(key: string, url: string, overwrite = false): this {
376
407
  return this.addToFileList('text', key, url, undefined, overwrite, '.txt');
377
408
  }
378
409
 
@@ -383,7 +414,7 @@ export class Loader {
383
414
  * @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
384
415
  * @returns {Loader} This Loader instance for chaining.
385
416
  */
386
- public json(key: string, url: string, overwrite = false) {
417
+ public json(key: string, url: string, overwrite = false): this {
387
418
  return this.addToFileList('json', key, url, undefined, overwrite, '.json');
388
419
  }
389
420
 
@@ -394,7 +425,7 @@ export class Loader {
394
425
  * @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
395
426
  * @returns {Loader} This Loader instance for chaining.
396
427
  */
397
- public xml(key: string, url: string, overwrite = false) {
428
+ public xml(key: string, url: string, overwrite = false): this {
398
429
  return this.addToFileList('xml', key, url, undefined, overwrite, '.xml');
399
430
  }
400
431
 
@@ -417,7 +448,7 @@ export class Loader {
417
448
  frameMax = -1,
418
449
  margin = 0,
419
450
  spacing = 0
420
- ) {
451
+ ): this {
421
452
  return this.addToFileList(
422
453
  'spritesheet',
423
454
  key,
@@ -435,7 +466,7 @@ export class Loader {
435
466
  * @param {boolean} autoDecode - Whether to automatically decode the audio file.
436
467
  * @returns {Loader} This Loader instance for chaining.
437
468
  */
438
- public audio(key: string, urls: string | string[], autoDecode = true) {
469
+ public audio(key: string, urls: string | string[], autoDecode = true): this {
439
470
  if (this.game.sound.noAudio || this.game.device.noAudioFormat) {
440
471
  return this;
441
472
  }
@@ -454,7 +485,7 @@ export class Loader {
454
485
  * @param {boolean} autoDecode - Whether to automatically decode the audio file.
455
486
  * @returns {Loader} This Loader instance for chaining.
456
487
  */
457
- public audioSprite(key: string, urls: string, jsonURL: string, jsonData: unknown, autoDecode = true) {
488
+ public audioSprite(key: string, urls: string, jsonURL: string, jsonData: unknown, autoDecode = true): this {
458
489
  if (this.game.sound.noAudio || this.game.device.noAudioFormat) {
459
490
  return this;
460
491
  }
@@ -488,7 +519,7 @@ export class Loader {
488
519
  atlasData: unknown = null,
489
520
  xSpacing = 0,
490
521
  ySpacing = 0
491
- ) {
522
+ ): this {
492
523
  textureURL ??= `${key}.png`;
493
524
  if (atlasURL === null && atlasData === null) {
494
525
  atlasURL = `${key}.xml`;
@@ -534,7 +565,7 @@ export class Loader {
534
565
  atlasURL: string | null = null,
535
566
  atlasData: unknown = null,
536
567
  format: number = TEXTURE_ATLAS_JSON_HASH
537
- ) {
568
+ ): this {
538
569
  textureURL ??= `${key}.png`;
539
570
  if (!atlasURL && !atlasData) {
540
571
  atlasURL = `${key}.json`;
@@ -554,7 +585,7 @@ export class Loader {
554
585
  * @param {object} callbackContext - The context in which to call the callback.
555
586
  * @returns {Loader} This Loader instance for chaining.
556
587
  */
557
- public withSyncPoint(callback: Function, callbackContext: unknown) {
588
+ public withSyncPoint(callback: Function, callbackContext: unknown): this {
558
589
  this._withSyncPointDepth += 1;
559
590
  try {
560
591
  callback.call(callbackContext ?? this, this);
@@ -570,7 +601,7 @@ export class Loader {
570
601
  * @param {string} key - The key of the file to add a sync point to.
571
602
  * @returns {Loader} This Loader instance for chaining.
572
603
  */
573
- public addSyncPoint(type: string, key: string) {
604
+ public addSyncPoint(type: string, key: string): this {
574
605
  const asset = this.getAsset(type, key);
575
606
  if (asset) {
576
607
  asset.file.syncPoint = true;
@@ -583,7 +614,7 @@ export class Loader {
583
614
  * @param {string} type - The type of file to remove.
584
615
  * @param {string} key - The key of the file to remove.
585
616
  */
586
- public removeFile(type: string, key: string) {
617
+ public removeFile(type: string, key: string): void {
587
618
  const asset = this.getAsset(type, key);
588
619
  if (asset) {
589
620
  if (!asset.file.loaded && !asset.file.loading) {
@@ -595,7 +626,7 @@ export class Loader {
595
626
  /**
596
627
  * Removes all files from the file list.
597
628
  */
598
- public removeAll() {
629
+ public removeAll(): void {
599
630
  this._fileList.length = 0;
600
631
  this._flightQueue.length = 0;
601
632
  }
@@ -603,7 +634,7 @@ export class Loader {
603
634
  /**
604
635
  * Starts the loading process for all queued files.
605
636
  */
606
- public start() {
637
+ public start(): void {
607
638
  if (this.isLoading) {
608
639
  return;
609
640
  }
@@ -616,7 +647,7 @@ export class Loader {
616
647
  /**
617
648
  * Processes the loading queue, loading files as appropriate.
618
649
  */
619
- public processLoadQueue() {
650
+ public processLoadQueue(): void {
620
651
  if (!this.isLoading) {
621
652
  this.game.logger.warn('Active loading canceled / reset');
622
653
  this.finishedLoading(true);
@@ -705,7 +736,7 @@ export class Loader {
705
736
  // This indicates a critical internal error with no known recovery.
706
737
  this.game.logger.warn('Aborting: processing queue empty, loading may have stalled');
707
738
  const scope = this;
708
- setTimeout(() => {
739
+ setTimeout((): void => {
709
740
  scope.finishedLoading(true);
710
741
  }, 2000);
711
742
  }
@@ -715,7 +746,7 @@ export class Loader {
715
746
  * Finishes the loading process, optionally reporting an abnormal termination.
716
747
  * @param {boolean} abnormal - Whether the loading was terminated abnormally.
717
748
  */
718
- public finishedLoading(abnormal = false) {
749
+ public finishedLoading(abnormal = false): void {
719
750
  if (this.hasLoaded) {
720
751
  return;
721
752
  }
@@ -739,7 +770,7 @@ export class Loader {
739
770
  * @param {object} file - The file to complete or mark as failed.
740
771
  * @param {string} errorMessage - An error message if the file failed to load.
741
772
  */
742
- public asyncComplete(file: LoaderFile, errorMessage = '') {
773
+ public asyncComplete(file: LoaderFile, errorMessage = ''): void {
743
774
  file.loaded = true;
744
775
  file.error = Boolean(errorMessage);
745
776
  if (file.error) {
@@ -754,53 +785,54 @@ export class Loader {
754
785
  * Processes a pack file, adding its contained files to the loader.
755
786
  * @param {object} pack - The pack file object to process.
756
787
  */
757
- public processPack(pack: LoaderFile) {
758
- const packData = pack.data[pack.key];
788
+ public processPack(pack: LoaderFile): void {
789
+ const manifest = (pack.data ?? {}) as Record<string, unknown>;
790
+ const packData = manifest[pack.key] as { files?: unknown[] } | unknown[] | undefined;
759
791
  if (!packData) {
760
792
  this.game.logger.warn('Missing loader pack key', { key: pack.key });
761
793
  return;
762
794
  }
763
- const packDataCompat = Array.isArray(packData) ? packData : packData.files;
795
+ const packDataCompat = (Array.isArray(packData) ? packData : (packData.files ?? [])) as PackEntry[];
764
796
  for (const file of packDataCompat) {
765
797
  switch (file.type) {
766
798
  case 'image': {
767
- this.image(file.key, file.url, file.overwrite);
799
+ this.image(file.key, file.url ?? file.key, file.overwrite);
768
800
  break;
769
801
  }
770
802
  case 'text': {
771
- this.text(file.key, file.url, file.overwrite);
803
+ this.text(file.key, file.url ?? file.key, file.overwrite);
772
804
  break;
773
805
  }
774
806
  case 'json': {
775
- this.json(file.key, file.url, file.overwrite);
807
+ this.json(file.key, file.url ?? file.key, file.overwrite);
776
808
  break;
777
809
  }
778
810
  case 'xml': {
779
- this.xml(file.key, file.url, file.overwrite);
811
+ this.xml(file.key, file.url ?? file.key, file.overwrite);
780
812
  break;
781
813
  }
782
814
  case 'spritesheet': {
783
815
  this.spritesheet(
784
816
  file.key,
785
- file.url,
786
- file.frameWidth,
787
- file.frameHeight,
788
- file.frameMax,
817
+ file.url ?? file.key,
818
+ file.frameWidth ?? 0,
819
+ file.frameHeight ?? 0,
820
+ file.frameMax ?? -1,
789
821
  file.margin,
790
822
  file.spacing
791
823
  );
792
824
  break;
793
825
  }
794
826
  case 'audio': {
795
- this.audio(file.key, file.urls ?? file.url);
827
+ this.audio(file.key, file.urls ?? file.url ?? file.key);
796
828
  break;
797
829
  }
798
830
  case 'audiosprite': {
799
- this.audioSprite(file.key, file.urls ?? file.url, file.jsonURL, file.jsonData);
831
+ this.audioSprite(file.key, String(file.urls ?? file.url ?? file.key), file.jsonURL ?? '', file.jsonData);
800
832
  break;
801
833
  }
802
834
  case 'audioSprite': {
803
- this.audioSprite(file.key, file.audioURL, file.jsonURL, file.jsonData);
835
+ this.audioSprite(file.key, file.audioURL ?? file.key, file.jsonURL ?? '', file.jsonData);
804
836
  break;
805
837
  }
806
838
  case 'bitmapFont': {
@@ -815,7 +847,7 @@ export class Loader {
815
847
  break;
816
848
  }
817
849
  case 'atlas': {
818
- this.atlas(file.key, file.textureURL, file.atlasURL, file.atlasData, TEXTURE_ATLAS_JSON_HASH);
850
+ this.atlas(file.key, file.textureURL ?? file.key, file.atlasURL, file.atlasData, TEXTURE_ATLAS_JSON_HASH);
819
851
  break;
820
852
  }
821
853
  }
@@ -845,7 +877,7 @@ export class Loader {
845
877
  * Loads a file using XMLHttpRequest, handling image files specially.
846
878
  * @param {object} file - The file object to load.
847
879
  */
848
- public loadFile(file: LoaderFile) {
880
+ public loadFile(file: LoaderFile): void {
849
881
  switch (file.type) {
850
882
  case 'packfile': {
851
883
  this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.fileComplete);
@@ -895,34 +927,40 @@ export class Loader {
895
927
  * Loads an image file using the Image DOM element.
896
928
  * @param {object} file - The file object to load.
897
929
  */
898
- public loadImageTag(file: LoaderFile) {
930
+ public loadImageTag(file: LoaderFile): void {
899
931
  this.log('loadImageTag', file);
900
932
  const scope = this;
901
- file.data = new globalThis.Image();
902
- file.data.name = file.key;
903
- if (this.crossOrigin) {
904
- file.data.crossOrigin = this.crossOrigin;
933
+ const image = new globalThis.Image();
934
+ file.data = image;
935
+ image.name = file.key;
936
+ if (typeof this.crossOrigin === 'string' && this.crossOrigin) {
937
+ image.crossOrigin = this.crossOrigin;
905
938
  }
906
- file.data.onload = () => {
907
- if (file.data.onload) {
908
- file.data.onload = null;
909
- file.data.onerror = null;
939
+ image.onload = (): void => {
940
+ if (image.onload) {
941
+ image.onload = null;
942
+ image.onerror = null;
910
943
  scope.fileComplete(file);
911
944
  }
912
945
  };
913
- file.data.onerror = () => {
946
+ image.onerror = (): void => {
914
947
  if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
915
- setTimeout(() => {
948
+ setTimeout((): void => {
916
949
  file.numRetry = !file.numRetry ? 1 : (file.numRetry += 1);
917
950
  scope.loadImageTag(file);
918
951
  }, 1000);
919
- } else if (file.data.onload) {
920
- file.data.onload = null;
921
- file.data.onerror = null;
952
+ } else if (image.onload) {
953
+ image.onload = null;
954
+ image.onerror = null;
922
955
  scope.fileError(file);
923
956
  }
924
957
  };
925
- file.data.src = this.transformUrl(file.url, file);
958
+ const src = this.transformUrl(file.url, file);
959
+ if (src === false) {
960
+ this.fileError(file, null, 'Could not resolve the file URL');
961
+ return;
962
+ }
963
+ image.src = src;
926
964
  }
927
965
 
928
966
  /**
@@ -939,7 +977,7 @@ export class Loader {
939
977
  type: XMLHttpRequestResponseType,
940
978
  onload: Function,
941
979
  onerror: Function | null = null
942
- ) {
980
+ ): void {
943
981
  if (url === false) {
944
982
  this.fileError(file, null, 'Could not resolve the file URL');
945
983
  return;
@@ -963,7 +1001,7 @@ export class Loader {
963
1001
  if (xhr.readyState === 4 && xhr.status >= 400 && xhr.status <= 599) {
964
1002
  // Handle HTTP status codes of 4xx and 5xx as errors, even if xhr.onerror was not called.
965
1003
  if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
966
- setTimeout(() => {
1004
+ setTimeout((): void => {
967
1005
  file.numRetry = !file.numRetry ? 1 : (file.numRetry += 1);
968
1006
  scope.xhrLoad(file, url, type, onload, onerror);
969
1007
  }, 1000);
@@ -986,7 +1024,7 @@ export class Loader {
986
1024
  };
987
1025
  xhr.onerror = () => {
988
1026
  if (scope.isUseRetry && (!file.numRetry || file.numRetry < scope.maxRetry)) {
989
- setTimeout(() => {
1027
+ setTimeout((): void => {
990
1028
  file.numRetry = !file.numRetry ? 1 : (file.numRetry += 1);
991
1029
  scope.xhrLoad(file, url, type, onload, onerror);
992
1030
  }, 1000);
@@ -1012,7 +1050,7 @@ export class Loader {
1012
1050
  /**
1013
1051
  * Placeholder for XDomainRequest loading (not implemented).
1014
1052
  */
1015
- public xhrLoadWithXDR() {
1053
+ public xhrLoadWithXDR(): void {
1016
1054
  // TODO
1017
1055
  this.game.logger.warn('loader.xhrLoadWithXDR() is not implemented');
1018
1056
  }
@@ -1022,7 +1060,7 @@ export class Loader {
1022
1060
  * @param {object[]} urls - The array of URLs to check for supported audio formats.
1023
1061
  * @returns {string} The first URL with a supported audio format, or null if none found.
1024
1062
  */
1025
- public getAudioURL(urls: string | AudioSource[]) {
1063
+ public getAudioURL(urls: string | AudioSource[]): string | null {
1026
1064
  if (this.game.sound.noAudio || this.game.device.noAudioFormat) {
1027
1065
  return null;
1028
1066
  }
@@ -1064,7 +1102,7 @@ export class Loader {
1064
1102
  * @param {XMLHttpRequest} xhr - The XMLHttpRequest object that failed.
1065
1103
  * @param {number | string} reason - The error code or message explaining the failure.
1066
1104
  */
1067
- public fileError(file: LoaderFile, xhr: XMLHttpRequest | null = null, reason: unknown = 0) {
1105
+ public fileError(file: LoaderFile, xhr: XMLHttpRequest | null = null, reason: unknown = 0): void {
1068
1106
  // const url = file.requestUrl || this.transformUrl(file.url, file);
1069
1107
  if (!reason && xhr) {
1070
1108
  reason = xhr.status;
@@ -1079,7 +1117,7 @@ export class Loader {
1079
1117
  * @param {XMLHttpRequest} xhr - TBD.
1080
1118
  * @throws {Error}
1081
1119
  */
1082
- public fileComplete(file: LoaderFile, xhr?: XMLHttpRequest) {
1120
+ public fileComplete(file: LoaderFile, xhr?: XMLHttpRequest): void {
1083
1121
  let loadNext = true;
1084
1122
  // By this point the audio candidate list has been resolved to a single URL.
1085
1123
  const url = typeof file.url === 'string' ? file.url : '';
@@ -1091,14 +1129,14 @@ export class Loader {
1091
1129
  break;
1092
1130
  }
1093
1131
  case 'image': {
1094
- this.cache.addImage(file.key, url, file.data);
1132
+ this.cache.addImage(file.key, url, file.data as HTMLImageElement);
1095
1133
  break;
1096
1134
  }
1097
1135
  case 'spritesheet': {
1098
1136
  this.cache.addSpriteSheet(
1099
1137
  file.key,
1100
1138
  url,
1101
- file.data,
1139
+ file.data as HTMLImageElement,
1102
1140
  file.frameWidth ?? 0,
1103
1141
  file.frameHeight ?? 0,
1104
1142
  file.frameMax ?? -1,
@@ -1109,7 +1147,7 @@ export class Loader {
1109
1147
  }
1110
1148
  case 'textureatlas': {
1111
1149
  if (file.atlasURL == null) {
1112
- this.cache.addTextureAtlas(file.key, url, file.data, file.atlasData);
1150
+ this.cache.addTextureAtlas(file.key, url, file.data as HTMLImageElement, file.atlasData);
1113
1151
  } else {
1114
1152
  loadNext = false;
1115
1153
  if (file.format === TEXTURE_ATLAS_JSON_HASH) {
@@ -1125,7 +1163,7 @@ export class Loader {
1125
1163
  this.cache.addBitmapFont(
1126
1164
  file.key,
1127
1165
  url,
1128
- file.data,
1166
+ file.data as HTMLImageElement,
1129
1167
  file.atlasData,
1130
1168
  file.atlasType ?? 'xml',
1131
1169
  file.xSpacing ?? 0,
@@ -1138,7 +1176,7 @@ export class Loader {
1138
1176
  file,
1139
1177
  this.transformUrl(file.atlasURL, file),
1140
1178
  'text',
1141
- (bitmapFontFile: LoaderFile, bitmapFontXhr: XMLHttpRequest) => {
1179
+ (bitmapFontFile: LoaderFile, bitmapFontXhr: XMLHttpRequest): void => {
1142
1180
  let json;
1143
1181
  try {
1144
1182
  // Try to parse as JSON, if it fails, then it's hopefully XML
@@ -1159,16 +1197,18 @@ export class Loader {
1159
1197
  break;
1160
1198
  }
1161
1199
  case 'audio': {
1162
- file.data = response.response;
1163
- this.cache.addSound(file.key, url, file.data);
1200
+ const audio = response.response as ArrayBuffer;
1201
+ file.data = audio;
1202
+ this.cache.addSound(file.key, url, audio);
1164
1203
  if (file.autoDecode) {
1165
1204
  this.game.sound.decode(file.key);
1166
1205
  }
1167
1206
  break;
1168
1207
  }
1169
1208
  case 'text': {
1170
- file.data = response.responseText;
1171
- this.cache.addText(file.key, url, file.data);
1209
+ const { responseText } = response;
1210
+ file.data = responseText;
1211
+ this.cache.addText(file.key, url, responseText);
1172
1212
  break;
1173
1213
  }
1174
1214
  default: {
@@ -1186,14 +1226,14 @@ export class Loader {
1186
1226
  * @param {object} file - The file object that was loaded successfully.
1187
1227
  * @param {XMLHttpRequest} xhr - The XMLHttpRequest object containing the file data.
1188
1228
  */
1189
- public jsonLoadComplete(file: LoaderFile, xhr: XMLHttpRequest) {
1229
+ public jsonLoadComplete(file: LoaderFile, xhr: XMLHttpRequest): void {
1190
1230
  const data = JSON.parse(xhr.responseText);
1191
1231
  const url = typeof file.url === 'string' ? file.url : '';
1192
1232
  if (file.type === 'bitmapfont') {
1193
1233
  this.cache.addBitmapFont(
1194
1234
  file.key,
1195
1235
  url,
1196
- file.data,
1236
+ file.data as HTMLImageElement,
1197
1237
  data,
1198
1238
  file.atlasType ?? 'json',
1199
1239
  file.xSpacing ?? 0,
@@ -1202,7 +1242,7 @@ export class Loader {
1202
1242
  } else if (file.type === 'json') {
1203
1243
  this.cache.addJSON(file.key, url, data);
1204
1244
  } else {
1205
- this.cache.addTextureAtlas(file.key, url, file.data, data);
1245
+ this.cache.addTextureAtlas(file.key, url, file.data as HTMLImageElement, data);
1206
1246
  }
1207
1247
  this.asyncComplete(file);
1208
1248
  }
@@ -1210,7 +1250,7 @@ export class Loader {
1210
1250
  /**
1211
1251
  * TBD.
1212
1252
  */
1213
- public csvLoadComplete() {
1253
+ public csvLoadComplete(): void {
1214
1254
  // TODO
1215
1255
  this.game.logger.warn('loader.csvLoadComplete() is not implemented');
1216
1256
  }
@@ -1220,7 +1260,7 @@ export class Loader {
1220
1260
  * @param {object} file - The file object containing the JSON data.
1221
1261
  * @param {XMLHttpRequest} xhr - The XMLHttpRequest object containing the file data.
1222
1262
  */
1223
- public xmlLoadComplete(file: LoaderFile, xhr: XMLHttpRequest) {
1263
+ public xmlLoadComplete(file: LoaderFile, xhr: XMLHttpRequest): void {
1224
1264
  // Always try parsing the content as XML, regardless of actually response type
1225
1265
  const data = xhr.responseText;
1226
1266
  const xml = this.parseXml(data);
@@ -1235,14 +1275,14 @@ export class Loader {
1235
1275
  this.cache.addBitmapFont(
1236
1276
  file.key,
1237
1277
  url,
1238
- file.data,
1278
+ file.data as HTMLImageElement,
1239
1279
  xml,
1240
1280
  file.atlasType ?? 'xml',
1241
1281
  file.xSpacing ?? 0,
1242
1282
  file.ySpacing ?? 0
1243
1283
  );
1244
1284
  } else if (file.type === 'textureatlas') {
1245
- this.cache.addTextureAtlas(file.key, url, file.data, xml);
1285
+ this.cache.addTextureAtlas(file.key, url, file.data as HTMLImageElement, xml);
1246
1286
  } else if (file.type === 'xml') {
1247
1287
  this.cache.addXML(file.key, url, xml);
1248
1288
  }
@@ -1278,7 +1318,7 @@ export class Loader {
1278
1318
  /**
1279
1319
  * Updates the preload sprite's progress indicator.
1280
1320
  */
1281
- public updateProgress() {
1321
+ public updateProgress(): void {
1282
1322
  if (this.preloadSprite) {
1283
1323
  if (this.preloadSprite.direction === 0) {
1284
1324
  this.preloadSprite.rect.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
@@ -1299,7 +1339,7 @@ export class Loader {
1299
1339
  * @param {string} message - The message to log.
1300
1340
  * @param {string|object} data - Additional data to log with the message.
1301
1341
  */
1302
- public log(message: string, data: string | any = '') {
1342
+ public log(message: string, data: string | any = ''): void {
1303
1343
  if (!this.isUseLog) {
1304
1344
  return;
1305
1345
  }
@@ -1310,7 +1350,7 @@ export class Loader {
1310
1350
  * Gets the number of files that have been loaded.
1311
1351
  * @returns {number} The total number of loaded files.
1312
1352
  */
1313
- public totalLoadedFiles() {
1353
+ public totalLoadedFiles(): number {
1314
1354
  return this._loadedFileCount;
1315
1355
  }
1316
1356
 
@@ -1318,7 +1358,7 @@ export class Loader {
1318
1358
  * Gets the number of files that are still queued for loading.
1319
1359
  * @returns {number} The total number of queued files.
1320
1360
  */
1321
- public totalQueuedFiles() {
1361
+ public totalQueuedFiles(): number {
1322
1362
  return this._totalFileCount - this._loadedFileCount;
1323
1363
  }
1324
1364
 
@@ -1326,7 +1366,7 @@ export class Loader {
1326
1366
  * Gets the number of pack files that have been loaded.
1327
1367
  * @returns {number} The total number of loaded pack files.
1328
1368
  */
1329
- public totalLoadedPacks() {
1369
+ public totalLoadedPacks(): number {
1330
1370
  return this._totalPackCount;
1331
1371
  }
1332
1372
 
@@ -1334,7 +1374,7 @@ export class Loader {
1334
1374
  * Gets the number of pack files that are still queued for loading.
1335
1375
  * @returns {number} The total number of queued pack files.
1336
1376
  */
1337
- public totalQueuedPacks() {
1377
+ public totalQueuedPacks(): number {
1338
1378
  return this._totalPackCount - this._loadedPackCount;
1339
1379
  }
1340
1380
 
@@ -1342,7 +1382,7 @@ export class Loader {
1342
1382
  * Gets the loading progress as a percentage (0-100).
1343
1383
  * @returns {number} The current loading progress as a percentage.
1344
1384
  */
1345
- public get progressFloat() {
1385
+ public get progressFloat(): number {
1346
1386
  const progress = (this._loadedFileCount / this._totalFileCount) * 100;
1347
1387
  return Math.max(0, Math.min(100, progress || 0));
1348
1388
  }
@@ -1351,7 +1391,7 @@ export class Loader {
1351
1391
  * Gets the loading progress as a rounded percentage (0-100).
1352
1392
  * @returns {number} The current loading progress as a rounded percentage.
1353
1393
  */
1354
- public get progress() {
1394
+ public get progress(): number {
1355
1395
  return Math.round(this.progressFloat);
1356
1396
  }
1357
1397
  }