import type { TextureSource } from '../display/webgl/base_texture.js'; import { BaseTexture } from '../display/webgl/base_texture.js'; import { Frame } from './frame.js'; import { FrameData } from './frame_data.js'; import { Signal } from './signal.js'; import type { BitmapFontData } from './loader_parser.js'; import type { Game } from './game.js'; export declare const CANVAS = 0; export declare const IMAGE = 1; export declare const TEXTURE = 2; export declare const SOUND = 3; export declare const TEXT = 4; export declare const BITMAPDATA = 5; export declare const BITMAPFONT = 6; export declare const JSONDATA = 7; export declare const XML = 8; export declare const RENDER_TEXTURE = 9; /** An image, sprite sheet or texture atlas: the source bitmap and the frames cut from it. */ export type ImageCacheEntry = { key: string; url: string; data: TextureSource; base: BaseTexture; frame?: Frame; frameData: FrameData | null; }; /** Audio as the cache holds it: the raw bytes on load, an AudioBuffer once decoded. */ export type SoundData = ArrayBuffer | AudioBuffer; /** A sound and how far its decoding has got. */ export type SoundCacheEntry = { url: string; data: SoundData; isDecoding: boolean; decoded: boolean; }; /** A bitmap font: the glyph atlas and the descriptor parsed from it. */ export type BitmapFontCacheEntry = { url: string; data: TextureSource; font: BitmapFontData; base: BaseTexture; }; /** A text, JSON or XML payload under the URL it came from. */ export type DataCacheEntry = { url: string; data: T; }; /** Anything the cache can hold, whichever bucket it lives in. */ export type CacheEntry = ImageCacheEntry | SoundCacheEntry | BitmapFontCacheEntry | DataCacheEntry; interface CacheBuckets { canvas: Record; image: Record; texture: Record; sound: Record; text: Record>; json: Record>; xml: Record>; bitmapData: Record; bitmapFont: Record; renderTexture: Record; } export declare class Cache { game: Game; autoResolveURL: boolean; _cache: CacheBuckets; _urlMap: Record | null; _urlResolver: HTMLImageElement | null; _urlTemp: string | null; onSoundUnlock: Signal; _cacheMap: Record[]; /** * Creates a new Cache instance. * @param {Game} game - The game instance. */ constructor(game: Game); /** * Adds the default image to the cache. */ addDefaultImage(): void; /** * Adds the missing image to the cache. */ addMissingImage(): void; /** * Adds an image to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the image was loaded from. * @param {HTMLImageElement} data - The image data to cache. * @returns {object} The cached image object. */ addImage(key: string, url: string | null, data: HTMLImageElement): ImageCacheEntry; /** * Adds a sprite sheet to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the sprite sheet was loaded from. * @param {HTMLImageElement} data - The image data to cache. * @param {number} frameWidth - The width of each frame in the sprite sheet. * @param {number} frameHeight - The height of each frame in the sprite sheet. * @param {number} frameMax - The maximum number of frames to parse (-1 for all). * @param {number} margin - The margin around each frame in pixels. * @param {number} spacing - The spacing between frames in pixels. */ addSpriteSheet(key: string, url: string, data: HTMLImageElement, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number): void; /** * Adds a texture atlas to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the atlas was loaded from. * @param {HTMLCanvasElement} data - The canvas data for the atlas. * @param {object} atlasData - The atlas data to cache. */ addTextureAtlas(key: string, url: string, data: TextureSource, atlasData: unknown): void; /** * Adds sound data to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the sound was loaded from. * @param {object} data - The sound data to cache. */ addSound(key: string, url: string, data: SoundData): void; /** * Adds text data to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the text was loaded from. * @param {string} data - The text data to cache. */ addText(key: string, url: string, data: string): void; /** * Adds a bitmap font to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the bitmap font was loaded from. * @param {HTMLCanvasElement} data - The canvas data for the font. * @param {object} atlasData - The bitmap font atlas data to cache. * @param {string} atlasType - The type of the atlas data ('json' or 'xml'). * @param {number} xSpacing - Horizontal spacing between characters. * @param {number} ySpacing - Vertical spacing between characters. */ addBitmapFont(key: string, url: string, data: TextureSource, atlasData: unknown, atlasType: string, xSpacing?: number, ySpacing?: number): void; /** * Adds JSON data to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the JSON was loaded from. * @param {object} data - The JSON data to cache. */ addJSON(key: string, url: string, data: unknown): void; /** * Adds XML data to the cache. * @param {string} key - The unique key for this cache entry. * @param {string} url - The URL the XML was loaded from. * @param {XMLDocument} data - The XML data to cache. */ addXML(key: string, url: string, data: XMLDocument): void; /** * Updates a sound property in the cache. * @param {string} key - The unique key for the cached sound. * @param {string} property - The property to update. * @param {any} value - The new value for the property. */ updateSound(key: string, property: K, value: SoundCacheEntry[K]): void; /** * Marks a sound as decoded in the cache. * @param {string} key - The unique key for the cached sound. * @param {AudioBuffer} data - The decoded audio buffer. */ decodedSound(key: string, data: AudioBuffer): void; /** * Checks if a sound has been decoded in the cache. * @param {string} key - The unique key for the cached sound. * @returns {boolean} True if the sound is decoded, false otherwise. */ isSoundDecoded(key: string): boolean | null; /** * Checks if a sound is ready to play (decoded and not locked). * @param {string} key - The unique key for the cached sound. * @returns {boolean} True if the sound is ready, false otherwise. */ isSoundReady(key: string): boolean; /** * Checks if a cache entry exists. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkKey(cache: number, key: string): boolean; /** * Checks if a URL has been resolved and cached. * @param {string} url - The URL to check. * @returns {boolean} True if the URL has been resolved and cached, false otherwise. */ checkURL(url: string): boolean; /** * Checks if a canvas cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkCanvasKey(key: string): boolean; /** * Checks if an image cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkImageKey(key: string): boolean; /** * Checks if a texture cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkTextureKey(key: string): boolean; /** * Checks if a sound cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkSoundKey(key: string): boolean; /** * Checks if a text cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkTextKey(key: string): boolean; /** * Checks if a bitmap data cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkBitmapDataKey(key: string): boolean; /** * Checks if a bitmap font cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkBitmapFontKey(key: string): boolean; /** * Checks if a JSON cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkJSONKey(key: string): boolean; /** * Checks if an XML cache entry exists. * @param {string} key - The unique key for the cache entry. * @returns {boolean} True if the entry exists, false otherwise. */ checkXMLKey(key: string): boolean; /** * TBD. * @param {string} key - TBD. * @param {number} cache - TBD. * @param {string} _method - TBD. * @param {string} property - TBD. * @returns {*} TBD. */ getItem(key: string, cache: number, _method: string, property?: string | null): unknown; /** * TBD. * @param {string} key - TBD. * @returns {HTMLCanvasElement} TBD. */ getCanvas(key: string): HTMLCanvasElement | null; /** * TBD. * @param {string} key - TBD. * @param {boolean} full - TBD. * @returns {HTMLImageElement} TBD. */ getImage(key?: string | number, full?: false): TextureSource; getImage(key: string | number | undefined, full: true): ImageCacheEntry; /** * TBD. * @param {string} key - TBD. * @returns {object} TBD. */ getTextureFrame(key: string): Frame | null; /** * TBD. * @param {string} key - TBD. * @returns {object} TBD. */ getSound(key: string): SoundCacheEntry | null; /** * TBD. * @param {string} key - TBD. * @returns {object} TBD. */ getSoundData(key: string): SoundData | null; /** * TBD. * @param {string} key - TBD. * @returns {object} TBD. */ getText(key: string): string | null; /** * TBD. * @param {string} key - TBD. * @returns {object} TBD. */ getBitmapData(key: string): unknown; /** * TBD. * @param {string} key - TBD. * @returns {object} TBD. */ getBitmapFont(key: string): BitmapFontCacheEntry | null; /** * Gets JSON data from the cache. * @template T * @param {string} key - The unique key for the cache entry. * @param {boolean} isClone - Whether to return a deep clone of the cached data. * @returns {T} The cached JSON data. */ getJSON(key: string, isClone?: boolean): T; /** * TBD. * @param {string} key - TBD. * @returns {XMLDocument} TBD. */ getXML(key: string): XMLDocument | null; /** * TBD. * @param {string} key - TBD. * @returns {RenderTexture} TBD. */ getRenderTexture(key: string): CacheEntry | null; /** * Gets the base texture of a cache entry. * @param {string} key - The unique key for the cache entry. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {BaseTexture} The base texture. */ getBaseTexture(key: string, cache?: number): BaseTexture | null; /** * Gets a frame from the cache. * @param {string} key - The unique key for the cache entry. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {Frame} The frame. */ getFrame(key: string, cache?: number): Frame | null; /** * Gets the frame count of a cache entry. * @param {string} key - The unique key for the cache entry. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {number} The number of frames. */ getFrameCount(key: string, cache?: number): number; /** * Gets the frame data of a cache entry. * @param {string} key - The unique key for the cache entry. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {FrameData | null} The frame data, or null when the entry has none. */ getFrameData(key: string, cache?: number): FrameData | null; /** * Checks if a cache entry has frame data. * @param {string} key - The unique key for the cache entry. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {boolean} True if the entry has frame data, false otherwise. */ hasFrameData(key: string, cache?: number): boolean; /** * Updates the frame data of a cache entry. * @param {string} key - The unique key for the cache entry. * @param {FrameData} frameData - The new frame data. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). */ updateFrameData(key: string, frameData: FrameData, cache?: number): void; /** * Gets a frame by index from the cache. * @param {string} key - The unique key for the cache entry. * @param {number} index - The index of the frame to get. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {Frame} The frame at the specified index. */ getFrameByIndex(key: string, index: number, cache?: number): Frame | null; /** * Gets a frame by name from the cache. * @param {string} key - The unique key for the cache entry. * @param {string} name - The name of the frame to get. * @param {number} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {Frame} The frame with the specified name. */ getFrameByName(key: string, name: string, cache?: number): Frame | null; /** * Gets the resolved URL from cache. * @param {string} url - The original URL to resolve. * @returns {string} The resolved URL or null if not found. */ getURL(url: string): object | null; /** * Gets all keys from a cache type. * @param {object} cache - The cache type (CANVAS, IMAGE, etc.). * @returns {string[]} An array of cache keys. */ getKeys(cache?: number): string[]; /** * Removes a canvas cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeCanvas(key: string): void; /** * Removes an image cache entry. * @param {string} key - The unique key for the cache entry to remove. * @param {boolean} destroyBaseTexture - Whether to destroy the base texture (default: true). */ removeImage(key: string, destroyBaseTexture?: boolean): void; /** * Removes a sound cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeSound(key: string): void; /** * Removes a text cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeText(key: string): void; /** * Removes a bitmap data cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeBitmapData(key: string): void; /** * Removes a bitmap font cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeBitmapFont(key: string): void; /** * Removes a JSON cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeJSON(key: string): void; /** * Removes an XML cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeXML(key: string): void; /** * Removes a render texture cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeRenderTexture(key: string): void; /** * Removes a sprite sheet cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeSpriteSheet(key: string): void; /** * Removes a texture atlas cache entry. * @param {string} key - The unique key for the cache entry to remove. */ removeTextureAtlas(key: string): void; /** * Clears all GL textures from the cache. */ clearGLTextures(): void; /** * Resolves a URL and stores it in the cache. * @param {string} url - The URL to resolve. * @param {object} data - The data to associate with the resolved URL. * @returns {string} The resolved URL or null if not enabled. */ _resolveURL(url: string, data?: object | null): string | null; /** * Destroys the cache and cleans up resources. */ destroy(): void; } export {}; //# sourceMappingURL=cache.d.ts.map