gdcore-tools 2.0.0-gd-v5.5.242-autobuild → 2.0.0-gd-v5.5.243-autobuild
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Runtime/AsyncTasksManager.js +2 -2
- package/dist/Runtime/AsyncTasksManager.js.map +2 -2
- package/dist/Runtime/CustomRuntimeObject.js +1 -1
- package/dist/Runtime/CustomRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/Cube3DRuntimeObject.js +1 -1
- package/dist/Runtime/Extensions/3D/Cube3DRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/JsExtension.js +5 -0
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js +1 -1
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject3DRenderer.js +1 -1
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject3DRenderer.js.map +2 -2
- package/dist/Runtime/Extensions/BBText/bbtextruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/BBText/bbtextruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/BitmapText/bitmaptextruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/BitmapText/bitmaptextruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/DebuggerTools/JsExtension.js +3 -1
- package/dist/Runtime/Extensions/DestroyOutsideBehavior/destroyoutsideruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/DestroyOutsideBehavior/destroyoutsideruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Lighting/lightruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Lighting/lightruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject.js +1 -1
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject.js.map +2 -2
- package/dist/Runtime/Extensions/PathfindingBehavior/pathfindingruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/PathfindingBehavior/pathfindingruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PlatformBehavior/platformerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/PlatformBehavior/platformerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PlatformBehavior/platformruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/PlatformBehavior/platformruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PrimitiveDrawing/shapepainterruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/PrimitiveDrawing/shapepainterruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/SaveState/JsExtension.js +488 -0
- package/dist/Runtime/Extensions/SaveState/SaveConfigurationRuntimeBehavior.js +2 -0
- package/dist/Runtime/Extensions/SaveState/SaveConfigurationRuntimeBehavior.js.map +7 -0
- package/dist/Runtime/Extensions/SaveState/SaveStateTools.js +2 -0
- package/dist/Runtime/Extensions/SaveState/SaveStateTools.js.map +7 -0
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextObject/textruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TextObject/textruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/helper/dts/model/TileMapModel.d.ts +4 -4
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/TweenManager.js +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/TweenManager.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/tweenruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/TweenBehavior/tweenruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/tweentools.js +1 -1
- package/dist/Runtime/Extensions/TweenBehavior/tweentools.js.map +2 -2
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js.map +2 -2
- package/dist/Runtime/RuntimeInstanceContainer.js +1 -1
- package/dist/Runtime/RuntimeInstanceContainer.js.map +2 -2
- package/dist/Runtime/RuntimeLayer.js +1 -1
- package/dist/Runtime/RuntimeLayer.js.map +2 -2
- package/dist/Runtime/debugger-client/hot-reloader.js +1 -1
- package/dist/Runtime/debugger-client/hot-reloader.js.map +2 -2
- package/dist/Runtime/events-tools/objecttools.js +1 -1
- package/dist/Runtime/events-tools/objecttools.js.map +2 -2
- package/dist/Runtime/events-tools/runtimescenetools.js +1 -1
- package/dist/Runtime/events-tools/runtimescenetools.js.map +2 -2
- package/dist/Runtime/gd.js +1 -1
- package/dist/Runtime/gd.js.map +2 -2
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
- package/dist/Runtime/indexeddb.js +2 -0
- package/dist/Runtime/indexeddb.js.map +7 -0
- package/dist/Runtime/oncetriggers.js +1 -1
- package/dist/Runtime/oncetriggers.js.map +2 -2
- package/dist/Runtime/runtimebehavior.js +1 -1
- package/dist/Runtime/runtimebehavior.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/runtimeobject.js +1 -1
- package/dist/Runtime/runtimeobject.js.map +2 -2
- package/dist/Runtime/runtimescene.js +1 -1
- package/dist/Runtime/runtimescene.js.map +2 -2
- package/dist/Runtime/scenestack.js +1 -1
- package/dist/Runtime/scenestack.js.map +2 -2
- package/dist/Runtime/spriteruntimeobject.js +1 -1
- package/dist/Runtime/spriteruntimeobject.js.map +2 -2
- package/dist/Runtime/timemanager.js +1 -1
- package/dist/Runtime/timemanager.js.map +2 -2
- package/dist/Runtime/timer.js +1 -1
- package/dist/Runtime/timer.js.map +2 -2
- package/dist/Runtime/types/global-types.d.ts +29 -0
- package/dist/Runtime/types/project-data.d.ts +144 -3
- package/dist/Runtime/types/save-state.d.ts +9 -0
- package/dist/Runtime/variable.js +1 -1
- package/dist/Runtime/variable.js.map +2 -2
- package/dist/Runtime/variablescontainer.js +1 -1
- package/dist/Runtime/variablescontainer.js.map +2 -2
- package/dist/lib/libGD.cjs +1 -1
- package/dist/lib/libGD.wasm +0 -0
- package/dist/loaders.cjs +1 -1
- package/gd.d.ts +1 -0
- 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 * Handles errors that occur when calling Howler sound methods.\n *\n * This function provides special handling for \"Maximum call stack size exceeded\" errors\n * that can occur in Howler.js due to recursive method calls in volume(), seek(), fade(),\n * and other sound manipulation methods. Instead of crashing the application, these\n * specific errors are logged as warnings to allow the application to continue running.\n *\n * @param error - The error that occurred during the method call\n * @param methodName - The name of the Howler method that caused the error (e.g., 'volume', 'seek')\n *\n * @throws {Error} Re-throws the original error if it's not a stack overflow error\n *\n */\n const handleHowlerSoundMethodError = (error: unknown, methodName: string) => {\n if (\n error instanceof Error &&\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 call method \"${methodName}\":`,\n error\n );\n } else {\n throw error;\n }\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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'play');\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 try {\n if (this._id !== null) this._howl.pause(this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'pause');\n }\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 try {\n if (this._id !== null) this._howl.stop(this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'stop');\n }\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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'rate');\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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'loop');\n }\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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'volume');\n }\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 try {\n if (this._id !== null) this._howl.mute(mute, this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'mute');\n }\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 try {\n if (this._id !== null) this._howl.seek(seek, this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'seek');\n }\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 try {\n if (this._id !== null)\n this._howl.fade(\n clampVolume(from),\n clampVolume(to),\n duration,\n this._id\n );\n } catch (error) {\n handleHowlerSoundMethodError(error, 'fade');\n }\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 implements gdjs.ResourceManager {\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 _cachedSpatialPosition: Record<integer, [number, number, number]> = {};\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 resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n\n gdjs.registerRuntimeScenePostEventsCallback(\n this._clearCachedSpatialPosition.bind(this)\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 that.pauseAllActiveSounds();\n },\n false\n );\n document.addEventListener(\n 'resume',\n function () {\n that.resumeAllActiveSounds();\n },\n false\n );\n });\n }\n\n pauseAllActiveSounds(): void {\n const soundList = this._freeSounds.concat(this._freeMusics);\n for (let key in this._sounds) {\n if (this._sounds.hasOwnProperty(key)) {\n soundList.push(this._sounds[key]);\n }\n }\n for (let key in this._musics) {\n if (this._musics.hasOwnProperty(key)) {\n soundList.push(this._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 this._pausedSounds.push(sound);\n }\n }\n this._paused = true;\n }\n\n resumeAllActiveSounds(): void {\n try {\n for (let i = 0; i < this._pausedSounds.length; i++) {\n const sound = this._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 this._pausedSounds.length = 0;\n this._paused = false;\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 * @param resource\n * @returns Resource files\n */\n private _getSoundUrlsFromResource(resource: ResourceData): string[] {\n return [this._resourceLoader.getFullUrl(resource.file)];\n }\n\n /**\n * @param resource\n * @returns Resource file\n */\n private _getDefaultSoundUrl(resource: ResourceData): string {\n return this._resourceLoader.getFullUrl(resource.file);\n }\n\n /**\n * Preload audio file\n * @param resource\n * @param isMusic\n */\n private _preloadAudioFile(\n resource: ResourceData,\n isMusic: boolean\n ): Promise<number> {\n const file = resource.file;\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._getSoundUrlsFromResource(resource),\n onload: resolve,\n onloaderror: (soundId: number, error?: string) => reject(error),\n html5: isMusic,\n xhr: {\n withCredentials:\n this._resourceLoader.checkIfCredentialsRequired(file),\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 /**\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 howl = new Howl(\n Object.assign(\n {\n src: this._getSoundUrlsFromResource(resource),\n html5: isMusic,\n xhr: {\n withCredentials:\n 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 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._getSoundUrlsFromResource(resource),\n html5: isMusic,\n xhr: {\n withCredentials:\n 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 const spatialPosition = this._cachedSpatialPosition[channel];\n if (spatialPosition) {\n sound.once('play', () => {\n sound.setSpatialPosition(...spatialPosition);\n });\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 // Musics are played with the html5 backend, that is not compatible with spatialization.\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 setSoundSpatialPositionOnChannel(\n channel: number,\n x: number,\n y: number,\n z: number\n ) {\n const sound = this.getSoundOnChannel(channel);\n if (sound && !sound.paused()) sound.setSpatialPosition(x, y, z);\n else {\n // If no sound is playing at the time the method is called, the\n // position is cached and will be used by the `playSoundOnChannel` method\n // to set the spatial position right after the sound starts playing.\n // This cached value is then cleared at the end of the frame.\n // Without this caching strategy, if actions are in the wrong order,\n // the spatial position will not apply to the sound because\n // it is not playing yet.\n this._cachedSpatialPosition[channel] = [x, y, z];\n }\n }\n\n _clearCachedSpatialPosition() {\n this._cachedSpatialPosition = {};\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 if (resource.preloadAsMusic) {\n try {\n await this._preloadAudioFile(resource, /* 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 this._preloadAudioFile(resource, /* 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 const file = resource.file;\n await new Promise((resolve, reject) => {\n const sound = new XMLHttpRequest();\n sound.withCredentials =\n this._resourceLoader.checkIfCredentialsRequired(file);\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._getDefaultSoundUrl(resource));\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 unloadResource(resourceData: ResourceData): void {\n const musicRes = this._loadedMusics.get(resourceData);\n if (musicRes) {\n this.unloadAudio(resourceData.name, true);\n }\n\n const soundRes = this._loadedSounds.get(resourceData);\n if (soundRes) {\n this.unloadAudio(resourceData.name, false);\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,EAiBH,EAA+B,CAAC,EAAgB,IAAuB,CAC3E,GACE,YAAiB,QACjB,EAAM,SACN,MAAO,GAAM,SAAY,UACzB,EAAM,QAAQ,WAAW,oCAEzB,QAAQ,KACN,uCAAuC,MACvC,OAGF,MAAM,IAaH,OAAkB,
|
|
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 * Handles errors that occur when calling Howler sound methods.\n *\n * This function provides special handling for \"Maximum call stack size exceeded\" errors\n * that can occur in Howler.js due to recursive method calls in volume(), seek(), fade(),\n * and other sound manipulation methods. Instead of crashing the application, these\n * specific errors are logged as warnings to allow the application to continue running.\n *\n * @param error - The error that occurred during the method call\n * @param methodName - The name of the Howler method that caused the error (e.g., 'volume', 'seek')\n *\n * @throws {Error} Re-throws the original error if it's not a stack overflow error\n *\n */\n const handleHowlerSoundMethodError = (error: unknown, methodName: string) => {\n if (\n error instanceof Error &&\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 call method \"${methodName}\":`,\n error\n );\n } else {\n throw error;\n }\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 /**\n * The filepath to the resource\n */\n private _audioResourceName: string;\n\n constructor(\n howl: Howl,\n volume: float,\n loop: boolean,\n rate: float,\n audioResourceName: string\n ) {\n this._howl = howl;\n this._initialVolume = clampVolume(volume);\n this._loop = loop;\n this._rate = rate;\n this._audioResourceName = audioResourceName;\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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'play');\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 try {\n if (this._id !== null) this._howl.pause(this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'pause');\n }\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 try {\n if (this._id !== null) this._howl.stop(this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'stop');\n }\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 const isSoundPlaying =\n this._id !== null ? this._howl.playing(this._id) : true;\n return (\n isSoundPlaying || !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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'rate');\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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'loop');\n }\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 try {\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 } catch (error) {\n handleHowlerSoundMethodError(error, 'volume');\n }\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 try {\n if (this._id !== null) this._howl.mute(mute, this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'mute');\n }\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 try {\n if (this._id !== null) this._howl.seek(seek, this._id);\n } catch (error) {\n handleHowlerSoundMethodError(error, 'seek');\n }\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 try {\n if (this._id !== null)\n this._howl.fade(\n clampVolume(from),\n clampVolume(to),\n duration,\n this._id\n );\n } catch (error) {\n handleHowlerSoundMethodError(error, 'fade');\n }\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 getNetworkSyncData(): SoundSyncData | undefined {\n if (this.paused() || !this.isLoaded() || this.stopped()) return undefined;\n // Seek can sometimes return the Howl object in case it isn't loaded yet, in this case we default to 0.\n const seek = this.getSeek();\n const numberSeek = typeof seek !== 'number' ? 0 : seek;\n // If the Howl is still loading, we use the initialVolume, as the Howl\n // has been initialized with volume 0.\n const volume = this.isLoaded() ? this.getVolume() : this._initialVolume;\n return {\n resourceName: this._audioResourceName,\n loop: this._loop,\n volume,\n rate: this._rate,\n seek: numberSeek,\n };\n }\n }\n\n /**\n * HowlerSoundManager is used to manage the sounds and musics of a RuntimeGame.\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 implements gdjs.ResourceManager {\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 _cachedSpatialPosition: Record<integer, [number, number, number]> = {};\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 resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n\n gdjs.registerRuntimeScenePostEventsCallback(\n this._clearCachedSpatialPosition.bind(this)\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 that.pauseAllActiveSounds();\n },\n false\n );\n document.addEventListener(\n 'resume',\n function () {\n that.resumeAllActiveSounds();\n },\n false\n );\n });\n }\n\n pauseAllActiveSounds(): void {\n const soundList = this._freeSounds.concat(this._freeMusics);\n for (let key in this._sounds) {\n if (this._sounds.hasOwnProperty(key)) {\n soundList.push(this._sounds[key]);\n }\n }\n for (let key in this._musics) {\n if (this._musics.hasOwnProperty(key)) {\n soundList.push(this._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 this._pausedSounds.push(sound);\n }\n }\n this._paused = true;\n }\n\n resumeAllActiveSounds(): void {\n try {\n for (let i = 0; i < this._pausedSounds.length; i++) {\n const sound = this._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 this._pausedSounds.length = 0;\n this._paused = false;\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 * @param resource\n * @returns Resource files\n */\n private _getSoundUrlsFromResource(resource: ResourceData): string[] {\n return [this._resourceLoader.getFullUrl(resource.file)];\n }\n\n /**\n * @param resource\n * @returns Resource file\n */\n private _getDefaultSoundUrl(resource: ResourceData): string {\n return this._resourceLoader.getFullUrl(resource.file);\n }\n\n /**\n * Preload audio file\n * @param resource\n * @param isMusic\n */\n private _preloadAudioFile(\n resource: ResourceData,\n isMusic: boolean\n ): Promise<number> {\n const file = resource.file;\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._getSoundUrlsFromResource(resource),\n onload: resolve,\n onloaderror: (soundId: number, error?: string) => reject(error),\n html5: isMusic,\n xhr: {\n withCredentials:\n this._resourceLoader.checkIfCredentialsRequired(file),\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 /**\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 howl = new Howl(\n Object.assign(\n {\n src: this._getSoundUrlsFromResource(resource),\n html5: isMusic,\n xhr: {\n withCredentials:\n 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 cacheContainer.set(resource, howl);\n }\n return new gdjs.HowlerSound(howl, volume, loop, rate, soundName);\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._getSoundUrlsFromResource(resource),\n html5: isMusic,\n xhr: {\n withCredentials:\n 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(\n soundName: string,\n loop: boolean,\n volume: float,\n pitch: float,\n seek?: float\n ) {\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 if (seek) {\n sound.setSeek(seek);\n }\n }\n\n playSoundOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float,\n seek?: 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 const spatialPosition = this._cachedSpatialPosition[channel];\n if (spatialPosition) {\n sound.once('play', () => {\n sound.setSpatialPosition(...spatialPosition);\n });\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 if (seek) {\n sound.setSeek(seek);\n }\n }\n\n getSoundOnChannel(channel: integer): HowlerSound | null {\n return this._sounds[channel] || null;\n }\n\n playMusic(\n soundName: string,\n loop: boolean,\n volume: float,\n pitch: float,\n seek?: float\n ) {\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 if (seek) {\n music.setSeek(seek);\n }\n }\n\n playMusicOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float,\n seek?: 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 // Musics are played with the html5 backend, that is not compatible with spatialization.\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 if (seek) {\n music.setSeek(seek);\n }\n }\n\n getMusicOnChannel(channel: integer): HowlerSound | null {\n return this._musics[channel] || null;\n }\n\n setSoundSpatialPositionOnChannel(\n channel: number,\n x: number,\n y: number,\n z: number\n ) {\n const sound = this.getSoundOnChannel(channel);\n if (sound && !sound.paused()) sound.setSpatialPosition(x, y, z);\n else {\n // If no sound is playing at the time the method is called, the\n // position is cached and will be used by the `playSoundOnChannel` method\n // to set the spatial position right after the sound starts playing.\n // This cached value is then cleared at the end of the frame.\n // Without this caching strategy, if actions are in the wrong order,\n // the spatial position will not apply to the sound because\n // it is not playing yet.\n this._cachedSpatialPosition[channel] = [x, y, z];\n }\n }\n\n _clearCachedSpatialPosition() {\n this._cachedSpatialPosition = {};\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 if (resource.preloadAsMusic) {\n try {\n await this._preloadAudioFile(resource, /* 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 this._preloadAudioFile(resource, /* 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 const file = resource.file;\n await new Promise((resolve, reject) => {\n const sound = new XMLHttpRequest();\n sound.withCredentials =\n this._resourceLoader.checkIfCredentialsRequired(file);\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._getDefaultSoundUrl(resource));\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 getNetworkSyncData(): SoundManagerSyncData {\n const freeMusicsNetworkSyncData: SoundSyncData[] = [];\n this._freeMusics.forEach((freeMusic) => {\n const musicSyncData = freeMusic.getNetworkSyncData();\n if (musicSyncData) freeMusicsNetworkSyncData.push(musicSyncData);\n });\n const freeSoundsNetworkSyncData: SoundSyncData[] = [];\n this._freeSounds.forEach((freeSound) => {\n const soundSyncData = freeSound.getNetworkSyncData();\n if (soundSyncData) freeSoundsNetworkSyncData.push(soundSyncData);\n });\n const musicsNetworkSyncData: ChannelsSoundSyncData = {};\n Object.entries(this._musics).forEach(([channel, music]) => {\n const musicSyncData = music.getNetworkSyncData();\n if (musicSyncData) {\n const channelNumber = parseInt(channel, 10);\n musicsNetworkSyncData[channelNumber] = musicSyncData;\n }\n });\n const soundsNetworkSyncData: ChannelsSoundSyncData = {};\n Object.entries(this._sounds).forEach(([channel, sound]) => {\n const soundSyncData = sound.getNetworkSyncData();\n if (soundSyncData) {\n const channelNumber = parseInt(channel, 10);\n soundsNetworkSyncData[channelNumber] = soundSyncData;\n }\n });\n\n return {\n globalVolume: this._globalVolume,\n cachedSpatialPosition: this._cachedSpatialPosition,\n freeMusics: freeMusicsNetworkSyncData,\n freeSounds: freeSoundsNetworkSyncData,\n musics: musicsNetworkSyncData,\n sounds: soundsNetworkSyncData,\n };\n }\n\n updateFromNetworkSyncData(syncData: SoundManagerSyncData): void {\n this.clearAll();\n this._globalVolume = syncData.globalVolume;\n this._cachedSpatialPosition = syncData.cachedSpatialPosition;\n\n for (let i = 0; i < syncData.freeSounds.length; i++) {\n const freeSoundsSyncData: SoundSyncData = syncData.freeSounds[i];\n\n this.playSound(\n freeSoundsSyncData.resourceName,\n freeSoundsSyncData.loop,\n freeSoundsSyncData.volume * 100,\n freeSoundsSyncData.rate,\n freeSoundsSyncData.seek\n );\n }\n\n for (let i = 0; i < syncData.freeMusics.length; i++) {\n const freeMusicsSyncData: SoundSyncData = syncData.freeMusics[i];\n this.playMusic(\n freeMusicsSyncData.resourceName,\n freeMusicsSyncData.loop,\n freeMusicsSyncData.volume * 100,\n freeMusicsSyncData.rate,\n freeMusicsSyncData.seek\n );\n }\n\n for (const [channel, soundSyncData] of Object.entries(syncData.sounds)) {\n const channelNumber = parseInt(channel, 10);\n this.playSoundOnChannel(\n soundSyncData.resourceName,\n channelNumber,\n soundSyncData.loop,\n soundSyncData.volume * 100,\n soundSyncData.rate,\n soundSyncData.seek\n );\n }\n\n for (const [channel, musicSyncData] of Object.entries(syncData.musics)) {\n const channelNumber = parseInt(channel, 10);\n this.playMusicOnChannel(\n musicSyncData.resourceName,\n channelNumber,\n musicSyncData.loop,\n musicSyncData.volume * 100,\n musicSyncData.rate,\n musicSyncData.seek\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 unloadResource(resourceData: ResourceData): void {\n const musicRes = this._loadedMusics.get(resourceData);\n if (musicRes) {\n this.unloadAudio(resourceData.name, true);\n }\n\n const soundRes = this._loadedSounds.get(resourceData);\n if (soundRes) {\n this.unloadAudio(resourceData.name, false);\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,EAiBH,EAA+B,CAAC,EAAgB,IAAuB,CAC3E,GACE,YAAiB,QACjB,EAAM,SACN,MAAO,GAAM,SAAY,UACzB,EAAM,QAAQ,WAAW,oCAEzB,QAAQ,KACN,uCAAuC,MACvC,OAGF,MAAM,IAaH,OAAkB,CAkDvB,YACE,EACA,EACA,EACA,EACA,EACA,CApDM,SAAsB,KAkCtB,eAAiC,GAKjC,aAA+B,GAcrC,KAAK,MAAQ,EACb,KAAK,eAAiB,EAAY,GAClC,KAAK,MAAQ,EACb,KAAK,MAAQ,EACb,KAAK,mBAAqB,EAM5B,UAAoB,CAClB,MAAO,MAAK,MAAM,UAAY,SAOhC,MAAa,CACX,GAAI,CACF,GAAI,KAAK,WAAY,CACnB,K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C5B,WAAY,EACZ,WAAY,EACZ,OAAQ,EACR,OAAQ,GAIZ,0BAA0B,EAAsC,CAC9D,KAAK,WACL,KAAK,cAAgB,EAAS,aAC9B,KAAK,uBAAyB,EAAS,sBAEvC,OAAS,GAAI,EAAG,EAAI,EAAS,WAAW,OAAQ,IAAK,CACnD,KAAM,GAAoC,EAAS,WAAW,GAE9D,KAAK,UACH,EAAmB,aACnB,EAAmB,KACnB,EAAmB,OAAS,IAC5B,EAAmB,KACnB,EAAmB,MAIvB,OAAS,GAAI,EAAG,EAAI,EAAS,WAAW,OAAQ,IAAK,CACnD,KAAM,GAAoC,EAAS,WAAW,GAC9D,KAAK,UACH,EAAmB,aACnB,EAAmB,KACnB,EAAmB,OAAS,IAC5B,EAAmB,KACnB,EAAmB,MAIvB,SAAW,CAAC,EAAS,IAAkB,QAAO,QAAQ,EAAS,QAAS,CACtE,KAAM,GAAgB,SAAS,EAAS,IACxC,KAAK,mBACH,EAAc,aACd,EACA,EAAc,KACd,EAAc,OAAS,IACvB,EAAc,KACd,EAAc,MAIlB,SAAW,CAAC,EAAS,IAAkB,QAAO,QAAQ,EAAS,QAAS,CACtE,KAAM,GAAgB,SAAS,EAAS,IACxC,KAAK,mBACH,EAAc,aACd,EACA,EAAc,KACd,EAAc,OAAS,IACvB,EAAc,KACd,EAAc,OASpB,SAAgB,CACd,KAAK,YAGP,eAAe,EAAkC,CAE/C,AAAI,AADa,KAAK,cAAc,IAAI,IAEtC,KAAK,YAAY,EAAa,KAAM,IAIlC,AADa,KAAK,cAAc,IAAI,IAEtC,KAAK,YAAY,EAAa,KAAM,KA3rBnC,EAAM,qBAisBA,eAAe,IA9oCpB",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var gdjs;(function(a){let p;(function(l){l.loadFromIndexedDB=async function(u,e,d){return new Promise((s,t)=>{try{const r=indexedDB.open(u,1);r.onupgradeneeded=function(){const n=r.result;n.objectStoreNames.contains(e)||n.createObjectStore(e)},r.onsuccess=function(){const o=r.result.transaction(e,"readonly").objectStore(e).get(d);o.onsuccess=function(){o.result!==void 0?s(o.result):s(null)},o.onerror=function(){console.error("Error loading data from IndexedDB:",o.error),t(o.error)}},r.onerror=function(){console.error("Error opening IndexedDB:",r.error),t(r.error)}}catch(r){console.error("Exception thrown while opening IndexedDB:",r),t(r);return}})},l.saveToIndexedDB=async function(u,e,d,s){return new Promise((t,r)=>{try{const n=indexedDB.open(u,1);n.onupgradeneeded=function(f){const c=n.result;c.objectStoreNames.contains(e)||c.createObjectStore(e)},n.onsuccess=function(){const i=n.result.transaction(e,"readwrite").objectStore(e).put(s,d);i.onsuccess=function(){t()},i.onerror=function(){console.error("Error saving data to IndexedDB:",i.error),r(i.error)}},n.onerror=function(){console.error("Error opening IndexedDB:",n.error),r(n.error)}}catch(n){console.error("Exception thrown while opening IndexedDB:",n),r(n);return}})}})(p=a.indexedDb||(a.indexedDb={}))})(gdjs||(gdjs={}));
|
|
2
|
+
//# sourceMappingURL=indexeddb.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../GDevelop/GDJS/Runtime/indexeddb.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n export namespace indexedDb {\n export const loadFromIndexedDB = async function (\n dbName: string,\n objectStoreName: string,\n key: string\n ): Promise<any> {\n return new Promise((resolve, reject) => {\n try {\n const request = indexedDB.open(dbName, 1);\n request.onupgradeneeded = function () {\n const db = request.result;\n if (!db.objectStoreNames.contains(objectStoreName)) {\n db.createObjectStore(objectStoreName);\n }\n };\n\n request.onsuccess = function () {\n const db = request.result;\n\n const tx = db.transaction(objectStoreName, 'readonly');\n const store = tx.objectStore(objectStoreName);\n const getRequest = store.get(key);\n\n getRequest.onsuccess = function () {\n if (getRequest.result !== undefined) {\n resolve(getRequest.result);\n } else {\n resolve(null);\n }\n };\n\n getRequest.onerror = function () {\n console.error(\n 'Error loading data from IndexedDB:',\n getRequest.error\n );\n reject(getRequest.error);\n };\n };\n\n request.onerror = function () {\n console.error('Error opening IndexedDB:', request.error);\n reject(request.error);\n };\n } catch (err) {\n console.error('Exception thrown while opening IndexedDB:', err);\n reject(err);\n return;\n }\n });\n };\n\n export const saveToIndexedDB = async function (\n dbName: string,\n objectStoreName: string,\n key: string,\n data: any\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n try {\n const request = indexedDB.open(dbName, 1);\n request.onupgradeneeded = function (event) {\n const db = request.result;\n if (!db.objectStoreNames.contains(objectStoreName)) {\n db.createObjectStore(objectStoreName);\n }\n };\n request.onsuccess = function () {\n const db = request.result;\n const tx = db.transaction(objectStoreName, 'readwrite');\n const store = tx.objectStore(objectStoreName);\n const putRequest = store.put(data, key);\n\n putRequest.onsuccess = function () {\n resolve();\n };\n\n putRequest.onerror = function () {\n console.error(\n 'Error saving data to IndexedDB:',\n putRequest.error\n );\n reject(putRequest.error);\n };\n };\n\n request.onerror = function () {\n console.error('Error opening IndexedDB:', request.error);\n reject(request.error);\n };\n } catch (err) {\n console.error('Exception thrown while opening IndexedDB:', err);\n reject(err);\n return;\n }\n });\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACS,GAAU,GAAV,UAAU,EAAV,CACE,AAAM,oBAAoB,eAC/B,EACA,EACA,EACc,CACd,MAAO,IAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,GAAI,CACF,KAAM,GAAU,UAAU,KAAK,EAAQ,GACvC,EAAQ,gBAAkB,UAAY,CACpC,KAAM,GAAK,EAAQ,OACnB,AAAK,EAAG,iBAAiB,SAAS,IAChC,EAAG,kBAAkB,IAIzB,EAAQ,UAAY,UAAY,CAK9B,KAAM,GAAa,AADL,AADH,AAFA,EAAQ,OAEL,YAAY,EAAiB,YAC1B,YAAY,GACJ,IAAI,GAE7B,EAAW,UAAY,UAAY,CACjC,AAAI,EAAW,SAAW,OACxB,EAAQ,EAAW,QAEnB,EAAQ,OAIZ,EAAW,QAAU,UAAY,CAC/B,QAAQ,MACN,qCACA,EAAW,OAEb,EAAO,EAAW,SAItB,EAAQ,QAAU,UAAY,CAC5B,QAAQ,MAAM,2BAA4B,EAAQ,OAClD,EAAO,EAAQ,cAEV,EAAP,CACA,QAAQ,MAAM,4CAA6C,GAC3D,EAAO,GACP,WAKO,kBAAkB,eAC7B,EACA,EACA,EACA,EACe,CACf,MAAO,IAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,GAAI,CACF,KAAM,GAAU,UAAU,KAAK,EAAQ,GACvC,EAAQ,gBAAkB,SAAU,EAAO,CACzC,KAAM,GAAK,EAAQ,OACnB,AAAK,EAAG,iBAAiB,SAAS,IAChC,EAAG,kBAAkB,IAGzB,EAAQ,UAAY,UAAY,CAI9B,KAAM,GAAa,AADL,AADH,AADA,EAAQ,OACL,YAAY,EAAiB,aAC1B,YAAY,GACJ,IAAI,EAAM,GAEnC,EAAW,UAAY,UAAY,CACjC,KAGF,EAAW,QAAU,UAAY,CAC/B,QAAQ,MACN,kCACA,EAAW,OAEb,EAAO,EAAW,SAItB,EAAQ,QAAU,UAAY,CAC5B,QAAQ,MAAM,2BAA4B,EAAQ,OAClD,EAAO,EAAQ,cAEV,EAAP,CACA,QAAQ,MAAM,4CAA6C,GAC3D,EAAO,GACP,aA7FS,mCADT",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(
|
|
1
|
+
var gdjs;(function(g){class r{constructor(){this._onceTriggers={};this._lastFrameOnceTrigger={}}startNewFrame(){for(const e in this._lastFrameOnceTrigger)this._lastFrameOnceTrigger.hasOwnProperty(e)&&delete this._lastFrameOnceTrigger[e];for(const e in this._onceTriggers)this._onceTriggers.hasOwnProperty(e)&&(this._lastFrameOnceTrigger[e]=this._onceTriggers[e],delete this._onceTriggers[e])}triggerOnce(e){return this._onceTriggers[e]=!0,!this._lastFrameOnceTrigger.hasOwnProperty(e)}getNetworkSyncData(){return{onceTriggers:this._onceTriggers,lastFrameOnceTriggers:this._lastFrameOnceTrigger}}updateNetworkSyncData(e){this._onceTriggers=e.onceTriggers,this._lastFrameOnceTrigger=e.lastFrameOnceTriggers}}g.OnceTriggers=r})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=oncetriggers.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/oncetriggers.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 * OnceTriggers is used to store the status of the conditions \"Trigger once\",\n * that are used in events to have conditions that are only valid for one frame in a row.\n */\n export class OnceTriggers {\n _onceTriggers: Record<integer, boolean> = {};\n _lastFrameOnceTrigger: Record<integer, boolean> = {};\n\n /**\n * To be called when events begin so that \"Trigger once\" conditions\n * are properly handled.\n */\n startNewFrame(): void {\n // Clear triggers from 2 frames ago\n for (const k in this._lastFrameOnceTrigger)\n if (this._lastFrameOnceTrigger.hasOwnProperty(k))\n delete this._lastFrameOnceTrigger[k];\n\n // Move triggers from this frame to last frame\n for (const k in this._onceTriggers) {\n if (this._onceTriggers.hasOwnProperty(k)) {\n this._lastFrameOnceTrigger[k] = this._onceTriggers[k];\n delete this._onceTriggers[k];\n }\n }\n }\n\n /**\n * Used by \"Trigger once\" conditions: return true only if\n * this method was not called with the same identifier during the last frame.\n * @param triggerId The identifier of the \"Trigger once\" condition.\n */\n triggerOnce(triggerId: integer): boolean {\n this._onceTriggers[triggerId] = true;\n return !this._lastFrameOnceTrigger.hasOwnProperty(triggerId);\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,
|
|
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 * OnceTriggers is used to store the status of the conditions \"Trigger once\",\n * that are used in events to have conditions that are only valid for one frame in a row.\n */\n\n type OnceTriggersSyncData = {\n onceTriggers: Record<integer, boolean>;\n lastFrameOnceTriggers: Record<integer, boolean>;\n };\n export class OnceTriggers {\n _onceTriggers: Record<integer, boolean> = {};\n _lastFrameOnceTrigger: Record<integer, boolean> = {};\n\n /**\n * To be called when events begin so that \"Trigger once\" conditions\n * are properly handled.\n */\n startNewFrame(): void {\n // Clear triggers from 2 frames ago\n for (const k in this._lastFrameOnceTrigger)\n if (this._lastFrameOnceTrigger.hasOwnProperty(k))\n delete this._lastFrameOnceTrigger[k];\n\n // Move triggers from this frame to last frame\n for (const k in this._onceTriggers) {\n if (this._onceTriggers.hasOwnProperty(k)) {\n this._lastFrameOnceTrigger[k] = this._onceTriggers[k];\n delete this._onceTriggers[k];\n }\n }\n }\n\n /**\n * Used by \"Trigger once\" conditions: return true only if\n * this method was not called with the same identifier during the last frame.\n * @param triggerId The identifier of the \"Trigger once\" condition.\n */\n triggerOnce(triggerId: integer): boolean {\n this._onceTriggers[triggerId] = true;\n return !this._lastFrameOnceTrigger.hasOwnProperty(triggerId);\n }\n\n getNetworkSyncData(): OnceTriggersSyncData {\n return {\n onceTriggers: this._onceTriggers,\n lastFrameOnceTriggers: this._lastFrameOnceTrigger,\n };\n }\n\n updateNetworkSyncData(data: OnceTriggersSyncData): void {\n this._onceTriggers = data.onceTriggers;\n this._lastFrameOnceTrigger = data.lastFrameOnceTriggers;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAUS,OAAmB,CAAnB,aAfT,CAgBI,mBAA0C,GAC1C,2BAAkD,GAMlD,eAAsB,CAEpB,SAAW,KAAK,MAAK,sBACnB,AAAI,KAAK,sBAAsB,eAAe,IAC5C,MAAO,MAAK,sBAAsB,GAGtC,SAAW,KAAK,MAAK,cACnB,AAAI,KAAK,cAAc,eAAe,IACpC,MAAK,sBAAsB,GAAK,KAAK,cAAc,GACnD,MAAO,MAAK,cAAc,IAUhC,YAAY,EAA6B,CACvC,YAAK,cAAc,GAAa,GACzB,CAAC,KAAK,sBAAsB,eAAe,GAGpD,oBAA2C,CACzC,MAAO,CACL,aAAc,KAAK,cACnB,sBAAuB,KAAK,uBAIhC,sBAAsB,EAAkC,CACtD,KAAK,cAAgB,EAAK,aAC1B,KAAK,sBAAwB,EAAK,uBA1C/B,EAAM,iBAVL",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(i){class n{constructor(
|
|
1
|
+
var gdjs;(function(i){class n{constructor(t){this.minX=0;this.minY=0;this.maxX=0;this.maxY=0;this.behavior=t,this.updateAABBFromOwner()}updateAABBFromOwner(){this.minX=this.behavior.owner.getAABB().min[0],this.minY=this.behavior.owner.getAABB().min[1],this.maxX=this.behavior.owner.getAABB().max[0],this.maxY=this.behavior.owner.getAABB().max[1]}}i.BehaviorRBushAABB=n;class o{constructor(t,e,r){this.owner=r;this._activated=!0;this._syncOverNetwork=!0;this.name=e.name||"",this.type=e.type||"",this._nameId=i.RuntimeObject.getNameIdentifier(this.name)}updateFromBehaviorData(t,e){return!1}getNetworkSyncData(t){return{act:this._activated,props:{}}}updateFromNetworkSyncData(t,e){t.act!==this._activated&&this.activate(t.act)}getName(){return this.name}getNameId(){return this._nameId}stepPreEvents(t){if(this._activated){const e=t.getScene().getProfiler();e&&e.begin(this.name),this.doStepPreEvents(t),e&&e.end(this.name)}}stepPostEvents(t){if(this._activated){const e=t.getScene().getProfiler();e&&e.begin(this.name),this.doStepPostEvents(t),e&&e.end(this.name)}}activate(t){t===void 0&&(t=!0),!this._activated&&t?(this._activated=!0,this.onActivate()):this._activated&&!t&&(this._activated=!1,this.onDeActivate())}onCreated(){}activated(){return this._activated}onActivate(){}onDeActivate(){}doStepPreEvents(t){}doStepPostEvents(t){}onDestroy(){}onObjectHotReloaded(){}usesLifecycleFunction(){return!0}enableSynchronization(t){this._syncOverNetwork=t}isSyncedOverNetwork(){return this._syncOverNetwork}}i.RuntimeBehavior=o,i.registerBehavior("",i.RuntimeBehavior)})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=runtimebehavior.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/runtimebehavior.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 * Allow to store a behavior in a RBush (spatial data structure).\n * Because this duplicates the AABB, this ensures the RBush AABB\n * stays the same even if the underlying object is moved\n * (in which case the behavior is responsible for removing/adding\n * back/updating this BehaviorRBushAABB).\n */\n export class BehaviorRBushAABB<T extends RuntimeBehavior> {\n minX: float = 0;\n minY: float = 0;\n maxX: float = 0;\n maxY: float = 0;\n behavior: T;\n\n constructor(behavior: T) {\n this.behavior = behavior;\n this.updateAABBFromOwner();\n }\n\n updateAABBFromOwner() {\n this.minX = this.behavior.owner.getAABB().min[0];\n this.minY = this.behavior.owner.getAABB().min[1];\n this.maxX = this.behavior.owner.getAABB().max[0];\n this.maxY = this.behavior.owner.getAABB().max[1];\n }\n }\n\n /**\n * RuntimeBehavior represents a behavior being used by a RuntimeObject.\n */\n export class RuntimeBehavior {\n name: string;\n type: string;\n _nameId: integer;\n _activated: boolean = true;\n\n // When synchronised over the network, a behavior is always owned by the player owning the object,\n // and always synced. If set to false, the behavior properties will not be synced to others.\n _syncOverNetwork: boolean = true;\n\n /**\n * @param instanceContainer The container owning the object of the behavior\n * @param behaviorData The properties used to setup the behavior\n * @param owner The object owning the behavior\n */\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n behaviorData: BehaviorData,\n public owner: gdjs.RuntimeObject\n ) {\n this.name = behaviorData.name || '';\n this.type = behaviorData.type || '';\n this._nameId = gdjs.RuntimeObject.getNameIdentifier(this.name);\n }\n\n /**\n * Called when the behavior must be updated using the specified behaviorData. This is the\n * case during hot-reload, and is only called if the behavior was modified.\n *\n * @see gdjs.RuntimeBehavior#onObjectHotReloaded\n *\n * @param oldBehaviorData The previous data for the behavior.\n * @param newBehaviorData The new data for the behavior.\n * @returns true if the behavior was updated, false if it could not (i.e: hot-reload is not supported).\n */\n updateFromBehaviorData(\n oldBehaviorData: BehaviorData,\n newBehaviorData: BehaviorData\n ): boolean {\n // If not redefined, mark by default the hot-reload as failed.\n return false;\n }\n\n getNetworkSyncData(): BehaviorNetworkSyncData {\n // To be redefined by behaviors that need to synchronize properties\n // while calling super() to get the common properties.\n return {\n act: this._activated,\n props: {},\n };\n }\n\n /**\n * Update the behavior properties using the provided data.\n * @param networkSyncData The new properties of the behavior.\n */\n updateFromNetworkSyncData(networkSyncData: BehaviorNetworkSyncData): void {\n // Must be redefined by behaviors that need to synchronize properties\n // while calling super() to get the common properties.\n if (networkSyncData.act !== this._activated) {\n this.activate(networkSyncData.act);\n }\n }\n\n /**\n * Get the name of the behavior.\n * @return The behavior's name.\n */\n getName(): string {\n return this.name;\n }\n\n /**\n * Get the name identifier of the behavior.\n * @return The behavior's name identifier.\n */\n getNameId(): integer {\n return this._nameId;\n }\n\n /**\n * Called at each frame before events. Call doStepPreEvents.<br>\n * Behaviors writers: Please do not redefine this method. Redefine doStepPreEvents instead.\n * @param instanceContainer The instanceContainer owning the object\n */\n stepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._activated) {\n const profiler = instanceContainer.getScene().getProfiler();\n if (profiler) {\n profiler.begin(this.name);\n }\n this.doStepPreEvents(instanceContainer);\n if (profiler) {\n profiler.end(this.name);\n }\n }\n }\n\n /**\n * Called at each frame after events. Call doStepPostEvents.<br>\n * Behaviors writers: Please do not redefine this method. Redefine doStepPreEvents instead.\n * @param instanceContainer The instanceContainer owning the object\n */\n stepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._activated) {\n const profiler = instanceContainer.getScene().getProfiler();\n if (profiler) {\n profiler.begin(this.name);\n }\n this.doStepPostEvents(instanceContainer);\n if (profiler) {\n profiler.end(this.name);\n }\n }\n }\n\n /**\n * De/Activate the behavior\n * @param enable true to enable the behavior, false to disable it\n */\n activate(enable: boolean): void {\n if (enable === undefined) {\n enable = true;\n }\n if (!this._activated && enable) {\n this._activated = true;\n this.onActivate();\n } else {\n if (this._activated && !enable) {\n this._activated = false;\n this.onDeActivate();\n }\n }\n }\n\n /**\n * Reimplement this to do extra work when the behavior is created (i.e: an\n * object using it was created), after the object is fully initialized (so\n * you can use `this.owner` without risk).\n */\n onCreated(): void {}\n\n /**\n * Return true if the behavior is activated\n */\n activated(): boolean {\n return this._activated;\n }\n\n /**\n * Reimplement this method to do extra work when the behavior is activated (after\n * it has been deactivated, see `onDeActivate`).\n */\n onActivate(): void {}\n\n /**\n * Reimplement this method to do extra work when the behavior is deactivated.\n */\n onDeActivate(): void {}\n\n /**\n * This method is called each tick before events are done.\n * @param instanceContainer The instanceContainer owning the object\n */\n doStepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {}\n\n /**\n * This method is called each tick after events are done.\n * @param instanceContainer The instanceContainer owning the object\n */\n doStepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {}\n\n /**\n * This method is called when the owner of the behavior\n * is being removed from the scene and is about to be destroyed/reused later\n * or when the behavior is removed from an object (can happen in case of\n * hot-reloading only. Otherwise, behaviors are just de-activated,\n * not removed. See `onDeActivate`).\n */\n onDestroy(): void {}\n\n /**\n * This method is called when the owner of the behavior\n * was hot reloaded, so its position, angle, size can have been changed outside\n * of events.\n */\n onObjectHotReloaded(): void {}\n\n /**\n * Should return `false` if the behavior does not need any lifecycle function to\n * be called.\n * Default, hidden, \"capability\" behaviors set it to `false`.\n * This avoids useless calls to empty lifecycle functions, which would waste CPU\n * time (and have a sizeable impact for example when lots of static instances\n * are living in the scene).\n * @returns\n */\n usesLifecycleFunction(): boolean {\n return true;\n }\n\n enableSynchronization(enable: boolean) {\n this._syncOverNetwork = enable;\n }\n\n isSyncedOverNetwork(): boolean {\n return this._syncOverNetwork;\n }\n }\n gdjs.registerBehavior('', gdjs.RuntimeBehavior);\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAQS,OAAmD,CAOxD,YAAY,EAAa,CANzB,UAAc,EACd,UAAc,EACd,UAAc,EACd,UAAc,EAIZ,KAAK,SAAW,EAChB,KAAK,sBAGP,qBAAsB,CACpB,KAAK,KAAO,KAAK,SAAS,MAAM,UAAU,IAAI,GAC9C,KAAK,KAAO,KAAK,SAAS,MAAM,UAAU,IAAI,GAC9C,KAAK,KAAO,KAAK,SAAS,MAAM,UAAU,IAAI,GAC9C,KAAK,KAAO,KAAK,SAAS,MAAM,UAAU,IAAI,IAhB3C,EAAM,oBAuBN,OAAsB,CAe3B,YACE,EACA,EACO,EACP,CADO,aAdT,gBAAsB,GAItB,sBAA4B,GAY1B,KAAK,KAAO,EAAa,MAAQ,GACjC,KAAK,KAAO,EAAa,MAAQ,GACjC,KAAK,QAAU,EAAK,cAAc,kBAAkB,KAAK,MAa3D,uBACE,EACA,EACS,CAET,MAAO,GAGT,
|
|
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 * Allow to store a behavior in a RBush (spatial data structure).\n * Because this duplicates the AABB, this ensures the RBush AABB\n * stays the same even if the underlying object is moved\n * (in which case the behavior is responsible for removing/adding\n * back/updating this BehaviorRBushAABB).\n */\n export class BehaviorRBushAABB<T extends RuntimeBehavior> {\n minX: float = 0;\n minY: float = 0;\n maxX: float = 0;\n maxY: float = 0;\n behavior: T;\n\n constructor(behavior: T) {\n this.behavior = behavior;\n this.updateAABBFromOwner();\n }\n\n updateAABBFromOwner() {\n this.minX = this.behavior.owner.getAABB().min[0];\n this.minY = this.behavior.owner.getAABB().min[1];\n this.maxX = this.behavior.owner.getAABB().max[0];\n this.maxY = this.behavior.owner.getAABB().max[1];\n }\n }\n\n /**\n * RuntimeBehavior represents a behavior being used by a RuntimeObject.\n */\n export class RuntimeBehavior {\n name: string;\n type: string;\n _nameId: integer;\n _activated: boolean = true;\n\n // When synchronised over the network, a behavior is always owned by the player owning the object,\n // and always synced. If set to false, the behavior properties will not be synced to others.\n _syncOverNetwork: boolean = true;\n\n /**\n * @param instanceContainer The container owning the object of the behavior\n * @param behaviorData The properties used to setup the behavior\n * @param owner The object owning the behavior\n */\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n behaviorData: BehaviorData,\n public owner: gdjs.RuntimeObject\n ) {\n this.name = behaviorData.name || '';\n this.type = behaviorData.type || '';\n this._nameId = gdjs.RuntimeObject.getNameIdentifier(this.name);\n }\n\n /**\n * Called when the behavior must be updated using the specified behaviorData. This is the\n * case during hot-reload, and is only called if the behavior was modified.\n *\n * @see gdjs.RuntimeBehavior#onObjectHotReloaded\n *\n * @param oldBehaviorData The previous data for the behavior.\n * @param newBehaviorData The new data for the behavior.\n * @returns true if the behavior was updated, false if it could not (i.e: hot-reload is not supported).\n */\n updateFromBehaviorData(\n oldBehaviorData: BehaviorData,\n newBehaviorData: BehaviorData\n ): boolean {\n // If not redefined, mark by default the hot-reload as failed.\n return false;\n }\n\n getNetworkSyncData(\n syncOptions: GetNetworkSyncDataOptions\n ): BehaviorNetworkSyncData {\n // To be redefined by behaviors that need to synchronize properties\n // while calling super() to get the common properties.\n return {\n act: this._activated,\n props: {},\n };\n }\n\n /**\n * Update the behavior properties using the provided data.\n * @param networkSyncData The new properties of the behavior.\n */\n updateFromNetworkSyncData(\n networkSyncData: BehaviorNetworkSyncData,\n options: UpdateFromNetworkSyncDataOptions\n ): void {\n // Must be redefined by behaviors that need to synchronize properties\n // while calling super() to get the common properties.\n if (networkSyncData.act !== this._activated) {\n this.activate(networkSyncData.act);\n }\n }\n\n /**\n * Get the name of the behavior.\n * @return The behavior's name.\n */\n getName(): string {\n return this.name;\n }\n\n /**\n * Get the name identifier of the behavior.\n * @return The behavior's name identifier.\n */\n getNameId(): integer {\n return this._nameId;\n }\n\n /**\n * Called at each frame before events. Call doStepPreEvents.<br>\n * Behaviors writers: Please do not redefine this method. Redefine doStepPreEvents instead.\n * @param instanceContainer The instanceContainer owning the object\n */\n stepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._activated) {\n const profiler = instanceContainer.getScene().getProfiler();\n if (profiler) {\n profiler.begin(this.name);\n }\n this.doStepPreEvents(instanceContainer);\n if (profiler) {\n profiler.end(this.name);\n }\n }\n }\n\n /**\n * Called at each frame after events. Call doStepPostEvents.<br>\n * Behaviors writers: Please do not redefine this method. Redefine doStepPreEvents instead.\n * @param instanceContainer The instanceContainer owning the object\n */\n stepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._activated) {\n const profiler = instanceContainer.getScene().getProfiler();\n if (profiler) {\n profiler.begin(this.name);\n }\n this.doStepPostEvents(instanceContainer);\n if (profiler) {\n profiler.end(this.name);\n }\n }\n }\n\n /**\n * De/Activate the behavior\n * @param enable true to enable the behavior, false to disable it\n */\n activate(enable: boolean): void {\n if (enable === undefined) {\n enable = true;\n }\n if (!this._activated && enable) {\n this._activated = true;\n this.onActivate();\n } else {\n if (this._activated && !enable) {\n this._activated = false;\n this.onDeActivate();\n }\n }\n }\n\n /**\n * Reimplement this to do extra work when the behavior is created (i.e: an\n * object using it was created), after the object is fully initialized (so\n * you can use `this.owner` without risk).\n */\n onCreated(): void {}\n\n /**\n * Return true if the behavior is activated\n */\n activated(): boolean {\n return this._activated;\n }\n\n /**\n * Reimplement this method to do extra work when the behavior is activated (after\n * it has been deactivated, see `onDeActivate`).\n */\n onActivate(): void {}\n\n /**\n * Reimplement this method to do extra work when the behavior is deactivated.\n */\n onDeActivate(): void {}\n\n /**\n * This method is called each tick before events are done.\n * @param instanceContainer The instanceContainer owning the object\n */\n doStepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {}\n\n /**\n * This method is called each tick after events are done.\n * @param instanceContainer The instanceContainer owning the object\n */\n doStepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer): void {}\n\n /**\n * This method is called when the owner of the behavior\n * is being removed from the scene and is about to be destroyed/reused later\n * or when the behavior is removed from an object (can happen in case of\n * hot-reloading only. Otherwise, behaviors are just de-activated,\n * not removed. See `onDeActivate`).\n */\n onDestroy(): void {}\n\n /**\n * This method is called when the owner of the behavior\n * was hot reloaded, so its position, angle, size can have been changed outside\n * of events.\n */\n onObjectHotReloaded(): void {}\n\n /**\n * Should return `false` if the behavior does not need any lifecycle function to\n * be called.\n * Default, hidden, \"capability\" behaviors set it to `false`.\n * This avoids useless calls to empty lifecycle functions, which would waste CPU\n * time (and have a sizeable impact for example when lots of static instances\n * are living in the scene).\n * @returns\n */\n usesLifecycleFunction(): boolean {\n return true;\n }\n\n enableSynchronization(enable: boolean) {\n this._syncOverNetwork = enable;\n }\n\n isSyncedOverNetwork(): boolean {\n return this._syncOverNetwork;\n }\n }\n gdjs.registerBehavior('', gdjs.RuntimeBehavior);\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAQS,OAAmD,CAOxD,YAAY,EAAa,CANzB,UAAc,EACd,UAAc,EACd,UAAc,EACd,UAAc,EAIZ,KAAK,SAAW,EAChB,KAAK,sBAGP,qBAAsB,CACpB,KAAK,KAAO,KAAK,SAAS,MAAM,UAAU,IAAI,GAC9C,KAAK,KAAO,KAAK,SAAS,MAAM,UAAU,IAA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K,iBAAmB,EAG1B,qBAA+B,CAC7B,MAAO,MAAK,kBAnNT,EAAM,kBAsNb,EAAK,iBAAiB,GAAI,EAAK,mBArPvB",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(n){const g=new n.Logger("Game manager"),c=u=>new Promise(e=>setTimeout(e,u)),h=u=>u.usedResources.map(e=>e.name);let l=null;const p=()=>{if(l)return l;l=[];try{new CompressionStream("gzip"),l.push("cs:gzip")}catch{}try{new CompressionStream("deflate"),l.push("cs:deflate")}catch{}return l};class _{constructor(e,t){this._sceneAndExtensionsData=[];this._notifyScenesForGameResolutionResize=!1;this._paused=!1;this._hasJustResumed=!1;this._sessionMetricsInitialized=!1;this._disableMetrics=!1;this._wasDisposed=!1;this.getPlatformInfo=()=>({isCordova:!!window.cordova,devicePlatform:typeof device!="undefined"&&device.platform||"",navigatorPlatform:typeof navigator!="undefined"?navigator.platform:"",hasTouch:typeof navigator!="undefined"?!!navigator.maxTouchPoints&&navigator.maxTouchPoints>2:!1,supportedCompressionMethods:p()});this._options=t||{},this._variables=new n.VariablesContainer(e.variables),this._variablesByExtensionName=new Map;for(const s of e.eventsFunctionsExtensions)s.globalVariables.length>0&&this._variablesByExtensionName.set(s.name,new n.VariablesContainer(s.globalVariables));this._eventsBasedObjectDatas=new Map,this._data=e,this._updateSceneAndExtensionsData(),this._sceneResourcesPreloading=this._data.properties.sceneResourcesPreloading||"at-startup",this._sceneResourcesUnloading=this._data.properties.sceneResourcesUnloading||"never",this._resourcesLoader=new n.ResourceLoader(this,e.resources.resources,h(e),e.layouts),this._effectsManager=new n.EffectsManager,this._maxFPS=this._data.properties.maxFPS,this._minFPS=this._data.properties.minFPS,this._gameResolutionWidth=this._data.properties.windowWidth,this._gameResolutionHeight=this._data.properties.windowHeight,this._originalWidth=this._gameResolutionWidth,this._originalHeight=this._gameResolutionHeight,this._resizeMode=this._data.properties.sizeOnStartupMode,this._adaptGameResolutionAtRuntime=this._data.properties.adaptGameResolutionAtRuntime,this._scaleMode=e.properties.scaleMode||"linear",this._pixelsRounding=this._data.properties.pixelsRounding,this._antialiasingMode=this._data.properties.antialiasingMode,this._isAntialisingEnabledOnMobile=this._data.properties.antialisingEnabledOnMobile,this._renderer=new n.RuntimeGameRenderer(this,this._options.forceFullscreen||!1),this._watermark=new n.watermark.RuntimeWatermark(this,e.properties.authorUsernames,this._data.properties.watermark),this._sceneStack=new n.SceneStack(this),this._inputManager=new n.InputManager,this._injectExternalLayout=this._options.injectExternalLayout||"",this._debuggerClient=n.DebuggerClient?new n.DebuggerClient(this):null,this._captureManager=n.CaptureManager?new n.CaptureManager(this._renderer,this._options.captureOptions||{}):null,this._isPreview=this._options.isPreview||!1,this._sessionId=null,this._playerId=null,this._embeddedResourcesMappings=new Map;for(const s of this._data.resources.resources)if(s.metadata)try{const i=JSON.parse(s.metadata);i?.embeddedResourcesMapping&&this._embeddedResourcesMappings.set(s.name,i.embeddedResourcesMapping)}catch{g.error("Some metadata of resources can not be successfully parsed.")}this.isUsingGDevelopDevelopmentEnvironment()&&g.info("This game will run on the development version of GDevelop APIs.")}setProjectData(e){this._data=e,this._updateSceneAndExtensionsData(),this._resourcesLoader.setResources(e.resources.resources,h(e),e.layouts)}_updateSceneAndExtensionsData(){const e=this._data.eventsFunctionsExtensions.filter(t=>t.sceneVariables.length>0);if(this._sceneAndExtensionsData=this._data.layouts.map(t=>({sceneData:t,usedExtensionsWithVariablesData:e})),this._eventsBasedObjectDatas.clear(),this._data.eventsFunctionsExtensions)for(const t of this._data.eventsFunctionsExtensions)for(const s of t.eventsBasedObjects)this._eventsBasedObjectDatas.set(t.name+"::"+s.name,s)}getAdditionalOptions(){return this._options}getRenderer(){return this._renderer}getVariables(){return this._variables}getVariablesForExtension(e){return this._variablesByExtensionName.get(e)||null}getResourceLoader(){return this._resourcesLoader}getSoundManager(){return this._resourcesLoader.getSoundManager()}getImageManager(){return this._resourcesLoader.getImageManager()}getFontManager(){return this._resourcesLoader.getFontManager()}getBitmapFontManager(){return this._resourcesLoader.getBitmapFontManager()}getJsonManager(){return this._resourcesLoader.getJsonManager()}getModel3DManager(){return this._resourcesLoader.getModel3DManager()}getSpineManager(){return this._resourcesLoader.getSpineManager()}getSpineAtlasManager(){return this._resourcesLoader.getSpineAtlasManager()}getInputManager(){return this._inputManager}getEffectsManager(){return this._effectsManager}getGameData(){return this._data}getEventsBasedObjectData(e){const t=this._eventsBasedObjectDatas.get(e);return t||(g.error('The game has no events-based object of the type "'+e+'"'),null)}getSceneAndExtensionsData(e){for(let t=0,s=this._sceneAndExtensionsData.length;t<s;++t){const i=this._sceneAndExtensionsData[t];if(e===void 0||i.sceneData.name===e)return i}return g.error('The game has no scene called "'+e+'"'),null}hasScene(e){for(let t=0,s=this._data.layouts.length;t<s;++t){const i=this._data.layouts[t];if(e===void 0||i.name==e)return!0}return!1}getExternalLayoutData(e){let t=null;for(let s=0,i=this._data.externalLayouts.length;s<i;++s){const r=this._data.externalLayouts[s];if(r.name===e){t=r;break}}return t}getInitialObjectsData(){return this._data.objects||[]}getOriginalWidth(){return this._originalWidth}getOriginalHeight(){return this._originalHeight}getGameResolutionWidth(){return this._gameResolutionWidth}getGameResolutionHeight(){return this._gameResolutionHeight}setGameResolutionSize(e,t){if(this._throwIfDisposed(),this._gameResolutionWidth=e,this._gameResolutionHeight=t,this._adaptGameResolutionAtRuntime&&n.RuntimeGameRenderer&&n.RuntimeGameRenderer.getWindowInnerWidth&&n.RuntimeGameRenderer.getWindowInnerHeight){const s=n.RuntimeGameRenderer.getWindowInnerWidth(),i=n.RuntimeGameRenderer.getWindowInnerHeight();if(this._resizeMode==="adaptWidth")this._gameResolutionWidth=this._gameResolutionHeight*s/i;else if(this._resizeMode==="adaptHeight")this._gameResolutionHeight=this._gameResolutionWidth*i/s;else if(this._resizeMode==="scaleOuter"){const r=s/this._originalWidth,o=i/this._originalHeight;r<o?(this._gameResolutionWidth=this._originalWidth,this._gameResolutionHeight=Math.floor(i/r)):(this._gameResolutionWidth=Math.floor(s/o),this._gameResolutionHeight=this._originalHeight)}}this._renderer.updateRendererSize(),this._notifyScenesForGameResolutionResize=!0}setGameResolutionResizeMode(e){this._resizeMode=e,this._forceGameResolutionUpdate()}getGameResolutionResizeMode(){return this._resizeMode}setAdaptGameResolutionAtRuntime(e){this._adaptGameResolutionAtRuntime=e,this._forceGameResolutionUpdate()}getAdaptGameResolutionAtRuntime(){return this._adaptGameResolutionAtRuntime}getMinimalFramerate(){return this._minFPS}getScaleMode(){return this._scaleMode}getPixelsRounding(){return this._pixelsRounding}getAntialiasingMode(){return this._antialiasingMode}isAntialisingEnabledOnMobile(){return this._isAntialisingEnabledOnMobile}pause(e){this._paused!==e&&(this._paused=e,this._debuggerClient&&(this._paused?this._debuggerClient.sendGamePaused():this._debuggerClient.sendGameResumed()))}hasJustResumed(){return this._hasJustResumed}prioritizeLoadingOfScene(e){this._resourcesLoader.loadSceneResources(e)}getSceneLoadingProgress(e){return this._resourcesLoader.getSceneLoadingProgress(e)}areSceneAssetsLoaded(e){return this._resourcesLoader.areSceneAssetsLoaded(e)}areSceneAssetsReady(e){return this._resourcesLoader.areSceneAssetsReady(e)}getSceneResourcesPreloading(){return this._sceneResourcesPreloading}getSceneResourcesUnloading(){return this._sceneResourcesUnloading}loadAllAssets(e,t){this._throwIfDisposed(),this.loadFirstAssetsAndStartBackgroundLoading(this._getFirstSceneName(),t).then(e)}async loadFirstAssetsAndStartBackgroundLoading(e,t){try{const s=this._data.properties.loadingScreen.backgroundImageResourceName;s&&await this._resourcesLoader.getImageManager().loadResource(s),await Promise.all([this._loadAssetsWithLoadingScreen(!0,async i=>{await this._resourcesLoader.loadGlobalAndFirstSceneResources(e,i),this._resourcesLoader.loadAllSceneInBackground()},t),n.getAllAsynchronouslyLoadingLibraryPromise()])}catch(s){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(s),s}}async loadSceneAssets(e,t){await this._loadAssetsWithLoadingScreen(!1,async s=>{await this._resourcesLoader.loadAndProcessSceneResources(e,s)},t)}async _loadAssetsWithLoadingScreen(e,t,s){this.pause(!0);const i=new n.LoadingScreenRenderer(this.getRenderer(),this._resourcesLoader.getImageManager(),this._data.properties.loadingScreen,this._data.properties.watermark.showWatermark,e);await t(async(o,a)=>{const d=Math.floor(100*o/a);i.setPercent(d),s&&s(d),i.renderIfNeeded()&&await c(1)}),await i.unload(),this.pause(!1)}_getFirstSceneName(){const e=this._data.firstLayout;return this.hasScene(e)?e:this.getSceneAndExtensionsData().sceneData.name}startGameLoop(){this._throwIfDisposed();try{if(!this.hasScene()){g.error("The game has no scene.");return}this._forceGameResolutionUpdate(),this._sceneStack.push(this._getFirstSceneName(),this._injectExternalLayout),this._watermark.displayAtStartup(),this._setupGameVisibilityEvents(),n.inAppTutorialMessage&&n.inAppTutorialMessage.displayInAppTutorialMessage(this,this._options.inAppTutorialMessageInPreview,this._options.inAppTutorialMessagePositionInPreview||"");let e=0;this._hasJustResumed=!1,this._renderer.startGameLoop(t=>{try{if(this._paused||(e+=t,this._maxFPS>0&&1e3/e>this._maxFPS+7))return!0;const s=e;return e=0,this._notifyScenesForGameResolutionResize&&(this._sceneStack.onGameResolutionResized(),this._notifyScenesForGameResolutionResize=!1),this._sceneStack.step(s)?(this.getInputManager().onFrameEnded(),this._hasJustResumed=!1,!0):!1}catch(s){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(s),s}}),setTimeout(()=>{this._setupSessionMetrics()},4e3),this._captureManager&&this._captureManager.setupCaptureOptions(this._isPreview)}catch(e){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(e),e}}dispose(e){this._renderer.stopGameLoop(),this._sceneStack.dispose(),this._renderer.dispose(e),this._resourcesLoader.dispose(),this._wasDisposed=!0}enableMetrics(e){this._disableMetrics=!e,e&&this._setupSessionMetrics()}_setupGameVisibilityEvents(){typeof navigator!="undefined"&&typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&(this._hasJustResumed=!0)}),window.addEventListener("resume",()=>{this._hasJustResumed=!0},!1))}_setupSessionMetrics(){if(this._sessionMetricsInitialized||this._disableMetrics||this.isPreview()||typeof fetch=="undefined"||!this._data.properties.projectUuid)return;const e="https://api.gdevelop-app.com/analytics";this._playerId=this._makePlayerUuid();let t=0,s=0,i=Date.now();const r=this.getPlatformInfo();fetch(e+"/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({gameId:this._data.properties.projectUuid,playerId:this._playerId,game:{name:this._data.properties.name||"",packageName:this._data.properties.packageName||"",version:this._data.properties.version||"",location:window.location.href},platform:{isCordova:r.isCordova,devicePlatform:r.devicePlatform,navigatorPlatform:r.navigatorPlatform,hasTouch:r.hasTouch}})}).then(a=>{if(!a.ok)throw console.error("Error while creating the session",a),new Error("Error while creating the session");return a}).then(a=>a.text()).then(a=>{this._sessionId=a}).catch(()=>{});const o=()=>{if(!this._sessionId)return;const a=Date.now();if(s+=a-i,i=a,s<5*1e3)return;const d=Math.floor(s/1e3)*1e3;t+=d,s-=d,navigator.sendBeacon(e+"/session-hit",JSON.stringify({gameId:this._data.properties.projectUuid,playerId:this._playerId,sessionId:this._sessionId,duration:Math.floor(t/1e3)}))};if(typeof navigator!="undefined"&&typeof document!="undefined"){document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"?i=Date.now():o()}),window.addEventListener("pagehide",o,!1),window.addEventListener("pause",o,!1),window.addEventListener("resume",()=>{i=Date.now()},!1);const a=typeof safari=="object"&&safari.pushNotification,d=/electron/i.test(navigator.userAgent);(a||d)&&window.addEventListener("beforeunload",()=>{o()})}this._sessionMetricsInitialized=!0,this._sessionId=this._sessionId}_makePlayerUuid(){try{const e="GDJS-internal-player-uuid",t=localStorage.getItem(e);if(t)return t;const s=n.makeUuid();return localStorage.setItem(e,s),s}catch{return n.makeUuid()}}getSessionId(){return this._sessionId}getPlayerId(){return this._playerId}onWindowInnerSizeChanged(){this._forceGameResolutionUpdate()}_forceGameResolutionUpdate(){this.setGameResolutionSize(this._gameResolutionWidth,this._gameResolutionHeight)}startCurrentSceneProfiler(e){this._throwIfDisposed();const t=this._sceneStack.getCurrentScene();return t?(t.startProfiler(e),!0):!1}stopCurrentSceneProfiler(){this._throwIfDisposed();const e=this._sceneStack.getCurrentScene();!e||e.stopProfiler()}wasFirstSceneLoaded(){return this._sceneStack.wasFirstSceneLoaded()}getSceneStack(){return this._sceneStack}isPreview(){return this._isPreview}isUsingGDevelopDevelopmentEnvironment(){return this._options.environment==="dev"}getExtensionProperty(e,t){for(let s of this._data.properties.extensionProperties)if(s.extension===e&&s.property===t)return s.value;return null}resolveEmbeddedResource(e,t){const s=this._embeddedResourcesMappings.get(e);return s&&s[t]?s[t]:t}getEmbeddedResourcesNames(e){return this._embeddedResourcesMappings.has(e)?Object.keys(this._embeddedResourcesMappings.get(e)):[]}getNetworkSyncData(e){const t={var:this._variables.getNetworkSyncData(e),ss:this._sceneStack.getNetworkSyncData(e)||void 0},s={};return this._variablesByExtensionName.forEach((i,r)=>{const o=i.getNetworkSyncData(e);o.length&&(s[r]=o)}),t.extVar=s,(!t.var||t.var.length===0)&&!t.ss&&(!t.extVar||Object.keys(t.extVar).length===0)?null:t}updateFromNetworkSyncData(e){if(this._throwIfDisposed(),e.var&&this._variables.updateFromNetworkSyncData(e.var),e.ss&&this._sceneStack.updateFromNetworkSyncData(e.ss),e.extVar)for(const t in e.extVar){if(!e.extVar.hasOwnProperty(t))continue;const s=e.extVar[t],i=this.getVariablesForExtension(t);i&&i.updateFromNetworkSyncData(s)}}_throwIfDisposed(){if(this._wasDisposed)throw"The RuntimeGame has been disposed and should not be used anymore."}}n.RuntimeGame=_})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(n){const g=new n.Logger("Game manager"),c=u=>new Promise(e=>setTimeout(e,u)),h=u=>u.usedResources.map(e=>e.name);let l=null;const p=()=>{if(l)return l;l=[];try{new CompressionStream("gzip"),l.push("cs:gzip")}catch{}try{new CompressionStream("deflate"),l.push("cs:deflate")}catch{}return l};class _{constructor(e,s){this._sceneAndExtensionsData=[];this._notifyScenesForGameResolutionResize=!1;this._paused=!1;this._hasJustResumed=!1;this._sessionMetricsInitialized=!1;this._disableMetrics=!1;this._wasDisposed=!1;this.getPlatformInfo=()=>({isCordova:!!window.cordova,devicePlatform:typeof device!="undefined"&&device.platform||"",navigatorPlatform:typeof navigator!="undefined"?navigator.platform:"",hasTouch:typeof navigator!="undefined"?!!navigator.maxTouchPoints&&navigator.maxTouchPoints>2:!1,supportedCompressionMethods:p()});this._options=s||{},this._variables=new n.VariablesContainer(e.variables),this._variablesByExtensionName=new Map;for(const t of e.eventsFunctionsExtensions)t.globalVariables.length>0&&this._variablesByExtensionName.set(t.name,new n.VariablesContainer(t.globalVariables));this._eventsBasedObjectDatas=new Map,this._data=e,this._updateSceneAndExtensionsData(),this._sceneResourcesPreloading=this._data.properties.sceneResourcesPreloading||"at-startup",this._sceneResourcesUnloading=this._data.properties.sceneResourcesUnloading||"never",this._resourcesLoader=new n.ResourceLoader(this,e.resources.resources,h(e),e.layouts),this._effectsManager=new n.EffectsManager,this._maxFPS=this._data.properties.maxFPS,this._minFPS=this._data.properties.minFPS,this._gameResolutionWidth=this._data.properties.windowWidth,this._gameResolutionHeight=this._data.properties.windowHeight,this._originalWidth=this._gameResolutionWidth,this._originalHeight=this._gameResolutionHeight,this._resizeMode=this._data.properties.sizeOnStartupMode,this._adaptGameResolutionAtRuntime=this._data.properties.adaptGameResolutionAtRuntime,this._scaleMode=e.properties.scaleMode||"linear",this._pixelsRounding=this._data.properties.pixelsRounding,this._antialiasingMode=this._data.properties.antialiasingMode,this._isAntialisingEnabledOnMobile=this._data.properties.antialisingEnabledOnMobile,this._renderer=new n.RuntimeGameRenderer(this,this._options.forceFullscreen||!1),this._watermark=new n.watermark.RuntimeWatermark(this,e.properties.authorUsernames,this._data.properties.watermark),this._sceneStack=new n.SceneStack(this),this._inputManager=new n.InputManager,this._injectExternalLayout=this._options.injectExternalLayout||"",this._debuggerClient=n.DebuggerClient?new n.DebuggerClient(this):null,this._captureManager=n.CaptureManager?new n.CaptureManager(this._renderer,this._options.captureOptions||{}):null,this._isPreview=this._options.isPreview||!1,this._sessionId=null,this._playerId=null,this._embeddedResourcesMappings=new Map;for(const t of this._data.resources.resources)if(t.metadata)try{const i=JSON.parse(t.metadata);i?.embeddedResourcesMapping&&this._embeddedResourcesMappings.set(t.name,i.embeddedResourcesMapping)}catch{g.error("Some metadata of resources can not be successfully parsed.")}this.isUsingGDevelopDevelopmentEnvironment()&&g.info("This game will run on the development version of GDevelop APIs.")}setProjectData(e){this._data=e,this._updateSceneAndExtensionsData(),this._resourcesLoader.setResources(e.resources.resources,h(e),e.layouts)}_updateSceneAndExtensionsData(){const e=this._data.eventsFunctionsExtensions.filter(s=>s.sceneVariables.length>0);if(this._sceneAndExtensionsData=this._data.layouts.map(s=>({sceneData:s,usedExtensionsWithVariablesData:e})),this._eventsBasedObjectDatas.clear(),this._data.eventsFunctionsExtensions)for(const s of this._data.eventsFunctionsExtensions)for(const t of s.eventsBasedObjects)this._eventsBasedObjectDatas.set(s.name+"::"+t.name,t)}getAdditionalOptions(){return this._options}getRenderer(){return this._renderer}getVariables(){return this._variables}getVariablesForExtension(e){return this._variablesByExtensionName.get(e)||null}getResourceLoader(){return this._resourcesLoader}getSoundManager(){return this._resourcesLoader.getSoundManager()}getImageManager(){return this._resourcesLoader.getImageManager()}getFontManager(){return this._resourcesLoader.getFontManager()}getBitmapFontManager(){return this._resourcesLoader.getBitmapFontManager()}getJsonManager(){return this._resourcesLoader.getJsonManager()}getModel3DManager(){return this._resourcesLoader.getModel3DManager()}getSpineManager(){return this._resourcesLoader.getSpineManager()}getSpineAtlasManager(){return this._resourcesLoader.getSpineAtlasManager()}getInputManager(){return this._inputManager}getEffectsManager(){return this._effectsManager}getGameData(){return this._data}getEventsBasedObjectData(e){const s=this._eventsBasedObjectDatas.get(e);return s||(g.error('The game has no events-based object of the type "'+e+'"'),null)}getSceneAndExtensionsData(e){for(let s=0,t=this._sceneAndExtensionsData.length;s<t;++s){const i=this._sceneAndExtensionsData[s];if(e===void 0||i.sceneData.name===e)return i}return g.error('The game has no scene called "'+e+'"'),null}hasScene(e){for(let s=0,t=this._data.layouts.length;s<t;++s){const i=this._data.layouts[s];if(e===void 0||i.name==e)return!0}return!1}getExternalLayoutData(e){let s=null;for(let t=0,i=this._data.externalLayouts.length;t<i;++t){const a=this._data.externalLayouts[t];if(a.name===e){s=a;break}}return s}getInitialObjectsData(){return this._data.objects||[]}getOriginalWidth(){return this._originalWidth}getOriginalHeight(){return this._originalHeight}getGameResolutionWidth(){return this._gameResolutionWidth}getGameResolutionHeight(){return this._gameResolutionHeight}setGameResolutionSize(e,s){if(this._throwIfDisposed(),this._gameResolutionWidth=e,this._gameResolutionHeight=s,this._adaptGameResolutionAtRuntime&&n.RuntimeGameRenderer&&n.RuntimeGameRenderer.getWindowInnerWidth&&n.RuntimeGameRenderer.getWindowInnerHeight){const t=n.RuntimeGameRenderer.getWindowInnerWidth(),i=n.RuntimeGameRenderer.getWindowInnerHeight();if(this._resizeMode==="adaptWidth")this._gameResolutionWidth=this._gameResolutionHeight*t/i;else if(this._resizeMode==="adaptHeight")this._gameResolutionHeight=this._gameResolutionWidth*i/t;else if(this._resizeMode==="scaleOuter"){const a=t/this._originalWidth,o=i/this._originalHeight;a<o?(this._gameResolutionWidth=this._originalWidth,this._gameResolutionHeight=Math.floor(i/a)):(this._gameResolutionWidth=Math.floor(t/o),this._gameResolutionHeight=this._originalHeight)}}this._renderer.updateRendererSize(),this._notifyScenesForGameResolutionResize=!0}setGameResolutionResizeMode(e){this._resizeMode=e,this._forceGameResolutionUpdate()}getGameResolutionResizeMode(){return this._resizeMode}setAdaptGameResolutionAtRuntime(e){this._adaptGameResolutionAtRuntime=e,this._forceGameResolutionUpdate()}getAdaptGameResolutionAtRuntime(){return this._adaptGameResolutionAtRuntime}getMinimalFramerate(){return this._minFPS}getScaleMode(){return this._scaleMode}getPixelsRounding(){return this._pixelsRounding}getAntialiasingMode(){return this._antialiasingMode}isAntialisingEnabledOnMobile(){return this._isAntialisingEnabledOnMobile}pause(e){this._paused!==e&&(this._paused=e,this._debuggerClient&&(this._paused?this._debuggerClient.sendGamePaused():this._debuggerClient.sendGameResumed()))}hasJustResumed(){return this._hasJustResumed}prioritizeLoadingOfScene(e){this._resourcesLoader.loadSceneResources(e)}getSceneLoadingProgress(e){return this._resourcesLoader.getSceneLoadingProgress(e)}areSceneAssetsLoaded(e){return this._resourcesLoader.areSceneAssetsLoaded(e)}areSceneAssetsReady(e){return this._resourcesLoader.areSceneAssetsReady(e)}getSceneResourcesPreloading(){return this._sceneResourcesPreloading}getSceneResourcesUnloading(){return this._sceneResourcesUnloading}loadAllAssets(e,s){this._throwIfDisposed(),this.loadFirstAssetsAndStartBackgroundLoading(this._getFirstSceneName(),s).then(e)}async loadFirstAssetsAndStartBackgroundLoading(e,s){try{const t=this._data.properties.loadingScreen.backgroundImageResourceName;t&&await this._resourcesLoader.getImageManager().loadResource(t),await Promise.all([this._loadAssetsWithLoadingScreen(!0,async i=>{await this._resourcesLoader.loadGlobalAndFirstSceneResources(e,i),this._resourcesLoader.loadAllSceneInBackground()},s),n.getAllAsynchronouslyLoadingLibraryPromise()])}catch(t){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(t),t}}async loadSceneAssets(e,s){await this._loadAssetsWithLoadingScreen(!1,async t=>{await this._resourcesLoader.loadAndProcessSceneResources(e,t)},s)}async _loadAssetsWithLoadingScreen(e,s,t){this.pause(!0);const i=new n.LoadingScreenRenderer(this.getRenderer(),this._resourcesLoader.getImageManager(),this._data.properties.loadingScreen,this._data.properties.watermark.showWatermark,e);await s(async(o,r)=>{const d=Math.floor(100*o/r);i.setPercent(d),t&&t(d),i.renderIfNeeded()&&await c(1)}),await i.unload(),this.pause(!1)}_getFirstSceneName(){const e=this._data.firstLayout;return this.hasScene(e)?e:this.getSceneAndExtensionsData().sceneData.name}startGameLoop(){this._throwIfDisposed();try{if(!this.hasScene()){g.error("The game has no scene.");return}this._forceGameResolutionUpdate(),this._sceneStack.push(this._getFirstSceneName(),this._injectExternalLayout),this._watermark.displayAtStartup(),this._setupGameVisibilityEvents(),n.inAppTutorialMessage&&n.inAppTutorialMessage.displayInAppTutorialMessage(this,this._options.inAppTutorialMessageInPreview,this._options.inAppTutorialMessagePositionInPreview||"");let e=0;this._hasJustResumed=!1,this._renderer.startGameLoop(s=>{try{if(this._paused||(e+=s,this._maxFPS>0&&1e3/e>this._maxFPS+7))return!0;const t=e;return e=0,this._notifyScenesForGameResolutionResize&&(this._sceneStack.onGameResolutionResized(),this._notifyScenesForGameResolutionResize=!1),this._sceneStack.step(t)?(this.getInputManager().onFrameEnded(),this._hasJustResumed=!1,!0):!1}catch(t){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(t),t}}),setTimeout(()=>{this._setupSessionMetrics()},4e3),this._captureManager&&this._captureManager.setupCaptureOptions(this._isPreview)}catch(e){throw this._debuggerClient&&this._debuggerClient.onUncaughtException(e),e}}dispose(e){this._renderer.stopGameLoop(),this._sceneStack.dispose(),this._renderer.dispose(e),this._resourcesLoader.dispose(),this._wasDisposed=!0}enableMetrics(e){this._disableMetrics=!e,e&&this._setupSessionMetrics()}_setupGameVisibilityEvents(){typeof navigator!="undefined"&&typeof document!="undefined"&&(document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&(this._hasJustResumed=!0)}),window.addEventListener("resume",()=>{this._hasJustResumed=!0},!1))}_setupSessionMetrics(){if(this._sessionMetricsInitialized||this._disableMetrics||this.isPreview()||typeof fetch=="undefined"||!this._data.properties.projectUuid)return;const e="https://api.gdevelop-app.com/analytics";this._playerId=this._makePlayerUuid();let s=0,t=0,i=Date.now();const a=this.getPlatformInfo();fetch(e+"/session",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({gameId:this._data.properties.projectUuid,playerId:this._playerId,game:{name:this._data.properties.name||"",packageName:this._data.properties.packageName||"",version:this._data.properties.version||"",location:window.location.href},platform:{isCordova:a.isCordova,devicePlatform:a.devicePlatform,navigatorPlatform:a.navigatorPlatform,hasTouch:a.hasTouch}})}).then(r=>{if(!r.ok)throw console.error("Error while creating the session",r),new Error("Error while creating the session");return r}).then(r=>r.text()).then(r=>{this._sessionId=r}).catch(()=>{});const o=()=>{if(!this._sessionId)return;const r=Date.now();if(t+=r-i,i=r,t<5*1e3)return;const d=Math.floor(t/1e3)*1e3;s+=d,t-=d,navigator.sendBeacon(e+"/session-hit",JSON.stringify({gameId:this._data.properties.projectUuid,playerId:this._playerId,sessionId:this._sessionId,duration:Math.floor(s/1e3)}))};if(typeof navigator!="undefined"&&typeof document!="undefined"){document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"?i=Date.now():o()}),window.addEventListener("pagehide",o,!1),window.addEventListener("pause",o,!1),window.addEventListener("resume",()=>{i=Date.now()},!1);const r=typeof safari=="object"&&safari.pushNotification,d=/electron/i.test(navigator.userAgent);(r||d)&&window.addEventListener("beforeunload",()=>{o()})}this._sessionMetricsInitialized=!0,this._sessionId=this._sessionId}_makePlayerUuid(){try{const e="GDJS-internal-player-uuid",s=localStorage.getItem(e);if(s)return s;const t=n.makeUuid();return localStorage.setItem(e,t),t}catch{return n.makeUuid()}}getSessionId(){return this._sessionId}getPlayerId(){return this._playerId}onWindowInnerSizeChanged(){this._forceGameResolutionUpdate()}_forceGameResolutionUpdate(){this.setGameResolutionSize(this._gameResolutionWidth,this._gameResolutionHeight)}startCurrentSceneProfiler(e){this._throwIfDisposed();const s=this._sceneStack.getCurrentScene();return s?(s.startProfiler(e),!0):!1}stopCurrentSceneProfiler(){this._throwIfDisposed();const e=this._sceneStack.getCurrentScene();!e||e.stopProfiler()}wasFirstSceneLoaded(){return this._sceneStack.wasFirstSceneLoaded()}getSceneStack(){return this._sceneStack}isPreview(){return this._isPreview}isUsingGDevelopDevelopmentEnvironment(){return this._options.environment==="dev"}getExtensionProperty(e,s){for(let t of this._data.properties.extensionProperties)if(t.extension===e&&t.property===s)return t.value;return null}resolveEmbeddedResource(e,s){const t=this._embeddedResourcesMappings.get(e);return t&&t[s]?t[s]:s}getEmbeddedResourcesNames(e){return this._embeddedResourcesMappings.has(e)?Object.keys(this._embeddedResourcesMappings.get(e)):[]}getNetworkSyncData(e){const s={var:e.syncGameVariables===!1?void 0:this._variables.getNetworkSyncData(e),sm:e.syncSounds?this.getSoundManager().getNetworkSyncData():void 0,ss:this._sceneStack.getNetworkSyncData(e)||void 0};if(e.syncGameVariables!==!1){const t={};this._variablesByExtensionName.forEach((i,a)=>{const o=i.getNetworkSyncData(e);o.length&&(t[a]=o)}),s.extVar=t}return(!s.var||s.var.length===0)&&!s.ss&&(!s.extVar||Object.keys(s.extVar).length===0)?null:s}updateFromNetworkSyncData(e,s){if(this._throwIfDisposed(),e.var&&this._variables.updateFromNetworkSyncData(e.var,s),e.sm&&this.getSoundManager().updateFromNetworkSyncData(e.sm),e.ss&&this._sceneStack.updateFromNetworkSyncData(e.ss),e.extVar)for(const t in e.extVar){if(!e.extVar.hasOwnProperty(t))continue;const i=e.extVar[t],a=this.getVariablesForExtension(t);a&&a.updateFromNetworkSyncData(i,s)}}_throwIfDisposed(){if(this._wasDisposed)throw"The RuntimeGame has been disposed and should not be used anymore."}}n.RuntimeGame=_})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=runtimegame.js.map
|