duckengine
Version:
A 2D Game Engine for the web.
145 lines (144 loc) • 5.74 kB
TypeScript
import { Duck } from '../..';
import Game from '../game';
import Scene from '../scene';
import TextureBase from '../texture/textureBase';
/**
* @class Loader
* @classdesc A class that loads images and other assets
* @description The Loader Class. Preloading and loading is handled here
* @since 1.0.0-beta
*/
export default class Loader {
/**
* @memberof Loader
* @description Game instance
* @type Game
* @since 1.0.0-beta
*/
game: Game;
/**
* @memberof Loader
* @description Scene instance
* @type Scene
* @since 2.0.0
*/
scene: Scene;
/**
* @memberof Loader
* @description An array of loaded Textures
* @type Duck.Types.Loader.TextureStackItem<TextureBase<'image'>>[]
* @since 2.0.0
*/
textureStack: Duck.Types.Loader.TextureStackItem<TextureBase<'image'>>[];
/**
* @memberof Loader
* @description An array of loaded JSON files
* @type Duck.Types.Loader.StackItem<Record<string, unknown>>[]
* @since 2.0.0
*/
jsonStack: Duck.Types.Loader.StackItem<Record<string, unknown>>[];
/**
* @memberof Loader
* @description An array of loaded HTML Documents
* @type Duck.Types.Loader.StackItem<Document>[]
* @since 2.0.0
*/
htmlStack: Duck.Types.Loader.StackItem<Document>[];
/**
* @memberof Loader
* @description An array of loaded XML Documents
* @type Duck.Types.Loader.StackItem<Document>[]
* @since 2.0.0
*/
xmlStack: Duck.Types.Loader.StackItem<Document>[];
/**
* @memberof Loader
* @description An array of loaded FontFaces
* @type Duck.Types.Loader.StackItem<FontFace>[]
* @since 2.0.0
*/
fontStack: Duck.Types.Loader.StackItem<FontFace>[];
/**
* @memberof Loader
* @description An array of loaded Audio elements
* @type Duck.Types.Loader.StackItem<HTMLAudioElement>[]
* @since 2.0.0
*/
audioStack: Duck.Types.Loader.StackItem<HTMLAudioElement>[];
/**
* @constructor Loader
* @description Creates a Loader instance
* @param {Game} game Game instance
* @param {Scene} scene Scene instance
* @since 1.0.0-beta
*/
constructor(game: Game, scene: Scene);
protected tryCache(prefix: string, key: string): Promise<string | null | undefined>;
protected saveCache(prefix: string, key: string, value: string): Promise<void>;
/**
* @memberof Loader
* @description Loads an image and creates a texture, caches it if it does not already exist in the cache (clear cache if texture does not update
* if you edit the image src)
* @param {string} pathOrURL Path to the file or the URL
* @param {string} key Key of the texture, used to load the texture in sprites
* @param {number} w Width of image
* @param {number} h Height of image
* @since 2.0.0
*/
loadTexture(pathOrURL: string, key: string, w: number, h: number): Promise<HTMLImageElement>;
/**
* @memberof Loader
* @description Loads an image and creates a texture sheet, caches it if it does not already exist in the cache (clear cache if texture does not update
* if you edit the image src)
* @param {string} pathOrURL Path to the file or the URL
* @param {string} key Key of the texture, used to load the texture in sprites and spritesheet
* @param {number} w Width of image
* @param {number} h Height of image
* @since 2.1.0
*/
loadTextureSheet(pathOrURL: string, key: string, frameWidth: number, frameHeight: number, rows: number, cols: number): Promise<HTMLImageElement>;
loadTextureAtlas(atlasKey: string, texturePathOrURL: string, jsonPathOrURL: string, textureKey: string, jsonKey: string, imageW: number, imageH: number): Promise<void>;
/**
* @memberof Loader
* @description Loads a JSON file and adds it to the jsonStack, caches it if it does not already exist
* @param {string} pathOrURL Path to the file or the URL
* @param {string} key Key of the file to use to save it as
* @since 2.0.0
*/
loadJSON(pathOrURL: string, key: string): Promise<Record<string, unknown>>;
/**
* @memberof Loader
* @description Loads a HTML file and adds it to the htmlStack
* @param {string} pathOrURL Path to the file or the URL
* @param {string} key Key of the file to use to save it as
* @since 2.0.0
*/
loadHTML(pathOrURL: string, key: string): Promise<Document>;
/**
* @memberof Loader
* @description Loads a XML file and adds it to the xmlStack
* @param {string} pathOrURL Path to the file or the URL
* @param {string} key Key of the file to use to save it as
* @since 2.0.0
*/
loadXML(pathOrURL: string, key: string): Promise<Document>;
/**
* @memberof Loader
* @description Loads a font and adds it to the fontStack
* @param {string} fontFamily Font Family
* @param {string} pathOrURL Path to the file or the URL
* @param {string} key Key of the file to use to save it as
* @param {FontFaceDescriptors} [descriptors] Font Face Descriptors
* @since 2.0.0
*/
loadFont(fontFamily: string, pathOrURL: string, key: string, descriptors?: FontFaceDescriptors): Promise<FontFace>;
/**
* @memberof Loader
* @description Loads an Audio file and adds it to the audioStack
* @param {string} pathOrURL Path to the file or the URL
* @param {string} key Key of the file to use to save it as
* @param {string} [mimeType] The mime type of the file, optional -> default: 'audio/mp3'
* @since 2.0.0
*/
loadAudio(pathOrURL: string, key: string, mimeType?: string): Promise<HTMLAudioElement>;
}