101 lines
2.8 KiB
TypeScript
101 lines
2.8 KiB
TypeScript
|
|
/// <reference types="node" />
|
||
|
|
import { EventEmitter } from 'events';
|
||
|
|
import Task from './tasks/Task';
|
||
|
|
import { Complete } from './tasks/Task';
|
||
|
|
import AssetManager from './AssetManager';
|
||
|
|
import AssetToken from './AssetToken';
|
||
|
|
export interface Asset {
|
||
|
|
id?: string;
|
||
|
|
cache?: string;
|
||
|
|
complete?: Complete;
|
||
|
|
remote?: boolean;
|
||
|
|
timeout?: number;
|
||
|
|
format?: string;
|
||
|
|
type?: string;
|
||
|
|
instance?: boolean;
|
||
|
|
src?: string;
|
||
|
|
}
|
||
|
|
export interface ITaskDefinition {
|
||
|
|
test: (asset: Asset) => boolean;
|
||
|
|
priority: number;
|
||
|
|
prototype: any;
|
||
|
|
new (manager: AssetManager, asset: Asset): Task;
|
||
|
|
}
|
||
|
|
export interface SetupOptions {
|
||
|
|
maxLoads?: number;
|
||
|
|
autoStart?: boolean;
|
||
|
|
cacheAll?: string;
|
||
|
|
remoteAll?: boolean;
|
||
|
|
timeoutAll?: number;
|
||
|
|
}
|
||
|
|
export interface AssetResult {
|
||
|
|
result?: any;
|
||
|
|
subAssets?: AssetToken[];
|
||
|
|
token: AssetToken;
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Class that represents a single multi load.
|
||
|
|
* @class AssetLoad
|
||
|
|
* @memberof jibo.loader
|
||
|
|
*/
|
||
|
|
declare class AssetLoad extends EventEmitter {
|
||
|
|
manager: AssetManager;
|
||
|
|
id: number;
|
||
|
|
mode: number;
|
||
|
|
maxLoads: number;
|
||
|
|
tasks: Array<Task>;
|
||
|
|
results: any;
|
||
|
|
running: boolean;
|
||
|
|
numLoaded: number;
|
||
|
|
numLoading: number;
|
||
|
|
total: number;
|
||
|
|
cacheAll: string;
|
||
|
|
remoteAll: boolean;
|
||
|
|
timeoutAll: number;
|
||
|
|
loadedTokens: AssetToken[];
|
||
|
|
/**
|
||
|
|
* When an asset is finished.
|
||
|
|
* @event jibo.loader.AssetLoad#taskDone
|
||
|
|
* @param {*} result The loader result.
|
||
|
|
* @param {object} originalAsset The original load asset.
|
||
|
|
* @param {jibo.loader.AssetLoad} load This loader to add additional assets to.
|
||
|
|
*/
|
||
|
|
/**
|
||
|
|
* When all assets have been completely loaded.
|
||
|
|
* @event jibo.loader.AssetLoad#complete
|
||
|
|
* @param {Array|Object} results The results of load.
|
||
|
|
*/
|
||
|
|
/**
|
||
|
|
* Checks how many assets have finished loading.
|
||
|
|
* @event jibo.loader.AssetLoad#progress
|
||
|
|
* @param {number} percentage The amount loaded from 0 to 1.
|
||
|
|
*/
|
||
|
|
/**
|
||
|
|
* List of AssetToken objects for all loads that will be or have been performed.
|
||
|
|
* @type {jibo.loader.AssetToken[]}
|
||
|
|
* @name jibo.loader.AssetLoad#tokens
|
||
|
|
*/
|
||
|
|
readonly tokens: AssetToken[];
|
||
|
|
/**
|
||
|
|
* Cancel the load progress.
|
||
|
|
* @method jibo.loader.AssetLoad#cancel
|
||
|
|
*/
|
||
|
|
cancel(): void;
|
||
|
|
/**
|
||
|
|
* Starts the load process.
|
||
|
|
* @method jibo.loader.AssetLoad#start
|
||
|
|
*/
|
||
|
|
start(): void;
|
||
|
|
/**
|
||
|
|
* Adds loads to an ongoing load. Call this during callbacks/events for individual task
|
||
|
|
* completion.
|
||
|
|
* @method jibo.loader.AssetLoad#addAssets
|
||
|
|
* @param {Object|Array} assets The assets to load.
|
||
|
|
* @return {jibo.loader.AssetToken[]} The asset tokens of the newly added assets (if they are cached).
|
||
|
|
*/
|
||
|
|
addAssets(assets: Asset | Array<Asset> | {
|
||
|
|
[id: string]: Asset;
|
||
|
|
}): AssetToken[];
|
||
|
|
}
|
||
|
|
export default AssetLoad;
|