gdcore-tools 2.0.0-gd-v5.4.217-autobuild → 2.0.0-gd-v5.4.219-autobuild

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js +1 -1
  2. package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js.map +2 -2
  3. package/dist/Runtime/Extensions/3D/JsExtension.js +7 -3
  4. package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js +1 -1
  5. package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js.map +2 -2
  6. package/dist/Runtime/Extensions/DialogueTree/JsExtension.js +44 -32
  7. package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js +2 -2
  8. package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js.map +2 -2
  9. package/dist/Runtime/Extensions/Multiplayer/JsExtension.js +15 -0
  10. package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
  11. package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
  12. package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
  13. package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
  14. package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
  15. package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
  16. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js +1 -1
  17. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js.map +2 -2
  18. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js +1 -1
  19. package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js.map +2 -2
  20. package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
  21. package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js.map +2 -2
  22. package/dist/Runtime/Model3DManager.js +1 -1
  23. package/dist/Runtime/Model3DManager.js.map +2 -2
  24. package/dist/Runtime/ResourceLoader.js +1 -1
  25. package/dist/Runtime/ResourceLoader.js.map +2 -2
  26. package/dist/Runtime/RuntimeLayer.js +1 -1
  27. package/dist/Runtime/RuntimeLayer.js.map +2 -2
  28. package/dist/Runtime/capturemanager.js +2 -0
  29. package/dist/Runtime/capturemanager.js.map +7 -0
  30. package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js +1 -1
  31. package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js.map +2 -2
  32. package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
  33. package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
  34. package/dist/Runtime/jsonmanager.js +1 -1
  35. package/dist/Runtime/jsonmanager.js.map +2 -2
  36. package/dist/Runtime/layer.js +1 -1
  37. package/dist/Runtime/layer.js.map +2 -2
  38. package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js +1 -1
  39. package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js.map +2 -2
  40. package/dist/Runtime/pixi-renderers/pixi-image-manager.js +1 -1
  41. package/dist/Runtime/pixi-renderers/pixi-image-manager.js.map +2 -2
  42. package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js +1 -1
  43. package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js.map +2 -2
  44. package/dist/Runtime/runtimegame.js +1 -1
  45. package/dist/Runtime/runtimegame.js.map +2 -2
  46. package/dist/Runtime/runtimewatermark.js +2 -2
  47. package/dist/Runtime/runtimewatermark.js.map +2 -2
  48. package/dist/Runtime/scenestack.js +1 -1
  49. package/dist/Runtime/scenestack.js.map +2 -2
  50. package/dist/Runtime/spriteruntimeobject.js +1 -1
  51. package/dist/Runtime/spriteruntimeobject.js.map +2 -2
  52. package/dist/Runtime/types/global-types.d.ts +20 -3
  53. package/dist/Runtime/types/project-data.d.ts +1 -1
  54. package/dist/lib/libGD.cjs +1 -1
  55. package/dist/lib/libGD.wasm +0 -0
  56. package/gd.d.ts +35 -7
  57. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- var gdjs;(function(i){let n;(function(a){a[a.TWO_D=0]="TWO_D",a[a.THREE_D=1]="THREE_D",a[a.TWO_D_PLUS_THREE_D=2]="TWO_D_PLUS_THREE_D"})(n=i.RuntimeLayerRenderingType||(i.RuntimeLayerRenderingType={}));const o=r=>r==="3d"?1:r==="2d+3d"||r===""?2:0;let s;(function(t){t[t.PERSPECTIVE=0]="PERSPECTIVE",t[t.ORTHOGRAPHIC=1]="ORTHOGRAPHIC"})(s=i.RuntimeLayerCameraType||(i.RuntimeLayerCameraType={}));const f=r=>r==="orthographic"?1:0;class l{constructor(e,t){this._timeScale=1;this._defaultZOrder=0;this._rendererEffects={};this._name=e.name,this._renderingType=o(e.renderingType),this._cameraType=f(e.cameraType),this._hidden=!e.visibility,this._initialCamera3DFieldOfView=e.camera3DFieldOfView||45,this._initialCamera3DNearPlaneDistance=e.camera3DNearPlaneDistance||.1,this._initialCamera3DFarPlaneDistance=e.camera3DFarPlaneDistance||2e3,this._initialEffectsData=e.effects||[],this._runtimeScene=t,this._effectsManager=t.getGame().getEffectsManager(),this._isLightingLayer=e.isLightingLayer,this._followBaseLayerCamera=e.followBaseLayerCamera,this._clearColor=[e.ambientLightColorR/255,e.ambientLightColorG/255,e.ambientLightColorB/255,1],this._renderer=new i.LayerRenderer(this,t.getRenderer(),t.getGame().getRenderer()),this.show(!this._hidden);for(let a=0;a<e.effects.length;++a)this.addEffect(e.effects[a])}getRenderer(){return this._renderer}getRendererObject(){return this._renderer.getRendererObject()}get3DRendererObject(){return this._renderer.getThreeScene()}getRenderingType(){return this._renderingType}getCameraType(){return this._cameraType}getDefaultZOrder(){return this._defaultZOrder}setDefaultZOrder(e){this._defaultZOrder=e}getRuntimeScene(){return this._runtimeScene.getScene()}updatePreRender(e){this._followBaseLayerCamera&&this.followBaseLayer(),this._renderer.updatePreRender(),this._effectsManager.updatePreRender(this._rendererEffects,this)}getName(){return this._name}show(e){this._hidden=!e,this._renderer.updateVisibility(e)}isVisible(){return!this._hidden}getWidth(){return this._runtimeScene.getViewportWidth()}getHeight(){return this._runtimeScene.getViewportHeight()}getInitialCamera3DFieldOfView(){return this._initialCamera3DFieldOfView}getInitialCamera3DNearPlaneDistance(){return this._initialCamera3DNearPlaneDistance}getInitialCamera3DFarPlaneDistance(){return this._initialCamera3DFarPlaneDistance}getInitialEffectsData(){return this._initialEffectsData}getRendererEffects(){return this._rendererEffects}addEffect(e){this._effectsManager.addEffect(e,this._rendererEffects,this)}removeEffect(e){this._effectsManager.removeEffect(this._rendererEffects,this,e)}setEffectDoubleParameter(e,t,a){this._effectsManager.setEffectDoubleParameter(this._rendererEffects,e,t,a)}setEffectStringParameter(e,t,a){this._effectsManager.setEffectStringParameter(this._rendererEffects,e,t,a)}setEffectBooleanParameter(e,t,a){this._effectsManager.setEffectBooleanParameter(this._rendererEffects,e,t,a)}enableEffect(e,t){this._effectsManager.enableEffect(this._rendererEffects,this,e,t)}isEffectEnabled(e){return this._effectsManager.isEffectEnabled(this._rendererEffects,this,e)}hasEffect(e){return this._effectsManager.hasEffect(this._rendererEffects,e)}setTimeScale(e){e>=0&&(this._timeScale=e)}getTimeScale(){return this._timeScale}getElapsedTime(e){return(e||this._runtimeScene).getElapsedTime()*this._timeScale}followBaseLayer(){const e=this._runtimeScene.getLayer("");this.setCameraX(e.getCameraX()),this.setCameraY(e.getCameraY()),this.setCameraRotation(e.getCameraRotation()),this.setCameraZoom(e.getCameraZoom())}getClearColor(){return this._clearColor}setClearColor(e,t,a){this._clearColor[0]=e/255,this._clearColor[1]=t/255,this._clearColor[2]=a/255,this._renderer.updateClearColor()}setFollowBaseLayerCamera(e){this._followBaseLayerCamera=e}isLightingLayer(){return this._isLightingLayer}}i.RuntimeLayer=l})(gdjs||(gdjs={}));
