gdcore-tools 2.0.0-gd-v5.4.217-autobuild → 2.0.0-gd-v5.4.218-autobuild
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Runtime/Extensions/3D/JsExtension.js +7 -3
- package/dist/Runtime/Extensions/DialogueTree/JsExtension.js +44 -32
- package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js +2 -2
- package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/JsExtension.js +15 -0
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js +1 -1
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js +1 -1
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js.map +2 -2
- package/dist/Runtime/Model3DManager.js +1 -1
- package/dist/Runtime/Model3DManager.js.map +2 -2
- package/dist/Runtime/ResourceLoader.js +1 -1
- package/dist/Runtime/ResourceLoader.js.map +2 -2
- package/dist/Runtime/capturemanager.js +2 -0
- package/dist/Runtime/capturemanager.js.map +7 -0
- package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js +1 -1
- package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js.map +2 -2
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
- package/dist/Runtime/jsonmanager.js +1 -1
- package/dist/Runtime/jsonmanager.js.map +2 -2
- package/dist/Runtime/layer.js +1 -1
- package/dist/Runtime/layer.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js +1 -1
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/runtimewatermark.js +2 -2
- package/dist/Runtime/runtimewatermark.js.map +2 -2
- package/dist/Runtime/scenestack.js +1 -1
- package/dist/Runtime/scenestack.js.map +2 -2
- package/dist/Runtime/spriteruntimeobject.js +1 -1
- package/dist/Runtime/spriteruntimeobject.js.map +2 -2
- package/dist/lib/libGD.cjs +1 -1
- package/dist/lib/libGD.wasm +0 -0
- package/gd.d.ts +22 -6
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(
|
|
1
|
+
var gdjs;(function(u){const c=["atlas"];class g{constructor(e,s){this._loadedSpineAtlases=new u.ResourceCache;this._loadingSpineAtlases=new u.ResourceCache;this._resourceLoader=e,this._imageManager=s}getResourceKinds(){return c}async processResource(e){}async loadResource(e){await this.getOrLoad(e)}getOrLoad(e){const s=this._getAtlasResource(e);if(!s)return Promise.reject(`Unable to find atlas for resource '${e}'.`);let t=this._loadingSpineAtlases.get(s);return t||(t=new Promise((n,a)=>{const o=(i,r)=>{if(i)return a(`Error while preloading a spine atlas resource: ${i}`);if(!r)return a(`Cannot reach texture atlas for resource '${e}'.`);n(r)};this.load(s,o)}),this._loadingSpineAtlases.set(s,t)),t}load(e,s){const t=this._resourceLoader.getRuntimeGame(),n=t.getEmbeddedResourcesNames(e.name);if(!n.length)return s(new Error(`${e.name} do not have image metadata!`));const a=n.reduce((r,l)=>{const d=t.resolveEmbeddedResource(e.name,l);return r[l]=this._imageManager.getOrLoadPIXITexture(d),r},{}),o=r=>{this._loadedSpineAtlases.set(e,r),s(null,r)},i=this._resourceLoader.getFullUrl(e.file);PIXI.Assets.setPreferences({preferWorkers:!1,crossOrigin:this._resourceLoader.checkIfCredentialsRequired(i)?"use-credentials":"anonymous"}),PIXI.Assets.add(e.name,i,{images:a}),PIXI.Assets.load(e.name).then(r=>{typeof r=="string"?new pixi_spine.TextureAtlas(r,(l,d)=>d(a[l].baseTexture),o):o(r)})}isLoaded(e){return!!this._loadedSpineAtlases.getFromName(e)}getAtlasTexture(e){return this._loadedSpineAtlases.getFromName(e)}_getAtlasResource(e){const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:null}dispose(){this._loadedSpineAtlases.clear(),this._loadingSpineAtlases.clear()}}u.SpineAtlasManager=g})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=pixi-spine-atlas-manager.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../GDevelop/Extensions/Spine/managers/pixi-spine-atlas-manager.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n /** The callback called when a text that was requested is loaded (or an error occurred). */\n export type SpineAtlasManagerRequestCallback = (\n error: Error | null,\n content?: pixi_spine.TextureAtlas\n ) => void;\n\n const atlasKinds: ResourceKind[] = ['atlas'];\n\n /**\n * AtlasManager loads atlas files with pixi loader, using the \"atlas\" resources\n * registered in the game resources and process them to Pixi TextureAtlas.\n *\n * Contrary to audio/fonts, text files are loaded asynchronously, when requested.\n * You should properly handle errors, and give the developer/player a way to know\n * that loading failed.\n */\n export class SpineAtlasManager implements gdjs.ResourceManager {\n private _imageManager: ImageManager;\n private _resourceLoader: ResourceLoader;\n private _loadedSpineAtlases = new gdjs.ResourceCache<\n pixi_spine.TextureAtlas\n >();\n private _loadingSpineAtlases = new gdjs.ResourceCache<\n Promise<pixi_spine.TextureAtlas>\n >();\n\n /**\n * @param resources The resources data of the game.\n * @param resourcesLoader The resources loader of the game.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n imageManager: ImageManager\n ) {\n this._resourceLoader = resourceLoader;\n this._imageManager = imageManager;\n }\n\n getResourceKinds(): ResourceKind[] {\n return atlasKinds;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because pixi-spine parses resources by itself.\n }\n\n async loadResource(resourceName: string): Promise<void> {\n await this.getOrLoad(resourceName);\n }\n\n /**\n * Returns promisified loaded atlas resource if it is availble, loads it otherwise.\n *\n * @param resources The data of resource to load.\n */\n getOrLoad(resourceName: string): Promise<pixi_spine.TextureAtlas> {\n const resource = this._getAtlasResource(resourceName);\n\n if (!resource) {\n return Promise.reject(\n `Unable to find atlas for resource '${resourceName}'.`\n );\n }\n\n let loadingPromise = this._loadingSpineAtlases.get(resource);\n\n if (!loadingPromise) {\n loadingPromise = new Promise<pixi_spine.TextureAtlas>(\n (resolve, reject) => {\n const onLoad: SpineAtlasManagerRequestCallback = (\n error,\n content\n ) => {\n if (error) {\n return reject(\n `Error while preloading a spine atlas resource: ${error}`\n );\n }\n if (!content) {\n return reject(\n `Cannot reach texture atlas for resource '${resourceName}'.`\n );\n }\n\n resolve(content);\n };\n\n this.load(resource, onLoad);\n }\n );\n\n this._loadingSpineAtlases.set(resource, loadingPromise);\n }\n\n return loadingPromise;\n }\n\n /**\n * Load specified atlas resource and pass it to callback once it is loaded.\n *\n * @param resources The data of resource to load.\n * @param callback The callback to pass atlas to it once it is loaded.\n */\n load(\n resource: ResourceData,\n callback: SpineAtlasManagerRequestCallback\n ): void {\n const game = this._resourceLoader.getRuntimeGame();\n const embeddedResourcesNames = game.getEmbeddedResourcesNames(\n resource.name\n );\n\n if (!embeddedResourcesNames.length)\n return callback(\n new Error(`${resource.name} do not have image metadata!`)\n );\n\n const images = embeddedResourcesNames.reduce<{\n [key: string]: PIXI.Texture;\n }>((imagesMap, embeddedResourceName) => {\n const mappedResourceName = game.resolveEmbeddedResource(\n resource.name,\n embeddedResourceName\n );\n imagesMap[\n embeddedResourceName\n ] = this._imageManager.getOrLoadPIXITexture(mappedResourceName);\n\n return imagesMap;\n }, {});\n const onLoad = (atlas: pixi_spine.TextureAtlas) => {\n this._loadedSpineAtlases.set(resource, atlas);\n callback(null, atlas);\n };\n const url = this._resourceLoader.getFullUrl(resource.file);\n\n PIXI.Assets.setPreferences({\n preferWorkers: false,\n crossOrigin: this._resourceLoader.checkIfCredentialsRequired(url)\n ? 'use-credentials'\n : 'anonymous',\n });\n PIXI.Assets.add(resource.name, url, { images });\n PIXI.Assets.load<pixi_spine.TextureAtlas | string>(resource.name).then(\n (atlas) => {\n /**\n * Ideally atlas of TextureAtlas should be passed here\n * but there is known issue in case of preloaded images (see https://github.com/pixijs/spine/issues/537)\n *\n * Here covered all possible ways to make it work fine if issue is fixed in pixi-spine or after migration to spine-pixi\n */\n if (typeof atlas === 'string') {\n new pixi_spine.TextureAtlas(\n atlas,\n (textureName, textureCb) =>\n textureCb(images[textureName].baseTexture),\n onLoad\n );\n } else {\n onLoad(atlas);\n }\n }\n );\n }\n\n /**\n * Check if the given atlas resource was loaded (preloaded or loaded with `load`).\n * @param resourceName The name of the atlas resource.\n * @returns true if the content of the atlas resource is loaded, false otherwise.\n */\n isLoaded(resourceName: string): boolean {\n return !!this._loadedSpineAtlases.getFromName(resourceName);\n }\n\n /**\n * Get the Pixi TextureAtlas for the given resource that is already loaded (preloaded or loaded with `load`).\n * If the resource is not loaded, `null` will be returned.\n * @param resourceName The name of the atlas resource.\n * @returns the TextureAtlas of the atlas if loaded, `null` otherwise.\n */\n getAtlasTexture(resourceName: string): pixi_spine.TextureAtlas | null {\n return this._loadedSpineAtlases.getFromName(resourceName);\n }\n\n private _getAtlasResource(resourceName: string): ResourceData | null {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAOE,KAAM,GAA6B,CAAC,SAU7B,OAAwD,CAc7D,YACE,EACA,EACA,CAdM,yBAAsB,GAAI,GAAK,cAG/B,0BAAuB,GAAI,GAAK,cAYtC,KAAK,gBAAkB,EACvB,KAAK,cAAgB,EAGvB,kBAAmC,CACjC,MAAO,QAGH,iBAAgB,EAAqC,OAIrD,cAAa,EAAqC,CACtD,KAAM,MAAK,UAAU,GAQvB,UAAU,EAAwD,CAChE,KAAM,GAAW,KAAK,kBAAkB,GAExC,GAAI,CAAC,EACH,MAAO,SAAQ,OACb,sCAAsC,OAI1C,GAAI,GAAiB,KAAK,qBAAqB,IAAI,GAEnD,MAAK,IACH,GAAiB,GAAI,SACnB,CAAC,EAAS,IAAW,CACnB,KAAM,GAA2C,CAC/C,EACA,IACG,CACH,GAAI,EACF,MAAO,GACL,kDAAkD,KAGtD,GAAI,CAAC,EACH,MAAO,GACL,4CAA4C,OAIhD,EAAQ,IAGV,KAAK,KAAK,EAAU,KAIxB,KAAK,qBAAqB,IAAI,EAAU,IAGnC,EAST,KACE,EACA,EACM,CACN,KAAM,GAAO,KAAK,gBAAgB,iBAC5B,EAAyB,EAAK,0BAClC,EAAS,MAGX,GAAI,CAAC,EAAuB,OAC1B,MAAO,GACL,GAAI,OAAM,GAAG,EAAS,qCAG1B,KAAM,GAAS,EAAuB,OAEnC,CAAC,EAAW,IAAyB,CACtC,KAAM,GAAqB,EAAK,wBAC9B,EAAS,KACT,GAEF,SACE,GACE,KAAK,cAAc,qBAAqB,GAErC,GACN,IACG,EAAS,AAAC,GAAmC,CACjD,KAAK,oBAAoB,IAAI,EAAU,GACvC,EAAS,KAAM,IAEX,EAAM,KAAK,gBAAgB,WAAW,EAAS,MAErD,KAAK,OAAO,eAAe,CACzB,cAAe,GACf,YAAa,KAAK,gBAAgB,2BAA2B,GACzD,kBACA,cAEN,KAAK,OAAO,IAAI,EAAS,KAAM,EAAK,CAAE,WACtC,KAAK,OAAO,KAAuC,EAAS,MAAM,KAChE,AAAC,GAAU,CAOT,AAAI,MAAO,IAAU,SACnB,GAAI,YAAW,aACb,EACA,CAAC,EAAa,IACZ,EAAU,EAAO,GAAa,aAChC,GAGF,EAAO,KAWf,SAAS,EAA+B,CACtC,MAAO,CAAC,CAAC,KAAK,oBAAoB,YAAY,GAShD,gBAAgB,EAAsD,CACpE,MAAO,MAAK,oBAAoB,YAAY,GAGtC,kBAAkB,EAA2C,CACnE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n /** The callback called when a text that was requested is loaded (or an error occurred). */\n export type SpineAtlasManagerRequestCallback = (\n error: Error | null,\n content?: pixi_spine.TextureAtlas\n ) => void;\n\n const atlasKinds: ResourceKind[] = ['atlas'];\n\n /**\n * AtlasManager loads atlas files with pixi loader, using the \"atlas\" resources\n * registered in the game resources and process them to Pixi TextureAtlas.\n *\n * Contrary to audio/fonts, text files are loaded asynchronously, when requested.\n * You should properly handle errors, and give the developer/player a way to know\n * that loading failed.\n */\n export class SpineAtlasManager implements gdjs.ResourceManager {\n private _imageManager: ImageManager;\n private _resourceLoader: ResourceLoader;\n private _loadedSpineAtlases = new gdjs.ResourceCache<\n pixi_spine.TextureAtlas\n >();\n private _loadingSpineAtlases = new gdjs.ResourceCache<\n Promise<pixi_spine.TextureAtlas>\n >();\n\n /**\n * @param resources The resources data of the game.\n * @param resourcesLoader The resources loader of the game.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n imageManager: ImageManager\n ) {\n this._resourceLoader = resourceLoader;\n this._imageManager = imageManager;\n }\n\n getResourceKinds(): ResourceKind[] {\n return atlasKinds;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because pixi-spine parses resources by itself.\n }\n\n async loadResource(resourceName: string): Promise<void> {\n await this.getOrLoad(resourceName);\n }\n\n /**\n * Returns promisified loaded atlas resource if it is availble, loads it otherwise.\n *\n * @param resources The data of resource to load.\n */\n getOrLoad(resourceName: string): Promise<pixi_spine.TextureAtlas> {\n const resource = this._getAtlasResource(resourceName);\n\n if (!resource) {\n return Promise.reject(\n `Unable to find atlas for resource '${resourceName}'.`\n );\n }\n\n let loadingPromise = this._loadingSpineAtlases.get(resource);\n\n if (!loadingPromise) {\n loadingPromise = new Promise<pixi_spine.TextureAtlas>(\n (resolve, reject) => {\n const onLoad: SpineAtlasManagerRequestCallback = (\n error,\n content\n ) => {\n if (error) {\n return reject(\n `Error while preloading a spine atlas resource: ${error}`\n );\n }\n if (!content) {\n return reject(\n `Cannot reach texture atlas for resource '${resourceName}'.`\n );\n }\n\n resolve(content);\n };\n\n this.load(resource, onLoad);\n }\n );\n\n this._loadingSpineAtlases.set(resource, loadingPromise);\n }\n\n return loadingPromise;\n }\n\n /**\n * Load specified atlas resource and pass it to callback once it is loaded.\n *\n * @param resources The data of resource to load.\n * @param callback The callback to pass atlas to it once it is loaded.\n */\n load(\n resource: ResourceData,\n callback: SpineAtlasManagerRequestCallback\n ): void {\n const game = this._resourceLoader.getRuntimeGame();\n const embeddedResourcesNames = game.getEmbeddedResourcesNames(\n resource.name\n );\n\n if (!embeddedResourcesNames.length)\n return callback(\n new Error(`${resource.name} do not have image metadata!`)\n );\n\n const images = embeddedResourcesNames.reduce<{\n [key: string]: PIXI.Texture;\n }>((imagesMap, embeddedResourceName) => {\n const mappedResourceName = game.resolveEmbeddedResource(\n resource.name,\n embeddedResourceName\n );\n imagesMap[\n embeddedResourceName\n ] = this._imageManager.getOrLoadPIXITexture(mappedResourceName);\n\n return imagesMap;\n }, {});\n const onLoad = (atlas: pixi_spine.TextureAtlas) => {\n this._loadedSpineAtlases.set(resource, atlas);\n callback(null, atlas);\n };\n const url = this._resourceLoader.getFullUrl(resource.file);\n\n PIXI.Assets.setPreferences({\n preferWorkers: false,\n crossOrigin: this._resourceLoader.checkIfCredentialsRequired(url)\n ? 'use-credentials'\n : 'anonymous',\n });\n PIXI.Assets.add(resource.name, url, { images });\n PIXI.Assets.load<pixi_spine.TextureAtlas | string>(resource.name).then(\n (atlas) => {\n /**\n * Ideally atlas of TextureAtlas should be passed here\n * but there is known issue in case of preloaded images (see https://github.com/pixijs/spine/issues/537)\n *\n * Here covered all possible ways to make it work fine if issue is fixed in pixi-spine or after migration to spine-pixi\n */\n if (typeof atlas === 'string') {\n new pixi_spine.TextureAtlas(\n atlas,\n (textureName, textureCb) =>\n textureCb(images[textureName].baseTexture),\n onLoad\n );\n } else {\n onLoad(atlas);\n }\n }\n );\n }\n\n /**\n * Check if the given atlas resource was loaded (preloaded or loaded with `load`).\n * @param resourceName The name of the atlas resource.\n * @returns true if the content of the atlas resource is loaded, false otherwise.\n */\n isLoaded(resourceName: string): boolean {\n return !!this._loadedSpineAtlases.getFromName(resourceName);\n }\n\n /**\n * Get the Pixi TextureAtlas for the given resource that is already loaded (preloaded or loaded with `load`).\n * If the resource is not loaded, `null` will be returned.\n * @param resourceName The name of the atlas resource.\n * @returns the TextureAtlas of the atlas if loaded, `null` otherwise.\n */\n getAtlasTexture(resourceName: string): pixi_spine.TextureAtlas | null {\n return this._loadedSpineAtlases.getFromName(resourceName);\n }\n\n private _getAtlasResource(resourceName: string): ResourceData | null {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n }\n /**\n * To be called when the game is disposed.\n * Clear the Spine Atlases loaded in this manager.\n */\n dispose(): void {\n this._loadedSpineAtlases.clear();\n this._loadingSpineAtlases.clear();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAOE,KAAM,GAA6B,CAAC,SAU7B,OAAwD,CAc7D,YACE,EACA,EACA,CAdM,yBAAsB,GAAI,GAAK,cAG/B,0BAAuB,GAAI,GAAK,cAYtC,KAAK,gBAAkB,EACvB,KAAK,cAAgB,EAGvB,kBAAmC,CACjC,MAAO,QAGH,iBAAgB,EAAqC,OAIrD,cAAa,EAAqC,CACtD,KAAM,MAAK,UAAU,GAQvB,UAAU,EAAwD,CAChE,KAAM,GAAW,KAAK,kBAAkB,GAExC,GAAI,CAAC,EACH,MAAO,SAAQ,OACb,sCAAsC,OAI1C,GAAI,GAAiB,KAAK,qBAAqB,IAAI,GAEnD,MAAK,IACH,GAAiB,GAAI,SACnB,CAAC,EAAS,IAAW,CACnB,KAAM,GAA2C,CAC/C,EACA,IACG,CACH,GAAI,EACF,MAAO,GACL,kDAAkD,KAGtD,GAAI,CAAC,EACH,MAAO,GACL,4CAA4C,OAIhD,EAAQ,IAGV,KAAK,KAAK,EAAU,KAIxB,KAAK,qBAAqB,IAAI,EAAU,IAGnC,EAST,KACE,EACA,EACM,CACN,KAAM,GAAO,KAAK,gBAAgB,iBAC5B,EAAyB,EAAK,0BAClC,EAAS,MAGX,GAAI,CAAC,EAAuB,OAC1B,MAAO,GACL,GAAI,OAAM,GAAG,EAAS,qCAG1B,KAAM,GAAS,EAAuB,OAEnC,CAAC,EAAW,IAAyB,CACtC,KAAM,GAAqB,EAAK,wBAC9B,EAAS,KACT,GAEF,SACE,GACE,KAAK,cAAc,qBAAqB,GAErC,GACN,IACG,EAAS,AAAC,GAAmC,CACjD,KAAK,oBAAoB,IAAI,EAAU,GACvC,EAAS,KAAM,IAEX,EAAM,KAAK,gBAAgB,WAAW,EAAS,MAErD,KAAK,OAAO,eAAe,CACzB,cAAe,GACf,YAAa,KAAK,gBAAgB,2BAA2B,GACzD,kBACA,cAEN,KAAK,OAAO,IAAI,EAAS,KAAM,EAAK,CAAE,WACtC,KAAK,OAAO,KAAuC,EAAS,MAAM,KAChE,AAAC,GAAU,CAOT,AAAI,MAAO,IAAU,SACnB,GAAI,YAAW,aACb,EACA,CAAC,EAAa,IACZ,EAAU,EAAO,GAAa,aAChC,GAGF,EAAO,KAWf,SAAS,EAA+B,CACtC,MAAO,CAAC,CAAC,KAAK,oBAAoB,YAAY,GAShD,gBAAgB,EAAsD,CACpE,MAAO,MAAK,oBAAoB,YAAY,GAGtC,kBAAkB,EAA2C,CACnE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,KAMN,SAAgB,CACd,KAAK,oBAAoB,QACzB,KAAK,qBAAqB,SApLvB,EAAM,sBAjBL",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(o){const
|
|
1
|
+
var gdjs;(function(o){const r=new o.Logger("Spine Manager"),c=["spine"];class l{constructor(s,e){this._loadedSpines=new o.ResourceCache;this._resourceLoader=s,this._spineAtlasManager=e}getResourceKinds(){return c}async processResource(s){}async loadResource(s){const e=this._getSpineResource(s);if(!e)return r.error(`Unable to find spine json for resource ${s}.`);try{const n=this._resourceLoader.getRuntimeGame(),a=n.getEmbeddedResourcesNames(e.name);if(a.length!==1)return r.error(`Unable to find atlas metadata for resource spine json ${s}.`);const d=n.resolveEmbeddedResource(e.name,a[0]),u=await this._spineAtlasManager.getOrLoad(d),t=this._resourceLoader.getFullUrl(e.file);PIXI.Assets.setPreferences({preferWorkers:!1,crossOrigin:this._resourceLoader.checkIfCredentialsRequired(t)?"use-credentials":"anonymous"}),PIXI.Assets.add(e.name,t,{spineAtlas:u});const i=await PIXI.Assets.load(e.name);i.spineData?this._loadedSpines.set(e,i.spineData):r.error(`Loader cannot process spine resource ${e.name} correctly.`)}catch(n){r.error(`Error while preloading spine resource ${e.name}: ${n}`)}}getSpine(s){return this._loadedSpines.getFromName(s)}isSpineLoaded(s){return!!this._loadedSpines.getFromName(s)}_getSpineResource(s){const e=this._resourceLoader.getResource(s);return e&&this.getResourceKinds().includes(e.kind)?e:null}dispose(){this._loadedSpines.clear()}}o.SpineManager=l})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=pixi-spine-manager.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../GDevelop/Extensions/Spine/managers/pixi-spine-manager.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Spine Manager');\n\n const resourceKinds: ResourceKind[] = ['spine'];\n\n /**\n * SpineManager manages pixi spine skeleton data.\n */\n export class SpineManager implements gdjs.ResourceManager {\n private _spineAtlasManager: SpineAtlasManager;\n private _resourceLoader: ResourceLoader;\n private _loadedSpines = new gdjs.ResourceCache<pixi_spine.ISkeletonData>();\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourcesLoader The resources loader of the game.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n spineAtlasManager: SpineAtlasManager\n ) {\n this._resourceLoader = resourceLoader;\n this._spineAtlasManager = spineAtlasManager;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because pixi-spine parses resources by itself.\n }\n\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._getSpineResource(resourceName);\n\n if (!resource) {\n return logger.error(\n `Unable to find spine json for resource ${resourceName}.`\n );\n }\n\n try {\n const game = this._resourceLoader.getRuntimeGame();\n const embeddedResourcesNames = game.getEmbeddedResourcesNames(\n resource.name\n );\n\n // there should be exactly one file which is pointing to atlas\n if (embeddedResourcesNames.length !== 1) {\n return logger.error(\n `Unable to find atlas metadata for resource spine json ${resourceName}.`\n );\n }\n\n const atlasResourceName = game.resolveEmbeddedResource(\n resource.name,\n embeddedResourcesNames[0]\n );\n const spineAtlas = await this._spineAtlasManager.getOrLoad(\n atlasResourceName\n );\n const url = this._resourceLoader.getFullUrl(resource.file);\n PIXI.Assets.setPreferences({\n preferWorkers: false,\n crossOrigin: this._resourceLoader.checkIfCredentialsRequired(url)\n ? 'use-credentials'\n : 'anonymous',\n });\n PIXI.Assets.add(resource.name, url, { spineAtlas });\n const loadedJson = await PIXI.Assets.load(resource.name);\n\n if (loadedJson.spineData) {\n this._loadedSpines.set(resource, loadedJson.spineData);\n } else {\n logger.error(\n `Loader cannot process spine resource ${resource.name} correctly.`\n );\n }\n } catch (error) {\n logger.error(\n `Error while preloading spine resource ${resource.name}: ${error}`\n );\n }\n }\n\n /**\n * Get the object for the given resource that is already loaded (preloaded or loaded with `loadJson`).\n * If the resource is not loaded, `null` will be returned.\n *\n * @param resourceName The name of the spine skeleton.\n * @returns the spine skeleton if loaded, `null` otherwise.\n */\n getSpine(resourceName: string): pixi_spine.ISkeletonData | null {\n return this._loadedSpines.getFromName(resourceName);\n }\n\n /**\n * Check if the given spine skeleton was loaded.\n * @param resourceName The name of the spine skeleton.\n * @returns true if the content of the spine skeleton is loaded, false otherwise.\n */\n isSpineLoaded(resourceName: string): boolean {\n return !!this._loadedSpines.getFromName(resourceName);\n }\n\n private _getSpineResource(resourceName: string): ResourceData | null {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,iBAEzB,EAAgC,CAAC,SAKhC,OAAmD,CASxD,YACE,EACA,EACA,CATM,mBAAgB,GAAI,GAAK,cAU/B,KAAK,gBAAkB,EACvB,KAAK,mBAAqB,EAG5B,kBAAmC,CACjC,MAAO,QAGH,iBAAgB,EAAqC,OAIrD,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,kBAAkB,GAExC,GAAI,CAAC,EACH,MAAO,GAAO,MACZ,0CAA0C,MAI9C,GAAI,CACF,KAAM,GAAO,KAAK,gBAAgB,iBAC5B,EAAyB,EAAK,0BAClC,EAAS,MAIX,GAAI,EAAuB,SAAW,EACpC,MAAO,GAAO,MACZ,yDAAyD,MAI7D,KAAM,GAAoB,EAAK,wBAC7B,EAAS,KACT,EAAuB,IAEnB,EAAa,KAAM,MAAK,mBAAmB,UAC/C,GAEI,EAAM,KAAK,gBAAgB,WAAW,EAAS,MACrD,KAAK,OAAO,eAAe,CACzB,cAAe,GACf,YAAa,KAAK,gBAAgB,2BAA2B,GACzD,kBACA,cAEN,KAAK,OAAO,IAAI,EAAS,KAAM,EAAK,CAAE,eACtC,KAAM,GAAa,KAAM,MAAK,OAAO,KAAK,EAAS,MAEnD,AAAI,EAAW,UACb,KAAK,cAAc,IAAI,EAAU,EAAW,WAE5C,EAAO,MACL,wCAAwC,EAAS,yBAG9C,EAAP,CACA,EAAO,MACL,yCAAyC,EAAS,SAAS,MAYjE,SAAS,EAAuD,CAC9D,MAAO,MAAK,cAAc,YAAY,GAQxC,cAAc,EAA+B,CAC3C,MAAO,CAAC,CAAC,KAAK,cAAc,YAAY,GAGlC,kBAAkB,EAA2C,CACnE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Spine Manager');\n\n const resourceKinds: ResourceKind[] = ['spine'];\n\n /**\n * SpineManager manages pixi spine skeleton data.\n */\n export class SpineManager implements gdjs.ResourceManager {\n private _spineAtlasManager: SpineAtlasManager;\n private _resourceLoader: ResourceLoader;\n private _loadedSpines = new gdjs.ResourceCache<pixi_spine.ISkeletonData>();\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourcesLoader The resources loader of the game.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n spineAtlasManager: SpineAtlasManager\n ) {\n this._resourceLoader = resourceLoader;\n this._spineAtlasManager = spineAtlasManager;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because pixi-spine parses resources by itself.\n }\n\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._getSpineResource(resourceName);\n\n if (!resource) {\n return logger.error(\n `Unable to find spine json for resource ${resourceName}.`\n );\n }\n\n try {\n const game = this._resourceLoader.getRuntimeGame();\n const embeddedResourcesNames = game.getEmbeddedResourcesNames(\n resource.name\n );\n\n // there should be exactly one file which is pointing to atlas\n if (embeddedResourcesNames.length !== 1) {\n return logger.error(\n `Unable to find atlas metadata for resource spine json ${resourceName}.`\n );\n }\n\n const atlasResourceName = game.resolveEmbeddedResource(\n resource.name,\n embeddedResourcesNames[0]\n );\n const spineAtlas = await this._spineAtlasManager.getOrLoad(\n atlasResourceName\n );\n const url = this._resourceLoader.getFullUrl(resource.file);\n PIXI.Assets.setPreferences({\n preferWorkers: false,\n crossOrigin: this._resourceLoader.checkIfCredentialsRequired(url)\n ? 'use-credentials'\n : 'anonymous',\n });\n PIXI.Assets.add(resource.name, url, { spineAtlas });\n const loadedJson = await PIXI.Assets.load(resource.name);\n\n if (loadedJson.spineData) {\n this._loadedSpines.set(resource, loadedJson.spineData);\n } else {\n logger.error(\n `Loader cannot process spine resource ${resource.name} correctly.`\n );\n }\n } catch (error) {\n logger.error(\n `Error while preloading spine resource ${resource.name}: ${error}`\n );\n }\n }\n\n /**\n * Get the object for the given resource that is already loaded (preloaded or loaded with `loadJson`).\n * If the resource is not loaded, `null` will be returned.\n *\n * @param resourceName The name of the spine skeleton.\n * @returns the spine skeleton if loaded, `null` otherwise.\n */\n getSpine(resourceName: string): pixi_spine.ISkeletonData | null {\n return this._loadedSpines.getFromName(resourceName);\n }\n\n /**\n * Check if the given spine skeleton was loaded.\n * @param resourceName The name of the spine skeleton.\n * @returns true if the content of the spine skeleton is loaded, false otherwise.\n */\n isSpineLoaded(resourceName: string): boolean {\n return !!this._loadedSpines.getFromName(resourceName);\n }\n\n private _getSpineResource(resourceName: string): ResourceData | null {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n }\n\n /**\n * To be called when the game is disposed.\n * Clear the Spine skeleton data loaded in this manager.\n */\n dispose(): void {\n this._loadedSpines.clear();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,iBAEzB,EAAgC,CAAC,SAKhC,OAAmD,CASxD,YACE,EACA,EACA,CATM,mBAAgB,GAAI,GAAK,cAU/B,KAAK,gBAAkB,EACvB,KAAK,mBAAqB,EAG5B,kBAAmC,CACjC,MAAO,QAGH,iBAAgB,EAAqC,OAIrD,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,kBAAkB,GAExC,GAAI,CAAC,EACH,MAAO,GAAO,MACZ,0CAA0C,MAI9C,GAAI,CACF,KAAM,GAAO,KAAK,gBAAgB,iBAC5B,EAAyB,EAAK,0BAClC,EAAS,MAIX,GAAI,EAAuB,SAAW,EACpC,MAAO,GAAO,MACZ,yDAAyD,MAI7D,KAAM,GAAoB,EAAK,wBAC7B,EAAS,KACT,EAAuB,IAEnB,EAAa,KAAM,MAAK,mBAAmB,UAC/C,GAEI,EAAM,KAAK,gBAAgB,WAAW,EAAS,MACrD,KAAK,OAAO,eAAe,CACzB,cAAe,GACf,YAAa,KAAK,gBAAgB,2BAA2B,GACzD,kBACA,cAEN,KAAK,OAAO,IAAI,EAAS,KAAM,EAAK,CAAE,eACtC,KAAM,GAAa,KAAM,MAAK,OAAO,KAAK,EAAS,MAEnD,AAAI,EAAW,UACb,KAAK,cAAc,IAAI,EAAU,EAAW,WAE5C,EAAO,MACL,wCAAwC,EAAS,yBAG9C,EAAP,CACA,EAAO,MACL,yCAAyC,EAAS,SAAS,MAYjE,SAAS,EAAuD,CAC9D,MAAO,MAAK,cAAc,YAAY,GAQxC,cAAc,EAA+B,CAC3C,MAAO,CAAC,CAAC,KAAK,cAAc,YAAY,GAGlC,kBAAkB,EAA2C,CACnE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,KAON,SAAgB,CACd,KAAK,cAAc,SA9GhB,EAAM,iBARL",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(
|
|
1
|
+
var gdjs;(function(d){const a=new d.Logger("Model3DManager"),i=["model3D"];class l{constructor(r){this._loadedThreeModels=new d.ResourceCache;this._downloadedArrayBuffers=new d.ResourceCache;this._loader=null;this._dracoLoader=null;if(this._resourceLoader=r,typeof THREE!="undefined"){this._loader=new THREE_ADDONS.GLTFLoader,this._dracoLoader=new THREE_ADDONS.DRACOLoader,this._dracoLoader.setDecoderPath("./pixi-renderers/draco/gltf/"),this._loader.setDRACOLoader(this._dracoLoader);const e=new THREE.Group;e.add(new THREE.Mesh(new THREE.BoxGeometry(1,1,1),new THREE.MeshBasicMaterial({color:"#ff00ff"}))),this._invalidModel={scene:e,animations:[],cameras:[],scenes:[],asset:{},userData:{},parser:null}}}getResourceKinds(){return i}async processResource(r){const e=this._resourceLoader.getResource(r);if(!e){a.warn('Unable to find texture for resource "'+r+'".');return}const t=this._loader;if(!t)return;const s=this._downloadedArrayBuffers.get(e);if(!!s){this._downloadedArrayBuffers.delete(e);try{const o=await t.parseAsync(s,"");this._loadedThreeModels.set(e,o)}catch(o){a.error("Can't fetch the 3D model file "+e.file+", error: "+o)}}}async loadResource(r){const e=this._resourceLoader.getResource(r);if(!e){a.warn('Unable to find texture for resource "'+r+'".');return}if(!this._loader||this._loadedThreeModels.get(e))return;const s=this._resourceLoader.getFullUrl(e.file);try{const o=await fetch(s,{credentials:this._resourceLoader.checkIfCredentialsRequired(s)?"include":"omit"});if(!o.ok)throw new Error("Network response was not ok");const n=await o.arrayBuffer();this._downloadedArrayBuffers.set(e,n)}catch(o){a.error("Can't fetch the 3D model file "+e.file+", error: "+o)}}getModel(r){return this._loadedThreeModels.getFromName(r)||this._invalidModel}dispose(){this._loadedThreeModels.clear(),this._downloadedArrayBuffers.clear(),this._loader=null,this._dracoLoader=null,this._invalidModel&&(this._invalidModel.cameras=[],this._invalidModel.animations=[],this._invalidModel.scenes=[],this._invalidModel.userData={},this._invalidModel.asset={},this._invalidModel.scene.clear())}}d.Model3DManager=l})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=Model3DManager.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/Model3DManager.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Model3DManager');\n\n const resourceKinds: Array<ResourceKind> = ['model3D'];\n\n /**\n * Load GLB files (using `Three.js`), using the \"model3D\" resources\n * registered in the game resources.\n */\n export class Model3DManager implements gdjs.ResourceManager {\n /**\n * Map associating a resource name to the loaded Three.js model.\n */\n private _loadedThreeModels = new gdjs.ResourceCache<THREE_ADDONS.GLTF>();\n private _downloadedArrayBuffers = new gdjs.ResourceCache<ArrayBuffer>();\n\n _resourceLoader: gdjs.ResourceLoader;\n\n _loader: THREE_ADDONS.GLTFLoader | null = null;\n _dracoLoader: THREE_ADDONS.DRACOLoader | null = null;\n\n //@ts-ignore Can only be null if THREE is not loaded.\n _invalidModel: THREE_ADDONS.GLTF;\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n\n if (typeof THREE !== 'undefined') {\n this._loader = new THREE_ADDONS.GLTFLoader();\n\n this._dracoLoader = new THREE_ADDONS.DRACOLoader();\n this._dracoLoader.setDecoderPath('./pixi-renderers/draco/gltf/');\n this._loader.setDRACOLoader(this._dracoLoader);\n\n /**\n * The invalid model is a box with magenta (#ff00ff) faces, to be\n * easily spotted if rendered on screen.\n */\n const group = new THREE.Group();\n group.add(\n new THREE.Mesh(\n new THREE.BoxGeometry(1, 1, 1),\n new THREE.MeshBasicMaterial({ color: '#ff00ff' })\n )\n );\n this._invalidModel = {\n scene: group,\n animations: [],\n cameras: [],\n scenes: [],\n asset: {},\n userData: {},\n //@ts-ignore\n parser: null,\n };\n }\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n async processResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return;\n }\n const loader = this._loader;\n if (!loader) {\n return;\n }\n const data = this._downloadedArrayBuffers.get(resource);\n if (!data) {\n return;\n }\n this._downloadedArrayBuffers.delete(resource);\n try {\n const gltf: THREE_ADDONS.GLTF = await loader.parseAsync(data, '');\n this._loadedThreeModels.set(resource, gltf);\n } catch (error) {\n logger.error(\n \"Can't fetch the 3D model file \" + resource.file + ', error: ' + error\n );\n }\n }\n\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return;\n }\n const loader = this._loader;\n if (!loader) {\n return;\n }\n if (this._loadedThreeModels.get(resource)) {\n return;\n }\n const url = this._resourceLoader.getFullUrl(resource.file);\n try {\n const response = await fetch(url, {\n credentials: this._resourceLoader.checkIfCredentialsRequired(url)\n ? 'include'\n : 'omit',\n });\n if (!response.ok) {\n throw new Error('Network response was not ok');\n }\n const data = await response.arrayBuffer();\n this._downloadedArrayBuffers.set(resource, data);\n } catch (error) {\n logger.error(\n \"Can't fetch the 3D model file \" + resource.file + ', error: ' + error\n );\n }\n }\n\n /**\n * Return a 3D model.\n *\n * Caller should not modify the object but clone it.\n *\n * @param resourceName The name of the json resource.\n * @returns a 3D model if it exists.\n */\n getModel(resourceName: string): THREE_ADDONS.GLTF {\n return (\n this._loadedThreeModels.getFromName(resourceName) || this._invalidModel\n );\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,kBAEzB,EAAqC,CAAC,WAMrC,OAAqD,CAmB1D,YAAY,EAAqC,CAfzC,wBAAqB,GAAI,GAAK,cAC9B,6BAA0B,GAAI,GAAK,cAI3C,aAA0C,KAC1C,kBAAgD,KAY9C,GAFA,KAAK,gBAAkB,EAEnB,MAAO,QAAU,YAAa,CAChC,KAAK,QAAU,GAAI,cAAa,WAEhC,KAAK,aAAe,GAAI,cAAa,YACrC,KAAK,aAAa,eAAe,gCACjC,KAAK,QAAQ,eAAe,KAAK,cAMjC,KAAM,GAAQ,GAAI,OAAM,MACxB,EAAM,IACJ,GAAI,OAAM,KACR,GAAI,OAAM,YAAY,EAAG,EAAG,GAC5B,GAAI,OAAM,kBAAkB,CAAE,MAAO,cAGzC,KAAK,cAAgB,CACnB,MAAO,EACP,WAAY,GACZ,QAAS,GACT,OAAQ,GACR,MAAO,GACP,SAAU,GAEV,OAAQ,OAKd,kBAAmC,CACjC,MAAO,QAGH,iBAAgB,EAAqC,CACzD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KACL,wCAA0C,EAAe,MAE3D,OAEF,KAAM,GAAS,KAAK,QACpB,GAAI,CAAC,EACH,OAEF,KAAM,GAAO,KAAK,wBAAwB,IAAI,GAC9C,GAAI,EAAC,EAGL,MAAK,wBAAwB,OAAO,GACpC,GAAI,CACF,KAAM,GAA0B,KAAM,GAAO,WAAW,EAAM,IAC9D,KAAK,mBAAmB,IAAI,EAAU,SAC/B,EAAP,CACA,EAAO,MACL,iCAAmC,EAAS,KAAO,YAAc,UAKjE,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KACL,wCAA0C,EAAe,MAE3D,OAMF,GAHI,CADW,KAAK,SAIhB,KAAK,mBAAmB,IAAI,GAC9B,OAEF,KAAM,GAAM,KAAK,gBAAgB,WAAW,EAAS,MACrD,GAAI,CACF,KAAM,GAAW,KAAM,OAAM,EAAK,CAChC,YAAa,KAAK,gBAAgB,2BAA2B,GACzD,UACA,SAEN,GAAI,CAAC,EAAS,GACZ,KAAM,IAAI,OAAM,+BAElB,KAAM,GAAO,KAAM,GAAS,cAC5B,KAAK,wBAAwB,IAAI,EAAU,SACpC,EAAP,CACA,EAAO,MACL,iCAAmC,EAAS,KAAO,YAAc,IAavE,SAAS,EAAyC,CAChD,MACE,MAAK,mBAAmB,YAAY,IAAiB,KAAK,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Model3DManager');\n\n const resourceKinds: Array<ResourceKind> = ['model3D'];\n\n /**\n * Load GLB files (using `Three.js`), using the \"model3D\" resources\n * registered in the game resources.\n */\n export class Model3DManager implements gdjs.ResourceManager {\n /**\n * Map associating a resource name to the loaded Three.js model.\n */\n private _loadedThreeModels = new gdjs.ResourceCache<THREE_ADDONS.GLTF>();\n private _downloadedArrayBuffers = new gdjs.ResourceCache<ArrayBuffer>();\n\n _resourceLoader: gdjs.ResourceLoader;\n\n _loader: THREE_ADDONS.GLTFLoader | null = null;\n _dracoLoader: THREE_ADDONS.DRACOLoader | null = null;\n\n //@ts-ignore Can only be null if THREE is not loaded.\n _invalidModel: THREE_ADDONS.GLTF;\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n\n if (typeof THREE !== 'undefined') {\n this._loader = new THREE_ADDONS.GLTFLoader();\n\n this._dracoLoader = new THREE_ADDONS.DRACOLoader();\n this._dracoLoader.setDecoderPath('./pixi-renderers/draco/gltf/');\n this._loader.setDRACOLoader(this._dracoLoader);\n\n /**\n * The invalid model is a box with magenta (#ff00ff) faces, to be\n * easily spotted if rendered on screen.\n */\n const group = new THREE.Group();\n group.add(\n new THREE.Mesh(\n new THREE.BoxGeometry(1, 1, 1),\n new THREE.MeshBasicMaterial({ color: '#ff00ff' })\n )\n );\n this._invalidModel = {\n scene: group,\n animations: [],\n cameras: [],\n scenes: [],\n asset: {},\n userData: {},\n //@ts-ignore\n parser: null,\n };\n }\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n async processResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return;\n }\n const loader = this._loader;\n if (!loader) {\n return;\n }\n const data = this._downloadedArrayBuffers.get(resource);\n if (!data) {\n return;\n }\n this._downloadedArrayBuffers.delete(resource);\n try {\n const gltf: THREE_ADDONS.GLTF = await loader.parseAsync(data, '');\n this._loadedThreeModels.set(resource, gltf);\n } catch (error) {\n logger.error(\n \"Can't fetch the 3D model file \" + resource.file + ', error: ' + error\n );\n }\n }\n\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return;\n }\n const loader = this._loader;\n if (!loader) {\n return;\n }\n if (this._loadedThreeModels.get(resource)) {\n return;\n }\n const url = this._resourceLoader.getFullUrl(resource.file);\n try {\n const response = await fetch(url, {\n credentials: this._resourceLoader.checkIfCredentialsRequired(url)\n ? 'include'\n : 'omit',\n });\n if (!response.ok) {\n throw new Error('Network response was not ok');\n }\n const data = await response.arrayBuffer();\n this._downloadedArrayBuffers.set(resource, data);\n } catch (error) {\n logger.error(\n \"Can't fetch the 3D model file \" + resource.file + ', error: ' + error\n );\n }\n }\n\n /**\n * Return a 3D model.\n *\n * Caller should not modify the object but clone it.\n *\n * @param resourceName The name of the json resource.\n * @returns a 3D model if it exists.\n */\n getModel(resourceName: string): THREE_ADDONS.GLTF {\n return (\n this._loadedThreeModels.getFromName(resourceName) || this._invalidModel\n );\n }\n\n /**\n * To be called when the game is disposed.\n * Clear the models, resources loaded and destroy 3D models loaders in this manager.\n */\n dispose(): void {\n this._loadedThreeModels.clear();\n this._downloadedArrayBuffers.clear();\n this._loader = null;\n this._dracoLoader = null;\n\n if (this._invalidModel) {\n this._invalidModel.cameras = [];\n this._invalidModel.animations = [];\n this._invalidModel.scenes = [];\n this._invalidModel.userData = {};\n this._invalidModel.asset = {};\n this._invalidModel.scene.clear();\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,kBAEzB,EAAqC,CAAC,WAMrC,OAAqD,CAmB1D,YAAY,EAAqC,CAfzC,wBAAqB,GAAI,GAAK,cAC9B,6BAA0B,GAAI,GAAK,cAI3C,aAA0C,KAC1C,kBAAgD,KAY9C,GAFA,KAAK,gBAAkB,EAEnB,MAAO,QAAU,YAAa,CAChC,KAAK,QAAU,GAAI,cAAa,WAEhC,KAAK,aAAe,GAAI,cAAa,YACrC,KAAK,aAAa,eAAe,gCACjC,KAAK,QAAQ,eAAe,KA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KAAK,mBAAmB,QACxB,KAAK,wBAAwB,QAC7B,KAAK,QAAU,KACf,KAAK,aAAe,KAEhB,KAAK,eACP,MAAK,cAAc,QAAU,GAC7B,KAAK,cAAc,WAAa,GAChC,KAAK,cAAc,OAAS,GAC5B,KAAK,cAAc,SAAW,GAC9B,KAAK,cAAc,MAAQ,GAC3B,KAAK,cAAc,MAAM,UApJxB,EAAM,mBATL",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(i){const c=new i.Logger("ResourceLoader"),
|
|
1
|
+
var gdjs;(function(i){const c=new i.Logger("ResourceLoader"),f=(t,e,s)=>{if(t.startsWith("data:")||t.startsWith("blob:"))return t;const n=t.indexOf("?")===-1?"?":"&";return t+n+e+"="+s},_=t=>t.startsWith("https://project-resources.gdevelop.io/")||t.startsWith("https://project-resources-dev.gdevelop.io/"),g=20,R=5,d=3;class v{constructor(e){this.isFinished=!1;this.sceneName=e,this.onProgressCallbacks=new Array,this.onFinishCallbacks=new Array}registerCallback(e,s){if(this.isFinished){e();return}this.onFinishCallbacks.push(e),s&&this.onProgressCallbacks.push(s)}onProgress(e,s){for(const n of this.onProgressCallbacks)n(e,s)}onFinish(){this.isFinished=!0;for(const e of this.onFinishCallbacks)e()}}class w{constructor(e,s,n,r){this._sceneToLoadQueue=new Array;this._spineAtlasManager=null;this._spineManager=null;this.currentLoadingSceneName="";this.currentSceneLoadingProgress=0;this._isLoadingInForeground=!0;this._runtimeGame=e,this._resources=new Map,this._globalResources=n,this._sceneResources=new Map,this._sceneNamesToLoad=new Set,this._sceneNamesToMakeReady=new Set,this.setResources(s,n,r),this._imageManager=new i.ImageManager(this),this._soundManager=new i.SoundManager(this),this._fontManager=new i.FontManager(this),this._jsonManager=new i.JsonManager(this),this._bitmapFontManager=new i.BitmapFontManager(this,this._imageManager),this._model3DManager=new i.Model3DManager(this),i.SpineAtlasManager&&i.SpineManager&&(this._spineAtlasManager=new i.SpineAtlasManager(this,this._imageManager),this._spineManager=new i.SpineManager(this,this._spineAtlasManager));const a=[this._imageManager,this._soundManager,this._fontManager,this._jsonManager,this._bitmapFontManager,this._model3DManager];this._spineAtlasManager&&a.push(this._spineAtlasManager),this._spineManager&&a.push(this._spineManager),this._resourceManagersMap=new Map;for(const o of a)for(const u of o.getResourceKinds())this._resourceManagersMap.set(u,o)}getRuntimeGame(){return this._runtimeGame}setResources(e,s,n){this._globalResources=s,this._sceneResources.clear(),this._sceneNamesToLoad.clear(),this._sceneNamesToMakeReady.clear();for(const r of n)this._sceneResources.set(r.name,r.usedResources.map(a=>a.name)),this._sceneNamesToLoad.add(r.name),this._sceneNamesToMakeReady.add(r.name);this._sceneToLoadQueue.length=0;for(let r=n.length-1;r>=0;r--){const a=n[r];this._sceneToLoadQueue.push(new v(a.name))}this._resources.clear();for(const r of e)!r.file||this._resources.set(r.name,r)}async loadAllResources(e){let s=0;await h([...this._resources.values()],g,d,async n=>{await this._loadResource(n),await this._processResource(n),s++,e(s,this._resources.size)}),this._sceneNamesToLoad.clear(),this._sceneNamesToMakeReady.clear()}async loadGlobalAndFirstSceneResources(e,s){const n=this._sceneResources.get(e);if(!n){c.warn(`Can't load resource for unknown scene: "`+e+'".');return}let r=0;const a=[...this._globalResources,...n.values()];await h(a,g,d,async o=>{const u=this._resources.get(o);if(!u){c.warn('Unable to find resource "'+o+'".');return}await this._loadResource(u),await this._processResource(u),r++,s(r,a.length)}),this._setSceneAssetsLoaded(e),this._setSceneAssetsReady(e)}async loadAllSceneInBackground(){for(;this._sceneToLoadQueue.length>0;){const e=this._sceneToLoadQueue[this._sceneToLoadQueue.length-1];e!==void 0&&(this.currentLoadingSceneName=e.sceneName,this.areSceneAssetsLoaded(e.sceneName)?this._sceneToLoadQueue.pop():(await this._doLoadSceneResources(e.sceneName,async(s,n)=>e.onProgress(s,n)),this._sceneToLoadQueue.splice(this._sceneToLoadQueue.findIndex(s=>s===e),1),e.onFinish()))}this.currentLoadingSceneName=""}async _doLoadSceneResources(e,s){const n=this._sceneResources.get(e);if(!n){c.warn(`Can't load resource for unknown scene: "`+e+'".');return}let r=0;await h([...n.values()],this._isLoadingInForeground?g:R,d,async a=>{const o=this._resources.get(a);if(!o){c.warn('Unable to find resource "'+a+'".');return}await this._loadResource(o),r++,this.currentSceneLoadingProgress=r/this._resources.size,s&&await s(r,this._resources.size)}),this._setSceneAssetsLoaded(e)}async _loadResource(e){const s=this._resourceManagersMap.get(e.kind);if(!s){c.warn('Unknown resource kind: "'+e.kind+'" for: "'+e.name+'".');return}await s.loadResource(e.name)}async loadAndProcessSceneResources(e,s){if(this.areSceneAssetsReady(e))return;await this.loadSceneResources(e,s);const n=this._sceneResources.get(e);if(!n){c.warn(`Can't load resource for unknown scene: "`+e+'".');return}let r=0;for(const a of n){const o=this._resources.get(a);if(!o){c.warn('Unable to find resource "'+a+'".');continue}await this._processResource(o),r++,s&&await s(r,n.length)}this._setSceneAssetsReady(e)}async loadSceneResources(e,s){this._isLoadingInForeground=!0;const n=this._prioritizeScene(e);return new Promise((r,a)=>{if(!n){this._isLoadingInForeground=!1,r();return}n.registerCallback(()=>{this._isLoadingInForeground=!1,r()},s)})}dispose(){for(const e of this._resourceManagersMap.values())e.dispose()}_prioritizeScene(e){const s=this._sceneToLoadQueue.findIndex(r=>r.sceneName===e);if(s<0)return null;const n=this._sceneToLoadQueue[s];return this._sceneToLoadQueue.splice(s,1),this._sceneToLoadQueue.push(n),n}async _processResource(e){const s=this._resourceManagersMap.get(e.kind);if(!s){c.warn('Unknown resource kind: "'+e.kind+'" for: "'+e.name+'".');return}await s.processResource(e.name)}getSceneLoadingProgress(e){return e===this.currentLoadingSceneName?this.currentSceneLoadingProgress:this.areSceneAssetsLoaded(e)?1:0}areSceneAssetsLoaded(e){return!this._sceneNamesToLoad.has(e)}areSceneAssetsReady(e){return!this._sceneNamesToMakeReady.has(e)}_setSceneAssetsLoaded(e){this._sceneNamesToLoad.delete(e)}_setSceneAssetsReady(e){this._sceneNamesToMakeReady.delete(e)}getResource(e){return this._resources.get(e)||null}getFullUrl(e){const{gdevelopResourceToken:s}=this._runtimeGame._options;return!s||!_(e)?e:f(e,"gd_resource_token",encodeURIComponent(s))}checkIfCredentialsRequired(e){return this._runtimeGame._options.gdevelopResourceToken?!1:!!_(e)}getSoundManager(){return this._soundManager}getImageManager(){return this._imageManager}getFontManager(){return this._fontManager}getBitmapFontManager(){return this._bitmapFontManager}getJsonManager(){return this._jsonManager}getModel3DManager(){return this._model3DManager}getSpineManager(){return this._spineManager}getSpineAtlasManager(){return this._spineAtlasManager}}i.ResourceLoader=w;const p=(t,e,s)=>{const n=[],r=[];let a=0,o=0;return new Promise((u,y)=>{const m=()=>{if(t.length===0){u({results:n,errors:r});return}for(;a<e&&o<t.length;){const M=t[o++];a++,s(M).then(l=>n.push(l)).catch(l=>r.push({item:M,error:l})).finally(()=>{a--,o===t.length&&a===0?u({results:n,errors:r}):m()})}};m()})},h=async(t,e,s,n)=>{const r=await p(t,e,n);r.errors.length!==0&&c.warn("Some assets couldn't be downloaded. Trying again now.");for(let a=1;a<s&&r.errors.length!==0;a++){const o=await p(t,e,n);r.results.push.apply(r.results,o.results),r.errors=o.errors}return r}})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=ResourceLoader.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/ResourceLoader.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2023 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('ResourceLoader');\n\n const addSearchParameterToUrl = (\n url: string,\n urlEncodedParameterName: string,\n urlEncodedValue: string\n ) => {\n if (url.startsWith('data:') || url.startsWith('blob:')) {\n // blob/data protocol does not support search parameters, which are useless anyway.\n return url;\n }\n\n const separator = url.indexOf('?') === -1 ? '?' : '&';\n return url + separator + urlEncodedParameterName + '=' + urlEncodedValue;\n };\n\n const checkIfIsGDevelopCloudBucketUrl = (url: string): boolean => {\n return (\n url.startsWith('https://project-resources.gdevelop.io/') ||\n url.startsWith('https://project-resources-dev.gdevelop.io/')\n );\n };\n\n const maxForegroundConcurrency = 20;\n const maxBackgroundConcurrency = 5;\n const maxAttempt = 3;\n\n /**\n * A task of pre-loading resources used by a scene.\n *\n * A Promise can't be used instead of this class because a Promise will start\n * as soon as possible. It would flood the server with downloading requests\n * and make impossible to finely tune in which order scenes are actually\n * downloaded.\n */\n class SceneLoadingTask {\n sceneName: string;\n private onProgressCallbacks: Array<(count: number, total: number) => void>;\n private onFinishCallbacks: Array<() => void>;\n private isFinished = false;\n\n constructor(sceneName: string) {\n this.sceneName = sceneName;\n this.onProgressCallbacks = new Array<\n (count: number, total: number) => void\n >();\n this.onFinishCallbacks = new Array<() => void>();\n }\n\n registerCallback(\n onFinish: () => void,\n onProgress?: (count: number, total: number) => void\n ) {\n if (this.isFinished) {\n onFinish();\n return;\n }\n this.onFinishCallbacks.push(onFinish);\n if (onProgress) {\n this.onProgressCallbacks.push(onProgress);\n }\n }\n\n onProgress(count: number, total: number) {\n for (const onProgress of this.onProgressCallbacks) {\n onProgress(count, total);\n }\n }\n\n onFinish() {\n this.isFinished = true;\n for (const onFinish of this.onFinishCallbacks) {\n onFinish();\n }\n }\n }\n\n /**\n * Pre-load resources of any kind needed for a game or a scene.\n */\n export class ResourceLoader {\n _runtimeGame: RuntimeGame;\n /**\n * All the resource of a game by resource name.\n */\n private _resources: Map<string, ResourceData>;\n /**\n * Resources needed for any scene. Typically, they are resources from\n * global objects.\n */\n private _globalResources: Array<string>;\n /**\n * Resources by scene names.\n */\n private _sceneResources: Map<string, Array<string>>;\n /**\n * Keep track of which scene whose resources has already be pre-loaded.\n */\n private _sceneNamesToLoad: Set<string>;\n /**\n * Keep track of which scene whose resources has already be loaded.\n */\n private _sceneNamesToMakeReady: Set<string>;\n /**\n * A queue of scenes whose resources are still to be pre-loaded.\n */\n private _sceneToLoadQueue: Array<SceneLoadingTask> = new Array<\n SceneLoadingTask\n >();\n /**\n * The resource managers that actually download and remember downloaded\n * content.\n */\n _resourceManagersMap: Map<ResourceKind, ResourceManager>;\n private _imageManager: ImageManager;\n private _soundManager: SoundManager;\n private _fontManager: FontManager;\n private _jsonManager: JsonManager;\n private _model3DManager: Model3DManager;\n private _bitmapFontManager: BitmapFontManager;\n private _spineAtlasManager: SpineAtlasManager | null = null;\n private _spineManager: SpineManager | null = null;\n\n /**\n * Only used by events.\n */\n private currentLoadingSceneName: string = '';\n /**\n * Only used by events.\n */\n private currentSceneLoadingProgress: float = 0;\n /**\n * It's set to `true` during intermediary loading screen to use a greater\n * concurrency as the game is paused and doesn't need bandwidth (for video\n * or music streaming or online multiplayer).\n */\n private _isLoadingInForeground = true;\n\n /**\n * @param runtimeGame The game.\n * @param resourceDataArray The resources data of the game.\n * @param globalResources The resources needed for any layer.\n * @param layoutDataArray The resources used by each layer.\n */\n constructor(\n runtimeGame: RuntimeGame,\n resourceDataArray: ResourceData[],\n globalResources: Array<string>,\n layoutDataArray: Array<LayoutData>\n ) {\n this._runtimeGame = runtimeGame;\n this._resources = new Map<string, ResourceData>();\n this._globalResources = globalResources;\n\n // These 3 attributes are filled by `setResources`.\n this._sceneResources = new Map<string, Array<string>>();\n this._sceneNamesToLoad = new Set<string>();\n this._sceneNamesToMakeReady = new Set<string>();\n this.setResources(resourceDataArray, globalResources, layoutDataArray);\n\n this._imageManager = new gdjs.ImageManager(this);\n this._soundManager = new gdjs.SoundManager(this);\n this._fontManager = new gdjs.FontManager(this);\n this._jsonManager = new gdjs.JsonManager(this);\n this._bitmapFontManager = new gdjs.BitmapFontManager(\n this,\n this._imageManager\n );\n this._model3DManager = new gdjs.Model3DManager(this);\n\n // add spine related managers only if spine extension is used\n if (gdjs.SpineAtlasManager && gdjs.SpineManager) {\n this._spineAtlasManager = new gdjs.SpineAtlasManager(\n this,\n this._imageManager\n );\n this._spineManager = new gdjs.SpineManager(\n this,\n this._spineAtlasManager\n );\n }\n\n const resourceManagers: Array<ResourceManager> = [\n this._imageManager,\n this._soundManager,\n this._fontManager,\n this._jsonManager,\n this._bitmapFontManager,\n this._model3DManager,\n ];\n\n if (this._spineAtlasManager)\n resourceManagers.push(this._spineAtlasManager);\n if (this._spineManager) resourceManagers.push(this._spineManager);\n\n this._resourceManagersMap = new Map<ResourceKind, ResourceManager>();\n for (const resourceManager of resourceManagers) {\n for (const resourceKind of resourceManager.getResourceKinds()) {\n this._resourceManagersMap.set(resourceKind, resourceManager);\n }\n }\n }\n\n /**\n * @returns the runtime game instance.\n */\n getRuntimeGame(): RuntimeGame {\n return this._runtimeGame;\n }\n\n /**\n * Update the resources data of the game. Useful for hot-reloading, should\n * not be used otherwise.\n */\n setResources(\n resourceDataArray: ResourceData[],\n globalResources: Array<string>,\n layoutDataArray: Array<LayoutData>\n ): void {\n this._globalResources = globalResources;\n\n this._sceneResources.clear();\n this._sceneNamesToLoad.clear();\n this._sceneNamesToMakeReady.clear();\n for (const layoutData of layoutDataArray) {\n this._sceneResources.set(\n layoutData.name,\n layoutData.usedResources.map((resource) => resource.name)\n );\n this._sceneNamesToLoad.add(layoutData.name);\n this._sceneNamesToMakeReady.add(layoutData.name);\n }\n // TODO Clearing the queue doesn't abort the running task, but it should\n // not matter as resource loading is really fast in preview mode.\n this._sceneToLoadQueue.length = 0;\n for (let index = layoutDataArray.length - 1; index >= 0; index--) {\n const layoutData = layoutDataArray[index];\n this._sceneToLoadQueue.push(new SceneLoadingTask(layoutData.name));\n }\n\n this._resources.clear();\n for (const resourceData of resourceDataArray) {\n if (!resourceData.file) {\n // Empty string or missing `file` field: not a valid resource, let's entirely ignore it.\n // Otherwise, this can confuse some loaders that will consider an empty string different\n // than a file that happen not to fail to load.\n continue;\n }\n\n this._resources.set(resourceData.name, resourceData);\n }\n }\n\n async loadAllResources(\n onProgress: (loadingCount: integer, totalCount: integer) => void\n ): Promise<void> {\n let loadedCount = 0;\n await processAndRetryIfNeededWithPromisePool(\n [...this._resources.values()],\n maxForegroundConcurrency,\n maxAttempt,\n async (resource) => {\n await this._loadResource(resource);\n await this._processResource(resource);\n loadedCount++;\n onProgress(loadedCount, this._resources.size);\n }\n );\n this._sceneNamesToLoad.clear();\n this._sceneNamesToMakeReady.clear();\n }\n\n /**\n * Load the resources that are needed to launch the first scene.\n */\n async loadGlobalAndFirstSceneResources(\n firstSceneName: string,\n onProgress: (count: number, total: number) => void\n ): Promise<void> {\n const sceneResources = this._sceneResources.get(firstSceneName);\n if (!sceneResources) {\n logger.warn(\n 'Can\\'t load resource for unknown scene: \"' + firstSceneName + '\".'\n );\n return;\n }\n let loadedCount = 0;\n const resources = [...this._globalResources, ...sceneResources.values()];\n await processAndRetryIfNeededWithPromisePool(\n resources,\n maxForegroundConcurrency,\n maxAttempt,\n async (resourceName) => {\n const resource = this._resources.get(resourceName);\n if (!resource) {\n logger.warn('Unable to find resource \"' + resourceName + '\".');\n return;\n }\n await this._loadResource(resource);\n await this._processResource(resource);\n loadedCount++;\n onProgress(loadedCount, resources.length);\n }\n );\n this._setSceneAssetsLoaded(firstSceneName);\n this._setSceneAssetsReady(firstSceneName);\n }\n\n /**\n * Load each scene in order.\n *\n * This is done in background to try to avoid loading screens when changing\n * scenes.\n */\n async loadAllSceneInBackground(): Promise<void> {\n while (this._sceneToLoadQueue.length > 0) {\n const task = this._sceneToLoadQueue[this._sceneToLoadQueue.length - 1];\n if (task === undefined) {\n continue;\n }\n this.currentLoadingSceneName = task.sceneName;\n if (!this.areSceneAssetsLoaded(task.sceneName)) {\n await this._doLoadSceneResources(\n task.sceneName,\n async (count, total) => task.onProgress(count, total)\n );\n // A scene may have been moved last while awaiting resources to be\n // downloaded (see _prioritizeScene).\n this._sceneToLoadQueue.splice(\n this._sceneToLoadQueue.findIndex((element) => element === task),\n 1\n );\n task.onFinish();\n } else {\n this._sceneToLoadQueue.pop();\n }\n }\n this.currentLoadingSceneName = '';\n }\n\n private async _doLoadSceneResources(\n sceneName: string,\n onProgress?: (count: number, total: number) => Promise<void>\n ): Promise<void> {\n const sceneResources = this._sceneResources.get(sceneName);\n if (!sceneResources) {\n logger.warn(\n 'Can\\'t load resource for unknown scene: \"' + sceneName + '\".'\n );\n return;\n }\n let loadedCount = 0;\n await processAndRetryIfNeededWithPromisePool(\n [...sceneResources.values()],\n this._isLoadingInForeground\n ? maxForegroundConcurrency\n : maxBackgroundConcurrency,\n maxAttempt,\n async (resourceName) => {\n const resource = this._resources.get(resourceName);\n if (!resource) {\n logger.warn('Unable to find resource \"' + resourceName + '\".');\n return;\n }\n await this._loadResource(resource);\n loadedCount++;\n this.currentSceneLoadingProgress = loadedCount / this._resources.size;\n onProgress && (await onProgress(loadedCount, this._resources.size));\n }\n );\n this._setSceneAssetsLoaded(sceneName);\n }\n\n private async _loadResource(resource: ResourceData): Promise<void> {\n const resourceManager = this._resourceManagersMap.get(resource.kind);\n if (!resourceManager) {\n logger.warn(\n 'Unknown resource kind: \"' +\n resource.kind +\n '\" for: \"' +\n resource.name +\n '\".'\n );\n return;\n }\n await resourceManager.loadResource(resource.name);\n }\n\n /**\n * Load and process a scene that is needed right away.\n *\n * The renderer will show a loading screen while its done.\n */\n async loadAndProcessSceneResources(\n sceneName: string,\n onProgress?: (count: number, total: number) => Promise<void>\n ): Promise<void> {\n if (this.areSceneAssetsReady(sceneName)) {\n return;\n }\n await this.loadSceneResources(sceneName, onProgress);\n\n const sceneResources = this._sceneResources.get(sceneName);\n if (!sceneResources) {\n logger.warn(\n 'Can\\'t load resource for unknown scene: \"' + sceneName + '\".'\n );\n return;\n }\n\n let parsedCount = 0;\n for (const resourceName of sceneResources) {\n const resource = this._resources.get(resourceName);\n if (!resource) {\n logger.warn('Unable to find resource \"' + resourceName + '\".');\n continue;\n }\n await this._processResource(resource);\n parsedCount++;\n onProgress && (await onProgress(parsedCount, sceneResources.length));\n }\n this._setSceneAssetsReady(sceneName);\n }\n\n /**\n * Load a scene resources without parsing them.\n *\n * When another scene resources are loading in background, it waits for\n * all its resources to be loaded before loading resources of the given\n * scene.\n */\n async loadSceneResources(\n sceneName: string,\n onProgress?: (count: number, total: number) => void\n ): Promise<void> {\n this._isLoadingInForeground = true;\n const task = this._prioritizeScene(sceneName);\n return new Promise<void>((resolve, reject) => {\n if (!task) {\n this._isLoadingInForeground = false;\n resolve();\n return;\n }\n task.registerCallback(() => {\n this._isLoadingInForeground = false;\n resolve();\n }, onProgress);\n });\n }\n\n /**\n * Put a given scene at the end of the queue.\n *\n * When the scene that is currently loading in background is done,\n * this scene will be the next to be loaded.\n */\n private _prioritizeScene(sceneName: string): SceneLoadingTask | null {\n const taskIndex = this._sceneToLoadQueue.findIndex(\n (task) => task.sceneName === sceneName\n );\n if (taskIndex < 0) {\n // The scene is already loaded.\n return null;\n }\n const task = this._sceneToLoadQueue[taskIndex];\n this._sceneToLoadQueue.splice(taskIndex, 1);\n this._sceneToLoadQueue.push(task);\n return task;\n }\n\n private async _processResource(resource: ResourceData): Promise<void> {\n const resourceManager = this._resourceManagersMap.get(resource.kind);\n if (!resourceManager) {\n logger.warn(\n 'Unknown resource kind: \"' +\n resource.kind +\n '\" for: \"' +\n resource.name +\n '\".'\n );\n return;\n }\n await resourceManager.processResource(resource.name);\n }\n\n getSceneLoadingProgress(sceneName: string): float {\n return sceneName === this.currentLoadingSceneName\n ? this.currentSceneLoadingProgress\n : this.areSceneAssetsLoaded(sceneName)\n ? 1\n : 0;\n }\n\n /**\n * @returns true when all the resources of the given scene are loaded\n * (but maybe not parsed).\n */\n areSceneAssetsLoaded(sceneName: string): boolean {\n return !this._sceneNamesToLoad.has(sceneName);\n }\n\n /**\n * @returns true when all the resources of the given scene are loaded and\n * parsed.\n */\n areSceneAssetsReady(sceneName: string): boolean {\n return !this._sceneNamesToMakeReady.has(sceneName);\n }\n\n private _setSceneAssetsLoaded(sceneName: string): void {\n this._sceneNamesToLoad.delete(sceneName);\n }\n\n private _setSceneAssetsReady(sceneName: string): void {\n this._sceneNamesToMakeReady.delete(sceneName);\n }\n\n getResource(resourceName: string): ResourceData | null {\n return this._resources.get(resourceName) || null;\n }\n\n // Helper methods used when resources are loaded from an URL.\n\n /**\n * Complete the given URL with any specific parameter required to access\n * the resource (this can be for example a token needed to access the resource).\n */\n getFullUrl(url: string) {\n const { gdevelopResourceToken } = this._runtimeGame._options;\n if (!gdevelopResourceToken) return url;\n\n if (!checkIfIsGDevelopCloudBucketUrl(url)) return url;\n\n return addSearchParameterToUrl(\n url,\n 'gd_resource_token',\n encodeURIComponent(gdevelopResourceToken)\n );\n }\n\n /**\n * Return true if the specified URL must be loaded with cookies (\"credentials\")\n * sent to grant access to them.\n */\n checkIfCredentialsRequired(url: string) {\n if (this._runtimeGame._options.gdevelopResourceToken) return false;\n\n // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n // Note that this is only useful during previews.\n if (checkIfIsGDevelopCloudBucketUrl(url)) return true;\n\n // For other resources, use the default way of loading resources (\"anonymous\" or \"same-site\").\n return false;\n }\n\n /**\n * Get the gdjs.SoundManager of the RuntimeGame.\n * @return The sound manager.\n */\n getSoundManager(): gdjs.HowlerSoundManager {\n return this._soundManager;\n }\n\n /**\n * Get the gdjs.ImageManager of the RuntimeGame.\n * @return The image manager.\n */\n getImageManager(): gdjs.PixiImageManager {\n return this._imageManager;\n }\n\n /**\n * Get the gdjs.FontManager of the RuntimeGame.\n * @return The font manager.\n */\n getFontManager(): gdjs.FontFaceObserverFontManager {\n return this._fontManager;\n }\n\n /**\n * Get the gdjs.BitmapFontManager of the RuntimeGame.\n * @return The bitmap font manager.\n */\n getBitmapFontManager(): gdjs.BitmapFontManager {\n return this._bitmapFontManager;\n }\n\n /**\n * Get the JSON manager of the game, used to load JSON from game\n * resources.\n * @return The json manager for the game\n */\n getJsonManager(): gdjs.JsonManager {\n return this._jsonManager;\n }\n\n /**\n * Get the 3D model manager of the game, used to load 3D model from game\n * resources.\n * @return The 3D model manager for the game\n */\n getModel3DManager(): gdjs.Model3DManager {\n return this._model3DManager;\n }\n\n /**\n * Get the Spine manager of the game, used to load and construct spine skeletons from game\n * resources.\n * @return The Spine manager for the game\n */\n getSpineManager(): gdjs.SpineManager | null {\n return this._spineManager;\n }\n\n /**\n * Get the Spine Atlas manager of the game, used to load atlases from game\n * resources.\n * @return The Spine Atlas manager for the game\n */\n getSpineAtlasManager(): gdjs.SpineAtlasManager | null {\n return this._spineAtlasManager;\n }\n }\n\n type PromiseError<T> = { item: T; error: Error };\n\n type PromisePoolOutput<T, U> = {\n results: Array<U>;\n errors: Array<PromiseError<T>>;\n };\n\n const processWithPromisePool = <T, U>(\n items: Array<T>,\n maxConcurrency: number,\n asyncFunction: (item: T) => Promise<U>\n ): Promise<PromisePoolOutput<T, U>> => {\n const results: Array<U> = [];\n const errors: Array<PromiseError<T>> = [];\n let activePromises = 0;\n let index = 0;\n\n return new Promise((resolve, reject) => {\n const executeNext = () => {\n if (items.length === 0) {\n resolve({ results, errors });\n return;\n }\n while (activePromises < maxConcurrency && index < items.length) {\n const item = items[index++];\n activePromises++;\n\n asyncFunction(item)\n .then((result) => results.push(result))\n .catch((error) => errors.push({ item, error }))\n .finally(() => {\n activePromises--;\n if (index === items.length && activePromises === 0) {\n resolve({ results, errors });\n } else {\n executeNext();\n }\n });\n }\n };\n\n executeNext();\n });\n };\n\n const processAndRetryIfNeededWithPromisePool = async <T, U>(\n items: Array<T>,\n maxConcurrency: number,\n maxAttempt: number,\n asyncFunction: (item: T) => Promise<U>\n ): Promise<PromisePoolOutput<T, U>> => {\n const output = await processWithPromisePool<T, U>(\n items,\n maxConcurrency,\n asyncFunction\n );\n if (output.errors.length !== 0) {\n logger.warn(\"Some assets couldn't be downloaded. Trying again now.\");\n }\n for (\n let attempt = 1;\n attempt < maxAttempt && output.errors.length !== 0;\n attempt++\n ) {\n const retryOutput = await processWithPromisePool<T, U>(\n items,\n maxConcurrency,\n asyncFunction\n );\n output.results.push.apply(output.results, retryOutput.results);\n output.errors = retryOutput.errors;\n }\n return output;\n };\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,kBAEzB,EAA0B,CAC9B,EACA,EACA,IACG,CACH,GAAI,EAAI,WAAW,UAAY,EAAI,WAAW,SAE5C,MAAO,GAGT,KAAM,GAAY,EAAI,QAAQ,OAAS,GAAK,IAAM,IAClD,MAAO,GAAM,EAAY,EAA0B,IAAM,GAGrD,EAAkC,AAAC,GAErC,EAAI,WAAW,2CACf,EAAI,WAAW,8CAIb,EAA2B,GAC3B,EAA2B,EAC3B,EAAa,EAUnB,OAAuB,CAMrB,YAAY,EAAmB,CAFvB,gBAAa,GAGnB,KAAK,UAAY,EACjB,KAAK,oBAAsB,GAAI,OAG/B,KAAK,kBAAoB,GAAI,OAG/B,iBACE,EACA,EACA,CACA,GAAI,KAAK,WAAY,CACnB,IACA,OAEF,KAAK,kBAAkB,KAAK,GACxB,GACF,KAAK,oBAAoB,KAAK,GAIlC,WAAW,EAAe,EAAe,CACvC,SAAW,KAAc,MAAK,oBAC5B,EAAW,EAAO,GAItB,UAAW,CACT,KAAK,WAAa,GAClB,SAAW,KAAY,MAAK,kBAC1B,KAQC,OAAqB,CAgE1B,YACE,EACA,EACA,EACA,EACA,CA3CM,uBAA6C,GAAI,OAcjD,wBAA+C,KAC/C,mBAAqC,KAKrC,6BAAkC,GAIlC,iCAAqC,EAMrC,4BAAyB,GAc/B,KAAK,aAAe,EACpB,KAAK,WAAa,GAAI,KACtB,KAAK,iBAAmB,EAGxB,KAAK,gBAAkB,GAAI,KAC3B,KAAK,kBAAoB,GAAI,KAC7B,KAAK,uBAAyB,GAAI,KAClC,KAAK,aAAa,EAAmB,EAAiB,GAEtD,KAAK,cAAgB,GAAI,GAAK,aAAa,MAC3C,KAAK,cAAgB,GAAI,GAAK,aAAa,MAC3C,KAAK,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ACrC,GAAI,CAAC,EAAU,CACb,EAAO,KAAK,4BAA8B,EAAe,MACzD,OAEF,KAAM,MAAK,cAAc,GACzB,IACA,KAAK,4BAA8B,EAAc,KAAK,WAAW,KACjE,GAAe,KAAM,GAAW,EAAa,KAAK,WAAW,QAGjE,KAAK,sBAAsB,QAGf,eAAc,EAAuC,CACjE,KAAM,GAAkB,KAAK,qBAAqB,IAAI,EAAS,MAC/D,GAAI,CAAC,EAAiB,CACpB,EAAO,KACL,2BACE,EAAS,KACT,WACA,EAAS,KACT,MAEJ,OAEF,KAAM,GAAgB,aAAa,EAAS,WAQxC,8BACJ,EACA,EACe,CACf,GAAI,KAAK,oBAAoB,GAC3B,OAEF,KAAM,MAAK,mBAAmB,EAAW,GAEzC,KAAM,GAAiB,KAAK,gBAAgB,IAAI,GAChD,GAAI,CAAC,EAAgB,CACnB,EAAO,KACL,2CAA8C,EAAY,MAE5D,OAGF,GAAI,GAAc,EAClB,SAAW,KAAgB,GAAgB,CACzC,KAAM,GAAW,KAAK,WAAW,IAAI,GACrC,GAAI,CAAC,EAAU,CACb,EAAO,KAAK,4BAA8B,EAAe,MACzD,SAEF,KAAM,MAAK,iBAAiB,GAC5B,IACA,GAAe,KAAM,GAAW,EAAa,EAAe,QAE9D,KAAK,qBAAqB,QAUtB,oBACJ,EACA,EACe,CACf,KAAK,uBAAyB,GAC9B,KAAM,GAAO,KAAK,iBAAiB,GACnC,MAAO,IAAI,SAAc,CAAC,EAAS,IAAW,CAC5C,GAAI,CAAC,EAAM,CACT,KAAK,uBAAyB,GAC9B,IACA,OAEF,EAAK,iBAAiB,IAAM,CAC1B,KAAK,uBAAyB,GAC9B,KACC,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2023 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('ResourceLoader');\n\n const addSearchParameterToUrl = (\n url: string,\n urlEncodedParameterName: string,\n urlEncodedValue: string\n ) => {\n if (url.startsWith('data:') || url.startsWith('blob:')) {\n // blob/data protocol does not support search parameters, which are useless anyway.\n return url;\n }\n\n const separator = url.indexOf('?') === -1 ? '?' : '&';\n return url + separator + urlEncodedParameterName + '=' + urlEncodedValue;\n };\n\n const checkIfIsGDevelopCloudBucketUrl = (url: string): boolean => {\n return (\n url.startsWith('https://project-resources.gdevelop.io/') ||\n url.startsWith('https://project-resources-dev.gdevelop.io/')\n );\n };\n\n const maxForegroundConcurrency = 20;\n const maxBackgroundConcurrency = 5;\n const maxAttempt = 3;\n\n /**\n * A task of pre-loading resources used by a scene.\n *\n * A Promise can't be used instead of this class because a Promise will start\n * as soon as possible. It would flood the server with downloading requests\n * and make impossible to finely tune in which order scenes are actually\n * downloaded.\n */\n class SceneLoadingTask {\n sceneName: string;\n private onProgressCallbacks: Array<(count: number, total: number) => void>;\n private onFinishCallbacks: Array<() => void>;\n private isFinished = false;\n\n constructor(sceneName: string) {\n this.sceneName = sceneName;\n this.onProgressCallbacks = new Array<\n (count: number, total: number) => void\n >();\n this.onFinishCallbacks = new Array<() => void>();\n }\n\n registerCallback(\n onFinish: () => void,\n onProgress?: (count: number, total: number) => void\n ) {\n if (this.isFinished) {\n onFinish();\n return;\n }\n this.onFinishCallbacks.push(onFinish);\n if (onProgress) {\n this.onProgressCallbacks.push(onProgress);\n }\n }\n\n onProgress(count: number, total: number) {\n for (const onProgress of this.onProgressCallbacks) {\n onProgress(count, total);\n }\n }\n\n onFinish() {\n this.isFinished = true;\n for (const onFinish of this.onFinishCallbacks) {\n onFinish();\n }\n }\n }\n\n /**\n * Pre-load resources of any kind needed for a game or a scene.\n */\n export class ResourceLoader {\n _runtimeGame: RuntimeGame;\n /**\n * All the resource of a game by resource name.\n */\n private _resources: Map<string, ResourceData>;\n /**\n * Resources needed for any scene. Typically, they are resources from\n * global objects.\n */\n private _globalResources: Array<string>;\n /**\n * Resources by scene names.\n */\n private _sceneResources: Map<string, Array<string>>;\n /**\n * Keep track of which scene whose resources has already be pre-loaded.\n */\n private _sceneNamesToLoad: Set<string>;\n /**\n * Keep track of which scene whose resources has already be loaded.\n */\n private _sceneNamesToMakeReady: Set<string>;\n /**\n * A queue of scenes whose resources are still to be pre-loaded.\n */\n private _sceneToLoadQueue: Array<SceneLoadingTask> = new Array<\n SceneLoadingTask\n >();\n /**\n * The resource managers that actually download and remember downloaded\n * content.\n */\n _resourceManagersMap: Map<ResourceKind, ResourceManager>;\n private _imageManager: ImageManager;\n private _soundManager: SoundManager;\n private _fontManager: FontManager;\n private _jsonManager: JsonManager;\n private _model3DManager: Model3DManager;\n private _bitmapFontManager: BitmapFontManager;\n private _spineAtlasManager: SpineAtlasManager | null = null;\n private _spineManager: SpineManager | null = null;\n\n /**\n * Only used by events.\n */\n private currentLoadingSceneName: string = '';\n /**\n * Only used by events.\n */\n private currentSceneLoadingProgress: float = 0;\n /**\n * It's set to `true` during intermediary loading screen to use a greater\n * concurrency as the game is paused and doesn't need bandwidth (for video\n * or music streaming or online multiplayer).\n */\n private _isLoadingInForeground = true;\n\n /**\n * @param runtimeGame The game.\n * @param resourceDataArray The resources data of the game.\n * @param globalResources The resources needed for any layer.\n * @param layoutDataArray The resources used by each layer.\n */\n constructor(\n runtimeGame: RuntimeGame,\n resourceDataArray: ResourceData[],\n globalResources: Array<string>,\n layoutDataArray: Array<LayoutData>\n ) {\n this._runtimeGame = runtimeGame;\n this._resources = new Map<string, ResourceData>();\n this._globalResources = globalResources;\n\n // These 3 attributes are filled by `setResources`.\n this._sceneResources = new Map<string, Array<string>>();\n this._sceneNamesToLoad = new Set<string>();\n this._sceneNamesToMakeReady = new Set<string>();\n this.setResources(resourceDataArray, globalResources, layoutDataArray);\n\n this._imageManager = new gdjs.ImageManager(this);\n this._soundManager = new gdjs.SoundManager(this);\n this._fontManager = new gdjs.FontManager(this);\n this._jsonManager = new gdjs.JsonManager(this);\n this._bitmapFontManager = new gdjs.BitmapFontManager(\n this,\n this._imageManager\n );\n this._model3DManager = new gdjs.Model3DManager(this);\n\n // add spine related managers only if spine extension is used\n if (gdjs.SpineAtlasManager && gdjs.SpineManager) {\n this._spineAtlasManager = new gdjs.SpineAtlasManager(\n this,\n this._imageManager\n );\n this._spineManager = new gdjs.SpineManager(\n this,\n this._spineAtlasManager\n );\n }\n\n const resourceManagers: Array<ResourceManager> = [\n this._imageManager,\n this._soundManager,\n this._fontManager,\n this._jsonManager,\n this._bitmapFontManager,\n this._model3DManager,\n ];\n\n if (this._spineAtlasManager)\n resourceManagers.push(this._spineAtlasManager);\n if (this._spineManager) resourceManagers.push(this._spineManager);\n\n this._resourceManagersMap = new Map<ResourceKind, ResourceManager>();\n for (const resourceManager of resourceManagers) {\n for (const resourceKind of resourceManager.getResourceKinds()) {\n this._resourceManagersMap.set(resourceKind, resourceManager);\n }\n }\n }\n\n /**\n * @returns the runtime game instance.\n */\n getRuntimeGame(): RuntimeGame {\n return this._runtimeGame;\n }\n\n /**\n * Update the resources data of the game. Useful for hot-reloading, should\n * not be used otherwise.\n */\n setResources(\n resourceDataArray: ResourceData[],\n globalResources: Array<string>,\n layoutDataArray: Array<LayoutData>\n ): void {\n this._globalResources = globalResources;\n\n this._sceneResources.clear();\n this._sceneNamesToLoad.clear();\n this._sceneNamesToMakeReady.clear();\n for (const layoutData of layoutDataArray) {\n this._sceneResources.set(\n layoutData.name,\n layoutData.usedResources.map((resource) => resource.name)\n );\n this._sceneNamesToLoad.add(layoutData.name);\n this._sceneNamesToMakeReady.add(layoutData.name);\n }\n // TODO Clearing the queue doesn't abort the running task, but it should\n // not matter as resource loading is really fast in preview mode.\n this._sceneToLoadQueue.length = 0;\n for (let index = layoutDataArray.length - 1; index >= 0; index--) {\n const layoutData = layoutDataArray[index];\n this._sceneToLoadQueue.push(new SceneLoadingTask(layoutData.name));\n }\n\n this._resources.clear();\n for (const resourceData of resourceDataArray) {\n if (!resourceData.file) {\n // Empty string or missing `file` field: not a valid resource, let's entirely ignore it.\n // Otherwise, this can confuse some loaders that will consider an empty string different\n // than a file that happen not to fail to load.\n continue;\n }\n\n this._resources.set(resourceData.name, resourceData);\n }\n }\n\n async loadAllResources(\n onProgress: (loadingCount: integer, totalCount: integer) => void\n ): Promise<void> {\n let loadedCount = 0;\n await processAndRetryIfNeededWithPromisePool(\n [...this._resources.values()],\n maxForegroundConcurrency,\n maxAttempt,\n async (resource) => {\n await this._loadResource(resource);\n await this._processResource(resource);\n loadedCount++;\n onProgress(loadedCount, this._resources.size);\n }\n );\n this._sceneNamesToLoad.clear();\n this._sceneNamesToMakeReady.clear();\n }\n\n /**\n * Load the resources that are needed to launch the first scene.\n */\n async loadGlobalAndFirstSceneResources(\n firstSceneName: string,\n onProgress: (count: number, total: number) => void\n ): Promise<void> {\n const sceneResources = this._sceneResources.get(firstSceneName);\n if (!sceneResources) {\n logger.warn(\n 'Can\\'t load resource for unknown scene: \"' + firstSceneName + '\".'\n );\n return;\n }\n let loadedCount = 0;\n const resources = [...this._globalResources, ...sceneResources.values()];\n await processAndRetryIfNeededWithPromisePool(\n resources,\n maxForegroundConcurrency,\n maxAttempt,\n async (resourceName) => {\n const resource = this._resources.get(resourceName);\n if (!resource) {\n logger.warn('Unable to find resource \"' + resourceName + '\".');\n return;\n }\n await this._loadResource(resource);\n await this._processResource(resource);\n loadedCount++;\n onProgress(loadedCount, resources.length);\n }\n );\n this._setSceneAssetsLoaded(firstSceneName);\n this._setSceneAssetsReady(firstSceneName);\n }\n\n /**\n * Load each scene in order.\n *\n * This is done in background to try to avoid loading screens when changing\n * scenes.\n */\n async loadAllSceneInBackground(): Promise<void> {\n while (this._sceneToLoadQueue.length > 0) {\n const task = this._sceneToLoadQueue[this._sceneToLoadQueue.length - 1];\n if (task === undefined) {\n continue;\n }\n this.currentLoadingSceneName = task.sceneName;\n if (!this.areSceneAssetsLoaded(task.sceneName)) {\n await this._doLoadSceneResources(\n task.sceneName,\n async (count, total) => task.onProgress(count, total)\n );\n // A scene may have been moved last while awaiting resources to be\n // downloaded (see _prioritizeScene).\n this._sceneToLoadQueue.splice(\n this._sceneToLoadQueue.findIndex((element) => element === task),\n 1\n );\n task.onFinish();\n } else {\n this._sceneToLoadQueue.pop();\n }\n }\n this.currentLoadingSceneName = '';\n }\n\n private async _doLoadSceneResources(\n sceneName: string,\n onProgress?: (count: number, total: number) => Promise<void>\n ): Promise<void> {\n const sceneResources = this._sceneResources.get(sceneName);\n if (!sceneResources) {\n logger.warn(\n 'Can\\'t load resource for unknown scene: \"' + sceneName + '\".'\n );\n return;\n }\n let loadedCount = 0;\n await processAndRetryIfNeededWithPromisePool(\n [...sceneResources.values()],\n this._isLoadingInForeground\n ? maxForegroundConcurrency\n : maxBackgroundConcurrency,\n maxAttempt,\n async (resourceName) => {\n const resource = this._resources.get(resourceName);\n if (!resource) {\n logger.warn('Unable to find resource \"' + resourceName + '\".');\n return;\n }\n await this._loadResource(resource);\n loadedCount++;\n this.currentSceneLoadingProgress = loadedCount / this._resources.size;\n onProgress && (await onProgress(loadedCount, this._resources.size));\n }\n );\n this._setSceneAssetsLoaded(sceneName);\n }\n\n private async _loadResource(resource: ResourceData): Promise<void> {\n const resourceManager = this._resourceManagersMap.get(resource.kind);\n if (!resourceManager) {\n logger.warn(\n 'Unknown resource kind: \"' +\n resource.kind +\n '\" for: \"' +\n resource.name +\n '\".'\n );\n return;\n }\n await resourceManager.loadResource(resource.name);\n }\n\n /**\n * Load and process a scene that is needed right away.\n *\n * The renderer will show a loading screen while its done.\n */\n async loadAndProcessSceneResources(\n sceneName: string,\n onProgress?: (count: number, total: number) => Promise<void>\n ): Promise<void> {\n if (this.areSceneAssetsReady(sceneName)) {\n return;\n }\n await this.loadSceneResources(sceneName, onProgress);\n\n const sceneResources = this._sceneResources.get(sceneName);\n if (!sceneResources) {\n logger.warn(\n 'Can\\'t load resource for unknown scene: \"' + sceneName + '\".'\n );\n return;\n }\n\n let parsedCount = 0;\n for (const resourceName of sceneResources) {\n const resource = this._resources.get(resourceName);\n if (!resource) {\n logger.warn('Unable to find resource \"' + resourceName + '\".');\n continue;\n }\n await this._processResource(resource);\n parsedCount++;\n onProgress && (await onProgress(parsedCount, sceneResources.length));\n }\n this._setSceneAssetsReady(sceneName);\n }\n\n /**\n * Load a scene resources without parsing them.\n *\n * When another scene resources are loading in background, it waits for\n * all its resources to be loaded before loading resources of the given\n * scene.\n */\n async loadSceneResources(\n sceneName: string,\n onProgress?: (count: number, total: number) => void\n ): Promise<void> {\n this._isLoadingInForeground = true;\n const task = this._prioritizeScene(sceneName);\n return new Promise<void>((resolve, reject) => {\n if (!task) {\n this._isLoadingInForeground = false;\n resolve();\n return;\n }\n task.registerCallback(() => {\n this._isLoadingInForeground = false;\n resolve();\n }, onProgress);\n });\n }\n\n /**\n * To be called when the game is disposed.\n * Dispose all the resource managers.\n */\n dispose(): void {\n for (const resourceManager of this._resourceManagersMap.values()) {\n resourceManager.dispose();\n }\n }\n\n /**\n * Put a given scene at the end of the queue.\n *\n * When the scene that is currently loading in background is done,\n * this scene will be the next to be loaded.\n */\n private _prioritizeScene(sceneName: string): SceneLoadingTask | null {\n const taskIndex = this._sceneToLoadQueue.findIndex(\n (task) => task.sceneName === sceneName\n );\n if (taskIndex < 0) {\n // The scene is already loaded.\n return null;\n }\n const task = this._sceneToLoadQueue[taskIndex];\n this._sceneToLoadQueue.splice(taskIndex, 1);\n this._sceneToLoadQueue.push(task);\n return task;\n }\n\n private async _processResource(resource: ResourceData): Promise<void> {\n const resourceManager = this._resourceManagersMap.get(resource.kind);\n if (!resourceManager) {\n logger.warn(\n 'Unknown resource kind: \"' +\n resource.kind +\n '\" for: \"' +\n resource.name +\n '\".'\n );\n return;\n }\n await resourceManager.processResource(resource.name);\n }\n\n getSceneLoadingProgress(sceneName: string): float {\n return sceneName === this.currentLoadingSceneName\n ? this.currentSceneLoadingProgress\n : this.areSceneAssetsLoaded(sceneName)\n ? 1\n : 0;\n }\n\n /**\n * @returns true when all the resources of the given scene are loaded\n * (but maybe not parsed).\n */\n areSceneAssetsLoaded(sceneName: string): boolean {\n return !this._sceneNamesToLoad.has(sceneName);\n }\n\n /**\n * @returns true when all the resources of the given scene are loaded and\n * parsed.\n */\n areSceneAssetsReady(sceneName: string): boolean {\n return !this._sceneNamesToMakeReady.has(sceneName);\n }\n\n private _setSceneAssetsLoaded(sceneName: string): void {\n this._sceneNamesToLoad.delete(sceneName);\n }\n\n private _setSceneAssetsReady(sceneName: string): void {\n this._sceneNamesToMakeReady.delete(sceneName);\n }\n\n getResource(resourceName: string): ResourceData | null {\n return this._resources.get(resourceName) || null;\n }\n\n // Helper methods used when resources are loaded from an URL.\n\n /**\n * Complete the given URL with any specific parameter required to access\n * the resource (this can be for example a token needed to access the resource).\n */\n getFullUrl(url: string) {\n const { gdevelopResourceToken } = this._runtimeGame._options;\n if (!gdevelopResourceToken) return url;\n\n if (!checkIfIsGDevelopCloudBucketUrl(url)) return url;\n\n return addSearchParameterToUrl(\n url,\n 'gd_resource_token',\n encodeURIComponent(gdevelopResourceToken)\n );\n }\n\n /**\n * Return true if the specified URL must be loaded with cookies (\"credentials\")\n * sent to grant access to them.\n */\n checkIfCredentialsRequired(url: string) {\n if (this._runtimeGame._options.gdevelopResourceToken) return false;\n\n // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n // Note that this is only useful during previews.\n if (checkIfIsGDevelopCloudBucketUrl(url)) return true;\n\n // For other resources, use the default way of loading resources (\"anonymous\" or \"same-site\").\n return false;\n }\n\n /**\n * Get the gdjs.SoundManager of the RuntimeGame.\n * @return The sound manager.\n */\n getSoundManager(): gdjs.HowlerSoundManager {\n return this._soundManager;\n }\n\n /**\n * Get the gdjs.ImageManager of the RuntimeGame.\n * @return The image manager.\n */\n getImageManager(): gdjs.PixiImageManager {\n return this._imageManager;\n }\n\n /**\n * Get the gdjs.FontManager of the RuntimeGame.\n * @return The font manager.\n */\n getFontManager(): gdjs.FontFaceObserverFontManager {\n return this._fontManager;\n }\n\n /**\n * Get the gdjs.BitmapFontManager of the RuntimeGame.\n * @return The bitmap font manager.\n */\n getBitmapFontManager(): gdjs.BitmapFontManager {\n return this._bitmapFontManager;\n }\n\n /**\n * Get the JSON manager of the game, used to load JSON from game\n * resources.\n * @return The json manager for the game\n */\n getJsonManager(): gdjs.JsonManager {\n return this._jsonManager;\n }\n\n /**\n * Get the 3D model manager of the game, used to load 3D model from game\n * resources.\n * @return The 3D model manager for the game\n */\n getModel3DManager(): gdjs.Model3DManager {\n return this._model3DManager;\n }\n\n /**\n * Get the Spine manager of the game, used to load and construct spine skeletons from game\n * resources.\n * @return The Spine manager for the game\n */\n getSpineManager(): gdjs.SpineManager | null {\n return this._spineManager;\n }\n\n /**\n * Get the Spine Atlas manager of the game, used to load atlases from game\n * resources.\n * @return The Spine Atlas manager for the game\n */\n getSpineAtlasManager(): gdjs.SpineAtlasManager | null {\n return this._spineAtlasManager;\n }\n }\n\n type PromiseError<T> = { item: T; error: Error };\n\n type PromisePoolOutput<T, U> = {\n results: Array<U>;\n errors: Array<PromiseError<T>>;\n };\n\n const processWithPromisePool = <T, U>(\n items: Array<T>,\n maxConcurrency: number,\n asyncFunction: (item: T) => Promise<U>\n ): Promise<PromisePoolOutput<T, U>> => {\n const results: Array<U> = [];\n const errors: Array<PromiseError<T>> = [];\n let activePromises = 0;\n let index = 0;\n\n return new Promise((resolve, reject) => {\n const executeNext = () => {\n if (items.length === 0) {\n resolve({ results, errors });\n return;\n }\n while (activePromises < maxConcurrency && index < items.length) {\n const item = items[index++];\n activePromises++;\n\n asyncFunction(item)\n .then((result) => results.push(result))\n .catch((error) => errors.push({ item, error }))\n .finally(() => {\n activePromises--;\n if (index === items.length && activePromises === 0) {\n resolve({ results, errors });\n } else {\n executeNext();\n }\n });\n }\n };\n\n executeNext();\n });\n };\n\n const processAndRetryIfNeededWithPromisePool = async <T, U>(\n items: Array<T>,\n maxConcurrency: number,\n maxAttempt: number,\n asyncFunction: (item: T) => Promise<U>\n ): Promise<PromisePoolOutput<T, U>> => {\n const output = await processWithPromisePool<T, U>(\n items,\n maxConcurrency,\n asyncFunction\n );\n if (output.errors.length !== 0) {\n logger.warn(\"Some assets couldn't be downloaded. Trying again now.\");\n }\n for (\n let attempt = 1;\n attempt < maxAttempt && output.errors.length !== 0;\n attempt++\n ) {\n const retryOutput = await processWithPromisePool<T, U>(\n items,\n maxConcurrency,\n asyncFunction\n );\n output.results.push.apply(output.results, retryOutput.results);\n output.errors = retryOutput.errors;\n }\n return output;\n };\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,kBAEzB,EAA0B,CAC9B,EACA,EACA,IACG,CACH,GAAI,EAAI,WAAW,UAAY,EAAI,WAAW,SAE5C,MAAO,GAGT,KAAM,GAAY,EAAI,QAAQ,OAAS,GAAK,IAAM,IAClD,MAAO,GAAM,EAAY,EAA0B,IAAM,GAGrD,EAAkC,AAAC,GAErC,EAAI,WAAW,2CACf,EAAI,WAAW,8CAIb,EAA2B,GAC3B,EAA2B,EAC3B,EAAa,EAUnB,OAAuB,CAMrB,YAAY,EAAmB,CAFvB,gBAAa,GAGnB,KAAK,UAAY,EACjB,KAAK,oBAAsB,GAAI,OAG/B,KAAK,kBAAoB,GAAI,OAG/B,iBACE,EACA,EACA,CACA,GAAI,KAAK,WAAY,CACnB,IACA,OAEF,KAAK,kBAAkB,KAAK,GACxB,GACF,KAAK,oBAAoB,KAAK,GAIlC,WAAW,EAAe,EAAe,CACvC,SAAW,KAAc,MAAK,oBAC5B,EAAW,EAAO,GAItB,UAAW,CACT,KAAK,WAAa,GAClB,SAAW,KAAY,MAAK,kBAC1B,KAQC,OAAqB,CAgE1B,YACE,EACA,EACA,EACA,EACA,CA3CM,uBAA6C,GAAI,OAcjD,wBAA+C,KAC/C,mBAAqC,KAKrC,6BAAkC,GAIlC,iCAAqC,EAMrC,4BAAyB,GAc/B,KAAK,aAAe,EACpB,KAAK,WAAa,GAAI,KACtB,KA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,CACvC,MAAO,MAAK,gBAQd,iBAA4C,CAC1C,MAAO,MAAK,cAQd,sBAAsD,CACpD,MAAO,MAAK,oBAviBT,EAAM,iBAkjBb,KAAM,GAAyB,CAC7B,EACA,EACA,IACqC,CACrC,KAAM,GAAoB,GACpB,EAAiC,GACvC,GAAI,GAAiB,EACjB,EAAQ,EAEZ,MAAO,IAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,KAAM,GAAc,IAAM,CACxB,GAAI,EAAM,SAAW,EAAG,CACtB,EAAQ,CAAE,UAAS,WACnB,OAEF,KAAO,EAAiB,GAAkB,EAAQ,EAAM,QAAQ,CAC9D,KAAM,GAAO,EAAM,KACnB,IAEA,EAAc,GACX,KAAK,AAAC,GAAW,EAAQ,KAAK,IAC9B,MAAM,AAAC,GAAU,EAAO,KAAK,CAAE,OAAM,WACrC,QAAQ,IAAM,CACb,IACA,AAAI,IAAU,EAAM,QAAU,IAAmB,EAC/C,EAAQ,CAAE,UAAS,WAEnB,QAMV,OAIE,EAAyC,MAC7C,EACA,EACA,EACA,IACqC,CACrC,KAAM,GAAS,KAAM,GACnB,EACA,EACA,GAEF,AAAI,EAAO,OAAO,SAAW,GAC3B,EAAO,KAAK,yDAEd,OACM,GAAU,EACd,EAAU,GAAc,EAAO,OAAO,SAAW,EACjD,IACA,CACA,KAAM,GAAc,KAAM,GACxB,EACA,EACA,GAEF,EAAO,QAAQ,KAAK,MAAM,EAAO,QAAS,EAAY,SACtD,EAAO,OAAS,EAAY,OAE9B,MAAO,MApsBD",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var gdjs;(function(i){const a=s=>{const e=atob(s.split(",")[1]),t=s.split(",")[0].split(":")[1].split(";")[0],n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return new Blob([n],{type:t})};class o{constructor(e,t){this._gameRenderer=e,this._captureOptions=t}setupCaptureOptions(e){if(!(!e||!this._captureOptions.screenshots))for(const t of this._captureOptions.screenshots)setTimeout(async()=>{await this.takeAndUploadScreenshot(t.signedUrl)},t.delayTimeInSeconds)}async takeAndUploadScreenshot(e){const t=this._gameRenderer.getCanvas();if(t)try{const n=t.toDataURL("image/png"),r=a(n);await fetch(e,{method:"PUT",body:r,headers:{"Content-Type":"image/png"}})}catch(n){console.error("Error while uploading screenshot:",n)}}}i.CaptureManager=o})(gdjs||(gdjs={}));
|
|
2
|
+
//# sourceMappingURL=capturemanager.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../GDevelop/GDJS/Runtime/capturemanager.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n export type CaptureOptions = {\n screenshots?: Array<{\n delayTimeInSeconds: number;\n signedUrl: string;\n publicUrl: string;\n }>;\n };\n\n /**\n * Helper function to convert a base64 string to a Blob, which can be uploaded to a server.\n */\n const base64ToBlob = (base64) => {\n const byteString = atob(base64.split(',')[1]);\n const mimeString = base64.split(',')[0].split(':')[1].split(';')[0];\n\n const arrayBuffer = new Uint8Array(byteString.length);\n for (let i = 0; i < byteString.length; i++) {\n arrayBuffer[i] = byteString.charCodeAt(i);\n }\n\n return new Blob([arrayBuffer], { type: mimeString });\n };\n\n /**\n * Manage the captures (screenshots, videos, etc...) that need to be taken during the game.\n */\n export class CaptureManager {\n _gameRenderer: gdjs.RuntimeGameRenderer;\n _captureOptions: CaptureOptions;\n\n constructor(\n renderer: gdjs.RuntimeGameRenderer,\n captureOptions: CaptureOptions\n ) {\n this._gameRenderer = renderer;\n this._captureOptions = captureOptions;\n }\n\n /**\n * To be called when the scene has started rendering.\n */\n setupCaptureOptions(isPreview: boolean): void {\n if (!isPreview || !this._captureOptions.screenshots) {\n return;\n }\n\n for (const screenshotCaptureOption of this._captureOptions.screenshots) {\n setTimeout(async () => {\n await this.takeAndUploadScreenshot(screenshotCaptureOption.signedUrl);\n }, screenshotCaptureOption.delayTimeInSeconds);\n }\n }\n\n /**\n * Take a screenshot and upload it to the server.\n */\n async takeAndUploadScreenshot(signedUrl: string) {\n const canvas = this._gameRenderer.getCanvas();\n if (canvas) {\n try {\n const base64Data = canvas.toDataURL('image/png');\n const blobData = base64ToBlob(base64Data);\n\n await fetch(signedUrl, {\n method: 'PUT',\n body: blobData,\n headers: {\n 'Content-Type': 'image/png',\n },\n });\n } catch (error) {\n console.error('Error while uploading screenshot:', error);\n }\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAYE,KAAM,GAAe,AAAC,GAAW,CAC/B,KAAM,GAAa,KAAK,EAAO,MAAM,KAAK,IACpC,EAAa,EAAO,MAAM,KAAK,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,GAE3D,EAAc,GAAI,YAAW,EAAW,QAC9C,OAAS,GAAI,EAAG,EAAI,EAAW,OAAQ,IACrC,EAAY,GAAK,EAAW,WAAW,GAGzC,MAAO,IAAI,MAAK,CAAC,GAAc,CAAE,KAAM,KAMlC,OAAqB,CAI1B,YACE,EACA,EACA,CACA,KAAK,cAAgB,EACrB,KAAK,gBAAkB,EAMzB,oBAAoB,EAA0B,CAC5C,GAAI,GAAC,GAAa,CAAC,KAAK,gBAAgB,aAIxC,SAAW,KAA2B,MAAK,gBAAgB,YACzD,WAAW,SAAY,CACrB,KAAM,MAAK,wBAAwB,EAAwB,YAC1D,EAAwB,yBAOzB,yBAAwB,EAAmB,CAC/C,KAAM,GAAS,KAAK,cAAc,YAClC,GAAI,EACF,GAAI,CACF,KAAM,GAAa,EAAO,UAAU,aAC9B,EAAW,EAAa,GAE9B,KAAM,OAAM,EAAW,CACrB,OAAQ,MACR,KAAM,EACN,QAAS,CACP,eAAgB,qBAGb,EAAP,CACA,QAAQ,MAAM,oCAAqC,KA7CpD,EAAM,mBA3BL",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(i){const
|
|
1
|
+
var gdjs;(function(i){const s=new i.Logger("Font manager"),d=["font"];class c{constructor(r){this._loadedFontFamily=new i.ResourceCache;this._loadedFontFamilySet=new Set;this._resourceLoader=r}getResourceKinds(){return d}getFontFamily(r){return this._loadedFontFamily.getFromName(r)||"Arial"}getFontFile(r){const e=this._resourceLoader.getResource(r);return e?e.file||"":r}_getFontFamilyFromFilename(r){let e="gdjs_font_"+r.file.toLowerCase().replace(/[^\w]/gi,"-");const o=e;let n=2;for(;this._loadedFontFamilySet.has(e);)e=e+"-"+n,n++;return o}_loadFont(r,e){const o={},n="url("+encodeURI(e)+")";if(typeof FontFace!="undefined")return fetch(this._resourceLoader.getFullUrl(e),{credentials:this._resourceLoader.checkIfCredentialsRequired(e)?"include":"same-origin"}).then(t=>{if(!t.ok){const a="Unable to fetch "+e+" to be loaded as a font. HTTP status is: "+t.status+".";throw s.error(a),new Error(a)}return t.arrayBuffer()}).then(t=>{const a=new FontFace(r,t,o);document.fonts.add(a)});{const t=document.createElement("style");return t.appendChild(document.createTextNode("@font-face { font-family: '"+r+"'; src: "+n+"; }")),document.head.appendChild(t),new FontFaceObserver(r,o).load()}}async processResource(r){}async loadResource(r){const e=this._resourceLoader.getResource(r);if(!e){s.warn('Unable to find font for resource "'+r+'".');return}if(this._loadedFontFamily.get(e))return;const o=e.file;if(!o)return;const n=this._getFontFamilyFromFilename(e);this._loadedFontFamily.set(e,n),this._loadedFontFamilySet.add(n);try{await this._loadFont(n,o)}catch(t){s.error('Error loading font resource "'+e.name+'" (file: '+o+"): "+(t.message||"Unknown error"))}}dispose(){this._loadedFontFamily.clear(),this._loadedFontFamilySet.clear()}}i.FontFaceObserverFontManager=c,i.FontManager=c})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=fontfaceobserver-font-manager.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../GDevelop/GDJS/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Font manager');\n\n const resourceKinds: Array<ResourceKind> = ['font'];\n\n /**\n * FontFaceObserverFontManager loads fonts (using `FontFace` or `fontfaceobserver` library)\n * from the game resources (see `loadFonts`), and allow to access to\n * the font families of the loaded fonts during the game (see `getFontFamily`).\n */\n export class FontFaceObserverFontManager implements gdjs.ResourceManager {\n _resourceLoader: gdjs.ResourceLoader;\n // Associate font resource names to the loaded font family\n _loadedFontFamily = new gdjs.ResourceCache<string>();\n _loadedFontFamilySet = new Set<string>();\n\n /**\n * @param resources The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Return the font family associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * a default font family will be returned (\"Arial\").\n *\n * @param resourceName The name of the resource to get.\n * @returns The font family to be used for this font resource,\n * or \"Arial\" if not loaded.\n */\n getFontFamily(resourceName: string): string {\n return this._loadedFontFamily.getFromName(resourceName) || 'Arial';\n }\n\n /**\n * Return the font file associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * the resource name will be returned (to\n * keep compatibility with GDevelop 5.0-beta56 and previous).\n *\n * Should only be useful for renderers running on a non HTML5/non browser environment.\n *\n * @param resourceName The name of the resource to get.\n * @returns The file of the font resource.\n */\n getFontFile(resourceName: string): string {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource ? resource.file || '' : resourceName;\n }\n\n /**\n * Return the font family to use for a given filename.\n * Each filename is guaranteed to have a unique font family. You should not rely\n * on the font family formatting (consider it as an \"opaque string\") - it's slugified\n * (no spaces, no dots, no non-alphanumeric characters) to avoid issues when using the\n * font family in various contexts.\n *\n * @param filename The filename of the font.\n * @returns The font family to be used for this font resource.\n */\n _getFontFamilyFromFilename(resource: ResourceData): string {\n // Replaces all non-alphanumeric characters with dashes to ensure no issues when\n // referring to this font family (see https://github.com/4ian/GDevelop/issues/1521).\n let baseSlugifiedName =\n 'gdjs_font_' + resource.file.toLowerCase().replace(/[^\\w]/gi, '-');\n\n // Ensure the generated font family is unique.\n const slugifiedName = baseSlugifiedName;\n let uniqueSuffix = 2;\n while (this._loadedFontFamilySet.has(baseSlugifiedName)) {\n baseSlugifiedName = baseSlugifiedName + '-' + uniqueSuffix;\n uniqueSuffix++;\n }\n return slugifiedName;\n }\n\n /**\n * Load the font at the given `src` location (relative to the project), giving\n * it the specified `fontFamily` name.\n *\n * This uses FontFace (if supported) or @font-face + FontFaceObserver\n * to load a font from an url and be notified when loading is done (or failed).\n *\n * @param fontFamily The font\n * @returns The font family to be used for this font resource.\n */\n private _loadFont(fontFamily: string, src: string): Promise<void> {\n const descriptors = {};\n const srcWithUrl = 'url(' + encodeURI(src) + ')';\n\n // @ts-ignore\n if (typeof FontFace !== 'undefined') {\n // Load the given font using CSS Font Loading API.\n return fetch(this._resourceLoader.getFullUrl(src), {\n credentials: this._resourceLoader.checkIfCredentialsRequired(src)\n ? // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n })\n .then((response) => {\n if (!response.ok) {\n const errorMessage =\n 'Unable to fetch ' +\n src +\n ' to be loaded as a font. HTTP status is: ' +\n response.status +\n '.';\n logger.error(errorMessage);\n throw new Error(errorMessage);\n }\n\n return response.arrayBuffer();\n })\n .then((arrayBuffer) => {\n // @ts-ignore\n const fontFace = new FontFace(fontFamily, arrayBuffer, descriptors);\n\n // @ts-ignore\n document.fonts.add(fontFace);\n });\n } else {\n // TODO: this method of loading font should be removed as old and not allowing\n // to handle loading with credentials. All moderns and not-so-modern browsers\n // that we support also support FontFace API.\n\n // Add @font-face and use FontFaceObserver to be notified when the\n // font is ready.\n const newStyle = document.createElement('style');\n newStyle.appendChild(\n document.createTextNode(\n \"@font-face { font-family: '\" +\n fontFamily +\n \"'; src: \" +\n srcWithUrl +\n '; }'\n )\n );\n document.head.appendChild(newStyle);\n\n // @ts-ignore\n return new FontFaceObserver(fontFamily, descriptors).load();\n }\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because fonts are light enough to be parsed in background.\n }\n\n /**\n * Load the specified resources, so that fonts are loaded and can then be\n * used by using the font family returned by getFontFamily.\n * @param onProgress Callback called each time a new file is loaded.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find font for resource \"' + resourceName + '\".');\n return;\n }\n\n if (this._loadedFontFamily.get(resource)) {\n return;\n }\n const file = resource.file;\n if (!file) {\n return;\n }\n\n const fontFamily = this._getFontFamilyFromFilename(resource);\n // Cache the result to avoid collision with a similar slugified name for another filename.\n this._loadedFontFamily.set(resource, fontFamily);\n this._loadedFontFamilySet.add(fontFamily);\n try {\n await this._loadFont(fontFamily, file);\n } catch (error) {\n logger.error(\n 'Error loading font resource \"' +\n resource.name +\n '\" (file: ' +\n file +\n '): ' +\n (error.message || 'Unknown error')\n );\n }\n }\n }\n\n //Register the class to let the engine use it.\n export type FontManager = FontFaceObserverFontManager;\n export const FontManager = FontFaceObserverFontManager;\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,gBAEzB,EAAqC,CAAC,QAOrC,OAAkE,CAUvE,YAAY,EAAqC,CAPjD,uBAAoB,GAAI,GAAK,cAC7B,0BAAuB,GAAI,KA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,2BAA2B,GAEnD,KAAK,kBAAkB,IAAI,EAAU,GACrC,KAAK,qBAAqB,IAAI,GAC9B,GAAI,CACF,KAAM,MAAK,UAAU,EAAY,SAC1B,EAAP,CACA,EAAO,MACL,gCACE,EAAS,KACT,YACA,EACA,MACC,GAAM,SAAW,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Font manager');\n\n const resourceKinds: Array<ResourceKind> = ['font'];\n\n /**\n * FontFaceObserverFontManager loads fonts (using `FontFace` or `fontfaceobserver` library)\n * from the game resources (see `loadFonts`), and allow to access to\n * the font families of the loaded fonts during the game (see `getFontFamily`).\n */\n export class FontFaceObserverFontManager implements gdjs.ResourceManager {\n _resourceLoader: gdjs.ResourceLoader;\n // Associate font resource names to the loaded font family\n _loadedFontFamily = new gdjs.ResourceCache<string>();\n _loadedFontFamilySet = new Set<string>();\n\n /**\n * @param resources The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Return the font family associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * a default font family will be returned (\"Arial\").\n *\n * @param resourceName The name of the resource to get.\n * @returns The font family to be used for this font resource,\n * or \"Arial\" if not loaded.\n */\n getFontFamily(resourceName: string): string {\n return this._loadedFontFamily.getFromName(resourceName) || 'Arial';\n }\n\n /**\n * Return the font file associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * the resource name will be returned (to\n * keep compatibility with GDevelop 5.0-beta56 and previous).\n *\n * Should only be useful for renderers running on a non HTML5/non browser environment.\n *\n * @param resourceName The name of the resource to get.\n * @returns The file of the font resource.\n */\n getFontFile(resourceName: string): string {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource ? resource.file || '' : resourceName;\n }\n\n /**\n * Return the font family to use for a given filename.\n * Each filename is guaranteed to have a unique font family. You should not rely\n * on the font family formatting (consider it as an \"opaque string\") - it's slugified\n * (no spaces, no dots, no non-alphanumeric characters) to avoid issues when using the\n * font family in various contexts.\n *\n * @param filename The filename of the font.\n * @returns The font family to be used for this font resource.\n */\n _getFontFamilyFromFilename(resource: ResourceData): string {\n // Replaces all non-alphanumeric characters with dashes to ensure no issues when\n // referring to this font family (see https://github.com/4ian/GDevelop/issues/1521).\n let baseSlugifiedName =\n 'gdjs_font_' + resource.file.toLowerCase().replace(/[^\\w]/gi, '-');\n\n // Ensure the generated font family is unique.\n const slugifiedName = baseSlugifiedName;\n let uniqueSuffix = 2;\n while (this._loadedFontFamilySet.has(baseSlugifiedName)) {\n baseSlugifiedName = baseSlugifiedName + '-' + uniqueSuffix;\n uniqueSuffix++;\n }\n return slugifiedName;\n }\n\n /**\n * Load the font at the given `src` location (relative to the project), giving\n * it the specified `fontFamily` name.\n *\n * This uses FontFace (if supported) or @font-face + FontFaceObserver\n * to load a font from an url and be notified when loading is done (or failed).\n *\n * @param fontFamily The font\n * @returns The font family to be used for this font resource.\n */\n private _loadFont(fontFamily: string, src: string): Promise<void> {\n const descriptors = {};\n const srcWithUrl = 'url(' + encodeURI(src) + ')';\n\n // @ts-ignore\n if (typeof FontFace !== 'undefined') {\n // Load the given font using CSS Font Loading API.\n return fetch(this._resourceLoader.getFullUrl(src), {\n credentials: this._resourceLoader.checkIfCredentialsRequired(src)\n ? // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n })\n .then((response) => {\n if (!response.ok) {\n const errorMessage =\n 'Unable to fetch ' +\n src +\n ' to be loaded as a font. HTTP status is: ' +\n response.status +\n '.';\n logger.error(errorMessage);\n throw new Error(errorMessage);\n }\n\n return response.arrayBuffer();\n })\n .then((arrayBuffer) => {\n // @ts-ignore\n const fontFace = new FontFace(fontFamily, arrayBuffer, descriptors);\n\n // @ts-ignore\n document.fonts.add(fontFace);\n });\n } else {\n // TODO: this method of loading font should be removed as old and not allowing\n // to handle loading with credentials. All moderns and not-so-modern browsers\n // that we support also support FontFace API.\n\n // Add @font-face and use FontFaceObserver to be notified when the\n // font is ready.\n const newStyle = document.createElement('style');\n newStyle.appendChild(\n document.createTextNode(\n \"@font-face { font-family: '\" +\n fontFamily +\n \"'; src: \" +\n srcWithUrl +\n '; }'\n )\n );\n document.head.appendChild(newStyle);\n\n // @ts-ignore\n return new FontFaceObserver(fontFamily, descriptors).load();\n }\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because fonts are light enough to be parsed in background.\n }\n\n /**\n * Load the specified resources, so that fonts are loaded and can then be\n * used by using the font family returned by getFontFamily.\n * @param onProgress Callback called each time a new file is loaded.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find font for resource \"' + resourceName + '\".');\n return;\n }\n\n if (this._loadedFontFamily.get(resource)) {\n return;\n }\n const file = resource.file;\n if (!file) {\n return;\n }\n\n const fontFamily = this._getFontFamilyFromFilename(resource);\n // Cache the result to avoid collision with a similar slugified name for another filename.\n this._loadedFontFamily.set(resource, fontFamily);\n this._loadedFontFamilySet.add(fontFamily);\n try {\n await this._loadFont(fontFamily, file);\n } catch (error) {\n logger.error(\n 'Error loading font resource \"' +\n resource.name +\n '\" (file: ' +\n file +\n '): ' +\n (error.message || 'Unknown error')\n );\n }\n }\n\n /**\n * To be called when the game is disposed.\n * Clear caches of loaded font families.\n */\n dispose(): void {\n this._loadedFontFamily.clear();\n this._loadedFontFamilySet.clear();\n }\n }\n\n //Register the class to let the engine use it.\n export type FontManager = FontFaceObserverFontManager;\n export const FontManager = FontFaceObserverFontManager;\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,U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,EAAU,CACb,EAAO,KAAK,qCAAuC,EAAe,MAClE,OAGF,GAAI,KAAK,kBAAkB,IAAI,GAC7B,OAEF,KAAM,GAAO,EAAS,KACtB,GAAI,CAAC,EACH,OAGF,KAAM,GAAa,KAAK,2BAA2B,GAEnD,KAAK,kBAAkB,IAAI,EAAU,GACrC,KAAK,qBAAqB,IAAI,GAC9B,GAAI,CACF,KAAM,MAAK,UAAU,EAAY,SAC1B,EAAP,CACA,EAAO,MACL,gCACE,EAAS,KACT,YACA,EACA,MACC,GAAM,SAAW,mBAS1B,SAAgB,CACd,KAAK,kBAAkB,QACvB,KAAK,qBAAqB,SA/LvB,EAAM,8BAqMA,cAAc,IA/MnB",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(a){const h=new a.Logger("Audio manager"),f=["audio"],c={preload:!0,onplayerror:(u,e)=>h.error("Can't play an audio file: "+e),onloaderror:(u,e)=>h.error("Error while loading an audio file: "+e)},d=u=>u>1?1:u<0?0:u;class g{constructor(e,s,t,o){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=d(s),this._loop=t,this._rate=o}isLoaded(){return this._howl.state()==="loaded"}play(){if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(a.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(s=>{this.on("play",s),s(e)}),this._oncePlay.forEach(s=>s(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play());return this}pause(){return this._id!==null&&this._howl.pause(this._id),this}stop(){return this._id!==null&&this._howl.stop(this._id),this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){return this._rate=e,this._id!==null&&(e=a.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id)),this}getLoop(){return this._loop}setLoop(e){return this._loop=e,this._id!==null&&this._howl.loop(e,this._id),this}getVolume(){return this._id===null?this._initialVolume:this._howl.volume(this._id)}setVolume(e){return this._initialVolume=d(e),this._id!==null&&this._howl.volume(this._initialVolume,this._id),this}getMute(){return this._id===null?!1:this._howl.mute(this._id)}setMute(e){return this._id!==null&&this._howl.mute(e,this._id),this}getSeek(){return this._id===null?0:this._howl.seek(this._id)}setSeek(e){return this._id!==null&&this._howl.seek(e,this._id),this}getSpatialPosition(e){return this._id===null?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,s,t){return this._id!==null&&this._howl.pos(e,s,t,this._id),this}fade(e,s,t){return this._id!==null&&this._howl.fade(d(e),d(s),t,this._id),this}on(e,s){return e==="play"?this._id===null?this._onPlay.push(s):this._howl.on(e,s,this._id):this._id===null?this.once("play",()=>this.on(e,s)):this._howl.on(e,s,this._id),this}once(e,s){return e==="play"?this._id===null?this._oncePlay.push(s):this.playing()?s(this._id):this._howl.once(e,s,this._id):this._id===null?this.once("play",()=>this.once(e,s)):this._howl.once(e,s,this._id),this}off(e,s){return this._id!==null&&this._howl.off(e,s,this._id),this}}a.HowlerSound=g;class p{constructor(e){this._loadedMusics=new a.ResourceCache;this._loadedSounds=new a.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:{file:e,kind:"audio",metadata:"",name:e}};this._resourceLoader=e;const s=this;document.addEventListener("deviceready",function(){document.addEventListener("pause",function(){const t=s._freeSounds.concat(s._freeMusics);for(let o in s._sounds)s._sounds.hasOwnProperty(o)&&t.push(s._sounds[o]);for(let o in s._musics)s._musics.hasOwnProperty(o)&&t.push(s._musics[o]);for(let o=0;o<t.length;o++){const i=t[o];!i.paused()&&!i.stopped()&&(i.pause(),s._pausedSounds.push(i))}s._paused=!0},!1),document.addEventListener("resume",function(){try{for(let t=0;t<s._pausedSounds.length;t++){const o=s._pausedSounds[t];o.stopped()||o.play()}}catch(t){if(t.message&&typeof t.message=="string"&&t.message.startsWith("Maximum call stack size exceeded"))console.warn("An error occurred when resuming paused sounds while the game was in background:",t);else throw t}s._pausedSounds.length=0,s._paused=!1},!1)})}getResourceKinds(){return f}static clampRate(e){return e>4?4:e<.5?.5:e}_storeSoundInArray(e,s){for(let t=0,o=e.length;t<o;++t)if(!e[t]||e[t].stopped())return e[t]=s,s;return e.push(s),s}createHowlerSound(e,s,t,o,i){const l=s?this._loadedMusics:this._loadedSounds,r=this._getAudioResource(e);let n=l.get(r);if(!n){const _=r?r.file:e;n=new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(_)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(_)},volume:0},c)),l.set(r,n)}return new a.HowlerSound(n,t,o,i)}loadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e);t.get(o)||t.set(o,new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(o.file)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(o.file)},volume:0},c)))}unloadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e),i=t.get(o);if(!i)return;function l(r){for(let n in r)r[n]&&r[n]._howl===i&&(r[n].stop(),delete r[n])}l(this._freeMusics),l(this._freeSounds),l(Object.values(this._musics)),l(Object.values(this._sounds)),l(this._pausedSounds),i.unload(),t.delete(o)}unloadAll(){Howler.unload(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0,this._loadedMusics.clear(),this._loadedSounds.clear()}playSound(e,s,t,o){const i=this.createHowlerSound(e,!1,t/100,s,o);this._storeSoundInArray(this._freeSounds,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playSoundOnChannel(e,s,t,o,i){this._sounds[s]&&this._sounds[s].stop();const l=this.createHowlerSound(e,!1,o/100,t,i);this._sounds[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getSoundOnChannel(e){return this._sounds[e]||null}playMusic(e,s,t,o){const i=this.createHowlerSound(e,!0,t/100,s,o);this._storeSoundInArray(this._freeMusics,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playMusicOnChannel(e,s,t,o,i){this._musics[s]&&this._musics[s].stop();const l=this.createHowlerSound(e,!0,o/100,t,i);this._musics[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getMusicOnChannel(e){return this._musics[e]||null}setGlobalVolume(e){this._globalVolume=e,this._globalVolume>100&&(this._globalVolume=100),this._globalVolume<0&&(this._globalVolume=0),Howler.volume(this._globalVolume/100)}getGlobalVolume(){return this._globalVolume}clearAll(){Howler.stop(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0}async processResource(e){}async loadResource(e){const s=this._resourceLoader.getResource(e);if(!s){h.warn('Unable to find audio for resource "'+e+'".');return}if(s.file){if(this._availableResources[s.name])return;this._availableResources[s.name]=s}const t=(i,l)=>new Promise((r,n)=>{const _=l?this._loadedMusics:this._loadedSounds;_[i]=new Howl(Object.assign({},c,{src:[this._resourceLoader.getFullUrl(i)],onload:r,onloaderror:(y,w)=>n(w),html5:l,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(i)},volume:0}))}),o=s.file;if(s.preloadAsMusic)try{await t(o,!0)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}if(s.preloadAsSound)try{await t(o,!1)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}else if(s.preloadInCache||!s.preloadAsMusic)try{await new Promise((i,l)=>{const r=new XMLHttpRequest;r.withCredentials=this._resourceLoader.checkIfCredentialsRequired(o),r.addEventListener("load",i),r.addEventListener("error",n=>l("XHR error: "+o)),r.addEventListener("abort",n=>l("XHR abort: "+o)),r.open("GET",this._resourceLoader.getFullUrl(o)),r.send()})}catch(i){h.warn("There was an error while preloading an audio file: "+i)}}}a.HowlerSoundManager=p,a.SoundManager=p})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(a){const h=new a.Logger("Audio manager"),f=["audio"],c={preload:!0,onplayerror:(u,e)=>h.error("Can't play an audio file: "+e),onloaderror:(u,e)=>h.error("Error while loading an audio file: "+e)},d=u=>u>1?1:u<0?0:u;class g{constructor(e,s,t,o){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=d(s),this._loop=t,this._rate=o}isLoaded(){return this._howl.state()==="loaded"}play(){if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(a.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(s=>{this.on("play",s),s(e)}),this._oncePlay.forEach(s=>s(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play());return this}pause(){return this._id!==null&&this._howl.pause(this._id),this}stop(){return this._id!==null&&this._howl.stop(this._id),this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){return this._rate=e,this._id!==null&&(e=a.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id)),this}getLoop(){return this._loop}setLoop(e){return this._loop=e,this._id!==null&&this._howl.loop(e,this._id),this}getVolume(){return this._id===null?this._initialVolume:this._howl.volume(this._id)}setVolume(e){return this._initialVolume=d(e),this._id!==null&&this._howl.volume(this._initialVolume,this._id),this}getMute(){return this._id===null?!1:this._howl.mute(this._id)}setMute(e){return this._id!==null&&this._howl.mute(e,this._id),this}getSeek(){return this._id===null?0:this._howl.seek(this._id)}setSeek(e){return this._id!==null&&this._howl.seek(e,this._id),this}getSpatialPosition(e){return this._id===null?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,s,t){return this._id!==null&&this._howl.pos(e,s,t,this._id),this}fade(e,s,t){return this._id!==null&&this._howl.fade(d(e),d(s),t,this._id),this}on(e,s){return e==="play"?this._id===null?this._onPlay.push(s):this._howl.on(e,s,this._id):this._id===null?this.once("play",()=>this.on(e,s)):this._howl.on(e,s,this._id),this}once(e,s){return e==="play"?this._id===null?this._oncePlay.push(s):this.playing()?s(this._id):this._howl.once(e,s,this._id):this._id===null?this.once("play",()=>this.once(e,s)):this._howl.once(e,s,this._id),this}off(e,s){return this._id!==null&&this._howl.off(e,s,this._id),this}}a.HowlerSound=g;class p{constructor(e){this._loadedMusics=new a.ResourceCache;this._loadedSounds=new a.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:{file:e,kind:"audio",metadata:"",name:e}};this._resourceLoader=e;const s=this;document.addEventListener("deviceready",function(){document.addEventListener("pause",function(){const t=s._freeSounds.concat(s._freeMusics);for(let o in s._sounds)s._sounds.hasOwnProperty(o)&&t.push(s._sounds[o]);for(let o in s._musics)s._musics.hasOwnProperty(o)&&t.push(s._musics[o]);for(let o=0;o<t.length;o++){const i=t[o];!i.paused()&&!i.stopped()&&(i.pause(),s._pausedSounds.push(i))}s._paused=!0},!1),document.addEventListener("resume",function(){try{for(let t=0;t<s._pausedSounds.length;t++){const o=s._pausedSounds[t];o.stopped()||o.play()}}catch(t){if(t.message&&typeof t.message=="string"&&t.message.startsWith("Maximum call stack size exceeded"))console.warn("An error occurred when resuming paused sounds while the game was in background:",t);else throw t}s._pausedSounds.length=0,s._paused=!1},!1)})}getResourceKinds(){return f}static clampRate(e){return e>4?4:e<.5?.5:e}_storeSoundInArray(e,s){for(let t=0,o=e.length;t<o;++t)if(!e[t]||e[t].stopped())return e[t]=s,s;return e.push(s),s}createHowlerSound(e,s,t,o,i){const l=s?this._loadedMusics:this._loadedSounds,r=this._getAudioResource(e);let n=l.get(r);if(!n){const _=r?r.file:e;n=new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(_)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(_)},volume:0},c)),l.set(r,n)}return new a.HowlerSound(n,t,o,i)}loadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e);t.get(o)||t.set(o,new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(o.file)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(o.file)},volume:0},c)))}unloadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e),i=t.get(o);if(!i)return;function l(r){for(let n in r)r[n]&&r[n]._howl===i&&(r[n].stop(),delete r[n])}l(this._freeMusics),l(this._freeSounds),l(Object.values(this._musics)),l(Object.values(this._sounds)),l(this._pausedSounds),i.unload(),t.delete(o)}unloadAll(){Howler.unload(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0,this._loadedMusics.clear(),this._loadedSounds.clear()}playSound(e,s,t,o){const i=this.createHowlerSound(e,!1,t/100,s,o);this._storeSoundInArray(this._freeSounds,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playSoundOnChannel(e,s,t,o,i){this._sounds[s]&&this._sounds[s].stop();const l=this.createHowlerSound(e,!1,o/100,t,i);this._sounds[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getSoundOnChannel(e){return this._sounds[e]||null}playMusic(e,s,t,o){const i=this.createHowlerSound(e,!0,t/100,s,o);this._storeSoundInArray(this._freeMusics,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playMusicOnChannel(e,s,t,o,i){this._musics[s]&&this._musics[s].stop();const l=this.createHowlerSound(e,!0,o/100,t,i);this._musics[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getMusicOnChannel(e){return this._musics[e]||null}setGlobalVolume(e){this._globalVolume=e,this._globalVolume>100&&(this._globalVolume=100),this._globalVolume<0&&(this._globalVolume=0),Howler.volume(this._globalVolume/100)}getGlobalVolume(){return this._globalVolume}clearAll(){Howler.stop(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0}async processResource(e){}async loadResource(e){const s=this._resourceLoader.getResource(e);if(!s){h.warn('Unable to find audio for resource "'+e+'".');return}if(s.file){if(this._availableResources[s.name])return;this._availableResources[s.name]=s}const t=(i,l)=>new Promise((r,n)=>{const _=l?this._loadedMusics:this._loadedSounds;_[i]=new Howl(Object.assign({},c,{src:[this._resourceLoader.getFullUrl(i)],onload:r,onloaderror:(y,w)=>n(w),html5:l,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(i)},volume:0}))}),o=s.file;if(s.preloadAsMusic)try{await t(o,!0)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}if(s.preloadAsSound)try{await t(o,!1)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}else if(s.preloadInCache||!s.preloadAsMusic)try{await new Promise((i,l)=>{const r=new XMLHttpRequest;r.withCredentials=this._resourceLoader.checkIfCredentialsRequired(o),r.addEventListener("load",i),r.addEventListener("error",n=>l("XHR error: "+o)),r.addEventListener("abort",n=>l("XHR abort: "+o)),r.open("GET",this._resourceLoader.getFullUrl(o)),r.send()})}catch(i){h.warn("There was an error while preloading an audio file: "+i)}}dispose(){this.unloadAll()}}a.HowlerSoundManager=p,a.SoundManager=p})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=howler-sound-manager.js.map
|