playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
79 lines (78 loc) • 2.72 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
class ResourceHandler {
/**
* @param {AppBase} app - The running {@link AppBase}.
* @param {string} handlerType - The type of the resource the handler handles.
*/
constructor(app, handlerType) {
/**
* Type of the resource the handler handles.
*/
__publicField(this, "handlerType", "");
/**
* The running app instance.
*
* @type {AppBase}
*/
__publicField(this, "_app");
/** @private */
__publicField(this, "_maxRetries", 0);
this._app = app;
this.handlerType = handlerType;
}
/**
* Sets the number of times to retry a failed request for the resource.
*
* @type {number}
*/
set maxRetries(value) {
this._maxRetries = value;
}
/**
* Gets the number of times to retry a failed request for the resource.
*
* @type {number}
*/
get maxRetries() {
return this._maxRetries;
}
/**
* Load a resource from a remote URL. The base implementation does nothing.
*
* @param {string | {load: string, original: string}} url - Either the URL of the resource to
* load or a structure containing the load URL (used for loading the resource) and the original
* URL (used for identifying the resource format; necessary when loading, for example, from
* a blob URL).
* @param {ResourceHandlerCallback} callback - The callback used when the resource is loaded or
* an error occurs.
* @param {Asset} [asset] - Optional asset that is passed by ResourceLoader.
*/
load(url, callback, asset) {
}
/**
* The open function is passed the raw resource data. The handler can then process the data
* into a format that can be used at runtime. The base implementation simply returns the data.
*
* @param {string} url - The URL of the resource to open.
* @param {*} data - The raw resource data passed by callback from {@link load}.
* @param {Asset} [asset] - Optional asset that is passed by ResourceLoader.
* @returns {*} The parsed resource data.
*/
open(url, data, asset) {
return data;
}
/**
* The patch function performs any operations on a resource that requires a dependency on its
* asset data or any other asset data. The base implementation does nothing.
*
* @param {Asset} asset - The asset to patch.
* @param {AssetRegistry} assets - The asset registry.
*/
patch(asset, assets) {
}
}
export {
ResourceHandler
};