@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.
- package/dist/index.js +195 -229
- package/dist/index.js.map +1 -1
- package/dist/phaser/core/animation.d.ts.map +1 -1
- package/dist/phaser/core/animation_manager.d.ts +16 -15
- package/dist/phaser/core/animation_manager.d.ts.map +1 -1
- 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 +76 -47
- package/dist/phaser/core/cache.d.ts.map +1 -1
- package/dist/phaser/core/device_util.d.ts.map +1 -1
- package/dist/phaser/core/dom.d.ts.map +1 -1
- package/dist/phaser/core/factory.d.ts.map +1 -1
- package/dist/phaser/core/game.d.ts.map +1 -1
- package/dist/phaser/core/input.d.ts +17 -17
- package/dist/phaser/core/input.d.ts.map +1 -1
- package/dist/phaser/core/input_handler.d.ts +11 -13
- package/dist/phaser/core/input_handler.d.ts.map +1 -1
- package/dist/phaser/core/input_mouse.d.ts.map +1 -1
- package/dist/phaser/core/input_mspointer.d.ts +8 -7
- package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
- package/dist/phaser/core/input_pointer.d.ts +19 -8
- package/dist/phaser/core/input_pointer.d.ts.map +1 -1
- package/dist/phaser/core/input_touch.d.ts.map +1 -1
- package/dist/phaser/core/loader.d.ts +30 -1
- package/dist/phaser/core/loader.d.ts.map +1 -1
- package/dist/phaser/core/loader_parser.d.ts +24 -4
- package/dist/phaser/core/loader_parser.d.ts.map +1 -1
- package/dist/phaser/core/raf.d.ts.map +1 -1
- package/dist/phaser/core/scale_manager.d.ts +37 -12
- package/dist/phaser/core/scale_manager.d.ts.map +1 -1
- package/dist/phaser/core/scene.d.ts.map +1 -1
- package/dist/phaser/core/scene_manager.d.ts.map +1 -1
- package/dist/phaser/core/signal.d.ts.map +1 -1
- package/dist/phaser/core/signal_binding.d.ts.map +1 -1
- package/dist/phaser/core/sound.d.ts +15 -5
- package/dist/phaser/core/sound.d.ts.map +1 -1
- package/dist/phaser/core/sound_manager.d.ts +24 -22
- package/dist/phaser/core/sound_manager.d.ts.map +1 -1
- package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
- package/dist/phaser/core/stage.d.ts.map +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/tween.d.ts +3 -3
- package/dist/phaser/core/tween.d.ts.map +1 -1
- package/dist/phaser/core/tween_data.d.ts +26 -26
- package/dist/phaser/core/tween_data.d.ts.map +1 -1
- package/dist/phaser/core/tween_manager.d.ts +8 -6
- package/dist/phaser/core/tween_manager.d.ts.map +1 -1
- package/dist/phaser/core/world.d.ts.map +1 -1
- package/dist/phaser/display/bitmap_text.d.ts +13 -8
- package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/canvas/masker.d.ts.map +1 -1
- package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/display_object.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/phaser/display/image.d.ts +2 -2
- package/dist/phaser/display/image.d.ts.map +1 -1
- package/dist/phaser/display/sprite_util.d.ts.map +1 -1
- 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 +12 -10
- package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +13 -12
- package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics.d.ts +9 -7
- package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/dist/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/dist/phaser/display/webgl/renderer.d.ts +12 -10
- package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/dist/phaser/display/webgl/texture.d.ts +18 -33
- 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.map +1 -1
- package/dist/phaser/geom/ellipse.d.ts.map +1 -1
- package/dist/phaser/geom/line.d.ts.map +1 -1
- package/dist/phaser/geom/matrix.d.ts +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.map +1 -1
- package/dist/phaser/geom/util/line.d.ts +5 -4
- package/dist/phaser/geom/util/line.d.ts.map +1 -1
- 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/polygon.d.ts.map +1 -1
- package/dist/phaser/geom/util/rectangle.d.ts +10 -1
- package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/dist/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/phaser/core/animation.ts +20 -20
- package/src/phaser/core/animation_manager.ts +27 -24
- package/src/phaser/core/animation_parser.ts +2 -2
- package/src/phaser/core/array_set.ts +7 -7
- package/src/phaser/core/cache.test.ts +201 -0
- package/src/phaser/core/cache.ts +174 -130
- package/src/phaser/core/device_util.ts +13 -13
- package/src/phaser/core/dom.ts +26 -22
- package/src/phaser/core/factory.ts +6 -6
- package/src/phaser/core/game.ts +10 -10
- package/src/phaser/core/input.ts +36 -38
- package/src/phaser/core/input_handler.ts +90 -93
- package/src/phaser/core/input_mouse.ts +19 -19
- package/src/phaser/core/input_mspointer.ts +25 -28
- package/src/phaser/core/input_pointer.ts +37 -28
- package/src/phaser/core/input_touch.ts +17 -17
- package/src/phaser/core/loader.ts +132 -92
- package/src/phaser/core/loader_parser.test.ts +115 -0
- package/src/phaser/core/loader_parser.ts +66 -38
- package/src/phaser/core/raf.ts +3 -3
- package/src/phaser/core/scale_manager.ts +86 -67
- package/src/phaser/core/scene.ts +7 -7
- package/src/phaser/core/scene_manager.ts +16 -16
- package/src/phaser/core/signal.ts +29 -19
- package/src/phaser/core/signal_binding.ts +4 -4
- package/src/phaser/core/sound.ts +45 -33
- package/src/phaser/core/sound_manager.ts +72 -73
- package/src/phaser/core/sound_sprite.ts +1 -1
- package/src/phaser/core/stage.ts +7 -7
- package/src/phaser/core/time.ts +16 -16
- package/src/phaser/core/timer.ts +36 -26
- package/src/phaser/core/tween.ts +29 -29
- package/src/phaser/core/tween_data.ts +41 -37
- package/src/phaser/core/tween_manager.ts +50 -43
- package/src/phaser/core/world.ts +1 -1
- package/src/phaser/display/bitmap_text.test.ts +212 -0
- package/src/phaser/display/bitmap_text.ts +52 -37
- package/src/phaser/display/button.ts +13 -13
- package/src/phaser/display/canvas/buffer.ts +3 -3
- package/src/phaser/display/canvas/graphics.ts +3 -3
- package/src/phaser/display/canvas/masker.ts +2 -2
- package/src/phaser/display/canvas/pool.ts +6 -6
- package/src/phaser/display/canvas/renderer.ts +6 -6
- package/src/phaser/display/canvas/tinter.ts +39 -8
- package/src/phaser/display/canvas/util.ts +15 -9
- package/src/phaser/display/display_object.ts +38 -38
- package/src/phaser/display/graphics.ts +30 -30
- package/src/phaser/display/graphics_data.ts +1 -1
- package/src/phaser/display/graphics_data_util.ts +1 -1
- package/src/phaser/display/group.ts +16 -16
- package/src/phaser/display/image.ts +30 -26
- package/src/phaser/display/sprite_util.ts +12 -4
- package/src/phaser/display/text.ts +55 -55
- package/src/phaser/display/webgl/abstract_filter.ts +1 -1
- package/src/phaser/display/webgl/base_texture.ts +22 -18
- package/src/phaser/display/webgl/blend_manager.ts +3 -3
- package/src/phaser/display/webgl/earcut.ts +3 -3
- package/src/phaser/display/webgl/fast_sprite_batch.ts +26 -24
- package/src/phaser/display/webgl/filter_manager.ts +7 -7
- package/src/phaser/display/webgl/filter_texture.ts +3 -3
- package/src/phaser/display/webgl/graphics.ts +43 -41
- package/src/phaser/display/webgl/graphics_data.ts +2 -2
- package/src/phaser/display/webgl/mask_manager.ts +2 -2
- package/src/phaser/display/webgl/render_texture.ts +6 -6
- package/src/phaser/display/webgl/renderer.ts +20 -25
- package/src/phaser/display/webgl/shader/normal.ts +3 -3
- package/src/phaser/display/webgl/shader_manager.ts +2 -2
- package/src/phaser/display/webgl/sprite_batch.ts +9 -9
- package/src/phaser/display/webgl/stencil_manager.ts +4 -4
- package/src/phaser/display/webgl/texture.ts +23 -42
- package/src/phaser/display/webgl/texture_util.ts +2 -2
- package/src/phaser/display/webgl/util.ts +11 -7
- package/src/phaser/geom/circle.ts +21 -21
- package/src/phaser/geom/ellipse.ts +7 -7
- package/src/phaser/geom/line.ts +29 -29
- package/src/phaser/geom/matrix.ts +13 -13
- package/src/phaser/geom/point.ts +36 -30
- package/src/phaser/geom/polygon.ts +6 -6
- package/src/phaser/geom/rectangle.ts +42 -42
- package/src/phaser/geom/rounded_rectangle.ts +2 -2
- package/src/phaser/geom/util/circle.ts +7 -7
- package/src/phaser/geom/util/ellipse.ts +1 -1
- package/src/phaser/geom/util/line.ts +13 -5
- package/src/phaser/geom/util/matrix.ts +3 -3
- package/src/phaser/geom/util/point.ts +20 -20
- package/src/phaser/geom/util/polygon.ts +1 -1
- package/src/phaser/geom/util/rectangle.ts +34 -17
- package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
package/src/phaser/core/cache.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TextureSource } from '../display/webgl/base_texture.js';
|
|
1
2
|
import { BaseTexture } from '../display/webgl/base_texture.js';
|
|
2
3
|
import { Texture } from '../display/webgl/texture.js';
|
|
3
4
|
import { JSONDataHash, spriteSheet } from './animation_parser.js';
|
|
@@ -5,6 +6,7 @@ import { Frame } from './frame.js';
|
|
|
5
6
|
import { FrameData } from './frame_data.js';
|
|
6
7
|
import { jsonBitmapFont, xmlBitmapFont } from './loader_parser.js';
|
|
7
8
|
import { Signal } from './signal.js';
|
|
9
|
+
import type { BitmapFontData } from './loader_parser.js';
|
|
8
10
|
import type { Game } from './game.js';
|
|
9
11
|
|
|
10
12
|
export const CANVAS = 0;
|
|
@@ -18,28 +20,66 @@ export const JSONDATA = 7;
|
|
|
18
20
|
export const XML = 8;
|
|
19
21
|
export const RENDER_TEXTURE = 9;
|
|
20
22
|
|
|
23
|
+
/** An image, sprite sheet or texture atlas: the source bitmap and the frames cut from it. */
|
|
24
|
+
export type ImageCacheEntry = {
|
|
25
|
+
key: string;
|
|
26
|
+
url: string;
|
|
27
|
+
data: TextureSource;
|
|
28
|
+
base: BaseTexture;
|
|
29
|
+
frame?: Frame;
|
|
30
|
+
frameData: FrameData | null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Audio as the cache holds it: the raw bytes on load, an AudioBuffer once decoded. */
|
|
34
|
+
export type SoundData = ArrayBuffer | AudioBuffer;
|
|
35
|
+
|
|
36
|
+
/** A sound and how far its decoding has got. */
|
|
37
|
+
export type SoundCacheEntry = {
|
|
38
|
+
url: string;
|
|
39
|
+
data: SoundData;
|
|
40
|
+
isDecoding: boolean;
|
|
41
|
+
decoded: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** A bitmap font: the glyph atlas and the descriptor parsed from it. */
|
|
45
|
+
export type BitmapFontCacheEntry = {
|
|
46
|
+
url: string;
|
|
47
|
+
data: TextureSource;
|
|
48
|
+
font: BitmapFontData;
|
|
49
|
+
base: BaseTexture;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** A text, JSON or XML payload under the URL it came from. */
|
|
53
|
+
export type DataCacheEntry<T> = {
|
|
54
|
+
url: string;
|
|
55
|
+
data: T;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Anything the cache can hold, whichever bucket it lives in. */
|
|
59
|
+
export type CacheEntry = ImageCacheEntry | SoundCacheEntry | BitmapFontCacheEntry | DataCacheEntry<unknown>;
|
|
60
|
+
|
|
21
61
|
interface CacheBuckets {
|
|
22
|
-
canvas: Record<string,
|
|
23
|
-
image: Record<string,
|
|
24
|
-
texture: Record<string,
|
|
25
|
-
sound: Record<string,
|
|
26
|
-
text: Record<string,
|
|
27
|
-
json: Record<string,
|
|
28
|
-
xml: Record<string,
|
|
29
|
-
bitmapData: Record<string,
|
|
30
|
-
bitmapFont: Record<string,
|
|
31
|
-
renderTexture: Record<string,
|
|
62
|
+
canvas: Record<string, CacheEntry>;
|
|
63
|
+
image: Record<string, ImageCacheEntry>;
|
|
64
|
+
texture: Record<string, CacheEntry>;
|
|
65
|
+
sound: Record<string, SoundCacheEntry>;
|
|
66
|
+
text: Record<string, DataCacheEntry<string>>;
|
|
67
|
+
json: Record<string, DataCacheEntry<unknown>>;
|
|
68
|
+
xml: Record<string, DataCacheEntry<XMLDocument>>;
|
|
69
|
+
bitmapData: Record<string, CacheEntry>;
|
|
70
|
+
bitmapFont: Record<string, BitmapFontCacheEntry>;
|
|
71
|
+
renderTexture: Record<string, CacheEntry>;
|
|
32
72
|
}
|
|
33
73
|
|
|
34
74
|
export class Cache {
|
|
35
75
|
public game!: Game;
|
|
36
|
-
public autoResolveURL!:
|
|
76
|
+
public autoResolveURL!: boolean;
|
|
37
77
|
public _cache!: CacheBuckets;
|
|
38
|
-
public _urlMap!:
|
|
39
|
-
public _urlResolver!:
|
|
40
|
-
public _urlTemp!:
|
|
41
|
-
public onSoundUnlock!:
|
|
42
|
-
public _cacheMap!: Record<string,
|
|
78
|
+
public _urlMap!: Record<string, object> | null;
|
|
79
|
+
public _urlResolver!: HTMLImageElement | null;
|
|
80
|
+
public _urlTemp!: string | null;
|
|
81
|
+
public onSoundUnlock!: Signal;
|
|
82
|
+
public _cacheMap!: Record<string, CacheEntry>[];
|
|
43
83
|
/**
|
|
44
84
|
* Creates a new Cache instance.
|
|
45
85
|
* @param {Game} game - The game instance.
|
|
@@ -81,7 +121,7 @@ export class Cache {
|
|
|
81
121
|
/**
|
|
82
122
|
* Adds the default image to the cache.
|
|
83
123
|
*/
|
|
84
|
-
public addDefaultImage() {
|
|
124
|
+
public addDefaultImage(): void {
|
|
85
125
|
const img = new Image();
|
|
86
126
|
img.src =
|
|
87
127
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgAQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==';
|
|
@@ -93,7 +133,7 @@ export class Cache {
|
|
|
93
133
|
/**
|
|
94
134
|
* Adds the missing image to the cache.
|
|
95
135
|
*/
|
|
96
|
-
public addMissingImage() {
|
|
136
|
+
public addMissingImage(): void {
|
|
97
137
|
const img = new Image();
|
|
98
138
|
img.src =
|
|
99
139
|
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==';
|
|
@@ -108,7 +148,7 @@ export class Cache {
|
|
|
108
148
|
* @param {HTMLImageElement} data - The image data to cache.
|
|
109
149
|
* @returns {object} The cached image object.
|
|
110
150
|
*/
|
|
111
|
-
public addImage(key: string, url: string | null, data: HTMLImageElement) {
|
|
151
|
+
public addImage(key: string, url: string | null, data: HTMLImageElement): ImageCacheEntry {
|
|
112
152
|
const resolvedUrl = url ?? '';
|
|
113
153
|
if (this.checkImageKey(key)) {
|
|
114
154
|
this.removeImage(key);
|
|
@@ -150,7 +190,7 @@ export class Cache {
|
|
|
150
190
|
frameMax = -1,
|
|
151
191
|
margin = 0,
|
|
152
192
|
spacing = 0
|
|
153
|
-
) {
|
|
193
|
+
): void {
|
|
154
194
|
const obj = {
|
|
155
195
|
key,
|
|
156
196
|
url,
|
|
@@ -169,14 +209,14 @@ export class Cache {
|
|
|
169
209
|
* @param {HTMLCanvasElement} data - The canvas data for the atlas.
|
|
170
210
|
* @param {object} atlasData - The atlas data to cache.
|
|
171
211
|
*/
|
|
172
|
-
public addTextureAtlas(key: string, url: string, data:
|
|
173
|
-
const obj:
|
|
212
|
+
public addTextureAtlas(key: string, url: string, data: TextureSource, atlasData: unknown): void {
|
|
213
|
+
const obj: ImageCacheEntry = {
|
|
174
214
|
key,
|
|
175
215
|
url,
|
|
176
216
|
data,
|
|
177
217
|
base: new BaseTexture(data),
|
|
218
|
+
frameData: JSONDataHash(this.game, atlasData, key),
|
|
178
219
|
};
|
|
179
|
-
obj.frameData = JSONDataHash(this.game, atlasData, key);
|
|
180
220
|
this._cache.image[key] = obj;
|
|
181
221
|
this._resolveURL(url, obj);
|
|
182
222
|
}
|
|
@@ -187,14 +227,15 @@ export class Cache {
|
|
|
187
227
|
* @param {string} url - The URL the sound was loaded from.
|
|
188
228
|
* @param {object} data - The sound data to cache.
|
|
189
229
|
*/
|
|
190
|
-
public addSound(key: string, url: string, data:
|
|
191
|
-
|
|
230
|
+
public addSound(key: string, url: string, data: SoundData): void {
|
|
231
|
+
const obj: SoundCacheEntry = {
|
|
192
232
|
url,
|
|
193
233
|
data,
|
|
194
234
|
isDecoding: false,
|
|
195
235
|
decoded: false,
|
|
196
236
|
};
|
|
197
|
-
this.
|
|
237
|
+
this._cache.sound[key] = obj;
|
|
238
|
+
this._resolveURL(url, obj);
|
|
198
239
|
}
|
|
199
240
|
|
|
200
241
|
/**
|
|
@@ -203,9 +244,10 @@ export class Cache {
|
|
|
203
244
|
* @param {string} url - The URL the text was loaded from.
|
|
204
245
|
* @param {string} data - The text data to cache.
|
|
205
246
|
*/
|
|
206
|
-
public addText(key: string, url: string, data: string) {
|
|
207
|
-
|
|
208
|
-
this.
|
|
247
|
+
public addText(key: string, url: string, data: string): void {
|
|
248
|
+
const obj: DataCacheEntry<string> = { url, data };
|
|
249
|
+
this._cache.text[key] = obj;
|
|
250
|
+
this._resolveURL(url, obj);
|
|
209
251
|
}
|
|
210
252
|
|
|
211
253
|
/**
|
|
@@ -221,23 +263,18 @@ export class Cache {
|
|
|
221
263
|
public addBitmapFont(
|
|
222
264
|
key: string,
|
|
223
265
|
url: string,
|
|
224
|
-
data:
|
|
225
|
-
atlasData:
|
|
266
|
+
data: TextureSource,
|
|
267
|
+
atlasData: unknown,
|
|
226
268
|
atlasType: string,
|
|
227
269
|
xSpacing = 0,
|
|
228
270
|
ySpacing = 0
|
|
229
|
-
) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
};
|
|
236
|
-
if (atlasType === 'json') {
|
|
237
|
-
obj.font = jsonBitmapFont(atlasData, obj.base, xSpacing, ySpacing);
|
|
238
|
-
} else {
|
|
239
|
-
obj.font = xmlBitmapFont(atlasData, obj.base, xSpacing, ySpacing);
|
|
240
|
-
}
|
|
271
|
+
): void {
|
|
272
|
+
const base = new BaseTexture(data);
|
|
273
|
+
const font =
|
|
274
|
+
atlasType === 'json'
|
|
275
|
+
? jsonBitmapFont(atlasData, base, xSpacing, ySpacing)
|
|
276
|
+
: xmlBitmapFont(atlasData as XMLDocument, base, xSpacing, ySpacing);
|
|
277
|
+
const obj: BitmapFontCacheEntry = { url, data, font, base };
|
|
241
278
|
this._cache.bitmapFont[key] = obj;
|
|
242
279
|
this._resolveURL(url, obj);
|
|
243
280
|
}
|
|
@@ -248,9 +285,10 @@ export class Cache {
|
|
|
248
285
|
* @param {string} url - The URL the JSON was loaded from.
|
|
249
286
|
* @param {object} data - The JSON data to cache.
|
|
250
287
|
*/
|
|
251
|
-
public addJSON(key: string, url: string, data:
|
|
252
|
-
|
|
253
|
-
this.
|
|
288
|
+
public addJSON(key: string, url: string, data: unknown): void {
|
|
289
|
+
const obj: DataCacheEntry<unknown> = { url, data };
|
|
290
|
+
this._cache.json[key] = obj;
|
|
291
|
+
this._resolveURL(url, obj);
|
|
254
292
|
}
|
|
255
293
|
|
|
256
294
|
/**
|
|
@@ -259,9 +297,10 @@ export class Cache {
|
|
|
259
297
|
* @param {string} url - The URL the XML was loaded from.
|
|
260
298
|
* @param {XMLDocument} data - The XML data to cache.
|
|
261
299
|
*/
|
|
262
|
-
public addXML(key: string, url: string, data: XMLDocument) {
|
|
263
|
-
|
|
264
|
-
this.
|
|
300
|
+
public addXML(key: string, url: string, data: XMLDocument): void {
|
|
301
|
+
const obj: DataCacheEntry<XMLDocument> = { url, data };
|
|
302
|
+
this._cache.xml[key] = obj;
|
|
303
|
+
this._resolveURL(url, obj);
|
|
265
304
|
}
|
|
266
305
|
|
|
267
306
|
// SOUND
|
|
@@ -272,7 +311,7 @@ export class Cache {
|
|
|
272
311
|
* @param {string} property - The property to update.
|
|
273
312
|
* @param {any} value - The new value for the property.
|
|
274
313
|
*/
|
|
275
|
-
public updateSound(key: string, property:
|
|
314
|
+
public updateSound<K extends keyof SoundCacheEntry>(key: string, property: K, value: SoundCacheEntry[K]): void {
|
|
276
315
|
const sound = this.getSound(key);
|
|
277
316
|
if (sound) {
|
|
278
317
|
sound[property] = value;
|
|
@@ -284,8 +323,11 @@ export class Cache {
|
|
|
284
323
|
* @param {string} key - The unique key for the cached sound.
|
|
285
324
|
* @param {AudioBuffer} data - The decoded audio buffer.
|
|
286
325
|
*/
|
|
287
|
-
public decodedSound(key: string, data: AudioBuffer) {
|
|
326
|
+
public decodedSound(key: string, data: AudioBuffer): void {
|
|
288
327
|
const sound = this.getSound(key);
|
|
328
|
+
if (!sound) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
289
331
|
sound.data = data;
|
|
290
332
|
sound.decoded = true;
|
|
291
333
|
sound.isDecoding = false;
|
|
@@ -296,8 +338,8 @@ export class Cache {
|
|
|
296
338
|
* @param {string} key - The unique key for the cached sound.
|
|
297
339
|
* @returns {boolean} True if the sound is decoded, false otherwise.
|
|
298
340
|
*/
|
|
299
|
-
public isSoundDecoded(key: string) {
|
|
300
|
-
const sound = this.
|
|
341
|
+
public isSoundDecoded(key: string): boolean | null {
|
|
342
|
+
const sound = this.getSound(key);
|
|
301
343
|
if (sound) {
|
|
302
344
|
return sound.decoded;
|
|
303
345
|
}
|
|
@@ -309,8 +351,8 @@ export class Cache {
|
|
|
309
351
|
* @param {string} key - The unique key for the cached sound.
|
|
310
352
|
* @returns {boolean} True if the sound is ready, false otherwise.
|
|
311
353
|
*/
|
|
312
|
-
public isSoundReady(key: string) {
|
|
313
|
-
const sound = this.
|
|
354
|
+
public isSoundReady(key: string): boolean {
|
|
355
|
+
const sound = this.getSound(key);
|
|
314
356
|
if (sound) {
|
|
315
357
|
return sound.decoded && !this.game.sound.isLocked;
|
|
316
358
|
}
|
|
@@ -325,7 +367,7 @@ export class Cache {
|
|
|
325
367
|
* @param {string} key - The unique key for the cache entry.
|
|
326
368
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
327
369
|
*/
|
|
328
|
-
public checkKey(cache: number, key: string) {
|
|
370
|
+
public checkKey(cache: number, key: string): boolean {
|
|
329
371
|
if (this._cacheMap[cache]?.[key]) {
|
|
330
372
|
return true;
|
|
331
373
|
}
|
|
@@ -337,8 +379,9 @@ export class Cache {
|
|
|
337
379
|
* @param {string} url - The URL to check.
|
|
338
380
|
* @returns {boolean} True if the URL has been resolved and cached, false otherwise.
|
|
339
381
|
*/
|
|
340
|
-
public checkURL(url: string) {
|
|
341
|
-
|
|
382
|
+
public checkURL(url: string): boolean {
|
|
383
|
+
const resolved = this._resolveURL(url);
|
|
384
|
+
if (resolved && this._urlMap?.[resolved]) {
|
|
342
385
|
return true;
|
|
343
386
|
}
|
|
344
387
|
return false;
|
|
@@ -349,7 +392,7 @@ export class Cache {
|
|
|
349
392
|
* @param {string} key - The unique key for the cache entry.
|
|
350
393
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
351
394
|
*/
|
|
352
|
-
public checkCanvasKey(key: string) {
|
|
395
|
+
public checkCanvasKey(key: string): boolean {
|
|
353
396
|
return this.checkKey(CANVAS, key);
|
|
354
397
|
}
|
|
355
398
|
|
|
@@ -358,7 +401,7 @@ export class Cache {
|
|
|
358
401
|
* @param {string} key - The unique key for the cache entry.
|
|
359
402
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
360
403
|
*/
|
|
361
|
-
public checkImageKey(key: string) {
|
|
404
|
+
public checkImageKey(key: string): boolean {
|
|
362
405
|
return this.checkKey(IMAGE, key);
|
|
363
406
|
}
|
|
364
407
|
|
|
@@ -367,7 +410,7 @@ export class Cache {
|
|
|
367
410
|
* @param {string} key - The unique key for the cache entry.
|
|
368
411
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
369
412
|
*/
|
|
370
|
-
public checkTextureKey(key: string) {
|
|
413
|
+
public checkTextureKey(key: string): boolean {
|
|
371
414
|
return this.checkKey(TEXTURE, key);
|
|
372
415
|
}
|
|
373
416
|
|
|
@@ -376,7 +419,7 @@ export class Cache {
|
|
|
376
419
|
* @param {string} key - The unique key for the cache entry.
|
|
377
420
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
378
421
|
*/
|
|
379
|
-
public checkSoundKey(key: string) {
|
|
422
|
+
public checkSoundKey(key: string): boolean {
|
|
380
423
|
return this.checkKey(SOUND, key);
|
|
381
424
|
}
|
|
382
425
|
|
|
@@ -385,7 +428,7 @@ export class Cache {
|
|
|
385
428
|
* @param {string} key - The unique key for the cache entry.
|
|
386
429
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
387
430
|
*/
|
|
388
|
-
public checkTextKey(key: string) {
|
|
431
|
+
public checkTextKey(key: string): boolean {
|
|
389
432
|
return this.checkKey(TEXT, key);
|
|
390
433
|
}
|
|
391
434
|
|
|
@@ -394,7 +437,7 @@ export class Cache {
|
|
|
394
437
|
* @param {string} key - The unique key for the cache entry.
|
|
395
438
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
396
439
|
*/
|
|
397
|
-
public checkBitmapDataKey(key: string) {
|
|
440
|
+
public checkBitmapDataKey(key: string): boolean {
|
|
398
441
|
return this.checkKey(BITMAPDATA, key);
|
|
399
442
|
}
|
|
400
443
|
|
|
@@ -403,7 +446,7 @@ export class Cache {
|
|
|
403
446
|
* @param {string} key - The unique key for the cache entry.
|
|
404
447
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
405
448
|
*/
|
|
406
|
-
public checkBitmapFontKey(key: string) {
|
|
449
|
+
public checkBitmapFontKey(key: string): boolean {
|
|
407
450
|
return this.checkKey(BITMAPFONT, key);
|
|
408
451
|
}
|
|
409
452
|
|
|
@@ -412,7 +455,7 @@ export class Cache {
|
|
|
412
455
|
* @param {string} key - The unique key for the cache entry.
|
|
413
456
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
414
457
|
*/
|
|
415
|
-
public checkJSONKey(key: string) {
|
|
458
|
+
public checkJSONKey(key: string): boolean {
|
|
416
459
|
return this.checkKey(JSONDATA, key);
|
|
417
460
|
}
|
|
418
461
|
|
|
@@ -421,7 +464,7 @@ export class Cache {
|
|
|
421
464
|
* @param {string} key - The unique key for the cache entry.
|
|
422
465
|
* @returns {boolean} True if the entry exists, false otherwise.
|
|
423
466
|
*/
|
|
424
|
-
public checkXMLKey(key: string) {
|
|
467
|
+
public checkXMLKey(key: string): boolean {
|
|
425
468
|
return this.checkKey(XML, key);
|
|
426
469
|
}
|
|
427
470
|
|
|
@@ -435,13 +478,13 @@ export class Cache {
|
|
|
435
478
|
* @param {string} property - TBD.
|
|
436
479
|
* @returns {*} TBD.
|
|
437
480
|
*/
|
|
438
|
-
public getItem(key: string, cache: number, _method: string, property: string | null = null) {
|
|
481
|
+
public getItem(key: string, cache: number, _method: string, property: string | null = null): unknown {
|
|
439
482
|
if (this.checkKey(cache, key)) {
|
|
440
|
-
const entry = this._cacheMap[cache]![key]
|
|
483
|
+
const entry = this._cacheMap[cache]![key]!;
|
|
441
484
|
if (!property) {
|
|
442
485
|
return entry;
|
|
443
486
|
}
|
|
444
|
-
return entry[property];
|
|
487
|
+
return (entry as Record<string, unknown>)[property];
|
|
445
488
|
}
|
|
446
489
|
return null;
|
|
447
490
|
}
|
|
@@ -451,8 +494,8 @@ export class Cache {
|
|
|
451
494
|
* @param {string} key - TBD.
|
|
452
495
|
* @returns {HTMLCanvasElement} TBD.
|
|
453
496
|
*/
|
|
454
|
-
public getCanvas(key: string) {
|
|
455
|
-
return this.getItem(key, CANVAS, 'getCanvas', 'canvas');
|
|
497
|
+
public getCanvas(key: string): HTMLCanvasElement | null {
|
|
498
|
+
return this.getItem(key, CANVAS, 'getCanvas', 'canvas') as HTMLCanvasElement | null;
|
|
456
499
|
}
|
|
457
500
|
|
|
458
501
|
/**
|
|
@@ -461,11 +504,11 @@ export class Cache {
|
|
|
461
504
|
* @param {boolean} full - TBD.
|
|
462
505
|
* @returns {HTMLImageElement} TBD.
|
|
463
506
|
*/
|
|
464
|
-
public getImage(key
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
507
|
+
public getImage(key?: string | number, full?: false): TextureSource;
|
|
508
|
+
public getImage(key: string | number | undefined, full: true): ImageCacheEntry;
|
|
509
|
+
public getImage(key: string | number = '__default', full = false): TextureSource | ImageCacheEntry {
|
|
510
|
+
const img = (this.getItem(String(key), IMAGE, 'getImage') ??
|
|
511
|
+
this.getItem('__missing', IMAGE, 'getImage')) as ImageCacheEntry;
|
|
469
512
|
if (full) {
|
|
470
513
|
return img;
|
|
471
514
|
}
|
|
@@ -477,8 +520,8 @@ export class Cache {
|
|
|
477
520
|
* @param {string} key - TBD.
|
|
478
521
|
* @returns {object} TBD.
|
|
479
522
|
*/
|
|
480
|
-
public getTextureFrame(key: string) {
|
|
481
|
-
return this.getItem(key, TEXTURE, 'getTextureFrame', 'frame');
|
|
523
|
+
public getTextureFrame(key: string): Frame | null {
|
|
524
|
+
return this.getItem(key, TEXTURE, 'getTextureFrame', 'frame') as Frame | null;
|
|
482
525
|
}
|
|
483
526
|
|
|
484
527
|
/**
|
|
@@ -486,8 +529,8 @@ export class Cache {
|
|
|
486
529
|
* @param {string} key - TBD.
|
|
487
530
|
* @returns {object} TBD.
|
|
488
531
|
*/
|
|
489
|
-
public getSound(key: string) {
|
|
490
|
-
return this.getItem(key, SOUND, 'getSound');
|
|
532
|
+
public getSound(key: string): SoundCacheEntry | null {
|
|
533
|
+
return this.getItem(key, SOUND, 'getSound') as SoundCacheEntry | null;
|
|
491
534
|
}
|
|
492
535
|
|
|
493
536
|
/**
|
|
@@ -495,8 +538,8 @@ export class Cache {
|
|
|
495
538
|
* @param {string} key - TBD.
|
|
496
539
|
* @returns {object} TBD.
|
|
497
540
|
*/
|
|
498
|
-
public getSoundData(key: string) {
|
|
499
|
-
return this.getItem(key, SOUND, 'getSoundData', 'data');
|
|
541
|
+
public getSoundData(key: string): SoundData | null {
|
|
542
|
+
return this.getItem(key, SOUND, 'getSoundData', 'data') as SoundData | null;
|
|
500
543
|
}
|
|
501
544
|
|
|
502
545
|
/**
|
|
@@ -504,8 +547,8 @@ export class Cache {
|
|
|
504
547
|
* @param {string} key - TBD.
|
|
505
548
|
* @returns {object} TBD.
|
|
506
549
|
*/
|
|
507
|
-
public getText(key: string) {
|
|
508
|
-
return this.getItem(key, TEXT, 'getText', 'data');
|
|
550
|
+
public getText(key: string): string | null {
|
|
551
|
+
return this.getItem(key, TEXT, 'getText', 'data') as string | null;
|
|
509
552
|
}
|
|
510
553
|
|
|
511
554
|
/**
|
|
@@ -513,7 +556,7 @@ export class Cache {
|
|
|
513
556
|
* @param {string} key - TBD.
|
|
514
557
|
* @returns {object} TBD.
|
|
515
558
|
*/
|
|
516
|
-
public getBitmapData(key: string) {
|
|
559
|
+
public getBitmapData(key: string): unknown {
|
|
517
560
|
return this.getItem(key, BITMAPDATA, 'getBitmapData', 'data');
|
|
518
561
|
}
|
|
519
562
|
|
|
@@ -522,8 +565,8 @@ export class Cache {
|
|
|
522
565
|
* @param {string} key - TBD.
|
|
523
566
|
* @returns {object} TBD.
|
|
524
567
|
*/
|
|
525
|
-
public getBitmapFont(key: string) {
|
|
526
|
-
return this.getItem(key, BITMAPFONT, 'getBitmapFont');
|
|
568
|
+
public getBitmapFont(key: string): BitmapFontCacheEntry | null {
|
|
569
|
+
return this.getItem(key, BITMAPFONT, 'getBitmapFont') as BitmapFontCacheEntry | null;
|
|
527
570
|
}
|
|
528
571
|
|
|
529
572
|
/**
|
|
@@ -534,7 +577,7 @@ export class Cache {
|
|
|
534
577
|
* @returns {T} The cached JSON data.
|
|
535
578
|
*/
|
|
536
579
|
public getJSON<T = unknown>(key: string, isClone = false): T {
|
|
537
|
-
const data = this.getItem(key, JSONDATA, 'getJSON', 'data');
|
|
580
|
+
const data = this.getItem(key, JSONDATA, 'getJSON', 'data') as T;
|
|
538
581
|
return isClone ? structuredClone(data) : data;
|
|
539
582
|
}
|
|
540
583
|
|
|
@@ -543,8 +586,8 @@ export class Cache {
|
|
|
543
586
|
* @param {string} key - TBD.
|
|
544
587
|
* @returns {XMLDocument} TBD.
|
|
545
588
|
*/
|
|
546
|
-
public getXML(key: string) {
|
|
547
|
-
return this.getItem(key, XML, 'getXML', 'data');
|
|
589
|
+
public getXML(key: string): XMLDocument | null {
|
|
590
|
+
return this.getItem(key, XML, 'getXML', 'data') as XMLDocument | null;
|
|
548
591
|
}
|
|
549
592
|
|
|
550
593
|
/**
|
|
@@ -552,8 +595,8 @@ export class Cache {
|
|
|
552
595
|
* @param {string} key - TBD.
|
|
553
596
|
* @returns {RenderTexture} TBD.
|
|
554
597
|
*/
|
|
555
|
-
public getRenderTexture(key: string) {
|
|
556
|
-
return this.getItem(key, RENDER_TEXTURE, 'getRenderTexture');
|
|
598
|
+
public getRenderTexture(key: string): CacheEntry | null {
|
|
599
|
+
return this.getItem(key, RENDER_TEXTURE, 'getRenderTexture') as CacheEntry | null;
|
|
557
600
|
}
|
|
558
601
|
|
|
559
602
|
// FRAME
|
|
@@ -564,8 +607,8 @@ export class Cache {
|
|
|
564
607
|
* @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
565
608
|
* @returns {BaseTexture} The base texture.
|
|
566
609
|
*/
|
|
567
|
-
public getBaseTexture(key: string, cache: number = IMAGE) {
|
|
568
|
-
return this.getItem(key, cache, 'getBaseTexture', 'base');
|
|
610
|
+
public getBaseTexture(key: string, cache: number = IMAGE): BaseTexture | null {
|
|
611
|
+
return this.getItem(key, cache, 'getBaseTexture', 'base') as BaseTexture | null;
|
|
569
612
|
}
|
|
570
613
|
|
|
571
614
|
/**
|
|
@@ -574,8 +617,8 @@ export class Cache {
|
|
|
574
617
|
* @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
575
618
|
* @returns {Frame} The frame.
|
|
576
619
|
*/
|
|
577
|
-
public getFrame(key: string, cache: number = IMAGE) {
|
|
578
|
-
return this.getItem(key, cache, 'getFrame', 'frame');
|
|
620
|
+
public getFrame(key: string, cache: number = IMAGE): Frame | null {
|
|
621
|
+
return this.getItem(key, cache, 'getFrame', 'frame') as Frame | null;
|
|
579
622
|
}
|
|
580
623
|
|
|
581
624
|
/**
|
|
@@ -584,7 +627,7 @@ export class Cache {
|
|
|
584
627
|
* @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
585
628
|
* @returns {number} The number of frames.
|
|
586
629
|
*/
|
|
587
|
-
public getFrameCount(key: string, cache: number = IMAGE) {
|
|
630
|
+
public getFrameCount(key: string, cache: number = IMAGE): number {
|
|
588
631
|
const data = this.getFrameData(key, cache);
|
|
589
632
|
if (data) {
|
|
590
633
|
return data.total;
|
|
@@ -599,7 +642,7 @@ export class Cache {
|
|
|
599
642
|
* @returns {FrameData | null} The frame data, or null when the entry has none.
|
|
600
643
|
*/
|
|
601
644
|
public getFrameData(key: string, cache: number = IMAGE): FrameData | null {
|
|
602
|
-
return this.getItem(key, cache, 'getFrameData', 'frameData');
|
|
645
|
+
return this.getItem(key, cache, 'getFrameData', 'frameData') as FrameData | null;
|
|
603
646
|
}
|
|
604
647
|
|
|
605
648
|
/**
|
|
@@ -608,7 +651,7 @@ export class Cache {
|
|
|
608
651
|
* @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
609
652
|
* @returns {boolean} True if the entry has frame data, false otherwise.
|
|
610
653
|
*/
|
|
611
|
-
public hasFrameData(key: string, cache: number = IMAGE) {
|
|
654
|
+
public hasFrameData(key: string, cache: number = IMAGE): boolean {
|
|
612
655
|
return this.getItem(key, cache, '', 'frameData') !== null;
|
|
613
656
|
}
|
|
614
657
|
|
|
@@ -618,10 +661,10 @@ export class Cache {
|
|
|
618
661
|
* @param {FrameData} frameData - The new frame data.
|
|
619
662
|
* @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
620
663
|
*/
|
|
621
|
-
public updateFrameData(key: string, frameData: FrameData, cache: number = IMAGE) {
|
|
664
|
+
public updateFrameData(key: string, frameData: FrameData, cache: number = IMAGE): void {
|
|
622
665
|
const entry = this._cacheMap[cache]?.[key];
|
|
623
666
|
if (entry) {
|
|
624
|
-
entry.frameData = frameData;
|
|
667
|
+
(entry as ImageCacheEntry).frameData = frameData;
|
|
625
668
|
}
|
|
626
669
|
}
|
|
627
670
|
|
|
@@ -632,7 +675,7 @@ export class Cache {
|
|
|
632
675
|
* @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
633
676
|
* @returns {Frame} The frame at the specified index.
|
|
634
677
|
*/
|
|
635
|
-
public getFrameByIndex(key: string, index: number, cache: number = IMAGE) {
|
|
678
|
+
public getFrameByIndex(key: string, index: number, cache: number = IMAGE): Frame | null {
|
|
636
679
|
const data = this.getFrameData(key, cache);
|
|
637
680
|
if (data) {
|
|
638
681
|
return data.getFrame(index);
|
|
@@ -647,7 +690,7 @@ export class Cache {
|
|
|
647
690
|
* @param {number} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
648
691
|
* @returns {Frame} The frame with the specified name.
|
|
649
692
|
*/
|
|
650
|
-
public getFrameByName(key: string, name: string, cache: number = IMAGE) {
|
|
693
|
+
public getFrameByName(key: string, name: string, cache: number = IMAGE): Frame | null {
|
|
651
694
|
const data = this.getFrameData(key, cache);
|
|
652
695
|
if (data) {
|
|
653
696
|
return data.getFrameByName(name);
|
|
@@ -663,7 +706,7 @@ export class Cache {
|
|
|
663
706
|
public getURL(url: string) {
|
|
664
707
|
const resolvedURL = this._resolveURL(url);
|
|
665
708
|
if (resolvedURL) {
|
|
666
|
-
return this._urlMap[resolvedURL];
|
|
709
|
+
return this._urlMap?.[resolvedURL] ?? null;
|
|
667
710
|
}
|
|
668
711
|
this.game.logger.warn('Cache invalid url', { resolvedURL });
|
|
669
712
|
return null;
|
|
@@ -674,10 +717,11 @@ export class Cache {
|
|
|
674
717
|
* @param {object} cache - The cache type (CANVAS, IMAGE, etc.).
|
|
675
718
|
* @returns {string[]} An array of cache keys.
|
|
676
719
|
*/
|
|
677
|
-
public getKeys(cache:
|
|
720
|
+
public getKeys(cache: number = IMAGE): string[] {
|
|
678
721
|
const result = [];
|
|
679
|
-
|
|
680
|
-
|
|
722
|
+
const bucket = this._cacheMap[cache];
|
|
723
|
+
if (bucket) {
|
|
724
|
+
const keys = Object.keys(bucket);
|
|
681
725
|
for (const key of keys) {
|
|
682
726
|
if (key !== '__default' && key !== '__missing') {
|
|
683
727
|
result.push(key);
|
|
@@ -693,7 +737,7 @@ export class Cache {
|
|
|
693
737
|
* Removes a canvas cache entry.
|
|
694
738
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
695
739
|
*/
|
|
696
|
-
public removeCanvas(key: string) {
|
|
740
|
+
public removeCanvas(key: string): void {
|
|
697
741
|
delete this._cache.canvas[key];
|
|
698
742
|
}
|
|
699
743
|
|
|
@@ -702,9 +746,9 @@ export class Cache {
|
|
|
702
746
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
703
747
|
* @param {boolean} destroyBaseTexture - Whether to destroy the base texture (default: true).
|
|
704
748
|
*/
|
|
705
|
-
public removeImage(key: string, destroyBaseTexture = true) {
|
|
749
|
+
public removeImage(key: string, destroyBaseTexture = true): void {
|
|
706
750
|
const img = this.getImage(key, true);
|
|
707
|
-
if (destroyBaseTexture
|
|
751
|
+
if (destroyBaseTexture) {
|
|
708
752
|
img.base.destroy();
|
|
709
753
|
}
|
|
710
754
|
delete this._cache.image[key];
|
|
@@ -714,7 +758,7 @@ export class Cache {
|
|
|
714
758
|
* Removes a sound cache entry.
|
|
715
759
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
716
760
|
*/
|
|
717
|
-
public removeSound(key: string) {
|
|
761
|
+
public removeSound(key: string): void {
|
|
718
762
|
delete this._cache.sound[key];
|
|
719
763
|
}
|
|
720
764
|
|
|
@@ -722,7 +766,7 @@ export class Cache {
|
|
|
722
766
|
* Removes a text cache entry.
|
|
723
767
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
724
768
|
*/
|
|
725
|
-
public removeText(key: string) {
|
|
769
|
+
public removeText(key: string): void {
|
|
726
770
|
delete this._cache.text[key];
|
|
727
771
|
}
|
|
728
772
|
|
|
@@ -730,7 +774,7 @@ export class Cache {
|
|
|
730
774
|
* Removes a bitmap data cache entry.
|
|
731
775
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
732
776
|
*/
|
|
733
|
-
public removeBitmapData(key: string) {
|
|
777
|
+
public removeBitmapData(key: string): void {
|
|
734
778
|
delete this._cache.bitmapData[key];
|
|
735
779
|
}
|
|
736
780
|
|
|
@@ -738,7 +782,7 @@ export class Cache {
|
|
|
738
782
|
* Removes a bitmap font cache entry.
|
|
739
783
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
740
784
|
*/
|
|
741
|
-
public removeBitmapFont(key: string) {
|
|
785
|
+
public removeBitmapFont(key: string): void {
|
|
742
786
|
delete this._cache.bitmapFont[key];
|
|
743
787
|
}
|
|
744
788
|
|
|
@@ -746,7 +790,7 @@ export class Cache {
|
|
|
746
790
|
* Removes a JSON cache entry.
|
|
747
791
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
748
792
|
*/
|
|
749
|
-
public removeJSON(key: string) {
|
|
793
|
+
public removeJSON(key: string): void {
|
|
750
794
|
delete this._cache.json[key];
|
|
751
795
|
}
|
|
752
796
|
|
|
@@ -754,7 +798,7 @@ export class Cache {
|
|
|
754
798
|
* Removes an XML cache entry.
|
|
755
799
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
756
800
|
*/
|
|
757
|
-
public removeXML(key: string) {
|
|
801
|
+
public removeXML(key: string): void {
|
|
758
802
|
delete this._cache.xml[key];
|
|
759
803
|
}
|
|
760
804
|
|
|
@@ -762,7 +806,7 @@ export class Cache {
|
|
|
762
806
|
* Removes a render texture cache entry.
|
|
763
807
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
764
808
|
*/
|
|
765
|
-
public removeRenderTexture(key: string) {
|
|
809
|
+
public removeRenderTexture(key: string): void {
|
|
766
810
|
delete this._cache.renderTexture[key];
|
|
767
811
|
}
|
|
768
812
|
|
|
@@ -770,7 +814,7 @@ export class Cache {
|
|
|
770
814
|
* Removes a sprite sheet cache entry.
|
|
771
815
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
772
816
|
*/
|
|
773
|
-
public removeSpriteSheet(key: string) {
|
|
817
|
+
public removeSpriteSheet(key: string): void {
|
|
774
818
|
delete this._cache.image[key];
|
|
775
819
|
}
|
|
776
820
|
|
|
@@ -778,17 +822,16 @@ export class Cache {
|
|
|
778
822
|
* Removes a texture atlas cache entry.
|
|
779
823
|
* @param {string} key - The unique key for the cache entry to remove.
|
|
780
824
|
*/
|
|
781
|
-
public removeTextureAtlas(key: string) {
|
|
825
|
+
public removeTextureAtlas(key: string): void {
|
|
782
826
|
delete this._cache.image[key];
|
|
783
827
|
}
|
|
784
828
|
|
|
785
829
|
/**
|
|
786
830
|
* Clears all GL textures from the cache.
|
|
787
831
|
*/
|
|
788
|
-
public clearGLTextures() {
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
this._cache.image[key].base._glTextures = [];
|
|
832
|
+
public clearGLTextures(): void {
|
|
833
|
+
for (const entry of Object.values(this._cache.image)) {
|
|
834
|
+
entry.base._glTextures = [];
|
|
792
835
|
}
|
|
793
836
|
}
|
|
794
837
|
|
|
@@ -798,16 +841,19 @@ export class Cache {
|
|
|
798
841
|
* @param {object} data - The data to associate with the resolved URL.
|
|
799
842
|
* @returns {string} The resolved URL or null if not enabled.
|
|
800
843
|
*/
|
|
801
|
-
public _resolveURL(url: string, data:
|
|
844
|
+
public _resolveURL(url: string, data: object | null = null): string | null {
|
|
802
845
|
if (!this.autoResolveURL) {
|
|
803
846
|
return null;
|
|
804
847
|
}
|
|
848
|
+
if (!this._urlResolver) {
|
|
849
|
+
return null;
|
|
850
|
+
}
|
|
805
851
|
this._urlResolver.src = this.game.load.baseURL + url;
|
|
806
852
|
this._urlTemp = this._urlResolver.src;
|
|
807
853
|
// Ensure no request is actually made
|
|
808
854
|
this._urlResolver.src = '';
|
|
809
855
|
// Record the URL to the map
|
|
810
|
-
if (data) {
|
|
856
|
+
if (data && this._urlMap) {
|
|
811
857
|
this._urlMap[this._urlTemp] = data;
|
|
812
858
|
}
|
|
813
859
|
return this._urlTemp;
|
|
@@ -816,14 +862,12 @@ export class Cache {
|
|
|
816
862
|
/**
|
|
817
863
|
* Destroys the cache and cleans up resources.
|
|
818
864
|
*/
|
|
819
|
-
public destroy() {
|
|
865
|
+
public destroy(): void {
|
|
820
866
|
for (const cache of this._cacheMap) {
|
|
821
867
|
const keys = cache ? Object.keys(cache) : [];
|
|
822
868
|
for (const key of keys) {
|
|
823
869
|
if (key !== '__default' && key !== '__missing') {
|
|
824
|
-
|
|
825
|
-
cache[key].destroy();
|
|
826
|
-
}
|
|
870
|
+
(cache[key] as { destroy?: () => void }).destroy?.();
|
|
827
871
|
delete cache[key];
|
|
828
872
|
}
|
|
829
873
|
}
|