Files
Foundry-VTT-Docker/resources/app/node_modules/@pixi/assets/lib/loader/Loader.mjs.map

1 line
12 KiB
Plaintext
Raw Normal View History

2025-01-04 00:34:03 +01:00
{"version":3,"file":"Loader.mjs","sources":["../../src/loader/Loader.ts"],"sourcesContent":["import { utils } from '@pixi/core';\nimport { convertToList, isSingleItem } from '../utils';\n\nimport type { ResolvedAsset } from '../types';\nimport type { LoaderParser } from './parsers/LoaderParser';\nimport type { PromiseAndParser } from './types';\n\n/**\n * The Loader is responsible for loading all assets, such as images, spritesheets, audio files, etc.\n * It does not do anything clever with URLs - it just loads stuff!\n * Behind the scenes all things are cached using promises. This means it's impossible to load an asset more than once.\n * Through the use of LoaderParsers, the loader can understand how to load any kind of file!\n *\n * It is not intended that this class is created by developers - its part of the Asset class\n * This is the second major system of PixiJS' main Assets class\n * @memberof PIXI\n * @class AssetLoader\n */\nexport class Loader\n{\n private _parsers: LoaderParser[] = [];\n private _parserHash: Record<string, LoaderParser>;\n\n private _parsersValidated = false;\n\n /** All loader parsers registered */\n public parsers = new Proxy(this._parsers, {\n set: (target, key, value) =>\n {\n this._parsersValidated = false;\n\n target[key as any as number] = value;\n\n return true;\n }\n });\n\n /** Cache loading promises that ae currently active */\n public promiseCache: Record<string, PromiseAndParser> = {};\n\n /** function used for testing */\n public reset(): void\n {\n this._parsersValidated = false;\n this.promiseCache = {};\n }\n\n /**\n * Used internally to generate a promise for the asset to be loaded.\n * @param url - The URL to be loaded\n * @param data - any custom additional information relevant to the asset being loaded\n * @returns - a promise that will resolve to an Asset for example a Texture of a JSON object\n */\n private _getLoadPromiseAndParser(url: string, data?: ResolvedAsset): PromiseAndParser\n {\n const result: PromiseAndParser = {\n promise: null,\n parser: null\n };\n\n result.promise = (async () =>\n {\n let asset = null;\n\n let parser: LoaderParser = null;\n\n // first check to see if the user has specified a parser\n if (data.loadParser)\n {\n // they have? lovely, lets use it\n parser = this._parserHash[data.loadParser];\n\n if (!parser)\n {\n if (process.env.DEBUG)\n {\n // eslint-disable-next-line max-len\n console.warn(`[Assets] specified load parser \"${data.loadParser}\" not found while loading ${url}`);\n }\n }\n }\n\n // no parser specified, so lets try and find one using the tests\n if (!parser)\n {\n for (let i = 0; i < this.parsers.length; i++)\n {\n const parserX = this.parsers[i];\n\n if (parserX.load && parserX.test?.(url, data, this))\n {\n parser = parserX;\n break;\n }\n }\n\n if (!parser)\n {\n if (process.env.DEBUG)\n {\n // eslint-disable-next-line max-len\n console.warn(`[Assets] ${url} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`);\n }\n\n return null;\n }\n }\n\n asset = await parser.load(url, data, this);\n result.parser = parser;\n\n for (let i = 0; i < this.parsers.length; i++)\n {\n const parser = this.parsers[i];\n\n if (parser.par