gdcore-tools 2.0.0-beta4 → 2.0.0-beta6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Runtime/CustomRuntimeObject.js +1 -1
- package/dist/Runtime/CustomRuntimeObject.js.map +2 -2
- package/dist/Runtime/CustomRuntimeObjectInstanceContainer.js +1 -1
- package/dist/Runtime/CustomRuntimeObjectInstanceContainer.js.map +2 -2
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/AdMob/admobtools.js +1 -1
- package/dist/Runtime/Extensions/AdMob/admobtools.js.map +2 -2
- package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Effects/JsExtension.js +2 -2
- package/dist/Runtime/Extensions/Multiplayer/JsExtension.js +97 -7
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayercomponents.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayercomponents.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayertools.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayertools.js.map +2 -2
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/JsExtension.js +62 -27
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/JsExtension.js +32 -0
- package/dist/Runtime/Extensions/Spine/spineruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/Spine/spineruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/JsExtension.js +3 -1
- package/dist/Runtime/Extensions/TileMap/JsExtension.js +84 -29
- package/dist/Runtime/Extensions/TileMap/collision/TransformedTileMap.js +1 -1
- package/dist/Runtime/Extensions/TileMap/collision/TransformedTileMap.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/helper/TileMapHelper.js +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/TileMapHelper.js.map +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/load/tiled/TiledTileMapLoader.d.ts.map +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/model/TileMapModel.d.ts +12 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/model/TileMapModel.d.ts.map +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/dts/render/TileMapManager.d.ts.map +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/JsExtension.js +1 -0
- package/dist/Runtime/RuntimeInstanceContainer.js.map +2 -2
- package/dist/Runtime/SpriteAnimator.js +1 -1
- package/dist/Runtime/SpriteAnimator.js.map +2 -2
- package/dist/Runtime/debugger-client/InGameDebugger.js +1 -1
- package/dist/Runtime/debugger-client/InGameDebugger.js.map +2 -2
- package/dist/Runtime/debugger-client/abstract-debugger-client.js +1 -1
- package/dist/Runtime/debugger-client/abstract-debugger-client.js.map +2 -2
- package/dist/Runtime/debugger-client/hot-reloader.js +2 -1
- package/dist/Runtime/debugger-client/hot-reloader.js.map +2 -2
- package/dist/Runtime/debugger-client/minimal-debugger-client.js +2 -0
- package/dist/Runtime/debugger-client/minimal-debugger-client.js.map +7 -0
- package/dist/Runtime/debugger-client/websocket-debugger-client.js.map +2 -2
- package/dist/Runtime/debugger-client/window-message-debugger-client.js.map +2 -2
- package/dist/Runtime/pixi-renderers/spriteruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/pixi-renderers/spriteruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/runtimescene.js +1 -1
- package/dist/Runtime/runtimescene.js.map +2 -2
- package/dist/Runtime/scenestack.js +1 -1
- package/dist/Runtime/scenestack.js.map +2 -2
- package/dist/Runtime/spriteruntimeobject.js +1 -1
- package/dist/Runtime/spriteruntimeobject.js.map +2 -2
- package/dist/Runtime/types/project-data.d.ts +31 -8
- package/dist/Runtime/variablescontainer.js +1 -1
- package/dist/Runtime/variablescontainer.js.map +2 -2
- package/dist/lib/libGD.cjs +1 -1
- package/dist/lib/libGD.wasm +0 -0
- package/gd.d.ts +77 -47
- package/package.json +2 -2
- package/dist/lib/libGD.d.cts +0 -5
- package/dist/loaders.d.cts +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/scenestack.ts"],
|
|
4
|
-
"sourcesContent": ["namespace gdjs {\n const logger = new gdjs.Logger('Scene stack');\n const debugLogger = new gdjs.Logger('Multiplayer - Debug');\n\n /**\n * Hold the stack of scenes ({@link gdjs.RuntimeScene}) being played.\n */\n export class SceneStack {\n _runtimeGame: gdjs.RuntimeGame;\n _stack: gdjs.RuntimeScene[] = [];\n _wasFirstSceneLoaded: boolean = false;\n _isNextLayoutLoading: boolean = false;\n _sceneStackSyncDataToApply: SceneStackNetworkSyncData | null = null;\n\n /**\n * @param runtimeGame The runtime game that is using the scene stack\n */\n constructor(runtimeGame: gdjs.RuntimeGame) {\n if (!runtimeGame) {\n throw 'SceneStack must be constructed with a gdjs.RuntimeGame.';\n }\n this._runtimeGame = runtimeGame;\n }\n\n /**\n * Called by the RuntimeGame when the game resolution is changed.\n * Useful to notify scene and layers that resolution is changed, as they\n * might be caching it.\n */\n onGameResolutionResized(): void {\n for (let i = 0; i < this._stack.length; ++i) {\n this._stack[i].onGameResolutionResized();\n }\n }\n\n step(elapsedTime: float): boolean {\n if (this._isNextLayoutLoading || this._stack.length === 0) {\n return false;\n }\n\n const hasMadeChangeToStack = this.applyUpdateFromNetworkSyncDataIfAny();\n if (hasMadeChangeToStack) {\n debugLogger.info(\n 'Scene stack has been updated from network sync data, skipping step.'\n );\n // If we have made changes to the stack as part of the network sync,\n // we trust the network to be the source of truth for the scene stack,\n // and skip the scene rendering (and so any other request to change the scene stack from it)\n return true;\n }\n\n const currentScene = this._stack[this._stack.length - 1];\n if (currentScene.renderAndStep(elapsedTime)) {\n const request = currentScene.getRequestedChange();\n\n // A scene change was requested by the current scene.\n if (request === gdjs.SceneChangeRequest.STOP_GAME) {\n this._runtimeGame.getRenderer().stopGame();\n return true;\n } else if (request === gdjs.SceneChangeRequest.POP_SCENE) {\n this.pop();\n } else if (request === gdjs.SceneChangeRequest.PUSH_SCENE) {\n this.push(currentScene.getRequestedScene());\n } else if (request === gdjs.SceneChangeRequest.REPLACE_SCENE) {\n this.replace(currentScene.getRequestedScene());\n } else if (request === gdjs.SceneChangeRequest.CLEAR_SCENES) {\n this.replace(currentScene.getRequestedScene(), true);\n } else {\n logger.error('Unrecognized change in scene stack: ' + request);\n }\n }\n\n return true;\n }\n\n renderWithoutStep(): boolean {\n if (this._stack.length === 0) {\n return false;\n }\n const currentScene = this._stack[this._stack.length - 1];\n currentScene.render();\n return true;\n }\n\n pop(popCount = 1): void {\n let hasDoneAnyChanges = false;\n for (let i = 0; i < popCount; ++i) {\n if (this._stack.length <= 1) {\n break;\n }\n\n // Unload the current scene\n hasDoneAnyChanges = true;\n const scene = this._stack.pop();\n if (!scene) {\n return;\n }\n scene.unloadScene();\n }\n\n // Tell the new current scene it's being resumed\n if (hasDoneAnyChanges) {\n const currentScene = this._stack[this._stack.length - 1];\n if (currentScene) {\n currentScene.onResume();\n }\n }\n }\n\n /**\n * Pause the scene currently being played and start the new scene that is specified.\n * If `externalLayoutName` is set, also instantiate the objects from this external layout.\n */\n push(\n newSceneName: string,\n externalLayoutName?: string\n ): gdjs.RuntimeScene | null {\n // Tell the scene it's being paused\n const currentScene = this._stack[this._stack.length - 1];\n if (currentScene) {\n currentScene.onPause();\n }\n\n // Avoid a risk of displaying an intermediate loading screen\n // during 1 frame.\n if (this._runtimeGame.areSceneAssetsReady(newSceneName)) {\n return this._loadNewScene(newSceneName, externalLayoutName);\n }\n\n this._isNextLayoutLoading = true;\n this._runtimeGame.loadSceneAssets(newSceneName).then(() => {\n this._loadNewScene(newSceneName);\n this._isNextLayoutLoading = false;\n });\n return null;\n }\n\n private _loadNewScene(\n newSceneName: string,\n externalLayoutName?: string\n ): gdjs.RuntimeScene {\n // Load the new one\n const newScene = new gdjs.RuntimeScene(this._runtimeGame);\n newScene.loadFromScene(\n this._runtimeGame.getSceneAndExtensionsData(newSceneName)\n );\n this._wasFirstSceneLoaded = true;\n\n // Optionally create the objects from an external layout.\n if (externalLayoutName) {\n const externalLayoutData = this._runtimeGame.getExternalLayoutData(\n externalLayoutName\n );\n if (externalLayoutData) {\n newScene.createObjectsFrom(\n externalLayoutData.instances,\n 0,\n 0,\n 0,\n /*trackByPersistentUuid=*/\n true\n );\n }\n }\n this._stack.push(newScene);\n return newScene;\n }\n\n /**\n * Start the specified scene, replacing the one currently being played.\n * If `clear` is set to true, all running scenes are also removed from the stack of scenes.\n */\n replace(newSceneName: string, clear?: boolean): gdjs.RuntimeScene | null {\n if (!!clear) {\n // Unload all the scenes\n while (this._stack.length !== 0) {\n let scene = this._stack.pop();\n if (scene) {\n scene.unloadScene();\n }\n }\n } else {\n // Unload the current scene\n if (this._stack.length !== 0) {\n let scene = this._stack.pop();\n if (scene) {\n scene.unloadScene();\n }\n }\n }\n return this.push(newSceneName);\n }\n\n /**\n * Return the current gdjs.RuntimeScene being played, or null if none is run.\n */\n getCurrentScene(): gdjs.RuntimeScene | null {\n if (this._stack.length === 0) {\n return null;\n }\n return this._stack[this._stack.length - 1];\n }\n\n /**\n * Return true if a scene was loaded, false otherwise (i.e: game not yet started).\n */\n wasFirstSceneLoaded(): boolean {\n return this._wasFirstSceneLoaded;\n }\n\n getNetworkSyncData(\n syncOptions: GetNetworkSyncDataOptions\n ): SceneStackNetworkSyncData | null {\n const syncedPlayerNumber = syncOptions.playerNumber;\n if (syncedPlayerNumber !== undefined && syncedPlayerNumber !== 1) {\n // If we are getting sync data of a specific player,\n // and they are not the host, we don't sync the scene stack.\n return null;\n }\n\n // If we are the host, we can take charge of\n // generating a networkId for each scene if they don't have one.\n // They will be reconciled on the other players' games.\n const sceneStackSyncData: SceneStackSceneNetworkSyncData[] = [];\n for (let i = 0; i < this._stack.length; ++i) {\n const scene = this._stack[i];\n sceneStackSyncData.push({\n name: scene.getName(),\n networkId: scene.getOrCreateNetworkId(),\n });\n }\n return sceneStackSyncData;\n }\n\n updateFromNetworkSyncData(\n sceneStackSyncData: SceneStackNetworkSyncData\n ): void {\n // Don't directly apply changes to the scene stack. Store them and they will be applied\n // in `step` (i.e: at the end of a frame). Otherwise, we would risk doing operations on the scene\n // stack, like creating a new scene or unloading a scene, while being inside the `renderAndStep` method\n // of the current scene.\n this._sceneStackSyncDataToApply = sceneStackSyncData;\n }\n\n applyUpdateFromNetworkSyncDataIfAny(): boolean {\n const sceneStackSyncData = this._sceneStackSyncDataToApply;\n let hasMadeChangeToStack = false;\n if (!sceneStackSyncData) return hasMadeChangeToStack;\n\n this._sceneStackSyncDataToApply = null;\n\n // If this method is called, we are a client.\n // We trust the host to be the source of truth for the scene stack.\n // So we loop through the scenes in the stack given by the host and either:\n // - Set the networkId of the scene if it's already in the stack at the right place\n // - Add the scene to the stack if it's not there, and set its networkId\n // - Remove any scenes that are in the stack but not in the data given by the host\n for (let i = 0; i < sceneStackSyncData.length; ++i) {\n const sceneSyncData = sceneStackSyncData[i];\n const sceneAtThisPositionInOurStack = this._stack[i];\n if (!sceneAtThisPositionInOurStack) {\n debugLogger.info(\n `Scene at position ${i} with name ${sceneSyncData.name} is missing from the stack, adding it.`\n );\n // We have fewer scenes in the stack than the host, let's add the scene.\n const newScene = this.push(sceneSyncData.name);\n if (newScene) {\n newScene.networkId = sceneSyncData.networkId;\n }\n hasMadeChangeToStack = true;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n if (sceneAtThisPositionInOurStack.getName() !== sceneSyncData.name) {\n debugLogger.info(\n `Scene at position ${i} and name ${sceneAtThisPositionInOurStack.getName()} is not the same as the expected ${\n sceneSyncData.name\n }, replacing.`\n );\n // The scene does not correspond to the scene at this position in our stack\n // Let's unload everything after this position to recreate the stack.\n const newScene = this.replace(\n sceneSyncData.name,\n true // Clear the stack\n );\n if (newScene) {\n newScene.networkId = sceneSyncData.networkId;\n }\n hasMadeChangeToStack = true;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n if (\n !sceneAtThisPositionInOurStack.networkId &&\n sceneSyncData.networkId &&\n sceneSyncData.name === sceneAtThisPositionInOurStack.getName()\n ) {\n debugLogger.info(\n `Scene at position ${i} and name ${sceneAtThisPositionInOurStack.getName()} has no networkId, let's assume it's the right one and reconcile it with the id ${\n sceneSyncData.networkId\n }.`\n );\n // The scene is in the stack but has no networkId,\n // this can happen at the start of the game on a player that is not the host,\n // or if a player switch to another scene before the host has sent the scene stack.\n // Let's set the networkId of the scene.\n sceneAtThisPositionInOurStack.networkId = sceneSyncData.networkId;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n if (\n sceneAtThisPositionInOurStack.networkId !== sceneSyncData.networkId\n ) {\n debugLogger.info(\n `Scene at position ${i} and name ${sceneAtThisPositionInOurStack.getName()} has a different networkId ${\n sceneAtThisPositionInOurStack.networkId\n } than the expected ${sceneSyncData.networkId}, replacing.`\n );\n // The scene is in the stack but has a different networkId\n // This can happen if the host has restarted the scene\n // We can't just update the networkId of the scene in the stack\n // We need to replace it with a new scene\n const newScene = this.replace(\n sceneSyncData.name,\n false // Don't clear the stack\n );\n if (newScene) {\n newScene.networkId = sceneSyncData.networkId;\n }\n hasMadeChangeToStack = true;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n // The scene is in the stack and has the right networkId.\n // Nothing to do, just continue to the next scene in the stack received from the host.\n }\n\n // Pop any scene not on the host.\n // In the future, we could avoid to pop scenes if they are not set to be synchronized.\n if (this._stack.length > sceneStackSyncData.length) {\n const popCount = this._stack.length - sceneStackSyncData.length;\n this.pop(popCount);\n hasMadeChangeToStack = true;\n }\n\n return hasMadeChangeToStack;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,eACzB,EAAc,GAAI,GAAK,OAAO,uBAK7B,OAAiB,CAUtB,YAAY,EAA+B,CAR3C,YAA8B,GAC9B,0BAAgC,GAChC,0BAAgC,GAChC,gCAA+D,KAM7D,GAAI,CAAC,EACH,KAAM,0DAER,KAAK,aAAe,EAQtB,yBAAgC,CAC9B,OAAS,GAAI,EAAG,EAAI,KAAK,OAAO,OAAQ,EAAE,EACxC,KAAK,OAAO,GAAG,0BAInB,KAAK,EAA6B,CAChC,GAAI,KAAK,sBAAwB,KAAK,OAAO,SAAW,EACtD,MAAO,GAIT,GAD6B,KAAK,sCAEhC,SAAY,KACV,uEAKK,GAGT,KAAM,GA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AqB,KAAK,aAAa,sBAC3C,GAEF,AAAI,GACF,EAAS,kBACP,EAAmB,UACnB,EACA,EACA,EAEA,IAIN,YAAK,OAAO,KAAK,GACV,EAOT,QAAQ,EAAsB,EAA2C,CACvE,GAAM,EAEJ,KAAO,KAAK,OAAO,SAAW,GAAG,CAC/B,GAAI,GAAQ,KAAK,OAAO,MACxB,AAAI,GACF,EAAM,sBAKN,KAAK,OAAO,SAAW,EAAG,CAC5B,GAAI,GAAQ,KAAK,OAAO,MACxB,AAAI,GACF,EAAM,cAIZ,MAAO,MAAK,KAAK,GAMnB,iBAA4C,CAC1C,MAAI,MAAK,OAAO,SAAW,EAClB,KAEF,KAAK,OAAO,KAAK,OAAO,OAAS,GAM1C,qBAA+B,CAC7B,MAAO,MAAK,qBAGd,mBACE,EACkC,CAClC,KAAM,GAAqB,EAAY,
|
|
4
|
+
"sourcesContent": ["namespace gdjs {\n const logger = new gdjs.Logger('Scene stack');\n const debugLogger = new gdjs.Logger('Multiplayer - Debug');\n\n /**\n * Hold the stack of scenes ({@link gdjs.RuntimeScene}) being played.\n */\n export class SceneStack {\n _runtimeGame: gdjs.RuntimeGame;\n _stack: gdjs.RuntimeScene[] = [];\n _wasFirstSceneLoaded: boolean = false;\n _isNextLayoutLoading: boolean = false;\n _sceneStackSyncDataToApply: SceneStackNetworkSyncData | null = null;\n\n /**\n * @param runtimeGame The runtime game that is using the scene stack\n */\n constructor(runtimeGame: gdjs.RuntimeGame) {\n if (!runtimeGame) {\n throw 'SceneStack must be constructed with a gdjs.RuntimeGame.';\n }\n this._runtimeGame = runtimeGame;\n }\n\n /**\n * Called by the RuntimeGame when the game resolution is changed.\n * Useful to notify scene and layers that resolution is changed, as they\n * might be caching it.\n */\n onGameResolutionResized(): void {\n for (let i = 0; i < this._stack.length; ++i) {\n this._stack[i].onGameResolutionResized();\n }\n }\n\n step(elapsedTime: float): boolean {\n if (this._isNextLayoutLoading || this._stack.length === 0) {\n return false;\n }\n\n const hasMadeChangeToStack = this.applyUpdateFromNetworkSyncDataIfAny();\n if (hasMadeChangeToStack) {\n debugLogger.info(\n 'Scene stack has been updated from network sync data, skipping step.'\n );\n // If we have made changes to the stack as part of the network sync,\n // we trust the network to be the source of truth for the scene stack,\n // and skip the scene rendering (and so any other request to change the scene stack from it)\n return true;\n }\n\n const currentScene = this._stack[this._stack.length - 1];\n if (currentScene.renderAndStep(elapsedTime)) {\n const request = currentScene.getRequestedChange();\n\n // A scene change was requested by the current scene.\n if (request === gdjs.SceneChangeRequest.STOP_GAME) {\n this._runtimeGame.getRenderer().stopGame();\n return true;\n } else if (request === gdjs.SceneChangeRequest.POP_SCENE) {\n this.pop();\n } else if (request === gdjs.SceneChangeRequest.PUSH_SCENE) {\n this.push(currentScene.getRequestedScene());\n } else if (request === gdjs.SceneChangeRequest.REPLACE_SCENE) {\n this.replace(currentScene.getRequestedScene());\n } else if (request === gdjs.SceneChangeRequest.CLEAR_SCENES) {\n this.replace(currentScene.getRequestedScene(), true);\n } else {\n logger.error('Unrecognized change in scene stack: ' + request);\n }\n }\n\n return true;\n }\n\n renderWithoutStep(): boolean {\n if (this._stack.length === 0) {\n return false;\n }\n const currentScene = this._stack[this._stack.length - 1];\n currentScene.render();\n return true;\n }\n\n pop(popCount = 1): void {\n let hasDoneAnyChanges = false;\n for (let i = 0; i < popCount; ++i) {\n if (this._stack.length <= 1) {\n break;\n }\n\n // Unload the current scene\n hasDoneAnyChanges = true;\n const scene = this._stack.pop();\n if (!scene) {\n return;\n }\n scene.unloadScene();\n }\n\n // Tell the new current scene it's being resumed\n if (hasDoneAnyChanges) {\n const currentScene = this._stack[this._stack.length - 1];\n if (currentScene) {\n currentScene.onResume();\n }\n }\n }\n\n /**\n * Pause the scene currently being played and start the new scene that is specified.\n * If `externalLayoutName` is set, also instantiate the objects from this external layout.\n */\n push(\n newSceneName: string,\n externalLayoutName?: string\n ): gdjs.RuntimeScene | null {\n // Tell the scene it's being paused\n const currentScene = this._stack[this._stack.length - 1];\n if (currentScene) {\n currentScene.onPause();\n }\n\n // Avoid a risk of displaying an intermediate loading screen\n // during 1 frame.\n if (this._runtimeGame.areSceneAssetsReady(newSceneName)) {\n return this._loadNewScene(newSceneName, externalLayoutName);\n }\n\n this._isNextLayoutLoading = true;\n this._runtimeGame.loadSceneAssets(newSceneName).then(() => {\n this._loadNewScene(newSceneName);\n this._isNextLayoutLoading = false;\n });\n return null;\n }\n\n private _loadNewScene(\n newSceneName: string,\n externalLayoutName?: string\n ): gdjs.RuntimeScene {\n // Load the new one\n const newScene = new gdjs.RuntimeScene(this._runtimeGame);\n newScene.loadFromScene(\n this._runtimeGame.getSceneAndExtensionsData(newSceneName)\n );\n this._wasFirstSceneLoaded = true;\n\n // Optionally create the objects from an external layout.\n if (externalLayoutName) {\n const externalLayoutData = this._runtimeGame.getExternalLayoutData(\n externalLayoutName\n );\n if (externalLayoutData) {\n newScene.createObjectsFrom(\n externalLayoutData.instances,\n 0,\n 0,\n 0,\n /*trackByPersistentUuid=*/\n true\n );\n }\n }\n this._stack.push(newScene);\n return newScene;\n }\n\n /**\n * Start the specified scene, replacing the one currently being played.\n * If `clear` is set to true, all running scenes are also removed from the stack of scenes.\n */\n replace(newSceneName: string, clear?: boolean): gdjs.RuntimeScene | null {\n if (!!clear) {\n // Unload all the scenes\n while (this._stack.length !== 0) {\n let scene = this._stack.pop();\n if (scene) {\n scene.unloadScene();\n }\n }\n } else {\n // Unload the current scene\n if (this._stack.length !== 0) {\n let scene = this._stack.pop();\n if (scene) {\n scene.unloadScene();\n }\n }\n }\n return this.push(newSceneName);\n }\n\n /**\n * Return the current gdjs.RuntimeScene being played, or null if none is run.\n */\n getCurrentScene(): gdjs.RuntimeScene | null {\n if (this._stack.length === 0) {\n return null;\n }\n return this._stack[this._stack.length - 1];\n }\n\n /**\n * Return true if a scene was loaded, false otherwise (i.e: game not yet started).\n */\n wasFirstSceneLoaded(): boolean {\n return this._wasFirstSceneLoaded;\n }\n\n getAllSceneNames(): Array<string> {\n return this._stack.map((scene) => scene.getName());\n }\n\n getNetworkSyncData(\n syncOptions: GetNetworkSyncDataOptions\n ): SceneStackNetworkSyncData | null {\n const syncedPlayerNumber = syncOptions.playerNumber;\n const isHost = syncOptions.isHost;\n if (syncedPlayerNumber !== undefined && !isHost) {\n // If we are getting sync data of a specific player,\n // and they are not the host, we don't sync the scene stack.\n return null;\n }\n\n // If we are the host, we can take charge of\n // generating a networkId for each scene if they don't have one.\n // They will be reconciled on the other players' games.\n const sceneStackSyncData: SceneStackSceneNetworkSyncData[] = [];\n for (let i = 0; i < this._stack.length; ++i) {\n const scene = this._stack[i];\n sceneStackSyncData.push({\n name: scene.getName(),\n networkId: scene.getOrCreateNetworkId(),\n });\n }\n return sceneStackSyncData;\n }\n\n updateFromNetworkSyncData(\n sceneStackSyncData: SceneStackNetworkSyncData\n ): void {\n // Don't directly apply changes to the scene stack. Store them and they will be applied\n // in `step` (i.e: at the end of a frame). Otherwise, we would risk doing operations on the scene\n // stack, like creating a new scene or unloading a scene, while being inside the `renderAndStep` method\n // of the current scene.\n this._sceneStackSyncDataToApply = sceneStackSyncData;\n }\n\n applyUpdateFromNetworkSyncDataIfAny(): boolean {\n const sceneStackSyncData = this._sceneStackSyncDataToApply;\n let hasMadeChangeToStack = false;\n if (!sceneStackSyncData) return hasMadeChangeToStack;\n\n this._sceneStackSyncDataToApply = null;\n\n // If this method is called, we are a client.\n // We trust the host to be the source of truth for the scene stack.\n // So we loop through the scenes in the stack given by the host and either:\n // - Set the networkId of the scene if it's already in the stack at the right place\n // - Add the scene to the stack if it's not there, and set its networkId\n // - Remove any scenes that are in the stack but not in the data given by the host\n for (let i = 0; i < sceneStackSyncData.length; ++i) {\n const sceneSyncData = sceneStackSyncData[i];\n const sceneAtThisPositionInOurStack = this._stack[i];\n if (!sceneAtThisPositionInOurStack) {\n debugLogger.info(\n `Scene at position ${i} with name ${sceneSyncData.name} is missing from the stack, adding it.`\n );\n // We have fewer scenes in the stack than the host, let's add the scene.\n const newScene = this.push(sceneSyncData.name);\n if (newScene) {\n newScene.networkId = sceneSyncData.networkId;\n }\n hasMadeChangeToStack = true;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n if (sceneAtThisPositionInOurStack.getName() !== sceneSyncData.name) {\n debugLogger.info(\n `Scene at position ${i} and name ${sceneAtThisPositionInOurStack.getName()} is not the same as the expected ${\n sceneSyncData.name\n }, replacing.`\n );\n // The scene does not correspond to the scene at this position in our stack\n // Let's unload everything after this position to recreate the stack.\n const newScene = this.replace(\n sceneSyncData.name,\n true // Clear the stack\n );\n if (newScene) {\n newScene.networkId = sceneSyncData.networkId;\n }\n hasMadeChangeToStack = true;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n if (\n !sceneAtThisPositionInOurStack.networkId &&\n sceneSyncData.networkId &&\n sceneSyncData.name === sceneAtThisPositionInOurStack.getName()\n ) {\n debugLogger.info(\n `Scene at position ${i} and name ${sceneAtThisPositionInOurStack.getName()} has no networkId, let's assume it's the right one and reconcile it with the id ${\n sceneSyncData.networkId\n }.`\n );\n // The scene is in the stack but has no networkId,\n // this can happen at the start of the game on a player that is not the host,\n // or if a player switch to another scene before the host has sent the scene stack.\n // Let's set the networkId of the scene.\n sceneAtThisPositionInOurStack.networkId = sceneSyncData.networkId;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n if (\n sceneAtThisPositionInOurStack.networkId !== sceneSyncData.networkId\n ) {\n debugLogger.info(\n `Scene at position ${i} and name ${sceneAtThisPositionInOurStack.getName()} has a different networkId ${\n sceneAtThisPositionInOurStack.networkId\n } than the expected ${sceneSyncData.networkId}, replacing.`\n );\n // The scene is in the stack but has a different networkId\n // This can happen if the host has restarted the scene\n // We can't just update the networkId of the scene in the stack\n // We need to replace it with a new scene\n const newScene = this.replace(\n sceneSyncData.name,\n false // Don't clear the stack\n );\n if (newScene) {\n newScene.networkId = sceneSyncData.networkId;\n }\n hasMadeChangeToStack = true;\n // Continue to the next scene in the stack received from the host.\n continue;\n }\n\n // The scene is in the stack and has the right networkId.\n // Nothing to do, just continue to the next scene in the stack received from the host.\n }\n\n // Pop any scene not on the host.\n // In the future, we could avoid to pop scenes if they are not set to be synchronized.\n if (this._stack.length > sceneStackSyncData.length) {\n const popCount = this._stack.length - sceneStackSyncData.length;\n this.pop(popCount);\n hasMadeChangeToStack = true;\n }\n\n return hasMadeChangeToStack;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,eACzB,EAAc,GAAI,GAAK,OAAO,uBAK7B,OAAiB,CAUtB,YAAY,EAA+B,CAR3C,YAA8B,GAC9B,0BAAgC,GAChC,0BAAgC,GAChC,gCAA+D,KAM7D,GAAI,CAAC,EACH,KAAM,0DAER,KAAK,aAAe,EAQtB,yBAAgC,CAC9B,OAAS,GAAI,EAAG,EAAI,KAAK,OAAO,OAAQ,EAAE,EACxC,KAAK,OAAO,GAAG,0BAInB,KAAK,EAA6B,CAChC,GAAI,KAAK,sBAAwB,KAAK,OAAO,SAAW,EACtD,MAAO,GAIT,GAD6B,KAAK,sCAEhC,SAAY,KACV,uEAKK,GAGT,KAAM,GAAe,KAAK,OAAO,KAAK,OAAO,OAAS,GACtD,GAAI,EAAa,cAAc,GAAc,CAC3C,KAAM,GAAU,EAAa,qBAG7B,GAAI,IAAY,EAAK,mBAAmB,UACtC,YAAK,aAAa,cAAc,WACzB,GACF,AAAI,IAAY,EAAK,mBAAmB,UAC7C,KAAK,MACA,AAAI,IAAY,EAAK,mBAAmB,WAC7C,KAAK,KAAK,EAAa,qBAClB,AAAI,IAAY,EAAK,mBAAmB,cAC7C,KAAK,QAAQ,EAAa,qBACrB,AAAI,IAAY,EAAK,mBAAmB,aAC7C,KAAK,QAAQ,EAAa,oBAAqB,IAE/C,EAAO,MAAM,uCAAyC,GAI1D,MAAO,GAGT,mBAA6B,CAC3B,MAAI,MAAK,OAAO,SAAW,EAClB,GAGT,CADqB,KAAK,OAAO,KA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Ac,KACd,IAEF,AAAI,GACF,GAAS,UAAY,EAAc,WAErC,EAAuB,GAEvB,UASJ,GAAI,KAAK,OAAO,OAAS,EAAmB,OAAQ,CAClD,KAAM,GAAW,KAAK,OAAO,OAAS,EAAmB,OACzD,KAAK,IAAI,GACT,EAAuB,GAGzB,MAAO,IA3VJ,EAAM,eAPL",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(n){class s extends n.RuntimeObject{constructor(t,e){super(t,e);this._scaleX=1;this._scaleY=1;this._blendMode=0;this._flippedX=!1;this._flippedY=!1;this.opacity=255;this._animationFrameDirty=!0;this._updateIfNotVisible=!!e.updateIfNotVisible,this._renderer=new n.SpriteRuntimeObjectRenderer(this,t),this._animator=new n.SpriteAnimator(e.animations,n.SpriteRuntimeObjectRenderer.getAnimationFrameTextureManager(t.getGame().getImageManager())),this._updateAnimationFrame(),this.onCreated()}reinitialize(t){super.reinitialize(t);const e=this.getInstanceContainer();this._animator.reinitialize(t.animations),this._scaleX=1,this._scaleY=1,this._blendMode=0,this._flippedX=!1,this._flippedY=!1,this.opacity=255,this._updateIfNotVisible=!!t.updateIfNotVisible,this._renderer.reinitialize(this,e),this._updateAnimationFrame(),this.onCreated()}updateFromObjectData(t,e){return this._animator.updateFromObjectData(t.animations,e.animations),this._updateIfNotVisible=!!e.updateIfNotVisible,this.invalidateHitboxes(),!0}getNetworkSyncData(){return{...super.getNetworkSyncData(),anim:this._animator.getNetworkSyncData(),ifx:this.isFlippedX(),ify:this.isFlippedY(),sx:this._scaleX,sy:this._scaleY,op:this.opacity,color:this.getColor()}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t),t.ifx!==void 0&&this.flipX(t.ifx),t.ify!==void 0&&this.flipY(t.ify),t.sx!==void 0&&this.setScaleX(Math.abs(t.sx)),t.sy!==void 0&&this.setScaleY(Math.abs(t.sy)),t.op!==void 0&&this.setOpacity(t.op),t.anim&&(this._animator.updateFromNetworkSyncData(t.anim),this._updateAnimationFrame()),(t.ifx!==void 0||t.ify!==void 0||t.sx!==void 0||t.sy!==void 0||t.anim!==void 0)&&this.invalidateHitboxes(),t.color!==void 0&&this.setColor(t.color)}extraInitializationFromInitialInstance(t){if(t.numberProperties)for(let e=0,i=t.numberProperties.length;e<i;++e){const a=t.numberProperties[e];a.name==="animation"&&this.setAnimationIndex(a.value)}t.customSize&&(this.setWidth(t.width),this.setHeight(t.height))}update(t){if(!this._updateIfNotVisible&&!this._renderer.getRendererObject().visible)return;this._animator.step(this.getElapsedTime()/1e3)&&(this._updateAnimationFrame(),this.invalidateHitboxes()),this._renderer.ensureUpToDate()}updatePreRender(t){this._animationFrameDirty&&this._updateAnimationFrame(),this._renderer.ensureUpToDate()}_updateAnimationFrame(){this._animationFrameDirty=!1;const t=this._animator.getCurrentFrame();t&&this._renderer.updateFrame(t)}getRendererObject(){return this._renderer.getRendererObject()}updateHitBoxes(){const t=this._animator.getCurrentFrame();if(!!t){if(!t.hasCustomHitBoxes)return super.updateHitBoxes();for(let e=0;e<t.customHitBoxes.length;++e){e>=this.hitBoxes.length&&this.hitBoxes.push(new n.Polygon);for(let i=0;i<t.customHitBoxes[e].vertices.length;++i)i>=this.hitBoxes[e].vertices.length&&this.hitBoxes[e].vertices.push([0,0]),this._transformToGlobal(t.customHitBoxes[e].vertices[i][0],t.customHitBoxes[e].vertices[i][1],this.hitBoxes[e].vertices[i]);this.hitBoxes[e].vertices.length=t.customHitBoxes[e].vertices.length}this.hitBoxes.length=t.customHitBoxes.length}}setAnimation(t){this.setAnimationIndex(t)}setAnimationIndex(t){this._animator.setAnimationIndex(t)&&(this._renderer.update(),this._animationFrameDirty=!0,this.invalidateHitboxes())}setAnimationName(t){this._animator.setAnimationName(t)&&(this._renderer.update(),this._animationFrameDirty=!0,this.invalidateHitboxes())}getAnimation(){return this.getAnimationIndex()}getAnimationIndex(){return this._animator.getAnimationIndex()}getAnimationName(){return this._animator.getAnimationName()}isCurrentAnimationName(t){return this.getAnimationName()===t}setDirectionOrAngle(t){const e=this._animator.setDirectionOrAngle(this.angle,t);e!==null&&(this.angle=e,this._renderer.update(),this._animationFrameDirty=!0,this.invalidateHitboxes(),this._renderer.updateAngle())}getDirectionOrAngle(){return this._animator.getDirectionOrAngle(this.angle)}setAnimationFrame(t){this._animator.setAnimationFrameIndex(t)&&(this._animationFrameDirty=!0,this.invalidateHitboxes())}getAnimationFrame(){return this._animator.getAnimationFrameIndex()}getAnimationElapsedTime(){return this._animator.getAnimationElapsedTime()}setAnimationElapsedTime(t){this._animator.getAnimationElapsedTime()&&(this._animationFrameDirty=!0,this.invalidateHitboxes())}getAnimationDuration(){return this._animator.getAnimationDuration()}getAnimationFrameCount(){return this._animator.getAnimationFrameCount()}hasAnimationEndedLegacy(){return this._animator.hasAnimationEndedLegacy()}hasAnimationEnded2(){return this._animator.hasAnimationEnded()}hasAnimationEnded(){return this._animator.hasAnimationEnded()}animationPaused(){return this._animator.isAnimationPaused()}isAnimationPaused(){return this._animator.isAnimationPaused()}pauseAnimation(){this._animator.pauseAnimation()}playAnimation(){this._animator.resumeAnimation()}resumeAnimation(){this._animator.resumeAnimation()}getAnimationSpeedScale(){return this._animator.getAnimationSpeedScale()}setAnimationSpeedScale(t){this._animator.setAnimationSpeedScale(t)}getPointX(t){const e=this._animator.getCurrentFrame();if(t.length===0||e===null)return this.getX();const i=e.getPoint(t),a=n.staticArray(s.prototype.getPointX);return this._transformToGlobal(i.x,i.y,a),a[0]}getPointY(t){const e=this._animator.getCurrentFrame();if(t.length===0||e===null)return this.getY();const i=e.getPoint(t),a=n.staticArray(s.prototype.getPointY);return this._transformToGlobal(i.x,i.y,a),a[1]}getPointPosition(t){const e=this._animator.getCurrentFrame();if(t.length===0||e===null)return[this.getX(),this.getY()];const i=e.getPoint(t),a=n.staticArray(s.prototype.getPointX);return this._transformToGlobal(i.x,i.y,a),[a[0],a[1]]}_transformToGlobal(t,e,i){const a=this._animator.getCurrentFrame();let r=a.center.x,o=a.center.y;this._flippedX&&(t=t+(r-t)*2),this._flippedY&&(e=e+(o-e)*2);const h=Math.abs(this._scaleX),l=Math.abs(this._scaleY);t*=h,e*=l,r*=h,o*=l;const d=this.angle/180*Math.PI,m=Math.cos(d),u=Math.sin(d),p=t-r,g=e-o;t=r+m*p-u*g,e=o+u*p+m*g,i.length=2,i[0]=t+(this.x-a.origin.x*h),i[1]=e+(this.y-a.origin.y*l)}getDrawableX(){const t=this._animator.getCurrentFrame();if(t===null)return this.x;const e=Math.abs(this._scaleX);return this._flippedX?this.x+(-t.origin.x-this._renderer.getUnscaledWidth()+2*t.center.x)*e:this.x-t.origin.x*e}getDrawableY(){const t=this._animator.getCurrentFrame();if(t===null)return this.y;const e=Math.abs(this._scaleY);return this._flippedY?this.y+(-t.origin.y-this._renderer.getUnscaledHeight()+2*t.center.y)*e:this.y-t.origin.y*e}getCenterX(){const t=this._animator.getCurrentFrame();return t===null?0:this._flippedX?(this._renderer.getUnscaledWidth()-t.center.x)*Math.abs(this._scaleX):t.center.x*Math.abs(this._scaleX)}getCenterY(){const t=this._animator.getCurrentFrame();return t===null?0:this._flippedY?(this._renderer.getUnscaledHeight()-t.center.y)*Math.abs(this._scaleY):t.center.y*Math.abs(this._scaleY)}setX(t){if(t===this.x)return;this.x=t,this._animator.getCurrentFrame()!==null&&(this.invalidateHitboxes(),this._renderer.updateX())}setY(t){if(t===this.y)return;this.y=t,this._animator.getCurrentFrame()!==null&&(this.invalidateHitboxes(),this._renderer.updateY())}setAngle(t){const e=this._animator.setAngle(this.angle,t);e!==null&&(this.angle=e,this.invalidateHitboxes(),this._renderer.updateAngle())}getAngle(){return this._animator.getAngle(this.angle)}setBlendMode(t){this._blendMode!==t&&(this._blendMode=t,this._renderer.update())}getBlendMode(){return this._blendMode}setOpacity(t){t<0&&(t=0),t>255&&(t=255),this.opacity=t,this._renderer.updateOpacity()}getOpacity(){return this.opacity}hide(t){t===void 0&&(t=!0),this.hidden=t,this._renderer.updateVisibility()}setColor(t){this._renderer.setColor(t)}getColor(){return this._renderer.getColor()}flipX(t){t!==this._flippedX&&(this._scaleX*=-1,this._flippedX=t,this.invalidateHitboxes(),this._renderer.update())}flipY(t){t!==this._flippedY&&(this._scaleY*=-1,this._flippedY=t,this.invalidateHitboxes(),this._renderer.update())}isFlippedX(){return this._flippedX}isFlippedY(){return this._flippedY}getWidth(){return this._animationFrameDirty&&this._updateAnimationFrame(),this._renderer.getWidth()}getHeight(){return this._animationFrameDirty&&this._updateAnimationFrame(),this._renderer.getHeight()}setWidth(t){this._animationFrameDirty&&this._updateAnimationFrame();const e=this._renderer.getUnscaledWidth();e!==0&&this.setScaleX(t/e)}setHeight(t){this._animationFrameDirty&&this._updateAnimationFrame();const e=this._renderer.getUnscaledHeight();e!==0&&this.setScaleY(t/e)}setSize(t,e){this.setWidth(t),this.setHeight(e)}setScale(t){t<0&&(t=0),!(t===Math.abs(this._scaleX)&&t===Math.abs(this._scaleY))&&(this._scaleX=t*(this._flippedX?-1:1),this._scaleY=t*(this._flippedY?-1:1),this._renderer.update(),this.invalidateHitboxes())}setScaleX(t){t<0&&(t=0),t!==Math.abs(this._scaleX)&&(this._scaleX=t*(this._flippedX?-1:1),this._renderer.update(),this.invalidateHitboxes())}setScaleY(t){t<0&&(t=0),t!==Math.abs(this._scaleY)&&(this._scaleY=t*(this._flippedY?-1:1),this._renderer.update(),this.invalidateHitboxes())}getScaleMean(){return(Math.abs(this._scaleX)+Math.abs(this._scaleY))/2}getScale(){const t=Math.abs(this._scaleX),e=Math.abs(this._scaleY);return t===e?t:Math.sqrt(t*e)}getScaleY(){return Math.abs(this._scaleY)}getScaleX(){return Math.abs(this._scaleX)}turnTowardObject(t,e){t!==null&&this.rotateTowardPosition(t.getDrawableX()+t.getCenterX(),t.getDrawableY()+t.getCenterY(),0,e)}}n.SpriteRuntimeObject=s,n.registerObject("Sprite",n.SpriteRuntimeObject),s.supportsReinitialization=!0})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(n){class s extends n.RuntimeObject{constructor(t,e){super(t,e);this._scaleX=1;this._scaleY=1;this._blendMode=0;this._flippedX=!1;this._flippedY=!1;this.opacity=255;this._preScale=1;this._animationFrameDirty=!0;this._updateIfNotVisible=!!e.updateIfNotVisible,this._preScale=e.preScale||1,this._renderer=new n.SpriteRuntimeObjectRenderer(this,t),this._animator=new n.SpriteAnimator(e.animations,n.SpriteRuntimeObjectRenderer.getAnimationFrameTextureManager(t.getGame().getImageManager())),this._updateAnimationFrame(),this.onCreated()}reinitialize(t){super.reinitialize(t);const e=this.getInstanceContainer();this._animator.reinitialize(t.animations),this._scaleX=1,this._scaleY=1,this._blendMode=0,this._flippedX=!1,this._flippedY=!1,this.opacity=255,this._updateIfNotVisible=!!t.updateIfNotVisible,this._preScale=t.preScale||1,this._renderer.reinitialize(this,e),this._updateAnimationFrame(),this.onCreated()}updateFromObjectData(t,e){return this._preScale=e.preScale||1,this._animator.updateFromObjectData(t.animations,e.animations),this._updateIfNotVisible=!!e.updateIfNotVisible,this._updateAnimationFrame(),this.invalidateHitboxes(),!0}getNetworkSyncData(){return{...super.getNetworkSyncData(),anim:this._animator.getNetworkSyncData(),ifx:this.isFlippedX(),ify:this.isFlippedY(),sx:this._scaleX,sy:this._scaleY,op:this.opacity,color:this.getColor()}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t),t.ifx!==void 0&&this.flipX(t.ifx),t.ify!==void 0&&this.flipY(t.ify),t.sx!==void 0&&this.setScaleX(Math.abs(t.sx)),t.sy!==void 0&&this.setScaleY(Math.abs(t.sy)),t.op!==void 0&&this.setOpacity(t.op),t.anim&&(this._animator.updateFromNetworkSyncData(t.anim),this._updateAnimationFrame()),(t.ifx!==void 0||t.ify!==void 0||t.sx!==void 0||t.sy!==void 0||t.anim!==void 0)&&this.invalidateHitboxes(),t.color!==void 0&&this.setColor(t.color)}extraInitializationFromInitialInstance(t){if(t.numberProperties)for(let e=0,i=t.numberProperties.length;e<i;++e){const a=t.numberProperties[e];a.name==="animation"&&this.setAnimationIndex(a.value)}t.customSize&&(this.setWidth(t.width),this.setHeight(t.height))}update(t){if(!this._updateIfNotVisible&&!this._renderer.getRendererObject().visible)return;this._animator.step(this.getElapsedTime()/1e3)&&(this._updateAnimationFrame(),this.invalidateHitboxes()),this._renderer.ensureUpToDate()}updatePreRender(t){this._animationFrameDirty&&this._updateAnimationFrame(),this._renderer.ensureUpToDate()}_updateAnimationFrame(){this._animationFrameDirty=!1;const t=this._animator.getCurrentFrame();t&&this._renderer.updateFrame(t)}getRendererObject(){return this._renderer.getRendererObject()}updateHitBoxes(){const t=this._animator.getCurrentFrame();if(!!t){if(!t.hasCustomHitBoxes)return super.updateHitBoxes();for(let e=0;e<t.customHitBoxes.length;++e){e>=this.hitBoxes.length&&this.hitBoxes.push(new n.Polygon);for(let i=0;i<t.customHitBoxes[e].vertices.length;++i)i>=this.hitBoxes[e].vertices.length&&this.hitBoxes[e].vertices.push([0,0]),this._transformToGlobal(t.customHitBoxes[e].vertices[i][0],t.customHitBoxes[e].vertices[i][1],this.hitBoxes[e].vertices[i]);this.hitBoxes[e].vertices.length=t.customHitBoxes[e].vertices.length}this.hitBoxes.length=t.customHitBoxes.length}}setAnimation(t){this.setAnimationIndex(t)}setAnimationIndex(t){this._animator.setAnimationIndex(t)&&(this._renderer.update(),this._animationFrameDirty=!0,this.invalidateHitboxes())}setAnimationName(t){this._animator.setAnimationName(t)&&(this._renderer.update(),this._animationFrameDirty=!0,this.invalidateHitboxes())}getAnimation(){return this.getAnimationIndex()}getAnimationIndex(){return this._animator.getAnimationIndex()}getAnimationName(){return this._animator.getAnimationName()}isCurrentAnimationName(t){return this.getAnimationName()===t}setDirectionOrAngle(t){const e=this._animator.setDirectionOrAngle(this.angle,t);e!==null&&(this.angle=e,this._renderer.update(),this._animationFrameDirty=!0,this.invalidateHitboxes(),this._renderer.updateAngle())}getDirectionOrAngle(){return this._animator.getDirectionOrAngle(this.angle)}setAnimationFrame(t){this._animator.setAnimationFrameIndex(t)&&(this._animationFrameDirty=!0,this.invalidateHitboxes())}getAnimationFrame(){return this._animator.getAnimationFrameIndex()}getAnimationElapsedTime(){return this._animator.getAnimationElapsedTime()}setAnimationElapsedTime(t){this._animator.getAnimationElapsedTime()&&(this._animationFrameDirty=!0,this.invalidateHitboxes())}getAnimationDuration(){return this._animator.getAnimationDuration()}getAnimationFrameCount(){return this._animator.getAnimationFrameCount()}hasAnimationEndedLegacy(){return this._animator.hasAnimationEndedLegacy()}hasAnimationEnded2(){return this._animator.hasAnimationEnded()}hasAnimationEnded(){return this._animator.hasAnimationEnded()}animationPaused(){return this._animator.isAnimationPaused()}isAnimationPaused(){return this._animator.isAnimationPaused()}pauseAnimation(){this._animator.pauseAnimation()}playAnimation(){this._animator.resumeAnimation()}resumeAnimation(){this._animator.resumeAnimation()}getAnimationSpeedScale(){return this._animator.getAnimationSpeedScale()}setAnimationSpeedScale(t){this._animator.setAnimationSpeedScale(t)}getPointX(t){const e=this._animator.getCurrentFrame();if(t.length===0||e===null)return this.getX();const i=e.getPoint(t),a=n.staticArray(s.prototype.getPointX);return this._transformToGlobal(i.x,i.y,a),a[0]}getPointY(t){const e=this._animator.getCurrentFrame();if(t.length===0||e===null)return this.getY();const i=e.getPoint(t),a=n.staticArray(s.prototype.getPointY);return this._transformToGlobal(i.x,i.y,a),a[1]}getPointPosition(t){const e=this._animator.getCurrentFrame();if(t.length===0||e===null)return[this.getX(),this.getY()];const i=e.getPoint(t),a=n.staticArray(s.prototype.getPointX);return this._transformToGlobal(i.x,i.y,a),[a[0],a[1]]}_transformToGlobal(t,e,i){const a=this._animator.getCurrentFrame();let r=a.center.x,o=a.center.y;this._flippedX&&(t=t+(r-t)*2),this._flippedY&&(e=e+(o-e)*2);const h=Math.abs(this._scaleX*this._preScale),l=Math.abs(this._scaleY*this._preScale);t*=h,e*=l,r*=h,o*=l;const d=this.angle/180*Math.PI,m=Math.cos(d),u=Math.sin(d),p=t-r,g=e-o;t=r+m*p-u*g,e=o+u*p+m*g,i.length=2,i[0]=t+(this.x-a.origin.x*h),i[1]=e+(this.y-a.origin.y*l)}getDrawableX(){const t=this._animator.getCurrentFrame();if(t===null)return this.x;const e=Math.abs(this._scaleX*this._preScale);return this._flippedX?this.x+(-t.origin.x-this._renderer.getUnscaledWidth()+2*t.center.x)*e:this.x-t.origin.x*e}getDrawableY(){const t=this._animator.getCurrentFrame();if(t===null)return this.y;const e=Math.abs(this._scaleY*this._preScale);return this._flippedY?this.y+(-t.origin.y-this._renderer.getUnscaledHeight()+2*t.center.y)*e:this.y-t.origin.y*e}getCenterX(){const t=this._animator.getCurrentFrame();return t===null?0:this._flippedX?(this._renderer.getUnscaledWidth()-t.center.x)*Math.abs(this._scaleX*this._preScale):t.center.x*Math.abs(this._scaleX*this._preScale)}getCenterY(){const t=this._animator.getCurrentFrame();return t===null?0:this._flippedY?(this._renderer.getUnscaledHeight()-t.center.y)*Math.abs(this._scaleY*this._preScale):t.center.y*Math.abs(this._scaleY*this._preScale)}setX(t){if(t===this.x)return;this.x=t,this._animator.getCurrentFrame()!==null&&(this.invalidateHitboxes(),this._renderer.updateX())}setY(t){if(t===this.y)return;this.y=t,this._animator.getCurrentFrame()!==null&&(this.invalidateHitboxes(),this._renderer.updateY())}setAngle(t){const e=this._animator.setAngle(this.angle,t);e!==null&&(this.angle=e,this.invalidateHitboxes(),this._renderer.updateAngle())}getAngle(){return this._animator.getAngle(this.angle)}setBlendMode(t){this._blendMode!==t&&(this._blendMode=t,this._renderer.update())}getBlendMode(){return this._blendMode}setOpacity(t){t<0&&(t=0),t>255&&(t=255),this.opacity=t,this._renderer.updateOpacity()}getOpacity(){return this.opacity}hide(t){t===void 0&&(t=!0),this.hidden=t,this._renderer.updateVisibility()}setColor(t){this._renderer.setColor(t)}getColor(){return this._renderer.getColor()}flipX(t){t!==this._flippedX&&(this._scaleX*=-1,this._flippedX=t,this.invalidateHitboxes(),this._renderer.update())}flipY(t){t!==this._flippedY&&(this._scaleY*=-1,this._flippedY=t,this.invalidateHitboxes(),this._renderer.update())}isFlippedX(){return this._flippedX}isFlippedY(){return this._flippedY}getWidth(){return this._animationFrameDirty&&this._updateAnimationFrame(),this._renderer.getWidth()}getHeight(){return this._animationFrameDirty&&this._updateAnimationFrame(),this._renderer.getHeight()}setWidth(t){this._animationFrameDirty&&this._updateAnimationFrame();const e=this._renderer.getUnscaledWidth();e!==0&&this.setScaleX(t/e)}setHeight(t){this._animationFrameDirty&&this._updateAnimationFrame();const e=this._renderer.getUnscaledHeight();e!==0&&this.setScaleY(t/e)}setSize(t,e){this.setWidth(t),this.setHeight(e)}setScale(t){t<0&&(t=0),!(t===Math.abs(this._scaleX)&&t===Math.abs(this._scaleY))&&(this._scaleX=t*(this._flippedX?-1:1),this._scaleY=t*(this._flippedY?-1:1),this._renderer.update(),this.invalidateHitboxes())}setScaleX(t){t<0&&(t=0),t!==Math.abs(this._scaleX)&&(this._scaleX=t*(this._flippedX?-1:1),this._renderer.update(),this.invalidateHitboxes())}setScaleY(t){t<0&&(t=0),t!==Math.abs(this._scaleY)&&(this._scaleY=t*(this._flippedY?-1:1),this._renderer.update(),this.invalidateHitboxes())}getScaleMean(){return(Math.abs(this._scaleX)+Math.abs(this._scaleY))/2}getScale(){const t=Math.abs(this._scaleX),e=Math.abs(this._scaleY);return t===e?t:Math.sqrt(t*e)}getScaleY(){return Math.abs(this._scaleY)}getScaleX(){return Math.abs(this._scaleX)}turnTowardObject(t,e){t!==null&&this.rotateTowardPosition(t.getDrawableX()+t.getCenterX(),t.getDrawableY()+t.getCenterY(),0,e)}}n.SpriteRuntimeObject=s,n.registerObject("Sprite",n.SpriteRuntimeObject),s.supportsReinitialization=!0})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=spriteruntimeobject.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/spriteruntimeobject.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 /** Represents the data of a {@link gdjs.SpriteRuntimeObject}. */\n export type SpriteObjectDataType = {\n /** Update the object even if he is not visible?. */\n updateIfNotVisible: boolean;\n /** The list of {@link SpriteAnimationData} representing {@link gdjs.SpriteAnimation} instances. */\n animations: Array<SpriteAnimationData>;\n };\n\n export type SpriteObjectData = ObjectData & SpriteObjectDataType;\n\n export type SpriteNetworkSyncDataType = {\n anim: SpriteAnimatorNetworkSyncData;\n ifx: boolean;\n ify: boolean;\n sx: float;\n sy: float;\n op: float;\n color: string;\n };\n\n export type SpriteNetworkSyncData = ObjectNetworkSyncData &\n SpriteNetworkSyncDataType;\n\n /**\n * The SpriteRuntimeObject represents an object that can display images.\n */\n export class SpriteRuntimeObject\n extends gdjs.RuntimeObject\n implements\n gdjs.Resizable,\n gdjs.Scalable,\n gdjs.Flippable,\n gdjs.Animatable,\n gdjs.OpacityHandler {\n _animator: gdjs.SpriteAnimator<any>;\n _scaleX: float = 1;\n _scaleY: float = 1;\n _blendMode: integer = 0;\n _flippedX: boolean = false;\n _flippedY: boolean = false;\n opacity: float = 255;\n _updateIfNotVisible: boolean;\n\n _renderer: gdjs.SpriteRuntimeObjectRenderer;\n _animationFrameDirty = true;\n\n /**\n * @param instanceContainer The container the object belongs to\n * @param spriteObjectData The object data used to initialize the object\n */\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n spriteObjectData: ObjectData & SpriteObjectDataType\n ) {\n super(instanceContainer, spriteObjectData);\n this._updateIfNotVisible = !!spriteObjectData.updateIfNotVisible;\n this._renderer = new gdjs.SpriteRuntimeObjectRenderer(\n this,\n instanceContainer\n );\n this._animator = new gdjs.SpriteAnimator(\n spriteObjectData.animations,\n gdjs.SpriteRuntimeObjectRenderer.getAnimationFrameTextureManager(\n instanceContainer.getGame().getImageManager()\n )\n );\n this._updateAnimationFrame();\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object constructor.\n this.onCreated();\n }\n\n reinitialize(spriteObjectData: SpriteObjectData) {\n super.reinitialize(spriteObjectData);\n const instanceContainer = this.getInstanceContainer();\n this._animator.reinitialize(spriteObjectData.animations);\n this._scaleX = 1;\n this._scaleY = 1;\n this._blendMode = 0;\n this._flippedX = false;\n this._flippedY = false;\n this.opacity = 255;\n this._updateIfNotVisible = !!spriteObjectData.updateIfNotVisible;\n this._renderer.reinitialize(this, instanceContainer);\n this._updateAnimationFrame();\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object reinitialize method.\n this.onCreated();\n }\n\n updateFromObjectData(\n oldObjectData: SpriteObjectData,\n newObjectData: SpriteObjectData\n ): boolean {\n this._animator.updateFromObjectData(\n oldObjectData.animations,\n newObjectData.animations\n );\n this._updateIfNotVisible = !!newObjectData.updateIfNotVisible;\n this.invalidateHitboxes();\n return true;\n }\n\n getNetworkSyncData(): SpriteNetworkSyncData {\n return {\n ...super.getNetworkSyncData(),\n anim: this._animator.getNetworkSyncData(),\n ifx: this.isFlippedX(),\n ify: this.isFlippedY(),\n sx: this._scaleX,\n sy: this._scaleY,\n op: this.opacity,\n color: this.getColor(),\n };\n }\n\n updateFromNetworkSyncData(newNetworkSyncData: SpriteNetworkSyncData) {\n super.updateFromNetworkSyncData(newNetworkSyncData);\n if (newNetworkSyncData.ifx !== undefined) {\n this.flipX(newNetworkSyncData.ifx);\n }\n if (newNetworkSyncData.ify !== undefined) {\n this.flipY(newNetworkSyncData.ify);\n }\n if (newNetworkSyncData.sx !== undefined) {\n this.setScaleX(Math.abs(newNetworkSyncData.sx));\n }\n if (newNetworkSyncData.sy !== undefined) {\n this.setScaleY(Math.abs(newNetworkSyncData.sy));\n }\n if (newNetworkSyncData.op !== undefined) {\n this.setOpacity(newNetworkSyncData.op);\n }\n if (newNetworkSyncData.anim) {\n this._animator.updateFromNetworkSyncData(newNetworkSyncData.anim);\n // TODO: optimize updating the animation frame only if needed.\n this._updateAnimationFrame();\n }\n if (\n newNetworkSyncData.ifx !== undefined ||\n newNetworkSyncData.ify !== undefined ||\n newNetworkSyncData.sx !== undefined ||\n newNetworkSyncData.sy !== undefined ||\n newNetworkSyncData.anim !== undefined\n ) {\n this.invalidateHitboxes();\n }\n if (newNetworkSyncData.color !== undefined) {\n this.setColor(newNetworkSyncData.color);\n }\n }\n\n /**\n * Initialize the extra parameters that could be set for an instance.\n * @param initialInstanceData The extra parameters\n */\n extraInitializationFromInitialInstance(initialInstanceData: InstanceData) {\n if (initialInstanceData.numberProperties) {\n for (\n let i = 0, len = initialInstanceData.numberProperties.length;\n i < len;\n ++i\n ) {\n const extraData = initialInstanceData.numberProperties[i];\n if (extraData.name === 'animation') {\n this.setAnimationIndex(extraData.value);\n }\n }\n }\n if (initialInstanceData.customSize) {\n this.setWidth(initialInstanceData.width);\n this.setHeight(initialInstanceData.height);\n }\n }\n\n /**\n * Update the current frame of the object according to the elapsed time on the scene.\n */\n update(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n //Playing the animation of all objects including the ones outside the screen can be\n //costly when the scene is big with a lot of animated objects. By default, we skip\n //updating the object if it is not visible.\n if (\n !this._updateIfNotVisible &&\n !this._renderer.getRendererObject().visible\n ) {\n return;\n }\n const hasFrameChanged = this._animator.step(this.getElapsedTime() / 1000);\n if (hasFrameChanged) {\n this._updateAnimationFrame();\n // TODO: Hitboxes may not need an update if every frames has the same ones.\n this.invalidateHitboxes();\n }\n this._renderer.ensureUpToDate();\n }\n\n /**\n * Ensure the sprite is ready to be displayed: the proper animation frame\n * is set and the renderer is up to date (position, angle, alpha, flip, blend mode...).\n */\n updatePreRender(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n this._renderer.ensureUpToDate();\n }\n\n /**\n * Update `this._animationFrame` according to the current animation/direction/frame values\n * (`this._currentAnimation`, `this._currentDirection`, `this._currentFrame`) and set\n * `this._animationFrameDirty` back to false.\n *\n * Trigger a call to the renderer to change the texture being shown (if the animation/direction/frame\n * is valid).\n * If invalid, `this._animationFrame` will be `null` after calling this function.\n */\n _updateAnimationFrame() {\n this._animationFrameDirty = false;\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame) {\n this._renderer.updateFrame(animationFrame);\n }\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n /**\n * Update the hit boxes for the object.\n * Fallback to the default implementation (rotated bounding box) if there is no custom\n * hitboxes defined for the current animation frame.\n */\n updateHitBoxes(): void {\n const animationFrame = this._animator.getCurrentFrame();\n if (!animationFrame) {\n return;\n }\n\n if (!animationFrame.hasCustomHitBoxes) {\n return super.updateHitBoxes();\n }\n\n //logger.log(\"Update for \"+this.name); //Uncomment to track updates\n //(and in particular be sure that unnecessary update are avoided).\n\n //Update the current hitboxes with the frame custom hit boxes\n //and apply transformations.\n for (let i = 0; i < animationFrame.customHitBoxes.length; ++i) {\n if (i >= this.hitBoxes.length) {\n this.hitBoxes.push(new gdjs.Polygon());\n }\n for (\n let j = 0;\n j < animationFrame.customHitBoxes[i].vertices.length;\n ++j\n ) {\n if (j >= this.hitBoxes[i].vertices.length) {\n this.hitBoxes[i].vertices.push([0, 0]);\n }\n this._transformToGlobal(\n animationFrame.customHitBoxes[i].vertices[j][0],\n animationFrame.customHitBoxes[i].vertices[j][1],\n this.hitBoxes[i].vertices[j]\n );\n }\n this.hitBoxes[i].vertices.length =\n animationFrame.customHitBoxes[i].vertices.length;\n }\n this.hitBoxes.length = animationFrame.customHitBoxes.length;\n }\n\n //Rotate and scale and flipping have already been applied to the point by _transformToGlobal.\n //Animations :\n /**\n * Change the animation being played.\n * @param newAnimation The index of the new animation to be played\n * @deprecated Use `setAnimationIndex` instead\n */\n setAnimation(newAnimation: integer): void {\n this.setAnimationIndex(newAnimation);\n }\n\n setAnimationIndex(newAnimation: integer): void {\n const hasAnimationChanged = this._animator.setAnimationIndex(\n newAnimation\n );\n if (hasAnimationChanged) {\n //TODO: This may be unnecessary.\n this._renderer.update();\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n setAnimationName(newAnimationName: string): void {\n const hasAnimationChanged = this._animator.setAnimationName(\n newAnimationName\n );\n if (hasAnimationChanged) {\n //TODO: This may be unnecessary.\n this._renderer.update();\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n /**\n * Get the index of the animation being played.\n * @return The index of the new animation being played\n * @deprecated Use `getAnimationIndex` instead\n */\n getAnimation(): integer {\n return this.getAnimationIndex();\n }\n\n getAnimationIndex(): integer {\n return this._animator.getAnimationIndex();\n }\n\n getAnimationName(): string {\n return this._animator.getAnimationName();\n }\n\n isCurrentAnimationName(name: string): boolean {\n return this.getAnimationName() === name;\n }\n\n /**\n * Change the angle (or direction index) of the object\n * @param The new angle (or direction index) to be applied\n */\n setDirectionOrAngle(newValue: float): void {\n const actualValue = this._animator.setDirectionOrAngle(\n this.angle,\n newValue\n );\n if (actualValue !== null) {\n this.angle = actualValue;\n //TODO: This may be unnecessary.\n this._renderer.update();\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n this._renderer.updateAngle();\n }\n }\n\n getDirectionOrAngle(): float {\n return this._animator.getDirectionOrAngle(this.angle);\n }\n\n /**\n * Change the current frame displayed by the animation\n * @param newFrame The index of the frame to be displayed\n */\n setAnimationFrame(newFrame: integer): void {\n const hasFrameChanged = this._animator.setAnimationFrameIndex(newFrame);\n if (hasFrameChanged) {\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n /**\n * Get the index of the current frame displayed by the animation\n * @return newFrame The index of the frame being displayed\n */\n getAnimationFrame(): integer {\n return this._animator.getAnimationFrameIndex();\n }\n\n getAnimationElapsedTime(): float {\n return this._animator.getAnimationElapsedTime();\n }\n\n setAnimationElapsedTime(time: float): void {\n const hasFrameChanged = this._animator.getAnimationElapsedTime();\n if (hasFrameChanged) {\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n getAnimationDuration(): float {\n return this._animator.getAnimationDuration();\n }\n\n getAnimationFrameCount(): integer {\n return this._animator.getAnimationFrameCount();\n }\n\n /**\n * @deprecated\n * Return true if animation has ended.\n * Prefer using `hasAnimationEnded2`. This method returns true as soon as\n * the animation enters the last frame, not at the end of the last frame.\n */\n hasAnimationEndedLegacy(): boolean {\n return this._animator.hasAnimationEndedLegacy();\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n *\n * @deprecated Use `hasAnimationEnded` instead.\n */\n hasAnimationEnded2(): boolean {\n return this._animator.hasAnimationEnded();\n }\n\n hasAnimationEnded(): boolean {\n return this._animator.hasAnimationEnded();\n }\n\n /**\n * @deprecated Use `isAnimationPaused` instead.\n */\n animationPaused(): boolean {\n return this._animator.isAnimationPaused();\n }\n\n isAnimationPaused(): boolean {\n return this._animator.isAnimationPaused();\n }\n\n pauseAnimation(): void {\n this._animator.pauseAnimation();\n }\n\n /**\n * @deprecated Use `resumeAnimation` instead.\n */\n playAnimation(): void {\n this._animator.resumeAnimation();\n }\n\n resumeAnimation(): void {\n this._animator.resumeAnimation();\n }\n\n getAnimationSpeedScale(): float {\n return this._animator.getAnimationSpeedScale();\n }\n\n setAnimationSpeedScale(ratio: float): void {\n this._animator.setAnimationSpeedScale(ratio);\n }\n\n //Position :\n /**\n * Get the position on X axis on the scene of the given point.\n * @param name The point name\n * @return the position on X axis on the scene of the given point.\n */\n getPointX(name: string): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (name.length === 0 || animationFrame === null) {\n return this.getX();\n }\n const pt = animationFrame.getPoint(name);\n const pos = gdjs.staticArray(SpriteRuntimeObject.prototype.getPointX);\n this._transformToGlobal(pt.x, pt.y, pos);\n return pos[0];\n }\n\n /**\n * Get the position on Y axis on the scene of the given point.\n * @param name The point name\n * @return the position on Y axis on the scene of the given point.\n */\n getPointY(name: string): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (name.length === 0 || animationFrame === null) {\n return this.getY();\n }\n const pt = animationFrame.getPoint(name);\n const pos = gdjs.staticArray(SpriteRuntimeObject.prototype.getPointY);\n this._transformToGlobal(pt.x, pt.y, pos);\n return pos[1];\n }\n /**\n * Get the positions on X and Y axis on the scene of the given point.\n * @param name The point name\n * @return An array of the position on X and Y axis on the scene of the given point.\n */\n getPointPosition(name: string): [x: float, y: float] {\n const animationFrame = this._animator.getCurrentFrame();\n if (name.length === 0 || animationFrame === null) {\n return [this.getX(), this.getY()];\n }\n const pt = animationFrame.getPoint(name);\n const pos = gdjs.staticArray(SpriteRuntimeObject.prototype.getPointX);\n this._transformToGlobal(pt.x, pt.y, pos);\n return [pos[0], pos[1]];\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in world coordinates (as opposed to the object local coordinates).\n *\n * Beware: this._animationFrame and this._sprite must *not* be null!\n *\n * All transformations (flipping, scale, rotation) are supported.\n *\n * @param x The X position of the point, in object coordinates.\n * @param y The Y position of the point, in object coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in global coordinates).\n */\n private _transformToGlobal(x: float, y: float, result: float[]) {\n const animationFrame = this._animator.getCurrentFrame() as SpriteAnimationFrame<\n any\n >;\n let cx = animationFrame.center.x;\n let cy = animationFrame.center.y;\n\n //Flipping\n if (this._flippedX) {\n x = x + (cx - x) * 2;\n }\n if (this._flippedY) {\n y = y + (cy - y) * 2;\n }\n\n //Scale\n const absScaleX = Math.abs(this._scaleX);\n const absScaleY = Math.abs(this._scaleY);\n x *= absScaleX;\n y *= absScaleY;\n cx *= absScaleX;\n cy *= absScaleY;\n\n //Rotation\n const angleInRadians = (this.angle / 180) * Math.PI;\n const cosValue = Math.cos(\n // Only compute cos and sin once (10% faster than doing it twice)\n angleInRadians\n );\n const sinValue = Math.sin(angleInRadians);\n const xToCenterXDelta = x - cx;\n const yToCenterYDelta = y - cy;\n x = cx + cosValue * xToCenterXDelta - sinValue * yToCenterYDelta;\n y = cy + sinValue * xToCenterXDelta + cosValue * yToCenterYDelta;\n result.length = 2;\n result[0] = x + (this.x - animationFrame.origin.x * absScaleX);\n result[1] = y + (this.y - animationFrame.origin.y * absScaleY);\n }\n\n /**\n * Get the X position, on the scene, of the origin of the texture of the object.\n * @return the X position, on the scene, of the origin of the texture of the object.\n */\n getDrawableX(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return this.x;\n }\n const absScaleX = Math.abs(this._scaleX);\n if (!this._flippedX) {\n return this.x - animationFrame.origin.x * absScaleX;\n } else {\n return (\n this.x +\n (-animationFrame.origin.x -\n this._renderer.getUnscaledWidth() +\n 2 * animationFrame.center.x) *\n absScaleX\n );\n }\n }\n\n /**\n * Get the Y position, on the scene, of the origin of the texture of the object.\n * @return the Y position, on the scene, of the origin of the texture of the object.\n */\n getDrawableY(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return this.y;\n }\n const absScaleY = Math.abs(this._scaleY);\n if (!this._flippedY) {\n return this.y - animationFrame.origin.y * absScaleY;\n } else {\n return (\n this.y +\n (-animationFrame.origin.y -\n this._renderer.getUnscaledHeight() +\n 2 * animationFrame.center.y) *\n absScaleY\n );\n }\n }\n\n /**\n * Get the X position of the center of the object, relative to top-left of the texture of the object (`getDrawableX`).\n * @return X position of the center of the object, relative to `getDrawableX()`.\n */\n getCenterX(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return 0;\n }\n if (!this._flippedX) {\n //Just need to multiply by the scale as it is the center.\n return animationFrame.center.x * Math.abs(this._scaleX);\n } else {\n return (\n (this._renderer.getUnscaledWidth() - animationFrame.center.x) *\n Math.abs(this._scaleX)\n );\n }\n }\n\n /**\n * Get the Y position of the center of the object, relative to top-left of the texture of the object (`getDrawableY`).\n * @return Y position of the center of the object, relative to `getDrawableY()`.\n */\n getCenterY(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return 0;\n }\n if (!this._flippedY) {\n //Just need to multiply by the scale as it is the center.\n return animationFrame.center.y * Math.abs(this._scaleY);\n } else {\n return (\n (this._renderer.getUnscaledHeight() - animationFrame.center.y) *\n Math.abs(this._scaleY)\n );\n }\n }\n\n /**\n * Set the X position of the (origin of the) object.\n * @param x The new X position.\n */\n setX(x: float): void {\n if (x === this.x) {\n return;\n }\n this.x = x;\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame !== null) {\n this.invalidateHitboxes();\n this._renderer.updateX();\n }\n }\n\n /**\n * Set the Y position of the (origin of the) object.\n * @param y The new Y position.\n */\n setY(y: float): void {\n if (y === this.y) {\n return;\n }\n this.y = y;\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame !== null) {\n this.invalidateHitboxes();\n this._renderer.updateY();\n }\n }\n\n /**\n * Set the angle of the object.\n * @param angle The new angle, in degrees.\n */\n setAngle(angle: float): void {\n const actualValue = this._animator.setAngle(this.angle, angle);\n if (actualValue !== null) {\n this.angle = actualValue;\n this.invalidateHitboxes();\n this._renderer.updateAngle();\n }\n }\n\n /**\n * Get the angle of the object.\n * @return The angle, in degrees.\n */\n getAngle(): float {\n return this._animator.getAngle(this.angle);\n }\n\n //Visibility and display :\n setBlendMode(newMode): void {\n if (this._blendMode === newMode) {\n return;\n }\n this._blendMode = newMode;\n this._renderer.update();\n }\n\n getBlendMode() {\n return this._blendMode;\n }\n\n setOpacity(opacity: float): void {\n if (opacity < 0) {\n opacity = 0;\n }\n if (opacity > 255) {\n opacity = 255;\n }\n this.opacity = opacity;\n this._renderer.updateOpacity();\n }\n\n getOpacity(): float {\n return this.opacity;\n }\n\n /**\n * Hide (or show) the object\n * @param enable true to hide the object, false to show it again.\n */\n hide(enable: boolean): void {\n if (enable === undefined) {\n enable = true;\n }\n this.hidden = enable;\n this._renderer.updateVisibility();\n }\n\n /**\n * Change the tint of the sprite object.\n *\n * @param rgbColor The color, in RGB format (\"128;200;255\").\n */\n setColor(rgbColor: string): void {\n this._renderer.setColor(rgbColor);\n }\n\n /**\n * Get the tint of the sprite object.\n *\n * @returns The color, in RGB format (\"128;200;255\").\n */\n getColor(): string {\n return this._renderer.getColor();\n }\n\n flipX(enable: boolean) {\n if (enable !== this._flippedX) {\n this._scaleX *= -1;\n this._flippedX = enable;\n this.invalidateHitboxes();\n this._renderer.update();\n }\n }\n\n flipY(enable: boolean) {\n if (enable !== this._flippedY) {\n this._scaleY *= -1;\n this._flippedY = enable;\n this.invalidateHitboxes();\n this._renderer.update();\n }\n }\n\n isFlippedX(): boolean {\n return this._flippedX;\n }\n\n isFlippedY(): boolean {\n return this._flippedY;\n }\n\n //Scale and size :\n /**\n * Get the width of the object.\n *\n * @return The width of the object, in pixels.\n */\n getWidth(): float {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n return this._renderer.getWidth();\n }\n\n /**\n * Get the height of the object.\n *\n * @return The height of the object, in pixels.\n */\n getHeight(): float {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n return this._renderer.getHeight();\n }\n\n setWidth(newWidth: float): void {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n const unscaledWidth = this._renderer.getUnscaledWidth();\n if (unscaledWidth !== 0) {\n this.setScaleX(newWidth / unscaledWidth);\n }\n }\n\n setHeight(newHeight: float): void {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n const unscaledHeight = this._renderer.getUnscaledHeight();\n if (unscaledHeight !== 0) {\n this.setScaleY(newHeight / unscaledHeight);\n }\n }\n\n setSize(newWidth: float, newHeight: float): void {\n this.setWidth(newWidth);\n this.setHeight(newHeight);\n }\n\n /**\n * Change the scale on X and Y axis of the object.\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScale(newScale: float): void {\n if (newScale < 0) {\n newScale = 0;\n }\n if (\n newScale === Math.abs(this._scaleX) &&\n newScale === Math.abs(this._scaleY)\n ) {\n return;\n }\n this._scaleX = newScale * (this._flippedX ? -1 : 1);\n this._scaleY = newScale * (this._flippedY ? -1 : 1);\n this._renderer.update();\n this.invalidateHitboxes();\n }\n\n /**\n * Change the scale on X axis of the object (changing its width).\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScaleX(newScale: float): void {\n if (newScale < 0) {\n newScale = 0;\n }\n if (newScale === Math.abs(this._scaleX)) {\n return;\n }\n this._scaleX = newScale * (this._flippedX ? -1 : 1);\n this._renderer.update();\n this.invalidateHitboxes();\n }\n\n /**\n * Change the scale on Y axis of the object (changing its height).\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScaleY(newScale: float): void {\n if (newScale < 0) {\n newScale = 0;\n }\n if (newScale === Math.abs(this._scaleY)) {\n return;\n }\n this._scaleY = newScale * (this._flippedY ? -1 : 1);\n this._renderer.update();\n this.invalidateHitboxes();\n }\n\n /**\n * Get the scale of the object (or the arithmetic mean of the X and Y scale in case they are different).\n *\n * @return the scale of the object (or the arithmetic mean of the X and Y scale in case they are different).\n * @deprecated Use `getScale` instead.\n */\n getScaleMean(): float {\n return (Math.abs(this._scaleX) + Math.abs(this._scaleY)) / 2.0;\n }\n\n /**\n * Get the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n *\n * @return the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n */\n getScale(): float {\n const scaleX = Math.abs(this._scaleX);\n const scaleY = Math.abs(this._scaleY);\n return scaleX === scaleY ? scaleX : Math.sqrt(scaleX * scaleY);\n }\n\n /**\n * Get the scale of the object on Y axis.\n *\n * @return the scale of the object on Y axis\n */\n getScaleY(): float {\n return Math.abs(this._scaleY);\n }\n\n /**\n * Get the scale of the object on X axis.\n *\n * @return the scale of the object on X axis\n */\n getScaleX(): float {\n return Math.abs(this._scaleX);\n }\n\n //Other :\n /**\n * @param obj The target object\n * @param scene The scene containing the object\n * @deprecated\n */\n turnTowardObject(obj: gdjs.RuntimeObject | null, scene: gdjs.RuntimeScene) {\n if (obj === null) {\n return;\n }\n this.rotateTowardPosition(\n obj.getDrawableX() + obj.getCenterX(),\n obj.getDrawableY() + obj.getCenterY(),\n 0,\n scene\n );\n }\n }\n gdjs.registerObject(\n 'Sprite',\n //Notify gdjs of the object existence.\n gdjs.SpriteRuntimeObject\n );\n\n //Others initialization and internal state management :\n SpriteRuntimeObject.supportsReinitialization = true;\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n /** Represents the data of a {@link gdjs.SpriteRuntimeObject}. */\n export type SpriteObjectDataType = {\n /** Update the object even if he is not visible?. */\n updateIfNotVisible: boolean;\n /** The scale applied to object to evaluate the default dimensions */\n preScale?: float;\n /** The list of {@link SpriteAnimationData} representing {@link gdjs.SpriteAnimation} instances. */\n animations: Array<SpriteAnimationData>;\n };\n\n export type SpriteObjectData = ObjectData & SpriteObjectDataType;\n\n export type SpriteNetworkSyncDataType = {\n anim: SpriteAnimatorNetworkSyncData;\n ifx: boolean;\n ify: boolean;\n sx: float;\n sy: float;\n op: float;\n color: string;\n };\n\n export type SpriteNetworkSyncData = ObjectNetworkSyncData &\n SpriteNetworkSyncDataType;\n\n /**\n * The SpriteRuntimeObject represents an object that can display images.\n */\n export class SpriteRuntimeObject\n extends gdjs.RuntimeObject\n implements\n gdjs.Resizable,\n gdjs.Scalable,\n gdjs.Flippable,\n gdjs.Animatable,\n gdjs.OpacityHandler {\n _animator: gdjs.SpriteAnimator<any>;\n _scaleX: float = 1;\n _scaleY: float = 1;\n _blendMode: integer = 0;\n _flippedX: boolean = false;\n _flippedY: boolean = false;\n opacity: float = 255;\n _updateIfNotVisible: boolean;\n _preScale: float = 1;\n\n _renderer: gdjs.SpriteRuntimeObjectRenderer;\n _animationFrameDirty = true;\n\n /**\n * @param instanceContainer The container the object belongs to\n * @param spriteObjectData The object data used to initialize the object\n */\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n spriteObjectData: ObjectData & SpriteObjectDataType\n ) {\n super(instanceContainer, spriteObjectData);\n this._updateIfNotVisible = !!spriteObjectData.updateIfNotVisible;\n this._preScale = spriteObjectData.preScale || 1;\n this._renderer = new gdjs.SpriteRuntimeObjectRenderer(\n this,\n instanceContainer\n );\n this._animator = new gdjs.SpriteAnimator(\n spriteObjectData.animations,\n gdjs.SpriteRuntimeObjectRenderer.getAnimationFrameTextureManager(\n instanceContainer.getGame().getImageManager()\n )\n );\n this._updateAnimationFrame();\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object constructor.\n this.onCreated();\n }\n\n reinitialize(spriteObjectData: SpriteObjectData) {\n super.reinitialize(spriteObjectData);\n const instanceContainer = this.getInstanceContainer();\n this._animator.reinitialize(spriteObjectData.animations);\n this._scaleX = 1;\n this._scaleY = 1;\n this._blendMode = 0;\n this._flippedX = false;\n this._flippedY = false;\n this.opacity = 255;\n this._updateIfNotVisible = !!spriteObjectData.updateIfNotVisible;\n this._preScale = spriteObjectData.preScale || 1;\n this._renderer.reinitialize(this, instanceContainer);\n this._updateAnimationFrame();\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object reinitialize method.\n this.onCreated();\n }\n\n updateFromObjectData(\n oldObjectData: SpriteObjectData,\n newObjectData: SpriteObjectData\n ): boolean {\n this._preScale = newObjectData.preScale || 1;\n this._animator.updateFromObjectData(\n oldObjectData.animations,\n newObjectData.animations\n );\n this._updateIfNotVisible = !!newObjectData.updateIfNotVisible;\n this._updateAnimationFrame();\n this.invalidateHitboxes();\n return true;\n }\n\n getNetworkSyncData(): SpriteNetworkSyncData {\n return {\n ...super.getNetworkSyncData(),\n anim: this._animator.getNetworkSyncData(),\n ifx: this.isFlippedX(),\n ify: this.isFlippedY(),\n sx: this._scaleX,\n sy: this._scaleY,\n op: this.opacity,\n color: this.getColor(),\n };\n }\n\n updateFromNetworkSyncData(newNetworkSyncData: SpriteNetworkSyncData) {\n super.updateFromNetworkSyncData(newNetworkSyncData);\n if (newNetworkSyncData.ifx !== undefined) {\n this.flipX(newNetworkSyncData.ifx);\n }\n if (newNetworkSyncData.ify !== undefined) {\n this.flipY(newNetworkSyncData.ify);\n }\n if (newNetworkSyncData.sx !== undefined) {\n this.setScaleX(Math.abs(newNetworkSyncData.sx));\n }\n if (newNetworkSyncData.sy !== undefined) {\n this.setScaleY(Math.abs(newNetworkSyncData.sy));\n }\n if (newNetworkSyncData.op !== undefined) {\n this.setOpacity(newNetworkSyncData.op);\n }\n if (newNetworkSyncData.anim) {\n this._animator.updateFromNetworkSyncData(newNetworkSyncData.anim);\n // TODO: optimize updating the animation frame only if needed.\n this._updateAnimationFrame();\n }\n if (\n newNetworkSyncData.ifx !== undefined ||\n newNetworkSyncData.ify !== undefined ||\n newNetworkSyncData.sx !== undefined ||\n newNetworkSyncData.sy !== undefined ||\n newNetworkSyncData.anim !== undefined\n ) {\n this.invalidateHitboxes();\n }\n if (newNetworkSyncData.color !== undefined) {\n this.setColor(newNetworkSyncData.color);\n }\n }\n\n /**\n * Initialize the extra parameters that could be set for an instance.\n * @param initialInstanceData The extra parameters\n */\n extraInitializationFromInitialInstance(initialInstanceData: InstanceData) {\n if (initialInstanceData.numberProperties) {\n for (\n let i = 0, len = initialInstanceData.numberProperties.length;\n i < len;\n ++i\n ) {\n const extraData = initialInstanceData.numberProperties[i];\n if (extraData.name === 'animation') {\n this.setAnimationIndex(extraData.value);\n }\n }\n }\n if (initialInstanceData.customSize) {\n this.setWidth(initialInstanceData.width);\n this.setHeight(initialInstanceData.height);\n }\n }\n\n /**\n * Update the current frame of the object according to the elapsed time on the scene.\n */\n update(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n //Playing the animation of all objects including the ones outside the screen can be\n //costly when the scene is big with a lot of animated objects. By default, we skip\n //updating the object if it is not visible.\n if (\n !this._updateIfNotVisible &&\n !this._renderer.getRendererObject().visible\n ) {\n return;\n }\n const hasFrameChanged = this._animator.step(this.getElapsedTime() / 1000);\n if (hasFrameChanged) {\n this._updateAnimationFrame();\n // TODO: Hitboxes may not need an update if every frames has the same ones.\n this.invalidateHitboxes();\n }\n this._renderer.ensureUpToDate();\n }\n\n /**\n * Ensure the sprite is ready to be displayed: the proper animation frame\n * is set and the renderer is up to date (position, angle, alpha, flip, blend mode...).\n */\n updatePreRender(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n this._renderer.ensureUpToDate();\n }\n\n /**\n * Update `this._animationFrame` according to the current animation/direction/frame values\n * (`this._currentAnimation`, `this._currentDirection`, `this._currentFrame`) and set\n * `this._animationFrameDirty` back to false.\n *\n * Trigger a call to the renderer to change the texture being shown (if the animation/direction/frame\n * is valid).\n * If invalid, `this._animationFrame` will be `null` after calling this function.\n */\n _updateAnimationFrame() {\n this._animationFrameDirty = false;\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame) {\n this._renderer.updateFrame(animationFrame);\n }\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n /**\n * Update the hit boxes for the object.\n * Fallback to the default implementation (rotated bounding box) if there is no custom\n * hitboxes defined for the current animation frame.\n */\n updateHitBoxes(): void {\n const animationFrame = this._animator.getCurrentFrame();\n if (!animationFrame) {\n return;\n }\n\n if (!animationFrame.hasCustomHitBoxes) {\n return super.updateHitBoxes();\n }\n\n //logger.log(\"Update for \"+this.name); //Uncomment to track updates\n //(and in particular be sure that unnecessary update are avoided).\n\n //Update the current hitboxes with the frame custom hit boxes\n //and apply transformations.\n for (let i = 0; i < animationFrame.customHitBoxes.length; ++i) {\n if (i >= this.hitBoxes.length) {\n this.hitBoxes.push(new gdjs.Polygon());\n }\n for (\n let j = 0;\n j < animationFrame.customHitBoxes[i].vertices.length;\n ++j\n ) {\n if (j >= this.hitBoxes[i].vertices.length) {\n this.hitBoxes[i].vertices.push([0, 0]);\n }\n this._transformToGlobal(\n animationFrame.customHitBoxes[i].vertices[j][0],\n animationFrame.customHitBoxes[i].vertices[j][1],\n this.hitBoxes[i].vertices[j]\n );\n }\n this.hitBoxes[i].vertices.length =\n animationFrame.customHitBoxes[i].vertices.length;\n }\n this.hitBoxes.length = animationFrame.customHitBoxes.length;\n }\n\n //Rotate and scale and flipping have already been applied to the point by _transformToGlobal.\n //Animations :\n /**\n * Change the animation being played.\n * @param newAnimation The index of the new animation to be played\n * @deprecated Use `setAnimationIndex` instead\n */\n setAnimation(newAnimation: integer): void {\n this.setAnimationIndex(newAnimation);\n }\n\n setAnimationIndex(newAnimation: integer): void {\n const hasAnimationChanged = this._animator.setAnimationIndex(\n newAnimation\n );\n if (hasAnimationChanged) {\n //TODO: This may be unnecessary.\n this._renderer.update();\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n setAnimationName(newAnimationName: string): void {\n const hasAnimationChanged = this._animator.setAnimationName(\n newAnimationName\n );\n if (hasAnimationChanged) {\n //TODO: This may be unnecessary.\n this._renderer.update();\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n /**\n * Get the index of the animation being played.\n * @return The index of the new animation being played\n * @deprecated Use `getAnimationIndex` instead\n */\n getAnimation(): integer {\n return this.getAnimationIndex();\n }\n\n getAnimationIndex(): integer {\n return this._animator.getAnimationIndex();\n }\n\n getAnimationName(): string {\n return this._animator.getAnimationName();\n }\n\n isCurrentAnimationName(name: string): boolean {\n return this.getAnimationName() === name;\n }\n\n /**\n * Change the angle (or direction index) of the object\n * @param The new angle (or direction index) to be applied\n */\n setDirectionOrAngle(newValue: float): void {\n const actualValue = this._animator.setDirectionOrAngle(\n this.angle,\n newValue\n );\n if (actualValue !== null) {\n this.angle = actualValue;\n //TODO: This may be unnecessary.\n this._renderer.update();\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n this._renderer.updateAngle();\n }\n }\n\n getDirectionOrAngle(): float {\n return this._animator.getDirectionOrAngle(this.angle);\n }\n\n /**\n * Change the current frame displayed by the animation\n * @param newFrame The index of the frame to be displayed\n */\n setAnimationFrame(newFrame: integer): void {\n const hasFrameChanged = this._animator.setAnimationFrameIndex(newFrame);\n if (hasFrameChanged) {\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n /**\n * Get the index of the current frame displayed by the animation\n * @return newFrame The index of the frame being displayed\n */\n getAnimationFrame(): integer {\n return this._animator.getAnimationFrameIndex();\n }\n\n getAnimationElapsedTime(): float {\n return this._animator.getAnimationElapsedTime();\n }\n\n setAnimationElapsedTime(time: float): void {\n const hasFrameChanged = this._animator.getAnimationElapsedTime();\n if (hasFrameChanged) {\n this._animationFrameDirty = true;\n this.invalidateHitboxes();\n }\n }\n\n getAnimationDuration(): float {\n return this._animator.getAnimationDuration();\n }\n\n getAnimationFrameCount(): integer {\n return this._animator.getAnimationFrameCount();\n }\n\n /**\n * @deprecated\n * Return true if animation has ended.\n * Prefer using `hasAnimationEnded2`. This method returns true as soon as\n * the animation enters the last frame, not at the end of the last frame.\n */\n hasAnimationEndedLegacy(): boolean {\n return this._animator.hasAnimationEndedLegacy();\n }\n\n /**\n * Return true if animation has ended.\n * The animation had ended if:\n * - it's not configured as a loop;\n * - the current frame is the last frame;\n * - the last frame has been displayed long enough.\n *\n * @deprecated Use `hasAnimationEnded` instead.\n */\n hasAnimationEnded2(): boolean {\n return this._animator.hasAnimationEnded();\n }\n\n hasAnimationEnded(): boolean {\n return this._animator.hasAnimationEnded();\n }\n\n /**\n * @deprecated Use `isAnimationPaused` instead.\n */\n animationPaused(): boolean {\n return this._animator.isAnimationPaused();\n }\n\n isAnimationPaused(): boolean {\n return this._animator.isAnimationPaused();\n }\n\n pauseAnimation(): void {\n this._animator.pauseAnimation();\n }\n\n /**\n * @deprecated Use `resumeAnimation` instead.\n */\n playAnimation(): void {\n this._animator.resumeAnimation();\n }\n\n resumeAnimation(): void {\n this._animator.resumeAnimation();\n }\n\n getAnimationSpeedScale(): float {\n return this._animator.getAnimationSpeedScale();\n }\n\n setAnimationSpeedScale(ratio: float): void {\n this._animator.setAnimationSpeedScale(ratio);\n }\n\n //Position :\n /**\n * Get the position on X axis on the scene of the given point.\n * @param name The point name\n * @return the position on X axis on the scene of the given point.\n */\n getPointX(name: string): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (name.length === 0 || animationFrame === null) {\n return this.getX();\n }\n const pt = animationFrame.getPoint(name);\n const pos = gdjs.staticArray(SpriteRuntimeObject.prototype.getPointX);\n this._transformToGlobal(pt.x, pt.y, pos);\n return pos[0];\n }\n\n /**\n * Get the position on Y axis on the scene of the given point.\n * @param name The point name\n * @return the position on Y axis on the scene of the given point.\n */\n getPointY(name: string): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (name.length === 0 || animationFrame === null) {\n return this.getY();\n }\n const pt = animationFrame.getPoint(name);\n const pos = gdjs.staticArray(SpriteRuntimeObject.prototype.getPointY);\n this._transformToGlobal(pt.x, pt.y, pos);\n return pos[1];\n }\n /**\n * Get the positions on X and Y axis on the scene of the given point.\n * @param name The point name\n * @return An array of the position on X and Y axis on the scene of the given point.\n */\n getPointPosition(name: string): [x: float, y: float] {\n const animationFrame = this._animator.getCurrentFrame();\n if (name.length === 0 || animationFrame === null) {\n return [this.getX(), this.getY()];\n }\n const pt = animationFrame.getPoint(name);\n const pos = gdjs.staticArray(SpriteRuntimeObject.prototype.getPointX);\n this._transformToGlobal(pt.x, pt.y, pos);\n return [pos[0], pos[1]];\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in world coordinates (as opposed to the object local coordinates).\n *\n * Beware: this._animationFrame and this._sprite must *not* be null!\n *\n * All transformations (flipping, scale, rotation) are supported.\n *\n * @param x The X position of the point, in object coordinates.\n * @param y The Y position of the point, in object coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in global coordinates).\n */\n private _transformToGlobal(x: float, y: float, result: float[]) {\n const animationFrame = this._animator.getCurrentFrame() as SpriteAnimationFrame<\n any\n >;\n let cx = animationFrame.center.x;\n let cy = animationFrame.center.y;\n\n //Flipping\n if (this._flippedX) {\n x = x + (cx - x) * 2;\n }\n if (this._flippedY) {\n y = y + (cy - y) * 2;\n }\n\n //Scale\n const absScaleX = Math.abs(this._scaleX * this._preScale);\n const absScaleY = Math.abs(this._scaleY * this._preScale);\n x *= absScaleX;\n y *= absScaleY;\n cx *= absScaleX;\n cy *= absScaleY;\n\n //Rotation\n const angleInRadians = (this.angle / 180) * Math.PI;\n const cosValue = Math.cos(\n // Only compute cos and sin once (10% faster than doing it twice)\n angleInRadians\n );\n const sinValue = Math.sin(angleInRadians);\n const xToCenterXDelta = x - cx;\n const yToCenterYDelta = y - cy;\n x = cx + cosValue * xToCenterXDelta - sinValue * yToCenterYDelta;\n y = cy + sinValue * xToCenterXDelta + cosValue * yToCenterYDelta;\n result.length = 2;\n result[0] = x + (this.x - animationFrame.origin.x * absScaleX);\n result[1] = y + (this.y - animationFrame.origin.y * absScaleY);\n }\n\n /**\n * Get the X position, on the scene, of the origin of the texture of the object.\n * @return the X position, on the scene, of the origin of the texture of the object.\n */\n getDrawableX(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return this.x;\n }\n const absScaleX = Math.abs(this._scaleX * this._preScale);\n if (!this._flippedX) {\n return this.x - animationFrame.origin.x * absScaleX;\n } else {\n return (\n this.x +\n (-animationFrame.origin.x -\n this._renderer.getUnscaledWidth() +\n 2 * animationFrame.center.x) *\n absScaleX\n );\n }\n }\n\n /**\n * Get the Y position, on the scene, of the origin of the texture of the object.\n * @return the Y position, on the scene, of the origin of the texture of the object.\n */\n getDrawableY(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return this.y;\n }\n const absScaleY = Math.abs(this._scaleY * this._preScale);\n if (!this._flippedY) {\n return this.y - animationFrame.origin.y * absScaleY;\n } else {\n return (\n this.y +\n (-animationFrame.origin.y -\n this._renderer.getUnscaledHeight() +\n 2 * animationFrame.center.y) *\n absScaleY\n );\n }\n }\n\n /**\n * Get the X position of the center of the object, relative to top-left of the texture of the object (`getDrawableX`).\n * @return X position of the center of the object, relative to `getDrawableX()`.\n */\n getCenterX(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return 0;\n }\n if (!this._flippedX) {\n //Just need to multiply by the scale as it is the center.\n return (\n animationFrame.center.x * Math.abs(this._scaleX * this._preScale)\n );\n } else {\n return (\n (this._renderer.getUnscaledWidth() - animationFrame.center.x) *\n Math.abs(this._scaleX * this._preScale)\n );\n }\n }\n\n /**\n * Get the Y position of the center of the object, relative to top-left of the texture of the object (`getDrawableY`).\n * @return Y position of the center of the object, relative to `getDrawableY()`.\n */\n getCenterY(): float {\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame === null) {\n return 0;\n }\n if (!this._flippedY) {\n //Just need to multiply by the scale as it is the center.\n return (\n animationFrame.center.y * Math.abs(this._scaleY * this._preScale)\n );\n } else {\n return (\n (this._renderer.getUnscaledHeight() - animationFrame.center.y) *\n Math.abs(this._scaleY * this._preScale)\n );\n }\n }\n\n /**\n * Set the X position of the (origin of the) object.\n * @param x The new X position.\n */\n setX(x: float): void {\n if (x === this.x) {\n return;\n }\n this.x = x;\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame !== null) {\n this.invalidateHitboxes();\n this._renderer.updateX();\n }\n }\n\n /**\n * Set the Y position of the (origin of the) object.\n * @param y The new Y position.\n */\n setY(y: float): void {\n if (y === this.y) {\n return;\n }\n this.y = y;\n const animationFrame = this._animator.getCurrentFrame();\n if (animationFrame !== null) {\n this.invalidateHitboxes();\n this._renderer.updateY();\n }\n }\n\n /**\n * Set the angle of the object.\n * @param angle The new angle, in degrees.\n */\n setAngle(angle: float): void {\n const actualValue = this._animator.setAngle(this.angle, angle);\n if (actualValue !== null) {\n this.angle = actualValue;\n this.invalidateHitboxes();\n this._renderer.updateAngle();\n }\n }\n\n /**\n * Get the angle of the object.\n * @return The angle, in degrees.\n */\n getAngle(): float {\n return this._animator.getAngle(this.angle);\n }\n\n //Visibility and display :\n setBlendMode(newMode): void {\n if (this._blendMode === newMode) {\n return;\n }\n this._blendMode = newMode;\n this._renderer.update();\n }\n\n getBlendMode() {\n return this._blendMode;\n }\n\n setOpacity(opacity: float): void {\n if (opacity < 0) {\n opacity = 0;\n }\n if (opacity > 255) {\n opacity = 255;\n }\n this.opacity = opacity;\n this._renderer.updateOpacity();\n }\n\n getOpacity(): float {\n return this.opacity;\n }\n\n /**\n * Hide (or show) the object\n * @param enable true to hide the object, false to show it again.\n */\n hide(enable: boolean): void {\n if (enable === undefined) {\n enable = true;\n }\n this.hidden = enable;\n this._renderer.updateVisibility();\n }\n\n /**\n * Change the tint of the sprite object.\n *\n * @param rgbColor The color, in RGB format (\"128;200;255\").\n */\n setColor(rgbColor: string): void {\n this._renderer.setColor(rgbColor);\n }\n\n /**\n * Get the tint of the sprite object.\n *\n * @returns The color, in RGB format (\"128;200;255\").\n */\n getColor(): string {\n return this._renderer.getColor();\n }\n\n flipX(enable: boolean) {\n if (enable !== this._flippedX) {\n this._scaleX *= -1;\n this._flippedX = enable;\n this.invalidateHitboxes();\n this._renderer.update();\n }\n }\n\n flipY(enable: boolean) {\n if (enable !== this._flippedY) {\n this._scaleY *= -1;\n this._flippedY = enable;\n this.invalidateHitboxes();\n this._renderer.update();\n }\n }\n\n isFlippedX(): boolean {\n return this._flippedX;\n }\n\n isFlippedY(): boolean {\n return this._flippedY;\n }\n\n //Scale and size :\n /**\n * Get the width of the object.\n *\n * @return The width of the object, in pixels.\n */\n getWidth(): float {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n return this._renderer.getWidth();\n }\n\n /**\n * Get the height of the object.\n *\n * @return The height of the object, in pixels.\n */\n getHeight(): float {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n return this._renderer.getHeight();\n }\n\n setWidth(newWidth: float): void {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n const unscaledWidth = this._renderer.getUnscaledWidth();\n if (unscaledWidth !== 0) {\n this.setScaleX(newWidth / unscaledWidth);\n }\n }\n\n setHeight(newHeight: float): void {\n if (this._animationFrameDirty) {\n this._updateAnimationFrame();\n }\n const unscaledHeight = this._renderer.getUnscaledHeight();\n if (unscaledHeight !== 0) {\n this.setScaleY(newHeight / unscaledHeight);\n }\n }\n\n setSize(newWidth: float, newHeight: float): void {\n this.setWidth(newWidth);\n this.setHeight(newHeight);\n }\n\n /**\n * Change the scale on X and Y axis of the object.\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScale(newScale: float): void {\n if (newScale < 0) {\n newScale = 0;\n }\n if (\n newScale === Math.abs(this._scaleX) &&\n newScale === Math.abs(this._scaleY)\n ) {\n return;\n }\n this._scaleX = newScale * (this._flippedX ? -1 : 1);\n this._scaleY = newScale * (this._flippedY ? -1 : 1);\n this._renderer.update();\n this.invalidateHitboxes();\n }\n\n /**\n * Change the scale on X axis of the object (changing its width).\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScaleX(newScale: float): void {\n if (newScale < 0) {\n newScale = 0;\n }\n if (newScale === Math.abs(this._scaleX)) {\n return;\n }\n this._scaleX = newScale * (this._flippedX ? -1 : 1);\n this._renderer.update();\n this.invalidateHitboxes();\n }\n\n /**\n * Change the scale on Y axis of the object (changing its height).\n *\n * @param newScale The new scale (must be greater than 0).\n */\n setScaleY(newScale: float): void {\n if (newScale < 0) {\n newScale = 0;\n }\n if (newScale === Math.abs(this._scaleY)) {\n return;\n }\n this._scaleY = newScale * (this._flippedY ? -1 : 1);\n this._renderer.update();\n this.invalidateHitboxes();\n }\n\n /**\n * Get the scale of the object (or the arithmetic mean of the X and Y scale in case they are different).\n *\n * @return the scale of the object (or the arithmetic mean of the X and Y scale in case they are different).\n * @deprecated Use `getScale` instead.\n */\n getScaleMean(): float {\n return (Math.abs(this._scaleX) + Math.abs(this._scaleY)) / 2.0;\n }\n\n /**\n * Get the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n *\n * @return the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n */\n getScale(): float {\n const scaleX = Math.abs(this._scaleX);\n const scaleY = Math.abs(this._scaleY);\n return scaleX === scaleY ? scaleX : Math.sqrt(scaleX * scaleY);\n }\n\n /**\n * Get the scale of the object on Y axis.\n *\n * @return the scale of the object on Y axis\n */\n getScaleY(): float {\n return Math.abs(this._scaleY);\n }\n\n /**\n * Get the scale of the object on X axis.\n *\n * @return the scale of the object on X axis\n */\n getScaleX(): float {\n return Math.abs(this._scaleX);\n }\n\n //Other :\n /**\n * @param obj The target object\n * @param scene The scene containing the object\n * @deprecated\n */\n turnTowardObject(obj: gdjs.RuntimeObject | null, scene: gdjs.RuntimeScene) {\n if (obj === null) {\n return;\n }\n this.rotateTowardPosition(\n obj.getDrawableX() + obj.getCenterX(),\n obj.getDrawableY() + obj.getCenterY(),\n 0,\n scene\n );\n }\n }\n gdjs.registerObject(\n 'Sprite',\n //Notify gdjs of the object existence.\n gdjs.SpriteRuntimeObject\n );\n\n //Others initialization and internal state management :\n SpriteRuntimeObject.supportsReinitialization = true;\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CA6BS,eACG,GAAK,aAMS,CAkBtB,YACE,EACA,EACA,CACA,MAAM,EAAmB,GApB3B,aAAiB,EACjB,aAAiB,EACjB,gBAAsB,EACtB,eAAqB,GACrB,eAAqB,GACrB,aAAiB,IAEjB,eAAmB,EAGnB,0BAAuB,GAWrB,KAAK,oBAAsB,CAAC,CAAC,EAAiB,mBAC9C,KAAK,UAAY,EAAiB,UAAY,EAC9C,KAAK,UAAY,GAAI,GAAK,4BACxB,KACA,GAEF,KAAK,UAAY,GAAI,GAAK,eACxB,EAAiB,WACjB,EAAK,4BAA4B,gCAC/B,EAAkB,UAAU,oBAGhC,KAAK,wBAGL,KAAK,YAGP,aAAa,EAAoC,CAC/C,MAAM,aAAa,GACnB,KAAM,GAAoB,KAAK,uBAC/B,KAAK,UAAU,aAAa,EAAiB,YAC7C,KAAK,QAAU,EACf,KAAK,QAAU,EACf,KAAK,WAAa,EAClB,KAAK,UAAY,GACjB,KAAK,UAAY,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AiB,EAAI,aACzB,EAAI,eAAiB,EAAI,aACzB,EACA,IAr5BC,EAAM,sBAy5Bb,EAAK,eACH,SAEA,EAAK,qBAIP,EAAoB,yBAA2B,KA77BvC",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -39,7 +39,10 @@ declare type ObjectData = {
|
|
|
39
39
|
effects: Array<EffectData>;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
declare type GetNetworkSyncDataOptions = {
|
|
42
|
+
declare type GetNetworkSyncDataOptions = {
|
|
43
|
+
playerNumber?: number;
|
|
44
|
+
isHost?: boolean;
|
|
45
|
+
};
|
|
43
46
|
|
|
44
47
|
/** Object containing basic properties for all objects synchronizing over the network. */
|
|
45
48
|
declare type BasicObjectNetworkSyncData = {
|
|
@@ -149,7 +152,14 @@ declare interface GdVersionData {
|
|
|
149
152
|
revision: number;
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
declare interface
|
|
155
|
+
declare interface InstanceContainerData {
|
|
156
|
+
variables: RootVariableData[];
|
|
157
|
+
instances: InstanceData[];
|
|
158
|
+
objects: ObjectData[];
|
|
159
|
+
layers: LayerData[];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
declare interface LayoutData extends InstanceContainerData {
|
|
153
163
|
r: number;
|
|
154
164
|
v: number;
|
|
155
165
|
b: number;
|
|
@@ -157,10 +167,6 @@ declare interface LayoutData {
|
|
|
157
167
|
name: string;
|
|
158
168
|
stopSoundsOnStartup: boolean;
|
|
159
169
|
title: string;
|
|
160
|
-
variables: RootVariableData[];
|
|
161
|
-
instances: InstanceData[];
|
|
162
|
-
objects: ObjectData[];
|
|
163
|
-
layers: LayerData[];
|
|
164
170
|
behaviorsSharedData: BehaviorSharedData[];
|
|
165
171
|
usedResources: ResourceReference[];
|
|
166
172
|
}
|
|
@@ -200,9 +206,25 @@ declare interface SceneAndExtensionsData {
|
|
|
200
206
|
usedExtensionsWithVariablesData: EventsFunctionsExtensionData[];
|
|
201
207
|
}
|
|
202
208
|
|
|
203
|
-
declare interface EventsBasedObjectData {
|
|
209
|
+
declare interface EventsBasedObjectData extends InstanceContainerData {
|
|
204
210
|
name: string;
|
|
205
|
-
|
|
211
|
+
isInnerAreaFollowingParentSize: boolean;
|
|
212
|
+
// The flat representation of defaultSize.
|
|
213
|
+
areaMinX: float;
|
|
214
|
+
areaMinY: float;
|
|
215
|
+
areaMinZ: float;
|
|
216
|
+
areaMaxX: float;
|
|
217
|
+
areaMaxY: float;
|
|
218
|
+
areaMaxZ: float;
|
|
219
|
+
/**
|
|
220
|
+
* A value shared by every object instances.
|
|
221
|
+
*
|
|
222
|
+
* @see gdjs.CustomRuntimeObjectInstanceContainer._originalInnerArea
|
|
223
|
+
**/
|
|
224
|
+
_initialInnerArea: {
|
|
225
|
+
min: [float, float, float];
|
|
226
|
+
max: [float, float, float];
|
|
227
|
+
} | null;
|
|
206
228
|
}
|
|
207
229
|
|
|
208
230
|
declare interface BehaviorSharedData {
|
|
@@ -212,6 +234,7 @@ declare interface BehaviorSharedData {
|
|
|
212
234
|
|
|
213
235
|
declare interface ExternalLayoutData {
|
|
214
236
|
name: string;
|
|
237
|
+
associatedLayout: string;
|
|
215
238
|
instances: InstanceData[];
|
|
216
239
|
}
|
|
217
240
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(o){const u=class{constructor(r){this._variablesArray=[];this._variables=new Hashtable,r!==void 0&&this.initFrom(r)}initFrom(r,e){e===void 0&&(e=!1),e||(u._deletedVars=u._deletedVars||[],this._variables.keys(u._deletedVars));const
|
|
1
|
+
var gdjs;(function(o){const u=class{constructor(r){this._variablesArray=[];this._variables=new Hashtable,r!==void 0&&this.initFrom(r)}initFrom(r,e){e===void 0&&(e=!1),e||(u._deletedVars=u._deletedVars||[],this._variables.keys(u._deletedVars));const a=this;let i=0;for(let t=0;t<r.length;++t){const n=r[t];if(!n.name)continue;const l=a.get(n.name);if(l.reinitialize(n),!e){i<a._variablesArray.length?a._variablesArray[i]=l:a._variablesArray.push(l),++i;const s=u._deletedVars.indexOf(n.name);s!==-1&&(u._deletedVars[s]=void 0)}}if(!e){this._variablesArray.length=i;for(let t=0,n=u._deletedVars.length;t<n;++t){const l=u._deletedVars[t];l!==void 0&&this._variables.get(l).setUndefinedInContainer()}}}rebuildIndexFrom(r){this._variablesArray.length=0;for(const e of r)if(e.name){const a=this._variables.get(e.name);this._variablesArray.push(a)}}_declare(r,e){this._variables.put(r,e),this._variablesArray.push(e)}add(r,e){const a=this._variables.get(r);if(this._variables.put(r,e),a){const i=this._variablesArray.indexOf(a);i!==-1&&(this._variablesArray[i]=e)}}remove(r){const e=this._variables.get(r);e&&e.setUndefinedInContainer()}get(r){let e=this._variables.get(r);return e?e.isUndefinedInContainer()&&e.reinitialize():(e=new o.Variable,this._variables.put(r,e)),e}getFromIndex(r){if(r>=this._variablesArray.length){let e=new o.Variable;return this._variables.put("",e),e}else{let e=this._variablesArray[r];return e.isUndefinedInContainer()&&e.reinitialize(),e}}has(r){const e=this._variables.get(r);return!!e&&!e.isUndefinedInContainer()}hasVariable(r){const e=this._variablesArray.find(a=>a===r);return!!e&&!e.isUndefinedInContainer()}getVariableNameInContainerByLoopingThroughAllVariables(r){const e=this._variables.items;for(const a in e)if(e.hasOwnProperty(a)&&e[a]===r)return a;return null}getNetworkSyncData(r){const e=r.playerNumber,a=r.isHost,i=[],t=[];return this._variables.keys(t),t.forEach(n=>{const l=this._variables.get(n),s=l.getPlayerOwnership();if(l.isUndefinedInContainer()||s===null||e!==void 0&&s===0&&!a||s!==0&&e!==s)return;const c=l.getType(),b=c==="structure"||c==="array"?"":l.getValue();i.push({name:n,value:b,type:c,children:this.getStructureNetworkSyncData(l),owner:s})}),i}getStructureNetworkSyncData(r){if(r.getType()==="array"){const e=[];return r.getAllChildrenArray().forEach(a=>{const i=a.getType(),t=i==="structure"||i==="array"?"":a.getValue(),n=a.getPlayerOwnership();a.isUndefinedInContainer()||n===null||e.push({name:"",value:t,type:i,children:this.getStructureNetworkSyncData(a),owner:n})}),e}if(r.getType()==="structure"){const e=r.getAllChildren();if(!e)return;const a=[];return Object.entries(e).forEach(([i,t])=>{const n=t.getType(),l=n==="structure"||n==="array"?"":t.getValue(),s=t.getPlayerOwnership();t.isUndefinedInContainer()||s===null||a.push({name:i,value:l,type:n,children:this.getStructureNetworkSyncData(t),owner:s})}),a}}updateFromNetworkSyncData(r){const e=this;for(let a=0;a<r.length;++a){const i=r[a],t=e._getVariableDataFromNetworkSyncData(i),n=t.name;if(!n)continue;const l=e.get(n),s=i.owner,c=o.multiplayer.getCurrentPlayerNumber(),b=l.getPlayerOwnership();if(c===b){console.info(`Variable ${n} is owned by us ${o.multiplayer.playerNumber}, ignoring update message from ${s}.`);return}s!==b&&(console.info(`Variable ${n} is owned by ${b} on our game, changing ownership to ${s} as part of the update event.`),l.setPlayerOwnership(s)),l.reinitialize(t)}}_getVariableDataFromNetworkSyncData(r){return{name:r.name,value:r.value,type:r.type,children:r.children?r.children.map(e=>this._getVariableDataFromNetworkSyncData(e)):void 0}}};let d=u;d._deletedVars=[],d.badVariablesContainer={_variables:new Hashtable,_variablesArray:[],has:function(){return!1},getFromIndex:function(){return u.badVariable},get:function(){return u.badVariable},remove:function(){},add:function(){},_declare:function(){},initFrom:function(){},getNetworkSyncData:function(){return[]},updateFromNetworkSyncData:function(){},getStructureNetworkSyncData:function(){},_getVariableDataFromNetworkSyncData:function(){return{}},hasVariable:function(){return!1},getVariableNameInContainerByLoopingThroughAllVariables:function(){return""},rebuildIndexFrom:function(){}},d.badVariable={_type:"number",_bool:!1,_children:{},_childrenArray:[],_str:"",_undefinedInContainer:!0,_value:0,_playerNumber:0,fromJSON:()=>o.VariablesContainer.badVariable,toJSObject:()=>0,fromJSObject:()=>o.VariablesContainer.badVariable,reinitialize:()=>{},addChild:()=>o.VariablesContainer.badVariable,castTo:()=>{},clearChildren:()=>{},clone:()=>o.VariablesContainer.badVariable,getChildrenCount:()=>0,replaceChildren:()=>{},replaceChildrenArray:()=>{},getType:function(){return"number"},isPrimitive:function(){return!0},setValue:()=>{},toggle:()=>{},getValue:()=>0,getChild:()=>o.VariablesContainer.badVariable,getChildAt:()=>o.VariablesContainer.badVariable,getChildNamed:()=>o.VariablesContainer.badVariable,hasChild:function(){return!1},isStructure:function(){return!1},isNumber:function(){return!0},removeChild:function(){},setNumber:function(){},setString:function(){},setBoolean:function(){},getAsString:function(){return"0"},getAsNumber:function(){return 0},getAsNumberOrString:function(){return 0},getAsBoolean:function(){return!1},getAllChildren:function(){return{}},getAllChildrenArray:function(){return[]},pushVariableCopy:()=>{},_pushVariable:()=>{},pushValue:()=>{},removeAtIndex:function(){},add:function(){},sub:function(){},mul:function(){},div:function(){},concatenate:function(){},concatenateString:function(){},setUndefinedInContainer:function(){},isUndefinedInContainer:function(){return!0},getPlayerOwnership:function(){return 0},setPlayerOwnership:function(){},disableSynchronization:function(){}},o.VariablesContainer=d})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=variablescontainer.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/variablescontainer.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 * VariablesContainer stores variables, usually for a a RuntimeGame, a RuntimeScene\n * or a RuntimeObject.\n */\n export class VariablesContainer {\n _variables: Hashtable<gdjs.Variable>;\n _variablesArray: gdjs.Variable[] = [];\n\n /**\n * @param [initialVariablesData] Optional array containing representations of the base variables.\n */\n constructor(initialVariablesData?: VariableData[]) {\n this._variables = new Hashtable();\n\n if (initialVariablesData !== undefined) {\n this.initFrom(initialVariablesData);\n }\n }\n\n /**\n * Initialize variables from a container data.<br>\n * If `keepOldVariables` is set to false (by default), all already existing variables will be\n * erased, but the new variables will be accessible thanks to getFromIndex. <br>\n * if `keepOldVariables` is set to true, already existing variables won't be erased and will be\n * still accessible thanks to getFromIndex.\n *\n * @param data The array containing data used to initialize variables.\n * @param [keepOldVariables] If set to true, already existing variables won't be erased.\n */\n initFrom(data: VariableData[], keepOldVariables?: Boolean) {\n if (keepOldVariables === undefined) {\n keepOldVariables = false;\n }\n if (!keepOldVariables) {\n VariablesContainer._deletedVars = VariablesContainer._deletedVars || [];\n // @ts-ignore\n this._variables.keys(VariablesContainer._deletedVars);\n }\n const that = this;\n let i = 0;\n for (let j = 0; j < data.length; ++j) {\n const varData = data[j];\n if (!varData.name) continue;\n\n //Get the variable:\n const variable = that.get(varData.name);\n variable.reinitialize(varData);\n if (!keepOldVariables) {\n //Register the variable in the extra array to ensure a fast lookup using getFromIndex.\n if (i < that._variablesArray.length) {\n that._variablesArray[i] = variable;\n } else {\n that._variablesArray.push(variable);\n }\n ++i;\n\n //Remove the variable from the list of variables to be deleted.\n const idx = VariablesContainer._deletedVars.indexOf(varData.name);\n if (idx !== -1) {\n VariablesContainer._deletedVars[idx] = undefined;\n }\n }\n }\n if (!keepOldVariables) {\n this._variablesArray.length = i;\n\n //If we do not want to keep the already existing variables,\n //remove all the variables not assigned above.\n //(Here, remove means flag the variable as not existing, to avoid garbage creation ).\n for (\n let i = 0, len = VariablesContainer._deletedVars.length;\n i < len;\n ++i\n ) {\n const variableName = VariablesContainer._deletedVars[i];\n if (variableName !== undefined) {\n this._variables.get(variableName).setUndefinedInContainer();\n }\n }\n }\n }\n\n /**\n * Declare a new variable.\n * This should only be used by generated code.\n *\n * @param name Variable name\n * @param newVariable The variable to be declared\n */\n _declare(name: string, newVariable: gdjs.Variable): void {\n this._variables.put(name, newVariable);\n this._variablesArray.push(newVariable);\n }\n\n /**\n * Add a new variable.\n * This can be costly, don't use in performance sensitive paths.\n *\n * @param name Variable name\n * @param newVariable The variable to be added\n */\n add(name: string, newVariable: gdjs.Variable) {\n const oldVariable = this._variables.get(name);\n\n // Variable is either already defined, considered as undefined\n // in the container or missing in the container.\n // Whatever the case, replace it by the new.\n this._variables.put(name, newVariable);\n if (oldVariable) {\n // If variable is indexed, ensure that the variable as the index\n // is replaced too. This can be costly (indexOf) but we assume `add` is not\n // used in performance sensitive code.\n const variableIndex = this._variablesArray.indexOf(oldVariable);\n if (variableIndex !== -1) {\n this._variablesArray[variableIndex] = newVariable;\n }\n }\n }\n\n /**\n * Remove a variable.\n * (the variable is not really removed from the container to avoid creating garbage, but marked as undefined)\n * @param name Variable to be removed\n */\n remove(name: string) {\n const variable = this._variables.get(name);\n if (variable) {\n variable.setUndefinedInContainer();\n }\n }\n\n /**\n * Get a variable.\n * @param name The variable's name\n * @return The specified variable. If not found, an empty variable is added to the container.\n */\n get(name: string): gdjs.Variable {\n let variable = this._variables.get(name);\n if (!variable) {\n //Add automatically non-existing variables.\n variable = new gdjs.Variable();\n this._variables.put(name, variable);\n } else {\n if (\n //Reuse variables removed before.\n variable.isUndefinedInContainer()\n ) {\n variable.reinitialize();\n }\n }\n return variable;\n }\n\n /**\n * Get a variable using its index. If you're unsure about how to use this method, prefer to use `get`.\n * The index of a variable is its index in the data passed to initFrom.\n *\n * This method is generally used by events generated code to increase lookup speed for variables.\n *\n * @param id The variable index\n * @return The specified variable. If not found, an empty variable is added to the container, but it\n * should not happen.\n */\n getFromIndex(id: number): gdjs.Variable {\n if (id >= this._variablesArray.length) {\n //Add automatically non-existing variables.\n let variable = new gdjs.Variable();\n this._variables.put('', variable);\n return variable;\n } else {\n let variable: gdjs.Variable = this._variablesArray[id];\n //Reuse variables removed before.\n if (variable.isUndefinedInContainer()) {\n variable.reinitialize();\n }\n return variable;\n }\n }\n\n /**\n * Check if a variable exists in the container.\n * @param name The variable's name\n * @return true if the variable exists.\n */\n has(name: string): boolean {\n const variable = this._variables.get(name);\n return !!variable && !variable.isUndefinedInContainer();\n }\n\n /**\n * Check if a variable exists in the container.\n * @param variable The variable\n * @return true if the variable exists.\n */\n hasVariable(variable: gdjs.Variable): boolean {\n const foundVariable = this._variablesArray.find((v) => v === variable);\n return !!foundVariable && !foundVariable.isUndefinedInContainer();\n }\n\n getVariableNameInContainerByLoopingThroughAllVariables(\n variable: gdjs.Variable\n ): string | null {\n const variableItems = this._variables.items;\n for (const variableName in variableItems) {\n if (variableItems.hasOwnProperty(variableName)) {\n if (variableItems[variableName] === variable) {\n return variableName;\n }\n }\n }\n\n return null;\n }\n\n static _deletedVars: Array<string | undefined> = [];\n\n getNetworkSyncData(\n syncOptions: GetNetworkSyncDataOptions\n ): VariableNetworkSyncData[] {\n const syncedPlayerNumber = syncOptions.playerNumber;\n const networkSyncData: VariableNetworkSyncData[] = [];\n const variableNames = [];\n this._variables.keys(variableNames);\n variableNames.forEach((variableName) => {\n const variable = this._variables.get(variableName);\n const variableOwner = variable.getPlayerOwnership();\n if (\n // Variable undefined.\n variable.isUndefinedInContainer() ||\n // Variable marked as not to be synchronized.\n variableOwner === null ||\n // Getting sync data for a specific player:\n (syncedPlayerNumber !== undefined &&\n // Owned by host but we are not player 1.\n variableOwner === 0 &&\n syncedPlayerNumber !== 1) ||\n // Owned by a player but we are not this player.\n (variableOwner !== 0 && syncedPlayerNumber !== variableOwner)\n ) {\n // In those cases, the variable should not be synchronized.\n return;\n }\n\n const variableType = variable.getType();\n const variableValue =\n variableType === 'structure' || variableType === 'array'\n ? ''\n : variable.getValue();\n\n networkSyncData.push({\n name: variableName,\n value: variableValue,\n type: variableType,\n children: this.getStructureNetworkSyncData(variable),\n owner: variableOwner,\n });\n });\n\n return networkSyncData;\n }\n\n // Structure variables can contain other variables, so we need to recursively\n // get the sync data for each child variable.\n getStructureNetworkSyncData(\n variable: gdjs.Variable\n ): VariableNetworkSyncData[] | undefined {\n if (variable.getType() === 'array') {\n const allVariableNetworkSyncData: VariableNetworkSyncData[] = [];\n variable.getAllChildrenArray().forEach((childVariable) => {\n const childVariableType = childVariable.getType();\n const childVariableValue =\n childVariableType === 'structure' || childVariableType === 'array'\n ? ''\n : childVariable.getValue();\n\n const childVariableOwner = childVariable.getPlayerOwnership();\n if (\n // Variable undefined.\n childVariable.isUndefinedInContainer() ||\n // Variable marked as not to be synchronized.\n childVariableOwner === null\n ) {\n // In those cases, the variable should not be synchronized.\n return;\n }\n\n allVariableNetworkSyncData.push({\n name: '',\n value: childVariableValue,\n type: childVariableType,\n children: this.getStructureNetworkSyncData(childVariable),\n owner: childVariableOwner,\n });\n });\n\n return allVariableNetworkSyncData;\n }\n\n if (variable.getType() === 'structure') {\n const variableChildren = variable.getAllChildren();\n if (!variableChildren) return undefined;\n const allVariableNetworkSyncData: VariableNetworkSyncData[] = [];\n\n Object.entries(variableChildren).forEach(\n ([childVariableName, childVariable]) => {\n const childVariableType = childVariable.getType();\n const childVariableValue =\n childVariableType === 'structure' || childVariableType === 'array'\n ? ''\n : childVariable.getValue();\n const childVariableOwner = childVariable.getPlayerOwnership();\n if (\n // Variable undefined.\n childVariable.isUndefinedInContainer() ||\n // Variable marked as not to be synchronized.\n childVariableOwner === null\n ) {\n // In those cases, the variable should not be synchronized.\n return;\n }\n\n allVariableNetworkSyncData.push({\n name: childVariableName,\n value: childVariableValue,\n type: childVariableType,\n children: this.getStructureNetworkSyncData(childVariable),\n owner: childVariableOwner,\n });\n }\n );\n\n return allVariableNetworkSyncData;\n }\n\n return undefined;\n }\n\n updateFromNetworkSyncData(networkSyncData: VariableNetworkSyncData[]) {\n const that = this;\n for (let j = 0; j < networkSyncData.length; ++j) {\n const variableSyncData = networkSyncData[j];\n const variableData = that._getVariableDataFromNetworkSyncData(\n variableSyncData\n );\n const variableName = variableData.name;\n if (!variableName) continue;\n\n const variable = that.get(variableName);\n\n // // If we receive an update for this variable for a different owner than the one we know about,\n // then 2 cases:\n // - If we are the owner of the variable, then ignore the message, we assume it's a late update message or a wrong one,\n // we are confident that we own this variable. (it may be reverted if we don't receive an acknowledgment in time)\n // - If we are not the owner of the variable, then assume that we missed the ownership change message, so update the variable's\n // ownership and then update the variable.\n const syncedVariableOwner = variableSyncData.owner;\n const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();\n const currentVariableOwner = variable.getPlayerOwnership();\n if (currentPlayerNumber === currentVariableOwner) {\n console.info(\n `Variable ${variableName} is owned by us ${gdjs.multiplayer.playerNumber}, ignoring update message from ${syncedVariableOwner}.`\n );\n return;\n }\n\n if (syncedVariableOwner !== currentVariableOwner) {\n console.info(\n `Variable ${variableName} is owned by ${currentVariableOwner} on our game, changing ownership to ${syncedVariableOwner} as part of the update event.`\n );\n variable.setPlayerOwnership(syncedVariableOwner);\n }\n\n variable.reinitialize(variableData);\n }\n }\n\n _getVariableDataFromNetworkSyncData(\n syncData: VariableNetworkSyncData\n ): VariableData {\n return {\n name: syncData.name,\n value: syncData.value,\n type: syncData.type,\n children: syncData.children\n ? syncData.children.map((childSyncData) =>\n this._getVariableDataFromNetworkSyncData(childSyncData)\n )\n : undefined,\n };\n }\n\n /**\n * \"Bad\" variable container, used by events when no other valid container can be found.\n * This container has no state and always returns the bad variable ( see VariablesContainer.badVariable ).\n * @static\n */\n static badVariablesContainer: VariablesContainer = {\n _variables: new Hashtable(),\n _variablesArray: [],\n has: function () {\n return false;\n },\n getFromIndex: function () {\n return VariablesContainer.badVariable;\n },\n get: function () {\n return VariablesContainer.badVariable;\n },\n remove: function () {\n return;\n },\n add: function () {\n return;\n },\n _declare: function () {\n return;\n },\n initFrom: function () {\n return;\n },\n getNetworkSyncData: function () {\n return [];\n },\n updateFromNetworkSyncData: function () {\n return;\n },\n getStructureNetworkSyncData: function () {\n return undefined;\n },\n _getVariableDataFromNetworkSyncData: function () {\n return {};\n },\n hasVariable: function () {\n return false;\n },\n getVariableNameInContainerByLoopingThroughAllVariables: function () {\n return '';\n },\n };\n\n /**\n * \"Bad\" variable, used by events when no other valid variable can be found.\n * This variable has no state and always return 0 or the empty string.\n * @static\n */\n static badVariable: Variable = {\n _type: 'number',\n _bool: false,\n _children: {},\n _childrenArray: [],\n _str: '',\n _undefinedInContainer: true,\n _value: 0,\n _playerNumber: 0,\n fromJSON: () => gdjs.VariablesContainer.badVariable,\n toJSObject: () => 0,\n fromJSObject: () => gdjs.VariablesContainer.badVariable,\n reinitialize: () => {},\n addChild: () => gdjs.VariablesContainer.badVariable,\n castTo: () => {},\n clearChildren: () => {},\n clone: () => gdjs.VariablesContainer.badVariable,\n getChildrenCount: () => 0,\n replaceChildren: () => {},\n replaceChildrenArray: () => {},\n getType: function () {\n return 'number';\n },\n isPrimitive: function () {\n return true;\n },\n setValue: () => {},\n toggle: () => {},\n getValue: () => 0,\n getChild: () => gdjs.VariablesContainer.badVariable,\n getChildAt: () => gdjs.VariablesContainer.badVariable,\n getChildNamed: () => gdjs.VariablesContainer.badVariable,\n hasChild: function () {\n return false;\n },\n isStructure: function () {\n return false;\n },\n isNumber: function () {\n return true;\n },\n removeChild: function () {\n return;\n },\n setNumber: function () {\n return;\n },\n setString: function () {\n return;\n },\n setBoolean: function () {\n return;\n },\n getAsString: function () {\n return '0';\n },\n getAsNumber: function () {\n return 0;\n },\n getAsNumberOrString: function () {\n return 0;\n },\n getAsBoolean: function () {\n return false;\n },\n getAllChildren: function () {\n return {};\n },\n getAllChildrenArray: function () {\n return [];\n },\n pushVariableCopy: () => {},\n _pushVariable: () => {},\n pushValue: () => {},\n removeAtIndex: function () {\n return;\n },\n add: function () {\n return;\n },\n sub: function () {\n return;\n },\n mul: function () {\n return;\n },\n div: function () {\n return;\n },\n concatenate: function () {\n return;\n },\n concatenateString: function () {\n return;\n },\n setUndefinedInContainer: function () {\n return;\n },\n isUndefinedInContainer: function () {\n return true;\n },\n getPlayerOwnership: function () {\n return 0;\n },\n setPlayerOwnership: function () {\n return;\n },\n disableSynchronization: function () {\n return;\n },\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAKS,aAAyB,CAO9B,YAAY,EAAuC,CALnD,qBAAmC,GAMjC,KAAK,WAAa,GAAI,WAElB,IAAyB,QAC3B,KAAK,SAAS,GAclB,SAAS,EAAsB,EAA4B,CACzD,AAAI,IAAqB,QACvB,GAAmB,IAEhB,GACH,GAAmB,aAAe,EAAmB,cAAgB,GAErE,KAAK,WAAW,KAAK,EAAmB,eAE1C,KAAM,GAAO,KACb,GAAI,GAAI,EACR,OAAS,GAAI,EAAG,EAAI,EAAK,OAAQ,EAAE,EAAG,CACpC,KAAM,GAAU,EAAK,GACrB,GAAI,CAAC,EAAQ,KAAM,SAGnB,KAAM,GAAW,EAAK,IAAI,EAAQ,MAElC,GADA,EAAS,aAAa,GAClB,CAAC,EAAkB,CAErB,AAAI,EAAI,EAAK,gBAAgB,OAC3B,EAAK,gBAAgB,GAAK,EAE1B,EAAK,gBAAgB,KAAK,GAE5B,EAAE,EAGF,KAAM,GAAM,EAAmB,aAAa,QAAQ,EAAQ,MAC5D,AAAI,IAAQ,IACV,GAAmB,aAAa,GAAO,SAI7C,GAAI,CAAC,EAAkB,CACrB,KAAK,gBAAgB,OAAS,EAK9B,OACM,GAAI,EAAG,EAAM,EAAmB,aAAa,OACjD,EAAI,EACJ,EAAE,EACF,CACA,KAAM,GAAe,EAAmB,aAAa,GACrD,AAAI,IAAiB,QACnB,KAAK,WAAW,IAAI,GAAc,
|
|
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 * VariablesContainer stores variables, usually for a a RuntimeGame, a RuntimeScene\n * or a RuntimeObject.\n */\n export class VariablesContainer {\n _variables: Hashtable<gdjs.Variable>;\n _variablesArray: gdjs.Variable[] = [];\n\n /**\n * @param [initialVariablesData] Optional array containing representations of the base variables.\n */\n constructor(initialVariablesData?: VariableData[]) {\n this._variables = new Hashtable();\n\n if (initialVariablesData !== undefined) {\n this.initFrom(initialVariablesData);\n }\n }\n\n /**\n * Initialize variables from a container data.<br>\n * If `keepOldVariables` is set to false (by default), all already existing variables will be\n * erased, but the new variables will be accessible thanks to getFromIndex. <br>\n * if `keepOldVariables` is set to true, already existing variables won't be erased and will be\n * still accessible thanks to getFromIndex.\n *\n * @param data The array containing data used to initialize variables.\n * @param [keepOldVariables] If set to true, already existing variables won't be erased.\n */\n initFrom(data: VariableData[], keepOldVariables?: Boolean) {\n if (keepOldVariables === undefined) {\n keepOldVariables = false;\n }\n if (!keepOldVariables) {\n VariablesContainer._deletedVars = VariablesContainer._deletedVars || [];\n // @ts-ignore\n this._variables.keys(VariablesContainer._deletedVars);\n }\n const that = this;\n let i = 0;\n for (let j = 0; j < data.length; ++j) {\n const varData = data[j];\n if (!varData.name) continue;\n\n //Get the variable:\n const variable = that.get(varData.name);\n variable.reinitialize(varData);\n if (!keepOldVariables) {\n //Register the variable in the extra array to ensure a fast lookup using getFromIndex.\n if (i < that._variablesArray.length) {\n that._variablesArray[i] = variable;\n } else {\n that._variablesArray.push(variable);\n }\n ++i;\n\n //Remove the variable from the list of variables to be deleted.\n const idx = VariablesContainer._deletedVars.indexOf(varData.name);\n if (idx !== -1) {\n VariablesContainer._deletedVars[idx] = undefined;\n }\n }\n }\n if (!keepOldVariables) {\n this._variablesArray.length = i;\n\n //If we do not want to keep the already existing variables,\n //remove all the variables not assigned above.\n //(Here, remove means flag the variable as not existing, to avoid garbage creation ).\n for (\n let i = 0, len = VariablesContainer._deletedVars.length;\n i < len;\n ++i\n ) {\n const variableName = VariablesContainer._deletedVars[i];\n if (variableName !== undefined) {\n this._variables.get(variableName).setUndefinedInContainer();\n }\n }\n }\n }\n\n rebuildIndexFrom(data: VariableData[]) {\n this._variablesArray.length = 0;\n for (const variableData of data) {\n if (variableData.name) {\n const variable = this._variables.get(variableData.name);\n this._variablesArray.push(variable);\n }\n }\n }\n\n /**\n * Declare a new variable.\n * This should only be used by generated code.\n *\n * @param name Variable name\n * @param newVariable The variable to be declared\n */\n _declare(name: string, newVariable: gdjs.Variable): void {\n this._variables.put(name, newVariable);\n this._variablesArray.push(newVariable);\n }\n\n /**\n * Add a new variable.\n * This can be costly, don't use in performance sensitive paths.\n *\n * @param name Variable name\n * @param newVariable The variable to be added\n */\n add(name: string, newVariable: gdjs.Variable) {\n const oldVariable = this._variables.get(name);\n\n // Variable is either already defined, considered as undefined\n // in the container or missing in the container.\n // Whatever the case, replace it by the new.\n this._variables.put(name, newVariable);\n if (oldVariable) {\n // If variable is indexed, ensure that the variable as the index\n // is replaced too. This can be costly (indexOf) but we assume `add` is not\n // used in performance sensitive code.\n const variableIndex = this._variablesArray.indexOf(oldVariable);\n if (variableIndex !== -1) {\n this._variablesArray[variableIndex] = newVariable;\n }\n }\n }\n\n /**\n * Remove a variable.\n * (the variable is not really removed from the container to avoid creating garbage, but marked as undefined)\n * @param name Variable to be removed\n */\n remove(name: string) {\n const variable = this._variables.get(name);\n if (variable) {\n variable.setUndefinedInContainer();\n }\n }\n\n /**\n * Get a variable.\n * @param name The variable's name\n * @return The specified variable. If not found, an empty variable is added to the container.\n */\n get(name: string): gdjs.Variable {\n let variable = this._variables.get(name);\n if (!variable) {\n //Add automatically non-existing variables.\n variable = new gdjs.Variable();\n this._variables.put(name, variable);\n } else {\n if (\n //Reuse variables removed before.\n variable.isUndefinedInContainer()\n ) {\n variable.reinitialize();\n }\n }\n return variable;\n }\n\n /**\n * Get a variable using its index. If you're unsure about how to use this method, prefer to use `get`.\n * The index of a variable is its index in the data passed to initFrom.\n *\n * This method is generally used by events generated code to increase lookup speed for variables.\n *\n * @param id The variable index\n * @return The specified variable. If not found, an empty variable is added to the container, but it\n * should not happen.\n */\n getFromIndex(id: number): gdjs.Variable {\n if (id >= this._variablesArray.length) {\n //Add automatically non-existing variables.\n let variable = new gdjs.Variable();\n this._variables.put('', variable);\n return variable;\n } else {\n let variable: gdjs.Variable = this._variablesArray[id];\n //Reuse variables removed before.\n if (variable.isUndefinedInContainer()) {\n variable.reinitialize();\n }\n return variable;\n }\n }\n\n /**\n * Check if a variable exists in the container.\n * @param name The variable's name\n * @return true if the variable exists.\n */\n has(name: string): boolean {\n const variable = this._variables.get(name);\n return !!variable && !variable.isUndefinedInContainer();\n }\n\n /**\n * Check if a variable exists in the container.\n * @param variable The variable\n * @return true if the variable exists.\n */\n hasVariable(variable: gdjs.Variable): boolean {\n const foundVariable = this._variablesArray.find((v) => v === variable);\n return !!foundVariable && !foundVariable.isUndefinedInContainer();\n }\n\n getVariableNameInContainerByLoopingThroughAllVariables(\n variable: gdjs.Variable\n ): string | null {\n const variableItems = this._variables.items;\n for (const variableName in variableItems) {\n if (variableItems.hasOwnProperty(variableName)) {\n if (variableItems[variableName] === variable) {\n return variableName;\n }\n }\n }\n\n return null;\n }\n\n static _deletedVars: Array<string | undefined> = [];\n\n getNetworkSyncData(\n syncOptions: GetNetworkSyncDataOptions\n ): VariableNetworkSyncData[] {\n const syncedPlayerNumber = syncOptions.playerNumber;\n const isHost = syncOptions.isHost;\n const networkSyncData: VariableNetworkSyncData[] = [];\n const variableNames = [];\n this._variables.keys(variableNames);\n variableNames.forEach((variableName) => {\n const variable = this._variables.get(variableName);\n const variableOwner = variable.getPlayerOwnership();\n if (\n // Variable undefined.\n variable.isUndefinedInContainer() ||\n // Variable marked as not to be synchronized.\n variableOwner === null ||\n // Getting sync data for a specific player:\n (syncedPlayerNumber !== undefined &&\n // Variable is owned by host but this player number is not the host.\n variableOwner === 0 &&\n !isHost) ||\n // Variable is owned by a player but not getting sync data for this player number.\n (variableOwner !== 0 && syncedPlayerNumber !== variableOwner)\n ) {\n // In those cases, the variable should not be synchronized.\n return;\n }\n\n const variableType = variable.getType();\n const variableValue =\n variableType === 'structure' || variableType === 'array'\n ? ''\n : variable.getValue();\n\n networkSyncData.push({\n name: variableName,\n value: variableValue,\n type: variableType,\n children: this.getStructureNetworkSyncData(variable),\n owner: variableOwner,\n });\n });\n\n return networkSyncData;\n }\n\n // Structure variables can contain other variables, so we need to recursively\n // get the sync data for each child variable.\n getStructureNetworkSyncData(\n variable: gdjs.Variable\n ): VariableNetworkSyncData[] | undefined {\n if (variable.getType() === 'array') {\n const allVariableNetworkSyncData: VariableNetworkSyncData[] = [];\n variable.getAllChildrenArray().forEach((childVariable) => {\n const childVariableType = childVariable.getType();\n const childVariableValue =\n childVariableType === 'structure' || childVariableType === 'array'\n ? ''\n : childVariable.getValue();\n\n const childVariableOwner = childVariable.getPlayerOwnership();\n if (\n // Variable undefined.\n childVariable.isUndefinedInContainer() ||\n // Variable marked as not to be synchronized.\n childVariableOwner === null\n ) {\n // In those cases, the variable should not be synchronized.\n return;\n }\n\n allVariableNetworkSyncData.push({\n name: '',\n value: childVariableValue,\n type: childVariableType,\n children: this.getStructureNetworkSyncData(childVariable),\n owner: childVariableOwner,\n });\n });\n\n return allVariableNetworkSyncData;\n }\n\n if (variable.getType() === 'structure') {\n const variableChildren = variable.getAllChildren();\n if (!variableChildren) return undefined;\n const allVariableNetworkSyncData: VariableNetworkSyncData[] = [];\n\n Object.entries(variableChildren).forEach(\n ([childVariableName, childVariable]) => {\n const childVariableType = childVariable.getType();\n const childVariableValue =\n childVariableType === 'structure' || childVariableType === 'array'\n ? ''\n : childVariable.getValue();\n const childVariableOwner = childVariable.getPlayerOwnership();\n if (\n // Variable undefined.\n childVariable.isUndefinedInContainer() ||\n // Variable marked as not to be synchronized.\n childVariableOwner === null\n ) {\n // In those cases, the variable should not be synchronized.\n return;\n }\n\n allVariableNetworkSyncData.push({\n name: childVariableName,\n value: childVariableValue,\n type: childVariableType,\n children: this.getStructureNetworkSyncData(childVariable),\n owner: childVariableOwner,\n });\n }\n );\n\n return allVariableNetworkSyncData;\n }\n\n return undefined;\n }\n\n updateFromNetworkSyncData(networkSyncData: VariableNetworkSyncData[]) {\n const that = this;\n for (let j = 0; j < networkSyncData.length; ++j) {\n const variableSyncData = networkSyncData[j];\n const variableData = that._getVariableDataFromNetworkSyncData(\n variableSyncData\n );\n const variableName = variableData.name;\n if (!variableName) continue;\n\n const variable = that.get(variableName);\n\n // // If we receive an update for this variable for a different owner than the one we know about,\n // then 2 cases:\n // - If we are the owner of the variable, then ignore the message, we assume it's a late update message or a wrong one,\n // we are confident that we own this variable. (it may be reverted if we don't receive an acknowledgment in time)\n // - If we are not the owner of the variable, then assume that we missed the ownership change message, so update the variable's\n // ownership and then update the variable.\n const syncedVariableOwner = variableSyncData.owner;\n const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();\n const currentVariableOwner = variable.getPlayerOwnership();\n if (currentPlayerNumber === currentVariableOwner) {\n console.info(\n `Variable ${variableName} is owned by us ${gdjs.multiplayer.playerNumber}, ignoring update message from ${syncedVariableOwner}.`\n );\n return;\n }\n\n if (syncedVariableOwner !== currentVariableOwner) {\n console.info(\n `Variable ${variableName} is owned by ${currentVariableOwner} on our game, changing ownership to ${syncedVariableOwner} as part of the update event.`\n );\n variable.setPlayerOwnership(syncedVariableOwner);\n }\n\n variable.reinitialize(variableData);\n }\n }\n\n _getVariableDataFromNetworkSyncData(\n syncData: VariableNetworkSyncData\n ): VariableData {\n return {\n name: syncData.name,\n value: syncData.value,\n type: syncData.type,\n children: syncData.children\n ? syncData.children.map((childSyncData) =>\n this._getVariableDataFromNetworkSyncData(childSyncData)\n )\n : undefined,\n };\n }\n\n /**\n * \"Bad\" variable container, used by events when no other valid container can be found.\n * This container has no state and always returns the bad variable ( see VariablesContainer.badVariable ).\n * @static\n */\n static badVariablesContainer: VariablesContainer = {\n _variables: new Hashtable(),\n _variablesArray: [],\n has: function () {\n return false;\n },\n getFromIndex: function () {\n return VariablesContainer.badVariable;\n },\n get: function () {\n return VariablesContainer.badVariable;\n },\n remove: function () {\n return;\n },\n add: function () {\n return;\n },\n _declare: function () {\n return;\n },\n initFrom: function () {\n return;\n },\n getNetworkSyncData: function () {\n return [];\n },\n updateFromNetworkSyncData: function () {\n return;\n },\n getStructureNetworkSyncData: function () {\n return undefined;\n },\n _getVariableDataFromNetworkSyncData: function () {\n return {};\n },\n hasVariable: function () {\n return false;\n },\n getVariableNameInContainerByLoopingThroughAllVariables: function () {\n return '';\n },\n rebuildIndexFrom: function () {\n return;\n },\n };\n\n /**\n * \"Bad\" variable, used by events when no other valid variable can be found.\n * This variable has no state and always return 0 or the empty string.\n * @static\n */\n static badVariable: Variable = {\n _type: 'number',\n _bool: false,\n _children: {},\n _childrenArray: [],\n _str: '',\n _undefinedInContainer: true,\n _value: 0,\n _playerNumber: 0,\n fromJSON: () => gdjs.VariablesContainer.badVariable,\n toJSObject: () => 0,\n fromJSObject: () => gdjs.VariablesContainer.badVariable,\n reinitialize: () => {},\n addChild: () => gdjs.VariablesContainer.badVariable,\n castTo: () => {},\n clearChildren: () => {},\n clone: () => gdjs.VariablesContainer.badVariable,\n getChildrenCount: () => 0,\n replaceChildren: () => {},\n replaceChildrenArray: () => {},\n getType: function () {\n return 'number';\n },\n isPrimitive: function () {\n return true;\n },\n setValue: () => {},\n toggle: () => {},\n getValue: () => 0,\n getChild: () => gdjs.VariablesContainer.badVariable,\n getChildAt: () => gdjs.VariablesContainer.badVariable,\n getChildNamed: () => gdjs.VariablesContainer.badVariable,\n hasChild: function () {\n return false;\n },\n isStructure: function () {\n return false;\n },\n isNumber: function () {\n return true;\n },\n removeChild: function () {\n return;\n },\n setNumber: function () {\n return;\n },\n setString: function () {\n return;\n },\n setBoolean: function () {\n return;\n },\n getAsString: function () {\n return '0';\n },\n getAsNumber: function () {\n return 0;\n },\n getAsNumberOrString: function () {\n return 0;\n },\n getAsBoolean: function () {\n return false;\n },\n getAllChildren: function () {\n return {};\n },\n getAllChildrenArray: function () {\n return [];\n },\n pushVariableCopy: () => {},\n _pushVariable: () => {},\n pushValue: () => {},\n removeAtIndex: function () {\n return;\n },\n add: function () {\n return;\n },\n sub: function () {\n return;\n },\n mul: function () {\n return;\n },\n div: function () {\n return;\n },\n concatenate: function () {\n return;\n },\n concatenateString: function () {\n return;\n },\n setUndefinedInContainer: function () {\n return;\n },\n isUndefinedInContainer: function () {\n return true;\n },\n getPlayerOwnership: function () {\n return 0;\n },\n setPlayerOwnership: function () {\n return;\n },\n disableSynchronization: function () {\n return;\n },\n };\n }\n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