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.
Files changed (47) hide show
  1. package/dist/Runtime/Extensions/3D/JsExtension.js +7 -3
  2. package/dist/Runtime/Extensions/DialogueTree/JsExtension.js +44 -32
  3. package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js +2 -2
  4. package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js.map +2 -2
  5. package/dist/Runtime/Extensions/Multiplayer/JsExtension.js +15 -0
  6. package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
  7. package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
  8. package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
  9. package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
  10. package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
  11. package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
  12. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js +1 -1
  13. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js.map +2 -2
  14. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js +1 -1
  15. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js.map +2 -2
  16. package/dist/Runtime/Model3DManager.js +1 -1
  17. package/dist/Runtime/Model3DManager.js.map +2 -2
  18. package/dist/Runtime/ResourceLoader.js +1 -1
  19. package/dist/Runtime/ResourceLoader.js.map +2 -2
  20. package/dist/Runtime/capturemanager.js +2 -0
  21. package/dist/Runtime/capturemanager.js.map +7 -0
  22. package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js +1 -1
  23. package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js.map +2 -2
  24. package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
  25. package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
  26. package/dist/Runtime/jsonmanager.js +1 -1
  27. package/dist/Runtime/jsonmanager.js.map +2 -2
  28. package/dist/Runtime/layer.js +1 -1
  29. package/dist/Runtime/layer.js.map +2 -2
  30. package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js +1 -1
  31. package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js.map +2 -2
  32. package/dist/Runtime/pixi-renderers/pixi-image-manager.js +1 -1
  33. package/dist/Runtime/pixi-renderers/pixi-image-manager.js.map +2 -2
  34. package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js +1 -1
  35. package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js.map +2 -2
  36. package/dist/Runtime/runtimegame.js +1 -1
  37. package/dist/Runtime/runtimegame.js.map +2 -2
  38. package/dist/Runtime/runtimewatermark.js +2 -2
  39. package/dist/Runtime/runtimewatermark.js.map +2 -2
  40. package/dist/Runtime/scenestack.js +1 -1
  41. package/dist/Runtime/scenestack.js.map +2 -2
  42. package/dist/Runtime/spriteruntimeobject.js +1 -1
  43. package/dist/Runtime/spriteruntimeobject.js.map +2 -2
  44. package/dist/lib/libGD.cjs +1 -1
  45. package/dist/lib/libGD.wasm +0 -0
  46. package/gd.d.ts +22 -6
  47. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../GDevelop/GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts"],