1
+ var gdjs;(function(i){let n;(function(r){r[r.TWO_D=0]="TWO_D",r[r.THREE_D=1]="THREE_D",r[r.TWO_D_PLUS_THREE_D=2]="TWO_D_PLUS_THREE_D"})(n=i.RuntimeLayerRenderingType||(i.RuntimeLayerRenderingType={}));const f=a=>a==="3d"?1:a==="2d+3d"||a===""?2:0;let s;(function(t){t[t.PERSPECTIVE=0]="PERSPECTIVE",t[t.ORTHOGRAPHIC=1]="ORTHOGRAPHIC"})(s=i.RuntimeLayerCameraType||(i.RuntimeLayerCameraType={}));const l=a=>a==="orthographic"?1:0;let o;(function(t){t[t.DO_NOTHING=0]="DO_NOTHING",t[t.TOP_LEFT_ANCHORED_IF_NEVER_MOVED=1]="TOP_LEFT_ANCHORED_IF_NEVER_MOVED"})(o=i.RuntimeLayerDefaultCameraBehavior||(i.RuntimeLayerDefaultCameraBehavior={}));const c=a=>a==="top-left-anchored-if-never-moved"?1:0;class d{constructor(e,t){this._timeScale=1;this._defaultZOrder=0;this._rendererEffects={};this._name=e.name,this._renderingType=f(e.renderingType),this._cameraType=l(e.cameraType),this._defaultCameraBehavior=c(e.defaultCameraBehavior||"top-left-anchored-if-never-moved"),this._hidden=!e.visibility,this._initialCamera3DFieldOfView=e.camera3DFieldOfView||45,this._initialCamera3DNearPlaneDistance=e.camera3DNearPlaneDistance||.1,this._initialCamera3DFarPlaneDistance=e.camera3DFarPlaneDistance||2e3,this._initialEffectsData=e.effects||[],this._runtimeScene=t,this._effectsManager=t.getGame().getEffectsManager(),this._isLightingLayer=e.isLightingLayer,this._followBaseLayerCamera=e.followBaseLayerCamera,this._clearColor=[e.ambientLightColorR/255,e.ambientLightColorG/255,e.ambientLightColorB/255,1],this._renderer=new i.LayerRenderer(this,t.getRenderer(),t.getGame().getRenderer()),this.show(!this._hidden);for(let r=0;r<e.effects.length;++r)this.addEffect(e.effects[r])}getRenderer(){return this._renderer}getRendererObject(){return this._renderer.getRendererObject()}get3DRendererObject(){return this._renderer.getThreeScene()}getRenderingType(){return this._renderingType}getCameraType(){return this._cameraType}getDefaultZOrder(){return this._defaultZOrder}setDefaultZOrder(e){this._defaultZOrder=e}getRuntimeScene(){return this._runtimeScene.getScene()}updatePreRender(e){this._followBaseLayerCamera&&this.followBaseLayer(),this._renderer.updatePreRender(),this._effectsManager.updatePreRender(this._rendererEffects,this)}getName(){return this._name}show(e){this._hidden=!e,this._renderer.updateVisibility(e)}isVisible(){return!this._hidden}getWidth(){return this._runtimeScene.getViewportWidth()}getHeight(){return this._runtimeScene.getViewportHeight()}getInitialCamera3DFieldOfView(){return this._initialCamera3DFieldOfView}getInitialCamera3DNearPlaneDistance(){return this._initialCamera3DNearPlaneDistance}getInitialCamera3DFarPlaneDistance(){return this._initialCamera3DFarPlaneDistance}getInitialEffectsData(){return this._initialEffectsData}getRendererEffects(){return this._rendererEffects}addEffect(e){this._effectsManager.addEffect(e,this._rendererEffects,this)}removeEffect(e){this._effectsManager.removeEffect(this._rendererEffects,this,e)}setEffectDoubleParameter(e,t,r){this._effectsManager.setEffectDoubleParameter(this._rendererEffects,e,t,r)}setEffectStringParameter(e,t,r){this._effectsManager.setEffectStringParameter(this._rendererEffects,e,t,r)}setEffectBooleanParameter(e,t,r){this._effectsManager.setEffectBooleanParameter(this._rendererEffects,e,t,r)}enableEffect(e,t){this._effectsManager.enableEffect(this._rendererEffects,this,e,t)}isEffectEnabled(e){return this._effectsManager.isEffectEnabled(this._rendererEffects,this,e)}hasEffect(e){return this._effectsManager.hasEffect(this._rendererEffects,e)}setTimeScale(e){e>=0&&(this._timeScale=e)}getTimeScale(){return this._timeScale}getElapsedTime(e){return(e||this._runtimeScene).getElapsedTime()*this._timeScale}followBaseLayer(){const e=this._runtimeScene.getLayer("");this.setCameraX(e.getCameraX()),this.setCameraY(e.getCameraY()),this.setCameraRotation(e.getCameraRotation()),this.setCameraZoom(e.getCameraZoom())}getClearColor(){return this._clearColor}setClearColor(e,t,r){this._clearColor[0]=e/255,this._clearColor[1]=t/255,this._clearColor[2]=r/255,this._renderer.updateClearColor()}setFollowBaseLayerCamera(e){this._followBaseLayerCamera=e}isLightingLayer(){return this._isLightingLayer}}i.RuntimeLayer=d})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=RuntimeLayer.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../GDevelop/GDJS/Runtime/RuntimeLayer.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 enum RuntimeLayerRenderingType {\n TWO_D,\n THREE_D,\n TWO_D_PLUS_THREE_D,\n }\n\n const getRenderingTypeFromString = (\n renderingTypeAsString: string | undefined\n ) =>\n renderingTypeAsString === '3d'\n ? RuntimeLayerRenderingType.THREE_D\n : renderingTypeAsString === '2d+3d' || renderingTypeAsString === ''\n ? RuntimeLayerRenderingType.TWO_D_PLUS_THREE_D\n : RuntimeLayerRenderingType.TWO_D;\n\n export enum RuntimeLayerCameraType {\n PERSPECTIVE,\n ORTHOGRAPHIC,\n }\n\n const getCameraTypeFromString = (renderingTypeAsString: string | undefined) =>\n renderingTypeAsString === 'orthographic'\n ? RuntimeLayerCameraType.ORTHOGRAPHIC\n : RuntimeLayerCameraType.PERSPECTIVE;\n /**\n * Represents a layer of a \"container\", used to display objects.\n * The container can be a scene (see gdjs.Layer)\n * or a custom object (see gdjs.RuntimeCustomObjectLayer).\n */\n export abstract class RuntimeLayer implements EffectsTarget {\n _name: string;\n _renderingType: RuntimeLayerRenderingType;\n _cameraType: RuntimeLayerCameraType;\n _timeScale: float = 1;\n _defaultZOrder: integer = 0;\n _hidden: boolean;\n _initialEffectsData: Array<EffectData>;\n\n // TODO EBO Don't store scene layer related data in layers used by custom objects.\n // (both these 3D settings and the lighting layer properties below).\n _initialCamera3DFieldOfView: float;\n _initialCamera3DFarPlaneDistance: float;\n _initialCamera3DNearPlaneDistance: float;\n\n _runtimeScene: gdjs.RuntimeInstanceContainer;\n _effectsManager: gdjs.EffectsManager;\n\n // Lighting layer properties.\n _isLightingLayer: boolean;\n _followBaseLayerCamera: boolean;\n _clearColor: Array<integer>;\n\n _rendererEffects: Record<string, gdjs.PixiFiltersTools.Filter> = {};\n _renderer: gdjs.LayerRenderer;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._name = layerData.name;\n this._renderingType = getRenderingTypeFromString(layerData.renderingType);\n this._cameraType = getCameraTypeFromString(layerData.cameraType);\n this._hidden = !layerData.visibility;\n this._initialCamera3DFieldOfView = layerData.camera3DFieldOfView || 45;\n this._initialCamera3DNearPlaneDistance =\n layerData.camera3DNearPlaneDistance || 0.1;\n this._initialCamera3DFarPlaneDistance =\n layerData.camera3DFarPlaneDistance || 2000;\n this._initialEffectsData = layerData.effects || [];\n this._runtimeScene = instanceContainer;\n this._effectsManager = instanceContainer.getGame().getEffectsManager();\n this._isLightingLayer = layerData.isLightingLayer;\n this._followBaseLayerCamera = layerData.followBaseLayerCamera;\n this._clearColor = [\n layerData.ambientLightColorR / 255,\n layerData.ambientLightColorG / 255,\n layerData.ambientLightColorB / 255,\n 1.0,\n ];\n this._renderer = new gdjs.LayerRenderer(\n this,\n instanceContainer.getRenderer(),\n instanceContainer.getGame().getRenderer()\n );\n this.show(!this._hidden);\n for (let i = 0; i < layerData.effects.length; ++i) {\n this.addEffect(layerData.effects[i]);\n }\n }\n\n getRenderer(): gdjs.LayerRenderer {\n return this._renderer;\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n get3DRendererObject() {\n return this._renderer.getThreeScene();\n }\n\n getRenderingType(): RuntimeLayerRenderingType {\n return this._renderingType;\n }\n\n getCameraType(): RuntimeLayerCameraType {\n return this._cameraType;\n }\n\n /**\n * Get the default Z order to be attributed to objects created on this layer\n * (usually from events generated code).\n */\n getDefaultZOrder(): float {\n return this._defaultZOrder;\n }\n\n /**\n * Set the default Z order to be attributed to objects created on this layer.\n * @param defaultZOrder The Z order to use when creating a new object from events.\n */\n setDefaultZOrder(defaultZOrder: integer): void {\n this._defaultZOrder = defaultZOrder;\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n abstract onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void;\n\n /**\n * Returns the scene the layer belongs to directly or indirectly\n * @returns the scene the layer belongs to directly or indirectly\n */\n getRuntimeScene(): gdjs.RuntimeScene {\n return this._runtimeScene.getScene();\n }\n\n /**\n * Called at each frame, after events are run and before rendering.\n */\n updatePreRender(instanceContainer?: gdjs.RuntimeInstanceContainer): void {\n if (this._followBaseLayerCamera) {\n this.followBaseLayer();\n }\n this._renderer.updatePreRender();\n this._effectsManager.updatePreRender(this._rendererEffects, this);\n }\n\n /**\n * Get the name of the layer\n * @return The name of the layer\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n abstract getCameraX(cameraId?: integer): float;\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n abstract getCameraY(cameraId?: integer): float;\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraX(x: float, cameraId?: integer): void;\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraY(y: float, cameraId?: integer): void;\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n abstract getCameraWidth(cameraId?: integer): float;\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n abstract getCameraHeight(cameraId?: integer): float;\n\n /**\n * Show (or hide) the layer.\n * @param enable true to show the layer, false to hide it.\n */\n show(enable: boolean): void {\n this._hidden = !enable;\n this._renderer.updateVisibility(enable);\n }\n\n /**\n * Check if the layer is visible.\n *\n * @return true if the layer is visible.\n */\n isVisible(): boolean {\n return !this._hidden;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZoom(newZoom: float, cameraId?: integer): void;\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n abstract getCameraZoom(cameraId?: integer): float;\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZ(z: float, fov: float | null, cameraId?: integer): void;\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n abstract getCameraZ(fov: float | null, cameraId?: integer): float;\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n abstract getCameraRotation(cameraId?: integer): float;\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraRotation(rotation: float, cameraId?: integer): void;\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n abstract applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n abstract applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n getWidth(): float {\n return this._runtimeScene.getViewportWidth();\n }\n\n getHeight(): float {\n return this._runtimeScene.getViewportHeight();\n }\n\n getInitialCamera3DFieldOfView(): float {\n return this._initialCamera3DFieldOfView;\n }\n getInitialCamera3DNearPlaneDistance(): float {\n return this._initialCamera3DNearPlaneDistance;\n }\n getInitialCamera3DFarPlaneDistance(): float {\n return this._initialCamera3DFarPlaneDistance;\n }\n\n /**\n * Return the initial effects data for the layer. Only to\n * be used by renderers.\n * @deprecated\n */\n getInitialEffectsData(): EffectData[] {\n return this._initialEffectsData;\n }\n\n /**\n * Returns the collection of effects to be rendered by the\n * underlying renderer.\n * @returns The renderer effects.\n */\n getRendererEffects() {\n return this._rendererEffects;\n }\n\n /**\n * Add a new effect, or replace the one with the same name.\n * @param effectData The data of the effect to add.\n */\n addEffect(effectData: EffectData): void {\n this._effectsManager.addEffect(effectData, this._rendererEffects, this);\n }\n\n /**\n * Remove the effect with the specified name\n * @param effectName The name of the effect.\n */\n removeEffect(effectName: string): void {\n this._effectsManager.removeEffect(\n this._rendererEffects,\n this,\n effectName\n );\n }\n\n /**\n * Change an effect property value (for properties that are numbers).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (number).\n */\n setEffectDoubleParameter(\n name: string,\n parameterName: string,\n value: float\n ): void {\n this._effectsManager.setEffectDoubleParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are strings).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (string).\n */\n setEffectStringParameter(\n name: string,\n parameterName: string,\n value: string\n ): void {\n this._effectsManager.setEffectStringParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are booleans).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (boolean).\n */\n setEffectBooleanParameter(\n name: string,\n parameterName: string,\n value: boolean\n ): void {\n this._effectsManager.setEffectBooleanParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Enable or disable an effect.\n * @param name The name of the effect to enable or disable.\n * @param enable true to enable, false to disable\n */\n enableEffect(name: string, enable: boolean): void {\n this._effectsManager.enableEffect(\n this._rendererEffects,\n this,\n name,\n enable\n );\n }\n\n /**\n * Check if an effect is enabled\n * @param name The name of the effect\n * @return true if the effect is enabled, false otherwise.\n */\n isEffectEnabled(name: string): boolean {\n return this._effectsManager.isEffectEnabled(\n this._rendererEffects,\n this,\n name\n );\n }\n\n /**\n * Check if an effect exists on this layer\n * @param name The name of the effect\n * @return true if the effect exists, false otherwise.\n */\n hasEffect(name: string): boolean {\n return this._effectsManager.hasEffect(this._rendererEffects, name);\n }\n\n /**\n * Set the time scale for the objects on the layer:\n * time will be slower if time scale is < 1, faster if > 1.\n * @param timeScale The new time scale (must be positive).\n */\n setTimeScale(timeScale: float): void {\n if (timeScale >= 0) {\n this._timeScale = timeScale;\n }\n }\n\n /**\n * Get the time scale for the objects on the layer.\n */\n getTimeScale(): float {\n return this._timeScale;\n }\n\n /**\n * Return the time elapsed since the last frame,\n * in milliseconds, for objects on the layer.\n *\n * @param instanceContainer The instance container the layer belongs to (deprecated - can be omitted).\n */\n getElapsedTime(instanceContainer?: gdjs.RuntimeInstanceContainer): float {\n const container = instanceContainer || this._runtimeScene;\n return container.getElapsedTime() * this._timeScale;\n }\n\n /**\n * Change the position, rotation and scale (zoom) of the layer camera to be the same as the base layer camera.\n */\n followBaseLayer(): void {\n const baseLayer = this._runtimeScene.getLayer('');\n this.setCameraX(baseLayer.getCameraX());\n this.setCameraY(baseLayer.getCameraY());\n this.setCameraRotation(baseLayer.getCameraRotation());\n this.setCameraZoom(baseLayer.getCameraZoom());\n }\n\n /**\n * The clear color is defined in the format [r, g, b], with components in the range of 0 to 1.\n * @return the clear color of layer in the range of [0, 1].\n */\n getClearColor(): Array<integer> {\n return this._clearColor;\n }\n\n /**\n * Set the clear color in format [r, g, b], with components in the range of 0 to 1.;\n * @param r Red color component in the range 0-255.\n * @param g Green color component in the range 0-255.\n * @param b Blue color component in the range 0-255.\n */\n setClearColor(r: integer, g: integer, b: integer): void {\n this._clearColor[0] = r / 255;\n this._clearColor[1] = g / 255;\n this._clearColor[2] = b / 255;\n this._renderer.updateClearColor();\n }\n\n /**\n * Set whether layer's camera follows base layer's camera or not.\n */\n setFollowBaseLayerCamera(follow: boolean): void {\n this._followBaseLayerCamera = follow;\n }\n\n /**\n * Return true if the layer is a lighting layer, false otherwise.\n * @return true if it is a lighting layer, false otherwise.\n */\n isLightingLayer(): boolean {\n return this._isLightingLayer;\n }\n }\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACS,GAAK,GAAL,UAAK,EAAL,CACL,qBACA,yBACA,iDAHU,iEAMZ,KAAM,GAA6B,AACj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Ac,SAAS,IAC9C,KAAK,WAAW,EAAU,cAC1B,KAAK,WAAW,EAAU,cAC1B,KAAK,kBAAkB,EAAU,qBACjC,KAAK,cAAc,EAAU,iBAO/B,eAAgC,CAC9B,MAAO,MAAK,YASd,cAAc,EAAY,EAAY,EAAkB,CACtD,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,UAAU,mBAMjB,yBAAyB,EAAuB,CAC9C,KAAK,uBAAyB,EAOhC,iBAA2B,CACzB,MAAO,MAAK,kBAniBT,EAAe,iBA9Bd",
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 enum RuntimeLayerRenderingType {\n TWO_D,\n THREE_D,\n TWO_D_PLUS_THREE_D,\n }\n\n const getRenderingTypeFromString = (\n renderingTypeAsString: string | undefined\n ) =>\n renderingTypeAsString === '3d'\n ? RuntimeLayerRenderingType.THREE_D\n : renderingTypeAsString === '2d+3d' || renderingTypeAsString === ''\n ? RuntimeLayerRenderingType.TWO_D_PLUS_THREE_D\n : RuntimeLayerRenderingType.TWO_D;\n\n export enum RuntimeLayerCameraType {\n PERSPECTIVE,\n ORTHOGRAPHIC,\n }\n const getCameraTypeFromString = (renderingTypeAsString: string | undefined) =>\n renderingTypeAsString === 'orthographic'\n ? RuntimeLayerCameraType.ORTHOGRAPHIC\n : RuntimeLayerCameraType.PERSPECTIVE;\n\n export enum RuntimeLayerDefaultCameraBehavior {\n DO_NOTHING,\n TOP_LEFT_ANCHORED_IF_NEVER_MOVED,\n }\n\n const getDefaultCameraBehaviorFromString = (\n defaultCameraBehaviorAsString: string\n ) =>\n defaultCameraBehaviorAsString === 'top-left-anchored-if-never-moved'\n ? RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED\n : RuntimeLayerDefaultCameraBehavior.DO_NOTHING;\n\n /**\n * Represents a layer of a \"container\", used to display objects.\n * The container can be a scene (see gdjs.Layer)\n * or a custom object (see gdjs.RuntimeCustomObjectLayer).\n */\n export abstract class RuntimeLayer implements EffectsTarget {\n _name: string;\n _renderingType: RuntimeLayerRenderingType;\n _cameraType: RuntimeLayerCameraType;\n _defaultCameraBehavior: RuntimeLayerDefaultCameraBehavior;\n _timeScale: float = 1;\n _defaultZOrder: integer = 0;\n _hidden: boolean;\n _initialEffectsData: Array<EffectData>;\n\n // TODO EBO Don't store scene layer related data in layers used by custom objects.\n // (both these 3D settings and the lighting layer properties below).\n _initialCamera3DFieldOfView: float;\n _initialCamera3DFarPlaneDistance: float;\n _initialCamera3DNearPlaneDistance: float;\n\n _runtimeScene: gdjs.RuntimeInstanceContainer;\n _effectsManager: gdjs.EffectsManager;\n\n // Lighting layer properties.\n _isLightingLayer: boolean;\n _followBaseLayerCamera: boolean;\n _clearColor: Array<integer>;\n\n _rendererEffects: Record<string, gdjs.PixiFiltersTools.Filter> = {};\n _renderer: gdjs.LayerRenderer;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._name = layerData.name;\n this._renderingType = getRenderingTypeFromString(layerData.renderingType);\n this._cameraType = getCameraTypeFromString(layerData.cameraType);\n this._defaultCameraBehavior = getDefaultCameraBehaviorFromString(\n layerData.defaultCameraBehavior || 'top-left-anchored-if-never-moved'\n );\n this._hidden = !layerData.visibility;\n this._initialCamera3DFieldOfView = layerData.camera3DFieldOfView || 45;\n this._initialCamera3DNearPlaneDistance =\n layerData.camera3DNearPlaneDistance || 0.1;\n this._initialCamera3DFarPlaneDistance =\n layerData.camera3DFarPlaneDistance || 2000;\n this._initialEffectsData = layerData.effects || [];\n this._runtimeScene = instanceContainer;\n this._effectsManager = instanceContainer.getGame().getEffectsManager();\n this._isLightingLayer = layerData.isLightingLayer;\n this._followBaseLayerCamera = layerData.followBaseLayerCamera;\n this._clearColor = [\n layerData.ambientLightColorR / 255,\n layerData.ambientLightColorG / 255,\n layerData.ambientLightColorB / 255,\n 1.0,\n ];\n this._renderer = new gdjs.LayerRenderer(\n this,\n instanceContainer.getRenderer(),\n instanceContainer.getGame().getRenderer()\n );\n this.show(!this._hidden);\n for (let i = 0; i < layerData.effects.length; ++i) {\n this.addEffect(layerData.effects[i]);\n }\n }\n\n getRenderer(): gdjs.LayerRenderer {\n return this._renderer;\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n get3DRendererObject() {\n return this._renderer.getThreeScene();\n }\n\n getRenderingType(): RuntimeLayerRenderingType {\n return this._renderingType;\n }\n\n getCameraType(): RuntimeLayerCameraType {\n return this._cameraType;\n }\n\n /**\n * Get the default Z order to be attributed to objects created on this layer\n * (usually from events generated code).\n */\n getDefaultZOrder(): float {\n return this._defaultZOrder;\n }\n\n /**\n * Set the default Z order to be attributed to objects created on this layer.\n * @param defaultZOrder The Z order to use when creating a new object from events.\n */\n setDefaultZOrder(defaultZOrder: integer): void {\n this._defaultZOrder = defaultZOrder;\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n abstract onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void;\n\n /**\n * Returns the scene the layer belongs to directly or indirectly\n * @returns the scene the layer belongs to directly or indirectly\n */\n getRuntimeScene(): gdjs.RuntimeScene {\n return this._runtimeScene.getScene();\n }\n\n /**\n * Called at each frame, after events are run and before rendering.\n */\n updatePreRender(instanceContainer?: gdjs.RuntimeInstanceContainer): void {\n if (this._followBaseLayerCamera) {\n this.followBaseLayer();\n }\n this._renderer.updatePreRender();\n this._effectsManager.updatePreRender(this._rendererEffects, this);\n }\n\n /**\n * Get the name of the layer\n * @return The name of the layer\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n abstract getCameraX(cameraId?: integer): float;\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n abstract getCameraY(cameraId?: integer): float;\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraX(x: float, cameraId?: integer): void;\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraY(y: float, cameraId?: integer): void;\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n abstract getCameraWidth(cameraId?: integer): float;\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n abstract getCameraHeight(cameraId?: integer): float;\n\n /**\n * Show (or hide) the layer.\n * @param enable true to show the layer, false to hide it.\n */\n show(enable: boolean): void {\n this._hidden = !enable;\n this._renderer.updateVisibility(enable);\n }\n\n /**\n * Check if the layer is visible.\n *\n * @return true if the layer is visible.\n */\n isVisible(): boolean {\n return !this._hidden;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZoom(newZoom: float, cameraId?: integer): void;\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n abstract getCameraZoom(cameraId?: integer): float;\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZ(z: float, fov: float | null, cameraId?: integer): void;\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n abstract getCameraZ(fov: float | null, cameraId?: integer): float;\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n abstract getCameraRotation(cameraId?: integer): float;\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraRotation(rotation: float, cameraId?: integer): void;\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n abstract applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n abstract applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n getWidth(): float {\n return this._runtimeScene.getViewportWidth();\n }\n\n getHeight(): float {\n return this._runtimeScene.getViewportHeight();\n }\n\n getInitialCamera3DFieldOfView(): float {\n return this._initialCamera3DFieldOfView;\n }\n getInitialCamera3DNearPlaneDistance(): float {\n return this._initialCamera3DNearPlaneDistance;\n }\n getInitialCamera3DFarPlaneDistance(): float {\n return this._initialCamera3DFarPlaneDistance;\n }\n\n /**\n * Return the initial effects data for the layer. Only to\n * be used by renderers.\n * @deprecated\n */\n getInitialEffectsData(): EffectData[] {\n return this._initialEffectsData;\n }\n\n /**\n * Returns the collection of effects to be rendered by the\n * underlying renderer.\n * @returns The renderer effects.\n */\n getRendererEffects() {\n return this._rendererEffects;\n }\n\n /**\n * Add a new effect, or replace the one with the same name.\n * @param effectData The data of the effect to add.\n */\n addEffect(effectData: EffectData): void {\n this._effectsManager.addEffect(effectData, this._rendererEffects, this);\n }\n\n /**\n * Remove the effect with the specified name\n * @param effectName The name of the effect.\n */\n removeEffect(effectName: string): void {\n this._effectsManager.removeEffect(\n this._rendererEffects,\n this,\n effectName\n );\n }\n\n /**\n * Change an effect property value (for properties that are numbers).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (number).\n */\n setEffectDoubleParameter(\n name: string,\n parameterName: string,\n value: float\n ): void {\n this._effectsManager.setEffectDoubleParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are strings).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (string).\n */\n setEffectStringParameter(\n name: string,\n parameterName: string,\n value: string\n ): void {\n this._effectsManager.setEffectStringParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are booleans).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (boolean).\n */\n setEffectBooleanParameter(\n name: string,\n parameterName: string,\n value: boolean\n ): void {\n this._effectsManager.setEffectBooleanParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Enable or disable an effect.\n * @param name The name of the effect to enable or disable.\n * @param enable true to enable, false to disable\n */\n enableEffect(name: string, enable: boolean): void {\n this._effectsManager.enableEffect(\n this._rendererEffects,\n this,\n name,\n enable\n );\n }\n\n /**\n * Check if an effect is enabled\n * @param name The name of the effect\n * @return true if the effect is enabled, false otherwise.\n */\n isEffectEnabled(name: string): boolean {\n return this._effectsManager.isEffectEnabled(\n this._rendererEffects,\n this,\n name\n );\n }\n\n /**\n * Check if an effect exists on this layer\n * @param name The name of the effect\n * @return true if the effect exists, false otherwise.\n */\n hasEffect(name: string): boolean {\n return this._effectsManager.hasEffect(this._rendererEffects, name);\n }\n\n /**\n * Set the time scale for the objects on the layer:\n * time will be slower if time scale is < 1, faster if > 1.\n * @param timeScale The new time scale (must be positive).\n */\n setTimeScale(timeScale: float): void {\n if (timeScale >= 0) {\n this._timeScale = timeScale;\n }\n }\n\n /**\n * Get the time scale for the objects on the layer.\n */\n getTimeScale(): float {\n return this._timeScale;\n }\n\n /**\n * Return the time elapsed since the last frame,\n * in milliseconds, for objects on the layer.\n *\n * @param instanceContainer The instance container the layer belongs to (deprecated - can be omitted).\n */\n getElapsedTime(instanceContainer?: gdjs.RuntimeInstanceContainer): float {\n const container = instanceContainer || this._runtimeScene;\n return container.getElapsedTime() * this._timeScale;\n }\n\n /**\n * Change the position, rotation and scale (zoom) of the layer camera to be the same as the base layer camera.\n */\n followBaseLayer(): void {\n const baseLayer = this._runtimeScene.getLayer('');\n this.setCameraX(baseLayer.getCameraX());\n this.setCameraY(baseLayer.getCameraY());\n this.setCameraRotation(baseLayer.getCameraRotation());\n this.setCameraZoom(baseLayer.getCameraZoom());\n }\n\n /**\n * The clear color is defined in the format [r, g, b], with components in the range of 0 to 1.\n * @return the clear color of layer in the range of [0, 1].\n */\n getClearColor(): Array<integer> {\n return this._clearColor;\n }\n\n /**\n * Set the clear color in format [r, g, b], with components in the range of 0 to 1.;\n * @param r Red color component in the range 0-255.\n * @param g Green color component in the range 0-255.\n * @param b Blue color component in the range 0-255.\n */\n setClearColor(r: integer, g: integer, b: integer): void {\n this._clearColor[0] = r / 255;\n this._clearColor[1] = g / 255;\n this._clearColor[2] = b / 255;\n this._renderer.updateClearColor();\n }\n\n /**\n * Set whether layer's camera follows base layer's camera or not.\n */\n setFollowBaseLayerCamera(follow: boolean): void {\n this._followBaseLayerCamera = follow;\n }\n\n /**\n * Return true if the layer is a lighting layer, false otherwise.\n * @return true if it is a lighting layer, false otherwise.\n */\n isLightingLayer(): boolean {\n return this._isLightingLayer;\n }\n }\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACS,GAAK,GAAL,UAAK,EAAL,CACL,qBACA,yBACA,iDAHU,iEAMZ,KAAM,GAA6B,AACjC,GAEA,IAA0B,KACtB,EACA,IAA0B,SAAW,IAA0B,GAC/D,EACA,EAEC,GAAK,GAAL,UAAK,EAAL,CACL,iCACA,qCAFU,2DAIZ,KAAM,GAA0B,AAAC,GAC/B,IAA0B,eACtB,EACA,EAEC,GAAK,GAAL,UAAK,EAAL,CACL,+BACA,6EAFU,iFAKZ,KAAM,GAAqC,AACzC,GAEA,IAAkC,mCAC9B,EACA,EAOC,OAAqD,CA+B1D,YACE,EACA,EACA,CA7BF,gBAAoB,EACpB,oBAA0B,EAkB1B,sBAAiE,GAW/D,KAAK,MAAQ,EAAU,KACvB,KAAK,eAAiB,EAA2B,EAAU,eAC3D,KAAK,YAAc,EAAwB,EAAU,YACrD,KAAK,uBAAyB,EAC5B,EAAU,uBAAyB,oCAErC,KAAK,QAAU,CAAC,EAAU,WAC1B,KAAK,4BAA8B,EAAU,qBAAuB,GACpE,KAAK,kCACH,EAAU,2BAA6B,GACzC,KAAK,iCACH,EAAU,0BAA4B,IACxC,KAAK,oBAAsB,EAAU,SAAW,GAChD,KAAK,cAAgB,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BAAkB,MAOpE,aAAa,EAA0B,CACrC,KAAK,gBAAgB,aACnB,KAAK,iBACL,KACA,GAUJ,yBACE,EACA,EACA,EACM,CACN,KAAK,gBAAgB,yBACnB,KAAK,iBACL,EACA,EACA,GAUJ,yBACE,EACA,EACA,EACM,CACN,KAAK,gBAAgB,yBACnB,KAAK,iBACL,EACA,EACA,GAUJ,0BACE,EACA,EACA,EACM,CACN,KAAK,gBAAgB,0BACnB,KAAK,iBACL,EACA,EACA,GASJ,aAAa,EAAc,EAAuB,CAChD,KAAK,gBAAgB,aACnB,KAAK,iBACL,KACA,EACA,GASJ,gBAAgB,EAAuB,CACrC,MAAO,MAAK,gBAAgB,gBAC1B,KAAK,iBACL,KACA,GASJ,UAAU,EAAuB,CAC/B,MAAO,MAAK,gBAAgB,UAAU,KAAK,iBAAkB,GAQ/D,aAAa,EAAwB,CACnC,AAAI,GAAa,GACf,MAAK,WAAa,GAOtB,cAAsB,CACpB,MAAO,MAAK,WASd,eAAe,EAA0D,CAEvE,MAAO,AADW,IAAqB,KAAK,eAC3B,iBAAmB,KAAK,WAM3C,iBAAwB,CACtB,KAAM,GAAY,KAAK,cAAc,SAAS,IAC9C,KAAK,WAAW,EAAU,cAC1B,KAAK,WAAW,EAAU,cAC1B,KAAK,kBAAkB,EAAU,qBACjC,KAAK,cAAc,EAAU,iBAO/B,eAAgC,CAC9B,MAAO,MAAK,YASd,cAAc,EAAY,EAAY,EAAkB,CACtD,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,UAAU,mBAMjB,yBAAyB,EAAuB,CAC9C,KAAK,uBAAyB,EAOhC,iBAA2B,CACzB,MAAO,MAAK,kBAviBT,EAAe,iBA1Cd",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,2 @@
1
+ var gdjs;(function(i){const a=s=>{const e=atob(s.split(",")[1]),t=s.split(",")[0].split(":")[1].split(";")[0],n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return new Blob([n],{type:t})};class o{constructor(e,t){this._gameRenderer=e,this._captureOptions=t}setupCaptureOptions(e){if(!(!e||!this._captureOptions.screenshots))for(const t of this._captureOptions.screenshots)setTimeout(async()=>{await this.takeAndUploadScreenshot(t.signedUrl)},t.delayTimeInSeconds)}async takeAndUploadScreenshot(e){const t=this._gameRenderer.getCanvas();if(t)try{const n=t.toDataURL("image/png"),r=a(n);await fetch(e,{method:"PUT",body:r,headers:{"Content-Type":"image/png"}})}catch(n){console.error("Error while uploading screenshot:",n)}}}i.CaptureManager=o})(gdjs||(gdjs={}));
2
+ //# sourceMappingURL=capturemanager.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../GDevelop/GDJS/Runtime/capturemanager.ts"],
4
+ "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n export type CaptureOptions = {\n screenshots?: Array<{\n delayTimeInSeconds: number;\n signedUrl: string;\n publicUrl: string;\n }>;\n };\n\n /**\n * Helper function to convert a base64 string to a Blob, which can be uploaded to a server.\n */\n const base64ToBlob = (base64) => {\n const byteString = atob(base64.split(',')[1]);\n const mimeString = base64.split(',')[0].split(':')[1].split(';')[0];\n\n const arrayBuffer = new Uint8Array(byteString.length);\n for (let i = 0; i < byteString.length; i++) {\n arrayBuffer[i] = byteString.charCodeAt(i);\n }\n\n return new Blob([arrayBuffer], { type: mimeString });\n };\n\n /**\n * Manage the captures (screenshots, videos, etc...) that need to be taken during the game.\n */\n export class CaptureManager {\n _gameRenderer: gdjs.RuntimeGameRenderer;\n _captureOptions: CaptureOptions;\n\n constructor(\n renderer: gdjs.RuntimeGameRenderer,\n captureOptions: CaptureOptions\n ) {\n this._gameRenderer = renderer;\n this._captureOptions = captureOptions;\n }\n\n /**\n * To be called when the scene has started rendering.\n */\n setupCaptureOptions(isPreview: boolean): void {\n if (!isPreview || !this._captureOptions.screenshots) {\n return;\n }\n\n for (const screenshotCaptureOption of this._captureOptions.screenshots) {\n setTimeout(async () => {\n await this.takeAndUploadScreenshot(screenshotCaptureOption.signedUrl);\n }, screenshotCaptureOption.delayTimeInSeconds);\n }\n }\n\n /**\n * Take a screenshot and upload it to the server.\n */\n async takeAndUploadScreenshot(signedUrl: string) {\n const canvas = this._gameRenderer.getCanvas();\n if (canvas) {\n try {\n const base64Data = canvas.toDataURL('image/png');\n const blobData = base64ToBlob(base64Data);\n\n await fetch(signedUrl, {\n method: 'PUT',\n body: blobData,\n headers: {\n 'Content-Type': 'image/png',\n },\n });\n } catch (error) {\n console.error('Error while uploading screenshot:', error);\n }\n }\n }\n }\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAYE,KAAM,GAAe,AAAC,GAAW,CAC/B,KAAM,GAAa,KAAK,EAAO,MAAM,KAAK,IACpC,EAAa,EAAO,MAAM,KAAK,GAAG,MAAM,KAAK,GAAG,MAAM,KAAK,GAE3D,EAAc,GAAI,YAAW,EAAW,QAC9C,OAAS,GAAI,EAAG,EAAI,EAAW,OAAQ,IACrC,EAAY,GAAK,EAAW,WAAW,GAGzC,MAAO,IAAI,MAAK,CAAC,GAAc,CAAE,KAAM,KAMlC,OAAqB,CAI1B,YACE,EACA,EACA,CACA,KAAK,cAAgB,EACrB,KAAK,gBAAkB,EAMzB,oBAAoB,EAA0B,CAC5C,GAAI,GAAC,GAAa,CAAC,KAAK,gBAAgB,aAIxC,SAAW,KAA2B,MAAK,gBAAgB,YACzD,WAAW,SAAY,CACrB,KAAM,MAAK,wBAAwB,EAAwB,YAC1D,EAAwB,yBAOzB,yBAAwB,EAAmB,CAC/C,KAAM,GAAS,KAAK,cAAc,YAClC,GAAI,EACF,GAAI,CACF,KAAM,GAAa,EAAO,UAAU,aAC9B,EAAW,EAAa,GAE9B,KAAM,OAAM,EAAW,CACrB,OAAQ,MACR,KAAM,EACN,QAAS,CACP,eAAgB,qBAGb,EAAP,CACA,QAAQ,MAAM,oCAAqC,KA7CpD,EAAM,mBA3BL",
6
+ "names": []
7
+ }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(i){const a=new i.Logger("Font manager"),c=["font"];class d{constructor(r){this._loadedFontFamily=new i.ResourceCache;this._loadedFontFamilySet=new Set;this._resourceLoader=r}getResourceKinds(){return c}getFontFamily(r){return this._loadedFontFamily.getFromName(r)||"Arial"}getFontFile(r){const e=this._resourceLoader.getResource(r);return e?e.file||"":r}_getFontFamilyFromFilename(r){let e="gdjs_font_"+r.file.toLowerCase().replace(/[^\w]/gi,"-");const o=e;let n=2;for(;this._loadedFontFamilySet.has(e);)e=e+"-"+n,n++;return o}_loadFont(r,e){const o={},n="url("+encodeURI(e)+")";if(typeof FontFace!="undefined")return fetch(this._resourceLoader.getFullUrl(e),{credentials:this._resourceLoader.checkIfCredentialsRequired(e)?"include":"same-origin"}).then(t=>{if(!t.ok){const s="Unable to fetch "+e+" to be loaded as a font. HTTP status is: "+t.status+".";throw a.error(s),new Error(s)}return t.arrayBuffer()}).then(t=>{const s=new FontFace(r,t,o);document.fonts.add(s)});{const t=document.createElement("style");return t.appendChild(document.createTextNode("@font-face { font-family: '"+r+"'; src: "+n+"; }")),document.head.appendChild(t),new FontFaceObserver(r,o).load()}}async processResource(r){}async loadResource(r){const e=this._resourceLoader.getResource(r);if(!e){a.warn('Unable to find font for resource "'+r+'".');return}if(this._loadedFontFamily.get(e))return;const o=e.file;if(!o)return;const n=this._getFontFamilyFromFilename(e);this._loadedFontFamily.set(e,n),this._loadedFontFamilySet.add(n);try{await this._loadFont(n,o)}catch(t){a.error('Error loading font resource "'+e.name+'" (file: '+o+"): "+(t.message||"Unknown error"))}}}i.FontFaceObserverFontManager=d,i.FontManager=d})(gdjs||(gdjs={}));
1
+ var gdjs;(function(i){const s=new i.Logger("Font manager"),d=["font"];class c{constructor(r){this._loadedFontFamily=new i.ResourceCache;this._loadedFontFamilySet=new Set;this._resourceLoader=r}getResourceKinds(){return d}getFontFamily(r){return this._loadedFontFamily.getFromName(r)||"Arial"}getFontFile(r){const e=this._resourceLoader.getResource(r);return e?e.file||"":r}_getFontFamilyFromFilename(r){let e="gdjs_font_"+r.file.toLowerCase().replace(/[^\w]/gi,"-");const o=e;let n=2;for(;this._loadedFontFamilySet.has(e);)e=e+"-"+n,n++;return o}_loadFont(r,e){const o={},n="url("+encodeURI(e)+")";if(typeof FontFace!="undefined")return fetch(this._resourceLoader.getFullUrl(e),{credentials:this._resourceLoader.checkIfCredentialsRequired(e)?"include":"same-origin"}).then(t=>{if(!t.ok){const a="Unable to fetch "+e+" to be loaded as a font. HTTP status is: "+t.status+".";throw s.error(a),new Error(a)}return t.arrayBuffer()}).then(t=>{const a=new FontFace(r,t,o);document.fonts.add(a)});{const t=document.createElement("style");return t.appendChild(document.createTextNode("@font-face { font-family: '"+r+"'; src: "+n+"; }")),document.head.appendChild(t),new FontFaceObserver(r,o).load()}}async processResource(r){}async loadResource(r){const e=this._resourceLoader.getResource(r);if(!e){s.warn('Unable to find font for resource "'+r+'".');return}if(this._loadedFontFamily.get(e))return;const o=e.file;if(!o)return;const n=this._getFontFamilyFromFilename(e);this._loadedFontFamily.set(e,n),this._loadedFontFamilySet.add(n);try{await this._loadFont(n,o)}catch(t){s.error('Error loading font resource "'+e.name+'" (file: '+o+"): "+(t.message||"Unknown error"))}}dispose(){this._loadedFontFamily.clear(),this._loadedFontFamilySet.clear()}}i.FontFaceObserverFontManager=c,i.FontManager=c})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=fontfaceobserver-font-manager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../GDevelop/GDJS/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.ts"],
4
- "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Font manager');\n\n const resourceKinds: Array<ResourceKind> = ['font'];\n\n /**\n * FontFaceObserverFontManager loads fonts (using `FontFace` or `fontfaceobserver` library)\n * from the game resources (see `loadFonts`), and allow to access to\n * the font families of the loaded fonts during the game (see `getFontFamily`).\n */\n export class FontFaceObserverFontManager implements gdjs.ResourceManager {\n _resourceLoader: gdjs.ResourceLoader;\n // Associate font resource names to the loaded font family\n _loadedFontFamily = new gdjs.ResourceCache<string>();\n _loadedFontFamilySet = new Set<string>();\n\n /**\n * @param resources The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Return the font family associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * a default font family will be returned (\"Arial\").\n *\n * @param resourceName The name of the resource to get.\n * @returns The font family to be used for this font resource,\n * or \"Arial\" if not loaded.\n */\n getFontFamily(resourceName: string): string {\n return this._loadedFontFamily.getFromName(resourceName) || 'Arial';\n }\n\n /**\n * Return the font file associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * the resource name will be returned (to\n * keep compatibility with GDevelop 5.0-beta56 and previous).\n *\n * Should only be useful for renderers running on a non HTML5/non browser environment.\n *\n * @param resourceName The name of the resource to get.\n * @returns The file of the font resource.\n */\n getFontFile(resourceName: string): string {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource ? resource.file || '' : resourceName;\n }\n\n /**\n * Return the font family to use for a given filename.\n * Each filename is guaranteed to have a unique font family. You should not rely\n * on the font family formatting (consider it as an \"opaque string\") - it's slugified\n * (no spaces, no dots, no non-alphanumeric characters) to avoid issues when using the\n * font family in various contexts.\n *\n * @param filename The filename of the font.\n * @returns The font family to be used for this font resource.\n */\n _getFontFamilyFromFilename(resource: ResourceData): string {\n // Replaces all non-alphanumeric characters with dashes to ensure no issues when\n // referring to this font family (see https://github.com/4ian/GDevelop/issues/1521).\n let baseSlugifiedName =\n 'gdjs_font_' + resource.file.toLowerCase().replace(/[^\\w]/gi, '-');\n\n // Ensure the generated font family is unique.\n const slugifiedName = baseSlugifiedName;\n let uniqueSuffix = 2;\n while (this._loadedFontFamilySet.has(baseSlugifiedName)) {\n baseSlugifiedName = baseSlugifiedName + '-' + uniqueSuffix;\n uniqueSuffix++;\n }\n return slugifiedName;\n }\n\n /**\n * Load the font at the given `src` location (relative to the project), giving\n * it the specified `fontFamily` name.\n *\n * This uses FontFace (if supported) or @font-face + FontFaceObserver\n * to load a font from an url and be notified when loading is done (or failed).\n *\n * @param fontFamily The font\n * @returns The font family to be used for this font resource.\n */\n private _loadFont(fontFamily: string, src: string): Promise<void> {\n const descriptors = {};\n const srcWithUrl = 'url(' + encodeURI(src) + ')';\n\n // @ts-ignore\n if (typeof FontFace !== 'undefined') {\n // Load the given font using CSS Font Loading API.\n return fetch(this._resourceLoader.getFullUrl(src), {\n credentials: this._resourceLoader.checkIfCredentialsRequired(src)\n ? // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n })\n .then((response) => {\n if (!response.ok) {\n const errorMessage =\n 'Unable to fetch ' +\n src +\n ' to be loaded as a font. HTTP status is: ' +\n response.status +\n '.';\n logger.error(errorMessage);\n throw new Error(errorMessage);\n }\n\n return response.arrayBuffer();\n })\n .then((arrayBuffer) => {\n // @ts-ignore\n const fontFace = new FontFace(fontFamily, arrayBuffer, descriptors);\n\n // @ts-ignore\n document.fonts.add(fontFace);\n });\n } else {\n // TODO: this method of loading font should be removed as old and not allowing\n // to handle loading with credentials. All moderns and not-so-modern browsers\n // that we support also support FontFace API.\n\n // Add @font-face and use FontFaceObserver to be notified when the\n // font is ready.\n const newStyle = document.createElement('style');\n newStyle.appendChild(\n document.createTextNode(\n \"@font-face { font-family: '\" +\n fontFamily +\n \"'; src: \" +\n srcWithUrl +\n '; }'\n )\n );\n document.head.appendChild(newStyle);\n\n // @ts-ignore\n return new FontFaceObserver(fontFamily, descriptors).load();\n }\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because fonts are light enough to be parsed in background.\n }\n\n /**\n * Load the specified resources, so that fonts are loaded and can then be\n * used by using the font family returned by getFontFamily.\n * @param onProgress Callback called each time a new file is loaded.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find font for resource \"' + resourceName + '\".');\n return;\n }\n\n if (this._loadedFontFamily.get(resource)) {\n return;\n }\n const file = resource.file;\n if (!file) {\n return;\n }\n\n const fontFamily = this._getFontFamilyFromFilename(resource);\n // Cache the result to avoid collision with a similar slugified name for another filename.\n this._loadedFontFamily.set(resource, fontFamily);\n this._loadedFontFamilySet.add(fontFamily);\n try {\n await this._loadFont(fontFamily, file);\n } catch (error) {\n logger.error(\n 'Error loading font resource \"' +\n resource.name +\n '\" (file: ' +\n file +\n '): ' +\n (error.message || 'Unknown error')\n );\n }\n }\n }\n\n //Register the class to let the engine use it.\n export type FontManager = FontFaceObserverFontManager;\n export const FontManager = FontFaceObserverFontManager;\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,gBAEzB,EAAqC,CAAC,QAOrC,OAAkE,CAUvE,YAAY,EAAqC,CAPjD,uBAAoB,GAAI,GAAK,cAC7B,0BAAuB,GAAI,KAOzB,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,GAYT,cAAc,EAA8B,CAC1C,MAAO,MAAK,kBAAkB,YAAY,IAAiB,QAc7D,YAAY,EAA8B,CACxC,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,GAAW,EAAS,MAAQ,GAAK,EAa1C,2BAA2B,EAAgC,CAGzD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esContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Font manager');\n\n const resourceKinds: Array<ResourceKind> = ['font'];\n\n /**\n * FontFaceObserverFontManager loads fonts (using `FontFace` or `fontfaceobserver` library)\n * from the game resources (see `loadFonts`), and allow to access to\n * the font families of the loaded fonts during the game (see `getFontFamily`).\n */\n export class FontFaceObserverFontManager implements gdjs.ResourceManager {\n _resourceLoader: gdjs.ResourceLoader;\n // Associate font resource names to the loaded font family\n _loadedFontFamily = new gdjs.ResourceCache<string>();\n _loadedFontFamilySet = new Set<string>();\n\n /**\n * @param resources The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Return the font family associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * a default font family will be returned (\"Arial\").\n *\n * @param resourceName The name of the resource to get.\n * @returns The font family to be used for this font resource,\n * or \"Arial\" if not loaded.\n */\n getFontFamily(resourceName: string): string {\n return this._loadedFontFamily.getFromName(resourceName) || 'Arial';\n }\n\n /**\n * Return the font file associated to the specified font resource name.\n * The font resource must have been loaded before. If that's not the case,\n * the resource name will be returned (to\n * keep compatibility with GDevelop 5.0-beta56 and previous).\n *\n * Should only be useful for renderers running on a non HTML5/non browser environment.\n *\n * @param resourceName The name of the resource to get.\n * @returns The file of the font resource.\n */\n getFontFile(resourceName: string): string {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource ? resource.file || '' : resourceName;\n }\n\n /**\n * Return the font family to use for a given filename.\n * Each filename is guaranteed to have a unique font family. You should not rely\n * on the font family formatting (consider it as an \"opaque string\") - it's slugified\n * (no spaces, no dots, no non-alphanumeric characters) to avoid issues when using the\n * font family in various contexts.\n *\n * @param filename The filename of the font.\n * @returns The font family to be used for this font resource.\n */\n _getFontFamilyFromFilename(resource: ResourceData): string {\n // Replaces all non-alphanumeric characters with dashes to ensure no issues when\n // referring to this font family (see https://github.com/4ian/GDevelop/issues/1521).\n let baseSlugifiedName =\n 'gdjs_font_' + resource.file.toLowerCase().replace(/[^\\w]/gi, '-');\n\n // Ensure the generated font family is unique.\n const slugifiedName = baseSlugifiedName;\n let uniqueSuffix = 2;\n while (this._loadedFontFamilySet.has(baseSlugifiedName)) {\n baseSlugifiedName = baseSlugifiedName + '-' + uniqueSuffix;\n uniqueSuffix++;\n }\n return slugifiedName;\n }\n\n /**\n * Load the font at the given `src` location (relative to the project), giving\n * it the specified `fontFamily` name.\n *\n * This uses FontFace (if supported) or @font-face + FontFaceObserver\n * to load a font from an url and be notified when loading is done (or failed).\n *\n * @param fontFamily The font\n * @returns The font family to be used for this font resource.\n */\n private _loadFont(fontFamily: string, src: string): Promise<void> {\n const descriptors = {};\n const srcWithUrl = 'url(' + encodeURI(src) + ')';\n\n // @ts-ignore\n if (typeof FontFace !== 'undefined') {\n // Load the given font using CSS Font Loading API.\n return fetch(this._resourceLoader.getFullUrl(src), {\n credentials: this._resourceLoader.checkIfCredentialsRequired(src)\n ? // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n })\n .then((response) => {\n if (!response.ok) {\n const errorMessage =\n 'Unable to fetch ' +\n src +\n ' to be loaded as a font. HTTP status is: ' +\n response.status +\n '.';\n logger.error(errorMessage);\n throw new Error(errorMessage);\n }\n\n return response.arrayBuffer();\n })\n .then((arrayBuffer) => {\n // @ts-ignore\n const fontFace = new FontFace(fontFamily, arrayBuffer, descriptors);\n\n // @ts-ignore\n document.fonts.add(fontFace);\n });\n } else {\n // TODO: this method of loading font should be removed as old and not allowing\n // to handle loading with credentials. All moderns and not-so-modern browsers\n // that we support also support FontFace API.\n\n // Add @font-face and use FontFaceObserver to be notified when the\n // font is ready.\n const newStyle = document.createElement('style');\n newStyle.appendChild(\n document.createTextNode(\n \"@font-face { font-family: '\" +\n fontFamily +\n \"'; src: \" +\n srcWithUrl +\n '; }'\n )\n );\n document.head.appendChild(newStyle);\n\n // @ts-ignore\n return new FontFaceObserver(fontFamily, descriptors).load();\n }\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because fonts are light enough to be parsed in background.\n }\n\n /**\n * Load the specified resources, so that fonts are loaded and can then be\n * used by using the font family returned by getFontFamily.\n * @param onProgress Callback called each time a new file is loaded.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find font for resource \"' + resourceName + '\".');\n return;\n }\n\n if (this._loadedFontFamily.get(resource)) {\n return;\n }\n const file = resource.file;\n if (!file) {\n return;\n }\n\n const fontFamily = this._getFontFamilyFromFilename(resource);\n // Cache the result to avoid collision with a similar slugified name for another filename.\n this._loadedFontFamily.set(resource, fontFamily);\n this._loadedFontFamilySet.add(fontFamily);\n try {\n await this._loadFont(fontFamily, file);\n } catch (error) {\n logger.error(\n 'Error loading font resource \"' +\n resource.name +\n '\" (file: ' +\n file +\n '): ' +\n (error.message || 'Unknown error')\n );\n }\n }\n\n /**\n * To be called when the game is disposed.\n * Clear caches of loaded font families.\n */\n dispose(): void {\n this._loadedFontFamily.clear();\n this._loadedFontFamilySet.clear();\n }\n }\n\n //Register the class to let the engine use it.\n export type FontManager = FontFaceObserverFontManager;\n export const FontManager = FontFaceObserverFontManager;\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,gBAEzB,EAAqC,CAAC,QAOrC,OAAkE,CAUvE,YAAY,EAAqC,CAPjD,uBAAoB,GAAI,GAAK,cAC7B,0BAAuB,GAAI,KAOzB,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,GAYT,cA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qBAAqB,IAAI,GAC9B,GAAI,CACF,KAAM,MAAK,UAAU,EAAY,SAC1B,EAAP,CACA,EAAO,MACL,gCACE,EAAS,KACT,YACA,EACA,MACC,GAAM,SAAW,mBAS1B,SAAgB,CACd,KAAK,kBAAkB,QACvB,KAAK,qBAAqB,SA/LvB,EAAM,8BAqMA,cAAc,IA/MnB",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(a){const h=new a.Logger("Audio manager"),f=["audio"],c={preload:!0,onplayerror:(u,e)=>h.error("Can't play an audio file: "+e),onloaderror:(u,e)=>h.error("Error while loading an audio file: "+e)},d=u=>u>1?1:u<0?0:u;class g{constructor(e,s,t,o){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=d(s),this._loop=t,this._rate=o}isLoaded(){return this._howl.state()==="loaded"}play(){if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(a.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(s=>{this.on("play",s),s(e)}),this._oncePlay.forEach(s=>s(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play());return this}pause(){return this._id!==null&&this._howl.pause(this._id),this}stop(){return this._id!==null&&this._howl.stop(this._id),this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){return this._rate=e,this._id!==null&&(e=a.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id)),this}getLoop(){return this._loop}setLoop(e){return this._loop=e,this._id!==null&&this._howl.loop(e,this._id),this}getVolume(){return this._id===null?this._initialVolume:this._howl.volume(this._id)}setVolume(e){return this._initialVolume=d(e),this._id!==null&&this._howl.volume(this._initialVolume,this._id),this}getMute(){return this._id===null?!1:this._howl.mute(this._id)}setMute(e){return this._id!==null&&this._howl.mute(e,this._id),this}getSeek(){return this._id===null?0:this._howl.seek(this._id)}setSeek(e){return this._id!==null&&this._howl.seek(e,this._id),this}getSpatialPosition(e){return this._id===null?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,s,t){return this._id!==null&&this._howl.pos(e,s,t,this._id),this}fade(e,s,t){return this._id!==null&&this._howl.fade(d(e),d(s),t,this._id),this}on(e,s){return e==="play"?this._id===null?this._onPlay.push(s):this._howl.on(e,s,this._id):this._id===null?this.once("play",()=>this.on(e,s)):this._howl.on(e,s,this._id),this}once(e,s){return e==="play"?this._id===null?this._oncePlay.push(s):this.playing()?s(this._id):this._howl.once(e,s,this._id):this._id===null?this.once("play",()=>this.once(e,s)):this._howl.once(e,s,this._id),this}off(e,s){return this._id!==null&&this._howl.off(e,s,this._id),this}}a.HowlerSound=g;class p{constructor(e){this._loadedMusics=new a.ResourceCache;this._loadedSounds=new a.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:{file:e,kind:"audio",metadata:"",name:e}};this._resourceLoader=e;const s=this;document.addEventListener("deviceready",function(){document.addEventListener("pause",function(){const t=s._freeSounds.concat(s._freeMusics);for(let o in s._sounds)s._sounds.hasOwnProperty(o)&&t.push(s._sounds[o]);for(let o in s._musics)s._musics.hasOwnProperty(o)&&t.push(s._musics[o]);for(let o=0;o<t.length;o++){const i=t[o];!i.paused()&&!i.stopped()&&(i.pause(),s._pausedSounds.push(i))}s._paused=!0},!1),document.addEventListener("resume",function(){try{for(let t=0;t<s._pausedSounds.length;t++){const o=s._pausedSounds[t];o.stopped()||o.play()}}catch(t){if(t.message&&typeof t.message=="string"&&t.message.startsWith("Maximum call stack size exceeded"))console.warn("An error occurred when resuming paused sounds while the game was in background:",t);else throw t}s._pausedSounds.length=0,s._paused=!1},!1)})}getResourceKinds(){return f}static clampRate(e){return e>4?4:e<.5?.5:e}_storeSoundInArray(e,s){for(let t=0,o=e.length;t<o;++t)if(!e[t]||e[t].stopped())return e[t]=s,s;return e.push(s),s}createHowlerSound(e,s,t,o,i){const l=s?this._loadedMusics:this._loadedSounds,r=this._getAudioResource(e);let n=l.get(r);if(!n){const _=r?r.file:e;n=new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(_)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(_)},volume:0},c)),l.set(r,n)}return new a.HowlerSound(n,t,o,i)}loadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e);t.get(o)||t.set(o,new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(o.file)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(o.file)},volume:0},c)))}unloadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e),i=t.get(o);if(!i)return;function l(r){for(let n in r)r[n]&&r[n]._howl===i&&(r[n].stop(),delete r[n])}l(this._freeMusics),l(this._freeSounds),l(Object.values(this._musics)),l(Object.values(this._sounds)),l(this._pausedSounds),i.unload(),t.delete(o)}unloadAll(){Howler.unload(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0,this._loadedMusics.clear(),this._loadedSounds.clear()}playSound(e,s,t,o){const i=this.createHowlerSound(e,!1,t/100,s,o);this._storeSoundInArray(this._freeSounds,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playSoundOnChannel(e,s,t,o,i){this._sounds[s]&&this._sounds[s].stop();const l=this.createHowlerSound(e,!1,o/100,t,i);this._sounds[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getSoundOnChannel(e){return this._sounds[e]||null}playMusic(e,s,t,o){const i=this.createHowlerSound(e,!0,t/100,s,o);this._storeSoundInArray(this._freeMusics,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playMusicOnChannel(e,s,t,o,i){this._musics[s]&&this._musics[s].stop();const l=this.createHowlerSound(e,!0,o/100,t,i);this._musics[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getMusicOnChannel(e){return this._musics[e]||null}setGlobalVolume(e){this._globalVolume=e,this._globalVolume>100&&(this._globalVolume=100),this._globalVolume<0&&(this._globalVolume=0),Howler.volume(this._globalVolume/100)}getGlobalVolume(){return this._globalVolume}clearAll(){Howler.stop(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0}async processResource(e){}async loadResource(e){const s=this._resourceLoader.getResource(e);if(!s){h.warn('Unable to find audio for resource "'+e+'".');return}if(s.file){if(this._availableResources[s.name])return;this._availableResources[s.name]=s}const t=(i,l)=>new Promise((r,n)=>{const _=l?this._loadedMusics:this._loadedSounds;_[i]=new Howl(Object.assign({},c,{src:[this._resourceLoader.getFullUrl(i)],onload:r,onloaderror:(y,w)=>n(w),html5:l,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(i)},volume:0}))}),o=s.file;if(s.preloadAsMusic)try{await t(o,!0)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}if(s.preloadAsSound)try{await t(o,!1)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}else if(s.preloadInCache||!s.preloadAsMusic)try{await new Promise((i,l)=>{const r=new XMLHttpRequest;r.withCredentials=this._resourceLoader.checkIfCredentialsRequired(o),r.addEventListener("load",i),r.addEventListener("error",n=>l("XHR error: "+o)),r.addEventListener("abort",n=>l("XHR abort: "+o)),r.open("GET",this._resourceLoader.getFullUrl(o)),r.send()})}catch(i){h.warn("There was an error while preloading an audio file: "+i)}}}a.HowlerSoundManager=p,a.SoundManager=p})(gdjs||(gdjs={}));
1
+ var gdjs;(function(a){const h=new a.Logger("Audio manager"),f=["audio"],c={preload:!0,onplayerror:(u,e)=>h.error("Can't play an audio file: "+e),onloaderror:(u,e)=>h.error("Error while loading an audio file: "+e)},d=u=>u>1?1:u<0?0:u;class g{constructor(e,s,t,o){this._id=null;this._oncePlay=[];this._onPlay=[];this._howl=e,this._initialVolume=d(s),this._loop=t,this._rate=o}isLoaded(){return this._howl.state()==="loaded"}play(){if(this.isLoaded()){const e=this._howl.play(this._id===null?"__default":this._id);this._id=e,this._howl.volume(this._initialVolume,e),this._howl.loop(this._loop,e),this._howl.rate(a.HowlerSoundManager.clampRate(this._rate),e),this._onPlay.forEach(s=>{this.on("play",s),s(e)}),this._oncePlay.forEach(s=>s(e)),this._onPlay=[],this._oncePlay=[]}else this._howl.once("load",()=>this.play());return this}pause(){return this._id!==null&&this._howl.pause(this._id),this}stop(){return this._id!==null&&this._howl.stop(this._id),this}playing(){return(this._id!==null?this._howl.playing(this._id):!0)||!this.isLoaded()}paused(){return!this.playing()}stopped(){return this.paused()&&this.getSeek()===0}getRate(){return this._rate}setRate(e){return this._rate=e,this._id!==null&&(e=a.HowlerSoundManager.clampRate(e),this._howl.rate(e,this._id)),this}getLoop(){return this._loop}setLoop(e){return this._loop=e,this._id!==null&&this._howl.loop(e,this._id),this}getVolume(){return this._id===null?this._initialVolume:this._howl.volume(this._id)}setVolume(e){return this._initialVolume=d(e),this._id!==null&&this._howl.volume(this._initialVolume,this._id),this}getMute(){return this._id===null?!1:this._howl.mute(this._id)}setMute(e){return this._id!==null&&this._howl.mute(e,this._id),this}getSeek(){return this._id===null?0:this._howl.seek(this._id)}setSeek(e){return this._id!==null&&this._howl.seek(e,this._id),this}getSpatialPosition(e){return this._id===null?0:this._howl.pos(this._id)[e==="x"?0:e==="y"?1:2]}setSpatialPosition(e,s,t){return this._id!==null&&this._howl.pos(e,s,t,this._id),this}fade(e,s,t){return this._id!==null&&this._howl.fade(d(e),d(s),t,this._id),this}on(e,s){return e==="play"?this._id===null?this._onPlay.push(s):this._howl.on(e,s,this._id):this._id===null?this.once("play",()=>this.on(e,s)):this._howl.on(e,s,this._id),this}once(e,s){return e==="play"?this._id===null?this._oncePlay.push(s):this.playing()?s(this._id):this._howl.once(e,s,this._id):this._id===null?this.once("play",()=>this.once(e,s)):this._howl.once(e,s,this._id),this}off(e,s){return this._id!==null&&this._howl.off(e,s,this._id),this}}a.HowlerSound=g;class p{constructor(e){this._loadedMusics=new a.ResourceCache;this._loadedSounds=new a.ResourceCache;this._availableResources={};this._globalVolume=100;this._sounds={};this._musics={};this._freeSounds=[];this._freeMusics=[];this._pausedSounds=[];this._paused=!1;this._getAudioResource=e=>{const s=this._resourceLoader.getResource(e);return s&&this.getResourceKinds().includes(s.kind)?s:{file:e,kind:"audio",metadata:"",name:e}};this._resourceLoader=e;const s=this;document.addEventListener("deviceready",function(){document.addEventListener("pause",function(){const t=s._freeSounds.concat(s._freeMusics);for(let o in s._sounds)s._sounds.hasOwnProperty(o)&&t.push(s._sounds[o]);for(let o in s._musics)s._musics.hasOwnProperty(o)&&t.push(s._musics[o]);for(let o=0;o<t.length;o++){const i=t[o];!i.paused()&&!i.stopped()&&(i.pause(),s._pausedSounds.push(i))}s._paused=!0},!1),document.addEventListener("resume",function(){try{for(let t=0;t<s._pausedSounds.length;t++){const o=s._pausedSounds[t];o.stopped()||o.play()}}catch(t){if(t.message&&typeof t.message=="string"&&t.message.startsWith("Maximum call stack size exceeded"))console.warn("An error occurred when resuming paused sounds while the game was in background:",t);else throw t}s._pausedSounds.length=0,s._paused=!1},!1)})}getResourceKinds(){return f}static clampRate(e){return e>4?4:e<.5?.5:e}_storeSoundInArray(e,s){for(let t=0,o=e.length;t<o;++t)if(!e[t]||e[t].stopped())return e[t]=s,s;return e.push(s),s}createHowlerSound(e,s,t,o,i){const l=s?this._loadedMusics:this._loadedSounds,r=this._getAudioResource(e);let n=l.get(r);if(!n){const _=r?r.file:e;n=new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(_)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(_)},volume:0},c)),l.set(r,n)}return new a.HowlerSound(n,t,o,i)}loadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e);t.get(o)||t.set(o,new Howl(Object.assign({src:[this._resourceLoader.getFullUrl(o.file)],html5:s,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(o.file)},volume:0},c)))}unloadAudio(e,s){const t=s?this._loadedMusics:this._loadedSounds,o=this._getAudioResource(e),i=t.get(o);if(!i)return;function l(r){for(let n in r)r[n]&&r[n]._howl===i&&(r[n].stop(),delete r[n])}l(this._freeMusics),l(this._freeSounds),l(Object.values(this._musics)),l(Object.values(this._sounds)),l(this._pausedSounds),i.unload(),t.delete(o)}unloadAll(){Howler.unload(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0,this._loadedMusics.clear(),this._loadedSounds.clear()}playSound(e,s,t,o){const i=this.createHowlerSound(e,!1,t/100,s,o);this._storeSoundInArray(this._freeSounds,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playSoundOnChannel(e,s,t,o,i){this._sounds[s]&&this._sounds[s].stop();const l=this.createHowlerSound(e,!1,o/100,t,i);this._sounds[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getSoundOnChannel(e){return this._sounds[e]||null}playMusic(e,s,t,o){const i=this.createHowlerSound(e,!0,t/100,s,o);this._storeSoundInArray(this._freeMusics,i),i.once("play",()=>{this._paused&&(i.pause(),this._pausedSounds.push(i))}),i.play()}playMusicOnChannel(e,s,t,o,i){this._musics[s]&&this._musics[s].stop();const l=this.createHowlerSound(e,!0,o/100,t,i);this._musics[s]=l,l.once("play",()=>{this._paused&&(l.pause(),this._pausedSounds.push(l))}),l.play()}getMusicOnChannel(e){return this._musics[e]||null}setGlobalVolume(e){this._globalVolume=e,this._globalVolume>100&&(this._globalVolume=100),this._globalVolume<0&&(this._globalVolume=0),Howler.volume(this._globalVolume/100)}getGlobalVolume(){return this._globalVolume}clearAll(){Howler.stop(),this._freeSounds.length=0,this._freeMusics.length=0,this._sounds={},this._musics={},this._pausedSounds.length=0}async processResource(e){}async loadResource(e){const s=this._resourceLoader.getResource(e);if(!s){h.warn('Unable to find audio for resource "'+e+'".');return}if(s.file){if(this._availableResources[s.name])return;this._availableResources[s.name]=s}const t=(i,l)=>new Promise((r,n)=>{const _=l?this._loadedMusics:this._loadedSounds;_[i]=new Howl(Object.assign({},c,{src:[this._resourceLoader.getFullUrl(i)],onload:r,onloaderror:(y,w)=>n(w),html5:l,xhr:{withCredentials:this._resourceLoader.checkIfCredentialsRequired(i)},volume:0}))}),o=s.file;if(s.preloadAsMusic)try{await t(o,!0)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}if(s.preloadAsSound)try{await t(o,!1)}catch(i){h.warn("There was an error while preloading an audio file: "+i)}else if(s.preloadInCache||!s.preloadAsMusic)try{await new Promise((i,l)=>{const r=new XMLHttpRequest;r.withCredentials=this._resourceLoader.checkIfCredentialsRequired(o),r.addEventListener("load",i),r.addEventListener("error",n=>l("XHR error: "+o)),r.addEventListener("abort",n=>l("XHR abort: "+o)),r.open("GET",this._resourceLoader.getFullUrl(o)),r.send()})}catch(i){h.warn("There was an error while preloading an audio file: "+i)}}dispose(){this.unloadAll()}}a.HowlerSoundManager=p,a.SoundManager=p})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=howler-sound-manager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../GDevelop/GDJS/Runtime/howler-sound-manager/howler-sound-manager.ts"],
4
- "sourcesContent": ["///<reference path='../types/howler'>\n/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Audio manager');\n\n const resourceKinds: Array<ResourceKind> = ['audio'];\n\n const HowlParameters: HowlOptions = {\n preload: true,\n onplayerror: (_, error) =>\n logger.error(\"Can't play an audio file: \" + error),\n onloaderror: (_, error) =>\n logger.error('Error while loading an audio file: ' + error),\n };\n\n /**\n * Ensure the volume is between 0 and 1.\n */\n const clampVolume = (volume: float): float => {\n if (volume > 1.0) {\n return 1.0;\n }\n if (volume < 0) {\n return 0;\n }\n return volume;\n };\n\n /**\n * A thin wrapper around a Howl object with:\n * * Handling of callbacks when the sound is not yet loaded.\n * * Automatic clamping when calling `setRate` to ensure a valid value is passed to Howler.js.\n * * Automatic clamping when calling `setVolume` so that the volume is always between 0 and 1.\n *\n * @memberof gdjs\n * @class HowlerSound\n */\n export class HowlerSound {\n /**\n * The ID of the played sound.\n */\n private _id: integer | null = null;\n\n /**\n * The Howl passed to the constructor.\n * It defines the sound file that is being played.\n */\n private _howl: Howl;\n\n /**\n * The **initial** volume at which the sound is being played.\n * Once the sound is started, this volume can be not in sync\n * (in the case the sound is faded by Howler), so volume must\n * be gotten from `this._howl` directly.\n *\n * This value is clamped between 0 and 1.\n */\n private _initialVolume: float;\n\n /**\n * Whether the sound is being played in a loop or not.\n */\n private _loop: boolean;\n\n /**\n * The rate (speed) the sound is being played at.\n * This value is not clamped, though technically Howler.js will only\n * accepts values between a specific range (so we clamp this when\n * passing it to Howler.js, but keep the original value here).\n */\n private _rate: float;\n\n /**\n * An array of callbacks to call once the sound starts to play.\n */\n private _oncePlay: Array<HowlCallback> = [];\n\n /**\n * An array of callbacks to call everytime the sound starts to play.\n */\n private _onPlay: Array<HowlCallback> = [];\n\n constructor(howl: Howl, volume: float, loop: boolean, rate: float) {\n this._howl = howl;\n this._initialVolume = clampVolume(volume);\n this._loop = loop;\n this._rate = rate;\n }\n\n /**\n * Returns true if the associated howl is fully loaded.\n */\n isLoaded(): boolean {\n return this._howl.state() === 'loaded';\n }\n\n /**\n * Begins playback of the sound, or if the Howl is still loading, schedule playing for once it loads.\n * @returns The current instance for chaining.\n */\n play(): this {\n if (this.isLoaded()) {\n const newID = this._howl.play(\n this._id === null ? '__default' : this._id\n );\n this._id = newID;\n\n // Set the howl properties as soon as the sound is played and we have its ID.\n this._howl.volume(this._initialVolume, newID); // this._initialVolume is already clamped between 0 and 1.\n this._howl.loop(this._loop, newID);\n // this._rate is not clamped, but we need to clamp it when passing it to Howler.js as it\n // only supports a specific range.\n this._howl.rate(gdjs.HowlerSoundManager.clampRate(this._rate), newID);\n\n // Manually handle the play event before we have an ID.\n // Before loading, howler won't register events as without an ID we cannot set a listener.\n // Once we have an ID, we can transfer control of the events to howler.\n // We also need to call them once as Howler doesn't for the first play event.\n this._onPlay.forEach((func) => {\n // Transfer the event to howler now that we have an ID\n this.on('play', func);\n func(newID);\n });\n this._oncePlay.forEach((func) => func(newID));\n this._onPlay = [];\n this._oncePlay = [];\n } else this._howl.once('load', () => this.play()); // Play only once the howl is fully loaded\n\n return this;\n }\n\n /**\n * Pauses playback of the sound, saving the seek of playback.\n * @returns The current instance for chaining.\n */\n pause(): this {\n if (this._id !== null) this._howl.pause(this._id);\n return this;\n }\n\n /**\n * Stops playback of the sound, resetting seek to 0.\n * @returns The current instance for chaining.\n */\n stop(): this {\n if (this._id !== null) this._howl.stop(this._id);\n return this;\n }\n\n /**\n * Check if the sound is currently playing.\n * Note that a loading sound is considered as playing (as it will be\n * played as soon as it's loaded). To avoid loading at runtime, prefer\n * to preload the sounds.\n */\n playing(): boolean {\n return (\n (this._id !== null ? this._howl.playing(this._id) : true) ||\n !this.isLoaded() // Loading is considered playing\n );\n }\n\n /**\n * Check if the sound is currently paused.\n */\n paused(): boolean {\n return !this.playing();\n }\n\n /**\n * Check if the sound is currently stopped.\n */\n stopped(): boolean {\n return this.paused() && this.getSeek() === 0;\n }\n\n /**\n * Get the sound playback rate. This 1 for the default speed.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n */\n getRate(): float {\n return this._rate;\n }\n\n /**\n * Set the playback rate.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n * @returns The current instance for chaining.\n */\n setRate(rate: float): this {\n this._rate = rate;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) {\n rate = gdjs.HowlerSoundManager.clampRate(rate);\n this._howl.rate(rate, this._id);\n }\n return this;\n }\n\n /**\n * Get if the sound is looping.\n */\n getLoop(): boolean {\n return this._loop;\n }\n\n /**\n * Set if the sound is looping.\n * @returns The current instance for chaining.\n */\n setLoop(loop: boolean): this {\n this._loop = loop;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.loop(loop, this._id);\n return this;\n }\n\n //TODO: Replace float type in those 2 methods with RangeOf<0..1> once it is standardized (https://github.com/Microsoft/TypeScript/issues/15480)\n /**\n * Get the sound volume.\n * @returns A float from 0 to 1.\n */\n getVolume(): float {\n if (this._id === null) return this._initialVolume;\n return this._howl.volume(this._id);\n }\n\n /**\n * Set the sound volume.\n * @param volume A float from 0 to 1. The value is clamped if too high or too low.\n * @returns The current instance for chaining.\n */\n setVolume(volume: float): this {\n this._initialVolume = clampVolume(volume);\n\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.volume(this._initialVolume, this._id);\n return this;\n }\n\n /**\n * Get if the sound is muted.\n */\n getMute(): boolean {\n if (this._id === null) return false;\n return this._howl.mute(this._id);\n }\n\n /**\n * Set if the sound is muted.\n * @returns The current instance for chaining.\n */\n setMute(mute: boolean): this {\n if (this._id !== null) this._howl.mute(mute, this._id);\n return this;\n }\n\n /**\n * Get the sound seek.\n */\n getSeek(): float {\n if (this._id === null) return 0;\n return this._howl.seek(this._id);\n }\n\n /**\n * Set the sound seek.\n * @returns The current instance for chaining.\n */\n setSeek(seek: float): this {\n if (this._id !== null) this._howl.seek(seek, this._id);\n return this;\n }\n\n /**\n * Get the sound spatial position.\n */\n getSpatialPosition(axis: 'x' | 'y' | 'z'): float {\n if (this._id === null) return 0;\n return this._howl.pos(this._id)[axis === 'x' ? 0 : axis === 'y' ? 1 : 2];\n }\n\n /**\n * Set the sound spatial position.\n * @returns The current instance for chaining.\n */\n setSpatialPosition(x: float, y: float, z: float): this {\n if (this._id !== null) this._howl.pos(x, y, z, this._id);\n return this;\n }\n\n /**\n * Fade the volume sound.\n * @returns The current instance for chaining.\n */\n fade(from: float, to: float, duration: float): this {\n if (this._id !== null)\n this._howl.fade(clampVolume(from), clampVolume(to), duration, this._id);\n return this;\n }\n\n /**\n * Adds an event listener to the howl.\n */\n on(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._onPlay.push(handler);\n } else {\n this._howl.on(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.on(event, handler));\n else this._howl.on(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Adds an event listener to the howl that removes itself after being called.\n * If the event is `play` and the sound is being played, the handler is\n * called synchronously.\n */\n once(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._oncePlay.push(handler);\n } else if (this.playing()) {\n // Immediately call the handler if the sound is already playing.\n // This is useful for sounds that were just started and have a `.once('play', ...)`\n // handler added on them to set up the volume/rate/loop. If we don't do it\n // synchronously, the sound can play for a tiny bit at the default volume and rate.\n // See https://github.com/4ian/GDevelop/issues/2490.\n handler(this._id);\n } else {\n this._howl.once(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.once(event, handler));\n else this._howl.once(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Removes an event listener to the howl.\n */\n off(event: HowlEvent, handler: HowlCallback): this {\n if (this._id !== null) this._howl.off(event, handler, this._id);\n return this;\n }\n }\n\n /**\n * HowlerSoundManager is used to manage the sounds and musics of a RuntimeScene.\n *\n * It is basically a container to associate channels to sounds and keep a list\n * of all sounds being played.\n */\n export class HowlerSoundManager {\n _loadedMusics = new gdjs.ResourceCache<Howl>();\n _loadedSounds = new gdjs.ResourceCache<Howl>();\n _availableResources: Record<string, ResourceData> = {};\n _globalVolume: float = 100;\n _sounds: Record<integer, HowlerSound> = {};\n _musics: Record<integer, HowlerSound> = {};\n _freeSounds: HowlerSound[] = []; // Sounds without an assigned channel.\n _freeMusics: HowlerSound[] = []; // Musics without an assigned channel.\n\n /** Paused sounds or musics that should be played once the game is resumed. */\n _pausedSounds: HowlerSound[] = [];\n _paused: boolean = false;\n\n _resourceLoader: gdjs.ResourceLoader;\n\n /**\n * @param resources The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n\n const that = this;\n document.addEventListener('deviceready', function () {\n // pause/resume sounds in Cordova when the app is being paused/resumed\n document.addEventListener(\n 'pause',\n function () {\n const soundList = that._freeSounds.concat(that._freeMusics);\n for (let key in that._sounds) {\n if (that._sounds.hasOwnProperty(key)) {\n soundList.push(that._sounds[key]);\n }\n }\n for (let key in that._musics) {\n if (that._musics.hasOwnProperty(key)) {\n soundList.push(that._musics[key]);\n }\n }\n for (let i = 0; i < soundList.length; i++) {\n const sound = soundList[i];\n if (!sound.paused() && !sound.stopped()) {\n sound.pause();\n that._pausedSounds.push(sound);\n }\n }\n that._paused = true;\n },\n false\n );\n document.addEventListener(\n 'resume',\n function () {\n try {\n for (let i = 0; i < that._pausedSounds.length; i++) {\n const sound = that._pausedSounds[i];\n if (!sound.stopped()) {\n sound.play();\n }\n }\n } catch (error) {\n if (\n error.message &&\n typeof error.message === 'string' &&\n error.message.startsWith('Maximum call stack size exceeded')\n ) {\n console.warn(\n 'An error occurred when resuming paused sounds while the game was in background:',\n error\n );\n } else {\n throw error;\n }\n }\n that._pausedSounds.length = 0;\n that._paused = false;\n },\n false\n );\n });\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Ensure rate is in a range valid for Howler.js\n * @return The clamped rate\n */\n static clampRate(rate: float): float {\n if (rate > 4.0) {\n return 4.0;\n }\n if (rate < 0.5) {\n return 0.5;\n }\n return rate;\n }\n\n /**\n * Return the file associated to the given sound name.\n *\n * Names and files are loaded from resources when preloadAudio is called. If no\n * file is associated to the given name, then the name will be considered as a\n * filename and will be returned.\n *\n * @return The associated resource\n */\n private _getAudioResource = (resourceName: string): ResourceData => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : ({\n file: resourceName,\n kind: 'audio',\n metadata: '',\n name: resourceName,\n } as ResourceData);\n };\n\n /**\n * Store the sound in the specified array, put it at the first index that\n * is free, or add it at the end if no element is free\n * (\"free\" means that the gdjs.HowlerSound can be destroyed).\n *\n * @param arr The array containing the sounds.\n * @param arr The gdjs.HowlerSound to add.\n * @return The gdjs.HowlerSound that have been added (i.e: the second parameter).\n */\n private _storeSoundInArray(\n arr: Array<HowlerSound>,\n sound: HowlerSound\n ): HowlerSound {\n // Try to recycle an old sound.\n for (let i = 0, len = arr.length; i < len; ++i) {\n if (!arr[i] || arr[i].stopped()) {\n arr[i] = sound;\n return sound;\n }\n }\n\n arr.push(sound);\n return sound;\n }\n\n /**\n * Creates a new gdjs.HowlerSound using preloaded/cached Howl instances.\n * @param soundName The name of the file or resource to play.\n * @param isMusic True if a music, false if a sound.\n * @param volume Between 0 and 1.\n * @param loop True if it should be played looping.\n * @param rate speed at which it is played.\n */\n createHowlerSound(\n soundName: string,\n isMusic: boolean,\n volume: float,\n loop: boolean,\n rate: float\n ): HowlerSound {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n let howl = cacheContainer.get(resource);\n if (!howl) {\n const fileName = resource ? resource.file : soundName;\n howl = new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(fileName)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n fileName\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n );\n cacheContainer.set(resource, howl);\n }\n\n return new gdjs.HowlerSound(howl, volume, loop, rate);\n }\n\n /**\n * Preloads a sound or a music in memory.\n * @param soundName The name of the file or resource to preload.\n * @param isMusic True if a music, false if a sound.\n */\n loadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n // Do not reload if it is already loaded.\n if (cacheContainer.get(resource)) {\n return;\n }\n\n cacheContainer.set(\n resource,\n new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(resource.file)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n )\n );\n }\n\n /**\n * Unloads a sound or a music from memory. This will stop any sound/music using it.\n * @param soundName The name of the file or resource to unload.\n * @param isMusic True if a music, false if a sound.\n */\n unloadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n const howl = cacheContainer.get(resource);\n if (!howl) {\n return;\n }\n\n // Make sure any sound using the howl is deleted so\n // that the howl can be garbage collected\n // and no weird \"zombies\" using the unloaded howl can exist.\n function clearContainer(howlerSoundContainer: HowlerSound[]) {\n for (let i in howlerSoundContainer) {\n if (\n howlerSoundContainer[i] &&\n //@ts-ignore We really need to access the raw howl here.\n howlerSoundContainer[i]._howl === howl\n ) {\n howlerSoundContainer[i].stop();\n delete howlerSoundContainer[i];\n }\n }\n }\n\n clearContainer(this._freeMusics);\n clearContainer(this._freeSounds);\n clearContainer(Object.values(this._musics));\n clearContainer(Object.values(this._sounds));\n clearContainer(this._pausedSounds);\n\n howl.unload();\n cacheContainer.delete(resource);\n }\n\n /**\n * Unloads all audio from memory.\n * This will clear the Howl cache.\n * This will also stop any running music or sounds.\n */\n unloadAll() {\n Howler.unload();\n\n // Clean up old sounds that still have the dead Howl instances.\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n this._loadedMusics.clear();\n this._loadedSounds.clear();\n }\n\n playSound(soundName: string, loop: boolean, volume: float, pitch: float) {\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeSounds, sound);\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n playSoundOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._sounds[channel]) this._sounds[channel].stop();\n\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._sounds[channel] = sound;\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n getSoundOnChannel(channel: integer): HowlerSound | null {\n return this._sounds[channel] || null;\n }\n\n playMusic(soundName: string, loop: boolean, volume: float, pitch: float) {\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeMusics, music);\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n playMusicOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._musics[channel]) this._musics[channel].stop();\n\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._musics[channel] = music;\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n getMusicOnChannel(channel: integer): HowlerSound | null {\n return this._musics[channel] || null;\n }\n\n setGlobalVolume(volume: float): void {\n this._globalVolume = volume;\n if (this._globalVolume > 100) {\n this._globalVolume = 100;\n }\n if (this._globalVolume < 0) {\n this._globalVolume = 0;\n }\n Howler.volume(this._globalVolume / 100);\n }\n\n getGlobalVolume(): float {\n return this._globalVolume;\n }\n\n clearAll() {\n Howler.stop();\n\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because sounds are light enough to be parsed in background.\n }\n\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find audio for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (resource.file) {\n if (this._availableResources[resource.name]) {\n return;\n }\n\n this._availableResources[resource.name] = resource;\n }\n\n const preloadAudioFile = (\n file: string,\n isMusic: boolean\n ): Promise<number> => {\n return new Promise((resolve, reject) => {\n const container = isMusic ? this._loadedMusics : this._loadedSounds;\n container[file] = new Howl(\n Object.assign({}, HowlParameters, {\n src: [this._resourceLoader.getFullUrl(file)],\n onload: resolve,\n onloaderror: (soundId: number, error?: string) => reject(error),\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n })\n );\n });\n };\n\n const file = resource.file;\n if (resource.preloadAsMusic) {\n try {\n await preloadAudioFile(file, /* isMusic= */ true);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n\n if (resource.preloadAsSound) {\n try {\n await preloadAudioFile(file, /* isMusic= */ false);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n } else if (\n resource.preloadInCache ||\n // Force downloading of sounds.\n // TODO Decide if sounds should be allowed to be downloaded after the scene starts.\n // - they should be requested automatically at the end of the scene loading\n // - they will be downloaded while the scene is playing\n // - other scenes will be pre-loaded only when all the sounds for the current scene are in cache\n !resource.preloadAsMusic\n ) {\n // preloading as sound already does a XHR request, hence \"else if\"\n try {\n await new Promise((resolve, reject) => {\n const sound = new XMLHttpRequest();\n sound.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n file\n );\n sound.addEventListener('load', resolve);\n sound.addEventListener('error', (_) =>\n reject('XHR error: ' + file)\n );\n sound.addEventListener('abort', (_) =>\n reject('XHR abort: ' + file)\n );\n sound.open('GET', this._resourceLoader.getFullUrl(file));\n sound.send();\n });\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n }\n }\n\n // Register the class to let the engine use it.\n export const SoundManager = HowlerSoundManager;\n export type SoundManager = HowlerSoundManager;\n}\n"],
5
- "mappings": "AAMA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,iBAEzB,EAAqC,CAAC,SAEtC,EAA8B,CAClC,QAAS,GACT,YAAa,CAAC,EAAG,IACf,EAAO,MAAM,6BAA+B,GAC9C,YAAa,CAAC,EAAG,IACf,EAAO,MAAM,sCAAwC,IAMnD,EAAc,AAAC,GACf,EAAS,EACJ,EAEL,EAAS,EACJ,EAEF,EAYF,OAAkB,CA6CvB,YAAY,EAAY,EAAe,EAAe,EAAa,CAzC3D,SAAsB,KAkCtB,eAAiC,GAKjC,aAA+B,GAGrC,KAAK,MAAQ,EACb,KAAK,eAAiB,EAAY,GAClC,KAAK,MAAQ,EACb,KAAK,MAAQ,EAMf,UAAoB,CAClB,MAAO,MAAK,MAAM,UAAY,SAOhC,MAAa,CACX,GAAI,KAAK,WAAY,CACnB,KAAM,GAAQ,KAAK,MAAM,KACvB,KAAK,MAAQ,KAAO,YAAc,KAAK,KAEzC,KAAK,IAAM,EAGX,KAAK,MAAM,OAAO,KAAK,eAAgB,GACvC,KAAK,MAAM,KAAK,KAAK,MAAO,GAG5B,KAAK,MAAM,KAAK,EAAK,mBAAmB,UAAU,KAAK,OAAQ,GAM/D,KAAK,QAAQ,QAAQ,AAAC,GAAS,CAE7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AQ,GAAI,gBAClB,EAAM,gBAAkB,KAAK,gBAAgB,2BAC3C,GAEF,EAAM,iBAAiB,OAAQ,GAC/B,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,KAAK,MAAO,KAAK,gBAAgB,WAAW,IAClD,EAAM,eAED,EAAP,CACA,EAAO,KACL,sDAAwD,KAlf3D,EAAM,qBA0fA,eAAe,IAn2BpB",
4
+ "sourcesContent": ["///<reference path='../types/howler'>\n/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Audio manager');\n\n const resourceKinds: Array<ResourceKind> = ['audio'];\n\n const HowlParameters: HowlOptions = {\n preload: true,\n onplayerror: (_, error) =>\n logger.error(\"Can't play an audio file: \" + error),\n onloaderror: (_, error) =>\n logger.error('Error while loading an audio file: ' + error),\n };\n\n /**\n * Ensure the volume is between 0 and 1.\n */\n const clampVolume = (volume: float): float => {\n if (volume > 1.0) {\n return 1.0;\n }\n if (volume < 0) {\n return 0;\n }\n return volume;\n };\n\n /**\n * A thin wrapper around a Howl object with:\n * * Handling of callbacks when the sound is not yet loaded.\n * * Automatic clamping when calling `setRate` to ensure a valid value is passed to Howler.js.\n * * Automatic clamping when calling `setVolume` so that the volume is always between 0 and 1.\n *\n * @memberof gdjs\n * @class HowlerSound\n */\n export class HowlerSound {\n /**\n * The ID of the played sound.\n */\n private _id: integer | null = null;\n\n /**\n * The Howl passed to the constructor.\n * It defines the sound file that is being played.\n */\n private _howl: Howl;\n\n /**\n * The **initial** volume at which the sound is being played.\n * Once the sound is started, this volume can be not in sync\n * (in the case the sound is faded by Howler), so volume must\n * be gotten from `this._howl` directly.\n *\n * This value is clamped between 0 and 1.\n */\n private _initialVolume: float;\n\n /**\n * Whether the sound is being played in a loop or not.\n */\n private _loop: boolean;\n\n /**\n * The rate (speed) the sound is being played at.\n * This value is not clamped, though technically Howler.js will only\n * accepts values between a specific range (so we clamp this when\n * passing it to Howler.js, but keep the original value here).\n */\n private _rate: float;\n\n /**\n * An array of callbacks to call once the sound starts to play.\n */\n private _oncePlay: Array<HowlCallback> = [];\n\n /**\n * An array of callbacks to call everytime the sound starts to play.\n */\n private _onPlay: Array<HowlCallback> = [];\n\n constructor(howl: Howl, volume: float, loop: boolean, rate: float) {\n this._howl = howl;\n this._initialVolume = clampVolume(volume);\n this._loop = loop;\n this._rate = rate;\n }\n\n /**\n * Returns true if the associated howl is fully loaded.\n */\n isLoaded(): boolean {\n return this._howl.state() === 'loaded';\n }\n\n /**\n * Begins playback of the sound, or if the Howl is still loading, schedule playing for once it loads.\n * @returns The current instance for chaining.\n */\n play(): this {\n if (this.isLoaded()) {\n const newID = this._howl.play(\n this._id === null ? '__default' : this._id\n );\n this._id = newID;\n\n // Set the howl properties as soon as the sound is played and we have its ID.\n this._howl.volume(this._initialVolume, newID); // this._initialVolume is already clamped between 0 and 1.\n this._howl.loop(this._loop, newID);\n // this._rate is not clamped, but we need to clamp it when passing it to Howler.js as it\n // only supports a specific range.\n this._howl.rate(gdjs.HowlerSoundManager.clampRate(this._rate), newID);\n\n // Manually handle the play event before we have an ID.\n // Before loading, howler won't register events as without an ID we cannot set a listener.\n // Once we have an ID, we can transfer control of the events to howler.\n // We also need to call them once as Howler doesn't for the first play event.\n this._onPlay.forEach((func) => {\n // Transfer the event to howler now that we have an ID\n this.on('play', func);\n func(newID);\n });\n this._oncePlay.forEach((func) => func(newID));\n this._onPlay = [];\n this._oncePlay = [];\n } else this._howl.once('load', () => this.play()); // Play only once the howl is fully loaded\n\n return this;\n }\n\n /**\n * Pauses playback of the sound, saving the seek of playback.\n * @returns The current instance for chaining.\n */\n pause(): this {\n if (this._id !== null) this._howl.pause(this._id);\n return this;\n }\n\n /**\n * Stops playback of the sound, resetting seek to 0.\n * @returns The current instance for chaining.\n */\n stop(): this {\n if (this._id !== null) this._howl.stop(this._id);\n return this;\n }\n\n /**\n * Check if the sound is currently playing.\n * Note that a loading sound is considered as playing (as it will be\n * played as soon as it's loaded). To avoid loading at runtime, prefer\n * to preload the sounds.\n */\n playing(): boolean {\n return (\n (this._id !== null ? this._howl.playing(this._id) : true) ||\n !this.isLoaded() // Loading is considered playing\n );\n }\n\n /**\n * Check if the sound is currently paused.\n */\n paused(): boolean {\n return !this.playing();\n }\n\n /**\n * Check if the sound is currently stopped.\n */\n stopped(): boolean {\n return this.paused() && this.getSeek() === 0;\n }\n\n /**\n * Get the sound playback rate. This 1 for the default speed.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n */\n getRate(): float {\n return this._rate;\n }\n\n /**\n * Set the playback rate.\n * This value is not clamped (any value greater than 0 is valid),\n * but the underlying audio system might not play the sound at the required\n * rate if it's very low or very high.\n * @returns The current instance for chaining.\n */\n setRate(rate: float): this {\n this._rate = rate;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) {\n rate = gdjs.HowlerSoundManager.clampRate(rate);\n this._howl.rate(rate, this._id);\n }\n return this;\n }\n\n /**\n * Get if the sound is looping.\n */\n getLoop(): boolean {\n return this._loop;\n }\n\n /**\n * Set if the sound is looping.\n * @returns The current instance for chaining.\n */\n setLoop(loop: boolean): this {\n this._loop = loop;\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.loop(loop, this._id);\n return this;\n }\n\n //TODO: Replace float type in those 2 methods with RangeOf<0..1> once it is standardized (https://github.com/Microsoft/TypeScript/issues/15480)\n /**\n * Get the sound volume.\n * @returns A float from 0 to 1.\n */\n getVolume(): float {\n if (this._id === null) return this._initialVolume;\n return this._howl.volume(this._id);\n }\n\n /**\n * Set the sound volume.\n * @param volume A float from 0 to 1. The value is clamped if too high or too low.\n * @returns The current instance for chaining.\n */\n setVolume(volume: float): this {\n this._initialVolume = clampVolume(volume);\n\n // If the sound has already started playing, then change the value directly.\n if (this._id !== null) this._howl.volume(this._initialVolume, this._id);\n return this;\n }\n\n /**\n * Get if the sound is muted.\n */\n getMute(): boolean {\n if (this._id === null) return false;\n return this._howl.mute(this._id);\n }\n\n /**\n * Set if the sound is muted.\n * @returns The current instance for chaining.\n */\n setMute(mute: boolean): this {\n if (this._id !== null) this._howl.mute(mute, this._id);\n return this;\n }\n\n /**\n * Get the sound seek.\n */\n getSeek(): float {\n if (this._id === null) return 0;\n return this._howl.seek(this._id);\n }\n\n /**\n * Set the sound seek.\n * @returns The current instance for chaining.\n */\n setSeek(seek: float): this {\n if (this._id !== null) this._howl.seek(seek, this._id);\n return this;\n }\n\n /**\n * Get the sound spatial position.\n */\n getSpatialPosition(axis: 'x' | 'y' | 'z'): float {\n if (this._id === null) return 0;\n return this._howl.pos(this._id)[axis === 'x' ? 0 : axis === 'y' ? 1 : 2];\n }\n\n /**\n * Set the sound spatial position.\n * @returns The current instance for chaining.\n */\n setSpatialPosition(x: float, y: float, z: float): this {\n if (this._id !== null) this._howl.pos(x, y, z, this._id);\n return this;\n }\n\n /**\n * Fade the volume sound.\n * @returns The current instance for chaining.\n */\n fade(from: float, to: float, duration: float): this {\n if (this._id !== null)\n this._howl.fade(clampVolume(from), clampVolume(to), duration, this._id);\n return this;\n }\n\n /**\n * Adds an event listener to the howl.\n */\n on(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._onPlay.push(handler);\n } else {\n this._howl.on(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.on(event, handler));\n else this._howl.on(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Adds an event listener to the howl that removes itself after being called.\n * If the event is `play` and the sound is being played, the handler is\n * called synchronously.\n */\n once(event: HowlEvent, handler: HowlCallback): this {\n if (event === 'play') {\n if (this._id === null) {\n this._oncePlay.push(handler);\n } else if (this.playing()) {\n // Immediately call the handler if the sound is already playing.\n // This is useful for sounds that were just started and have a `.once('play', ...)`\n // handler added on them to set up the volume/rate/loop. If we don't do it\n // synchronously, the sound can play for a tiny bit at the default volume and rate.\n // See https://github.com/4ian/GDevelop/issues/2490.\n handler(this._id);\n } else {\n this._howl.once(event, handler, this._id);\n }\n } else if (this._id === null)\n this.once('play', () => this.once(event, handler));\n else this._howl.once(event, handler, this._id);\n\n return this;\n }\n\n /**\n * Removes an event listener to the howl.\n */\n off(event: HowlEvent, handler: HowlCallback): this {\n if (this._id !== null) this._howl.off(event, handler, this._id);\n return this;\n }\n }\n\n /**\n * HowlerSoundManager is used to manage the sounds and musics of a RuntimeScene.\n *\n * It is basically a container to associate channels to sounds and keep a list\n * of all sounds being played.\n */\n export class HowlerSoundManager {\n _loadedMusics = new gdjs.ResourceCache<Howl>();\n _loadedSounds = new gdjs.ResourceCache<Howl>();\n _availableResources: Record<string, ResourceData> = {};\n _globalVolume: float = 100;\n _sounds: Record<integer, HowlerSound> = {};\n _musics: Record<integer, HowlerSound> = {};\n _freeSounds: HowlerSound[] = []; // Sounds without an assigned channel.\n _freeMusics: HowlerSound[] = []; // Musics without an assigned channel.\n\n /** Paused sounds or musics that should be played once the game is resumed. */\n _pausedSounds: HowlerSound[] = [];\n _paused: boolean = false;\n\n _resourceLoader: gdjs.ResourceLoader;\n\n /**\n * @param resources The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n\n const that = this;\n document.addEventListener('deviceready', function () {\n // pause/resume sounds in Cordova when the app is being paused/resumed\n document.addEventListener(\n 'pause',\n function () {\n const soundList = that._freeSounds.concat(that._freeMusics);\n for (let key in that._sounds) {\n if (that._sounds.hasOwnProperty(key)) {\n soundList.push(that._sounds[key]);\n }\n }\n for (let key in that._musics) {\n if (that._musics.hasOwnProperty(key)) {\n soundList.push(that._musics[key]);\n }\n }\n for (let i = 0; i < soundList.length; i++) {\n const sound = soundList[i];\n if (!sound.paused() && !sound.stopped()) {\n sound.pause();\n that._pausedSounds.push(sound);\n }\n }\n that._paused = true;\n },\n false\n );\n document.addEventListener(\n 'resume',\n function () {\n try {\n for (let i = 0; i < that._pausedSounds.length; i++) {\n const sound = that._pausedSounds[i];\n if (!sound.stopped()) {\n sound.play();\n }\n }\n } catch (error) {\n if (\n error.message &&\n typeof error.message === 'string' &&\n error.message.startsWith('Maximum call stack size exceeded')\n ) {\n console.warn(\n 'An error occurred when resuming paused sounds while the game was in background:',\n error\n );\n } else {\n throw error;\n }\n }\n that._pausedSounds.length = 0;\n that._paused = false;\n },\n false\n );\n });\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Ensure rate is in a range valid for Howler.js\n * @return The clamped rate\n */\n static clampRate(rate: float): float {\n if (rate > 4.0) {\n return 4.0;\n }\n if (rate < 0.5) {\n return 0.5;\n }\n return rate;\n }\n\n /**\n * Return the file associated to the given sound name.\n *\n * Names and files are loaded from resources when preloadAudio is called. If no\n * file is associated to the given name, then the name will be considered as a\n * filename and will be returned.\n *\n * @return The associated resource\n */\n private _getAudioResource = (resourceName: string): ResourceData => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : ({\n file: resourceName,\n kind: 'audio',\n metadata: '',\n name: resourceName,\n } as ResourceData);\n };\n\n /**\n * Store the sound in the specified array, put it at the first index that\n * is free, or add it at the end if no element is free\n * (\"free\" means that the gdjs.HowlerSound can be destroyed).\n *\n * @param arr The array containing the sounds.\n * @param arr The gdjs.HowlerSound to add.\n * @return The gdjs.HowlerSound that have been added (i.e: the second parameter).\n */\n private _storeSoundInArray(\n arr: Array<HowlerSound>,\n sound: HowlerSound\n ): HowlerSound {\n // Try to recycle an old sound.\n for (let i = 0, len = arr.length; i < len; ++i) {\n if (!arr[i] || arr[i].stopped()) {\n arr[i] = sound;\n return sound;\n }\n }\n\n arr.push(sound);\n return sound;\n }\n\n /**\n * Creates a new gdjs.HowlerSound using preloaded/cached Howl instances.\n * @param soundName The name of the file or resource to play.\n * @param isMusic True if a music, false if a sound.\n * @param volume Between 0 and 1.\n * @param loop True if it should be played looping.\n * @param rate speed at which it is played.\n */\n createHowlerSound(\n soundName: string,\n isMusic: boolean,\n volume: float,\n loop: boolean,\n rate: float\n ): HowlerSound {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n let howl = cacheContainer.get(resource);\n if (!howl) {\n const fileName = resource ? resource.file : soundName;\n howl = new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(fileName)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n fileName\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n );\n cacheContainer.set(resource, howl);\n }\n\n return new gdjs.HowlerSound(howl, volume, loop, rate);\n }\n\n /**\n * Preloads a sound or a music in memory.\n * @param soundName The name of the file or resource to preload.\n * @param isMusic True if a music, false if a sound.\n */\n loadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n // Do not reload if it is already loaded.\n if (cacheContainer.get(resource)) {\n return;\n }\n\n cacheContainer.set(\n resource,\n new Howl(\n Object.assign(\n {\n src: [this._resourceLoader.getFullUrl(resource.file)],\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n },\n HowlParameters\n )\n )\n );\n }\n\n /**\n * Unloads a sound or a music from memory. This will stop any sound/music using it.\n * @param soundName The name of the file or resource to unload.\n * @param isMusic True if a music, false if a sound.\n */\n unloadAudio(soundName: string, isMusic: boolean) {\n const cacheContainer = isMusic ? this._loadedMusics : this._loadedSounds;\n const resource = this._getAudioResource(soundName);\n\n const howl = cacheContainer.get(resource);\n if (!howl) {\n return;\n }\n\n // Make sure any sound using the howl is deleted so\n // that the howl can be garbage collected\n // and no weird \"zombies\" using the unloaded howl can exist.\n function clearContainer(howlerSoundContainer: HowlerSound[]) {\n for (let i in howlerSoundContainer) {\n if (\n howlerSoundContainer[i] &&\n //@ts-ignore We really need to access the raw howl here.\n howlerSoundContainer[i]._howl === howl\n ) {\n howlerSoundContainer[i].stop();\n delete howlerSoundContainer[i];\n }\n }\n }\n\n clearContainer(this._freeMusics);\n clearContainer(this._freeSounds);\n clearContainer(Object.values(this._musics));\n clearContainer(Object.values(this._sounds));\n clearContainer(this._pausedSounds);\n\n howl.unload();\n cacheContainer.delete(resource);\n }\n\n /**\n * Unloads all audio from memory.\n * This will clear the Howl cache.\n * This will also stop any running music or sounds.\n */\n unloadAll() {\n Howler.unload();\n\n // Clean up old sounds that still have the dead Howl instances.\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n this._loadedMusics.clear();\n this._loadedSounds.clear();\n }\n\n playSound(soundName: string, loop: boolean, volume: float, pitch: float) {\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeSounds, sound);\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n playSoundOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._sounds[channel]) this._sounds[channel].stop();\n\n const sound = this.createHowlerSound(\n soundName,\n /* isMusic= */ false,\n volume / 100,\n loop,\n pitch\n );\n this._sounds[channel] = sound;\n sound.once('play', () => {\n if (this._paused) {\n sound.pause();\n this._pausedSounds.push(sound);\n }\n });\n sound.play();\n }\n\n getSoundOnChannel(channel: integer): HowlerSound | null {\n return this._sounds[channel] || null;\n }\n\n playMusic(soundName: string, loop: boolean, volume: float, pitch: float) {\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._storeSoundInArray(this._freeMusics, music);\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n playMusicOnChannel(\n soundName: string,\n channel: integer,\n loop: boolean,\n volume: float,\n pitch: float\n ) {\n if (this._musics[channel]) this._musics[channel].stop();\n\n const music = this.createHowlerSound(\n soundName,\n /* isMusic= */ true,\n volume / 100,\n loop,\n pitch\n );\n this._musics[channel] = music;\n music.once('play', () => {\n if (this._paused) {\n music.pause();\n this._pausedSounds.push(music);\n }\n });\n music.play();\n }\n\n getMusicOnChannel(channel: integer): HowlerSound | null {\n return this._musics[channel] || null;\n }\n\n setGlobalVolume(volume: float): void {\n this._globalVolume = volume;\n if (this._globalVolume > 100) {\n this._globalVolume = 100;\n }\n if (this._globalVolume < 0) {\n this._globalVolume = 0;\n }\n Howler.volume(this._globalVolume / 100);\n }\n\n getGlobalVolume(): float {\n return this._globalVolume;\n }\n\n clearAll() {\n Howler.stop();\n\n this._freeSounds.length = 0;\n this._freeMusics.length = 0;\n this._sounds = {};\n this._musics = {};\n this._pausedSounds.length = 0;\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because sounds are light enough to be parsed in background.\n }\n\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find audio for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (resource.file) {\n if (this._availableResources[resource.name]) {\n return;\n }\n\n this._availableResources[resource.name] = resource;\n }\n\n const preloadAudioFile = (\n file: string,\n isMusic: boolean\n ): Promise<number> => {\n return new Promise((resolve, reject) => {\n const container = isMusic ? this._loadedMusics : this._loadedSounds;\n container[file] = new Howl(\n Object.assign({}, HowlParameters, {\n src: [this._resourceLoader.getFullUrl(file)],\n onload: resolve,\n onloaderror: (soundId: number, error?: string) => reject(error),\n html5: isMusic,\n xhr: {\n withCredentials: this._resourceLoader.checkIfCredentialsRequired(\n file\n ),\n },\n // Cache the sound with no volume. This avoids a bug where it plays at full volume\n // for a split second before setting its correct volume.\n volume: 0,\n })\n );\n });\n };\n\n const file = resource.file;\n if (resource.preloadAsMusic) {\n try {\n await preloadAudioFile(file, /* isMusic= */ true);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n\n if (resource.preloadAsSound) {\n try {\n await preloadAudioFile(file, /* isMusic= */ false);\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n } else if (\n resource.preloadInCache ||\n // Force downloading of sounds.\n // TODO Decide if sounds should be allowed to be downloaded after the scene starts.\n // - they should be requested automatically at the end of the scene loading\n // - they will be downloaded while the scene is playing\n // - other scenes will be pre-loaded only when all the sounds for the current scene are in cache\n !resource.preloadAsMusic\n ) {\n // preloading as sound already does a XHR request, hence \"else if\"\n try {\n await new Promise((resolve, reject) => {\n const sound = new XMLHttpRequest();\n sound.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n file\n );\n sound.addEventListener('load', resolve);\n sound.addEventListener('error', (_) =>\n reject('XHR error: ' + file)\n );\n sound.addEventListener('abort', (_) =>\n reject('XHR abort: ' + file)\n );\n sound.open('GET', this._resourceLoader.getFullUrl(file));\n sound.send();\n });\n } catch (error) {\n logger.warn(\n 'There was an error while preloading an audio file: ' + error\n );\n }\n }\n }\n\n /**\n * To be called when the game is disposed.\n * Unloads all audio from memory, clear Howl cache and stop all audio.\n */\n dispose(): void {\n this.unloadAll();\n }\n }\n\n // Register the class to let the engine use it.\n export const SoundManager = HowlerSoundManager;\n export type SoundManager = HowlerSoundManager;\n}\n"],
5
+ "mappings": "AAMA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,iBAEzB,EAAqC,CAAC,SAEtC,EAA8B,CAClC,QAAS,GACT,YAAa,CAAC,EAAG,IACf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AK,oBAAoB,EAAS,MAAQ,EAG5C,KAAM,GAAmB,CACvB,EACA,IAEO,GAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,KAAM,GAAY,EAAU,KAAK,cAAgB,KAAK,cACtD,EAAU,GAAQ,GAAI,MACpB,OAAO,OAAO,GAAI,EAAgB,CAChC,IAAK,CAAC,KAAK,gBAAgB,WAAW,IACtC,OAAQ,EACR,YAAa,CAAC,EAAiB,IAAmB,EAAO,GACzD,MAAO,EACP,IAAK,CACH,gBAAiB,KAAK,gBAAgB,2BACpC,IAKJ,OAAQ,OAMV,EAAO,EAAS,KACtB,GAAI,EAAS,eACX,GAAI,CACF,KAAM,GAAiB,EAAqB,UACrC,EAAP,CACA,EAAO,KACL,sDAAwD,GAK9D,GAAI,EAAS,eACX,GAAI,CACF,KAAM,GAAiB,EAAqB,UACrC,EAAP,CACA,EAAO,KACL,sDAAwD,WAI5D,EAAS,gBAMT,CAAC,EAAS,eAGV,GAAI,CACF,KAAM,IAAI,SAAQ,CAAC,EAAS,IAAW,CACrC,KAAM,GAAQ,GAAI,gBAClB,EAAM,gBAAkB,KAAK,gBAAgB,2BAC3C,GAEF,EAAM,iBAAiB,OAAQ,GAC/B,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,iBAAiB,QAAS,AAAC,GAC/B,EAAO,cAAgB,IAEzB,EAAM,KAAK,MAAO,KAAK,gBAAgB,WAAW,IAClD,EAAM,eAED,EAAP,CACA,EAAO,KACL,sDAAwD,IAUhE,SAAgB,CACd,KAAK,aA7fF,EAAM,qBAkgBA,eAAe,IA32BpB",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(c){const l=new c.Logger("JSON Manager"),u=["json","tilemap","tileset"];class i{constructor(r){this._loadedJsons=new c.ResourceCache;this._callbacks=new c.ResourceCache;this._getJsonResource=r=>{const s=this._resourceLoader.getResource(r);return s&&this.getResourceKinds().includes(s.kind)?s:null};this._resourceLoader=r}getResourceKinds(){return u}async loadResource(r){const s=this._resourceLoader.getResource(r);if(!s){l.warn('Unable to find json for resource "'+r+'".');return}if(!s.disablePreload)try{await this.loadJsonAsync(s.name)}catch(e){l.error(`Error while preloading json resource ${s.name}:`,e)}}loadJsonAsync(r){const s=this;return new Promise((e,t)=>{s.loadJson(r,(o,n)=>{o&&t(o.message),e(n)})})}async processResource(r){}loadJson(r,s){const e=this._getJsonResource(r);if(!e){s(new Error(`Can't find resource with name: "`+r+'" (or is not a json resource).'),null);return}if(this._loadedJsons.get(e)){s(null,this._loadedJsons.get(e));return}{const n=this._callbacks.get(e);if(n){n.push(s);return}else this._callbacks.set(e,[s])}const t=this,o=new XMLHttpRequest;o.responseType="json",o.withCredentials=this._resourceLoader.checkIfCredentialsRequired(e.file),o.open("GET",this._resourceLoader.getFullUrl(e.file)),o.onload=function(){const n=t._callbacks.get(e);if(!!n){if(o.status!==200){for(const a of n)a(new Error("HTTP error: "+o.status+"("+o.statusText+")"),null);t._callbacks.delete(e);return}t._loadedJsons.set(e,o.response);for(const a of n)a(null,o.response);t._callbacks.delete(e)}},o.onerror=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Network error"),null);t._callbacks.delete(e)}},o.onabort=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Request aborted"),null);t._callbacks.delete(e)}},o.send()}isJsonLoaded(r){return!!this._loadedJsons.getFromName(r)}getLoadedJson(r){return this._loadedJsons.getFromName(r)||null}}c.JsonManager=i})(gdjs||(gdjs={}));
1
+ var gdjs;(function(c){const l=new c.Logger("JSON Manager"),i=["json","tilemap","tileset"];class u{constructor(s){this._loadedJsons=new c.ResourceCache;this._callbacks=new c.ResourceCache;this._getJsonResource=s=>{const r=this._resourceLoader.getResource(s);return r&&this.getResourceKinds().includes(r.kind)?r:null};this._resourceLoader=s}getResourceKinds(){return i}async loadResource(s){const r=this._resourceLoader.getResource(s);if(!r){l.warn('Unable to find json for resource "'+s+'".');return}if(!r.disablePreload)try{await this.loadJsonAsync(r.name)}catch(e){l.error(`Error while preloading json resource ${r.name}:`,e)}}loadJsonAsync(s){const r=this;return new Promise((e,t)=>{r.loadJson(s,(o,n)=>{o&&t(o.message),e(n)})})}async processResource(s){}loadJson(s,r){const e=this._getJsonResource(s);if(!e){r(new Error(`Can't find resource with name: "`+s+'" (or is not a json resource).'),null);return}if(this._loadedJsons.get(e)){r(null,this._loadedJsons.get(e));return}{const n=this._callbacks.get(e);if(n){n.push(r);return}else this._callbacks.set(e,[r])}const t=this,o=new XMLHttpRequest;o.responseType="json",o.withCredentials=this._resourceLoader.checkIfCredentialsRequired(e.file),o.open("GET",this._resourceLoader.getFullUrl(e.file)),o.onload=function(){const n=t._callbacks.get(e);if(!!n){if(o.status!==200){for(const a of n)a(new Error("HTTP error: "+o.status+"("+o.statusText+")"),null);t._callbacks.delete(e);return}t._loadedJsons.set(e,o.response);for(const a of n)a(null,o.response);t._callbacks.delete(e)}},o.onerror=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Network error"),null);t._callbacks.delete(e)}},o.onabort=function(){const n=t._callbacks.get(e);if(!!n){for(const a of n)a(new Error("Request aborted"),null);t._callbacks.delete(e)}},o.send()}isJsonLoaded(s){return!!this._loadedJsons.getFromName(s)}getLoadedJson(s){return this._loadedJsons.getFromName(s)||null}dispose(){this._loadedJsons.clear(),this._callbacks.clear()}}c.JsonManager=u})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=jsonmanager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../GDevelop/GDJS/Runtime/jsonmanager.ts"],
4
- "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('JSON Manager');\n\n /** The callback called when a json that was requested is loaded (or an error occurred). */\n export type JsonManagerRequestCallback = (\n error: Error | null,\n content: Object | null\n ) => void;\n\n const resourceKinds: Array<ResourceKind> = ['json', 'tilemap', 'tileset'];\n /**\n * JsonManager loads json files (using `XMLHttpRequest`), using the \"json\" resources\n * registered in the game resources.\n *\n * Contrary to audio/fonts, json files are loaded asynchronously, when requested.\n * You should properly handle errors, and give the developer/player a way to know\n * that loading failed.\n */\n export class JsonManager implements gdjs.ResourceManager {\n _resourceLoader: ResourceLoader;\n\n _loadedJsons = new gdjs.ResourceCache<Object>();\n _callbacks = new gdjs.ResourceCache<Array<JsonManagerRequestCallback>>();\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Request all the json resources to be preloaded (unless they are marked as not preloaded).\n *\n * Note that even if a JSON is already loaded, it will be reloaded (useful for hot-reloading,\n * as JSON files can have been modified without the editor knowing).\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find json for resource \"' + resourceName + '\".');\n return;\n }\n if (resource.disablePreload) {\n return;\n }\n\n try {\n await this.loadJsonAsync(resource.name);\n } catch (error) {\n logger.error(\n `Error while preloading json resource ${resource.name}:`,\n error\n );\n }\n }\n\n loadJsonAsync(resourceName: string): Promise<Object | null> {\n const that = this;\n return new Promise((resolve, reject) => {\n that.loadJson(resourceName, (error, content) => {\n if (error) {\n reject(error.message);\n }\n resolve(content);\n });\n });\n }\n\n private _getJsonResource = (resourceName: string): ResourceData | null => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n };\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because json are light enough to be parsed in background.\n }\n\n /**\n * Request the json file from the given resource name.\n * This method is asynchronous. When loaded, the `callback` is called with the error\n * (null if none) and the loaded json (a JS Object).\n *\n * @param resourceName The resource pointing to the json file to load.\n * @param callback The callback function called when json is loaded (or an error occurred).\n */\n loadJson(resourceName: string, callback: JsonManagerRequestCallback): void {\n const resource = this._getJsonResource(resourceName);\n if (!resource) {\n callback(\n new Error(\n 'Can\\'t find resource with name: \"' +\n resourceName +\n '\" (or is not a json resource).'\n ),\n null\n );\n return;\n }\n\n // Don't fetch again an object that is already in memory\n if (this._loadedJsons.get(resource)) {\n callback(null, this._loadedJsons.get(resource));\n return;\n }\n // Don't fetch again an object that is already being fetched.\n {\n const callbacks = this._callbacks.get(resource);\n if (callbacks) {\n callbacks.push(callback);\n return;\n } else {\n this._callbacks.set(resource, [callback]);\n }\n }\n\n const that = this;\n const xhr = new XMLHttpRequest();\n xhr.responseType = 'json';\n xhr.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n );\n xhr.open('GET', this._resourceLoader.getFullUrl(resource.file));\n xhr.onload = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n if (xhr.status !== 200) {\n for (const callback of callbacks) {\n callback(\n new Error(\n 'HTTP error: ' + xhr.status + '(' + xhr.statusText + ')'\n ),\n null\n );\n }\n that._callbacks.delete(resource);\n return;\n }\n\n // Cache the result\n that._loadedJsons.set(resource, xhr.response);\n for (const callback of callbacks) {\n callback(null, xhr.response);\n }\n that._callbacks.delete(resource);\n };\n xhr.onerror = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Network error'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.onabort = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Request aborted'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.send();\n }\n\n /**\n * Check if the given json resource was loaded (preloaded or loaded with `loadJson`).\n * @param resourceName The name of the json resource.\n * @returns true if the content of the json resource is loaded. false otherwise.\n */\n isJsonLoaded(resourceName: string): boolean {\n return !!this._loadedJsons.getFromName(resourceName);\n }\n\n /**\n * Get the object for the given resource that is already loaded (preloaded or loaded with `loadJson`).\n * If the resource is not loaded, `null` will be returned.\n *\n * @param resourceName The name of the json resource.\n * @returns the content of the json resource, if loaded. `null` otherwise.\n */\n getLoadedJson(resourceName: string): Object | null {\n return this._loadedJsons.getFromName(resourceName) || null;\n }\n }\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,gBAQzB,EAAqC,CAAC,OAAQ,UAAW,WASxD,OAAkD,CAUvD,YAAY,EAAqC,CAPjD,kBAAe,GAAI,GAAK,cACxB,gBAAa,GAAI,GAAK,cAoDd,sBAAmB,AAAC,GAA8C,CACxE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,MAjDJ,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,QASH,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KAAK,qCAAuC,EAAe,MAClE,OAEF,GAAI,GAAS,eAIb,GAAI,CACF,KAAM,MAAK,cAAc,EAAS,YAC3B,EAAP,CACA,EAAO,MACL,wCAAwC,EAAS,QACjD,IAKN,cAAc,EAA8C,CAC1D,KAAM,GAAO,KACb,MAAO,IAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,EAAK,SAAS,EAAc,CAAC,EAAO,IAAY,CAC9C,AAAI,GACF,EAAO,EAAM,SAEf,EAAQ,YAYR,iBAAgB,EAAqC,EAY3D,SAAS,EAAsB,EAA4C,CACzE,KAAM,GAAW,KAAK,iBAAiB,GACvC,GAAI,CAAC,EAAU,CACb,EACE,GAAI,OACF,mCACE,EACA,kCAEJ,MAEF,OAIF,GAAI,KAAK,aAAa,IAAI,GAAW,CACnC,EAAS,KAAM,KAAK,aAAa,IAAI,IACrC,OAGF,CACE,KAAM,GAAY,KAAK,WAAW,IAAI,GACtC,GAAI,EAAW,CACb,EAAU,KAAK,GACf,WAEA,MAAK,WAAW,IAAI,EAAU,CAAC,IAInC,KAAM,GAAO,KACP,EAAM,GAAI,gBAChB,EAAI,aAAe,OACnB,EAAI,gBAAkB,KAAK,gBAAgB,2BACzC,EAAS,MAEX,EAAI,KAAK,MAAO,KAAK,gBAAgB,WAAW,EAAS,OACzD,EAAI,OAAS,UAAY,CACvB,KAAM,GAAY,EAAK,WAAW,IAAI,GACtC,GAAI,EAAC,EAGL,IAAI,EAAI,SAAW,IAAK,CACtB,SAAW,KAAY,GACrB,EACE,GAAI,OACF,eAAiB,EAAI,OAAS,IAAM,EAAI,WAAa,KAEvD,MAGJ,EAAK,WAAW,OAAO,GACvB,OAIF,EAAK,aAAa,IAAI,EAAU,EAAI,UACpC,SAAW,KAAY,GACrB,EAAS,KAAM,EAAI,UAErB,EAAK,WAAW,OAAO,KAEzB,EAAI,QAAU,UAAY,CACxB,KAAM,GAAY,EAAK,WAAW,IAAI,GACtC,GAAI,EAAC,EAGL,UAAW,KAAY,GACrB,EAAS,GAAI,OAAM,iBAAkB,MAEvC,EAAK,WAAW,OAAO,KAEzB,EAAI,QAAU,UAAY,CACxB,KAAM,GAAY,EAAK,WAAW,IAAI,GACtC,GAAI,EAAC,EAGL,UAAW,KAAY,GACrB,EAAS,GAAI,OAAM,mBAAoB,MAEzC,EAAK,WAAW,OAAO,KAEzB,EAAI,OAQN,aAAa,EAA+B,CAC1C,MAAO,CAAC,CAAC,KAAK,aAAa,YAAY,GAUzC,cAAc,EAAqC,CACjD,MAAO,MAAK,aAAa,YAAY,IAAiB,MAjLnD,EAAM,gBAlBL",
4
+ "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-present Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('JSON Manager');\n\n /** The callback called when a json that was requested is loaded (or an error occurred). */\n export type JsonManagerRequestCallback = (\n error: Error | null,\n content: Object | null\n ) => void;\n\n const resourceKinds: Array<ResourceKind> = ['json', 'tilemap', 'tileset'];\n /**\n * JsonManager loads json files (using `XMLHttpRequest`), using the \"json\" resources\n * registered in the game resources.\n *\n * Contrary to audio/fonts, json files are loaded asynchronously, when requested.\n * You should properly handle errors, and give the developer/player a way to know\n * that loading failed.\n */\n export class JsonManager implements gdjs.ResourceManager {\n _resourceLoader: ResourceLoader;\n\n _loadedJsons = new gdjs.ResourceCache<Object>();\n _callbacks = new gdjs.ResourceCache<Array<JsonManagerRequestCallback>>();\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n */\n constructor(resourceLoader: gdjs.ResourceLoader) {\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Request all the json resources to be preloaded (unless they are marked as not preloaded).\n *\n * Note that even if a JSON is already loaded, it will be reloaded (useful for hot-reloading,\n * as JSON files can have been modified without the editor knowing).\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn('Unable to find json for resource \"' + resourceName + '\".');\n return;\n }\n if (resource.disablePreload) {\n return;\n }\n\n try {\n await this.loadJsonAsync(resource.name);\n } catch (error) {\n logger.error(\n `Error while preloading json resource ${resource.name}:`,\n error\n );\n }\n }\n\n loadJsonAsync(resourceName: string): Promise<Object | null> {\n const that = this;\n return new Promise((resolve, reject) => {\n that.loadJson(resourceName, (error, content) => {\n if (error) {\n reject(error.message);\n }\n resolve(content);\n });\n });\n }\n\n private _getJsonResource = (resourceName: string): ResourceData | null => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n };\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because json are light enough to be parsed in background.\n }\n\n /**\n * Request the json file from the given resource name.\n * This method is asynchronous. When loaded, the `callback` is called with the error\n * (null if none) and the loaded json (a JS Object).\n *\n * @param resourceName The resource pointing to the json file to load.\n * @param callback The callback function called when json is loaded (or an error occurred).\n */\n loadJson(resourceName: string, callback: JsonManagerRequestCallback): void {\n const resource = this._getJsonResource(resourceName);\n if (!resource) {\n callback(\n new Error(\n 'Can\\'t find resource with name: \"' +\n resourceName +\n '\" (or is not a json resource).'\n ),\n null\n );\n return;\n }\n\n // Don't fetch again an object that is already in memory\n if (this._loadedJsons.get(resource)) {\n callback(null, this._loadedJsons.get(resource));\n return;\n }\n // Don't fetch again an object that is already being fetched.\n {\n const callbacks = this._callbacks.get(resource);\n if (callbacks) {\n callbacks.push(callback);\n return;\n } else {\n this._callbacks.set(resource, [callback]);\n }\n }\n\n const that = this;\n const xhr = new XMLHttpRequest();\n xhr.responseType = 'json';\n xhr.withCredentials = this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n );\n xhr.open('GET', this._resourceLoader.getFullUrl(resource.file));\n xhr.onload = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n if (xhr.status !== 200) {\n for (const callback of callbacks) {\n callback(\n new Error(\n 'HTTP error: ' + xhr.status + '(' + xhr.statusText + ')'\n ),\n null\n );\n }\n that._callbacks.delete(resource);\n return;\n }\n\n // Cache the result\n that._loadedJsons.set(resource, xhr.response);\n for (const callback of callbacks) {\n callback(null, xhr.response);\n }\n that._callbacks.delete(resource);\n };\n xhr.onerror = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Network error'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.onabort = function () {\n const callbacks = that._callbacks.get(resource);\n if (!callbacks) {\n return;\n }\n for (const callback of callbacks) {\n callback(new Error('Request aborted'), null);\n }\n that._callbacks.delete(resource);\n };\n xhr.send();\n }\n\n /**\n * Check if the given json resource was loaded (preloaded or loaded with `loadJson`).\n * @param resourceName The name of the json resource.\n * @returns true if the content of the json resource is loaded. false otherwise.\n */\n isJsonLoaded(resourceName: string): boolean {\n return !!this._loadedJsons.getFromName(resourceName);\n }\n\n /**\n * Get the object for the given resource that is already loaded (preloaded or loaded with `loadJson`).\n * If the resource is not loaded, `null` will be returned.\n *\n * @param resourceName The name of the json resource.\n * @returns the content of the json resource, if loaded. `null` otherwise.\n */\n getLoadedJson(resourceName: string): Object | null {\n return this._loadedJsons.getFromName(resourceName) || null;\n }\n\n /**\n * To be called when the game is disposed.\n * Clear the JSONs loaded in this manager.\n */\n dispose(): void {\n this._loadedJsons.clear();\n this._callbacks.clear();\n }\n }\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,gBAQzB,EAAqC,CAAC,OAAQ,UAAW,WASxD,OAAkD,CAUvD,YAAY,EAAqC,CAPjD,kBAAe,GAAI,GAAK,cACxB,gBAAa,GAAI,GAAK,cAoDd,sBAAmB,AAAC,GAA8C,CACxE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,MAjDJ,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,QASH,cAAa,EAAqC,CACtD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KAAK,qCAAuC,EAAe,MAClE,OAEF,GAAI,GAAS,eAIb,GAAI,CACF,KAAM,MAAK,cAAc,EAAS,YAC3B,EAAP,CACA,EAAO,MACL,wCAAwC,EAAS,QACjD,IAKN,cAAc,EAA8C,CAC1D,KAAM,GAAO,KACb,MAAO,IAAI,SAAQ,CAAC,EAAS,IAAW,CACtC,EAAK,SAAS,EAAc,CAAC,EAAO,IAAY,CAC9C,AAAI,GACF,EAAO,EAAM,SAEf,EAAQ,YAYR,iBAAgB,EAAqC,EAY3D,SAAS,EAAsB,EAA4C,CACzE,KAAM,GAAW,KAAK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B,KAAK,WAAW,SA1Lb,EAAM,gBAlBL",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(m){class c extends m.RuntimeLayer{constructor(t,e){super(t,e);this._cameraRotation=0;this._zoomFactor=1;this._cameraZ=0;this._isCameraZDirty=!0;this._cameraX=this.getWidth()/2,this._cameraY=this.getHeight()/2,this.getCameraType()===m.RuntimeLayerCameraType.ORTHOGRAPHIC&&(this._cameraZ=(this._initialCamera3DFarPlaneDistance+this._initialCamera3DNearPlaneDistance)/2),this._renderer.onCreated()}onGameResolutionResized(t,e){this._cameraX===t&&this._cameraY===e&&this._zoomFactor===1&&(this._cameraX+=this._runtimeScene.getViewportOriginX()-t,this._cameraY+=this._runtimeScene.getViewportOriginY()-e),this._renderer.updatePosition(),this._renderer.updateResolution()}getCameraX(t){return this._forceDimensionUpdate(),this._cameraX}getCameraY(t){return this._forceDimensionUpdate(),this._cameraY}setCameraX(t,e){this._forceDimensionUpdate(),this._cameraX=t,this._renderer.updatePosition()}setCameraY(t,e){this._forceDimensionUpdate(),this._cameraY=t,this._renderer.updatePosition()}getCameraWidth(t){return this.getWidth()/this._zoomFactor}getCameraHeight(t){return this.getHeight()/this._zoomFactor}setCameraZoom(t,e){this._zoomFactor=t,this._isCameraZDirty=!0,this._renderer.updatePosition()}getCameraZoom(t){return this._zoomFactor}setCameraZ(t,e,i){if(e){const o=m.toRad(e),a=Math.min(Number.MAX_SAFE_INTEGER,.5*this.getHeight()/(t*Math.tan(.5*o)));a>0&&(this._zoomFactor=a)}this._cameraZ=t,this._isCameraZDirty=!1,this._renderer.updatePosition()}getCameraZ(t,e){return!this._isCameraZDirty||!t?this._cameraZ:.5*this.getHeight()/this.getCameraZoom()/Math.tan(.5*m.toRad(t))}getCameraRotation(t){return this._cameraRotation}setCameraRotation(t,e){this._cameraRotation=t,this._renderer.updatePosition()}convertCoords(t,e,i=0,o){let a=o||[0,0];if(this._renderer.isCameraRotatedIn3D())return this._renderer.transformTo3DWorld(t,e,0,i,o);t-=this.getRuntimeScene()._cachedGameResolutionWidth/2,e-=this.getRuntimeScene()._cachedGameResolutionHeight/2,t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const n=this._cameraRotation/180*Math.PI,s=t,r=Math.cos(n),h=Math.sin(n);return t=r*t-h*e,e=h*s+r*e,a[0]=t+this.getCameraX(i),a[1]=e+this.getCameraY(i),a}applyLayerInverseTransformation(t,e,i,o){t-=this._runtimeScene.getViewportOriginX(),e-=this._runtimeScene.getViewportOriginY(),t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(a),r=Math.sin(a);return t=s*t-r*e,e=r*n+s*e,o[0]=t+this.getCameraX(i),o[1]=e+this.getCameraY(i),o}convertInverseCoords(t,e,i=0,o){let a=o||[0,0];t-=this.getCameraX(i),e-=this.getCameraY(i);const n=this._cameraRotation/180*Math.PI,s=t,r=Math.cos(-n),h=Math.sin(-n);return t=r*t-h*e,e=h*s+r*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),a[0]=t+this.getRuntimeScene()._cachedGameResolutionWidth/2,a[1]=e+this.getRuntimeScene()._cachedGameResolutionHeight/2,a}applyLayerTransformation(t,e,i,o){t-=this.getCameraX(i),e-=this.getCameraY(i);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(-a),r=Math.sin(-a);return t=s*t-r*e,e=r*n+s*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),t+=this._runtimeScene.getViewportOriginX(),e+=this._runtimeScene.getViewportOriginY(),o[0]=t,o[1]=e,o}_forceDimensionUpdate(){this._runtimeScene.getViewportWidth()}}m.Layer=c})(gdjs||(gdjs={}));
1
+ var gdjs;(function(h){class c extends h.RuntimeLayer{constructor(t,e){super(t,e);this._cameraRotation=0;this._zoomFactor=1;this._cameraZ=0;this._isCameraZDirty=!0;this._defaultCameraBehavior===h.RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED?(this._cameraX=this._runtimeScene.getViewportOriginX(),this._cameraY=this._runtimeScene.getViewportOriginY()):(this._cameraX=(this._runtimeScene.getInitialUnrotatedViewportMinX()+this._runtimeScene.getInitialUnrotatedViewportMaxX())/2,this._cameraY=(this._runtimeScene.getInitialUnrotatedViewportMinY()+this._runtimeScene.getInitialUnrotatedViewportMaxY())/2),this.getCameraType()===h.RuntimeLayerCameraType.ORTHOGRAPHIC&&(this._cameraZ=(this._initialCamera3DFarPlaneDistance+this._initialCamera3DNearPlaneDistance)/2),this._renderer.onCreated()}onGameResolutionResized(t,e){this._defaultCameraBehavior===h.RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED&&Math.abs(this._cameraX-t)<1&&Math.abs(this._cameraY-e)<1&&this._zoomFactor===1&&(this._cameraX+=this._runtimeScene.getViewportOriginX()-t,this._cameraY+=this._runtimeScene.getViewportOriginY()-e),this._renderer.updatePosition(),this._renderer.updateResolution()}getCameraX(t){return this._forceDimensionUpdate(),this._cameraX}getCameraY(t){return this._forceDimensionUpdate(),this._cameraY}setCameraX(t,e){this._forceDimensionUpdate(),this._cameraX=t,this._renderer.updatePosition()}setCameraY(t,e){this._forceDimensionUpdate(),this._cameraY=t,this._renderer.updatePosition()}getCameraWidth(t){return this.getWidth()/this._zoomFactor}getCameraHeight(t){return this.getHeight()/this._zoomFactor}setCameraZoom(t,e){this._zoomFactor=t,this._isCameraZDirty=!0,this._renderer.updatePosition()}getCameraZoom(t){return this._zoomFactor}setCameraZ(t,e,i){if(e){const r=h.toRad(e),a=Math.min(Number.MAX_SAFE_INTEGER,.5*this.getHeight()/(t*Math.tan(.5*r)));a>0&&(this._zoomFactor=a)}this._cameraZ=t,this._isCameraZDirty=!1,this._renderer.updatePosition()}getCameraZ(t,e){return!this._isCameraZDirty||!t?this._cameraZ:.5*this.getHeight()/this.getCameraZoom()/Math.tan(.5*h.toRad(t))}getCameraRotation(t){return this._cameraRotation}setCameraRotation(t,e){this._cameraRotation=t,this._renderer.updatePosition()}convertCoords(t,e,i=0,r){let a=r||[0,0];if(this._renderer.isCameraRotatedIn3D())return this._renderer.transformTo3DWorld(t,e,0,i,r);t-=this.getRuntimeScene()._cachedGameResolutionWidth/2,e-=this.getRuntimeScene()._cachedGameResolutionHeight/2,t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const n=this._cameraRotation/180*Math.PI,s=t,o=Math.cos(n),m=Math.sin(n);return t=o*t-m*e,e=m*s+o*e,a[0]=t+this.getCameraX(i),a[1]=e+this.getCameraY(i),a}applyLayerInverseTransformation(t,e,i,r){t-=this._runtimeScene.getViewportOriginX(),e-=this._runtimeScene.getViewportOriginY(),t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(a),o=Math.sin(a);return t=s*t-o*e,e=o*n+s*e,r[0]=t+this.getCameraX(i),r[1]=e+this.getCameraY(i),r}convertInverseCoords(t,e,i=0,r){let a=r||[0,0];t-=this.getCameraX(i),e-=this.getCameraY(i);const n=this._cameraRotation/180*Math.PI,s=t,o=Math.cos(-n),m=Math.sin(-n);return t=o*t-m*e,e=m*s+o*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),a[0]=t+this.getRuntimeScene()._cachedGameResolutionWidth/2,a[1]=e+this.getRuntimeScene()._cachedGameResolutionHeight/2,a}applyLayerTransformation(t,e,i,r){t-=this.getCameraX(i),e-=this.getCameraY(i);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(-a),o=Math.sin(-a);return t=s*t-o*e,e=o*n+s*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),t+=this._runtimeScene.getViewportOriginX(),e+=this._runtimeScene.getViewportOriginY(),r[0]=t,r[1]=e,r}_forceDimensionUpdate(){this._runtimeScene.getViewportWidth()}}h.Layer=c})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=layer.js.map