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,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../GDevelop/GDJS/Runtime/layer.ts"],
4
- "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n /**\n * Represents a layer of a scene, used to display objects.\n */\n export class Layer extends gdjs.RuntimeLayer {\n _cameraRotation: float = 0;\n _zoomFactor: float = 1;\n _cameraX: float;\n _cameraY: float;\n _cameraZ: float = 0;\n /**\n * `_cameraZ` is dirty when the zoom factor is set last.\n */\n _isCameraZDirty: boolean = true;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n super(layerData, instanceContainer);\n\n this._cameraX = this.getWidth() / 2;\n this._cameraY = this.getHeight() / 2;\n if (this.getCameraType() === gdjs.RuntimeLayerCameraType.ORTHOGRAPHIC) {\n this._cameraZ =\n (this._initialCamera3DFarPlaneDistance +\n this._initialCamera3DNearPlaneDistance) /\n 2;\n }\n\n // Let the renderer do its final set up:\n this._renderer.onCreated();\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void {\n // Adapt position of the camera center only if the camera has never moved as:\n // * When the camera follows a player/object, it will rarely be at the default position.\n // * Cameras not following a player/object are usually UIs which are intuitively\n // expected not to \"move\". Not adapting the center position would make the camera\n // move from its initial position (which is centered in the screen) - and anchor\n // behavior would behave counterintuitively.\n if (\n this._cameraX === oldGameResolutionOriginX &&\n this._cameraY === oldGameResolutionOriginY &&\n this._zoomFactor === 1\n ) {\n this._cameraX +=\n this._runtimeScene.getViewportOriginX() - oldGameResolutionOriginX;\n this._cameraY +=\n this._runtimeScene.getViewportOriginY() - oldGameResolutionOriginY;\n }\n this._renderer.updatePosition();\n this._renderer.updateResolution();\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n getCameraX(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraX;\n }\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n getCameraY(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraY;\n }\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraX(x: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraX = x;\n this._renderer.updatePosition();\n }\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraY(y: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraY = y;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n getCameraWidth(cameraId?: integer): float {\n return this.getWidth() / this._zoomFactor;\n }\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n getCameraHeight(cameraId?: integer): float {\n return this.getHeight() / this._zoomFactor;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZoom(newZoom: float, cameraId?: integer): void {\n this._zoomFactor = newZoom;\n this._isCameraZDirty = true;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n getCameraZoom(cameraId?: integer): float {\n return this._zoomFactor;\n }\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZ(z: float, fov: float | null, cameraId?: integer): void {\n if (fov) {\n const cameraFovInRadians = gdjs.toRad(fov);\n\n // The zoom factor is capped to a not too big value to avoid infinity.\n // MAX_SAFE_INTEGER is an arbitrary choice. It's big but not too big.\n const zoomFactor = Math.min(\n Number.MAX_SAFE_INTEGER,\n (0.5 * this.getHeight()) / (z * Math.tan(0.5 * cameraFovInRadians))\n );\n\n if (zoomFactor > 0) {\n this._zoomFactor = zoomFactor;\n }\n }\n\n this._cameraZ = z;\n this._isCameraZDirty = false;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n getCameraZ(fov: float | null, cameraId?: integer): float {\n if (!this._isCameraZDirty || !fov) {\n return this._cameraZ;\n }\n\n // Set the camera so that it displays the whole PixiJS plane, as if it was a 2D rendering.\n // The Z position is computed by taking the half height of the displayed rendering,\n // and using the angle of the triangle defined by the field of view to compute the length\n // of the triangle defining the distance between the camera and the rendering plane.\n const cameraZPosition =\n (0.5 * this.getHeight()) /\n this.getCameraZoom() /\n Math.tan(0.5 * gdjs.toRad(fov));\n\n return cameraZPosition;\n }\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n getCameraRotation(cameraId?: integer): float {\n return this._cameraRotation;\n }\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraRotation(rotation: float, cameraId?: integer): void {\n this._cameraRotation = rotation;\n this._renderer.updatePosition();\n }\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * This method handles 3D rotations.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerInverseTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n\n if (this._renderer.isCameraRotatedIn3D()) {\n return this._renderer.transformTo3DWorld(x, y, 0, cameraId, result);\n }\n\n x -= this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n y -= this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n position[0] = x + this.getCameraX(cameraId);\n position[1] = y + this.getCameraY(cameraId);\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this._runtimeScene.getViewportOriginX();\n y -= this._runtimeScene.getViewportOriginY();\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n result[0] = x + this.getCameraX(cameraId);\n result[1] = y + this.getCameraY(cameraId);\n\n return result;\n }\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n position[0] = x + this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n position[1] = y + this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n x += this._runtimeScene.getViewportOriginX();\n y += this._runtimeScene.getViewportOriginY();\n\n result[0] = x;\n result[1] = y;\n return result;\n }\n\n /**\n * This ensure that the viewport dimensions are up to date.\n *\n * It's needed because custom objects dimensions are only updated on\n * demand for efficiency reasons.\n */\n private _forceDimensionUpdate(): void {\n // This will update dimensions.\n this._runtimeScene.getViewportWidth();\n }\n }\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAIS,eAAoB,GAAK,YAAa,CAe3C,YACE,EACA,EACA,CACA,MAAM,EAAW,GAlBnB,qBAAyB,EACzB,iBAAqB,EAGrB,cAAkB,EAIlB,qBAA2B,GAYzB,KAAK,SAAW,KAAK,WAAa,EAClC,KAAK,SAAW,KAAK,YAAc,EAC/B,KAAK,kBAAoB,EAAK,uBAAuB,cACvD,MAAK,SACF,MAAK,iCACJ,KAAK,mCACP,GAIJ,KAAK,UAAU,YAOjB,wBACE,EACA,EACM,CAON,AACE,KAAK,WAAa,GAClB,KAAK,WAAa,GAClB,KAAK,cAAgB,GAErB,MAAK,UACH,KAAK,cAAc,qBAAuB,EAC5C,KAAK,UACH,KAAK,cAAc,qBAAuB,GAE9C,KAAK,UAAU,iBACf,KAAK,UAAU,mBASjB,WAAW,EAA2B,CACpC,YAAK,wBACE,KAAK,SASd,WAAW,EAA2B,CACpC,YAAK,wBACE,KAAK,SASd,WAAW,EAAU,EAA0B,CAC7C,KAAK,wBACL,KAAK,SAAW,EAChB,KAAK,UAAU,iBASjB,WAAW,EAAU,EAA0B,CAC7C,KAAK,wBACL,KAAK,SAAW,EAChB,KAAK,UAAU,iBAUjB,eAAe,EAA2B,CACxC,MAAO,MAAK,WAAa,KAAK,YAUh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,GAAK,EACZ,EAAO,GAAK,EACL,EASD,uBAA8B,CAEpC,KAAK,cAAc,oBAxYhB,EAAM,UAJL",
4
+ "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n /**\n * Represents a layer of a scene, used to display objects.\n */\n export class Layer extends gdjs.RuntimeLayer {\n _cameraRotation: float = 0;\n _zoomFactor: float = 1;\n _cameraX: float;\n _cameraY: float;\n _cameraZ: float = 0;\n /**\n * `_cameraZ` is dirty when the zoom factor is set last.\n */\n _isCameraZDirty: boolean = true;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n super(layerData, instanceContainer);\n\n if (\n this._defaultCameraBehavior ===\n gdjs.RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED\n ) {\n // If top-left must stay in the top-left corner, this means we center the camera on the current size.\n this._cameraX = this._runtimeScene.getViewportOriginX();\n this._cameraY = this._runtimeScene.getViewportOriginY();\n } else {\n // Otherwise, the default camera position is the center of the initial viewport.\n this._cameraX =\n (this._runtimeScene.getInitialUnrotatedViewportMinX() +\n this._runtimeScene.getInitialUnrotatedViewportMaxX()) /\n 2;\n this._cameraY =\n (this._runtimeScene.getInitialUnrotatedViewportMinY() +\n this._runtimeScene.getInitialUnrotatedViewportMaxY()) /\n 2;\n }\n if (this.getCameraType() === gdjs.RuntimeLayerCameraType.ORTHOGRAPHIC) {\n this._cameraZ =\n (this._initialCamera3DFarPlaneDistance +\n this._initialCamera3DNearPlaneDistance) /\n 2;\n }\n\n // Let the renderer do its final set up:\n this._renderer.onCreated();\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void {\n // Adapt position of the camera center only if the camera has never moved as:\n // * When the camera follows a player/object, it will rarely be at the default position.\n // (and if is, it will be moved again by the behavior/events).\n // * Cameras not following a player/object are usually UIs which are intuitively\n // expected not to \"move\" (top-left stays \"fixed\"), while gameplay is \"centered\" (center stays \"fixed\").\n //\n // Note that anchor behavior is usually a better choice for UIs.\n if (\n this._defaultCameraBehavior ===\n gdjs.RuntimeLayerDefaultCameraBehavior\n .TOP_LEFT_ANCHORED_IF_NEVER_MOVED &&\n // Have a safety margin of 1 pixel to avoid rounding errors.\n Math.abs(this._cameraX - oldGameResolutionOriginX) < 1 &&\n Math.abs(this._cameraY - oldGameResolutionOriginY) < 1 &&\n this._zoomFactor === 1\n ) {\n this._cameraX +=\n this._runtimeScene.getViewportOriginX() - oldGameResolutionOriginX;\n this._cameraY +=\n this._runtimeScene.getViewportOriginY() - oldGameResolutionOriginY;\n }\n\n this._renderer.updatePosition();\n this._renderer.updateResolution();\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n getCameraX(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraX;\n }\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n getCameraY(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraY;\n }\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraX(x: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraX = x;\n this._renderer.updatePosition();\n }\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraY(y: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraY = y;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n getCameraWidth(cameraId?: integer): float {\n return this.getWidth() / this._zoomFactor;\n }\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n getCameraHeight(cameraId?: integer): float {\n return this.getHeight() / this._zoomFactor;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZoom(newZoom: float, cameraId?: integer): void {\n this._zoomFactor = newZoom;\n this._isCameraZDirty = true;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n getCameraZoom(cameraId?: integer): float {\n return this._zoomFactor;\n }\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZ(z: float, fov: float | null, cameraId?: integer): void {\n if (fov) {\n const cameraFovInRadians = gdjs.toRad(fov);\n\n // The zoom factor is capped to a not too big value to avoid infinity.\n // MAX_SAFE_INTEGER is an arbitrary choice. It's big but not too big.\n const zoomFactor = Math.min(\n Number.MAX_SAFE_INTEGER,\n (0.5 * this.getHeight()) / (z * Math.tan(0.5 * cameraFovInRadians))\n );\n\n if (zoomFactor > 0) {\n this._zoomFactor = zoomFactor;\n }\n }\n\n this._cameraZ = z;\n this._isCameraZDirty = false;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n getCameraZ(fov: float | null, cameraId?: integer): float {\n if (!this._isCameraZDirty || !fov) {\n return this._cameraZ;\n }\n\n // Set the camera so that it displays the whole PixiJS plane, as if it was a 2D rendering.\n // The Z position is computed by taking the half height of the displayed rendering,\n // and using the angle of the triangle defined by the field of view to compute the length\n // of the triangle defining the distance between the camera and the rendering plane.\n const cameraZPosition =\n (0.5 * this.getHeight()) /\n this.getCameraZoom() /\n Math.tan(0.5 * gdjs.toRad(fov));\n\n return cameraZPosition;\n }\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n getCameraRotation(cameraId?: integer): float {\n return this._cameraRotation;\n }\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraRotation(rotation: float, cameraId?: integer): void {\n this._cameraRotation = rotation;\n this._renderer.updatePosition();\n }\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * This method handles 3D rotations.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerInverseTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n\n if (this._renderer.isCameraRotatedIn3D()) {\n return this._renderer.transformTo3DWorld(x, y, 0, cameraId, result);\n }\n\n x -= this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n y -= this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n position[0] = x + this.getCameraX(cameraId);\n position[1] = y + this.getCameraY(cameraId);\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this._runtimeScene.getViewportOriginX();\n y -= this._runtimeScene.getViewportOriginY();\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n result[0] = x + this.getCameraX(cameraId);\n result[1] = y + this.getCameraY(cameraId);\n\n return result;\n }\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n position[0] = x + this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n position[1] = y + this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n x += this._runtimeScene.getViewportOriginX();\n y += this._runtimeScene.getViewportOriginY();\n\n result[0] = x;\n result[1] = y;\n return result;\n }\n\n /**\n * This ensure that the viewport dimensions are up to date.\n *\n * It's needed because custom objects dimensions are only updated on\n * demand for efficiency reasons.\n */\n private _forceDimensionUpdate(): void {\n // This will update dimensions.\n this._runtimeScene.getViewportWidth();\n }\n }\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAIS,eAAoB,GAAK,YAAa,CAe3C,YACE,EACA,EACA,CACA,MAAM,EAAW,GAlBnB,qBAAyB,EACzB,iBAAqB,EAGrB,cAAkB,EAIlB,qBAA2B,GAYzB,AACE,KAAK,yBACL,EAAK,kCAAkC,iCAGvC,MAAK,SAAW,KAAK,cAAc,qBACnC,KAAK,SAAW,KAAK,cAAc,sBAGnC,MAAK,SACF,MAAK,cAAc,kCAClB,KAAK,cAAc,mCACrB,EACF,KAAK,SACF,MAAK,cAAc,kCAClB,KAAK,cAAc,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N,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,EAAS,GAAK,EAAI,KAAK,kBAAkB,2BAA6B,EACtE,EAAS,GAAK,EAAI,KAAK,kBAAkB,4BAA8B,EAEhE,EAgBT,yBACE,EACA,EACA,EACA,EACY,CACZ,GAAK,KAAK,WAAW,GACrB,GAAK,KAAK,WAAW,GAGrB,KAAM,GAAkB,KAAK,gBAAkB,IAAO,KAAK,GACrD,EAAM,EACN,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,cAAc,qBACxB,GAAK,KAAK,cAAc,qBAExB,EAAO,GAAK,EACZ,EAAO,GAAK,EACL,EASD,uBAA8B,CAEpC,KAAK,cAAc,oBA/ZhB,EAAM,UAJL",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(a){const n=new a.Logger("Bitmap text"),l="GDJS-DEFAULT-BITMAP-FONT",d=5,p=(o,t)=>{const e=o.font;return o.font=t,PIXI.BitmapFont.available[t]=o,delete PIXI.BitmapFont.available[e],PIXI.BitmapFont.available[t]},m=["bitmapFont"];class c{constructor(t,e){this._pixiBitmapFontsInUse={};this._pixiBitmapFontsToUninstall=[];this._loadedFontsData=new a.ResourceCache;this._defaultSlugFontName=null;this._imageManager=e,this._resourceLoader=t}getResourceKinds(){return m}getDefaultBitmapFont(){if(this._defaultSlugFontName!==null)return PIXI.BitmapFont.available[this._defaultSlugFontName];const t="Arial",e=new PIXI.TextStyle({fontFamily:t,fontSize:20,padding:5,align:"left",fill:"#ffffff",wordWrap:!0,lineHeight:20}),i=p(PIXI.BitmapFont.from(t,e,{chars:[[" ","~"]]}),l);return this._defaultSlugFontName=i.font,i}_markBitmapFontAsUsed(t){this._pixiBitmapFontsInUse[t]=this._pixiBitmapFontsInUse[t]||{objectsUsingTheFont:0},this._pixiBitmapFontsInUse[t].objectsUsingTheFont++;for(let e=0;e<this._pixiBitmapFontsToUninstall.length;)this._pixiBitmapFontsToUninstall[e]===t?this._pixiBitmapFontsToUninstall.splice(e,1):e++}releaseBitmapFont(t){if(t!==l){if(!this._pixiBitmapFontsInUse[t]){n.warn("BitmapFont with name "+t+" was tried to be released but was never marked as used.");return}if(this._pixiBitmapFontsInUse[t].objectsUsingTheFont--,this._pixiBitmapFontsInUse[t].objectsUsingTheFont===0&&(delete this._pixiBitmapFontsInUse[t],this._pixiBitmapFontsToUninstall.includes(t)||this._pixiBitmapFontsToUninstall.push(t),this._pixiBitmapFontsToUninstall.length>d)){const e=this._pixiBitmapFontsToUninstall.shift();PIXI.BitmapFont.uninstall(e),n.log("Bitmap Text",'Uninstalled BitmapFont "'+e+'" from memory.')}}}obtainBitmapFont(t,e){const i=t+"@"+e;if(PIXI.BitmapFont.available[i])return this._markBitmapFontAsUsed(i),PIXI.BitmapFont.available[i];const s=this._loadedFontsData.getFromName(t);if(!s)return n.warn('Could not find Bitmap Font for resource named "'+t+'". The default font will be used.'),this.getDefaultBitmapFont();const u=this._imageManager.getPIXITexture(e);try{const r=p(PIXI.BitmapFont.install(s,u),i);return this._markBitmapFontAsUsed(i),r}catch(r){return n.error('Could not load the Bitmap Font for resource named "'+t+'". The default font will be used. Error is: '+r),this.getDefaultBitmapFont()}}async processResource(t){}async loadResource(t){const e=this._resourceLoader.getResource(t);if(!e){n.warn('Unable to find bitmap font for resource "'+t+'".');return}if(!this._loadedFontsData.get(e))try{const s=await(await fetch(this._resourceLoader.getFullUrl(e.file),{credentials:this._resourceLoader.checkIfCredentialsRequired(e.file)?"include":"same-origin"})).text();this._loadedFontsData.set(e,s)}catch(i){n.error("Can't fetch the bitmap font file "+e.file+", error: "+i)}}}a.PixiBitmapFontManager=c,a.BitmapFontManager=a.PixiBitmapFontManager})(gdjs||(gdjs={}));
1
+ var gdjs;(function(a){const n=new a.Logger("Bitmap text"),l="GDJS-DEFAULT-BITMAP-FONT",m=5,p=(s,t)=>{const i=s.font;return s.font=t,PIXI.BitmapFont.available[t]=s,delete PIXI.BitmapFont.available[i],PIXI.BitmapFont.available[t]},d=["bitmapFont"];class u{constructor(t,i){this._pixiBitmapFontsInUse={};this._pixiBitmapFontsToUninstall=[];this._loadedFontsData=new a.ResourceCache;this._defaultSlugFontName=null;this._imageManager=i,this._resourceLoader=t}getResourceKinds(){return d}getDefaultBitmapFont(){if(this._defaultSlugFontName!==null)return PIXI.BitmapFont.available[this._defaultSlugFontName];const t="Arial",i=new PIXI.TextStyle({fontFamily:t,fontSize:20,padding:5,align:"left",fill:"#ffffff",wordWrap:!0,lineHeight:20}),e=p(PIXI.BitmapFont.from(t,i,{chars:[[" ","~"]]}),l);return this._defaultSlugFontName=e.font,e}_markBitmapFontAsUsed(t){this._pixiBitmapFontsInUse[t]=this._pixiBitmapFontsInUse[t]||{objectsUsingTheFont:0},this._pixiBitmapFontsInUse[t].objectsUsingTheFont++;for(let i=0;i<this._pixiBitmapFontsToUninstall.length;)this._pixiBitmapFontsToUninstall[i]===t?this._pixiBitmapFontsToUninstall.splice(i,1):i++}releaseBitmapFont(t){if(t!==l){if(!this._pixiBitmapFontsInUse[t]){n.warn("BitmapFont with name "+t+" was tried to be released but was never marked as used.");return}if(this._pixiBitmapFontsInUse[t].objectsUsingTheFont--,this._pixiBitmapFontsInUse[t].objectsUsingTheFont===0&&(delete this._pixiBitmapFontsInUse[t],this._pixiBitmapFontsToUninstall.includes(t)||this._pixiBitmapFontsToUninstall.push(t),this._pixiBitmapFontsToUninstall.length>m)){const i=this._pixiBitmapFontsToUninstall.shift();PIXI.BitmapFont.uninstall(i),n.log("Bitmap Text",'Uninstalled BitmapFont "'+i+'" from memory.')}}}obtainBitmapFont(t,i){const e=t+"@"+i;if(PIXI.BitmapFont.available[e])return this._markBitmapFontAsUsed(e),PIXI.BitmapFont.available[e];const o=this._loadedFontsData.getFromName(t);if(!o)return n.warn('Could not find Bitmap Font for resource named "'+t+'". The default font will be used.'),this.getDefaultBitmapFont();const c=this._imageManager.getPIXITexture(i);try{const r=p(PIXI.BitmapFont.install(o,c),e);return this._markBitmapFontAsUsed(e),r}catch(r){return n.error('Could not load the Bitmap Font for resource named "'+t+'". The default font will be used. Error is: '+r),this.getDefaultBitmapFont()}}async processResource(t){}async loadResource(t){const i=this._resourceLoader.getResource(t);if(!i){n.warn('Unable to find bitmap font for resource "'+t+'".');return}if(!this._loadedFontsData.get(i))try{const o=await(await fetch(this._resourceLoader.getFullUrl(i.file),{credentials:this._resourceLoader.checkIfCredentialsRequired(i.file)?"include":"same-origin"})).text();this._loadedFontsData.set(i,o)}catch(e){n.error("Can't fetch the bitmap font file "+i.file+", error: "+e)}}dispose(){for(const t in this._pixiBitmapFontsInUse)PIXI.BitmapFont.uninstall(t);for(const t of this._pixiBitmapFontsToUninstall)PIXI.BitmapFont.uninstall(t);this._pixiBitmapFontsInUse={},this._pixiBitmapFontsToUninstall.length=0,this._loadedFontsData.clear()}}a.PixiBitmapFontManager=u,a.BitmapFontManager=a.PixiBitmapFontManager})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=pixi-bitmapfont-manager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../GDevelop/GDJS/Runtime/pixi-renderers/pixi-bitmapfont-manager.ts"],
4
- "sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2021-present Aur\u00E9lien Vivet (bouh.vivez@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Bitmap text');\n\n const defaultBitmapFontKey = 'GDJS-DEFAULT-BITMAP-FONT';\n\n // When a font is unused, we put it in a cache of unused fonts. It's unloaded\n // from memory only when the cache is full and the font is at the last position\n // in the cache.\n // Set this to 0 to unload from memory (\"uninstall\") as soon as a font is unused.\n const uninstallCacheSize = 5;\n\n /**\n * We patch the installed font to use a name that is unique for each font data and texture,\n * to avoid conflicts between different font files using the same font name (by default, the\n * font name used by Pixi is the one inside the font data, but this name is not necessarily unique.\n * For example, 2 resources can use the same font, or we can have multiple objects with the same\n * font data and different textures).\n */\n const patchInstalledBitmapFont = (\n bitmapFont: PIXI.BitmapFont,\n bitmapFontInstallKey: string\n ) => {\n const defaultName = bitmapFont.font;\n // @ts-ignore - we \"hack\" into Pixi to change the font name\n bitmapFont.font = bitmapFontInstallKey;\n PIXI.BitmapFont.available[bitmapFontInstallKey] = bitmapFont;\n delete PIXI.BitmapFont.available[defaultName];\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n };\n\n const resourceKinds: Array<ResourceKind> = ['bitmapFont'];\n\n /**\n * PixiBitmapFontManager loads fnt/xml files (using `fetch`), from the \"bitmapFont\" resources of the game.\n *\n * It installs the \"BitmapFont\" with PixiJS to be used with PIXI.BitmapText.\n */\n export class PixiBitmapFontManager implements gdjs.ResourceManager {\n private _imageManager: gdjs.PixiImageManager;\n\n /** Pixi.BitmapFont used, indexed by their BitmapFont name. */\n private _pixiBitmapFontsInUse: Record<\n string,\n { objectsUsingTheFont: number }\n > = {};\n\n /** Pixi.BitmapFont not used anymore, but not yet uninstalled, indexed by their BitmapFont name. */\n private _pixiBitmapFontsToUninstall: string[] = [];\n\n /** Loaded fonts data, indexed by resource name. */\n private _loadedFontsData = new gdjs.ResourceCache<any>();\n\n private _defaultSlugFontName: string | null = null;\n\n _resourceLoader: gdjs.ResourceLoader;\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n * @param imageManager The image manager to be used to get textures used by fonts.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n imageManager: gdjs.PixiImageManager\n ) {\n this._imageManager = imageManager;\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Get the instance of the default `Pixi.BitmapFont`, always available.\n */\n getDefaultBitmapFont() {\n if (this._defaultSlugFontName !== null) {\n return PIXI.BitmapFont.available[this._defaultSlugFontName];\n }\n\n // Default bitmap font style\n const fontFamily = 'Arial';\n const bitmapFontStyle = new PIXI.TextStyle({\n fontFamily: fontFamily,\n fontSize: 20,\n padding: 5,\n align: 'left',\n fill: '#ffffff',\n wordWrap: true,\n lineHeight: 20,\n });\n\n // Generate default bitmapFont, and replace the name of PIXI.BitmapFont by a unique name\n const defaultBitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.from(fontFamily, bitmapFontStyle, {\n // All the printable ASCII characters\n chars: [[' ', '~']],\n }),\n defaultBitmapFontKey\n );\n\n // Define the default name used for the default bitmap font.\n this._defaultSlugFontName = defaultBitmapFont.font;\n return defaultBitmapFont;\n }\n\n /**\n * Called to specify that the bitmap font with the specified key is used by an object\n * (i.e: this is reference counting).\n * `releaseBitmapFont` *must* be called to mark the font as not used anymore when the\n * object is destroyed or its font changed.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n private _markBitmapFontAsUsed(bitmapFontInstallKey: string): void {\n this._pixiBitmapFontsInUse[bitmapFontInstallKey] = this\n ._pixiBitmapFontsInUse[bitmapFontInstallKey] || {\n objectsUsingTheFont: 0,\n };\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont++;\n\n for (let i = 0; i < this._pixiBitmapFontsToUninstall.length; ) {\n if (this._pixiBitmapFontsToUninstall[i] === bitmapFontInstallKey) {\n // The font is in the cache of fonts to uninstall, because it was previously used and then marked as not used anymore.\n // Remove it from the cache to avoid the font getting uninstalled.\n this._pixiBitmapFontsToUninstall.splice(i, 1);\n } else {\n i++;\n }\n }\n }\n\n /**\n * When a font is not used by an object anymore (object destroyed or font changed),\n * call this function to decrease the internal count of objects using the font.\n *\n * When a font is not unused anymore, it goes in a temporary cache. The cache holds up to 10 fonts.\n * If the cache reaches its maximum capacity, the oldest font is uninstalled from memory.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n releaseBitmapFont(bitmapFontInstallKey: string) {\n if (bitmapFontInstallKey === defaultBitmapFontKey) {\n // Never uninstall the default font.\n return;\n }\n\n if (!this._pixiBitmapFontsInUse[bitmapFontInstallKey]) {\n logger.warn(\n 'BitmapFont with name ' +\n bitmapFontInstallKey +\n ' was tried to be released but was never marked as used.'\n );\n return;\n }\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont--;\n\n if (\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont ===\n 0\n ) {\n delete this._pixiBitmapFontsInUse[bitmapFontInstallKey];\n\n // Add the font name at the last position of the cache.\n if (!this._pixiBitmapFontsToUninstall.includes(bitmapFontInstallKey)) {\n this._pixiBitmapFontsToUninstall.push(bitmapFontInstallKey);\n }\n if (this._pixiBitmapFontsToUninstall.length > uninstallCacheSize) {\n // Remove the first font (i.e: the oldest one)\n const oldestUnloadedPixiBitmapFontName = this._pixiBitmapFontsToUninstall.shift() as string;\n\n PIXI.BitmapFont.uninstall(oldestUnloadedPixiBitmapFontName);\n logger.log(\n 'Bitmap Text',\n 'Uninstalled BitmapFont \"' +\n oldestUnloadedPixiBitmapFontName +\n '\" from memory.'\n );\n }\n }\n }\n\n /**\n * Given a bitmap font resource name and a texture atlas resource name, returns the PIXI.BitmapFont\n * for it.\n * The font is register and should be released with `releaseBitmapFont` - so that it can be removed\n * from memory when unused.\n */\n obtainBitmapFont(\n bitmapFontResourceName: string,\n textureAtlasResourceName: string\n ): PIXI.BitmapFont {\n const bitmapFontInstallKey =\n bitmapFontResourceName + '@' + textureAtlasResourceName;\n\n if (PIXI.BitmapFont.available[bitmapFontInstallKey]) {\n // Return the existing BitmapFont that is already in memory and already installed.\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n }\n\n // The Bitmap Font is not loaded, load it in memory.\n\n // First get the font data:\n const fontData = this._loadedFontsData.getFromName(\n bitmapFontResourceName\n );\n if (!fontData) {\n logger.warn(\n 'Could not find Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used.'\n );\n return this.getDefaultBitmapFont();\n }\n\n // Get the texture to be used in the font:\n const texture = this._imageManager.getPIXITexture(\n textureAtlasResourceName\n );\n\n try {\n // Create and install the Pixi.BitmapFont in memory:\n const bitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.install(fontData, texture),\n bitmapFontInstallKey\n );\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return bitmapFont;\n } catch (error) {\n logger.error(\n 'Could not load the Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used. Error is: ' +\n error\n );\n return this.getDefaultBitmapFont();\n }\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because fonts are light enough to be parsed in background.\n }\n\n /**\n * Load the \"bitmapFont\" resources of the game, so that they are ready\n * to be used when `obtainBitmapFont` is called.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find bitmap font for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (this._loadedFontsData.get(resource)) {\n return;\n }\n\n try {\n const response = await fetch(\n this._resourceLoader.getFullUrl(resource.file),\n {\n credentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n )\n ? // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n }\n );\n const fontData = await response.text();\n this._loadedFontsData.set(resource, fontData);\n } catch (error) {\n logger.error(\n \"Can't fetch the bitmap font file \" +\n resource.file +\n ', error: ' +\n error\n );\n }\n }\n }\n\n // Register the class to let the engine use it.\n export const BitmapFontManager = gdjs.PixiBitmapFontManager;\n export type BitmapFontManager = gdjs.PixiBitmapFontManager;\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,eAEzB,EAAuB,2BAMvB,EAAqB,EASrB,EAA2B,CAC/B,EACA,IACG,CACH,KAAM,GAAc,EAAW,KAE/B,SAAW,KAAO,EAClB,KAAK,WAAW,UAAU,GAAwB,EAClD,MAAO,MAAK,WAAW,UAAU,GAC1B,KAAK,WAAW,UAAU,IAG7B,EAAqC,CAAC,cAOrC,OAA4D,CAwBjE,YACE,EACA,EACA,CAvBM,2BAGJ,GAGI,iCAAwC,GAGxC,sBAAmB,GAAI,GAAK,cAE5B,0BAAsC,KAa5C,KAAK,cAAgB,EACrB,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,GAMT,sBAAuB,CACrB,GAAI,KAAK,uBAAyB,KAChC,MAAO,MAAK,WAAW,UAAU,KAAK,sBAIxC,KAAM,GAAa,QACb,EAAkB,GAAI,MAAK,UAAU,CACzC,WAAY,EACZ,SAAU,GACV,QAAS,EACT,MAAO,OACP,KAAM,UACN,SAAU,GACV,WAAY,KAIR,EAAoB,EACxB,KAAK,WAAW,KAAK,EAAY,EAAiB,CAEhD,MAAO,CAAC,CAAC,IAAK,QAEhB,GAIF,YAAK,qBAAuB,EAAkB,KACvC,EAWD,sBAAsB,EAAoC,CAChE,KAAK,sBAAsB,GAAwB,KAChD,sBAAsB,IAAyB,CAChD,oBAAqB,GAEvB,KAAK,sBAAsB,GAAsB,sBAEjD,OAAS,GAAI,EAAG,EAAI,KAAK,4BAA4B,QACnD,AAAI,KAAK,4BAA4B,KAAO,EAG1C,KAAK,4BAA4B,OAAO,EAAG,GAE3C,IAcN,kBAAkB,EAA8B,CAC9C,GAAI,IAAyB,EAK7B,IAAI,CAAC,KAAK,sBAAsB,GAAuB,CACrD,EA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E9lien Vivet (bouh.vivez@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Bitmap text');\n\n const defaultBitmapFontKey = 'GDJS-DEFAULT-BITMAP-FONT';\n\n // When a font is unused, we put it in a cache of unused fonts. It's unloaded\n // from memory only when the cache is full and the font is at the last position\n // in the cache.\n // Set this to 0 to unload from memory (\"uninstall\") as soon as a font is unused.\n const uninstallCacheSize = 5;\n\n /**\n * We patch the installed font to use a name that is unique for each font data and texture,\n * to avoid conflicts between different font files using the same font name (by default, the\n * font name used by Pixi is the one inside the font data, but this name is not necessarily unique.\n * For example, 2 resources can use the same font, or we can have multiple objects with the same\n * font data and different textures).\n */\n const patchInstalledBitmapFont = (\n bitmapFont: PIXI.BitmapFont,\n bitmapFontInstallKey: string\n ) => {\n const defaultName = bitmapFont.font;\n // @ts-ignore - we \"hack\" into Pixi to change the font name\n bitmapFont.font = bitmapFontInstallKey;\n PIXI.BitmapFont.available[bitmapFontInstallKey] = bitmapFont;\n delete PIXI.BitmapFont.available[defaultName];\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n };\n\n const resourceKinds: Array<ResourceKind> = ['bitmapFont'];\n\n /**\n * PixiBitmapFontManager loads fnt/xml files (using `fetch`), from the \"bitmapFont\" resources of the game.\n *\n * It installs the \"BitmapFont\" with PixiJS to be used with PIXI.BitmapText.\n */\n export class PixiBitmapFontManager implements gdjs.ResourceManager {\n private _imageManager: gdjs.PixiImageManager;\n\n /** Pixi.BitmapFont used, indexed by their BitmapFont name. */\n private _pixiBitmapFontsInUse: Record<\n string,\n { objectsUsingTheFont: number }\n > = {};\n\n /** Pixi.BitmapFont not used anymore, but not yet uninstalled, indexed by their BitmapFont name. */\n private _pixiBitmapFontsToUninstall: string[] = [];\n\n /** Loaded fonts data, indexed by resource name. */\n private _loadedFontsData = new gdjs.ResourceCache<any>();\n\n private _defaultSlugFontName: string | null = null;\n\n _resourceLoader: gdjs.ResourceLoader;\n\n /**\n * @param resourceDataArray The resources data of the game.\n * @param resourceLoader The resources loader of the game.\n * @param imageManager The image manager to be used to get textures used by fonts.\n */\n constructor(\n resourceLoader: gdjs.ResourceLoader,\n imageManager: gdjs.PixiImageManager\n ) {\n this._imageManager = imageManager;\n this._resourceLoader = resourceLoader;\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Get the instance of the default `Pixi.BitmapFont`, always available.\n */\n getDefaultBitmapFont() {\n if (this._defaultSlugFontName !== null) {\n return PIXI.BitmapFont.available[this._defaultSlugFontName];\n }\n\n // Default bitmap font style\n const fontFamily = 'Arial';\n const bitmapFontStyle = new PIXI.TextStyle({\n fontFamily: fontFamily,\n fontSize: 20,\n padding: 5,\n align: 'left',\n fill: '#ffffff',\n wordWrap: true,\n lineHeight: 20,\n });\n\n // Generate default bitmapFont, and replace the name of PIXI.BitmapFont by a unique name\n const defaultBitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.from(fontFamily, bitmapFontStyle, {\n // All the printable ASCII characters\n chars: [[' ', '~']],\n }),\n defaultBitmapFontKey\n );\n\n // Define the default name used for the default bitmap font.\n this._defaultSlugFontName = defaultBitmapFont.font;\n return defaultBitmapFont;\n }\n\n /**\n * Called to specify that the bitmap font with the specified key is used by an object\n * (i.e: this is reference counting).\n * `releaseBitmapFont` *must* be called to mark the font as not used anymore when the\n * object is destroyed or its font changed.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n private _markBitmapFontAsUsed(bitmapFontInstallKey: string): void {\n this._pixiBitmapFontsInUse[bitmapFontInstallKey] = this\n ._pixiBitmapFontsInUse[bitmapFontInstallKey] || {\n objectsUsingTheFont: 0,\n };\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont++;\n\n for (let i = 0; i < this._pixiBitmapFontsToUninstall.length; ) {\n if (this._pixiBitmapFontsToUninstall[i] === bitmapFontInstallKey) {\n // The font is in the cache of fonts to uninstall, because it was previously used and then marked as not used anymore.\n // Remove it from the cache to avoid the font getting uninstalled.\n this._pixiBitmapFontsToUninstall.splice(i, 1);\n } else {\n i++;\n }\n }\n }\n\n /**\n * When a font is not used by an object anymore (object destroyed or font changed),\n * call this function to decrease the internal count of objects using the font.\n *\n * When a font is not unused anymore, it goes in a temporary cache. The cache holds up to 10 fonts.\n * If the cache reaches its maximum capacity, the oldest font is uninstalled from memory.\n *\n * @param bitmapFontInstallKey Name of the font of the BitmapFont (`bitmapFont.font`)\n */\n releaseBitmapFont(bitmapFontInstallKey: string) {\n if (bitmapFontInstallKey === defaultBitmapFontKey) {\n // Never uninstall the default font.\n return;\n }\n\n if (!this._pixiBitmapFontsInUse[bitmapFontInstallKey]) {\n logger.warn(\n 'BitmapFont with name ' +\n bitmapFontInstallKey +\n ' was tried to be released but was never marked as used.'\n );\n return;\n }\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont--;\n\n if (\n this._pixiBitmapFontsInUse[bitmapFontInstallKey].objectsUsingTheFont ===\n 0\n ) {\n delete this._pixiBitmapFontsInUse[bitmapFontInstallKey];\n\n // Add the font name at the last position of the cache.\n if (!this._pixiBitmapFontsToUninstall.includes(bitmapFontInstallKey)) {\n this._pixiBitmapFontsToUninstall.push(bitmapFontInstallKey);\n }\n if (this._pixiBitmapFontsToUninstall.length > uninstallCacheSize) {\n // Remove the first font (i.e: the oldest one)\n const oldestUnloadedPixiBitmapFontName = this._pixiBitmapFontsToUninstall.shift() as string;\n\n PIXI.BitmapFont.uninstall(oldestUnloadedPixiBitmapFontName);\n logger.log(\n 'Bitmap Text',\n 'Uninstalled BitmapFont \"' +\n oldestUnloadedPixiBitmapFontName +\n '\" from memory.'\n );\n }\n }\n }\n\n /**\n * Given a bitmap font resource name and a texture atlas resource name, returns the PIXI.BitmapFont\n * for it.\n * The font is register and should be released with `releaseBitmapFont` - so that it can be removed\n * from memory when unused.\n */\n obtainBitmapFont(\n bitmapFontResourceName: string,\n textureAtlasResourceName: string\n ): PIXI.BitmapFont {\n const bitmapFontInstallKey =\n bitmapFontResourceName + '@' + textureAtlasResourceName;\n\n if (PIXI.BitmapFont.available[bitmapFontInstallKey]) {\n // Return the existing BitmapFont that is already in memory and already installed.\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return PIXI.BitmapFont.available[bitmapFontInstallKey];\n }\n\n // The Bitmap Font is not loaded, load it in memory.\n\n // First get the font data:\n const fontData = this._loadedFontsData.getFromName(\n bitmapFontResourceName\n );\n if (!fontData) {\n logger.warn(\n 'Could not find Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used.'\n );\n return this.getDefaultBitmapFont();\n }\n\n // Get the texture to be used in the font:\n const texture = this._imageManager.getPIXITexture(\n textureAtlasResourceName\n );\n\n try {\n // Create and install the Pixi.BitmapFont in memory:\n const bitmapFont = patchInstalledBitmapFont(\n PIXI.BitmapFont.install(fontData, texture),\n bitmapFontInstallKey\n );\n this._markBitmapFontAsUsed(bitmapFontInstallKey);\n return bitmapFont;\n } catch (error) {\n logger.error(\n 'Could not load the Bitmap Font for resource named \"' +\n bitmapFontResourceName +\n '\". The default font will be used. Error is: ' +\n error\n );\n return this.getDefaultBitmapFont();\n }\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because fonts are light enough to be parsed in background.\n }\n\n /**\n * Load the \"bitmapFont\" resources of the game, so that they are ready\n * to be used when `obtainBitmapFont` is called.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find bitmap font for resource \"' + resourceName + '\".'\n );\n return;\n }\n if (this._loadedFontsData.get(resource)) {\n return;\n }\n\n try {\n const response = await fetch(\n this._resourceLoader.getFullUrl(resource.file),\n {\n credentials: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n )\n ? // Any resource stored on the GDevelop Cloud buckets needs the \"credentials\" of the user,\n // i.e: its gdevelop.io cookie, to be passed.\n 'include'\n : // For other resources, use \"same-origin\" as done by default by fetch.\n 'same-origin',\n }\n );\n const fontData = await response.text();\n this._loadedFontsData.set(resource, fontData);\n } catch (error) {\n logger.error(\n \"Can't fetch the bitmap font file \" +\n resource.file +\n ', error: ' +\n error\n );\n }\n }\n\n /**\n * To be called when the game is disposed.\n * Uninstall all the fonts from memory and clear cache of loaded fonts.\n */\n dispose(): void {\n for (const bitmapFontInstallKey in this._pixiBitmapFontsInUse) {\n PIXI.BitmapFont.uninstall(bitmapFontInstallKey);\n }\n\n for (const bitmapFontInstallKey of this._pixiBitmapFontsToUninstall) {\n PIXI.BitmapFont.uninstall(bitmapFontInstallKey);\n }\n\n this._pixiBitmapFontsInUse = {};\n this._pixiBitmapFontsToUninstall.length = 0;\n this._loadedFontsData.clear();\n }\n }\n\n // Register the class to let the engine use it.\n export const BitmapFontManager = gdjs.PixiBitmapFontManager;\n export type BitmapFontManager = gdjs.PixiBitmapFontManager;\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,eAEzB,EAAuB,2BAMvB,EAAqB,EASrB,EAA2B,CAC/B,EACA,IACG,CACH,KAAM,GAAc,EAAW,KAE/B,SAAW,KAAO,EAClB,KAAK,WAAW,UAAU,GAAwB,EAClD,MAAO,MAAK,WAAW,UAAU,GAC1B,KAAK,WAAW,UAAU,IAG7B,EAAqC,CAAC,cAOrC,OAA4D,CAwBjE,YACE,EACA,EACA,CAvBM,2BAGJ,GAGI,iCAAwC,GAGxC,sBAAmB,GAAI,GAAK,cAE5B,0BAAsC,KAa5C,KAAK,cAAgB,EACrB,KAAK,gBAAkB,EAGzB,kBAAmC,CACjC,MAAO,GAMT,sBAAuB,CACrB,GAAI,KAAK,uBAAyB,KAChC,MAAO,MAAK,WAAW,UAAU,KAAK,sBAIxC,KAAM,GAAa,QACb,EAAkB,GAAI,MAAK,UAAU,CACzC,WAAY,EACZ,SAAU,GACV,QAAS,EACT,MAAO,OACP,KAA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,EAAqC,CACtD,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,GAAI,CAAC,EAAU,CACb,EAAO,KACL,4CAA8C,EAAe,MAE/D,OAEF,GAAI,MAAK,iBAAiB,IAAI,GAI9B,GAAI,CAcF,KAAM,GAAW,KAAM,AAbN,MAAM,OACrB,KAAK,gBAAgB,WAAW,EAAS,MACzC,CACE,YAAa,KAAK,gBAAgB,2BAChC,EAAS,MAIP,UAEA,iBAGwB,OAChC,KAAK,iBAAiB,IAAI,EAAU,SAC7B,EAAP,CACA,EAAO,MACL,oCACE,EAAS,KACT,YACA,IASR,SAAgB,CACd,SAAW,KAAwB,MAAK,sBACtC,KAAK,WAAW,UAAU,GAG5B,SAAW,KAAwB,MAAK,4BACtC,KAAK,WAAW,UAAU,GAG5B,KAAK,sBAAwB,GAC7B,KAAK,4BAA4B,OAAS,EAC1C,KAAK,iBAAiB,SAzQnB,EAAM,wBA8QA,oBAAoB,EAAK,wBAnT9B",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(l){const n=new l.Logger("PIXI Image manager"),c=(o,e)=>{n.error("Unable to load file "+o+" with error:",e||"(unknown error)")},d=(o,e)=>{!o||e.smoothed||(o.baseTexture.scaleMode=PIXI.SCALE_MODES.NEAREST)},g=(o,e)=>{e&&!e.smoothed&&(o.magFilter=THREE.NearestFilter,o.minFilter=THREE.NearestFilter)},x=["image","video"];class h{constructor(e){this._loadedTextures=new l.ResourceCache;this._diskTextures=new Map;this._rectangleTextures=new Map;this._scaledTextures=new Map;this._getImageResource=e=>{const r=this._resourceLoader.getResource(e);return r&&this.getResourceKinds().includes(r.kind)?r:null};this._resourceLoader=e,this._invalidTexture=PIXI.Texture.from("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA"),this._loadedThreeTextures=new Hashtable,this._loadedThreeMaterials=new Hashtable}getResourceKinds(){return x}getPIXITexture(e){const r=this._getImageResource(e);if(!r)return n.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const i=this._loadedTextures.get(r);return i?i.valid?i:(n.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture):this._invalidTexture}getOrLoadPIXITexture(e){const r=this._getImageResource(e);if(!r)return n.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const i=this._loadedTextures.get(r);if(i)return i.valid?i:(n.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture);n.log('Loading texture for resource "'+e+'"...');const s=r.file,a=this._resourceLoader.getFullUrl(s),t=PIXI.Texture.from(a,{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(s)?"use-credentials":"anonymous"}}).on("error",u=>{c(s,u)});if(!t)throw new Error("Texture loading by PIXI returned nothing for file "+s+" behind url "+a);return d(t,r),this._loadedTextures.set(r,t),t}getThreeTexture(e){const r=this._loadedThreeTextures.get(e);if(r)return r;const i=this.getPIXITexture(e);if(!this._resourceLoader._runtimeGame.getRenderer().getPIXIRenderer())throw new Error("No PIXI renderer was found.");const a=i.baseTexture.resource.source;if(!(a instanceof HTMLImageElement))throw new Error(`Can't load texture for resource "${e}" as it's not an image.`);const t=new THREE.Texture(a);t.magFilter=THREE.LinearFilter,t.minFilter=THREE.LinearFilter,t.wrapS=THREE.RepeatWrapping,t.wrapT=THREE.RepeatWrapping,t.colorSpace=THREE.SRGBColorSpace,t.needsUpdate=!0;const u=this._getImageResource(e);return g(t,u),this._loadedThreeTextures.put(e,t),t}getThreeMaterial(e,{useTransparentTexture:r,forceBasicMaterial:i}){const s=`${e}|${r?1:0}|${i?1:0}`,a=this._loadedThreeMaterials.get(s);if(a)return a;const t=i?new THREE.MeshBasicMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r}):new THREE.MeshStandardMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r,metalness:0});return this._loadedThreeMaterials.put(s,t),t}getPIXIVideoTexture(e){if(e==="")return this._invalidTexture;const r=this._getImageResource(e);if(!r)return n.warn('Unable to find video texture for resource "'+e+'".'),this._invalidTexture;const i=this._loadedTextures.get(r);return i||this._invalidTexture}getInvalidPIXITexture(){return this._invalidTexture}async loadResource(e){const r=this._resourceLoader.getResource(e);if(!r){n.warn('Unable to find texture for resource "'+e+'".');return}await this._loadTexture(r)}async processResource(e){}async _loadTexture(e){if(!this._loadedTextures.get(e))try{if(e.kind==="video")await new Promise((r,i)=>{const s=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous",autoPlay:!1}}).on("error",t=>{i(t)});s.baseTexture.on("loaded",()=>{this._loadedTextures.set(e,s),d(s,e),r()}).on("error",t=>{i(t)})});else{const r=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{autoLoad:!1,crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous"}});await r.baseTexture.resource.load(),this._loadedTextures.set(e,r),d(r,e)}}catch(r){c(e.file,r)}}getOrCreateDiskTexture(e,r){let i=this._diskTextures.get(e);if(!i){const s=new PIXI.Graphics;s.lineStyle(0,0,0),s.beginFill(l.rgbToHexNumber(255,255,255),1),s.drawCircle(0,0,e),s.endFill(),i=r.generateTexture(s),s.destroy(),this._diskTextures.set(e,i)}return i}getOrCreateRectangleTexture(e,r,i){const s=`${e}_${r}`;let a=this._rectangleTextures.get(s);if(!a){const t=new PIXI.Graphics;t.lineStyle(0,0,0),t.beginFill(l.rgbToHexNumber(255,255,255),1),t.drawRect(0,0,e,r),t.endFill(),a=i.generateTexture(t),t.destroy(),this._rectangleTextures.set(s,a)}return a}getOrCreateScaledTexture(e,r,i,s){const a=`${e}_${r}_${i}`;let t=this._scaledTextures.get(a);if(!t){const u=new PIXI.Graphics,T=new PIXI.Sprite(this.getPIXITexture(e));T.width=r,T.height=i,u.addChild(T),t=s.generateTexture(u),u.destroy(),this._scaledTextures.set(a,t)}return t}}l.PixiImageManager=h,l.ImageManager=l.PixiImageManager})(gdjs||(gdjs={}));
1
+ var gdjs;(function(l){const o=new l.Logger("PIXI Image manager"),c=(n,e)=>{o.error("Unable to load file "+n+" with error:",e||"(unknown error)")},d=(n,e)=>{!n||e.smoothed||(n.baseTexture.scaleMode=PIXI.SCALE_MODES.NEAREST)},x=(n,e)=>{e&&!e.smoothed&&(n.magFilter=THREE.NearestFilter,n.minFilter=THREE.NearestFilter)},g=["image","video"];class h{constructor(e){this._loadedTextures=new l.ResourceCache;this._diskTextures=new Map;this._rectangleTextures=new Map;this._scaledTextures=new Map;this._getImageResource=e=>{const r=this._resourceLoader.getResource(e);return r&&this.getResourceKinds().includes(r.kind)?r:null};this._resourceLoader=e,this._invalidTexture=PIXI.Texture.from("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA"),this._loadedThreeTextures=new Hashtable,this._loadedThreeMaterials=new Hashtable}getResourceKinds(){return g}getPIXITexture(e){const r=this._getImageResource(e);if(!r)return o.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);return t?t.valid?t:(o.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture):this._invalidTexture}getOrLoadPIXITexture(e){const r=this._getImageResource(e);if(!r)return o.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);if(t)return t.valid?t:(o.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture);o.log('Loading texture for resource "'+e+'"...');const s=r.file,a=this._resourceLoader.getFullUrl(s),i=PIXI.Texture.from(a,{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(s)?"use-credentials":"anonymous"}}).on("error",u=>{c(s,u)});if(!i)throw new Error("Texture loading by PIXI returned nothing for file "+s+" behind url "+a);return d(i,r),this._loadedTextures.set(r,i),i}getThreeTexture(e){const r=this._loadedThreeTextures.get(e);if(r)return r;const t=this.getPIXITexture(e);if(!this._resourceLoader._runtimeGame.getRenderer().getPIXIRenderer())throw new Error("No PIXI renderer was found.");const a=t.baseTexture.resource.source;if(!(a instanceof HTMLImageElement))throw new Error(`Can't load texture for resource "${e}" as it's not an image.`);const i=new THREE.Texture(a);i.magFilter=THREE.LinearFilter,i.minFilter=THREE.LinearFilter,i.wrapS=THREE.RepeatWrapping,i.wrapT=THREE.RepeatWrapping,i.colorSpace=THREE.SRGBColorSpace,i.needsUpdate=!0;const u=this._getImageResource(e);return x(i,u),this._loadedThreeTextures.put(e,i),i}getThreeMaterial(e,{useTransparentTexture:r,forceBasicMaterial:t}){const s=`${e}|${r?1:0}|${t?1:0}`,a=this._loadedThreeMaterials.get(s);if(a)return a;const i=t?new THREE.MeshBasicMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r}):new THREE.MeshStandardMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r,metalness:0});return this._loadedThreeMaterials.put(s,i),i}getPIXIVideoTexture(e){if(e==="")return this._invalidTexture;const r=this._getImageResource(e);if(!r)return o.warn('Unable to find video texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);return t||this._invalidTexture}getInvalidPIXITexture(){return this._invalidTexture}async loadResource(e){const r=this._resourceLoader.getResource(e);if(!r){o.warn('Unable to find texture for resource "'+e+'".');return}await this._loadTexture(r)}async processResource(e){}async _loadTexture(e){if(!this._loadedTextures.get(e))try{if(e.kind==="video")await new Promise((r,t)=>{const s=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous",autoPlay:!1}}).on("error",i=>{t(i)});s.baseTexture.on("loaded",()=>{this._loadedTextures.set(e,s),d(s,e),r()}).on("error",i=>{t(i)})});else{const r=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{autoLoad:!1,crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous"}});await r.baseTexture.resource.load(),this._loadedTextures.set(e,r),d(r,e)}}catch(r){c(e.file,r)}}getOrCreateDiskTexture(e,r){let t=this._diskTextures.get(e);if(!t){const s=new PIXI.Graphics;s.lineStyle(0,0,0),s.beginFill(l.rgbToHexNumber(255,255,255),1),s.drawCircle(0,0,e),s.endFill(),t=r.generateTexture(s),s.destroy(),this._diskTextures.set(e,t)}return t}getOrCreateRectangleTexture(e,r,t){const s=`${e}_${r}`;let a=this._rectangleTextures.get(s);if(!a){const i=new PIXI.Graphics;i.lineStyle(0,0,0),i.beginFill(l.rgbToHexNumber(255,255,255),1),i.drawRect(0,0,e,r),i.endFill(),a=t.generateTexture(i),i.destroy(),this._rectangleTextures.set(s,a)}return a}getOrCreateScaledTexture(e,r,t,s){const a=`${e}_${r}_${t}`;let i=this._scaledTextures.get(a);if(!i){const u=new PIXI.Graphics,T=new PIXI.Sprite(this.getPIXITexture(e));T.width=r,T.height=t,u.addChild(T),i=s.generateTexture(u),u.destroy(),this._scaledTextures.set(a,i)}return i}dispose(){this._loadedTextures.clear();const e=[];this._loadedThreeTextures.values(e),this._loadedThreeTextures.clear();for(const t of e)t.dispose();const r=[];this._loadedThreeMaterials.values(r),this._loadedThreeMaterials.clear();for(const t of r)t.dispose();for(const t of this._diskTextures.values())t.destroyed||t.destroy();this._diskTextures.clear();for(const t of this._rectangleTextures.values())t.destroyed||t.destroy();this._rectangleTextures.clear();for(const t of this._scaledTextures.values())t.destroyed||t.destroy();this._scaledTextures.clear()}}l.PixiImageManager=h,l.ImageManager=l.PixiImageManager})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=pixi-image-manager.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../GDevelop/GDJS/Runtime/pixi-renderers/pixi-image-manager.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 const logger = new gdjs.Logger('PIXI Image manager');\n\n const logFileLoadingError = (file: string, error: Error | undefined) => {\n logger.error(\n 'Unable to load file ' + file + ' with error:',\n error ? error : '(unknown error)'\n );\n };\n\n const applyTextureSettings = (\n texture: PIXI.Texture | undefined,\n resourceData: ResourceData\n ) => {\n if (!texture) return;\n\n if (!resourceData.smoothed) {\n texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST;\n }\n };\n\n const applyThreeTextureSettings = (\n threeTexture: THREE.Texture,\n resourceData: ResourceData | null\n ) => {\n if (resourceData && !resourceData.smoothed) {\n threeTexture.magFilter = THREE.NearestFilter;\n threeTexture.minFilter = THREE.NearestFilter;\n }\n };\n\n const resourceKinds: Array<ResourceKind> = ['image', 'video'];\n\n /**\n * PixiImageManager loads and stores textures that can be used by the Pixi.js renderers.\n */\n export class PixiImageManager implements gdjs.ResourceManager {\n /**\n * The invalid texture is a 8x8 PNG file filled with magenta (#ff00ff), to be\n * easily spotted if rendered on screen.\n */\n private _invalidTexture: PIXI.Texture;\n\n /**\n * Map associating a resource name to the loaded PixiJS texture.\n */\n private _loadedTextures = new gdjs.ResourceCache<PIXI.Texture>();\n\n /**\n * Map associating a resource name to the loaded Three.js texture.\n */\n private _loadedThreeTextures: Hashtable<THREE.Texture>;\n private _loadedThreeMaterials: Hashtable<THREE.Material>;\n\n private _diskTextures = new Map<float, PIXI.Texture>();\n private _rectangleTextures = new Map<string, PIXI.Texture>();\n private _scaledTextures = new Map<string, PIXI.Texture>();\n\n private _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 this._invalidTexture = PIXI.Texture.from(\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA'\n );\n this._loadedThreeTextures = new Hashtable();\n this._loadedThreeMaterials = new Hashtable();\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Return the PIXI texture associated to the specified resource name.\n * Returns a placeholder texture if not found.\n * @param resourceName The name of the resource\n * @returns The requested texture, or a placeholder if not found.\n */\n getPIXITexture(resourceName: string): PIXI.Texture {\n const resource = this._getImageResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return this._invalidTexture;\n }\n\n const existingTexture = this._loadedTextures.get(resource);\n if (!existingTexture) {\n return this._invalidTexture;\n }\n if (!existingTexture.valid) {\n logger.error(\n 'Texture for ' +\n resourceName +\n ' is not valid anymore (or never was).'\n );\n return this._invalidTexture;\n }\n\n return existingTexture;\n }\n\n /**\n * Return the PIXI texture associated to the specified resource name.\n * If not found in the loaded textures, this method will try to load it.\n * Warning: this method should only be used in specific cases that cannot rely on\n * the initial resources loading of the game, such as the splashscreen.\n * @param resourceName The name of the resource\n * @returns The requested texture, or a placeholder if not valid.\n */\n getOrLoadPIXITexture(resourceName: string): PIXI.Texture {\n const resource = this._getImageResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return this._invalidTexture;\n }\n\n const existingTexture = this._loadedTextures.get(resource);\n if (existingTexture) {\n if (existingTexture.valid) {\n return existingTexture;\n } else {\n logger.error(\n 'Texture for ' +\n resourceName +\n ' is not valid anymore (or never was).'\n );\n return this._invalidTexture;\n }\n }\n\n logger.log('Loading texture for resource \"' + resourceName + '\"...');\n const file = resource.file;\n const url = this._resourceLoader.getFullUrl(file);\n const texture = PIXI.Texture.from(url, {\n resourceOptions: {\n // Note that using `false`\n // to not having `crossorigin` at all would NOT work because the browser would taint the\n // loaded resource so that it can't be read/used in a canvas (it's only working for display `<img>` on screen).\n crossorigin: this._resourceLoader.checkIfCredentialsRequired(file)\n ? 'use-credentials'\n : 'anonymous',\n },\n }).on('error', (error) => {\n logFileLoadingError(file, error);\n });\n if (!texture) {\n throw new Error(\n 'Texture loading by PIXI returned nothing for file ' +\n file +\n ' behind url ' +\n url\n );\n }\n applyTextureSettings(texture, resource);\n\n this._loadedTextures.set(resource, texture);\n return texture;\n }\n\n /**\n * Return the three.js texture associated to the specified resource name.\n * Returns a placeholder texture if not found.\n * @param resourceName The name of the resource\n * @returns The requested texture, or a placeholder if not found.\n */\n getThreeTexture(resourceName: string): THREE.Texture {\n const loadedThreeTexture = this._loadedThreeTextures.get(resourceName);\n if (loadedThreeTexture) {\n return loadedThreeTexture;\n }\n\n // Texture is not loaded, load it now from the PixiJS texture.\n // TODO (3D) - optimization: don't load the PixiJS Texture if not used by PixiJS.\n // TODO (3D) - optimization: Ideally we could even share the same WebGL texture.\n const pixiTexture = this.getPIXITexture(resourceName);\n const pixiRenderer = this._resourceLoader._runtimeGame\n .getRenderer()\n .getPIXIRenderer();\n if (!pixiRenderer) throw new Error('No PIXI renderer was found.');\n\n // @ts-ignore - source does exist on resource.\n const image = pixiTexture.baseTexture.resource.source;\n if (!(image instanceof HTMLImageElement)) {\n throw new Error(\n `Can't load texture for resource \"${resourceName}\" as it's not an image.`\n );\n }\n\n const threeTexture = new THREE.Texture(image);\n threeTexture.magFilter = THREE.LinearFilter;\n threeTexture.minFilter = THREE.LinearFilter;\n threeTexture.wrapS = THREE.RepeatWrapping;\n threeTexture.wrapT = THREE.RepeatWrapping;\n threeTexture.colorSpace = THREE.SRGBColorSpace;\n threeTexture.needsUpdate = true;\n\n const resource = this._getImageResource(resourceName);\n\n applyThreeTextureSettings(threeTexture, resource);\n this._loadedThreeTextures.put(resourceName, threeTexture);\n\n return threeTexture;\n }\n\n /**\n * Return the three.js material associated to the specified resource name.\n * @param resourceName The name of the resource\n * @param options\n * @returns The requested material.\n */\n getThreeMaterial(\n resourceName: string,\n {\n useTransparentTexture,\n forceBasicMaterial,\n }: { useTransparentTexture: boolean; forceBasicMaterial: boolean }\n ): THREE.Material {\n const cacheKey = `${resourceName}|${useTransparentTexture ? 1 : 0}|${\n forceBasicMaterial ? 1 : 0\n }`;\n\n const loadedThreeMaterial = this._loadedThreeMaterials.get(cacheKey);\n if (loadedThreeMaterial) return loadedThreeMaterial;\n\n const material = forceBasicMaterial\n ? new THREE.MeshBasicMaterial({\n map: this.getThreeTexture(resourceName),\n side: useTransparentTexture ? THREE.DoubleSide : THREE.FrontSide,\n transparent: useTransparentTexture,\n })\n : new THREE.MeshStandardMaterial({\n map: this.getThreeTexture(resourceName),\n side: useTransparentTexture ? THREE.DoubleSide : THREE.FrontSide,\n transparent: useTransparentTexture,\n metalness: 0,\n });\n this._loadedThreeMaterials.put(cacheKey, material);\n return material;\n }\n\n /**\n * Return the PIXI video texture associated to the specified resource name.\n * Returns a placeholder texture if not found.\n * @param resourceName The name of the resource to get.\n */\n getPIXIVideoTexture(resourceName: string) {\n if (resourceName === '') {\n return this._invalidTexture;\n }\n const resource = this._getImageResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find video texture for resource \"' + resourceName + '\".'\n );\n return this._invalidTexture;\n }\n\n const texture = this._loadedTextures.get(resource);\n if (!texture) {\n return this._invalidTexture;\n }\n return texture;\n }\n\n private _getImageResource = (resourceName: string): ResourceData | null => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n };\n\n /**\n * Return a PIXI texture which can be used as a placeholder when no\n * suitable texture can be found.\n */\n getInvalidPIXITexture() {\n return this._invalidTexture;\n }\n\n /**\n * Load the specified resources, so that textures are loaded and can then be\n * used by calling `getPIXITexture`.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return;\n }\n await this._loadTexture(resource);\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because images are light enough to be parsed in background.\n }\n\n /**\n * Load the specified resources, so that textures are loaded and can then be\n * used by calling `getPIXITexture`.\n * @param onProgress Callback called each time a new file is loaded.\n */\n async _loadTexture(resource: ResourceData): Promise<void> {\n if (this._loadedTextures.get(resource)) {\n return;\n }\n try {\n if (resource.kind === 'video') {\n // For videos, we want to preload them so they are available as soon as we want to use them.\n // We cannot use Pixi.assets.load() as it does not allow passing options (autoplay) to the resource loader.\n // Pixi.Texture.from() does not return a promise, so we need to ensure we look at the 'loaded' event of the baseTexture,\n // to continue, otherwise if we try to play the video too soon (at the beginning of scene for instance),\n // it will fail.\n await new Promise<void>((resolve, reject) => {\n const texture = PIXI.Texture.from(\n this._resourceLoader.getFullUrl(resource.file),\n {\n resourceOptions: {\n crossorigin: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n )\n ? 'use-credentials'\n : 'anonymous',\n autoPlay: false,\n },\n }\n ).on('error', (error) => {\n reject(error);\n });\n\n const baseTexture = texture.baseTexture;\n baseTexture\n .on('loaded', () => {\n this._loadedTextures.set(resource, texture);\n applyTextureSettings(texture, resource);\n resolve();\n })\n .on('error', (error) => {\n reject(error);\n });\n });\n } else {\n // If the file has no extension, PIXI.assets.load cannot find\n // an adequate load parser and does not load the file although\n // we would like to force it to load (we are confident it's an image).\n // TODO: When PIXI v8+ is used, PIXI.Assets.load can be used because\n // loadParser can be forced in PIXI.Assets.load\n // (see https://github.com/pixijs/pixijs/blob/71ed56c569ebc6b53da19e3c49258a0a84892101/packages/assets/src/loader/Loader.ts#L68)\n const loadedTexture = PIXI.Texture.from(\n this._resourceLoader.getFullUrl(resource.file),\n {\n resourceOptions: {\n autoLoad: false,\n crossorigin: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n )\n ? 'use-credentials'\n : 'anonymous',\n },\n }\n );\n await loadedTexture.baseTexture.resource.load();\n\n this._loadedTextures.set(resource, loadedTexture);\n // TODO What if 2 assets share the same file with different settings?\n applyTextureSettings(loadedTexture, resource);\n }\n } catch (error) {\n logFileLoadingError(resource.file, error);\n }\n }\n\n /**\n * Return a texture containing a circle filled with white.\n * @param radius The circle radius\n * @param pixiRenderer The renderer used to generate the texture\n */\n getOrCreateDiskTexture(\n radius: float,\n pixiRenderer: PIXI.Renderer\n ): PIXI.Texture {\n let particleTexture = this._diskTextures.get(radius);\n if (!particleTexture) {\n const graphics = new PIXI.Graphics();\n graphics.lineStyle(0, 0, 0);\n graphics.beginFill(gdjs.rgbToHexNumber(255, 255, 255), 1);\n graphics.drawCircle(0, 0, radius);\n graphics.endFill();\n particleTexture = pixiRenderer.generateTexture(graphics);\n graphics.destroy();\n\n this._diskTextures.set(radius, particleTexture);\n }\n return particleTexture;\n }\n\n /**\n * Return a texture filled with white.\n * @param width The texture width\n * @param height The texture height\n * @param pixiRenderer The renderer used to generate the texture\n */\n getOrCreateRectangleTexture(\n width: float,\n height: float,\n pixiRenderer: PIXI.Renderer\n ): PIXI.Texture {\n const key = `${width}_${height}`;\n let particleTexture = this._rectangleTextures.get(key);\n if (!particleTexture) {\n const graphics = new PIXI.Graphics();\n graphics.lineStyle(0, 0, 0);\n graphics.beginFill(gdjs.rgbToHexNumber(255, 255, 255), 1);\n graphics.drawRect(0, 0, width, height);\n graphics.endFill();\n particleTexture = pixiRenderer.generateTexture(graphics);\n graphics.destroy();\n\n this._rectangleTextures.set(key, particleTexture);\n }\n return particleTexture;\n }\n\n /**\n * Return a texture rescaled according to given dimensions.\n * @param width The texture width\n * @param height The texture height\n * @param pixiRenderer The renderer used to generate the texture\n */\n getOrCreateScaledTexture(\n imageResourceName: string,\n width: float,\n height: float,\n pixiRenderer: PIXI.Renderer\n ): PIXI.Texture {\n const key = `${imageResourceName}_${width}_${height}`;\n let particleTexture = this._scaledTextures.get(key);\n if (!particleTexture) {\n const graphics = new PIXI.Graphics();\n const sprite = new PIXI.Sprite(this.getPIXITexture(imageResourceName));\n sprite.width = width;\n sprite.height = height;\n graphics.addChild(sprite);\n particleTexture = pixiRenderer.generateTexture(graphics);\n graphics.destroy();\n\n this._scaledTextures.set(key, particleTexture);\n }\n return particleTexture;\n }\n }\n\n //Register the class to let the engine use it.\n export const ImageManager = gdjs.PixiImageManager;\n export type ImageManager = gdjs.PixiImageManager;\n}\n"],
5
- "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,sBAEzB,EAAsB,CAAC,EAAc,IAA6B,CACtE,EAAO,MACL,uBAAyB,EAAO,eAChC,GAAgB,oBAId,EAAuB,CAC3B,EACA,IACG,CACH,AAAI,CAAC,GAEA,EAAa,UAChB,GAAQ,YAAY,UAAY,KAAK,YAAY,UAI/C,EAA4B,CAChC,EACA,IACG,CACH,AAAI,GAAgB,CAAC,EAAa,UAChC,GAAa,UAAY,MAAM,cAC/B,EAAa,UAAY,MAAM,gBAI7B,EAAqC,CAAC,QAAS,SAK9C,OAAuD,CA4B5D,YAAY,EAAqC,CAlBzC,qBAAkB,GAAI,GAAK,cAQ3B,mBAAgB,GAAI,KACpB,wBAAqB,GAAI,KACzB,qBAAkB,GAAI,KAyNtB,uBAAoB,AAAC,GAA8C,CACzE,KAAM,GAAW,KAAK,gBAAgB,YAAY,GAClD,MAAO,IAAY,KAAK,mBAAmB,SAAS,EAAS,MACzD,EACA,MApNJ,KAAK,gBAAkB,EACvB,KAAK,gBAAkB,KAAK,QAAQ,KAClC,kIAEF,KAAK,qBAAuB,GAAI,WAChC,KAAK,sBAAwB,GAAI,WAGnC,kBAAmC,CACjC,MAAO,GAST,eAAe,EAAoC,CACjD,KAAM,GAAW,KAAK,kBAAkB,GACxC,GAAI,CAAC,EACH,SAAO,KACL,wCAA0C,EAAe,MAEpD,KAAK,gBAGd,KAAM,GAAkB,KAAK,gBAAgB,IAAI,GACjD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AO,KAAK,eAAe,IACnD,EAAO,MAAQ,EACf,EAAO,OAAS,EAChB,EAAS,SAAS,GAClB,EAAkB,EAAa,gBAAgB,GAC/C,EAAS,UAET,KAAK,gBAAgB,IAAI,EAAK,GAEhC,MAAO,IAtaJ,EAAM,mBA2aA,eAAe,EAAK,mBA/czB",
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 const logger = new gdjs.Logger('PIXI Image manager');\n\n const logFileLoadingError = (file: string, error: Error | undefined) => {\n logger.error(\n 'Unable to load file ' + file + ' with error:',\n error ? error : '(unknown error)'\n );\n };\n\n const applyTextureSettings = (\n texture: PIXI.Texture | undefined,\n resourceData: ResourceData\n ) => {\n if (!texture) return;\n\n if (!resourceData.smoothed) {\n texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST;\n }\n };\n\n const applyThreeTextureSettings = (\n threeTexture: THREE.Texture,\n resourceData: ResourceData | null\n ) => {\n if (resourceData && !resourceData.smoothed) {\n threeTexture.magFilter = THREE.NearestFilter;\n threeTexture.minFilter = THREE.NearestFilter;\n }\n };\n\n const resourceKinds: Array<ResourceKind> = ['image', 'video'];\n\n /**\n * PixiImageManager loads and stores textures that can be used by the Pixi.js renderers.\n */\n export class PixiImageManager implements gdjs.ResourceManager {\n /**\n * The invalid texture is a 8x8 PNG file filled with magenta (#ff00ff), to be\n * easily spotted if rendered on screen.\n */\n private _invalidTexture: PIXI.Texture;\n\n /**\n * Map associating a resource name to the loaded PixiJS texture.\n */\n private _loadedTextures = new gdjs.ResourceCache<PIXI.Texture>();\n\n /**\n * Map associating a resource name to the loaded Three.js texture.\n */\n private _loadedThreeTextures: Hashtable<THREE.Texture>;\n private _loadedThreeMaterials: Hashtable<THREE.Material>;\n\n private _diskTextures = new Map<float, PIXI.Texture>();\n private _rectangleTextures = new Map<string, PIXI.Texture>();\n private _scaledTextures = new Map<string, PIXI.Texture>();\n\n private _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 this._invalidTexture = PIXI.Texture.from(\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA'\n );\n this._loadedThreeTextures = new Hashtable();\n this._loadedThreeMaterials = new Hashtable();\n }\n\n getResourceKinds(): ResourceKind[] {\n return resourceKinds;\n }\n\n /**\n * Return the PIXI texture associated to the specified resource name.\n * Returns a placeholder texture if not found.\n * @param resourceName The name of the resource\n * @returns The requested texture, or a placeholder if not found.\n */\n getPIXITexture(resourceName: string): PIXI.Texture {\n const resource = this._getImageResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return this._invalidTexture;\n }\n\n const existingTexture = this._loadedTextures.get(resource);\n if (!existingTexture) {\n return this._invalidTexture;\n }\n if (!existingTexture.valid) {\n logger.error(\n 'Texture for ' +\n resourceName +\n ' is not valid anymore (or never was).'\n );\n return this._invalidTexture;\n }\n\n return existingTexture;\n }\n\n /**\n * Return the PIXI texture associated to the specified resource name.\n * If not found in the loaded textures, this method will try to load it.\n * Warning: this method should only be used in specific cases that cannot rely on\n * the initial resources loading of the game, such as the splashscreen.\n * @param resourceName The name of the resource\n * @returns The requested texture, or a placeholder if not valid.\n */\n getOrLoadPIXITexture(resourceName: string): PIXI.Texture {\n const resource = this._getImageResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return this._invalidTexture;\n }\n\n const existingTexture = this._loadedTextures.get(resource);\n if (existingTexture) {\n if (existingTexture.valid) {\n return existingTexture;\n } else {\n logger.error(\n 'Texture for ' +\n resourceName +\n ' is not valid anymore (or never was).'\n );\n return this._invalidTexture;\n }\n }\n\n logger.log('Loading texture for resource \"' + resourceName + '\"...');\n const file = resource.file;\n const url = this._resourceLoader.getFullUrl(file);\n const texture = PIXI.Texture.from(url, {\n resourceOptions: {\n // Note that using `false`\n // to not having `crossorigin` at all would NOT work because the browser would taint the\n // loaded resource so that it can't be read/used in a canvas (it's only working for display `<img>` on screen).\n crossorigin: this._resourceLoader.checkIfCredentialsRequired(file)\n ? 'use-credentials'\n : 'anonymous',\n },\n }).on('error', (error) => {\n logFileLoadingError(file, error);\n });\n if (!texture) {\n throw new Error(\n 'Texture loading by PIXI returned nothing for file ' +\n file +\n ' behind url ' +\n url\n );\n }\n applyTextureSettings(texture, resource);\n\n this._loadedTextures.set(resource, texture);\n return texture;\n }\n\n /**\n * Return the three.js texture associated to the specified resource name.\n * Returns a placeholder texture if not found.\n * @param resourceName The name of the resource\n * @returns The requested texture, or a placeholder if not found.\n */\n getThreeTexture(resourceName: string): THREE.Texture {\n const loadedThreeTexture = this._loadedThreeTextures.get(resourceName);\n if (loadedThreeTexture) {\n return loadedThreeTexture;\n }\n\n // Texture is not loaded, load it now from the PixiJS texture.\n // TODO (3D) - optimization: don't load the PixiJS Texture if not used by PixiJS.\n // TODO (3D) - optimization: Ideally we could even share the same WebGL texture.\n const pixiTexture = this.getPIXITexture(resourceName);\n const pixiRenderer = this._resourceLoader._runtimeGame\n .getRenderer()\n .getPIXIRenderer();\n if (!pixiRenderer) throw new Error('No PIXI renderer was found.');\n\n // @ts-ignore - source does exist on resource.\n const image = pixiTexture.baseTexture.resource.source;\n if (!(image instanceof HTMLImageElement)) {\n throw new Error(\n `Can't load texture for resource \"${resourceName}\" as it's not an image.`\n );\n }\n\n const threeTexture = new THREE.Texture(image);\n threeTexture.magFilter = THREE.LinearFilter;\n threeTexture.minFilter = THREE.LinearFilter;\n threeTexture.wrapS = THREE.RepeatWrapping;\n threeTexture.wrapT = THREE.RepeatWrapping;\n threeTexture.colorSpace = THREE.SRGBColorSpace;\n threeTexture.needsUpdate = true;\n\n const resource = this._getImageResource(resourceName);\n\n applyThreeTextureSettings(threeTexture, resource);\n this._loadedThreeTextures.put(resourceName, threeTexture);\n\n return threeTexture;\n }\n\n /**\n * Return the three.js material associated to the specified resource name.\n * @param resourceName The name of the resource\n * @param options\n * @returns The requested material.\n */\n getThreeMaterial(\n resourceName: string,\n {\n useTransparentTexture,\n forceBasicMaterial,\n }: { useTransparentTexture: boolean; forceBasicMaterial: boolean }\n ): THREE.Material {\n const cacheKey = `${resourceName}|${useTransparentTexture ? 1 : 0}|${\n forceBasicMaterial ? 1 : 0\n }`;\n\n const loadedThreeMaterial = this._loadedThreeMaterials.get(cacheKey);\n if (loadedThreeMaterial) return loadedThreeMaterial;\n\n const material = forceBasicMaterial\n ? new THREE.MeshBasicMaterial({\n map: this.getThreeTexture(resourceName),\n side: useTransparentTexture ? THREE.DoubleSide : THREE.FrontSide,\n transparent: useTransparentTexture,\n })\n : new THREE.MeshStandardMaterial({\n map: this.getThreeTexture(resourceName),\n side: useTransparentTexture ? THREE.DoubleSide : THREE.FrontSide,\n transparent: useTransparentTexture,\n metalness: 0,\n });\n this._loadedThreeMaterials.put(cacheKey, material);\n return material;\n }\n\n /**\n * Return the PIXI video texture associated to the specified resource name.\n * Returns a placeholder texture if not found.\n * @param resourceName The name of the resource to get.\n */\n getPIXIVideoTexture(resourceName: string) {\n if (resourceName === '') {\n return this._invalidTexture;\n }\n const resource = this._getImageResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find video texture for resource \"' + resourceName + '\".'\n );\n return this._invalidTexture;\n }\n\n const texture = this._loadedTextures.get(resource);\n if (!texture) {\n return this._invalidTexture;\n }\n return texture;\n }\n\n private _getImageResource = (resourceName: string): ResourceData | null => {\n const resource = this._resourceLoader.getResource(resourceName);\n return resource && this.getResourceKinds().includes(resource.kind)\n ? resource\n : null;\n };\n\n /**\n * Return a PIXI texture which can be used as a placeholder when no\n * suitable texture can be found.\n */\n getInvalidPIXITexture() {\n return this._invalidTexture;\n }\n\n /**\n * Load the specified resources, so that textures are loaded and can then be\n * used by calling `getPIXITexture`.\n */\n async loadResource(resourceName: string): Promise<void> {\n const resource = this._resourceLoader.getResource(resourceName);\n if (!resource) {\n logger.warn(\n 'Unable to find texture for resource \"' + resourceName + '\".'\n );\n return;\n }\n await this._loadTexture(resource);\n }\n\n async processResource(resourceName: string): Promise<void> {\n // Do nothing because images are light enough to be parsed in background.\n }\n\n /**\n * Load the specified resources, so that textures are loaded and can then be\n * used by calling `getPIXITexture`.\n * @param onProgress Callback called each time a new file is loaded.\n */\n async _loadTexture(resource: ResourceData): Promise<void> {\n if (this._loadedTextures.get(resource)) {\n return;\n }\n try {\n if (resource.kind === 'video') {\n // For videos, we want to preload them so they are available as soon as we want to use them.\n // We cannot use Pixi.assets.load() as it does not allow passing options (autoplay) to the resource loader.\n // Pixi.Texture.from() does not return a promise, so we need to ensure we look at the 'loaded' event of the baseTexture,\n // to continue, otherwise if we try to play the video too soon (at the beginning of scene for instance),\n // it will fail.\n await new Promise<void>((resolve, reject) => {\n const texture = PIXI.Texture.from(\n this._resourceLoader.getFullUrl(resource.file),\n {\n resourceOptions: {\n crossorigin: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n )\n ? 'use-credentials'\n : 'anonymous',\n autoPlay: false,\n },\n }\n ).on('error', (error) => {\n reject(error);\n });\n\n const baseTexture = texture.baseTexture;\n baseTexture\n .on('loaded', () => {\n this._loadedTextures.set(resource, texture);\n applyTextureSettings(texture, resource);\n resolve();\n })\n .on('error', (error) => {\n reject(error);\n });\n });\n } else {\n // If the file has no extension, PIXI.assets.load cannot find\n // an adequate load parser and does not load the file although\n // we would like to force it to load (we are confident it's an image).\n // TODO: When PIXI v8+ is used, PIXI.Assets.load can be used because\n // loadParser can be forced in PIXI.Assets.load\n // (see https://github.com/pixijs/pixijs/blob/71ed56c569ebc6b53da19e3c49258a0a84892101/packages/assets/src/loader/Loader.ts#L68)\n const loadedTexture = PIXI.Texture.from(\n this._resourceLoader.getFullUrl(resource.file),\n {\n resourceOptions: {\n autoLoad: false,\n crossorigin: this._resourceLoader.checkIfCredentialsRequired(\n resource.file\n )\n ? 'use-credentials'\n : 'anonymous',\n },\n }\n );\n await loadedTexture.baseTexture.resource.load();\n\n this._loadedTextures.set(resource, loadedTexture);\n // TODO What if 2 assets share the same file with different settings?\n applyTextureSettings(loadedTexture, resource);\n }\n } catch (error) {\n logFileLoadingError(resource.file, error);\n }\n }\n\n /**\n * Return a texture containing a circle filled with white.\n * @param radius The circle radius\n * @param pixiRenderer The renderer used to generate the texture\n */\n getOrCreateDiskTexture(\n radius: float,\n pixiRenderer: PIXI.Renderer\n ): PIXI.Texture {\n let particleTexture = this._diskTextures.get(radius);\n if (!particleTexture) {\n const graphics = new PIXI.Graphics();\n graphics.lineStyle(0, 0, 0);\n graphics.beginFill(gdjs.rgbToHexNumber(255, 255, 255), 1);\n graphics.drawCircle(0, 0, radius);\n graphics.endFill();\n particleTexture = pixiRenderer.generateTexture(graphics);\n graphics.destroy();\n\n this._diskTextures.set(radius, particleTexture);\n }\n return particleTexture;\n }\n\n /**\n * Return a texture filled with white.\n * @param width The texture width\n * @param height The texture height\n * @param pixiRenderer The renderer used to generate the texture\n */\n getOrCreateRectangleTexture(\n width: float,\n height: float,\n pixiRenderer: PIXI.Renderer\n ): PIXI.Texture {\n const key = `${width}_${height}`;\n let particleTexture = this._rectangleTextures.get(key);\n if (!particleTexture) {\n const graphics = new PIXI.Graphics();\n graphics.lineStyle(0, 0, 0);\n graphics.beginFill(gdjs.rgbToHexNumber(255, 255, 255), 1);\n graphics.drawRect(0, 0, width, height);\n graphics.endFill();\n particleTexture = pixiRenderer.generateTexture(graphics);\n graphics.destroy();\n\n this._rectangleTextures.set(key, particleTexture);\n }\n return particleTexture;\n }\n\n /**\n * Return a texture rescaled according to given dimensions.\n * @param width The texture width\n * @param height The texture height\n * @param pixiRenderer The renderer used to generate the texture\n */\n getOrCreateScaledTexture(\n imageResourceName: string,\n width: float,\n height: float,\n pixiRenderer: PIXI.Renderer\n ): PIXI.Texture {\n const key = `${imageResourceName}_${width}_${height}`;\n let particleTexture = this._scaledTextures.get(key);\n if (!particleTexture) {\n const graphics = new PIXI.Graphics();\n const sprite = new PIXI.Sprite(this.getPIXITexture(imageResourceName));\n sprite.width = width;\n sprite.height = height;\n graphics.addChild(sprite);\n particleTexture = pixiRenderer.generateTexture(graphics);\n graphics.destroy();\n\n this._scaledTextures.set(key, particleTexture);\n }\n return particleTexture;\n }\n\n /**\n * To be called when the game is disposed.\n * Clear caches of loaded textures and materials.\n */\n dispose(): void {\n this._loadedTextures.clear();\n\n const threeTextures: THREE.Texture[] = [];\n this._loadedThreeTextures.values(threeTextures);\n this._loadedThreeTextures.clear();\n for (const threeTexture of threeTextures) {\n threeTexture.dispose();\n }\n\n const threeMaterials: THREE.Material[] = [];\n this._loadedThreeMaterials.values(threeMaterials);\n this._loadedThreeMaterials.clear();\n for (const threeMaterial of threeMaterials) {\n threeMaterial.dispose();\n }\n\n for (const pixiTexture of this._diskTextures.values()) {\n if (pixiTexture.destroyed) {\n continue;\n }\n\n pixiTexture.destroy();\n }\n this._diskTextures.clear();\n\n for (const pixiTexture of this._rectangleTextures.values()) {\n if (pixiTexture.destroyed) {\n continue;\n }\n\n pixiTexture.destroy();\n }\n this._rectangleTextures.clear();\n\n for (const pixiTexture of this._scaledTextures.values()) {\n if (pixiTexture.destroyed) {\n continue;\n }\n\n pixiTexture.destroy();\n }\n this._scaledTextures.clear();\n }\n }\n\n //Register the class to let the engine use it.\n export const ImageManager = gdjs.PixiImageManager;\n export type ImageManager = gdjs.PixiImageManager;\n}\n"],
5
+ "mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,sBAEzB,EAAsB,CAAC,EAAc,IAA6B,CACtE,EAAO,MACL,uBAAyB,EAAO,eAChC,GAAgB,oBAId,EAAuB,CAC3B,EACA,IACG,CACH,AAAI,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,MAAK,mBAAmB,SAChD,AAAI,EAAY,WAIhB,EAAY,UAEd,KAAK,mBAAmB,QAExB,SAAW,KAAe,MAAK,gBAAgB,SAC7C,AAAI,EAAY,WAIhB,EAAY,UAEd,KAAK,gBAAgB,SAvdlB,EAAM,mBA4dA,eAAe,EAAK,mBAhgBzB",
6
6
  "names": []
7
7
  }
@@ -1,2 +1,2 @@
1
- var gdjs;(function(l){const u=new l.Logger("PIXI game renderer"),f=[37,38,39,40];class R{constructor(t,e){this._isFullPage=!0;this._isFullscreen=!1;this._pixiRenderer=null;this._threeRenderer=null;this._gameCanvas=null;this._domElementsContainer=null;this._canvasWidth=0;this._canvasHeight=0;this._keepRatio=!0;this._nextFrameId=0;this.getElectronRemote=()=>{if(typeof require=="function"){const t=this._game.getAdditionalOptions(),e=t&&t.electronRemoteRequirePath?t.electronRemoteRequirePath:"@electron/remote";try{return require(e)}catch(i){console.error(`Could not load @electron/remote from "${e}". Error is:`,i)}}return null};this._game=t,this._forceFullscreen=e,this._marginLeft=this._marginTop=this._marginRight=this._marginBottom=0,this._setupOrientation()}createStandardCanvas(t){let e;typeof THREE!="undefined"?(e=document.createElement("canvas"),this._threeRenderer=new THREE.WebGLRenderer({canvas:e,antialias:this._game.getAntialiasingMode()!=="none"&&(this._game.isAntialisingEnabledOnMobile()||!l.evtTools.common.isMobile())}),this._threeRenderer.useLegacyLights=!0,this._threeRenderer.autoClear=!1,this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._pixiRenderer=new PIXI.Renderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),view:e,context:this._threeRenderer.getContext(),clearBeforeRender:!1,preserveDrawingBuffer:!0,antialias:!1,backgroundAlpha:0}),e=this._threeRenderer.domElement):(this._pixiRenderer=PIXI.autoDetectRenderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),preserveDrawingBuffer:!0,antialias:!1}),e=this._pixiRenderer.view),this._pixiRenderer.plugins.accessibility.destroy(),delete this._pixiRenderer.plugins.accessibility,t.appendChild(e),this._gameCanvas=e,e.style.position="absolute",e.tabIndex=1,e.style.userSelect="none",e.style.outline="none";const i=document.createElement("div");i.style.position="absolute",i.style.overflow="hidden",i.style.outline="none",i.style.pointerEvents="none",i.addEventListener("scroll",o=>{i.scrollLeft=0,i.scrollTop=0,o.preventDefault()}),e.addEventListener("pointerdown",()=>{e.focus()}),i.style["-webkit-user-select"]="none",t.appendChild(i),this._domElementsContainer=i,this._resizeCanvas(),this._game.getScaleMode()==="nearest"&&(e.style["image-rendering"]="-moz-crisp-edges",e.style["image-rendering"]="-webkit-optimize-contrast",e.style["image-rendering"]="-webkit-crisp-edges",e.style["image-rendering"]="pixelated"),this._game.getPixelsRounding()&&(PIXI.settings.ROUND_PIXELS=!0),window.addEventListener("resize",()=>{this._game.onWindowInnerSizeChanged(),this._resizeCanvas()}),e.focus()}static getWindowInnerWidth(){return typeof window!="undefined"?window.innerWidth:800}static getWindowInnerHeight(){return typeof window!="undefined"?window.innerHeight:800}updateRendererSize(){this._resizeCanvas()}_setupOrientation(){if(typeof window=="undefined"||!window.screen||!window.screen.orientation)return;const t=this._game.getGameData().properties.orientation;try{if(t==="default"){const e=window.screen.orientation.unlock();e&&e.catch(()=>{})}else window.screen.orientation.lock(t).catch(()=>{})}catch(e){u.error("Unexpected error while setting up orientation: ",e)}}_resizeCanvas(){if(!this._pixiRenderer||!this._domElementsContainer)return;(this._pixiRenderer.width!==this._game.getGameResolutionWidth()||this._pixiRenderer.height!==this._game.getGameResolutionHeight())&&(this._pixiRenderer.resize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._threeRenderer&&this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()));const t=this._forceFullscreen||this._isFullPage||this._isFullscreen;let e=this._game.getGameResolutionWidth(),i=this._game.getGameResolutionHeight(),o=window.innerWidth-this._marginLeft-this._marginRight,r=window.innerHeight-this._marginTop-this._marginBottom;if(o<0&&(o=0),r<0&&(r=0),t&&!this._keepRatio)e=o,i=r;else if(t&&this._keepRatio||e>o||i>r){let c=o/e;i*c>r&&(c=r/i),e*=c,i*=c}this._gameCanvas&&(this._gameCanvas.style.top=this._marginTop+(r-i)/2+"px",this._gameCanvas.style.left=this._marginLeft+(o-e)/2+"px",this._gameCanvas.style.width=e+"px",this._gameCanvas.style.height=i+"px"),this._domElementsContainer.style.top=this._marginTop+(r-i)/2+"px",this._domElementsContainer.style.left=this._marginLeft+(o-e)/2+"px",this._domElementsContainer.style.width=e+"px",this._domElementsContainer.style.height=i+"px",this._canvasWidth=e,this._canvasHeight=i}keepAspectRatio(t){this._keepRatio!==t&&(this._keepRatio=t,this._resizeCanvas())}setMargins(t,e,i,o){this._marginTop===t&&this._marginRight===e&&this._marginBottom===i&&this._marginLeft===o||(this._marginTop=t,this._marginRight=e,this._marginBottom=i,this._marginLeft=o,this._resizeCanvas())}setWindowSize(t,e){const i=this.getElectronRemote();if(i){const o=i.getCurrentWindow();try{o&&o.setContentSize(t,e)}catch(r){u.error(`Window size setting to width ${t} and height ${e} failed. See error:`,r)}}else u.warn("Window size can't be changed on this platform.")}centerWindow(){const t=this.getElectronRemote();if(t){const e=t.getCurrentWindow();try{e&&e.center()}catch(i){u.error("Window centering failed. See error:",i)}}else u.warn("Window can't be centered on this platform.")}setFullScreen(t){if(!this._forceFullscreen&&this._isFullscreen!==t){this._isFullscreen=!!t;const e=this.getElectronRemote();if(e){const i=e.getCurrentWindow();try{i&&i.setFullScreen(this._isFullscreen)}catch(o){u.error(`Full screen setting to ${this._isFullscreen} failed. See error:`,o)}}else this._isFullscreen?document.documentElement.requestFullscreen?document.documentElement.requestFullscreen():document.documentElement.mozRequestFullScreen?document.documentElement.mozRequestFullScreen():document.documentElement.webkitRequestFullScreen&&document.documentElement.webkitRequestFullScreen():document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen();this._resizeCanvas()}}isFullScreen(){const t=this.getElectronRemote();if(t)try{return t.getCurrentWindow().isFullScreen()}catch(e){return u.error("Full screen detection failed. See error:",e),!1}return this._isFullscreen||window.screen.height===window.innerHeight}convertCanvasToDomElementContainerCoords(t,e){const i=e||[0,0];return i[0]=t[0]*this._canvasWidth/this._game.getGameResolutionWidth(),i[1]=t[1]*this._canvasHeight/this._game.getGameResolutionHeight(),i}getCanvasToDomElementContainerHeightScale(){return(this._canvasHeight||1)/this._game.getGameResolutionHeight()}bindStandardEvents(t,e,i){const o=this._gameCanvas;if(!o)return;const r=n=>{const s=[n.pageX-o.offsetLeft,n.pageY-o.offsetTop];return s[0]*=this._game.getGameResolutionWidth()/(this._canvasWidth||1),s[1]*=this._game.getGameResolutionHeight()/(this._canvasHeight||1),s},c=n=>{const s=n.pageX-o.offsetLeft,a=n.pageY-o.offsetTop;return 0<=s&&s<(this._canvasWidth||1)&&0<=a&&a<(this._canvasHeight||1)};(function(){isNaN(o.offsetLeft)&&(o.offsetLeft=0,o.offsetTop=0),isNaN(i.body.scrollLeft)&&(i.body.scrollLeft=0,i.body.scrollTop=0),(i.documentElement===void 0||i.documentElement===null)&&(i.documentElement={}),isNaN(i.documentElement.scrollLeft)&&(i.documentElement.scrollLeft=0,i.documentElement.scrollTop=0),isNaN(o.offsetLeft)&&(o.offsetLeft=0,o.offsetTop=0)})();const m=()=>!(i.activeElement===o||i.activeElement===i.body||i.activeElement===null),d=n=>!(n.target===o||n.target===i.body);i.onkeydown=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),t.onKeyPressed(n.keyCode,n.location))},i.onkeyup=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),t.onKeyReleased(n.keyCode,n.location))};function g(n){switch(n){case 1:return l.InputManager.MOUSE_MIDDLE_BUTTON;case 2:return l.InputManager.MOUSE_RIGHT_BUTTON}return n}o.onmousemove=function(n){const s=r(n);t.onMouseMove(s[0],s[1])},o.onmousedown=function(n){return t.onMouseButtonPressed(g(n.button)),e.focus!==void 0&&e.focus(),!1},o.onmouseup=function(n){return t.onMouseButtonReleased(g(n.button)),!1},o.onmouseleave=function(n){t.onMouseLeave()},o.onmouseenter=function(n){t.onMouseEnter();const s=[l.InputManager.MOUSE_LEFT_BUTTON,l.InputManager.MOUSE_RIGHT_BUTTON,l.InputManager.MOUSE_MIDDLE_BUTTON,l.InputManager.MOUSE_BACK_BUTTON,l.InputManager.MOUSE_FORWARD_BUTTON];for(let a=0,v=s.length;a<v;++a){const h=s[a],_=(n.buttons&1<<a)!=0,p=t.isMouseButtonPressed(h);_&&!p?t.onMouseButtonPressed(h):!_&&p&&t.onMouseButtonReleased(h)}},e.addEventListener("click",function(n){return e.focus!==void 0&&e.focus(),!1},!1),o.oncontextmenu=function(n){return n.preventDefault(),n.stopPropagation(),!1},o.onwheel=function(n){t.onMouseWheel(-n.deltaY)},e.addEventListener("touchmove",function(n){if(!d(n)&&(n.preventDefault(),n.changedTouches))for(let s=0;s<n.changedTouches.length;++s){const a=r(n.changedTouches[s]);t.onTouchMove(n.changedTouches[s].identifier,a[0],a[1]),t.isSimulatingMouseWithTouch()&&(c(n.changedTouches[s])?t.onMouseEnter():t.onMouseLeave())}},{passive:!1}),e.addEventListener("touchstart",function(n){if(!d(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s){const a=r(n.changedTouches[s]);t.onTouchStart(n.changedTouches[s].identifier,a[0],a[1])}return!1}},{passive:!1}),e.addEventListener("touchend",function(n){if(!d(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s)t.onTouchEnd(n.changedTouches[s].identifier);return!1}},{passive:!1}),e.addEventListener("touchcancel",function(n){if(!d(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s)t.onTouchCancel(n.changedTouches[s].identifier);return!1}},{passive:!1})}setWindowTitle(t){typeof document!="undefined"&&(document.title=t)}getWindowTitle(){return typeof document!="undefined"?document.title:""}startGameLoop(t){let e=0;const i=o=>{this._nextFrameId=requestAnimationFrame(i);const r=e?o-e:0;e=o,t(r)||cancelAnimationFrame(this._nextFrameId)};requestAnimationFrame(i)}getPIXIRenderer(){return this._pixiRenderer}getThreeRenderer(){return this._threeRenderer}getDomElementContainer(){return this._domElementsContainer}openURL(t){if(typeof window!="undefined"){const e=this.getElectron();e?e.shell.openExternal(t):typeof window.cordova!="undefined"&&typeof window.cordova.InAppBrowser!="undefined"?window.cordova.InAppBrowser.open(t,"_system","location=yes"):window.open(t,"_blank")}}stopGame(){const t=this.getElectronRemote();if(t){const e=t.getCurrentWindow();if(e)try{e.close()}catch(i){u.error("Window closing failed. See error:",i)}}else typeof navigator!="undefined"&&navigator.app&&navigator.app.exitApp&&navigator.app.exitApp()}getCanvas(){return this._gameCanvas}isWebGLSupported(){return!!this._pixiRenderer&&this._pixiRenderer.type===PIXI.RENDERER_TYPE.WEBGL}getElectron(){return typeof require=="function"?require("electron"):null}getGame(){return this._game}}l.RuntimeGamePixiRenderer=R,l.RuntimeGameRenderer=R})(gdjs||(gdjs={}));
1
+ var gdjs;(function(l){const u=new l.Logger("PIXI game renderer"),f=[37,38,39,40];class R{constructor(e,t){this._isFullPage=!0;this._isFullscreen=!1;this._pixiRenderer=null;this._threeRenderer=null;this._gameCanvas=null;this._domElementsContainer=null;this._canvasWidth=0;this._canvasHeight=0;this._keepRatio=!0;this._nextFrameId=0;this._wasDisposed=!1;this.getElectronRemote=()=>{if(typeof require=="function"){const e=this._game.getAdditionalOptions(),t=e&&e.electronRemoteRequirePath?e.electronRemoteRequirePath:"@electron/remote";try{return require(t)}catch(i){console.error(`Could not load @electron/remote from "${t}". Error is:`,i)}}return null};this._game=e,this._forceFullscreen=t,this._marginLeft=this._marginTop=this._marginRight=this._marginBottom=0,this._setupOrientation()}createStandardCanvas(e){this._throwIfDisposed();const t=document.createElement("canvas");e.appendChild(t),this.initializeForCanvas(t)}initializeForCanvas(e){this._throwIfDisposed(),typeof THREE!="undefined"?(this._threeRenderer=new THREE.WebGLRenderer({canvas:e,antialias:this._game.getAntialiasingMode()!=="none"&&(this._game.isAntialisingEnabledOnMobile()||!l.evtTools.common.isMobile()),preserveDrawingBuffer:!0}),this._threeRenderer.useLegacyLights=!0,this._threeRenderer.autoClear=!1,this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._pixiRenderer=new PIXI.Renderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),view:e,context:this._threeRenderer.getContext(),clearBeforeRender:!1,preserveDrawingBuffer:!0,antialias:!1,backgroundAlpha:0})):this._pixiRenderer=PIXI.autoDetectRenderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),view:e,preserveDrawingBuffer:!0,antialias:!1}),this._pixiRenderer.plugins.accessibility.destroy(),delete this._pixiRenderer.plugins.accessibility,this._gameCanvas=e,e.style.position="absolute",e.tabIndex=1,e.style.userSelect="none",e.style.outline="none";const t=document.createElement("div");t.style.position="absolute",t.style.overflow="hidden",t.style.outline="none",t.style.pointerEvents="none",t.addEventListener("scroll",i=>{t.scrollLeft=0,t.scrollTop=0,i.preventDefault()}),e.addEventListener("pointerdown",()=>{e.focus()}),t.style["-webkit-user-select"]="none",e.parentNode?.appendChild(t),this._domElementsContainer=t,this._resizeCanvas(),this._game.getScaleMode()==="nearest"&&(e.style["image-rendering"]="-moz-crisp-edges",e.style["image-rendering"]="-webkit-optimize-contrast",e.style["image-rendering"]="-webkit-crisp-edges",e.style["image-rendering"]="pixelated"),this._game.getPixelsRounding()&&(PIXI.settings.ROUND_PIXELS=!0),window.addEventListener("resize",()=>{this._game.onWindowInnerSizeChanged(),this._resizeCanvas()}),e.focus()}static getWindowInnerWidth(){return typeof window!="undefined"?window.innerWidth:800}static getWindowInnerHeight(){return typeof window!="undefined"?window.innerHeight:800}updateRendererSize(){this._resizeCanvas()}_setupOrientation(){if(typeof window=="undefined"||!window.screen||!window.screen.orientation)return;const e=this._game.getGameData().properties.orientation;try{if(e==="default"){const t=window.screen.orientation.unlock();t&&t.catch(()=>{})}else window.screen.orientation.lock(e).catch(()=>{})}catch(t){u.error("Unexpected error while setting up orientation: ",t)}}_resizeCanvas(){if(!this._pixiRenderer||!this._domElementsContainer)return;(this._pixiRenderer.width!==this._game.getGameResolutionWidth()||this._pixiRenderer.height!==this._game.getGameResolutionHeight())&&(this._pixiRenderer.resize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._threeRenderer&&this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()));const e=this._forceFullscreen||this._isFullPage||this._isFullscreen;let t=this._game.getGameResolutionWidth(),i=this._game.getGameResolutionHeight(),o=window.innerWidth-this._marginLeft-this._marginRight,r=window.innerHeight-this._marginTop-this._marginBottom;if(o<0&&(o=0),r<0&&(r=0),e&&!this._keepRatio)t=o,i=r;else if(e&&this._keepRatio||t>o||i>r){let d=o/t;i*d>r&&(d=r/i),t*=d,i*=d}this._gameCanvas&&(this._gameCanvas.style.top=this._marginTop+(r-i)/2+"px",this._gameCanvas.style.left=this._marginLeft+(o-t)/2+"px",this._gameCanvas.style.width=t+"px",this._gameCanvas.style.height=i+"px"),this._domElementsContainer.style.top=this._marginTop+(r-i)/2+"px",this._domElementsContainer.style.left=this._marginLeft+(o-t)/2+"px",this._domElementsContainer.style.width=t+"px",this._domElementsContainer.style.height=i+"px",this._canvasWidth=t,this._canvasHeight=i}keepAspectRatio(e){this._keepRatio!==e&&(this._keepRatio=e,this._resizeCanvas())}setMargins(e,t,i,o){this._throwIfDisposed(),!(this._marginTop===e&&this._marginRight===t&&this._marginBottom===i&&this._marginLeft===o)&&(this._marginTop=e,this._marginRight=t,this._marginBottom=i,this._marginLeft=o,this._resizeCanvas())}setWindowSize(e,t){this._throwIfDisposed();const i=this.getElectronRemote();if(i){const o=i.getCurrentWindow();try{o&&o.setContentSize(e,t)}catch(r){u.error(`Window size setting to width ${e} and height ${t} failed. See error:`,r)}}else u.warn("Window size can't be changed on this platform.")}centerWindow(){this._throwIfDisposed();const e=this.getElectronRemote();if(e){const t=e.getCurrentWindow();try{t&&t.center()}catch(i){u.error("Window centering failed. See error:",i)}}else u.warn("Window can't be centered on this platform.")}setFullScreen(e){if(this._throwIfDisposed(),!this._forceFullscreen&&this._isFullscreen!==e){this._isFullscreen=!!e;const t=this.getElectronRemote();if(t){const i=t.getCurrentWindow();try{i&&i.setFullScreen(this._isFullscreen)}catch(o){u.error(`Full screen setting to ${this._isFullscreen} failed. See error:`,o)}}else this._isFullscreen?document.documentElement.requestFullscreen?document.documentElement.requestFullscreen():document.documentElement.mozRequestFullScreen?document.documentElement.mozRequestFullScreen():document.documentElement.webkitRequestFullScreen&&document.documentElement.webkitRequestFullScreen():document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen();this._resizeCanvas()}}isFullScreen(){const e=this.getElectronRemote();if(e)try{return e.getCurrentWindow().isFullScreen()}catch(t){return u.error("Full screen detection failed. See error:",t),!1}return this._isFullscreen||window.screen.height===window.innerHeight}convertCanvasToDomElementContainerCoords(e,t){const i=t||[0,0];return i[0]=e[0]*this._canvasWidth/this._game.getGameResolutionWidth(),i[1]=e[1]*this._canvasHeight/this._game.getGameResolutionHeight(),i}getCanvasToDomElementContainerHeightScale(){return(this._canvasHeight||1)/this._game.getGameResolutionHeight()}bindStandardEvents(e,t,i){this._throwIfDisposed();const o=this._gameCanvas;if(!o)return;const r=n=>{const s=[n.pageX-o.offsetLeft,n.pageY-o.offsetTop];return s[0]*=this._game.getGameResolutionWidth()/(this._canvasWidth||1),s[1]*=this._game.getGameResolutionHeight()/(this._canvasHeight||1),s},d=n=>{const s=n.pageX-o.offsetLeft,a=n.pageY-o.offsetTop;return 0<=s&&s<(this._canvasWidth||1)&&0<=a&&a<(this._canvasHeight||1)};(function(){isNaN(o.offsetLeft)&&(o.offsetLeft=0,o.offsetTop=0),isNaN(i.body.scrollLeft)&&(i.body.scrollLeft=0,i.body.scrollTop=0),(i.documentElement===void 0||i.documentElement===null)&&(i.documentElement={}),isNaN(i.documentElement.scrollLeft)&&(i.documentElement.scrollLeft=0,i.documentElement.scrollTop=0),isNaN(o.offsetLeft)&&(o.offsetLeft=0,o.offsetTop=0)})();const m=()=>!(i.activeElement===o||i.activeElement===i.body||i.activeElement===null),h=n=>!(n.target===o||n.target===i.body);i.onkeydown=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),e.onKeyPressed(n.keyCode,n.location))},i.onkeyup=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),e.onKeyReleased(n.keyCode,n.location))};function g(n){switch(n){case 1:return l.InputManager.MOUSE_MIDDLE_BUTTON;case 2:return l.InputManager.MOUSE_RIGHT_BUTTON}return n}o.onmousemove=function(n){const s=r(n);e.onMouseMove(s[0],s[1])},o.onmousedown=function(n){return e.onMouseButtonPressed(g(n.button)),t.focus!==void 0&&t.focus(),!1},o.onmouseup=function(n){return e.onMouseButtonReleased(g(n.button)),!1},o.onmouseleave=function(n){e.onMouseLeave()},o.onmouseenter=function(n){e.onMouseEnter();const s=[l.InputManager.MOUSE_LEFT_BUTTON,l.InputManager.MOUSE_RIGHT_BUTTON,l.InputManager.MOUSE_MIDDLE_BUTTON,l.InputManager.MOUSE_BACK_BUTTON,l.InputManager.MOUSE_FORWARD_BUTTON];for(let a=0,v=s.length;a<v;++a){const c=s[a],p=(n.buttons&1<<a)!=0,_=e.isMouseButtonPressed(c);p&&!_?e.onMouseButtonPressed(c):!p&&_&&e.onMouseButtonReleased(c)}},t.addEventListener("click",function(n){return t.focus!==void 0&&t.focus(),!1},!1),o.oncontextmenu=function(n){return n.preventDefault(),n.stopPropagation(),!1},o.onwheel=function(n){e.onMouseWheel(-n.deltaY)},t.addEventListener("touchmove",function(n){if(!h(n)&&(n.preventDefault(),n.changedTouches))for(let s=0;s<n.changedTouches.length;++s){const a=r(n.changedTouches[s]);e.onTouchMove(n.changedTouches[s].identifier,a[0],a[1]),e.isSimulatingMouseWithTouch()&&(d(n.changedTouches[s])?e.onMouseEnter():e.onMouseLeave())}},{passive:!1}),t.addEventListener("touchstart",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s){const a=r(n.changedTouches[s]);e.onTouchStart(n.changedTouches[s].identifier,a[0],a[1])}return!1}},{passive:!1}),t.addEventListener("touchend",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s)e.onTouchEnd(n.changedTouches[s].identifier);return!1}},{passive:!1}),t.addEventListener("touchcancel",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s)e.onTouchCancel(n.changedTouches[s].identifier);return!1}},{passive:!1})}setWindowTitle(e){typeof document!="undefined"&&(document.title=e)}getWindowTitle(){return typeof document!="undefined"?document.title:""}startGameLoop(e){this._throwIfDisposed();let t=0;const i=o=>{this._nextFrameId=requestAnimationFrame(i);const r=t?o-t:0;t=o,e(r)||cancelAnimationFrame(this._nextFrameId)};requestAnimationFrame(i)}stopGameLoop(){cancelAnimationFrame(this._nextFrameId)}getPIXIRenderer(){return this._pixiRenderer}getThreeRenderer(){return this._threeRenderer}getDomElementContainer(){return this._domElementsContainer}openURL(e){if(typeof window!="undefined"){const t=this.getElectron();t?t.shell.openExternal(e):typeof window.cordova!="undefined"&&typeof window.cordova.InAppBrowser!="undefined"?window.cordova.InAppBrowser.open(e,"_system","location=yes"):window.open(e,"_blank")}}stopGame(){const e=this.getElectronRemote();if(e){const t=e.getCurrentWindow();if(t)try{t.close()}catch(i){u.error("Window closing failed. See error:",i)}}else typeof navigator!="undefined"&&navigator.app&&navigator.app.exitApp&&navigator.app.exitApp()}dispose(e){this._pixiRenderer?.destroy(),this._threeRenderer?.dispose(),this._pixiRenderer=null,this._threeRenderer=null,e&&this._gameCanvas&&this._gameCanvas.parentNode?.removeChild(this._gameCanvas),this._gameCanvas=null,this._domElementsContainer?.parentNode?.removeChild(this._domElementsContainer),this._domElementsContainer=null,this._wasDisposed=!0}getCanvas(){return this._gameCanvas}isWebGLSupported(){return!!this._pixiRenderer&&this._pixiRenderer.type===PIXI.RENDERER_TYPE.WEBGL}getElectron(){return typeof require=="function"?require("electron"):null}getGame(){return this._game}_throwIfDisposed(){if(this._wasDisposed)throw"The RuntimeGameRenderer has been disposed and should not be used anymore."}}l.RuntimeGamePixiRenderer=R,l.RuntimeGameRenderer=R})(gdjs||(gdjs={}));
2
2
  //# sourceMappingURL=runtimegame-pixi-renderer.js.map