4
- "sourcesContent": ["///<reference path='../types/howler'>\n/*\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('Audio manager');\n\n const resourceKinds: Array<ResourceKind> = ['audio'];\n\n const HowlParameters: HowlOptions = {\n preload: true,\n onplayerror: (_, error) =>\n logger.error(\"Can't play an audio file: \" + error),\n onloaderror: (_, error) =>\n logger.error('Error while loading an audio file: ' + error),\n };\n\n /**\n * Ensure the volume is between 0 and 1.\n */\n const clampVolume = (volume: float): float => {\n if (volume > 1.0) {\n return 1.0;\n }\n if (volume < 0) {\n return 0;\n }\n return volume;\n };\n\n /**\n * A thin wrapper around a Howl object with:\n * * Handling of callbacks when the sound is not yet loaded.\n * * Automatic clamping when calling `setRate` to ensure a valid value is passed to Howler.js.\n * * Automatic clamping when calling `setVolume` so that the volume is always between 0 and 1.\n *\n * @memberof gdjs\n * @class HowlerSound\n */\n export class HowlerSound {\n /**\n * The ID of the played sound.\n */\n private _id: integer | null = null;\n\n /**\n * The Howl passed to the constructor.\n * It defines the sound file that is being played.\n */\n private _howl: Howl;\n\n /**\n * The **initial** volume at which the sound is being played.\n * Once the sound is started, this volume can be not in sync\n * (in the case the sound is faded by Howler), so volume must\n * be gotten from `this._howl` directly.\n *\n * This value is clamped between 0 and 1.\n */\n private _initialVolume: float;\n\n /**\n * Whether the sound is being played in a loop or not.\n */\n private _loop: boolean;\n\n /**\n * The rate (speed) the sound is being played at.\n * This value is not clamped, though technically Howler.js will only\n * accepts values between a specific range (so we clamp this when\n * passing it to Howler.js, but keep the original value here).\n */\n private _rate: float;\n\n /**\n * An array of callbacks to call once the sound starts to play.\n */\n private _oncePlay: Array<HowlCallback> = [];\n\n /**\n * An array of callbacks to call everytime the sound starts to play.\n */\n private _onPlay: Array<HowlCallback> = [];\n\n constructor(howl: Howl, volume: float, loop: boolean, rate: float) {\n this._howl = howl;\n this._initialVolume = clampVolume(volume);\n this._loop = loop;\n this._rate = rate;\n }\n\n /**\n * Returns true if the associated howl is fully loaded.\n */\n isLoaded(): boolean {\n return this._howl.state() === 'loaded';\n }\n\n /**\n * Begins playback of the sound, or if the Howl is still loading, schedule playing for once it loads.\n * @returns The current instance for chaining.\n */\n play(): this {\n if (this.isLoaded()) {\n const newID = this._howl.play(\n this._id === null ? '__default' : this._id\n );\n this._id = newID;\n\n // Set the howl properties as soon as the sound is played and we have its ID.\n this._howl.volume(this._initialVolume, newID); // this._initialVolume is already clamped between 0 and 1.\n this._howl.loop(this._loop, newID);\n // this._rate is not clamped, but we need to clamp it when passing it to Howler.js as it\n // only supports a specific range.\n this._howl.rate(gdjs.HowlerSoundManager.clampRate(this._rate), newID);\n\n // Manually handle the play event before we have an ID.\n // Before loading, howler won't register events as without an ID we cannot set a listener.\n // Once we have an ID, we can transfer control of the events to howler.\n // We also need to call them once as Howler doesn't for the first play event.\n this._onPlay.forEach((func) => {\n // Transfer the event to howler now that we have an ID\n this.on('play', func);\n func(newID);\n });\n this._oncePlay.forEach((func) => func(newID));\n this._onPlay = [];\n this._oncePlay = [];\n } else this._howl.once('load', () => this.play()); // Play only once the howl is fully loaded\n\n return this;\n }\n\n /**\n * Pauses playback of the sound, saving the seek of playback.\n * @returns The current instance for chaining.\n */\n pause(): this {\n if (this._id !== null) this._howl.pause(this._id);\n return this;\n }\n\n /**\n * Stops playback of the sound, resetting seek to 0.\n * @returns The current instance for chaining.\n */\n stop(): this {\n if (this._id !== null) this._howl.stop(this._id);\n return this;\n }\n\n /**\n * Check if the sound is currently playing.\n * Note that a loading sound is considered as playing (as it will be\n * played as soon as it's loaded). To avoid loading at runtime, prefer\n * to preload the sounds.\n */\n playing(): boolean {\n return (\n (this._id !== null ? this._howl.playing(this._id) : true) ||\n !this.isLoaded() // Loading is considered playing\n );\n }\n\n /**\n * Check if the sound is currently paused.\n */\n paused(): boolean {\n return !this.playing();\n }\n\n /**\n * Check if the sound is currently stopped.\n */\n stopped(): boolean {\n return this.paused() && this.getSeek() === 0;\n }\n\n /**\n * Get the sound playback rate. This 1 for the default speed.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n */\n getRate(): float {\n return this._rate;\n }\n\n /**\n * Set the playback rate.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n * @returns The current instance for chaining.\n */\n setRate(rate: float): this {\n this._rate = rate;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) {\n rate = gdjs.HowlerSoundManager.clampRate(rate);\n this._howl.rate(rate, this._id);\n }\n return this;\n }\n\n /**\n * Get if the sound is looping.\n */\n getLoop(): boolean {\n return this._loop;\n }\n\n /**\n * Set if the sound is looping.\n * @returns The current instance for chaining.\n */\n setLoop(loop: boolean): this {\n this._loop = loop;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.loop(loop, this._id);\n return this;\n }\n\n //TODO: Replace float type in those 2 methods with RangeOf<0..1> once it is standardized (https://github.com/Microsoft/TypeScript/issues/15480)\n /**\n * Get the sound volume.\n * @returns A float from 0 to 1.\n */\n getVolume(): float {\n if (this._id === null) return this._initialVolume;\n return this._howl.volume(this._id);\n }\n\n /**\n * Set the sound volume.\n * @param volume A float from 0 to 1. The value is clamped if too high or too low.\n * @returns The current instance for chaining.\n */\n setVolume(volume: float): this {\n this._initialVolume = clampVolume(volume);\n\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.volume(this._initialVolume, this._id);\n return this;\n }\n\n /**\n * Get if the sound is muted.\n */\n getMute(): boolean {\n if (this._id === null) return false;\n return this._howl.mute(this._id);\n }\n\n /**\n * Set if the sound is muted.\n * @returns The current instance for chaining.\n */\n setMute(mute: boolean): this {\n if (this._id !== null) this._howl.mute(mute, this._id);\n return this;\n }\n\n /**\n * Get the sound seek.\n */\n getSeek(): float {\n if (this._id === null) return 0;\n return this._howl.seek(this._id);\n }\n\n /**\n * Set the sound seek.\n * @returns The current instance for chaining.\n */\n setSeek(seek: float): this {\n if (this._id !== null) this._howl.seek(seek, this._id);\n return this;\n }\n\n /**\n * Get the sound spatial position.\n */\n getSpatialPosition(axis: 'x' | 'y' | 'z'): float {\n if (this._id === null) return 0;\n return this._howl.pos(this._id)[axis === 'x' ? 0 : axis === 'y' ? 1 : 2];\n }\n\n /**\n * Set the sound spatial position.\n * @returns The current instance for chaining.\n */\n setSpatialPosition(x: float, y: float, z: float): this {\n if (this._id !== null) this._howl.pos(x, y, z, this._id);\n return this;\n }\n\n /**\n * Fade the volume sound.\n * @returns The current instance for chaining.\n */\n fade(from: float, to: float, duration: float): this {\n if (this._id !== null)\n this._howl.fade(clampVolume(from), clampVolume(to), duration, this._id);\n return this;\n }\n\n /**\n * Adds an event listener to the howl.\n */\n on(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._onPlay.push(handler);\n } else {\n this._howl.on(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.on(event, handler));\n else this._howl.on(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Adds an event listener to the howl that removes itself after being called.\n * If the event is `play` and the sound is being played, the handler is\n * called synchronously.\n */\n once(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._oncePlay.push(handler);\n } else if (this.playing()) {\n // Immediately call the handler if the sound is already playing.\n // This is useful for sounds that were just started and have a `.once('play', ...)`\n // handler added on them to set up the volume/rate/loop. If we don't do it\n // synchronously, the sound can play for a tiny bit at the default volume and rate.\n // See https://github.com/4ian/GDevelop/issues/2490.\n handler(this._id);\n } else {\n this._howl.once(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.once(event, handler));\n else this._howl.once(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Removes an event listener to the howl.\n */\n off(event: HowlEvent, handler: HowlCallback): this {\n if (this._id !== null) this._howl.off(event, handler, this._id);\n return this;\n }\n }\n\n /**\n * HowlerSoundManager is used to manage the sounds and musics of a RuntimeScene.\n *\n * It is basically a container to associate channels to sounds and keep a list\n * of all sounds being played.\n */\n export class HowlerSoundManager {\n _loadedMusics = new gdjs.ResourceCache<Howl>();\n _loadedSounds = new gdjs.ResourceCache<Howl>();\n _availableResources: Record<string, ResourceData> = {};\n _globalVolume: float = 100;\n _sounds: Record<integer, HowlerSound> = {};\n _musics: Record<integer, HowlerSound> = {};\n _freeSounds: HowlerSound[] = []; // Sounds without an assigned channel.\n _freeMusics: HowlerSound[] = []; // Musics without an assigned channel.\n\n /** Paused sounds or musics that should be played once the game is resumed. */\n _pausedSounds: HowlerSound[] = [];\n _paused: boolean = false;\n\n _resourceLoader: gdjs.ResourceLoader;\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 const that = this;\n document.addEventListener('deviceready', function () {\n // pause/resume sounds in Cordova when the app is being paused/resumed\n document.addEventListener(\n 'pause',\n function () {\n const soundList = that._freeSounds.concat(that._freeMusics);\n for (let key in that._sounds) {\n if (that._sounds.hasOwnProperty(key)) {\n soundList.push(that._sounds[key]);\n }\n }\n for (let key in that._musics) {\n if (that._musics.hasOwnProperty(key)) {\n soundList.push(that._musics[key]);\n }\n }\n for (let i = 0; i < soundList.length; i++) {\n const sound = soundList[i];\n if (!sound.paused() && !sound.stopped()) {\n sound.pause();\n that._pausedSounds.push(sound);\n }\n }\n that._paused = true;\n },\n false\n );\n document.addEventListener(\n 'resume',\n function () {\n try {\n for (let i = 0; i < that._pausedSounds.length; i++) {\n const sound = that._pausedSounds[i];\n if (!sound.stopped()) {\n sound.play();\n }\n }\n } catch (error) {\n if (\n error.message &&\n typeof error.message === 'string' &&\n error.message.startsWith('Maximum call stack size exceeded')\n ) {\n console.warn(\n 'An error occurred when resuming paused sounds while the game was in background:',\n error\n );\n } else {\n throw error;\n }\n }\n that._pausedSounds.length = 0;\n that._paused = false;\n },\n false\n );\n });\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Ensure rate is in a range valid for Howler.js\n * @return The clamped rate\n */\n static clampRate(rate: float): float {\n if (rate > 4.0) {\n return 4.0;\n }\n if (rate < 0.5) {\n return 0.5;\n }\n return rate;\n }\n\n /**\n * Return the file associated to the given sound name.\n *\n * Names and files are loaded from resources when preloadAudio is called. If no\n * file is associated to the given name, then the name will be considered as a\n * filename and will be returned.\n *\n * @return The associated resource\n */\n private _getAudioResource = (resourceName: string): ResourceData => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : ({\n file: resourceName,\n kind: 'audio',\n metadata: '',\n name: resourceName,\n } as ResourceData);\n };\n\n /**\n * Store the sound in the specified array, put it at the first index that\n * is free, or add it at the end if no element is free\n * (\"free\" means that the gdjs.HowlerSound can be destroyed).\n *\n * @param arr The array containing the sounds.\n * @param arr The gdjs.HowlerSound to add.\n * @return The gdjs.HowlerSound that have been added (i.e: the second parameter).\n */\n private _storeSoundInArray(\n arr: Array<HowlerSound>,\n sound: HowlerSound\n ): HowlerSound {\n // Try to recycle an old sound.\n for (let i = 0, len = arr.length; i < len; ++i) {\n if (!arr[i] || arr[i].stopped()) {\n arr[i] = sound;\n return sound;\n }\n }\n\n arr.push(sound);\n return sound;\n }\n\n /**\n * Creates a new gdjs.HowlerSound using preloaded/cached Howl instances.\n * @param soundName The name of the file or resource to play.\n * @param isMusic True if a music, false if a sound.\n * @param volume Between 0 and 1.\n * @param loop True if it should be played looping.\n * @param rate speed at which it is played.\n */\n createHowlerSound(\n soundName: string,\n isMusic: boolean,\n volume: float,\n loop: boolean,\n rate: float\n ): HowlerSound {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n let howl = cacheContainer.get(resource);\n if (!howl) {\n const fileName = resource ? resource.file : soundName;\n howl = new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(fileName)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n fileName\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n );\n cacheContainer.set(resource, howl);\n }\n\n return new gdjs.HowlerSound(howl, volume, loop, rate);\n }\n\n /**\n * Preloads a sound or a music in memory.\n * @param soundName The name of the file or resource to preload.\n * @param isMusic True if a music, false if a sound.\n */\n loadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n // Do not reload if it is already loaded.\n if (cacheContainer.get(resource)) {\n return;\n }\n\n cacheContainer.set(\n resource,\n new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(resource.file)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n )\n );\n }\n\n /**\n * Unloads a sound or a music from memory. This will stop any sound/music using it.\n * @param soundName The name of the file or resource to unload.\n * @param isMusic True if a music, false if a sound.\n */\n unloadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n const howl = cacheContainer.get(resource);\n if (!howl) {\n return;\n }\n\n // Make sure any sound using the howl is deleted so\n // that the howl can be garbage collected\n // and no weird \"zombies\" using the unloaded howl can exist.\n function clearContainer(howlerSoundContainer: HowlerSound[]) {\n for (let i in howlerSoundContainer) {\n if (\n howlerSoundContainer[i] &&\n //@ts-ignore We really need to access the raw howl here.\n howlerSoundContainer[i]._howl === howl\n ) {\n howlerSoundContainer[i].stop();\n delete howlerSoundContainer[i];\n }\n }\n }\n\n clearContainer(this._freeMusics);\n clearContainer(this._freeSounds);\n clearContainer(Object.values(this._musics));\n clearContainer(Object.values(this._sounds));\n clearContainer(this._pausedSounds);\n\n howl.unload();\n cacheContainer.delete(resource);\n }\n\n /**\n * Unloads all audio from memory.\n * This will clear the Howl cache.\n * This will also stop any running music or sounds.\n */\n unloadAll() {\n Howler.unload();\n\n // Clean up old sounds that still have the dead Howl instances.\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n this._loadedMusics.clear();\n this._loadedSounds.clear();\n }\n\n playSound(soundName: string, loop: boolean, volume: float, pitch: float) {\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeSounds, sound);\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n playSoundOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._sounds[channel]) this._sounds[channel].stop();\n\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._sounds[channel] = sound;\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n getSoundOnChannel(channel: integer): HowlerSound | null {\n return this._sounds[channel] || null;\n }\n\n playMusic(soundName: string, loop: boolean, volume: float, pitch: float) {\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeMusics, music);\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n playMusicOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._musics[channel]) this._musics[channel].stop();\n\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._musics[channel] = music;\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n getMusicOnChannel(channel: integer): HowlerSound | null {\n return this._musics[channel] || null;\n }\n\n setGlobalVolume(volume: float): void {\n this._globalVolume = volume;\n if (this._globalVolume > 100) {\n this._globalVolume = 100;\n }\n if (this._globalVolume < 0) {\n this._globalVolume = 0;\n }\n Howler.volume(this._globalVolume / 100);\n }\n\n getGlobalVolume(): float {\n return this._globalVolume;\n }\n\n clearAll() {\n Howler.stop();\n\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because sounds are light enough to be parsed in background.\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 audio for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (resource.file) {\n if (this._availableResources[resource.name]) {\n return;\n }\n\n this._availableResources[resource.name] = resource;\n }\n\n const preloadAudioFile = (\n file: string,\n isMusic: boolean\n ): Promise<number> => {\n return new Promise((resolve, reject) => {\n const container = isMusic ? this._loadedMusics : this._loadedSounds;\n container[file] = new Howl(\n Object.assign({}, HowlParameters, {\n src: [this._resourceLoader.getFullUrl(file)],\n onload: resolve,\n onloaderror: (soundId: number, error?: string) => reject(error),\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n })\n );\n });\n };\n\n const file = resource.file;\n if (resource.preloadAsMusic) {\n try {\n await preloadAudioFile(file, /* isMusic= */ true);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n\n if (resource.preloadAsSound) {\n try {\n await preloadAudioFile(file, /* isMusic= */ false);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n } else if (\n resource.preloadInCache ||\n // Force downloading of sounds.\n // TODO Decide if sounds should be allowed to be downloaded after the scene starts.\n // - they should be requested automatically at the end of the scene loading\n // - they will be downloaded while the scene is playing\n // - other scenes will be pre-loaded only when all the sounds for the current scene are in cache\n !resource.preloadAsMusic\n ) {\n // preloading as sound already does a XHR request, hence \"else if\"\n try {\n await new Promise((resolve, reject) => {\n const sound = new XMLHttpRequest();\n sound.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n file\n );\n sound.addEventListener('load', resolve);\n sound.addEventListener('error', (_) =>\n reject('XHR error: ' + file)\n );\n sound.addEventListener('abort', (_) =>\n reject('XHR abort: ' + file)\n );\n sound.open('GET', this._resourceLoader.getFullUrl(file));\n sound.send();\n });\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n }\n }\n\n // Register the class to let the engine use it.\n export const SoundManager = HowlerSoundManager;\n export type SoundManager = HowlerSoundManager;\n}\n"],
5
- "mappings": "AAMA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,iBAEzB,EAAqC,CAAC,SAEtC,EAA8B,CAClC,QAAS,GACT,YAAa,CAAC,EAAG,IACf,EAAO,MAAM,6BAA+B,GAC9C,YAAa,CAAC,EAAG,IACf,EAAO,MAAM,sCAAwC,IAMnD,EAAc,AAAC,GACf,EAAS,EACJ,EAEL,EAAS,EACJ,EAEF,EAYF,OAAkB,CA6CvB,YAAY,EAAY,EAAe,EAAe,EAAa,CAzC3D,SAAsB,KAkCtB,eAAiC,GAKjC,aAA+B,GAGrC,KAAK,MAAQ,EACb,KAAK,eAAiB,EAAY,GAClC,KAAK,MAAQ,EACb,KAAK,MAAQ,EAMf,UAAoB,CAClB,MAAO,MAAK,MAAM,UAAY,SAOhC,MAAa,CACX,GAAI,KAAK,WAAY,CACnB,KAAM,GAAQ,KAAK,MAAM,KACvB,KAAK,MAAQ,KAAO,YAAc,KAAK,KAEzC,KAAK,IAAM,EAGX,KAAK,MAAM,OAAO,KAAK,eAAgB,GACvC,KAAK,MAAM,KAAK,KAAK,MAAO,GAG5B,KAAK,MAAM,KAAK,EAAK,mBAAmB,UAAU,KAAK,OAAQ,GAM/D,KAAK,QAAQ,QAAQ,AAA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ACrC,KAAM,GAAQ,GAAI,gBAClB,EAAM,gBAAkB,KAAK,gBAAgB,2BAC3C,GAEF,EAAM,iBAAiB,OAAQ,GAC/B,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,KAAK,MAAO,KAAK,gBAAgB,WAAW,IAClD,EAAM,eAED,EAAP,CACA,EAAO,KACL,sDAAwD,KAlf3D,EAAM,qBA0fA,eAAe,IAn2BpB",
4
+ "sourcesContent": ["///<reference path='../types/howler'>\n/*\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('Audio manager');\n\n const resourceKinds: Array<ResourceKind> = ['audio'];\n\n const HowlParameters: HowlOptions = {\n preload: true,\n onplayerror: (_, error) =>\n logger.error(\"Can't play an audio file: \" + error),\n onloaderror: (_, error) =>\n logger.error('Error while loading an audio file: ' + error),\n };\n\n /**\n * Ensure the volume is between 0 and 1.\n */\n const clampVolume = (volume: float): float => {\n if (volume > 1.0) {\n return 1.0;\n }\n if (volume < 0) {\n return 0;\n }\n return volume;\n };\n\n /**\n * A thin wrapper around a Howl object with:\n * * Handling of callbacks when the sound is not yet loaded.\n * * Automatic clamping when calling `setRate` to ensure a valid value is passed to Howler.js.\n * * Automatic clamping when calling `setVolume` so that the volume is always between 0 and 1.\n *\n * @memberof gdjs\n * @class HowlerSound\n */\n export class HowlerSound {\n /**\n * The ID of the played sound.\n */\n private _id: integer | null = null;\n\n /**\n * The Howl passed to the constructor.\n * It defines the sound file that is being played.\n */\n private _howl: Howl;\n\n /**\n * The **initial** volume at which the sound is being played.\n * Once the sound is started, this volume can be not in sync\n * (in the case the sound is faded by Howler), so volume must\n * be gotten from `this._howl` directly.\n *\n * This value is clamped between 0 and 1.\n */\n private _initialVolume: float;\n\n /**\n * Whether the sound is being played in a loop or not.\n */\n private _loop: boolean;\n\n /**\n * The rate (speed) the sound is being played at.\n * This value is not clamped, though technically Howler.js will only\n * accepts values between a specific range (so we clamp this when\n * passing it to Howler.js, but keep the original value here).\n */\n private _rate: float;\n\n /**\n * An array of callbacks to call once the sound starts to play.\n */\n private _oncePlay: Array<HowlCallback> = [];\n\n /**\n * An array of callbacks to call everytime the sound starts to play.\n */\n private _onPlay: Array<HowlCallback> = [];\n\n constructor(howl: Howl, volume: float, loop: boolean, rate: float) {\n this._howl = howl;\n this._initialVolume = clampVolume(volume);\n this._loop = loop;\n this._rate = rate;\n }\n\n /**\n * Returns true if the associated howl is fully loaded.\n */\n isLoaded(): boolean {\n return this._howl.state() === 'loaded';\n }\n\n /**\n * Begins playback of the sound, or if the Howl is still loading, schedule playing for once it loads.\n * @returns The current instance for chaining.\n */\n play(): this {\n if (this.isLoaded()) {\n const newID = this._howl.play(\n this._id === null ? '__default' : this._id\n );\n this._id = newID;\n\n // Set the howl properties as soon as the sound is played and we have its ID.\n this._howl.volume(this._initialVolume, newID); // this._initialVolume is already clamped between 0 and 1.\n this._howl.loop(this._loop, newID);\n // this._rate is not clamped, but we need to clamp it when passing it to Howler.js as it\n // only supports a specific range.\n this._howl.rate(gdjs.HowlerSoundManager.clampRate(this._rate), newID);\n\n // Manually handle the play event before we have an ID.\n // Before loading, howler won't register events as without an ID we cannot set a listener.\n // Once we have an ID, we can transfer control of the events to howler.\n // We also need to call them once as Howler doesn't for the first play event.\n this._onPlay.forEach((func) => {\n // Transfer the event to howler now that we have an ID\n this.on('play', func);\n func(newID);\n });\n this._oncePlay.forEach((func) => func(newID));\n this._onPlay = [];\n this._oncePlay = [];\n } else this._howl.once('load', () => this.play()); // Play only once the howl is fully loaded\n\n return this;\n }\n\n /**\n * Pauses playback of the sound, saving the seek of playback.\n * @returns The current instance for chaining.\n */\n pause(): this {\n if (this._id !== null) this._howl.pause(this._id);\n return this;\n }\n\n /**\n * Stops playback of the sound, resetting seek to 0.\n * @returns The current instance for chaining.\n */\n stop(): this {\n if (this._id !== null) this._howl.stop(this._id);\n return this;\n }\n\n /**\n * Check if the sound is currently playing.\n * Note that a loading sound is considered as playing (as it will be\n * played as soon as it's loaded). To avoid loading at runtime, prefer\n * to preload the sounds.\n */\n playing(): boolean {\n return (\n (this._id !== null ? this._howl.playing(this._id) : true) ||\n !this.isLoaded() // Loading is considered playing\n );\n }\n\n /**\n * Check if the sound is currently paused.\n */\n paused(): boolean {\n return !this.playing();\n }\n\n /**\n * Check if the sound is currently stopped.\n */\n stopped(): boolean {\n return this.paused() && this.getSeek() === 0;\n }\n\n /**\n * Get the sound playback rate. This 1 for the default speed.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n */\n getRate(): float {\n return this._rate;\n }\n\n /**\n * Set the playback rate.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n * @returns The current instance for chaining.\n */\n setRate(rate: float): this {\n this._rate = rate;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) {\n rate = gdjs.HowlerSoundManager.clampRate(rate);\n this._howl.rate(rate, this._id);\n }\n return this;\n }\n\n /**\n * Get if the sound is looping.\n */\n getLoop(): boolean {\n return this._loop;\n }\n\n /**\n * Set if the sound is looping.\n * @returns The current instance for chaining.\n */\n setLoop(loop: boolean): this {\n this._loop = loop;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.loop(loop, this._id);\n return this;\n }\n\n //TODO: Replace float type in those 2 methods with RangeOf<0..1> once it is standardized (https://github.com/Microsoft/TypeScript/issues/15480)\n /**\n * Get the sound volume.\n * @returns A float from 0 to 1.\n */\n getVolume(): float {\n if (this._id === null) return this._initialVolume;\n return this._howl.volume(this._id);\n }\n\n /**\n * Set the sound volume.\n * @param volume A float from 0 to 1. The value is clamped if too high or too low.\n * @returns The current instance for chaining.\n */\n setVolume(volume: float): this {\n this._initialVolume = clampVolume(volume);\n\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.volume(this._initialVolume, this._id);\n return this;\n }\n\n /**\n * Get if the sound is muted.\n */\n getMute(): boolean {\n if (this._id === null) return false;\n return this._howl.mute(this._id);\n }\n\n /**\n * Set if the sound is muted.\n * @returns The current instance for chaining.\n */\n setMute(mute: boolean): this {\n if (this._id !== null) this._howl.mute(mute, this._id);\n return this;\n }\n\n /**\n * Get the sound seek.\n */\n getSeek(): float {\n if (this._id === null) return 0;\n return this._howl.seek(this._id);\n }\n\n /**\n * Set the sound seek.\n * @returns The current instance for chaining.\n */\n setSeek(seek: float): this {\n if (this._id !== null) this._howl.seek(seek, this._id);\n return this;\n }\n\n /**\n * Get the sound spatial position.\n */\n getSpatialPosition(axis: 'x' | 'y' | 'z'): float {\n if (this._id === null) return 0;\n return this._howl.pos(this._id)[axis === 'x' ? 0 : axis === 'y' ? 1 : 2];\n }\n\n /**\n * Set the sound spatial position.\n * @returns The current instance for chaining.\n */\n setSpatialPosition(x: float, y: float, z: float): this {\n if (this._id !== null) this._howl.pos(x, y, z, this._id);\n return this;\n }\n\n /**\n * Fade the volume sound.\n * @returns The current instance for chaining.\n */\n fade(from: float, to: float, duration: float): this {\n if (this._id !== null)\n this._howl.fade(clampVolume(from), clampVolume(to), duration, this._id);\n return this;\n }\n\n /**\n * Adds an event listener to the howl.\n */\n on(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._onPlay.push(handler);\n } else {\n this._howl.on(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.on(event, handler));\n else this._howl.on(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Adds an event listener to the howl that removes itself after being called.\n * If the event is `play` and the sound is being played, the handler is\n * called synchronously.\n */\n once(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._oncePlay.push(handler);\n } else if (this.playing()) {\n // Immediately call the handler if the sound is already playing.\n // This is useful for sounds that were just started and have a `.once('play', ...)`\n // handler added on them to set up the volume/rate/loop. If we don't do it\n // synchronously, the sound can play for a tiny bit at the default volume and rate.\n // See https://github.com/4ian/GDevelop/issues/2490.\n handler(this._id);\n } else {\n this._howl.once(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.once(event, handler));\n else this._howl.once(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Removes an event listener to the howl.\n */\n off(event: HowlEvent, handler: HowlCallback): this {\n if (this._id !== null) this._howl.off(event, handler, this._id);\n return this;\n }\n }\n\n /**\n * HowlerSoundManager is used to manage the sounds and musics of a RuntimeScene.\n *\n * It is basically a container to associate channels to sounds and keep a list\n * of all sounds being played.\n */\n export class HowlerSoundManager {\n _loadedMusics = new gdjs.ResourceCache<Howl>();\n _loadedSounds = new gdjs.ResourceCache<Howl>();\n _availableResources: Record<string, ResourceData> = {};\n _globalVolume: float = 100;\n _sounds: Record<integer, HowlerSound> = {};\n _musics: Record<integer, HowlerSound> = {};\n _freeSounds: HowlerSound[] = []; // Sounds without an assigned channel.\n _freeMusics: HowlerSound[] = []; // Musics without an assigned channel.\n\n /** Paused sounds or musics that should be played once the game is resumed. */\n _pausedSounds: HowlerSound[] = [];\n _paused: boolean = false;\n\n _resourceLoader: gdjs.ResourceLoader;\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 const that = this;\n document.addEventListener('deviceready', function () {\n // pause/resume sounds in Cordova when the app is being paused/resumed\n document.addEventListener(\n 'pause',\n function () {\n const soundList = that._freeSounds.concat(that._freeMusics);\n for (let key in that._sounds) {\n if (that._sounds.hasOwnProperty(key)) {\n soundList.push(that._sounds[key]);\n }\n }\n for (let key in that._musics) {\n if (that._musics.hasOwnProperty(key)) {\n soundList.push(that._musics[key]);\n }\n }\n for (let i = 0; i < soundList.length; i++) {\n const sound = soundList[i];\n if (!sound.paused() && !sound.stopped()) {\n sound.pause();\n that._pausedSounds.push(sound);\n }\n }\n that._paused = true;\n },\n false\n );\n document.addEventListener(\n 'resume',\n function () {\n try {\n for (let i = 0; i < that._pausedSounds.length; i++) {\n const sound = that._pausedSounds[i];\n if (!sound.stopped()) {\n sound.play();\n }\n }\n } catch (error) {\n if (\n error.message &&\n typeof error.message === 'string' &&\n error.message.startsWith('Maximum call stack size exceeded')\n ) {\n console.warn(\n 'An error occurred when resuming paused sounds while the game was in background:',\n error\n );\n } else {\n throw error;\n }\n }\n that._pausedSounds.length = 0;\n that._paused = false;\n },\n false\n );\n });\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Ensure rate is in a range valid for Howler.js\n * @return The clamped rate\n */\n static clampRate(rate: float): float {\n if (rate > 4.0) {\n return 4.0;\n }\n if (rate < 0.5) {\n return 0.5;\n }\n return rate;\n }\n\n /**\n * Return the file associated to the given sound name.\n *\n * Names and files are loaded from resources when preloadAudio is called. If no\n * file is associated to the given name, then the name will be considered as a\n * filename and will be returned.\n *\n * @return The associated resource\n */\n private _getAudioResource = (resourceName: string): ResourceData => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : ({\n file: resourceName,\n kind: 'audio',\n metadata: '',\n name: resourceName,\n } as ResourceData);\n };\n\n /**\n * Store the sound in the specified array, put it at the first index that\n * is free, or add it at the end if no element is free\n * (\"free\" means that the gdjs.HowlerSound can be destroyed).\n *\n * @param arr The array containing the sounds.\n * @param arr The gdjs.HowlerSound to add.\n * @return The gdjs.HowlerSound that have been added (i.e: the second parameter).\n */\n private _storeSoundInArray(\n arr: Array<HowlerSound>,\n sound: HowlerSound\n ): HowlerSound {\n // Try to recycle an old sound.\n for (let i = 0, len = arr.length; i < len; ++i) {\n if (!arr[i] || arr[i].stopped()) {\n arr[i] = sound;\n return sound;\n }\n }\n\n arr.push(sound);\n return sound;\n }\n\n /**\n * Creates a new gdjs.HowlerSound using preloaded/cached Howl instances.\n * @param soundName The name of the file or resource to play.\n * @param isMusic True if a music, false if a sound.\n * @param volume Between 0 and 1.\n * @param loop True if it should be played looping.\n * @param rate speed at which it is played.\n */\n createHowlerSound(\n soundName: string,\n isMusic: boolean,\n volume: float,\n loop: boolean,\n rate: float\n ): HowlerSound {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n let howl = cacheContainer.get(resource);\n if (!howl) {\n const fileName = resource ? resource.file : soundName;\n howl = new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(fileName)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n fileName\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n );\n cacheContainer.set(resource, howl);\n }\n\n return new gdjs.HowlerSound(howl, volume, loop, rate);\n }\n\n /**\n * Preloads a sound or a music in memory.\n * @param soundName The name of the file or resource to preload.\n * @param isMusic True if a music, false if a sound.\n */\n loadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n // Do not reload if it is already loaded.\n if (cacheContainer.get(resource)) {\n return;\n }\n\n cacheContainer.set(\n resource,\n new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(resource.file)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n )\n );\n }\n\n /**\n * Unloads a sound or a music from memory. This will stop any sound/music using it.\n * @param soundName The name of the file or resource to unload.\n * @param isMusic True if a music, false if a sound.\n */\n unloadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n const howl = cacheContainer.get(resource);\n if (!howl) {\n return;\n }\n\n // Make sure any sound using the howl is deleted so\n // that the howl can be garbage collected\n // and no weird \"zombies\" using the unloaded howl can exist.\n function clearContainer(howlerSoundContainer: HowlerSound[]) {\n for (let i in howlerSoundContainer) {\n if (\n howlerSoundContainer[i] &&\n //@ts-ignore We really need to access the raw howl here.\n howlerSoundContainer[i]._howl === howl\n ) {\n howlerSoundContainer[i].stop();\n delete howlerSoundContainer[i];\n }\n }\n }\n\n clearContainer(this._freeMusics);\n clearContainer(this._freeSounds);\n clearContainer(Object.values(this._musics));\n clearContainer(Object.values(this._sounds));\n clearContainer(this._pausedSounds);\n\n howl.unload();\n cacheContainer.delete(resource);\n }\n\n /**\n * Unloads all audio from memory.\n * This will clear the Howl cache.\n * This will also stop any running music or sounds.\n */\n unloadAll() {\n Howler.unload();\n\n // Clean up old sounds that still have the dead Howl instances.\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n this._loadedMusics.clear();\n this._loadedSounds.clear();\n }\n\n playSound(soundName: string, loop: boolean, volume: float, pitch: float) {\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeSounds, sound);\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n playSoundOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._sounds[channel]) this._sounds[channel].stop();\n\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._sounds[channel] = sound;\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n getSoundOnChannel(channel: integer): HowlerSound | null {\n return this._sounds[channel] || null;\n }\n\n playMusic(soundName: string, loop: boolean, volume: float, pitch: float) {\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeMusics, music);\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n playMusicOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._musics[channel]) this._musics[channel].stop();\n\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._musics[channel] = music;\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n getMusicOnChannel(channel: integer): HowlerSound | null {\n return this._musics[channel] || null;\n }\n\n setGlobalVolume(volume: float): void {\n this._globalVolume = volume;\n if (this._globalVolume > 100) {\n this._globalVolume = 100;\n }\n if (this._globalVolume < 0) {\n this._globalVolume = 0;\n }\n Howler.volume(this._globalVolume / 100);\n }\n\n getGlobalVolume(): float {\n return this._globalVolume;\n }\n\n clearAll() {\n Howler.stop();\n\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because sounds are light enough to be parsed in background.\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 audio for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (resource.file) {\n if (this._availableResources[resource.name]) {\n return;\n }\n\n this._availableResources[resource.name] = resource;\n }\n\n const preloadAudioFile = (\n file: string,\n isMusic: boolean\n ): Promise<number> => {\n return new Promise((resolve, reject) => {\n const container = isMusic ? this._loadedMusics : this._loadedSounds;\n container[file] = new Howl(\n Object.assign({}, HowlParameters, {\n src: [this._resourceLoader.getFullUrl(file)],\n onload: resolve,\n onloaderror: (soundId: number, error?: string) => reject(error),\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n })\n );\n });\n };\n\n const file = resource.file;\n if (resource.preloadAsMusic) {\n try {\n await preloadAudioFile(file, /* isMusic= */ true);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n\n if (resource.preloadAsSound) {\n try {\n await preloadAudioFile(file, /* isMusic= */ false);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n } else if (\n resource.preloadInCache ||\n // Force downloading of sounds.\n // TODO Decide if sounds should be allowed to be downloaded after the scene starts.\n // - they should be requested automatically at the end of the scene loading\n // - they will be downloaded while the scene is playing\n // - other scenes will be pre-loaded only when all the sounds for the current scene are in cache\n !resource.preloadAsMusic\n ) {\n // preloading as sound already does a XHR request, hence \"else if\"\n try {\n await new Promise((resolve, reject) => {\n const sound = new XMLHttpRequest();\n sound.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n file\n );\n sound.addEventListener('load', resolve);\n sound.addEventListener('error', (_) =>\n reject('XHR error: ' + file)\n );\n sound.addEventListener('abort', (_) =>\n reject('XHR abort: ' + file)\n );\n sound.open('GET', this._resourceLoader.getFullUrl(file));\n sound.send();\n });\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n }\n\n /**\n * To be called when the game is disposed.\n * Unloads all audio from memory, clear Howl cache and stop all audio.\n */\n dispose(): void {\n this.unloadAll();\n }\n }\n\n // Register the class to let the engine use it.\n export const SoundManager = HowlerSoundManager;\n export type SoundManager = HowlerSoundManager;\n}\n"],
5
+ "mappings": "AAMA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,iBAEzB,EAAqC,CAAC,SAEtC,EAA8B,CAClC,QAAS,GACT,YAAa,CA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ACpC,OAGF,KAAK,oBAAoB,EAAS,MAAQ,EAG5C,KAAM,GAAmB,CACvB,EACA,IAEO,GAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,KAAM,GAAY,EAAU,KAAK,cAAgB,KAAK,cACtD,EAAU,GAAQ,GAAI,MACpB,OAAO,OAAO,GAAI,EAAgB,CAChC,IAAK,CAAC,KAAK,gBAAgB,WAAW,IACtC,OAAQ,EACR,YAAa,CAAC,EAAiB,IAAmB,EAAO,GACzD,MAAO,EACP,IAAK,CACH,gBAAiB,KAAK,gBAAgB,2BACpC,IAKJ,OAAQ,OAMV,EAAO,EAAS,KACtB,GAAI,EAAS,eACX,GAAI,CACF,KAAM,GAAiB,EAAqB,UACrC,EAAP,CACA,EAAO,KACL,sDAAwD,GAK9D,GAAI,EAAS,eACX,GAAI,CACF,KAAM,GAAiB,EAAqB,UACrC,EAAP,CACA,EAAO,KACL,sDAAwD,WAI5D,EAAS,gBAMT,CAAC,EAAS,eAGV,GAAI,CACF,KAAM,IAAI,SAAQ,CAAC,EAAS,IAAW,CACrC,KAAM,GAAQ,GAAI,gBAClB,EAAM,gBAAkB,KAAK,gBAAgB,2BAC3C,GAEF,EAAM,iBAAiB,OAAQ,GAC/B,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,KAAK,MAAO,KAAK,gBAAgB,WAAW,IAClD,EAAM,eAED,EAAP,CACA,EAAO,KACL,sDAAwD,IAUhE,SAAgB,CACd,KAAK,aA7fF,EAAM,qBAkgBA,eAAe,IA32BpB",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(c){const l=new c.Logger("JSON Manager"),u=["json","tilemap","tileset"];class i{constructor(r){this._loadedJsons=new c.ResourceCache;this._callbacks=new c.ResourceCache;this._getJsonResource=r=>{const s=this._resourceLoader.getResource(r);return s&&this.getResourceKinds().includes(s.kind)?s:null};this._resourceLoader=r}getResourceKinds(){return u}async loadResource(r){const s=this._resourceLoader.getResource(r);if(!s){l.warn('Unable to find json for resource "'+r+'".');return}if(!s.disablePreload)try{await this.loadJsonAsync(s.name)}catch(e){l.error(`Error while preloading json resource ${s.name}:`,e)}}loadJsonAsync(r){const s=this;return new Promise((e,t)=>{s.loadJson(r,(o,n)=>{o&&t(o.message),e(n)})})}async processResource(r){}loadJson(r,s){const e=this._getJsonResource(r);if(!e){s(new Error(`Can't find resource with name: "`+r+'" (or is not a json resource).'),null);return}if(this._loadedJsons.get(e)){s(null,this._loadedJsons.get(e));return}{const n=this._callbacks.get(e);if(n){n.push(s);return}else this._callbacks.set(e,[s])}const t=this,o=new XMLHttpRequest;o.responseType="json",o.withCredentials=this._resourceLoader.checkIfCredentialsRequired(e.file),o.open("GET",this._resourceLoader.getFullUrl(e.file)),o.onload=function(){const n=t._callbacks.get(e);if(!!n){if(o.status!==200){for(const a of n)a(new Error("HTTP error: "+o.status+"("+o.statusText+")"),null);t._callbacks.delete(e);return}t._loadedJsons.set(e,o.response);for(const a of n)a(null,o.response);t._callbacks.delete(e)}},o.onerror=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Network error"),null);t._callbacks.delete(e)}},o.onabort=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Request aborted"),null);t._callbacks.delete(e)}},o.send()}isJsonLoaded(r){return!!this._loadedJsons.getFromName(r)}getLoadedJson(r){return this._loadedJsons.getFromName(r)||null}}c.JsonManager=i})(gdjs||(gdjs={}));
1
+ var gdjs;(function(c){const l=new c.Logger("JSON Manager"),i=["json","tilemap","tileset"];class u{constructor(s){this._loadedJsons=new c.ResourceCache;this._callbacks=new c.ResourceCache;this._getJsonResource=s=>{const r=this._resourceLoader.getResource(s);return r&&this.getResourceKinds().includes(r.kind)?r:null};this._resourceLoader=s}getResourceKinds(){return i}async loadResource(s){const r=this._resourceLoader.getResource(s);if(!r){l.warn('Unable to find json for resource "'+s+'".');return}if(!r.disablePreload)try{await this.loadJsonAsync(r.name)}catch(e){l.error(`Error while preloading json resource ${r.name}:`,e)}}loadJsonAsync(s){const r=this;return new Promise((e,t)=>{r.loadJson(s,(o,n)=>{o&&t(o.message),e(n)})})}async processResource(s){}loadJson(s,r){const e=this._getJsonResource(s);if(!e){r(new Error(`Can't find resource with name: "`+s+'" (or is not a json resource).'),null);return}if(this._loadedJsons.get(e)){r(null,this._loadedJsons.get(e));return}{const n=this._callbacks.get(e);if(n){n.push(r);return}else this._callbacks.set(e,[r])}const t=this,o=new XMLHttpRequest;o.responseType="json",o.withCredentials=this._resourceLoader.checkIfCredentialsRequired(e.file),o.open("GET",this._resourceLoader.getFullUrl(e.file)),o.onload=function(){const n=t._callbacks.get(e);if(!!n){if(o.status!==200){for(const a of n)a(new Error("HTTP error: "+o.status+"("+o.statusText+")"),null);t._callbacks.delete(e);return}t._loadedJsons.set(e,o.response);for(const a of n)a(null,o.response);t._callbacks.delete(e)}},o.onerror=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Network error"),null);t._callbacks.delete(e)}},o.onabort=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Request aborted"),null);t._callbacks.delete(e)}},o.send()}isJsonLoaded(s){return!!this._loadedJsons.getFromName(s)}getLoadedJson(s){return this._loadedJsons.getFromName(s)||null}dispose(){this._loadedJsons.clear(),this._callbacks.clear()}}c.JsonManager=u})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=jsonmanager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../GDevelop/GDJS/Runtime/jsonmanager.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('JSON Manager');\n\n /** The callback called when a json that was requested is loaded (or an error occurred). */\n export type JsonManagerRequestCallback = (\n error: Error | null,\n content: Object | null\n ) => void;\n\n const resourceKinds: Array<ResourceKind> = ['json', 'tilemap', 'tileset'];\n /**\n * JsonManager loads json files (using `XMLHttpRequest`), using the \"json\" resources\n * registered in the game resources.\n *\n * Contrary to audio/fonts, json 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 JsonManager implements gdjs.ResourceManager {\n _resourceLoader: ResourceLoader;\n\n _loadedJsons = new gdjs.ResourceCache<Object>();\n _callbacks = new gdjs.ResourceCache<Array<JsonManagerRequestCallback>>();\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\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Request all the json resources to be preloaded (unless they are marked as not preloaded).\n *\n * Note that even if a JSON is already loaded, it will be reloaded (useful for hot-reloading,\n * as JSON files can have been modified without the editor knowing).\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find json for resource \"' + resourceName + '\".');\n return;\n }\n if (resource.disablePreload) {\n return;\n }\n\n try {\n await this.loadJsonAsync(resource.name);\n } catch (error) {\n logger.error(\n `Error while preloading json resource ${resource.name}:`,\n error\n );\n }\n }\n\n loadJsonAsync(resourceName: string): Promise<Object | null> {\n const that = this;\n return new Promise((resolve, reject) => {\n that.loadJson(resourceName, (error, content) => {\n if (error) {\n reject(error.message);\n }\n resolve(content);\n });\n });\n }\n\n private _getJsonResource = (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 async processResource(resourceName: string): Promise<void> {\n // Do nothing because json are light enough to be parsed in background.\n }\n\n /**\n * Request the json file from the given resource name.\n * This method is asynchronous. When loaded, the `callback` is called with the error\n * (null if none) and the loaded json (a JS Object).\n *\n * @param resourceName The resource pointing to the json file to load.\n * @param callback The callback function called when json is loaded (or an error occurred).\n */\n loadJson(resourceName: string, callback: JsonManagerRequestCallback): void {\n const resource = this._getJsonResource(resourceName);\n if (!resource) {\n callback(\n new Error(\n 'Can\\'t find resource with name: \"' +\n resourceName +\n '\" (or is not a json resource).'\n ),\n null\n );\n return;\n }\n\n // Don't fetch again an object that is already in memory\n if (this._loadedJsons.get(resource)) {\n callback(null, this._loadedJsons.get(resource));\n return;\n }\n // Don't fetch again an object that is already being fetched.\n {\n const callbacks = this._callbacks.get(resource);\n if (callbacks) {\n callbacks.push(callback);\n return;\n } else {\n this._callbacks.set(resource, [callback]);\n }\n }\n\n const that = this;\n const xhr = new XMLHttpRequest();\n xhr.responseType = 'json';\n xhr.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n );\n xhr.open('GET', this._resourceLoader.getFullUrl(resource.file));\n xhr.onload = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n if (xhr.status !== 200) {\n for (const callback of callbacks) {\n callback(\n new Error(\n 'HTTP error: ' + xhr.status + '(' + xhr.statusText + ')'\n ),\n null\n );\n }\n that._callbacks.delete(resource);\n return;\n }\n\n // Cache the result\n that._loadedJsons.set(resource, xhr.response);\n for (const callback of callbacks) {\n callback(null, xhr.response);\n }\n that._callbacks.delete(resource);\n };\n xhr.onerror = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Network error'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.onabort = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Request aborted'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.send();\n }\n\n /**\n * Check if the given json resource was loaded (preloaded or loaded with `loadJson`).\n * @param resourceName The name of the json resource.\n * @returns true if the content of the json resource is loaded. false otherwise.\n */\n isJsonLoaded(resourceName: string): boolean {\n return !!this._loadedJsons.getFromName(resourceName);\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 json resource.\n * @returns the content of the json resource, if loaded. `null` otherwise.\n */\n getLoadedJson(resourceName: string): Object | null {\n return this._loadedJsons.getFromName(resourceName) || null;\n }\n }\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,gBAQzB,EAAqC,CAAC,OAAQ,UAAW,WASxD,OAAkD,CAUvD,YAAY,EAAqC,CAPjD,kBAAe,GAAI,GAAK,cACxB,gBAAa,GAAI,GAAK,cAoDd,sBAAmB,AAAC,GAA8C,CACxE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,MAjDJ,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,QASH,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KAAK,qCAAuC,EAAe,MAClE,OAEF,GAAI,GAAS,eAIb,GAAI,CACF,KAAM,MAAK,cAAc,EAAS,YAC3B,EAAP,CACA,EAAO,MACL,wCAAwC,EAAS,QACjD,IAKN,cAAc,EAA8C,CAC1D,KAAM,GAAO,KACb,MAAO,IAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,EAAK,SAAS,EAAc,CAAC,EAAO,IAAY,CAC9C,AAAI,GACF,EAAO,EAAM,SAEf,EAAQ,YAYR,iBAAgB,EAAqC,EAY3D,SAAS,EAAsB,EAA4C,CACzE,KAAM,GAAW,KAAK,iBAAiB,GACvC,GAAI,CAAC,EAAU,CACb,EACE,GAAI,OACF,mCACE,EACA,kCAEJ,MAEF,OAIF,GAAI,KAAK,aAAa,IAAI,GAAW,CACnC,EAAS,KAAM,KAAK,aAAa,IAAI,IACrC,OAGF,CACE,KAAM,GAAY,KAAK,WAAW,IAAI,GACtC,GAAI,EAAW,CACb,EAAU,KAAK,GACf,WAEA,MAAK,WAAW,IAAI,EAAU,CAAC,IAInC,KAAM,GAAO,KACP,EAAM,GAAI,gBAChB,EAAI,aAAe,OACnB,EAAI,gBAAkB,KAAK,gBAAgB,2BACzC,EAAS,MAEX,EAAI,KAAK,MAAO,KAAK,gBAAgB,WAAW,EAAS,OACzD,EAAI,OAAS,UAAY,CACvB,KAAM,GAAY,EAAK,WAAW,IAAI,GACtC,GAAI,EAAC,EAGL,IAAI,EAAI,SAAW,IAAK,CACtB,SAAW,KAAY,GACrB,EACE,GAAI,OACF,eAAiB,EAAI,OAAS,IAAM,EAAI,WAAa,KAEvD,MAGJ,EAAK,WAAW,OAAO,GACvB,OAIF,EAAK,aAAa,IAAI,EAAU,EAAI,UACpC,SAAW,KAAY,GACrB,EAAS,KAAM,EAAI,UAErB,EAAK,WAAW,OAAO,KAEzB,EAAI,QAAU,UAAY,CACxB,KAAM,GAAY,EAAK,WAAW,IAAI,GACtC,GAAI,EAAC,EAGL,UAAW,KAAY,GACrB,EAAS,GAAI,OAAM,iBAAkB,MAEvC,EAAK,WAAW,OAAO,KAEzB,EAAI,QAAU,UAAY,CACxB,KAAM,GAAY,EAAK,WAAW,IAAI,GACtC,GAAI,EAAC,EAGL,UAAW,KAAY,GACrB,EAAS,GAAI,OAAM,mBAAoB,MAEzC,EAAK,WAAW,OAAO,KAEzB,EAAI,OAQN,aAAa,EAA+B,CAC1C,MAAO,CAAC,CAAC,KAAK,aAAa,YAAY,GAUzC,cAAc,EAAqC,CACjD,MAAO,MAAK,aAAa,YAAY,IAAiB,MAjLnD,EAAM,gBAlBL",
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('JSON Manager');\n\n /** The callback called when a json that was requested is loaded (or an error occurred). */\n export type JsonManagerRequestCallback = (\n error: Error | null,\n content: Object | null\n ) => void;\n\n const resourceKinds: Array<ResourceKind> = ['json', 'tilemap', 'tileset'];\n /**\n * JsonManager loads json files (using `XMLHttpRequest`), using the \"json\" resources\n * registered in the game resources.\n *\n * Contrary to audio/fonts, json 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 JsonManager implements gdjs.ResourceManager {\n _resourceLoader: ResourceLoader;\n\n _loadedJsons = new gdjs.ResourceCache<Object>();\n _callbacks = new gdjs.ResourceCache<Array<JsonManagerRequestCallback>>();\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\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Request all the json resources to be preloaded (unless they are marked as not preloaded).\n *\n * Note that even if a JSON is already loaded, it will be reloaded (useful for hot-reloading,\n * as JSON files can have been modified without the editor knowing).\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find json for resource \"' + resourceName + '\".');\n return;\n }\n if (resource.disablePreload) {\n return;\n }\n\n try {\n await this.loadJsonAsync(resource.name);\n } catch (error) {\n logger.error(\n `Error while preloading json resource ${resource.name}:`,\n error\n );\n }\n }\n\n loadJsonAsync(resourceName: string): Promise<Object | null> {\n const that = this;\n return new Promise((resolve, reject) => {\n that.loadJson(resourceName, (error, content) => {\n if (error) {\n reject(error.message);\n }\n resolve(content);\n });\n });\n }\n\n private _getJsonResource = (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 async processResource(resourceName: string): Promise<void> {\n // Do nothing because json are light enough to be parsed in background.\n }\n\n /**\n * Request the json file from the given resource name.\n * This method is asynchronous. When loaded, the `callback` is called with the error\n * (null if none) and the loaded json (a JS Object).\n *\n * @param resourceName The resource pointing to the json file to load.\n * @param callback The callback function called when json is loaded (or an error occurred).\n */\n loadJson(resourceName: string, callback: JsonManagerRequestCallback): void {\n const resource = this._getJsonResource(resourceName);\n if (!resource) {\n callback(\n new Error(\n 'Can\\'t find resource with name: \"' +\n resourceName +\n '\" (or is not a json resource).'\n ),\n null\n );\n return;\n }\n\n // Don't fetch again an object that is already in memory\n if (this._loadedJsons.get(resource)) {\n callback(null, this._loadedJsons.get(resource));\n return;\n }\n // Don't fetch again an object that is already being fetched.\n {\n const callbacks = this._callbacks.get(resource);\n if (callbacks) {\n callbacks.push(callback);\n return;\n } else {\n this._callbacks.set(resource, [callback]);\n }\n }\n\n const that = this;\n const xhr = new XMLHttpRequest();\n xhr.responseType = 'json';\n xhr.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n );\n xhr.open('GET', this._resourceLoader.getFullUrl(resource.file));\n xhr.onload = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n if (xhr.status !== 200) {\n for (const callback of callbacks) {\n callback(\n new Error(\n 'HTTP error: ' + xhr.status + '(' + xhr.statusText + ')'\n ),\n null\n );\n }\n that._callbacks.delete(resource);\n return;\n }\n\n // Cache the result\n that._loadedJsons.set(resource, xhr.response);\n for (const callback of callbacks) {\n callback(null, xhr.response);\n }\n that._callbacks.delete(resource);\n };\n xhr.onerror = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Network error'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.onabort = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Request aborted'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.send();\n }\n\n /**\n * Check if the given json resource was loaded (preloaded or loaded with `loadJson`).\n * @param resourceName The name of the json resource.\n * @returns true if the content of the json resource is loaded. false otherwise.\n */\n isJsonLoaded(resourceName: string): boolean {\n return !!this._loadedJsons.getFromName(resourceName);\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 json resource.\n * @returns the content of the json resource, if loaded. `null` otherwise.\n */\n getLoadedJson(resourceName: string): Object | null {\n return this._loadedJsons.getFromName(resourceName) || null;\n }\n\n /**\n * To be called when the game is disposed.\n * Clear the JSONs loaded in this manager.\n */\n dispose(): void {\n this._loadedJsons.clear();\n this._callbacks.clear();\n }\n }\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,gBAQzB,EAAqC,CAAC,OAAQ,UAAW,WASxD,OAAkD,CAUvD,YAAY,EAAqC,CAPjD,kBAAe,GAAI,GAAK,cACxB,gBAAa,GAAI,GAAK,cAoDd,sBAAmB,AAAC,GAA8C,CACxE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,MAjDJ,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,QASH,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KAAK,qCAAuC,EAAe,MAClE,OAEF,GAAI,GAAS,eAIb,GAAI,CACF,KAAM,MAAK,cAAc,EAAS,YAC3B,EAAP,CACA,EAAO,MACL,wCAAwC,EAAS,QACjD,IAKN,cAAc,EAA8C,CAC1D,KAAM,GAAO,KACb,MAAO,IAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,EAAK,SAAS,EAAc,CAAC,EAAO,IAAY,CAC9C,AAAI,GACF,EAAO,EAAM,SAEf,EAAQ,YAYR,iBAAgB,EAAqC,EAY3D,SAAS,EAAsB,EAA4C,CACzE,KAA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AK,aAAa,QAClB,KAAK,WAAW,SA1Lb,EAAM,gBAlBL",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(m){class c extends m.RuntimeLayer{constructor(t,e){super(t,e);this._cameraRotation=0;this._zoomFactor=1;this._cameraZ=0;this._isCameraZDirty=!0;this._cameraX=this.getWidth()/2,this._cameraY=this.getHeight()/2,this.getCameraType()===m.RuntimeLayerCameraType.ORTHOGRAPHIC&&(this._cameraZ=(this._initialCamera3DFarPlaneDistance+this._initialCamera3DNearPlaneDistance)/2),this._renderer.onCreated()}onGameResolutionResized(t,e){this._cameraX===t&&this._cameraY===e&&this._zoomFactor===1&&(this._cameraX+=this._runtimeScene.getViewportOriginX()-t,this._cameraY+=this._runtimeScene.getViewportOriginY()-e),this._renderer.updatePosition(),this._renderer.updateResolution()}getCameraX(t){return this._forceDimensionUpdate(),this._cameraX}getCameraY(t){return this._forceDimensionUpdate(),this._cameraY}setCameraX(t,e){this._forceDimensionUpdate(),this._cameraX=t,this._renderer.updatePosition()}setCameraY(t,e){this._forceDimensionUpdate(),this._cameraY=t,this._renderer.updatePosition()}getCameraWidth(t){return this.getWidth()/this._zoomFactor}getCameraHeight(t){return this.getHeight()/this._zoomFactor}setCameraZoom(t,e){this._zoomFactor=t,this._isCameraZDirty=!0,this._renderer.updatePosition()}getCameraZoom(t){return this._zoomFactor}setCameraZ(t,e,i){if(e){const o=m.toRad(e),a=Math.min(Number.MAX_SAFE_INTEGER,.5*this.getHeight()/(t*Math.tan(.5*o)));a>0&&(this._zoomFactor=a)}this._cameraZ=t,this._isCameraZDirty=!1,this._renderer.updatePosition()}getCameraZ(t,e){return!this._isCameraZDirty||!t?this._cameraZ:.5*this.getHeight()/this.getCameraZoom()/Math.tan(.5*m.toRad(t))}getCameraRotation(t){return this._cameraRotation}setCameraRotation(t,e){this._cameraRotation=t,this._renderer.updatePosition()}convertCoords(t,e,i=0,o){let a=o||[0,0];if(this._renderer.isCameraRotatedIn3D())return this._renderer.transformTo3DWorld(t,e,0,i,o);t-=this.getRuntimeScene()._cachedGameResolutionWidth/2,e-=this.getRuntimeScene()._cachedGameResolutionHeight/2,t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const n=this._cameraRotation/180*Math.PI,s=t,r=Math.cos(n),h=Math.sin(n);return t=r*t-h*e,e=h*s+r*e,a[0]=t+this.getCameraX(i),a[1]=e+this.getCameraY(i),a}applyLayerInverseTransformation(t,e,i,o){t-=this._runtimeScene.getViewportOriginX(),e-=this._runtimeScene.getViewportOriginY(),t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(a),r=Math.sin(a);return t=s*t-r*e,e=r*n+s*e,o[0]=t+this.getCameraX(i),o[1]=e+this.getCameraY(i),o}convertInverseCoords(t,e,i=0,o){let a=o||[0,0];t-=this.getCameraX(i),e-=this.getCameraY(i);const n=this._cameraRotation/180*Math.PI,s=t,r=Math.cos(-n),h=Math.sin(-n);return t=r*t-h*e,e=h*s+r*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),a[0]=t+this.getRuntimeScene()._cachedGameResolutionWidth/2,a[1]=e+this.getRuntimeScene()._cachedGameResolutionHeight/2,a}applyLayerTransformation(t,e,i,o){t-=this.getCameraX(i),e-=this.getCameraY(i);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(-a),r=Math.sin(-a);return t=s*t-r*e,e=r*n+s*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),t+=this._runtimeScene.getViewportOriginX(),e+=this._runtimeScene.getViewportOriginY(),o[0]=t,o[1]=e,o}_forceDimensionUpdate(){this._runtimeScene.getViewportWidth()}}m.Layer=c})(gdjs||(gdjs={}));
1
+ var gdjs;(function(m){class c extends m.RuntimeLayer{constructor(t,e){super(t,e);this._cameraRotation=0;this._zoomFactor=1;this._cameraZ=0;this._isCameraZDirty=!0;this._cameraX=this.getWidth()/2,this._cameraY=this.getHeight()/2,this.getCameraType()===m.RuntimeLayerCameraType.ORTHOGRAPHIC&&(this._cameraZ=(this._initialCamera3DFarPlaneDistance+this._initialCamera3DNearPlaneDistance)/2),this._renderer.onCreated()}onGameResolutionResized(t,e){Math.abs(this._cameraX-t)<1&&Math.abs(this._cameraY-e)<1&&this._zoomFactor===1&&(this._cameraX+=this._runtimeScene.getViewportOriginX()-t,this._cameraY+=this._runtimeScene.getViewportOriginY()-e),this._renderer.updatePosition(),this._renderer.updateResolution()}getCameraX(t){return this._forceDimensionUpdate(),this._cameraX}getCameraY(t){return this._forceDimensionUpdate(),this._cameraY}setCameraX(t,e){this._forceDimensionUpdate(),this._cameraX=t,this._renderer.updatePosition()}setCameraY(t,e){this._forceDimensionUpdate(),this._cameraY=t,this._renderer.updatePosition()}getCameraWidth(t){return this.getWidth()/this._zoomFactor}getCameraHeight(t){return this.getHeight()/this._zoomFactor}setCameraZoom(t,e){this._zoomFactor=t,this._isCameraZDirty=!0,this._renderer.updatePosition()}getCameraZoom(t){return this._zoomFactor}setCameraZ(t,e,i){if(e){const o=m.toRad(e),a=Math.min(Number.MAX_SAFE_INTEGER,.5*this.getHeight()/(t*Math.tan(.5*o)));a>0&&(this._zoomFactor=a)}this._cameraZ=t,this._isCameraZDirty=!1,this._renderer.updatePosition()}getCameraZ(t,e){return!this._isCameraZDirty||!t?this._cameraZ:.5*this.getHeight()/this.getCameraZoom()/Math.tan(.5*m.toRad(t))}getCameraRotation(t){return this._cameraRotation}setCameraRotation(t,e){this._cameraRotation=t,this._renderer.updatePosition()}convertCoords(t,e,i=0,o){let a=o||[0,0];if(this._renderer.isCameraRotatedIn3D())return this._renderer.transformTo3DWorld(t,e,0,i,o);t-=this.getRuntimeScene()._cachedGameResolutionWidth/2,e-=this.getRuntimeScene()._cachedGameResolutionHeight/2,t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const n=this._cameraRotation/180*Math.PI,s=t,r=Math.cos(n),h=Math.sin(n);return t=r*t-h*e,e=h*s+r*e,a[0]=t+this.getCameraX(i),a[1]=e+this.getCameraY(i),a}applyLayerInverseTransformation(t,e,i,o){t-=this._runtimeScene.getViewportOriginX(),e-=this._runtimeScene.getViewportOriginY(),t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(a),r=Math.sin(a);return t=s*t-r*e,e=r*n+s*e,o[0]=t+this.getCameraX(i),o[1]=e+this.getCameraY(i),o}convertInverseCoords(t,e,i=0,o){let a=o||[0,0];t-=this.getCameraX(i),e-=this.getCameraY(i);const n=this._cameraRotation/180*Math.PI,s=t,r=Math.cos(-n),h=Math.sin(-n);return t=r*t-h*e,e=h*s+r*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),a[0]=t+this.getRuntimeScene()._cachedGameResolutionWidth/2,a[1]=e+this.getRuntimeScene()._cachedGameResolutionHeight/2,a}applyLayerTransformation(t,e,i,o){t-=this.getCameraX(i),e-=this.getCameraY(i);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(-a),r=Math.sin(-a);return t=s*t-r*e,e=r*n+s*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),t+=this._runtimeScene.getViewportOriginX(),e+=this._runtimeScene.getViewportOriginY(),o[0]=t,o[1]=e,o}_forceDimensionUpdate(){this._runtimeScene.getViewportWidth()}}m.Layer=c})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=layer.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../GDevelop/GDJS/Runtime/layer.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 /**\n * Represents a layer of a scene, used to display objects.\n */\n export class Layer extends gdjs.RuntimeLayer {\n _cameraRotation: float = 0;\n _zoomFactor: float = 1;\n _cameraX: float;\n _cameraY: float;\n _cameraZ: float = 0;\n /**\n * `_cameraZ` is dirty when the zoom factor is set last.\n */\n _isCameraZDirty: boolean = true;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n super(layerData, instanceContainer);\n\n this._cameraX = this.getWidth() / 2;\n this._cameraY = this.getHeight() / 2;\n if (this.getCameraType() === gdjs.RuntimeLayerCameraType.ORTHOGRAPHIC) {\n this._cameraZ =\n (this._initialCamera3DFarPlaneDistance +\n this._initialCamera3DNearPlaneDistance) /\n 2;\n }\n\n // Let the renderer do its final set up:\n this._renderer.onCreated();\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void {\n // Adapt position of the camera center only if the camera has never moved as:\n // * When the camera follows a player/object, it will rarely be at the default position.\n // * Cameras not following a player/object are usually UIs which are intuitively\n // expected not to \"move\". Not adapting the center position would make the camera\n // move from its initial position (which is centered in the screen) - and anchor\n // behavior would behave counterintuitively.\n if (\n this._cameraX === oldGameResolutionOriginX &&\n this._cameraY === oldGameResolutionOriginY &&\n this._zoomFactor === 1\n ) {\n this._cameraX +=\n this._runtimeScene.getViewportOriginX() - oldGameResolutionOriginX;\n this._cameraY +=\n this._runtimeScene.getViewportOriginY() - oldGameResolutionOriginY;\n }\n this._renderer.updatePosition();\n this._renderer.updateResolution();\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n getCameraX(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraX;\n }\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n getCameraY(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraY;\n }\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraX(x: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraX = x;\n this._renderer.updatePosition();\n }\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraY(y: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraY = y;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n getCameraWidth(cameraId?: integer): float {\n return this.getWidth() / this._zoomFactor;\n }\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n getCameraHeight(cameraId?: integer): float {\n return this.getHeight() / this._zoomFactor;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZoom(newZoom: float, cameraId?: integer): void {\n this._zoomFactor = newZoom;\n this._isCameraZDirty = true;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n getCameraZoom(cameraId?: integer): float {\n return this._zoomFactor;\n }\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZ(z: float, fov: float | null, cameraId?: integer): void {\n if (fov) {\n const cameraFovInRadians = gdjs.toRad(fov);\n\n // The zoom factor is capped to a not too big value to avoid infinity.\n // MAX_SAFE_INTEGER is an arbitrary choice. It's big but not too big.\n const zoomFactor = Math.min(\n Number.MAX_SAFE_INTEGER,\n (0.5 * this.getHeight()) / (z * Math.tan(0.5 * cameraFovInRadians))\n );\n\n if (zoomFactor > 0) {\n this._zoomFactor = zoomFactor;\n }\n }\n\n this._cameraZ = z;\n this._isCameraZDirty = false;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n getCameraZ(fov: float | null, cameraId?: integer): float {\n if (!this._isCameraZDirty || !fov) {\n return this._cameraZ;\n }\n\n // Set the camera so that it displays the whole PixiJS plane, as if it was a 2D rendering.\n // The Z position is computed by taking the half height of the displayed rendering,\n // and using the angle of the triangle defined by the field of view to compute the length\n // of the triangle defining the distance between the camera and the rendering plane.\n const cameraZPosition =\n (0.5 * this.getHeight()) /\n this.getCameraZoom() /\n Math.tan(0.5 * gdjs.toRad(fov));\n\n return cameraZPosition;\n }\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n getCameraRotation(cameraId?: integer): float {\n return this._cameraRotation;\n }\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraRotation(rotation: float, cameraId?: integer): void {\n this._cameraRotation = rotation;\n this._renderer.updatePosition();\n }\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * This method handles 3D rotations.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerInverseTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n\n if (this._renderer.isCameraRotatedIn3D()) {\n return this._renderer.transformTo3DWorld(x, y, 0, cameraId, result);\n }\n\n x -= this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n y -= this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n position[0] = x + this.getCameraX(cameraId);\n position[1] = y + this.getCameraY(cameraId);\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this._runtimeScene.getViewportOriginX();\n y -= this._runtimeScene.getViewportOriginY();\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n result[0] = x + this.getCameraX(cameraId);\n result[1] = y + this.getCameraY(cameraId);\n\n return result;\n }\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n position[0] = x + this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n position[1] = y + this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n x += this._runtimeScene.getViewportOriginX();\n y += this._runtimeScene.getViewportOriginY();\n\n result[0] = x;\n result[1] = y;\n return result;\n }\n\n /**\n * This ensure that the viewport dimensions are up to date.\n *\n * It's needed because custom objects dimensions are only updated on\n * demand for efficiency reasons.\n */\n private _forceDimensionUpdate(): void {\n // This will update dimensions.\n this._runtimeScene.getViewportWidth();\n }\n }\n}\n"],
5
- "mappings": "A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AI,GAAW,GAAU,CAAC,EAAG,GAC7B,GAAK,KAAK,WAAW,GACrB,GAAK,KAAK,WAAW,GAGrB,KAAM,GAAkB,KAAK,gBAAkB,IAAO,KAAK,GACrD,EAAM,EACN,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,EAAS,GAAK,EAAI,KAAK,kBAAkB,2BAA6B,EACtE,EAAS,GAAK,EAAI,KAAK,kBAAkB,4BAA8B,EAChE,EAgBT,yBACE,EACA,EACA,EACA,EACY,CACZ,GAAK,KAAK,WAAW,GACrB,GAAK,KAAK,WAAW,GAGrB,KAAM,GAAkB,KAAK,gBAAkB,IAAO,KAAK,GACrD,EAAM,EACN,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,cAAc,qBACxB,GAAK,KAAK,cAAc,qBAExB,EAAO,GAAK,EACZ,EAAO,GAAK,EACL,EASD,uBAA8B,CAEpC,KAAK,cAAc,oBAxYhB,EAAM,UAJL",
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 /**\n * Represents a layer of a scene, used to display objects.\n */\n export class Layer extends gdjs.RuntimeLayer {\n _cameraRotation: float = 0;\n _zoomFactor: float = 1;\n _cameraX: float;\n _cameraY: float;\n _cameraZ: float = 0;\n /**\n * `_cameraZ` is dirty when the zoom factor is set last.\n */\n _isCameraZDirty: boolean = true;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n super(layerData, instanceContainer);\n\n this._cameraX = this.getWidth() / 2;\n this._cameraY = this.getHeight() / 2;\n if (this.getCameraType() === gdjs.RuntimeLayerCameraType.ORTHOGRAPHIC) {\n this._cameraZ =\n (this._initialCamera3DFarPlaneDistance +\n this._initialCamera3DNearPlaneDistance) /\n 2;\n }\n\n // Let the renderer do its final set up:\n this._renderer.onCreated();\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void {\n // Adapt position of the camera center only if the camera has never moved as:\n // * When the camera follows a player/object, it will rarely be at the default position.\n // (and if is, it will be moved again by the behavior/events).\n // * Cameras not following a player/object are usually UIs which are intuitively\n // expected not to \"move\". Not adapting the center position would make the camera\n // move from its initial position (which is centered on the screen) - and anchor\n // behavior would behave counterintuitively.\n if (\n // Have a safety margin of 1 pixel to avoid rounding errors.\n Math.abs(this._cameraX - oldGameResolutionOriginX) < 1 &&\n Math.abs(this._cameraY - oldGameResolutionOriginY) < 1 &&\n this._zoomFactor === 1\n ) {\n this._cameraX +=\n this._runtimeScene.getViewportOriginX() - oldGameResolutionOriginX;\n this._cameraY +=\n this._runtimeScene.getViewportOriginY() - oldGameResolutionOriginY;\n }\n\n this._renderer.updatePosition();\n this._renderer.updateResolution();\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n getCameraX(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraX;\n }\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n getCameraY(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraY;\n }\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraX(x: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraX = x;\n this._renderer.updatePosition();\n }\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraY(y: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraY = y;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n getCameraWidth(cameraId?: integer): float {\n return this.getWidth() / this._zoomFactor;\n }\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n getCameraHeight(cameraId?: integer): float {\n return this.getHeight() / this._zoomFactor;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZoom(newZoom: float, cameraId?: integer): void {\n this._zoomFactor = newZoom;\n this._isCameraZDirty = true;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n getCameraZoom(cameraId?: integer): float {\n return this._zoomFactor;\n }\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZ(z: float, fov: float | null, cameraId?: integer): void {\n if (fov) {\n const cameraFovInRadians = gdjs.toRad(fov);\n\n // The zoom factor is capped to a not too big value to avoid infinity.\n // MAX_SAFE_INTEGER is an arbitrary choice. It's big but not too big.\n const zoomFactor = Math.min(\n Number.MAX_SAFE_INTEGER,\n (0.5 * this.getHeight()) / (z * Math.tan(0.5 * cameraFovInRadians))\n );\n\n if (zoomFactor > 0) {\n this._zoomFactor = zoomFactor;\n }\n }\n\n this._cameraZ = z;\n this._isCameraZDirty = false;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n getCameraZ(fov: float | null, cameraId?: integer): float {\n if (!this._isCameraZDirty || !fov) {\n return this._cameraZ;\n }\n\n // Set the camera so that it displays the whole PixiJS plane, as if it was a 2D rendering.\n // The Z position is computed by taking the half height of the displayed rendering,\n // and using the angle of the triangle defined by the field of view to compute the length\n // of the triangle defining the distance between the camera and the rendering plane.\n const cameraZPosition =\n (0.5 * this.getHeight()) /\n this.getCameraZoom() /\n Math.tan(0.5 * gdjs.toRad(fov));\n\n return cameraZPosition;\n }\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n getCameraRotation(cameraId?: integer): float {\n return this._cameraRotation;\n }\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraRotation(rotation: float, cameraId?: integer): void {\n this._cameraRotation = rotation;\n this._renderer.updatePosition();\n }\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * This method handles 3D rotations.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerInverseTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n\n if (this._renderer.isCameraRotatedIn3D()) {\n return this._renderer.transformTo3DWorld(x, y, 0, cameraId, result);\n }\n\n x -= this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n y -= this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n position[0] = x + this.getCameraX(cameraId);\n position[1] = y + this.getCameraY(cameraId);\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this._runtimeScene.getViewportOriginX();\n y -= this._runtimeScene.getViewportOriginY();\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n result[0] = x + this.getCameraX(cameraId);\n result[1] = y + this.getCameraY(cameraId);\n\n return result;\n }\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n position[0] = x + this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n position[1] = y + this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n x += this._runtimeScene.getViewportOriginX();\n y += this._runtimeScene.getViewportOriginY();\n\n result[0] = x;\n result[1] = y;\n return result;\n }\n\n /**\n * This ensure that the viewport dimensions are up to date.\n *\n * It's needed because custom objects dimensions are only updated on\n * demand for efficiency reasons.\n */\n private _forceDimensionUpdate(): void {\n // This will update dimensions.\n this._runtimeScene.getViewportWidth();\n }\n }\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAIS,e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,GAAI,GAAW,GAAU,CAAC,EAAG,GAC7B,GAAK,KAAK,WAAW,GACrB,GAAK,KAAK,WAAW,GAGrB,KAAM,GAAkB,KAAK,gBAAkB,IAAO,KAAK,GACrD,EAAM,EACN,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,EAAS,GAAK,EAAI,KAAK,kBAAkB,2BAA6B,EACtE,EAAS,GAAK,EAAI,KAAK,kBAAkB,4BAA8B,EAChE,EAgBT,yBACE,EACA,EACA,EACA,EACY,CACZ,GAAK,KAAK,WAAW,GACrB,GAAK,KAAK,WAAW,GAGrB,KAAM,GAAkB,KAAK,gBAAkB,IAAO,KAAK,GACrD,EAAM,EACN,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,cAAc,qBACxB,GAAK,KAAK,cAAc,qBAExB,EAAO,GAAK,EACZ,EAAO,GAAK,EACL,EASD,uBAA8B,CAEpC,KAAK,cAAc,oBA3YhB,EAAM,UAJL",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(a){const n=new a.Logger("Bitmap text"),l="GDJS-DEFAULT-BITMAP-FONT",d=5,p=(o,t)=>{const e=o.font;return o.font=t,PIXI.BitmapFont.available[t]=o,delete PIXI.BitmapFont.available[e],PIXI.BitmapFont.available[t]},m=["bitmapFont"];class c{constructor(t,e){this._pixiBitmapFontsInUse={};this._pixiBitmapFontsToUninstall=[];this._loadedFontsData=new a.ResourceCache;this._defaultSlugFontName=null;this._imageManager=e,this._resourceLoader=t}getResourceKinds(){return m}getDefaultBitmapFont(){if(this._defaultSlugFontName!==null)return PIXI.BitmapFont.available[this._defaultSlugFontName];const t="Arial",e=new PIXI.TextStyle({fontFamily:t,fontSize:20,padding:5,align:"left",fill:"#ffffff",wordWrap:!0,lineHeight:20}),i=p(PIXI.BitmapFont.from(t,e,{chars:[[" ","~"]]}),l);return this._defaultSlugFontName=i.font,i}_markBitmapFontAsUsed(t){this._pixiBitmapFontsInUse[t]=this._pixiBitmapFontsInUse[t]||{objectsUsingTheFont:0},this._pixiBitmapFontsInUse[t].objectsUsingTheFont++;for(let e=0;e<this._pixiBitmapFontsToUninstall.length;)this._pixiBitmapFontsToUninstall[e]===t?this._pixiBitmapFontsToUninstall.splice(e,1):e++}releaseBitmapFont(t){if(t!==l){if(!this._pixiBitmapFontsInUse[t]){n.warn("BitmapFont with name "+t+" was tried to be released but was never marked as used.");return}if(this._pixiBitmapFontsInUse[t].objectsUsingTheFont--,this._pixiBitmapFontsInUse[t].objectsUsingTheFont===0&&(delete this._pixiBitmapFontsInUse[t],this._pixiBitmapFontsToUninstall.includes(t)||this._pixiBitmapFontsToUninstall.push(t),this._pixiBitmapFontsToUninstall.length>d)){const e=this._pixiBitmapFontsToUninstall.shift();PIXI.BitmapFont.uninstall(e),n.log("Bitmap Text",'Uninstalled BitmapFont "'+e+'" from memory.')}}}obtainBitmapFont(t,e){const i=t+"@"+e;if(PIXI.BitmapFont.available[i])return this._markBitmapFontAsUsed(i),PIXI.BitmapFont.available[i];const s=this._loadedFontsData.getFromName(t);if(!s)return n.warn('Could not find Bitmap Font for resource named "'+t+'". The default font will be used.'),this.getDefaultBitmapFont();const u=this._imageManager.getPIXITexture(e);try{const r=p(PIXI.BitmapFont.install(s,u),i);return this._markBitmapFontAsUsed(i),r}catch(r){return n.error('Could not load the Bitmap Font for resource named "'+t+'". The default font will be used. Error is: '+r),this.getDefaultBitmapFont()}}async processResource(t){}async loadResource(t){const e=this._resourceLoader.getResource(t);if(!e){n.warn('Unable to find bitmap font for resource "'+t+'".');return}if(!this._loadedFontsData.get(e))try{const s=await(await fetch(this._resourceLoader.getFullUrl(e.file),{credentials:this._resourceLoader.checkIfCredentialsRequired(e.file)?"include":"same-origin"})).text();this._loadedFontsData.set(e,s)}catch(i){n.error("Can't fetch the bitmap font file "+e.file+", error: "+i)}}}a.PixiBitmapFontManager=c,a.BitmapFontManager=a.PixiBitmapFontManager})(gdjs||(gdjs={}));
1
+ var gdjs;(function(a){const n=new a.Logger("Bitmap text"),l="GDJS-DEFAULT-BITMAP-FONT",m=5,p=(s,t)=>{const i=s.font;return s.font=t,PIXI.BitmapFont.available[t]=s,delete PIXI.BitmapFont.available[i],PIXI.BitmapFont.available[t]},d=["bitmapFont"];class u{constructor(t,i){this._pixiBitmapFontsInUse={};this._pixiBitmapFontsToUninstall=[];this._loadedFontsData=new a.ResourceCache;this._defaultSlugFontName=null;this._imageManager=i,this._resourceLoader=t}getResourceKinds(){return d}getDefaultBitmapFont(){if(this._defaultSlugFontName!==null)return PIXI.BitmapFont.available[this._defaultSlugFontName];const t="Arial",i=new PIXI.TextStyle({fontFamily:t,fontSize:20,padding:5,align:"left",fill:"#ffffff",wordWrap:!0,lineHeight:20}),e=p(PIXI.BitmapFont.from(t,i,{chars:[[" ","~"]]}),l);return this._defaultSlugFontName=e.font,e}_markBitmapFontAsUsed(t){this._pixiBitmapFontsInUse[t]=this._pixiBitmapFontsInUse[t]||{objectsUsingTheFont:0},this._pixiBitmapFontsInUse[t].objectsUsingTheFont++;for(let i=0;i<this._pixiBitmapFontsToUninstall.length;)this._pixiBitmapFontsToUninstall[i]===t?this._pixiBitmapFontsToUninstall.splice(i,1):i++}releaseBitmapFont(t){if(t!==l){if(!this._pixiBitmapFontsInUse[t]){n.warn("BitmapFont with name "+t+" was tried to be released but was never marked as used.");return}if(this._pixiBitmapFontsInUse[t].objectsUsingTheFont--,this._pixiBitmapFontsInUse[t].objectsUsingTheFont===0&&(delete this._pixiBitmapFontsInUse[t],this._pixiBitmapFontsToUninstall.includes(t)||this._pixiBitmapFontsToUninstall.push(t),this._pixiBitmapFontsToUninstall.length>m)){const i=this._pixiBitmapFontsToUninstall.shift();PIXI.BitmapFont.uninstall(i),n.log("Bitmap Text",'Uninstalled BitmapFont "'+i+'" from memory.')}}}obtainBitmapFont(t,i){const e=t+"@"+i;if(PIXI.BitmapFont.available[e])return this._markBitmapFontAsUsed(e),PIXI.BitmapFont.available[e];const o=this._loadedFontsData.getFromName(t);if(!o)return n.warn('Could not find Bitmap Font for resource named "'+t+'". The default font will be used.'),this.getDefaultBitmapFont();const c=this._imageManager.getPIXITexture(i);try{const r=p(PIXI.BitmapFont.install(o,c),e);return this._markBitmapFontAsUsed(e),r}catch(r){return n.error('Could not load the Bitmap Font for resource named "'+t+'". The default font will be used. Error is: '+r),this.getDefaultBitmapFont()}}async processResource(t){}async loadResource(t){const i=this._resourceLoader.getResource(t);if(!i){n.warn('Unable to find bitmap font for resource "'+t+'".');return}if(!this._loadedFontsData.get(i))try{const o=await(await fetch(this._resourceLoader.getFullUrl(i.file),{credentials:this._resourceLoader.checkIfCredentialsRequired(i.file)?"include":"same-origin"})).text();this._loadedFontsData.set(i,o)}catch(e){n.error("Can't fetch the bitmap font file "+i.file+", error: "+e)}}dispose(){for(const t in this._pixiBitmapFontsInUse)PIXI.BitmapFont.uninstall(t);for(const t of this._pixiBitmapFontsToUninstall)PIXI.BitmapFont.uninstall(t);this._pixiBitmapFontsInUse={},this._pixiBitmapFontsToUninstall.length=0,this._loadedFontsData.clear()}}a.PixiBitmapFontManager=u,a.BitmapFontManager=a.PixiBitmapFontManager})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=pixi-bitmapfont-manager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../GDevelop/GDJS/Runtime/pixi-renderers/pixi-bitmapfont-manager.ts"],
4
- "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2021-present Aur\u00E9lien Vivet (bouh.vivez@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Bitmap text');\n\n const defaultBitmapFontKey = 'GDJS-DEFAULT-BITMAP-FONT';\n\n // When a font is unused, we put it in a cache of unused fonts. It's unloaded\n // from memory only when the cache is full and the font is at the last position\n // in the cache.\n // Set this to 0 to unload from memory (\"uninstall\") as soon as a font is unused.\n const uninstallCacheSize = 5;\n\n /**\n * We patch the installed font to use a name that is unique for each font data and texture,\n * to avoid conflicts between different font files using the same font name (by default, the\n * font name used by Pixi is the one inside the font data, but this name is not necessarily unique.\n * For example, 2 resources can use the same font, or we can have multiple objects with the same\n * font data and different textures).\n */\n const patchInstalledBitmapFont = (\n bitmapFont: PIXI.BitmapFont,\n bitmapFontInstallKey: string\n ) => {\n const defaultName = bitmapFont.font;\n // @ts-ignore - we \"hack\" into Pixi to change the font name\n bitmapFont.font = bitmapFontInstallKey;\n PIXI.BitmapFont.available[bitmapFontInstallKey] = bitmapFont;\n delete PIXI.BitmapFont.available[defaultName];\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n };\n\n const resourceKinds: Array<ResourceKind> = ['bitmapFont'];\n\n /**\n * PixiBitmapFontManager loads fnt/xml files (using `fetch`), from the \"bitmapFont\" resources of the game.\n *\n * It installs the \"BitmapFont\" with PixiJS to be used with PIXI.BitmapText.\n */\n export class PixiBitmapFontManager implements gdjs.ResourceManager {\n private _imageManager: gdjs.PixiImageManager;\n\n /** Pixi.BitmapFont used, indexed by their BitmapFont name. */\n private _pixiBitmapFontsInUse: Record<\n string,\n { objectsUsingTheFont: number }\n > = {};\n\n /** Pixi.BitmapFont not used anymore, but not yet uninstalled, indexed by their BitmapFont name. */\n private _pixiBitmapFontsToUninstall: string[] = [];\n\n /** Loaded fonts data, indexed by resource name. */\n private _loadedFontsData = new gdjs.ResourceCache<any>();\n\n private _defaultSlugFontName: string | null = null;\n\n _resourceLoader: gdjs.ResourceLoader;\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n * @param imageManager The image manager to be used to get textures used by fonts.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n imageManager: gdjs.PixiImageManager\n ) {\n this._imageManager = imageManager;\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Get the instance of the default `Pixi.BitmapFont`, always available.\n */\n getDefaultBitmapFont() {\n if (this._defaultSlugFontName !== null) {\n return PIXI.BitmapFont.available[this._defaultSlugFontName];\n }\n\n // Default bitmap font style\n const fontFamily = 'Arial';\n const bitmapFontStyle = new PIXI.TextStyle({\n fontFamily: fontFamily,\n fontSize: 20,\n padding: 5,\n align: 'left',\n fill: '#ffffff',\n wordWrap: true,\n lineHeight: 20,\n });\n\n // Generate default bitmapFont, and replace the name of PIXI.BitmapFont by a unique name\n const defaultBitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.from(fontFamily, bitmapFontStyle, {\n // All the printable ASCII characters\n chars: [[' ', '~']],\n }),\n defaultBitmapFontKey\n );\n\n // Define the default name used for the default bitmap font.\n this._defaultSlugFontName = defaultBitmapFont.font;\n return defaultBitmapFont;\n }\n\n /**\n * Called to specify that the bitmap font with the specified key is used by an object\n * (i.e: this is reference counting).\n * `releaseBitmapFont` *must* be called to mark the font as not used anymore when the\n * object is destroyed or its font changed.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n private _markBitmapFontAsUsed(bitmapFontInstallKey: string): void {\n this._pixiBitmapFontsInUse[bitmapFontInstallKey] = this\n ._pixiBitmapFontsInUse[bitmapFontInstallKey] || {\n objectsUsingTheFont: 0,\n };\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont++;\n\n for (let i = 0; i < this._pixiBitmapFontsToUninstall.length; ) {\n if (this._pixiBitmapFontsToUninstall[i] === bitmapFontInstallKey) {\n // The font is in the cache of fonts to uninstall, because it was previously used and then marked as not used anymore.\n // Remove it from the cache to avoid the font getting uninstalled.\n this._pixiBitmapFontsToUninstall.splice(i, 1);\n } else {\n i++;\n }\n }\n }\n\n /**\n * When a font is not used by an object anymore (object destroyed or font changed),\n * call this function to decrease the internal count of objects using the font.\n *\n * When a font is not unused anymore, it goes in a temporary cache. The cache holds up to 10 fonts.\n * If the cache reaches its maximum capacity, the oldest font is uninstalled from memory.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n releaseBitmapFont(bitmapFontInstallKey: string) {\n if (bitmapFontInstallKey === defaultBitmapFontKey) {\n // Never uninstall the default font.\n return;\n }\n\n if (!this._pixiBitmapFontsInUse[bitmapFontInstallKey]) {\n logger.warn(\n 'BitmapFont with name ' +\n bitmapFontInstallKey +\n ' was tried to be released but was never marked as used.'\n );\n return;\n }\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont--;\n\n if (\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont ===\n 0\n ) {\n delete this._pixiBitmapFontsInUse[bitmapFontInstallKey];\n\n // Add the font name at the last position of the cache.\n if (!this._pixiBitmapFontsToUninstall.includes(bitmapFontInstallKey)) {\n this._pixiBitmapFontsToUninstall.push(bitmapFontInstallKey);\n }\n if (this._pixiBitmapFontsToUninstall.length > uninstallCacheSize) {\n // Remove the first font (i.e: the oldest one)\n const oldestUnloadedPixiBitmapFontName = this._pixiBitmapFontsToUninstall.shift() as string;\n\n PIXI.BitmapFont.uninstall(oldestUnloadedPixiBitmapFontName);\n logger.log(\n 'Bitmap Text',\n 'Uninstalled BitmapFont \"' +\n oldestUnloadedPixiBitmapFontName +\n '\" from memory.'\n );\n }\n }\n }\n\n /**\n * Given a bitmap font resource name and a texture atlas resource name, returns the PIXI.BitmapFont\n * for it.\n * The font is register and should be released with `releaseBitmapFont` - so that it can be removed\n * from memory when unused.\n */\n obtainBitmapFont(\n bitmapFontResourceName: string,\n textureAtlasResourceName: string\n ): PIXI.BitmapFont {\n const bitmapFontInstallKey =\n bitmapFontResourceName + '@' + textureAtlasResourceName;\n\n if (PIXI.BitmapFont.available[bitmapFontInstallKey]) {\n // Return the existing BitmapFont that is already in memory and already installed.\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n }\n\n // The Bitmap Font is not loaded, load it in memory.\n\n // First get the font data:\n const fontData = this._loadedFontsData.getFromName(\n bitmapFontResourceName\n );\n if (!fontData) {\n logger.warn(\n 'Could not find Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used.'\n );\n return this.getDefaultBitmapFont();\n }\n\n // Get the texture to be used in the font:\n const texture = this._imageManager.getPIXITexture(\n textureAtlasResourceName\n );\n\n try {\n // Create and install the Pixi.BitmapFont in memory:\n const bitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.install(fontData, texture),\n bitmapFontInstallKey\n );\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return bitmapFont;\n } catch (error) {\n logger.error(\n 'Could not load the Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used. Error is: ' +\n error\n );\n return this.getDefaultBitmapFont();\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 \"bitmapFont\" resources of the game, so that they are ready\n * to be used when `obtainBitmapFont` is called.\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 bitmap font for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (this._loadedFontsData.get(resource)) {\n return;\n }\n\n try {\n const response = await fetch(\n this._resourceLoader.getFullUrl(resource.file),\n {\n credentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\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 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n }\n );\n const fontData = await response.text();\n this._loadedFontsData.set(resource, fontData);\n } catch (error) {\n logger.error(\n \"Can't fetch the bitmap font file \" +\n resource.file +\n ', error: ' +\n error\n );\n }\n }\n }\n\n // Register the class to let the engine use it.\n export const BitmapFontManager = gdjs.PixiBitmapFontManager;\n export type BitmapFontManager = gdjs.PixiBitmapFontManager;\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,eAEzB,EAAuB,2BAMvB,EAAqB,EASrB,EAA2B,CAC/B,EACA,IACG,CACH,KAAM,GAAc,EAAW,KAE/B,SAAW,KAAO,EAClB,KAAK,WAAW,UAAU,GAAwB,EAClD,MAAO,MAAK,WAAW,UAAU,GAC1B,KAAK,WAAW,UAAU,IAG7B,EAAqC,CAAC,cAOrC,OAA4D,CAwBjE,YACE,EACA,EACA,CAvBM,2BAGJ,GAGI,iCAAwC,GAGxC,sBAAmB,GAAI,GAAK,cAE5B,0BAAsC,KAa5C,KAAK,cAAgB,EACrB,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,GAMT,sBAAuB,CACrB,GAAI,KAAK,uBAAyB,KAChC,MAAO,MAAK,WAAW,UAAU,KAAK,sBAIxC,KAAM,GAAa,QACb,EAAkB,GAAI,MAAK,UAAU,CACzC,WAAY,EACZ,SAAU,GACV,QAAS,EACT,MAAO,OACP,KAAM,UACN,SAAU,GACV,WAAY,KAIR,EAAoB,EACxB,KAAK,WAAW,KAAK,EAAY,EAAiB,CAEhD,MAAO,CAAC,CAAC,IAAK,QAEhB,GAIF,YAAK,qBAAuB,EAAkB,KACvC,EAWD,sBAAsB,EAAoC,CAChE,KAAK,sBAAsB,GAAwB,KAChD,sBAAsB,IAAyB,CAChD,oBAAqB,GAEvB,KAAK,sBAAsB,GAAsB,sBAEjD,OAAS,GAAI,EAAG,EAAI,KAAK,4BAA4B,QACnD,AAAI,KAAK,4BAA4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,CACA,EAAO,MACL,oCACE,EAAS,KACT,YACA,KArPH,EAAM,wBA4PA,oBAAoB,EAAK,wBAjS9B",
4
+ "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2021-present Aur\u00E9lien Vivet (bouh.vivez@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Bitmap text');\n\n const defaultBitmapFontKey = 'GDJS-DEFAULT-BITMAP-FONT';\n\n // When a font is unused, we put it in a cache of unused fonts. It's unloaded\n // from memory only when the cache is full and the font is at the last position\n // in the cache.\n // Set this to 0 to unload from memory (\"uninstall\") as soon as a font is unused.\n const uninstallCacheSize = 5;\n\n /**\n * We patch the installed font to use a name that is unique for each font data and texture,\n * to avoid conflicts between different font files using the same font name (by default, the\n * font name used by Pixi is the one inside the font data, but this name is not necessarily unique.\n * For example, 2 resources can use the same font, or we can have multiple objects with the same\n * font data and different textures).\n */\n const patchInstalledBitmapFont = (\n bitmapFont: PIXI.BitmapFont,\n bitmapFontInstallKey: string\n ) => {\n const defaultName = bitmapFont.font;\n // @ts-ignore - we \"hack\" into Pixi to change the font name\n bitmapFont.font = bitmapFontInstallKey;\n PIXI.BitmapFont.available[bitmapFontInstallKey] = bitmapFont;\n delete PIXI.BitmapFont.available[defaultName];\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n };\n\n const resourceKinds: Array<ResourceKind> = ['bitmapFont'];\n\n /**\n * PixiBitmapFontManager loads fnt/xml files (using `fetch`), from the \"bitmapFont\" resources of the game.\n *\n * It installs the \"BitmapFont\" with PixiJS to be used with PIXI.BitmapText.\n */\n export class PixiBitmapFontManager implements gdjs.ResourceManager {\n private _imageManager: gdjs.PixiImageManager;\n\n /** Pixi.BitmapFont used, indexed by their BitmapFont name. */\n private _pixiBitmapFontsInUse: Record<\n string,\n { objectsUsingTheFont: number }\n > = {};\n\n /** Pixi.BitmapFont not used anymore, but not yet uninstalled, indexed by their BitmapFont name. */\n private _pixiBitmapFontsToUninstall: string[] = [];\n\n /** Loaded fonts data, indexed by resource name. */\n private _loadedFontsData = new gdjs.ResourceCache<any>();\n\n private _defaultSlugFontName: string | null = null;\n\n _resourceLoader: gdjs.ResourceLoader;\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n * @param imageManager The image manager to be used to get textures used by fonts.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n imageManager: gdjs.PixiImageManager\n ) {\n this._imageManager = imageManager;\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Get the instance of the default `Pixi.BitmapFont`, always available.\n */\n getDefaultBitmapFont() {\n if (this._defaultSlugFontName !== null) {\n return PIXI.BitmapFont.available[this._defaultSlugFontName];\n }\n\n // Default bitmap font style\n const fontFamily = 'Arial';\n const bitmapFontStyle = new PIXI.TextStyle({\n fontFamily: fontFamily,\n fontSize: 20,\n padding: 5,\n align: 'left',\n fill: '#ffffff',\n wordWrap: true,\n lineHeight: 20,\n });\n\n // Generate default bitmapFont, and replace the name of PIXI.BitmapFont by a unique name\n const defaultBitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.from(fontFamily, bitmapFontStyle, {\n // All the printable ASCII characters\n chars: [[' ', '~']],\n }),\n defaultBitmapFontKey\n );\n\n // Define the default name used for the default bitmap font.\n this._defaultSlugFontName = defaultBitmapFont.font;\n return defaultBitmapFont;\n }\n\n /**\n * Called to specify that the bitmap font with the specified key is used by an object\n * (i.e: this is reference counting).\n * `releaseBitmapFont` *must* be called to mark the font as not used anymore when the\n * object is destroyed or its font changed.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n private _markBitmapFontAsUsed(bitmapFontInstallKey: string): void {\n this._pixiBitmapFontsInUse[bitmapFontInstallKey] = this\n ._pixiBitmapFontsInUse[bitmapFontInstallKey] || {\n objectsUsingTheFont: 0,\n };\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont++;\n\n for (let i = 0; i < this._pixiBitmapFontsToUninstall.length; ) {\n if (this._pixiBitmapFontsToUninstall[i] === bitmapFontInstallKey) {\n // The font is in the cache of fonts to uninstall, because it was previously used and then marked as not used anymore.\n // Remove it from the cache to avoid the font getting uninstalled.\n this._pixiBitmapFontsToUninstall.splice(i, 1);\n } else {\n i++;\n }\n }\n }\n\n /**\n * When a font is not used by an object anymore (object destroyed or font changed),\n * call this function to decrease the internal count of objects using the font.\n *\n * When a font is not unused anymore, it goes in a temporary cache. The cache holds up to 10 fonts.\n * If the cache reaches its maximum capacity, the oldest font is uninstalled from memory.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n releaseBitmapFont(bitmapFontInstallKey: string) {\n if (bitmapFontInstallKey === defaultBitmapFontKey) {\n // Never uninstall the default font.\n return;\n }\n\n if (!this._pixiBitmapFontsInUse[bitmapFontInstallKey]) {\n logger.warn(\n 'BitmapFont with name ' +\n bitmapFontInstallKey +\n ' was tried to be released but was never marked as used.'\n );\n return;\n }\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont--;\n\n if (\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont ===\n 0\n ) {\n delete this._pixiBitmapFontsInUse[bitmapFontInstallKey];\n\n // Add the font name at the last position of the cache.\n if (!this._pixiBitmapFontsToUninstall.includes(bitmapFontInstallKey)) {\n this._pixiBitmapFontsToUninstall.push(bitmapFontInstallKey);\n }\n if (this._pixiBitmapFontsToUninstall.length > uninstallCacheSize) {\n // Remove the first font (i.e: the oldest one)\n const oldestUnloadedPixiBitmapFontName = this._pixiBitmapFontsToUninstall.shift() as string;\n\n PIXI.BitmapFont.uninstall(oldestUnloadedPixiBitmapFontName);\n logger.log(\n 'Bitmap Text',\n 'Uninstalled BitmapFont \"' +\n oldestUnloadedPixiBitmapFontName +\n '\" from memory.'\n );\n }\n }\n }\n\n /**\n * Given a bitmap font resource name and a texture atlas resource name, returns the PIXI.BitmapFont\n * for it.\n * The font is register and should be released with `releaseBitmapFont` - so that it can be removed\n * from memory when unused.\n */\n obtainBitmapFont(\n bitmapFontResourceName: string,\n textureAtlasResourceName: string\n ): PIXI.BitmapFont {\n const bitmapFontInstallKey =\n bitmapFontResourceName + '@' + textureAtlasResourceName;\n\n if (PIXI.BitmapFont.available[bitmapFontInstallKey]) {\n // Return the existing BitmapFont that is already in memory and already installed.\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n }\n\n // The Bitmap Font is not loaded, load it in memory.\n\n // First get the font data:\n const fontData = this._loadedFontsData.getFromName(\n bitmapFontResourceName\n );\n if (!fontData) {\n logger.warn(\n 'Could not find Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used.'\n );\n return this.getDefaultBitmapFont();\n }\n\n // Get the texture to be used in the font:\n const texture = this._imageManager.getPIXITexture(\n textureAtlasResourceName\n );\n\n try {\n // Create and install the Pixi.BitmapFont in memory:\n const bitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.install(fontData, texture),\n bitmapFontInstallKey\n );\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return bitmapFont;\n } catch (error) {\n logger.error(\n 'Could not load the Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used. Error is: ' +\n error\n );\n return this.getDefaultBitmapFont();\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 \"bitmapFont\" resources of the game, so that they are ready\n * to be used when `obtainBitmapFont` is called.\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 bitmap font for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (this._loadedFontsData.get(resource)) {\n return;\n }\n\n try {\n const response = await fetch(\n this._resourceLoader.getFullUrl(resource.file),\n {\n credentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\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 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n }\n );\n const fontData = await response.text();\n this._loadedFontsData.set(resource, fontData);\n } catch (error) {\n logger.error(\n \"Can't fetch the bitmap font file \" +\n resource.file +\n ', error: ' +\n error\n );\n }\n }\n\n /**\n * To be called when the game is disposed.\n * Uninstall all the fonts from memory and clear cache of loaded fonts.\n */\n dispose(): void {\n for (const bitmapFontInstallKey in this._pixiBitmapFontsInUse) {\n PIXI.BitmapFont.uninstall(bitmapFontInstallKey);\n }\n\n for (const bitmapFontInstallKey of this._pixiBitmapFontsToUninstall) {\n PIXI.BitmapFont.uninstall(bitmapFontInstallKey);\n }\n\n this._pixiBitmapFontsInUse = {};\n this._pixiBitmapFontsToUninstall.length = 0;\n this._loadedFontsData.clear();\n }\n }\n\n // Register the class to let the engine use it.\n export const BitmapFontManager = gdjs.PixiBitmapFontManager;\n export type BitmapFontManager = gdjs.PixiBitmapFontManager;\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,eAEzB,EAAuB,2BAMvB,EAAqB,EASrB,EAA2B,CAC/B,EACA,IACG,CACH,KAAM,GAAc,EAAW,KAE/B,SAAW,KAAO,EAClB,KAAK,WAAW,UAAU,GAAwB,EAClD,MAAO,MAAK,WAAW,UAAU,GAC1B,KAAK,WAAW,UAAU,IAG7B,EAAqC,CAAC,cAOrC,OAA4D,CAwBjE,YACE,EACA,EACA,CAvBM,2BAGJ,GAGI,iCAAwC,GAGxC,sBAAmB,GAAI,GAAK,cAE5B,0BAAsC,KAa5C,KAAK,cAAgB,EACrB,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,GAMT,sBAAuB,CACrB,GAAI,KAAK,uBAAyB,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AAW,QAAQ,EAAU,GAClC,GAEF,YAAK,sBAAsB,GACpB,QACA,EAAP,CACA,SAAO,MACL,sDACE,EACA,+CACA,GAEG,KAAK,6BAIV,iBAAgB,EAAqC,OAQrD,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KACL,4CAA8C,EAAe,MAE/D,OAEF,GAAI,MAAK,iBAAiB,IAAI,GAI9B,GAAI,CAcF,KAAM,GAAW,KAAM,AAbN,MAAM,OACrB,KAAK,gBAAgB,WAAW,EAAS,MACzC,CACE,YAAa,KAAK,gBAAgB,2BAChC,EAAS,MAIP,UAEA,iBAGwB,OAChC,KAAK,iBAAiB,IAAI,EAAU,SAC7B,EAAP,CACA,EAAO,MACL,oCACE,EAAS,KACT,YACA,IASR,SAAgB,CACd,SAAW,KAAwB,MAAK,sBACtC,KAAK,WAAW,UAAU,GAG5B,SAAW,KAAwB,MAAK,4BACtC,KAAK,WAAW,UAAU,GAG5B,KAAK,sBAAwB,GAC7B,KAAK,4BAA4B,OAAS,EAC1C,KAAK,iBAAiB,SAzQnB,EAAM,wBA8QA,oBAAoB,EAAK,wBAnT9B",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(l){const n=new l.Logger("PIXI Image manager"),c=(o,e)=>{n.error("Unable to load file "+o+" with error:",e||"(unknown error)")},d=(o,e)=>{!o||e.smoothed||(o.baseTexture.scaleMode=PIXI.SCALE_MODES.NEAREST)},g=(o,e)=>{e&&!e.smoothed&&(o.magFilter=THREE.NearestFilter,o.minFilter=THREE.NearestFilter)},x=["image","video"];class h{constructor(e){this._loadedTextures=new l.ResourceCache;this._diskTextures=new Map;this._rectangleTextures=new Map;this._scaledTextures=new Map;this._getImageResource=e=>{const r=this._resourceLoader.getResource(e);return r&&this.getResourceKinds().includes(r.kind)?r:null};this._resourceLoader=e,this._invalidTexture=PIXI.Texture.from("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA"),this._loadedThreeTextures=new Hashtable,this._loadedThreeMaterials=new Hashtable}getResourceKinds(){return x}getPIXITexture(e){const r=this._getImageResource(e);if(!r)return n.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const i=this._loadedTextures.get(r);return i?i.valid?i:(n.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture):this._invalidTexture}getOrLoadPIXITexture(e){const r=this._getImageResource(e);if(!r)return n.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const i=this._loadedTextures.get(r);if(i)return i.valid?i:(n.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture);n.log('Loading texture for resource "'+e+'"...');const s=r.file,a=this._resourceLoader.getFullUrl(s),t=PIXI.Texture.from(a,{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(s)?"use-credentials":"anonymous"}}).on("error",u=>{c(s,u)});if(!t)throw new Error("Texture loading by PIXI returned nothing for file "+s+" behind url "+a);return d(t,r),this._loadedTextures.set(r,t),t}getThreeTexture(e){const r=this._loadedThreeTextures.get(e);if(r)return r;const i=this.getPIXITexture(e);if(!this._resourceLoader._runtimeGame.getRenderer().getPIXIRenderer())throw new Error("No PIXI renderer was found.");const a=i.baseTexture.resource.source;if(!(a instanceof HTMLImageElement))throw new Error(`Can't load texture for resource "${e}" as it's not an image.`);const t=new THREE.Texture(a);t.magFilter=THREE.LinearFilter,t.minFilter=THREE.LinearFilter,t.wrapS=THREE.RepeatWrapping,t.wrapT=THREE.RepeatWrapping,t.colorSpace=THREE.SRGBColorSpace,t.needsUpdate=!0;const u=this._getImageResource(e);return g(t,u),this._loadedThreeTextures.put(e,t),t}getThreeMaterial(e,{useTransparentTexture:r,forceBasicMaterial:i}){const s=`${e}|${r?1:0}|${i?1:0}`,a=this._loadedThreeMaterials.get(s);if(a)return a;const t=i?new THREE.MeshBasicMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r}):new THREE.MeshStandardMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r,metalness:0});return this._loadedThreeMaterials.put(s,t),t}getPIXIVideoTexture(e){if(e==="")return this._invalidTexture;const r=this._getImageResource(e);if(!r)return n.warn('Unable to find video texture for resource "'+e+'".'),this._invalidTexture;const i=this._loadedTextures.get(r);return i||this._invalidTexture}getInvalidPIXITexture(){return this._invalidTexture}async loadResource(e){const r=this._resourceLoader.getResource(e);if(!r){n.warn('Unable to find texture for resource "'+e+'".');return}await this._loadTexture(r)}async processResource(e){}async _loadTexture(e){if(!this._loadedTextures.get(e))try{if(e.kind==="video")await new Promise((r,i)=>{const s=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous",autoPlay:!1}}).on("error",t=>{i(t)});s.baseTexture.on("loaded",()=>{this._loadedTextures.set(e,s),d(s,e),r()}).on("error",t=>{i(t)})});else{const r=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{autoLoad:!1,crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous"}});await r.baseTexture.resource.load(),this._loadedTextures.set(e,r),d(r,e)}}catch(r){c(e.file,r)}}getOrCreateDiskTexture(e,r){let i=this._diskTextures.get(e);if(!i){const s=new PIXI.Graphics;s.lineStyle(0,0,0),s.beginFill(l.rgbToHexNumber(255,255,255),1),s.drawCircle(0,0,e),s.endFill(),i=r.generateTexture(s),s.destroy(),this._diskTextures.set(e,i)}return i}getOrCreateRectangleTexture(e,r,i){const s=`${e}_${r}`;let a=this._rectangleTextures.get(s);if(!a){const t=new PIXI.Graphics;t.lineStyle(0,0,0),t.beginFill(l.rgbToHexNumber(255,255,255),1),t.drawRect(0,0,e,r),t.endFill(),a=i.generateTexture(t),t.destroy(),this._rectangleTextures.set(s,a)}return a}getOrCreateScaledTexture(e,r,i,s){const a=`${e}_${r}_${i}`;let t=this._scaledTextures.get(a);if(!t){const u=new PIXI.Graphics,T=new PIXI.Sprite(this.getPIXITexture(e));T.width=r,T.height=i,u.addChild(T),t=s.generateTexture(u),u.destroy(),this._scaledTextures.set(a,t)}return t}}l.PixiImageManager=h,l.ImageManager=l.PixiImageManager})(gdjs||(gdjs={}));
1
+ var gdjs;(function(l){const o=new l.Logger("PIXI Image manager"),c=(n,e)=>{o.error("Unable to load file "+n+" with error:",e||"(unknown error)")},d=(n,e)=>{!n||e.smoothed||(n.baseTexture.scaleMode=PIXI.SCALE_MODES.NEAREST)},x=(n,e)=>{e&&!e.smoothed&&(n.magFilter=THREE.NearestFilter,n.minFilter=THREE.NearestFilter)},g=["image","video"];class h{constructor(e){this._loadedTextures=new l.ResourceCache;this._diskTextures=new Map;this._rectangleTextures=new Map;this._scaledTextures=new Map;this._getImageResource=e=>{const r=this._resourceLoader.getResource(e);return r&&this.getResourceKinds().includes(r.kind)?r:null};this._resourceLoader=e,this._invalidTexture=PIXI.Texture.from("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA"),this._loadedThreeTextures=new Hashtable,this._loadedThreeMaterials=new Hashtable}getResourceKinds(){return g}getPIXITexture(e){const r=this._getImageResource(e);if(!r)return o.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);return t?t.valid?t:(o.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture):this._invalidTexture}getOrLoadPIXITexture(e){const r=this._getImageResource(e);if(!r)return o.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);if(t)return t.valid?t:(o.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture);o.log('Loading texture for resource "'+e+'"...');const s=r.file,a=this._resourceLoader.getFullUrl(s),i=PIXI.Texture.from(a,{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(s)?"use-credentials":"anonymous"}}).on("error",u=>{c(s,u)});if(!i)throw new Error("Texture loading by PIXI returned nothing for file "+s+" behind url "+a);return d(i,r),this._loadedTextures.set(r,i),i}getThreeTexture(e){const r=this._loadedThreeTextures.get(e);if(r)return r;const t=this.getPIXITexture(e);if(!this._resourceLoader._runtimeGame.getRenderer().getPIXIRenderer())throw new Error("No PIXI renderer was found.");const a=t.baseTexture.resource.source;if(!(a instanceof HTMLImageElement))throw new Error(`Can't load texture for resource "${e}" as it's not an image.`);const i=new THREE.Texture(a);i.magFilter=THREE.LinearFilter,i.minFilter=THREE.LinearFilter,i.wrapS=THREE.RepeatWrapping,i.wrapT=THREE.RepeatWrapping,i.colorSpace=THREE.SRGBColorSpace,i.needsUpdate=!0;const u=this._getImageResource(e);return x(i,u),this._loadedThreeTextures.put(e,i),i}getThreeMaterial(e,{useTransparentTexture:r,forceBasicMaterial:t}){const s=`${e}|${r?1:0}|${t?1:0}`,a=this._loadedThreeMaterials.get(s);if(a)return a;const i=t?new THREE.MeshBasicMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r}):new THREE.MeshStandardMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r,metalness:0});return this._loadedThreeMaterials.put(s,i),i}getPIXIVideoTexture(e){if(e==="")return this._invalidTexture;const r=this._getImageResource(e);if(!r)return o.warn('Unable to find video texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);return t||this._invalidTexture}getInvalidPIXITexture(){return this._invalidTexture}async loadResource(e){const r=this._resourceLoader.getResource(e);if(!r){o.warn('Unable to find texture for resource "'+e+'".');return}await this._loadTexture(r)}async processResource(e){}async _loadTexture(e){if(!this._loadedTextures.get(e))try{if(e.kind==="video")await new Promise((r,t)=>{const s=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous",autoPlay:!1}}).on("error",i=>{t(i)});s.baseTexture.on("loaded",()=>{this._loadedTextures.set(e,s),d(s,e),r()}).on("error",i=>{t(i)})});else{const r=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{autoLoad:!1,crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous"}});await r.baseTexture.resource.load(),this._loadedTextures.set(e,r),d(r,e)}}catch(r){c(e.file,r)}}getOrCreateDiskTexture(e,r){let t=this._diskTextures.get(e);if(!t){const s=new PIXI.Graphics;s.lineStyle(0,0,0),s.beginFill(l.rgbToHexNumber(255,255,255),1),s.drawCircle(0,0,e),s.endFill(),t=r.generateTexture(s),s.destroy(),this._diskTextures.set(e,t)}return t}getOrCreateRectangleTexture(e,r,t){const s=`${e}_${r}`;let a=this._rectangleTextures.get(s);if(!a){const i=new PIXI.Graphics;i.lineStyle(0,0,0),i.beginFill(l.rgbToHexNumber(255,255,255),1),i.drawRect(0,0,e,r),i.endFill(),a=t.generateTexture(i),i.destroy(),this._rectangleTextures.set(s,a)}return a}getOrCreateScaledTexture(e,r,t,s){const a=`${e}_${r}_${t}`;let i=this._scaledTextures.get(a);if(!i){const u=new PIXI.Graphics,T=new PIXI.Sprite(this.getPIXITexture(e));T.width=r,T.height=t,u.addChild(T),i=s.generateTexture(u),u.destroy(),this._scaledTextures.set(a,i)}return i}dispose(){this._loadedTextures.clear();const e=[];this._loadedThreeTextures.values(e),this._loadedThreeTextures.clear();for(const t of e)t.dispose();const r=[];this._loadedThreeMaterials.values(r),this._loadedThreeMaterials.clear();for(const t of r)t.dispose();for(const t of this._diskTextures.values())t.destroyed||t.destroy();this._diskTextures.clear();for(const t of this._rectangleTextures.values())t.destroyed||t.destroy();this._rectangleTextures.clear();for(const t of this._scaledTextures.values())t.destroyed||t.destroy();this._scaledTextures.clear()}}l.PixiImageManager=h,l.ImageManager=l.PixiImageManager})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=pixi-image-manager.js.map