@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.
- package/dist/index.js +1261 -1314
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts +14 -10
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +10 -8
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- package/dist/phaser/core/animation_parser.d.ts +5 -4
- package/dist/phaser/core/animation_parser.d.ts.map +1 -1
- package/dist/phaser/core/array_set.d.ts.map +1 -1
- package/dist/phaser/core/cache.d.ts +4 -3
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/const.d.ts.map +1 -1
- package/dist/phaser/core/device.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts +3 -2
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/event_manager.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/frame.d.ts.map +1 -1
- package/dist/phaser/core/frame_data.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +8 -6
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +40 -30
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts +3 -2
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +3 -2
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +6 -4
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts +3 -2
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +4 -3
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +9 -8
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts +3 -2
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/registry.d.ts +7 -0
- package/dist/phaser/core/registry.d.ts.map +1 -0
- package/dist/phaser/core/scale_manager.d.ts +1 -1
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts +0 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts +0 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts +4 -3
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +6 -4
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +3 -2
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts +5 -4
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts +3 -2
- package/dist/phaser/core/stage.d.ts.map +1 -1
- package/dist/phaser/core/time.d.ts +1 -1
- package/dist/phaser/core/time.d.ts.map +1 -1
- package/dist/phaser/core/timer.d.ts +1 -1
- package/dist/phaser/core/timer.d.ts.map +1 -1
- package/dist/phaser/core/timer_event.d.ts.map +1 -1
- package/dist/phaser/core/tween.d.ts +10 -7
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +3 -2
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_easing.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +3 -2
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts +3 -2
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +3 -2
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- package/dist/phaser/display/button.d.ts +3 -2
- package/dist/phaser/display/button.d.ts.map +1 -1
- package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/graphics.d.ts +7 -6
- package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts +2 -2
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- package/dist/phaser/display/canvas/renderer.d.ts +10 -8
- package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/dist/phaser/display/canvas/tinter.d.ts +3 -2
- package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/dist/phaser/display/canvas/util.d.ts +2 -2
- package/dist/phaser/display/canvas/util.d.ts.map +1 -1
- package/dist/phaser/display/display_object.d.ts +14 -12
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- package/dist/phaser/display/graphics.d.ts +8 -5
- package/dist/phaser/display/graphics.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/dist/phaser/display/group.d.ts +4 -3
- package/dist/phaser/display/group.d.ts.map +1 -1
- package/dist/phaser/display/image.d.ts +13 -10
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_batch.d.ts +3 -2
- package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts +18 -15
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- package/dist/phaser/display/text.d.ts +11 -9
- package/dist/phaser/display/text.d.ts.map +1 -1
- package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +7 -6
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +16 -11
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
- package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
- package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
- package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +3 -2
- package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/dist/phaser/display/webgl/util.d.ts.map +1 -1
- package/dist/phaser/geom/circle.d.ts +4 -1
- package/dist/phaser/geom/circle.d.ts.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/point.d.ts.map +1 -1
- package/dist/phaser/geom/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/circle.d.ts.map +1 -1
- package/dist/phaser/geom/util/ellipse.d.ts +3 -2
- package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- package/dist/phaser/geom/util/matrix.d.ts +2 -2
- package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
- package/dist/phaser/geom/util/point.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/util/math.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/phaser/core/animation.ts +64 -60
- package/src/phaser/core/animation_manager.ts +50 -53
- package/src/phaser/core/animation_parser.ts +9 -9
- package/src/phaser/core/array_set.ts +16 -17
- package/src/phaser/core/cache.ts +92 -93
- package/src/phaser/core/const.ts +1 -1
- package/src/phaser/core/device.ts +24 -29
- package/src/phaser/core/device_util.ts +22 -26
- package/src/phaser/core/dom.ts +54 -65
- package/src/phaser/core/event_manager.ts +64 -94
- package/src/phaser/core/factory.ts +14 -14
- package/src/phaser/core/frame.ts +28 -28
- package/src/phaser/core/frame_data.test.ts +100 -0
- package/src/phaser/core/frame_data.ts +24 -24
- package/src/phaser/core/frame_util.ts +2 -2
- package/src/phaser/core/game.ts +47 -48
- package/src/phaser/core/input.ts +104 -110
- package/src/phaser/core/input_handler.test.ts +113 -0
- package/src/phaser/core/input_handler.ts +199 -218
- package/src/phaser/core/input_mouse.ts +71 -54
- package/src/phaser/core/input_mspointer.ts +52 -39
- package/src/phaser/core/input_pointer.ts +81 -80
- package/src/phaser/core/input_touch.ts +49 -36
- package/src/phaser/core/loader.ts +173 -152
- package/src/phaser/core/loader_parser.ts +39 -57
- package/src/phaser/core/raf.ts +8 -7
- package/src/phaser/core/registry.test.ts +31 -0
- package/src/phaser/core/registry.ts +9 -0
- package/src/phaser/core/scale_manager.ts +156 -152
- package/src/phaser/core/scene.ts +9 -13
- package/src/phaser/core/scene_manager.ts +47 -47
- package/src/phaser/core/signal.test.ts +4 -4
- package/src/phaser/core/signal.ts +41 -52
- package/src/phaser/core/signal_binding.ts +26 -25
- package/src/phaser/core/signal_dispatch.test.ts +180 -0
- package/src/phaser/core/sound.ts +75 -83
- package/src/phaser/core/sound_manager.ts +52 -51
- package/src/phaser/core/sound_sprite.ts +17 -16
- package/src/phaser/core/stage.ts +25 -24
- package/src/phaser/core/time.ts +52 -52
- package/src/phaser/core/timer.test.ts +187 -0
- package/src/phaser/core/timer.ts +82 -69
- package/src/phaser/core/timer_event.ts +10 -10
- package/src/phaser/core/tween.ts +90 -93
- package/src/phaser/core/tween_data.ts +45 -51
- package/src/phaser/core/tween_easing.test.ts +106 -0
- package/src/phaser/core/tween_easing.ts +151 -123
- package/src/phaser/core/tween_manager.ts +19 -18
- package/src/phaser/core/world.ts +4 -3
- package/src/phaser/display/bitmap_text.ts +56 -64
- package/src/phaser/display/button.ts +33 -32
- package/src/phaser/display/canvas/buffer.ts +8 -8
- package/src/phaser/display/canvas/graphics.ts +36 -37
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.test.ts +106 -0
- package/src/phaser/display/canvas/pool.ts +25 -27
- package/src/phaser/display/canvas/renderer.ts +32 -31
- package/src/phaser/display/canvas/tinter.ts +25 -25
- package/src/phaser/display/canvas/util.ts +7 -10
- package/src/phaser/display/display_object.ts +114 -118
- package/src/phaser/display/graphics.ts +121 -119
- package/src/phaser/display/graphics_data.ts +12 -12
- package/src/phaser/display/graphics_data_util.ts +2 -3
- package/src/phaser/display/group.ts +50 -57
- package/src/phaser/display/image.ts +55 -52
- package/src/phaser/display/sprite_batch.ts +3 -2
- package/src/phaser/display/sprite_util.ts +48 -54
- package/src/phaser/display/text.ts +199 -204
- package/src/phaser/display/webgl/abstract_filter.ts +9 -9
- package/src/phaser/display/webgl/base_texture.ts +21 -24
- package/src/phaser/display/webgl/blend_manager.ts +6 -10
- package/src/phaser/display/webgl/earcut.ts +73 -37
- package/src/phaser/display/webgl/earcut_node.ts +10 -10
- package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
- package/src/phaser/display/webgl/filter_manager.ts +13 -12
- package/src/phaser/display/webgl/filter_texture.ts +14 -13
- package/src/phaser/display/webgl/graphics.ts +51 -57
- package/src/phaser/display/webgl/graphics_data.ts +15 -14
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +26 -25
- package/src/phaser/display/webgl/renderer.ts +57 -62
- package/src/phaser/display/webgl/shader/complex.ts +28 -12
- package/src/phaser/display/webgl/shader/fast.ts +30 -12
- package/src/phaser/display/webgl/shader/normal.ts +70 -57
- package/src/phaser/display/webgl/shader/primitive.ts +26 -11
- package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
- package/src/phaser/display/webgl/shader/strip.ts +27 -12
- package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
- package/src/phaser/display/webgl/shader_manager.ts +26 -34
- package/src/phaser/display/webgl/sprite_batch.ts +67 -61
- package/src/phaser/display/webgl/stencil_manager.ts +23 -34
- package/src/phaser/display/webgl/texture.ts +43 -50
- package/src/phaser/display/webgl/texture_util.ts +2 -3
- package/src/phaser/display/webgl/util.ts +26 -25
- package/src/phaser/geom/circle.test.ts +2 -3
- package/src/phaser/geom/circle.ts +36 -36
- package/src/phaser/geom/ellipse.test.ts +73 -71
- package/src/phaser/geom/ellipse.ts +14 -14
- package/src/phaser/geom/line.test.ts +5 -5
- package/src/phaser/geom/line.ts +35 -35
- package/src/phaser/geom/matrix.test.ts +1 -1
- package/src/phaser/geom/matrix.ts +27 -27
- package/src/phaser/geom/point.test.ts +1 -2
- package/src/phaser/geom/point.ts +35 -35
- package/src/phaser/geom/polygon.test.ts +82 -0
- package/src/phaser/geom/polygon.ts +16 -16
- package/src/phaser/geom/rectangle.test.ts +14 -14
- package/src/phaser/geom/rectangle.ts +83 -75
- package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
- package/src/phaser/geom/rounded_rectangle.ts +9 -9
- package/src/phaser/geom/util/circle.test.ts +25 -23
- package/src/phaser/geom/util/circle.ts +9 -18
- package/src/phaser/geom/util/ellipse.test.ts +7 -5
- package/src/phaser/geom/util/ellipse.ts +3 -2
- package/src/phaser/geom/util/line.test.ts +10 -8
- package/src/phaser/geom/util/line.ts +6 -16
- package/src/phaser/geom/util/matrix.test.ts +20 -18
- package/src/phaser/geom/util/matrix.ts +8 -15
- package/src/phaser/geom/util/point.test.ts +8 -6
- package/src/phaser/geom/util/point.ts +24 -28
- package/src/phaser/geom/util/polygon.test.ts +12 -10
- package/src/phaser/geom/util/polygon.ts +2 -2
- package/src/phaser/geom/util/rectangle.test.ts +10 -8
- package/src/phaser/geom/util/rectangle.ts +18 -37
- package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
- package/src/phaser/util/math.test.ts +11 -11
- package/src/phaser/util/math.ts +29 -46
|
@@ -3,6 +3,7 @@ import { canPlayAudio } from './device_util.js';
|
|
|
3
3
|
import { ENGINE_ERROR_INVALID_BITMAP_FONT_ATLAS } from './error_code.js';
|
|
4
4
|
import type { Cache } from './cache.js';
|
|
5
5
|
import type { Game } from './game.js';
|
|
6
|
+
import type { Image } from '../display/image.js';
|
|
6
7
|
import { Signal } from './signal.js';
|
|
7
8
|
|
|
8
9
|
const TEXTURE_ATLAS_JSON_HASH = 1;
|
|
@@ -19,39 +20,39 @@ export interface LoaderFile {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export class Loader {
|
|
22
|
-
game!: Game;
|
|
23
|
-
cache!: Cache;
|
|
24
|
-
isLoading!: boolean;
|
|
25
|
-
isUseLog!: boolean;
|
|
26
|
-
isUseRetry!: boolean;
|
|
27
|
-
maxRetry!: number;
|
|
28
|
-
hasLoaded!: boolean;
|
|
29
|
-
preloadSprite!: any;
|
|
30
|
-
crossOrigin!: boolean | string;
|
|
31
|
-
baseURL!: string;
|
|
32
|
-
path!: string;
|
|
33
|
-
headers!: Record<string, string | false>;
|
|
34
|
-
onLoadStart!: Signal;
|
|
35
|
-
onLoadComplete!: Signal;
|
|
36
|
-
onPackComplete!: Signal;
|
|
37
|
-
onFileStart!: Signal;
|
|
38
|
-
onFileComplete!: Signal;
|
|
39
|
-
onFileError!: Signal;
|
|
40
|
-
maxParallelDownloads!: number;
|
|
41
|
-
_withSyncPointDepth!: number;
|
|
42
|
-
_fileList!: any;
|
|
43
|
-
_flightQueue!: any;
|
|
44
|
-
_processingHead!: number;
|
|
45
|
-
_fileLoadStarted!: boolean;
|
|
46
|
-
_totalPackCount!: number;
|
|
47
|
-
_totalFileCount!: number;
|
|
48
|
-
_loadedPackCount!: number;
|
|
49
|
-
_loadedFileCount!: number;
|
|
23
|
+
public game!: Game;
|
|
24
|
+
public cache!: Cache;
|
|
25
|
+
public isLoading!: boolean;
|
|
26
|
+
public isUseLog!: boolean;
|
|
27
|
+
public isUseRetry!: boolean;
|
|
28
|
+
public maxRetry!: number;
|
|
29
|
+
public hasLoaded!: boolean;
|
|
30
|
+
public preloadSprite!: any;
|
|
31
|
+
public crossOrigin!: boolean | string;
|
|
32
|
+
public baseURL!: string;
|
|
33
|
+
public path!: string;
|
|
34
|
+
public headers!: Record<string, string | false>;
|
|
35
|
+
public onLoadStart!: Signal;
|
|
36
|
+
public onLoadComplete!: Signal;
|
|
37
|
+
public onPackComplete!: Signal;
|
|
38
|
+
public onFileStart!: Signal;
|
|
39
|
+
public onFileComplete!: Signal;
|
|
40
|
+
public onFileError!: Signal;
|
|
41
|
+
public maxParallelDownloads!: number;
|
|
42
|
+
public _withSyncPointDepth!: number;
|
|
43
|
+
public _fileList!: any;
|
|
44
|
+
public _flightQueue!: any;
|
|
45
|
+
public _processingHead!: number;
|
|
46
|
+
public _fileLoadStarted!: boolean;
|
|
47
|
+
public _totalPackCount!: number;
|
|
48
|
+
public _totalFileCount!: number;
|
|
49
|
+
public _loadedPackCount!: number;
|
|
50
|
+
public _loadedFileCount!: number;
|
|
50
51
|
/**
|
|
51
52
|
* Creates a new Loader instance.
|
|
52
|
-
* @param {
|
|
53
|
+
* @param {Game} game - Reference to the Phaser Game instance.
|
|
53
54
|
*/
|
|
54
|
-
constructor(game: Game) {
|
|
55
|
+
public constructor(game: Game) {
|
|
55
56
|
this.game = game;
|
|
56
57
|
this.cache = game.cache;
|
|
57
58
|
this.isLoading = false;
|
|
@@ -74,7 +75,7 @@ export class Loader {
|
|
|
74
75
|
this.onFileStart = new Signal();
|
|
75
76
|
this.onFileComplete = new Signal();
|
|
76
77
|
this.onFileError = new Signal();
|
|
77
|
-
this.maxParallelDownloads = this.game.config.maxParallelDownloads
|
|
78
|
+
this.maxParallelDownloads = this.game.config.maxParallelDownloads ?? 16;
|
|
78
79
|
this._withSyncPointDepth = 0;
|
|
79
80
|
this._fileList = [];
|
|
80
81
|
this._flightQueue = [];
|
|
@@ -88,10 +89,10 @@ export class Loader {
|
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
91
|
* Sets the preload sprite for displaying loading progress.
|
|
91
|
-
* @param {
|
|
92
|
+
* @param {Image} sprite - The image to use as the preload sprite.
|
|
92
93
|
* @param {number} direction - The direction of the progress (0 = horizontal, 1 = vertical).
|
|
93
94
|
*/
|
|
94
|
-
setPreloadSprite(sprite:
|
|
95
|
+
public setPreloadSprite(sprite: Image, direction = 0) {
|
|
95
96
|
this.preloadSprite = {
|
|
96
97
|
sprite,
|
|
97
98
|
direction,
|
|
@@ -113,7 +114,7 @@ export class Loader {
|
|
|
113
114
|
/**
|
|
114
115
|
* Resizes the preload sprite when the window is resized.
|
|
115
116
|
*/
|
|
116
|
-
resize() {
|
|
117
|
+
public resize() {
|
|
117
118
|
if (this.preloadSprite && this.preloadSprite.height !== this.preloadSprite.sprite.height) {
|
|
118
119
|
this.preloadSprite.rect.height = this.preloadSprite.sprite.height;
|
|
119
120
|
}
|
|
@@ -125,7 +126,7 @@ export class Loader {
|
|
|
125
126
|
* @param {string} key - The key of the file to check for.
|
|
126
127
|
* @returns {boolean} True if the file exists, false otherwise.
|
|
127
128
|
*/
|
|
128
|
-
checkKeyExists(type: string, key: string) {
|
|
129
|
+
public checkKeyExists(type: string, key: string) {
|
|
129
130
|
return this.getAssetIndex(type, key) > -1;
|
|
130
131
|
}
|
|
131
132
|
|
|
@@ -135,7 +136,7 @@ export class Loader {
|
|
|
135
136
|
* @param {string} key - The key of the file to find.
|
|
136
137
|
* @returns {number} The index of the file in the list, or -1 if not found.
|
|
137
138
|
*/
|
|
138
|
-
getAssetIndex(type: string, key: string) {
|
|
139
|
+
public getAssetIndex(type: string, key: string) {
|
|
139
140
|
let bestFound = -1;
|
|
140
141
|
for (let i = 0; i < this._fileList.length; i += 1) {
|
|
141
142
|
const file = this._fileList[i];
|
|
@@ -157,7 +158,7 @@ export class Loader {
|
|
|
157
158
|
* @param {string} key - The key of the file to get.
|
|
158
159
|
* @returns {{index: number, file: object} | null} The file and its index, or null if not found.
|
|
159
160
|
*/
|
|
160
|
-
getAsset(type: string, key: string) {
|
|
161
|
+
public getAsset(type: string, key: string) {
|
|
161
162
|
const fileIndex = this.getAssetIndex(type, key);
|
|
162
163
|
if (fileIndex > -1) {
|
|
163
164
|
return { index: fileIndex, file: this._fileList[fileIndex] };
|
|
@@ -170,7 +171,7 @@ export class Loader {
|
|
|
170
171
|
* @param {boolean} hard - Whether to perform a hard reset (clears preload sprite).
|
|
171
172
|
* @param {boolean} clearEvents - Whether to clear event listeners.
|
|
172
173
|
*/
|
|
173
|
-
reset(hard
|
|
174
|
+
public reset(hard = false, clearEvents = false) {
|
|
174
175
|
if (hard) {
|
|
175
176
|
this.preloadSprite = null;
|
|
176
177
|
}
|
|
@@ -203,12 +204,12 @@ export class Loader {
|
|
|
203
204
|
* @param {string} extension - The file extension to use if URL is not provided.
|
|
204
205
|
* @returns {Loader} This Loader instance for chaining.
|
|
205
206
|
*/
|
|
206
|
-
addToFileList(
|
|
207
|
+
public addToFileList(
|
|
207
208
|
type: string,
|
|
208
|
-
key
|
|
209
|
+
key = '',
|
|
209
210
|
url: string | null = null,
|
|
210
211
|
properties: any | null = null,
|
|
211
|
-
overwrite
|
|
212
|
+
overwrite = false,
|
|
212
213
|
extension: string | null = null
|
|
213
214
|
) {
|
|
214
215
|
if (key === undefined || key === '') {
|
|
@@ -264,7 +265,7 @@ export class Loader {
|
|
|
264
265
|
* @param {object} properties - The new properties for the file.
|
|
265
266
|
* @returns {Loader} This Loader instance for chaining.
|
|
266
267
|
*/
|
|
267
|
-
replaceInFileList(type: string, key: string, url: string, properties: any) {
|
|
268
|
+
public replaceInFileList(type: string, key: string, url: string, properties: any) {
|
|
268
269
|
return this.addToFileList(type, key, url, properties, true);
|
|
269
270
|
}
|
|
270
271
|
|
|
@@ -276,24 +277,24 @@ export class Loader {
|
|
|
276
277
|
* @param {object} callbackContext - The context in which to call the callback.
|
|
277
278
|
* @returns {Loader} This Loader instance for chaining.
|
|
278
279
|
*/
|
|
279
|
-
pack(key: string, url: string, data: any, callbackContext: any) {
|
|
280
|
+
public pack(key: string, url: string, data: any, callbackContext: any) {
|
|
280
281
|
const pack = {
|
|
281
282
|
type: 'packfile',
|
|
282
|
-
key
|
|
283
|
-
url
|
|
283
|
+
key,
|
|
284
|
+
url,
|
|
284
285
|
path: this.path,
|
|
285
286
|
syncPoint: true,
|
|
286
287
|
data: null as unknown,
|
|
287
288
|
loading: false,
|
|
288
289
|
loaded: false,
|
|
289
290
|
error: false,
|
|
290
|
-
callbackContext
|
|
291
|
+
callbackContext,
|
|
291
292
|
};
|
|
292
293
|
if (data) {
|
|
293
294
|
if (typeof data === 'string') {
|
|
294
295
|
data = JSON.parse(data);
|
|
295
296
|
}
|
|
296
|
-
pack.data = data
|
|
297
|
+
pack.data = data ?? {};
|
|
297
298
|
pack.loaded = true;
|
|
298
299
|
}
|
|
299
300
|
for (let i = 0; i < this._fileList.length + 1; i += 1) {
|
|
@@ -314,7 +315,7 @@ export class Loader {
|
|
|
314
315
|
* @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
|
|
315
316
|
* @returns {Loader} This Loader instance for chaining.
|
|
316
317
|
*/
|
|
317
|
-
image(key: string, url?: any, overwrite
|
|
318
|
+
public image(key: string, url?: any, overwrite = false) {
|
|
318
319
|
return this.addToFileList('image', key, url, undefined, overwrite, '.png');
|
|
319
320
|
}
|
|
320
321
|
|
|
@@ -324,14 +325,14 @@ export class Loader {
|
|
|
324
325
|
* @param {string[]} urls - The URLs of the image files to load.
|
|
325
326
|
* @returns {Loader} This Loader instance for chaining.
|
|
326
327
|
*/
|
|
327
|
-
images(keys: string[], urls: string[]) {
|
|
328
|
+
public images(keys: string[], urls: string[]) {
|
|
328
329
|
if (Array.isArray(urls)) {
|
|
329
330
|
for (let i = 0; i < keys.length; i += 1) {
|
|
330
|
-
this.image(keys[i]
|
|
331
|
+
this.image(keys[i]!, urls[i]);
|
|
331
332
|
}
|
|
332
333
|
} else {
|
|
333
|
-
for (
|
|
334
|
-
this.image(
|
|
334
|
+
for (const key of keys) {
|
|
335
|
+
this.image(key);
|
|
335
336
|
}
|
|
336
337
|
}
|
|
337
338
|
return this;
|
|
@@ -344,7 +345,7 @@ export class Loader {
|
|
|
344
345
|
* @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
|
|
345
346
|
* @returns {Loader} This Loader instance for chaining.
|
|
346
347
|
*/
|
|
347
|
-
text(key: string, url: string, overwrite
|
|
348
|
+
public text(key: string, url: string, overwrite = false) {
|
|
348
349
|
return this.addToFileList('text', key, url, undefined, overwrite, '.txt');
|
|
349
350
|
}
|
|
350
351
|
|
|
@@ -355,7 +356,7 @@ export class Loader {
|
|
|
355
356
|
* @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
|
|
356
357
|
* @returns {Loader} This Loader instance for chaining.
|
|
357
358
|
*/
|
|
358
|
-
json(key: string, url: string, overwrite
|
|
359
|
+
public json(key: string, url: string, overwrite = false) {
|
|
359
360
|
return this.addToFileList('json', key, url, undefined, overwrite, '.json');
|
|
360
361
|
}
|
|
361
362
|
|
|
@@ -366,7 +367,7 @@ export class Loader {
|
|
|
366
367
|
* @param {boolean} overwrite - Whether to overwrite an existing file with the same key.
|
|
367
368
|
* @returns {Loader} This Loader instance for chaining.
|
|
368
369
|
*/
|
|
369
|
-
xml(key: string, url: string, overwrite
|
|
370
|
+
public xml(key: string, url: string, overwrite = false) {
|
|
370
371
|
return this.addToFileList('xml', key, url, undefined, overwrite, '.xml');
|
|
371
372
|
}
|
|
372
373
|
|
|
@@ -381,14 +382,14 @@ export class Loader {
|
|
|
381
382
|
* @param {number} spacing - The spacing between frames in pixels.
|
|
382
383
|
* @returns {Loader} This Loader instance for chaining.
|
|
383
384
|
*/
|
|
384
|
-
spritesheet(
|
|
385
|
+
public spritesheet(
|
|
385
386
|
key: string,
|
|
386
387
|
url: string,
|
|
387
388
|
frameWidth: number,
|
|
388
389
|
frameHeight: number,
|
|
389
|
-
frameMax
|
|
390
|
-
margin
|
|
391
|
-
spacing
|
|
390
|
+
frameMax = -1,
|
|
391
|
+
margin = 0,
|
|
392
|
+
spacing = 0
|
|
392
393
|
) {
|
|
393
394
|
return this.addToFileList(
|
|
394
395
|
'spritesheet',
|
|
@@ -407,7 +408,7 @@ export class Loader {
|
|
|
407
408
|
* @param {boolean} autoDecode - Whether to automatically decode the audio file.
|
|
408
409
|
* @returns {Loader} This Loader instance for chaining.
|
|
409
410
|
*/
|
|
410
|
-
audio(key: string, urls: any, autoDecode
|
|
411
|
+
public audio(key: string, urls: any, autoDecode = true) {
|
|
411
412
|
if (this.game.sound.noAudio || this.game.device.noAudioFormat) {
|
|
412
413
|
return this;
|
|
413
414
|
}
|
|
@@ -426,7 +427,7 @@ export class Loader {
|
|
|
426
427
|
* @param {boolean} autoDecode - Whether to automatically decode the audio file.
|
|
427
428
|
* @returns {Loader} This Loader instance for chaining.
|
|
428
429
|
*/
|
|
429
|
-
audioSprite(key: string, urls: string, jsonURL: string, jsonData: any, autoDecode
|
|
430
|
+
public audioSprite(key: string, urls: string, jsonURL: string, jsonData: any, autoDecode = true) {
|
|
430
431
|
if (this.game.sound.noAudio || this.game.device.noAudioFormat) {
|
|
431
432
|
return this;
|
|
432
433
|
}
|
|
@@ -453,17 +454,15 @@ export class Loader {
|
|
|
453
454
|
* @returns {Loader} This Loader instance for chaining.
|
|
454
455
|
* @throws {Error} If the bitmap font atlas data is invalid.
|
|
455
456
|
*/
|
|
456
|
-
bitmapFont(
|
|
457
|
+
public bitmapFont(
|
|
457
458
|
key: string,
|
|
458
459
|
textureURL: string | null = null,
|
|
459
460
|
atlasURL: string | null = null,
|
|
460
461
|
atlasData: any | null = null,
|
|
461
|
-
xSpacing
|
|
462
|
-
ySpacing
|
|
462
|
+
xSpacing = 0,
|
|
463
|
+
ySpacing = 0
|
|
463
464
|
) {
|
|
464
|
-
|
|
465
|
-
textureURL = `${key}.png`;
|
|
466
|
-
}
|
|
465
|
+
textureURL ??= `${key}.png`;
|
|
467
466
|
if (atlasURL === null && atlasData === null) {
|
|
468
467
|
atlasURL = `${key}.xml`;
|
|
469
468
|
}
|
|
@@ -476,7 +475,7 @@ export class Loader {
|
|
|
476
475
|
let xml = null;
|
|
477
476
|
try {
|
|
478
477
|
json = JSON.parse(atlasData);
|
|
479
|
-
} catch
|
|
478
|
+
} catch {
|
|
480
479
|
xml = this.parseXml(atlasData);
|
|
481
480
|
}
|
|
482
481
|
if (!xml && !json) {
|
|
@@ -484,7 +483,7 @@ export class Loader {
|
|
|
484
483
|
}
|
|
485
484
|
this.addToFileList('bitmapfont', key, textureURL, {
|
|
486
485
|
atlasURL: null,
|
|
487
|
-
atlasData: json
|
|
486
|
+
atlasData: json ?? xml,
|
|
488
487
|
atlasType: json ? 'json' : 'xml',
|
|
489
488
|
xSpacing,
|
|
490
489
|
ySpacing,
|
|
@@ -502,16 +501,14 @@ export class Loader {
|
|
|
502
501
|
* @param {number} format - The format of the atlas file (JSON or XML).
|
|
503
502
|
* @returns {Loader} This Loader instance for chaining.
|
|
504
503
|
*/
|
|
505
|
-
atlas(
|
|
504
|
+
public atlas(
|
|
506
505
|
key: string,
|
|
507
506
|
textureURL: string,
|
|
508
507
|
atlasURL: string | null = null,
|
|
509
508
|
atlasData: any | null = null,
|
|
510
509
|
format: number = TEXTURE_ATLAS_JSON_HASH
|
|
511
510
|
) {
|
|
512
|
-
|
|
513
|
-
textureURL = `${key}.png`;
|
|
514
|
-
}
|
|
511
|
+
textureURL ??= `${key}.png`;
|
|
515
512
|
if (!atlasURL && !atlasData) {
|
|
516
513
|
atlasURL = `${key}.json`;
|
|
517
514
|
}
|
|
@@ -530,10 +527,10 @@ export class Loader {
|
|
|
530
527
|
* @param {object} callbackContext - The context in which to call the callback.
|
|
531
528
|
* @returns {Loader} This Loader instance for chaining.
|
|
532
529
|
*/
|
|
533
|
-
withSyncPoint(callback: Function, callbackContext: any) {
|
|
530
|
+
public withSyncPoint(callback: Function, callbackContext: any) {
|
|
534
531
|
this._withSyncPointDepth += 1;
|
|
535
532
|
try {
|
|
536
|
-
callback.call(callbackContext
|
|
533
|
+
callback.call(callbackContext ?? this, this);
|
|
537
534
|
} finally {
|
|
538
535
|
this._withSyncPointDepth -= 1;
|
|
539
536
|
}
|
|
@@ -546,7 +543,7 @@ export class Loader {
|
|
|
546
543
|
* @param {string} key - The key of the file to add a sync point to.
|
|
547
544
|
* @returns {Loader} This Loader instance for chaining.
|
|
548
545
|
*/
|
|
549
|
-
addSyncPoint(type: string, key: string) {
|
|
546
|
+
public addSyncPoint(type: string, key: string) {
|
|
550
547
|
const asset = this.getAsset(type, key);
|
|
551
548
|
if (asset) {
|
|
552
549
|
asset.file.syncPoint = true;
|
|
@@ -559,7 +556,7 @@ export class Loader {
|
|
|
559
556
|
* @param {string} type - The type of file to remove.
|
|
560
557
|
* @param {string} key - The key of the file to remove.
|
|
561
558
|
*/
|
|
562
|
-
removeFile(type: string, key: string) {
|
|
559
|
+
public removeFile(type: string, key: string) {
|
|
563
560
|
const asset = this.getAsset(type, key);
|
|
564
561
|
if (asset) {
|
|
565
562
|
if (!asset.file.loaded && !asset.file.loading) {
|
|
@@ -571,7 +568,7 @@ export class Loader {
|
|
|
571
568
|
/**
|
|
572
569
|
* Removes all files from the file list.
|
|
573
570
|
*/
|
|
574
|
-
removeAll() {
|
|
571
|
+
public removeAll() {
|
|
575
572
|
this._fileList.length = 0;
|
|
576
573
|
this._flightQueue.length = 0;
|
|
577
574
|
}
|
|
@@ -579,7 +576,7 @@ export class Loader {
|
|
|
579
576
|
/**
|
|
580
577
|
* Starts the loading process for all queued files.
|
|
581
578
|
*/
|
|
582
|
-
start() {
|
|
579
|
+
public start() {
|
|
583
580
|
if (this.isLoading) {
|
|
584
581
|
return;
|
|
585
582
|
}
|
|
@@ -592,7 +589,7 @@ export class Loader {
|
|
|
592
589
|
/**
|
|
593
590
|
* Processes the loading queue, loading files as appropriate.
|
|
594
591
|
*/
|
|
595
|
-
processLoadQueue() {
|
|
592
|
+
public processLoadQueue() {
|
|
596
593
|
if (!this.isLoading) {
|
|
597
594
|
this.game.logger.warn('Active loading canceled / reset');
|
|
598
595
|
this.finishedLoading(true);
|
|
@@ -676,7 +673,7 @@ export class Loader {
|
|
|
676
673
|
// (There should be no inflight items as they are complete - loaded/error.)
|
|
677
674
|
if (this._processingHead >= this._fileList.length) {
|
|
678
675
|
this.finishedLoading();
|
|
679
|
-
} else if (
|
|
676
|
+
} else if (this._flightQueue.length === 0) {
|
|
680
677
|
// Flight queue is empty but file list is not done being processed.
|
|
681
678
|
// This indicates a critical internal error with no known recovery.
|
|
682
679
|
this.game.logger.warn('Aborting: processing queue empty, loading may have stalled');
|
|
@@ -691,7 +688,7 @@ export class Loader {
|
|
|
691
688
|
* Finishes the loading process, optionally reporting an abnormal termination.
|
|
692
689
|
* @param {boolean} abnormal - Whether the loading was terminated abnormally.
|
|
693
690
|
*/
|
|
694
|
-
finishedLoading(abnormal
|
|
691
|
+
public finishedLoading(abnormal = false) {
|
|
695
692
|
if (this.hasLoaded) {
|
|
696
693
|
return;
|
|
697
694
|
}
|
|
@@ -715,9 +712,9 @@ export class Loader {
|
|
|
715
712
|
* @param {object} file - The file to complete or mark as failed.
|
|
716
713
|
* @param {string} errorMessage - An error message if the file failed to load.
|
|
717
714
|
*/
|
|
718
|
-
asyncComplete(file: any, errorMessage
|
|
715
|
+
public asyncComplete(file: any, errorMessage = '') {
|
|
719
716
|
file.loaded = true;
|
|
720
|
-
file.error =
|
|
717
|
+
file.error = Boolean(errorMessage);
|
|
721
718
|
if (file.error) {
|
|
722
719
|
file.errorMessage = errorMessage;
|
|
723
720
|
this.game.logger.warn('Error loading file', file);
|
|
@@ -730,29 +727,32 @@ export class Loader {
|
|
|
730
727
|
* Processes a pack file, adding its contained files to the loader.
|
|
731
728
|
* @param {object} pack - The pack file object to process.
|
|
732
729
|
*/
|
|
733
|
-
processPack(pack: any) {
|
|
730
|
+
public processPack(pack: any) {
|
|
734
731
|
const packData = pack.data[pack.key];
|
|
735
732
|
if (!packData) {
|
|
736
733
|
this.game.logger.warn('Missing loader pack key', { key: pack.key });
|
|
737
734
|
return;
|
|
738
735
|
}
|
|
739
736
|
const packDataCompat = Array.isArray(packData) ? packData : packData.files;
|
|
740
|
-
for (
|
|
741
|
-
const file = packDataCompat[i];
|
|
737
|
+
for (const file of packDataCompat) {
|
|
742
738
|
switch (file.type) {
|
|
743
|
-
case 'image':
|
|
739
|
+
case 'image': {
|
|
744
740
|
this.image(file.key, file.url, file.overwrite);
|
|
745
741
|
break;
|
|
746
|
-
|
|
742
|
+
}
|
|
743
|
+
case 'text': {
|
|
747
744
|
this.text(file.key, file.url, file.overwrite);
|
|
748
745
|
break;
|
|
749
|
-
|
|
746
|
+
}
|
|
747
|
+
case 'json': {
|
|
750
748
|
this.json(file.key, file.url, file.overwrite);
|
|
751
749
|
break;
|
|
752
|
-
|
|
750
|
+
}
|
|
751
|
+
case 'xml': {
|
|
753
752
|
this.xml(file.key, file.url, file.overwrite);
|
|
754
753
|
break;
|
|
755
|
-
|
|
754
|
+
}
|
|
755
|
+
case 'spritesheet': {
|
|
756
756
|
this.spritesheet(
|
|
757
757
|
file.key,
|
|
758
758
|
file.url,
|
|
@@ -763,28 +763,34 @@ export class Loader {
|
|
|
763
763
|
file.spacing
|
|
764
764
|
);
|
|
765
765
|
break;
|
|
766
|
-
|
|
767
|
-
|
|
766
|
+
}
|
|
767
|
+
case 'audio': {
|
|
768
|
+
this.audio(file.key, file.urls ?? file.url);
|
|
768
769
|
break;
|
|
769
|
-
|
|
770
|
-
|
|
770
|
+
}
|
|
771
|
+
case 'audiosprite': {
|
|
772
|
+
this.audioSprite(file.key, file.urls ?? file.url, file.jsonURL, file.jsonData);
|
|
771
773
|
break;
|
|
772
|
-
|
|
774
|
+
}
|
|
775
|
+
case 'audioSprite': {
|
|
773
776
|
this.audioSprite(file.key, file.audioURL, file.jsonURL, file.jsonData);
|
|
774
777
|
break;
|
|
775
|
-
|
|
778
|
+
}
|
|
779
|
+
case 'bitmapFont': {
|
|
776
780
|
this.bitmapFont(
|
|
777
781
|
file.key,
|
|
778
782
|
file.textureURL,
|
|
779
|
-
file.fontDataURL
|
|
783
|
+
file.fontDataURL ?? file.atlasURL,
|
|
780
784
|
file.atlasData,
|
|
781
785
|
file.xSpacing,
|
|
782
786
|
file.ySpacing
|
|
783
787
|
);
|
|
784
788
|
break;
|
|
785
|
-
|
|
789
|
+
}
|
|
790
|
+
case 'atlas': {
|
|
786
791
|
this.atlas(file.key, file.textureURL, file.atlasURL, file.atlasData, TEXTURE_ATLAS_JSON_HASH);
|
|
787
792
|
break;
|
|
793
|
+
}
|
|
788
794
|
}
|
|
789
795
|
}
|
|
790
796
|
}
|
|
@@ -795,11 +801,11 @@ export class Loader {
|
|
|
795
801
|
* @param {object} file - The file object containing path information.
|
|
796
802
|
* @returns {string} The transformed URL.
|
|
797
803
|
*/
|
|
798
|
-
transformUrl(url: any, file: any): any {
|
|
804
|
+
public transformUrl(url: any, file: any): any {
|
|
799
805
|
if (!url) {
|
|
800
806
|
return false;
|
|
801
807
|
}
|
|
802
|
-
if (
|
|
808
|
+
if (/^(?:blob:|data:|http:\/\/|https:\/\/|\/\/)/.test(url)) {
|
|
803
809
|
return url;
|
|
804
810
|
}
|
|
805
811
|
return this.baseURL + file.path + url;
|
|
@@ -809,18 +815,20 @@ export class Loader {
|
|
|
809
815
|
* Loads a file using XMLHttpRequest, handling image files specially.
|
|
810
816
|
* @param {object} file - The file object to load.
|
|
811
817
|
*/
|
|
812
|
-
loadFile(file: any) {
|
|
818
|
+
public loadFile(file: any) {
|
|
813
819
|
switch (file.type) {
|
|
814
|
-
case 'packfile':
|
|
820
|
+
case 'packfile': {
|
|
815
821
|
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.fileComplete);
|
|
816
822
|
break;
|
|
823
|
+
}
|
|
817
824
|
case 'image':
|
|
818
825
|
case 'spritesheet':
|
|
819
826
|
case 'textureatlas':
|
|
820
|
-
case 'bitmapfont':
|
|
827
|
+
case 'bitmapfont': {
|
|
821
828
|
this.loadImageTag(file);
|
|
822
829
|
break;
|
|
823
|
-
|
|
830
|
+
}
|
|
831
|
+
case 'audio': {
|
|
824
832
|
file.url = this.getAudioURL(file.url);
|
|
825
833
|
if (file.url) {
|
|
826
834
|
this.xhrLoad(file, this.transformUrl(file.url, file), 'arraybuffer', this.fileComplete);
|
|
@@ -832,18 +840,23 @@ export class Loader {
|
|
|
832
840
|
this.fileError(file, null, 'No supported audio URL specified');
|
|
833
841
|
}
|
|
834
842
|
break;
|
|
835
|
-
|
|
843
|
+
}
|
|
844
|
+
case 'json': {
|
|
836
845
|
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.jsonLoadComplete);
|
|
837
846
|
break;
|
|
838
|
-
|
|
847
|
+
}
|
|
848
|
+
case 'xml': {
|
|
839
849
|
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.xmlLoadComplete);
|
|
840
850
|
break;
|
|
841
|
-
|
|
851
|
+
}
|
|
852
|
+
case 'text': {
|
|
842
853
|
this.xhrLoad(file, this.transformUrl(file.url, file), 'text', this.fileComplete);
|
|
843
854
|
break;
|
|
844
|
-
|
|
855
|
+
}
|
|
856
|
+
default: {
|
|
845
857
|
// pass
|
|
846
858
|
break;
|
|
859
|
+
}
|
|
847
860
|
}
|
|
848
861
|
}
|
|
849
862
|
|
|
@@ -851,10 +864,10 @@ export class Loader {
|
|
|
851
864
|
* Loads an image file using the Image DOM element.
|
|
852
865
|
* @param {object} file - The file object to load.
|
|
853
866
|
*/
|
|
854
|
-
loadImageTag(file: any) {
|
|
867
|
+
public loadImageTag(file: any) {
|
|
855
868
|
this.log('loadImageTag', file);
|
|
856
869
|
const scope = this;
|
|
857
|
-
file.data = new Image();
|
|
870
|
+
file.data = new globalThis.Image();
|
|
858
871
|
file.data.name = file.key;
|
|
859
872
|
if (this.crossOrigin) {
|
|
860
873
|
file.data.crossOrigin = this.crossOrigin;
|
|
@@ -889,20 +902,21 @@ export class Loader {
|
|
|
889
902
|
* @param {Function} onload - The function to call when the file loads successfully.
|
|
890
903
|
* @param {Function} onerror - The function to call if the file fails to load.
|
|
891
904
|
*/
|
|
892
|
-
xhrLoad(file: any, url: any, type: any, onload: Function, onerror: Function | null = null) {
|
|
905
|
+
public xhrLoad(file: any, url: any, type: any, onload: Function, onerror: Function | null = null) {
|
|
893
906
|
this.log('xhrLoad', file);
|
|
894
907
|
const scope = this;
|
|
895
908
|
const xhr = new XMLHttpRequest();
|
|
896
909
|
xhr.open('GET', url, true);
|
|
897
910
|
xhr.responseType = type;
|
|
898
|
-
|
|
899
|
-
|
|
911
|
+
const { requestedWith } = this.headers;
|
|
912
|
+
if (requestedWith !== false && requestedWith !== undefined) {
|
|
913
|
+
xhr.setRequestHeader('X-Requested-With', requestedWith);
|
|
900
914
|
}
|
|
901
915
|
const acceptHeader = this.headers[file.type];
|
|
902
916
|
if (acceptHeader) {
|
|
903
917
|
xhr.setRequestHeader('Accept', acceptHeader);
|
|
904
918
|
}
|
|
905
|
-
onerror = onerror
|
|
919
|
+
onerror = onerror ?? this.fileError;
|
|
906
920
|
xhr.onload = () => {
|
|
907
921
|
try {
|
|
908
922
|
if (xhr.readyState === 4 && xhr.status >= 400 && xhr.status <= 599) {
|
|
@@ -913,9 +927,8 @@ export class Loader {
|
|
|
913
927
|
scope.xhrLoad(file, url, type, onload, onerror);
|
|
914
928
|
}, 1000);
|
|
915
929
|
return null;
|
|
916
|
-
} else {
|
|
917
|
-
return onerror.call(scope, file, xhr);
|
|
918
930
|
}
|
|
931
|
+
return onerror.call(scope, file, xhr);
|
|
919
932
|
}
|
|
920
933
|
return onload.call(scope, file, xhr);
|
|
921
934
|
} catch (error) {
|
|
@@ -958,7 +971,7 @@ export class Loader {
|
|
|
958
971
|
/**
|
|
959
972
|
* Placeholder for XDomainRequest loading (not implemented).
|
|
960
973
|
*/
|
|
961
|
-
xhrLoadWithXDR() {
|
|
974
|
+
public xhrLoadWithXDR() {
|
|
962
975
|
// TODO
|
|
963
976
|
this.game.logger.warn('loader.xhrLoadWithXDR() is not implemented');
|
|
964
977
|
}
|
|
@@ -968,7 +981,7 @@ export class Loader {
|
|
|
968
981
|
* @param {object[]} urls - The array of URLs to check for supported audio formats.
|
|
969
982
|
* @returns {string} The first URL with a supported audio format, or null if none found.
|
|
970
983
|
*/
|
|
971
|
-
getAudioURL(urls: any[]) {
|
|
984
|
+
public getAudioURL(urls: any[]) {
|
|
972
985
|
if (this.game.sound.noAudio || this.game.device.noAudioFormat) {
|
|
973
986
|
return null;
|
|
974
987
|
}
|
|
@@ -987,11 +1000,11 @@ export class Loader {
|
|
|
987
1000
|
if (url.indexOf('blob:') === 0 || url.indexOf('data:') === 0) {
|
|
988
1001
|
return url;
|
|
989
1002
|
}
|
|
990
|
-
if (url.
|
|
1003
|
+
if (url.includes('?')) {
|
|
991
1004
|
// Remove query from URL
|
|
992
1005
|
url = url.substr(0, url.indexOf('?'));
|
|
993
1006
|
}
|
|
994
|
-
const extension = url.
|
|
1007
|
+
const extension = url.slice((Math.max(0, url.lastIndexOf('.')) || Infinity) + 1);
|
|
995
1008
|
audioType = extension.toLowerCase();
|
|
996
1009
|
if (canPlayAudio(this.game.device, audioType)) {
|
|
997
1010
|
return urls[i];
|
|
@@ -1009,7 +1022,7 @@ export class Loader {
|
|
|
1009
1022
|
* @param {XMLHttpRequest} xhr - The XMLHttpRequest object that failed.
|
|
1010
1023
|
* @param {number | string} reason - The error code or message explaining the failure.
|
|
1011
1024
|
*/
|
|
1012
|
-
fileError(file: any, xhr: any | null = null, reason: any = 0) {
|
|
1025
|
+
public fileError(file: any, xhr: any | null = null, reason: any = 0) {
|
|
1013
1026
|
// const url = file.requestUrl || this.transformUrl(file.url, file);
|
|
1014
1027
|
if (!reason && xhr) {
|
|
1015
1028
|
reason = xhr.status;
|
|
@@ -1024,17 +1037,19 @@ export class Loader {
|
|
|
1024
1037
|
* @param {XMLHttpRequest} xhr - TBD.
|
|
1025
1038
|
* @throws {Error}
|
|
1026
1039
|
*/
|
|
1027
|
-
fileComplete(file: any, xhr?: any) {
|
|
1040
|
+
public fileComplete(file: any, xhr?: any) {
|
|
1028
1041
|
let loadNext = true;
|
|
1029
1042
|
switch (file.type) {
|
|
1030
|
-
case 'packfile':
|
|
1043
|
+
case 'packfile': {
|
|
1031
1044
|
// Pack data must never be false-ish after it is fetched without error
|
|
1032
|
-
file.data = JSON.parse(xhr.responseText)
|
|
1045
|
+
file.data = JSON.parse(xhr.responseText) ?? {};
|
|
1033
1046
|
break;
|
|
1034
|
-
|
|
1047
|
+
}
|
|
1048
|
+
case 'image': {
|
|
1035
1049
|
this.cache.addImage(file.key, file.url, file.data);
|
|
1036
1050
|
break;
|
|
1037
|
-
|
|
1051
|
+
}
|
|
1052
|
+
case 'spritesheet': {
|
|
1038
1053
|
this.cache.addSpriteSheet(
|
|
1039
1054
|
file.key,
|
|
1040
1055
|
file.url,
|
|
@@ -1046,7 +1061,8 @@ export class Loader {
|
|
|
1046
1061
|
file.spacing
|
|
1047
1062
|
);
|
|
1048
1063
|
break;
|
|
1049
|
-
|
|
1064
|
+
}
|
|
1065
|
+
case 'textureatlas': {
|
|
1050
1066
|
if (file.atlasURL == null) {
|
|
1051
1067
|
this.cache.addTextureAtlas(file.key, file.url, file.data, file.atlasData);
|
|
1052
1068
|
} else {
|
|
@@ -1058,7 +1074,8 @@ export class Loader {
|
|
|
1058
1074
|
}
|
|
1059
1075
|
}
|
|
1060
1076
|
break;
|
|
1061
|
-
|
|
1077
|
+
}
|
|
1078
|
+
case 'bitmapfont': {
|
|
1062
1079
|
if (!file.atlasURL) {
|
|
1063
1080
|
this.cache.addBitmapFont(
|
|
1064
1081
|
file.key,
|
|
@@ -1081,34 +1098,38 @@ export class Loader {
|
|
|
1081
1098
|
try {
|
|
1082
1099
|
// Try to parse as JSON, if it fails, then it's hopefully XML
|
|
1083
1100
|
json = JSON.parse(bitmapFontXhr.responseText);
|
|
1084
|
-
} catch
|
|
1101
|
+
} catch {
|
|
1085
1102
|
// pass
|
|
1086
1103
|
}
|
|
1087
1104
|
if (json) {
|
|
1088
|
-
bitmapFontFile
|
|
1105
|
+
bitmapFontFile['atlasType'] = 'json';
|
|
1089
1106
|
this.jsonLoadComplete(bitmapFontFile, bitmapFontXhr);
|
|
1090
1107
|
} else {
|
|
1091
|
-
bitmapFontFile
|
|
1108
|
+
bitmapFontFile['atlasType'] = 'xml';
|
|
1092
1109
|
this.xmlLoadComplete(bitmapFontFile, bitmapFontXhr);
|
|
1093
1110
|
}
|
|
1094
1111
|
}
|
|
1095
1112
|
);
|
|
1096
1113
|
}
|
|
1097
1114
|
break;
|
|
1098
|
-
|
|
1115
|
+
}
|
|
1116
|
+
case 'audio': {
|
|
1099
1117
|
file.data = xhr.response;
|
|
1100
1118
|
this.cache.addSound(file.key, file.url, file.data);
|
|
1101
1119
|
if (file.autoDecode) {
|
|
1102
1120
|
this.game.sound.decode(file.key);
|
|
1103
1121
|
}
|
|
1104
1122
|
break;
|
|
1105
|
-
|
|
1123
|
+
}
|
|
1124
|
+
case 'text': {
|
|
1106
1125
|
file.data = xhr.responseText;
|
|
1107
1126
|
this.cache.addText(file.key, file.url, file.data);
|
|
1108
1127
|
break;
|
|
1109
|
-
|
|
1128
|
+
}
|
|
1129
|
+
default: {
|
|
1110
1130
|
// pass
|
|
1111
1131
|
break;
|
|
1132
|
+
}
|
|
1112
1133
|
}
|
|
1113
1134
|
if (loadNext) {
|
|
1114
1135
|
this.asyncComplete(file);
|
|
@@ -1120,7 +1141,7 @@ export class Loader {
|
|
|
1120
1141
|
* @param {object} file - The file object that was loaded successfully.
|
|
1121
1142
|
* @param {XMLHttpRequest} xhr - The XMLHttpRequest object containing the file data.
|
|
1122
1143
|
*/
|
|
1123
|
-
jsonLoadComplete(file: any, xhr: XMLHttpRequest) {
|
|
1144
|
+
public jsonLoadComplete(file: any, xhr: XMLHttpRequest) {
|
|
1124
1145
|
const data = JSON.parse(xhr.responseText);
|
|
1125
1146
|
if (file.type === 'bitmapfont') {
|
|
1126
1147
|
this.cache.addBitmapFont(file.key, file.url, file.data, data, file.atlasType, file.xSpacing, file.ySpacing);
|
|
@@ -1135,7 +1156,7 @@ export class Loader {
|
|
|
1135
1156
|
/**
|
|
1136
1157
|
* TBD.
|
|
1137
1158
|
*/
|
|
1138
|
-
csvLoadComplete() {
|
|
1159
|
+
public csvLoadComplete() {
|
|
1139
1160
|
// TODO
|
|
1140
1161
|
this.game.logger.warn('loader.csvLoadComplete() is not implemented');
|
|
1141
1162
|
}
|
|
@@ -1145,7 +1166,7 @@ export class Loader {
|
|
|
1145
1166
|
* @param {object} file - The file object containing the JSON data.
|
|
1146
1167
|
* @param {XMLHttpRequest} xhr - The XMLHttpRequest object containing the file data.
|
|
1147
1168
|
*/
|
|
1148
|
-
xmlLoadComplete(file: any, xhr: XMLHttpRequest) {
|
|
1169
|
+
public xmlLoadComplete(file: any, xhr: XMLHttpRequest) {
|
|
1149
1170
|
// Always try parsing the content as XML, regardless of actually response type
|
|
1150
1171
|
const data = xhr.responseText;
|
|
1151
1172
|
const xml = this.parseXml(data);
|
|
@@ -1170,22 +1191,22 @@ export class Loader {
|
|
|
1170
1191
|
* @param {object} data - The XML string data to parse.
|
|
1171
1192
|
* @returns {Document} The parsed DOM Document, or null if parsing failed.
|
|
1172
1193
|
*/
|
|
1173
|
-
parseXml(data: any) {
|
|
1194
|
+
public parseXml(data: any) {
|
|
1174
1195
|
let xml = null;
|
|
1175
1196
|
try {
|
|
1176
|
-
if (
|
|
1197
|
+
if (globalThis.DOMParser) {
|
|
1177
1198
|
const domparser = new DOMParser();
|
|
1178
1199
|
xml = domparser.parseFromString(data, 'text/xml');
|
|
1179
1200
|
} else {
|
|
1180
|
-
xml = new
|
|
1201
|
+
xml = new globalThis.ActiveXObject('Microsoft.XMLDOM');
|
|
1181
1202
|
// Why is this 'false'?
|
|
1182
1203
|
xml.async = 'false';
|
|
1183
1204
|
xml.loadXML(data);
|
|
1184
1205
|
}
|
|
1185
|
-
} catch
|
|
1206
|
+
} catch {
|
|
1186
1207
|
xml = null;
|
|
1187
1208
|
}
|
|
1188
|
-
if (!xml || !xml.documentElement || xml.
|
|
1209
|
+
if (!xml || !xml.documentElement || xml.querySelectorAll('parsererror').length > 0) {
|
|
1189
1210
|
return null;
|
|
1190
1211
|
}
|
|
1191
1212
|
return xml;
|
|
@@ -1194,7 +1215,7 @@ export class Loader {
|
|
|
1194
1215
|
/**
|
|
1195
1216
|
* Updates the preload sprite's progress indicator.
|
|
1196
1217
|
*/
|
|
1197
|
-
updateProgress() {
|
|
1218
|
+
public updateProgress() {
|
|
1198
1219
|
if (this.preloadSprite) {
|
|
1199
1220
|
if (this.preloadSprite.direction === 0) {
|
|
1200
1221
|
this.preloadSprite.rect.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
|
|
@@ -1215,7 +1236,7 @@ export class Loader {
|
|
|
1215
1236
|
* @param {string} message - The message to log.
|
|
1216
1237
|
* @param {string|object} data - Additional data to log with the message.
|
|
1217
1238
|
*/
|
|
1218
|
-
log(message: string, data: string | any = '') {
|
|
1239
|
+
public log(message: string, data: string | any = '') {
|
|
1219
1240
|
if (!this.isUseLog) {
|
|
1220
1241
|
return;
|
|
1221
1242
|
}
|
|
@@ -1226,7 +1247,7 @@ export class Loader {
|
|
|
1226
1247
|
* Gets the number of files that have been loaded.
|
|
1227
1248
|
* @returns {number} The total number of loaded files.
|
|
1228
1249
|
*/
|
|
1229
|
-
totalLoadedFiles() {
|
|
1250
|
+
public totalLoadedFiles() {
|
|
1230
1251
|
return this._loadedFileCount;
|
|
1231
1252
|
}
|
|
1232
1253
|
|
|
@@ -1234,7 +1255,7 @@ export class Loader {
|
|
|
1234
1255
|
* Gets the number of files that are still queued for loading.
|
|
1235
1256
|
* @returns {number} The total number of queued files.
|
|
1236
1257
|
*/
|
|
1237
|
-
totalQueuedFiles() {
|
|
1258
|
+
public totalQueuedFiles() {
|
|
1238
1259
|
return this._totalFileCount - this._loadedFileCount;
|
|
1239
1260
|
}
|
|
1240
1261
|
|
|
@@ -1242,7 +1263,7 @@ export class Loader {
|
|
|
1242
1263
|
* Gets the number of pack files that have been loaded.
|
|
1243
1264
|
* @returns {number} The total number of loaded pack files.
|
|
1244
1265
|
*/
|
|
1245
|
-
totalLoadedPacks() {
|
|
1266
|
+
public totalLoadedPacks() {
|
|
1246
1267
|
return this._totalPackCount;
|
|
1247
1268
|
}
|
|
1248
1269
|
|
|
@@ -1250,7 +1271,7 @@ export class Loader {
|
|
|
1250
1271
|
* Gets the number of pack files that are still queued for loading.
|
|
1251
1272
|
* @returns {number} The total number of queued pack files.
|
|
1252
1273
|
*/
|
|
1253
|
-
totalQueuedPacks() {
|
|
1274
|
+
public totalQueuedPacks() {
|
|
1254
1275
|
return this._totalPackCount - this._loadedPackCount;
|
|
1255
1276
|
}
|
|
1256
1277
|
|
|
@@ -1258,7 +1279,7 @@ export class Loader {
|
|
|
1258
1279
|
* Gets the loading progress as a percentage (0-100).
|
|
1259
1280
|
* @returns {number} The current loading progress as a percentage.
|
|
1260
1281
|
*/
|
|
1261
|
-
get progressFloat() {
|
|
1282
|
+
public get progressFloat() {
|
|
1262
1283
|
const progress = (this._loadedFileCount / this._totalFileCount) * 100;
|
|
1263
1284
|
return Math.max(0, Math.min(100, progress || 0));
|
|
1264
1285
|
}
|
|
@@ -1267,7 +1288,7 @@ export class Loader {
|
|
|
1267
1288
|
* Gets the loading progress as a rounded percentage (0-100).
|
|
1268
1289
|
* @returns {number} The current loading progress as a rounded percentage.
|
|
1269
1290
|
*/
|
|
1270
|
-
get progress() {
|
|
1291
|
+
public get progress() {
|
|
1271
1292
|
return Math.round(this.progressFloat);
|
|
1272
1293
|
}
|
|
1273
1294
|
}
|