UNPKG

@pixi/assets

Version:

Asset manager for PixiJS, loading resolving and Cacheing

1 lines 1.91 kB
{"version":3,"file":"createTexture.mjs","sources":["../../../../../src/loader/parsers/textures/utils/createTexture.ts"],"sourcesContent":["import { Texture } from '@pixi/core';\nimport { Cache } from '../../../../cache/Cache';\n\nimport type { BaseTexture } from '@pixi/core';\nimport type { Loader } from '../../../Loader';\n\nexport function createTexture(base: BaseTexture, loader: Loader, url: string)\n{\n // make sure the resource is destroyed when the base texture is destroyed\n base.resource.internal = true;\n\n const texture = new Texture(base);\n const unload = () =>\n {\n delete loader.promiseCache[url];\n\n if (Cache.has(url))\n {\n Cache.remove(url);\n }\n };\n\n // remove the promise from the loader and the url from the cache when the texture is destroyed\n texture.baseTexture.once('destroyed', () =>\n {\n if (url in loader.promiseCache)\n {\n console.warn('[Assets] A BaseTexture managed by Assets was destroyed instead of unloaded! '\n + 'Use Assets.unload() instead of destroying the BaseTexture.');\n unload();\n }\n });\n texture.once('destroyed', () =>\n {\n if (!base.destroyed)\n {\n console.warn('[Assets] A Texture managed by Assets was destroyed instead of unloaded! '\n + 'Use Assets.unload() instead of destroying the Texture.');\n unload();\n }\n });\n\n return texture;\n}\n"],"names":[],"mappings":";;AAMgB,SAAA,cAAc,MAAmB,QAAgB,KACjE;AAEI,OAAK,SAAS,WAAW;AAEzB,QAAM,UAAU,IAAI,QAAQ,IAAI,GAC1B,SAAS,MACf;AACW,WAAA,OAAO,aAAa,GAAG,GAE1B,MAAM,IAAI,GAAG,KAEb,MAAM,OAAO,GAAG;AAAA,EAAA;AAKhB,SAAA,QAAA,YAAY,KAAK,aAAa,MACtC;AACQ,WAAO,OAAO,iBAEd,QAAQ,KAAK,wIACqD,GAClE,OAAO;AAAA,EAEd,CAAA,GACD,QAAQ,KAAK,aAAa,MAC1B;AACS,SAAK,cAEN,QAAQ,KAAK,gIACiD,GAC9D,OAAO;AAAA,EAEd,CAAA,GAEM;AACX;"}