UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

101 lines (100 loc) 2.42 kB
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); import { EventHandler } from "../../core/event-handler.js"; class Bundle extends EventHandler { constructor() { super(...arguments); /** * Index of file url to DataView. * * @type {Map<string, DataView>} * @private */ __publicField(this, "_index", /* @__PURE__ */ new Map()); /** * If Bundle has all files loaded. * * @private */ __publicField(this, "_loaded", false); } /** * Add file to a Bundle. * * @param {string} url - A url of a file. * @param {DataView} data - A DataView of a file. * @ignore */ addFile(url, data) { if (this._index.has(url)) { return; } this._index.set(url, data); this.fire("add", url, data); } /** * Returns true if the specified URL exists in the loaded bundle. * * @param {string} url - The original file URL. Make sure you have called decodeURIComponent on * the URL first. * @returns {boolean} True of false. */ has(url) { return this._index.has(url); } /** * Returns a DataView for the specified URL. * * @param {string} url - The original file URL. Make sure you have called decodeURIComponent on * the URL first. * @returns {DataView|null} A DataView. */ get(url) { return this._index.get(url) || null; } /** * Destroys the bundle. */ destroy() { this._index.clear(); } /** * True if all files of a Bundle are loaded. * * @type {boolean} */ set loaded(value) { if (!value || this._loaded) { return; } this._loaded = true; this.fire("load"); } get loaded() { return this._loaded; } } /** * Fired when a file has been added to a Bundle. * * @event * @example * bundle.on("add", (url, data) => { * console.log("file added: " + url); * }); */ __publicField(Bundle, "EVENT_ADD", "add"); /** * Fired when all files of a Bundle has been loaded. * * @event * @example * bundle.on("load", () => { * console.log("All Bundle files has been loaded"); * }); */ __publicField(Bundle, "EVENT_LOAD", "load"); export { Bundle };