gdcore-tools 2.0.0-beta9 → 2.0.0-gd-v5.4.218-autobuild
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -64
- package/dist/Runtime/Extensions/3D/JsExtension.js +7 -3
- package/dist/Runtime/Extensions/DialogueTree/JsExtension.js +44 -32
- package/dist/Runtime/Extensions/DialogueTree/bondage.js/dist/bondage.min.js +10 -10
- package/dist/Runtime/Extensions/DialogueTree/bondage.js/version.txt +5 -5
- package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js +2 -2
- package/dist/Runtime/Extensions/DialogueTree/dialoguetools.js.map +2 -2
- package/dist/Runtime/Extensions/Firebase/A_firebasejs/NOTICE.txt +6 -6
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PhysicsBehavior/box2djs/box2d.js +804 -804
- package/dist/Runtime/Extensions/Shopify/shopify-buy.umd.polyfilled.min.js +1 -1
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js +1 -1
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-atlas-manager.js.map +2 -2
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js +1 -1
- package/dist/Runtime/Extensions/Spine/managers/pixi-spine-manager.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/example/anotherIsland.json +5768 -5768
- package/dist/Runtime/Extensions/TileMap/example/island.json +5822 -5822
- package/dist/Runtime/Model3DManager.js +1 -1
- package/dist/Runtime/Model3DManager.js.map +2 -2
- package/dist/Runtime/ResourceLoader.js +1 -1
- package/dist/Runtime/ResourceLoader.js.map +2 -2
- package/dist/Runtime/capturemanager.js +2 -0
- package/dist/Runtime/capturemanager.js.map +7 -0
- package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js +1 -1
- package/dist/Runtime/fontfaceobserver-font-manager/fontfaceobserver-font-manager.js.map +2 -2
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
- package/dist/Runtime/jsonmanager.js +1 -1
- package/dist/Runtime/jsonmanager.js.map +2 -2
- package/dist/Runtime/layer.js +1 -1
- package/dist/Runtime/layer.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-bitmapfont-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js +1 -1
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/runtimewatermark.js +2 -2
- package/dist/Runtime/runtimewatermark.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/lib/libGD.cjs +21 -21
- package/dist/lib/libGD.wasm +0 -0
- package/gd.d.ts +22 -6
- package/package.json +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/.package-lock.json +0 -19
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/@types/pako/index.d.ts +0 -165
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/@types/pako/package.json +0 -35
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako.es5.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako.es5.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako.es5.min.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako.min.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_deflate.es5.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_deflate.es5.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_deflate.es5.min.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_deflate.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_deflate.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_deflate.min.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_inflate.es5.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_inflate.es5.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_inflate.es5.min.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_inflate.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_inflate.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/dist/pako_inflate.min.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/index.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/index.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/deflate.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/deflate.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/inflate.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/inflate.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/utils/common.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/utils/common.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/utils/strings.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/utils/strings.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/adler32.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/adler32.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/constants.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/constants.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/crc32.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/crc32.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/deflate.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/deflate.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/gzheader.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/gzheader.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/inffast.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/inffast.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/inflate.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/inflate.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/inftrees.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/inftrees.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/messages.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/messages.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/trees.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/trees.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/zstream.js +0 -2
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/lib/zlib/zstream.js.map +0 -7
- package/dist/Runtime/Extensions/TileMap/helper/node_modules/pako/package.json +0 -64
- package/types/index.d.ts +0 -23
- package/types/open_project.d.ts +0 -25
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(a){const d=new a.Logger("Multiplayer"),m=new a.Logger("Multiplayer - Debug"),f=window.performance&&typeof window.performance.now=="function"?window.performance.now.bind(window.performance):Date.now;class g extends a.RuntimeBehavior{constructor(t,n,e){super(t,n,e);this.playerNumber=0;this._lastObjectSyncTimestamp=0;this._lastBasicObjectSyncTimestamp=0;this._objectBasicInfoSyncRate=5;this._numberOfForcedBasicObjectUpdates=0;this._lastVariablesSyncTimestamp=0;this._variablesSyncRate=1;this._numberOfForcedVariablesUpdates=0;this._lastEffectsSyncTimestamp=0;this._effectsSyncRate=1;this._numberOfForcedEffectsUpdates=0;this._lastLogTimestamp=0;this._logSyncRate=1;this._clock=0;this._destroyInstanceTimeoutId=null;this._timeBeforeDestroyingObjectWithoutNetworkIdInMs=500;this._sendDataToPeersWithIncreasedClock=async(t,n)=>{this._clock++,n._clock=this._clock;const e=a.multiplayerPeerJsHelper.getAllPeers();await a.multiplayerMessageManager.sendDataTo(e,t,n)};this.playerNumber=n.playerNumber==="Host"?0:parseInt(n.playerNumber,10),this.actionOnPlayerDisconnect=n.actionOnPlayerDisconnect,this._destroyInstanceTimeoutId=setTimeout(()=>{const r=this.owner.getRuntimeScene().networkId;!e.networkId&&a.multiplayer.isLobbyGameRunning()&&r&&(m.info(`Lobby game is running on a synced scene and object ${e.getName()} has not been assigned a networkId after a short delay, destroying it.`),e.deleteFromScene(t))},this._timeBeforeDestroyingObjectWithoutNetworkIdInMs)}_isOwnerAsPlayerOrHost(){const t=a.multiplayer.getCurrentPlayerNumber(),n=a.multiplayer.isCurrentPlayerHost();return t===this.playerNumber||n&&this.playerNumber===0}_hasObjectBeenSyncedWithinMaxRate(){const t=a.multiplayer.getObjectsSynchronizationRate();return f()-this._lastObjectSyncTimestamp<1e3/t}_hasObjectBasicInfoBeenSyncedRecently(){return f()-this._lastBasicObjectSyncTimestamp<1e3/this._objectBasicInfoSyncRate}_haveVariablesBeenSyncedRecently(){return f()-this._lastVariablesSyncTimestamp<1e3/this._variablesSyncRate}_haveEffectsBeenSyncedRecently(){return f()-this._lastEffectsSyncTimestamp<1e3/this._effectsSyncRate}_getOrCreateInstanceNetworkId(){if(!this.owner.networkId){const t=a.makeUuid().substring(0,8);this.owner.networkId=t}return this.owner.networkId}_isBasicObjectNetworkSyncDataDifferentFromLastSync(t){return this._lastSentBasicObjectSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentBasicObjectSyncData):!0}_areVariablesDifferentFromLastSync(t){return this._lastSentVariableSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentVariableSyncData):!0}_areEffectsDifferentFromLastSync(t){if(!this._lastSentEffectSyncData)return!0;for(const n in t){if(!t.hasOwnProperty(n))continue;const e=t[n],r=e.ena,i=e.fc,c=this._lastSentEffectSyncData[n];if(!c||c.ena!==r)return!0;for(const s in i){if(!i.hasOwnProperty(s))continue;const o=i[s];if(c.fc[s]!==o)return!0}}return!1}doStepPostEvents(){if(!a.multiplayer.isLobbyGameRunning())return;if(this.playerNumber!==0&&!a.multiplayerMessageManager.isPlayerConnected(this.playerNumber)){m.info(`Player number ${this.playerNumber} does not exist in the lobby at the moment. Destroying the object.`),this.owner.deleteFromScene(this.owner.getInstanceContainer());return}if(!this._isOwnerAsPlayerOrHost()||this._hasObjectBeenSyncedWithinMaxRate())return;const t=this._getOrCreateInstanceNetworkId(),n=this.owner.getName(),e=this.owner.getNetworkSyncData(),r=this._isBasicObjectNetworkSyncDataDifferentFromLastSync({x:e.x,y:e.y,z:e.z,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy}),i=!this._hasObjectBasicInfoBeenSyncedRecently()||r||this._numberOfForcedBasicObjectUpdates>0;if(r&&(this._numberOfForcedBasicObjectUpdates=3),!i)return;const c=e.var&&this._areVariablesDifferentFromLastSync(e.var),s=!this._haveVariablesBeenSyncedRecently()||c||this._numberOfForcedVariablesUpdates>0;c&&(this._numberOfForcedVariablesUpdates=3),s||delete e.var;const o=e.eff&&this._areEffectsDifferentFromLastSync(e.eff),l=!this._haveEffectsBeenSyncedRecently()||o||this._numberOfForcedEffectsUpdates>0;o&&(this._numberOfForcedEffectsUpdates=3),l||delete e.eff;const y=this.owner.getRuntimeScene().networkId;if(!y)return;const{messageName:h,messageData:b}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:e,sceneNetworkId:y});this._sendDataToPeersWithIncreasedClock(h,b);const u=f();this._lastObjectSyncTimestamp=u,i&&(this._lastBasicObjectSyncTimestamp=u,this._lastSentBasicObjectSyncData={x:e.x,y:e.y,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy},this._numberOfForcedBasicObjectUpdates=Math.max(this._numberOfForcedBasicObjectUpdates-1,0)),s&&(this._lastVariablesSyncTimestamp=u,this._lastSentVariableSyncData=e.var,this._numberOfForcedVariablesUpdates=Math.max(this._numberOfForcedVariablesUpdates-1,0)),l&&(this._lastEffectsSyncTimestamp=u,this._lastSentEffectSyncData=e.eff,this._numberOfForcedEffectsUpdates=Math.max(this._numberOfForcedEffectsUpdates-1,0))}onDestroy(){if(this._destroyInstanceTimeoutId&&(clearTimeout(this._destroyInstanceTimeoutId),this._destroyInstanceTimeoutId=null),!a.multiplayer.isLobbyGameRunning()||!this._isOwnerAsPlayerOrHost()&&!a.multiplayer.isCurrentPlayerHost())return;const t=this.owner.networkId,n=this.owner.getName();if(!t){m.info(`Destroying object ${n} without networkId, no need to send a message.`);return}const e=this.owner.getRuntimeScene().networkId;if(!e)return;const{messageName:r,messageData:i}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:this.owner.getNetworkSyncData(),sceneNetworkId:e});this._sendDataToPeersWithIncreasedClock(r,i);const c=a.multiplayerPeerJsHelper.getAllPeers(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createDestroyInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,sceneNetworkId:e}),l=a.multiplayerMessageManager.createInstanceDestroyedMessageNameFromDestroyInstanceMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:l,otherPeerIds:c,shouldCancelMessageIfTimesOut:!1}),this._sendDataToPeersWithIncreasedClock(s,o)}setPlayerObjectOwnership(t){if(m.info(`Setting ownership of object ${this.owner.getName()} (networkId: ${this.owner.networkId} to player ${t}.`),t<0){d.error("Invalid player number ("+t+") when setting ownership of an object.");return}const n=this.playerNumber;this.playerNumber=t;const e=a.multiplayer.getCurrentPlayerNumber();if(!a.multiplayer.isLobbyGameRunning())return;let r=this.owner.networkId;if(!r){if(m.info("Object has no networkId, we change the ownership locally, but it will not be synchronized yet if we are not the owner."),t!==e)return;m.info("We are the new owner, creating a networkId for the object."),r=this._getOrCreateInstanceNetworkId()}const i=this.owner.getRuntimeScene().networkId;if(!i)return;const c=this.owner.getName(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createChangeInstanceOwnerMessage({objectOwner:n,objectName:c,instanceNetworkId:r,newObjectOwner:t,instanceX:this.owner.getX(),instanceY:this.owner.getY(),sceneNetworkId:i});if(t===e){const l=a.multiplayerPeerJsHelper.getAllPeers(),y=a.multiplayerMessageManager.createInstanceOwnerChangedMessageNameFromChangeInstanceOwnerMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:y,otherPeerIds:l,shouldCancelMessageIfTimesOut:!a.multiplayer.isCurrentPlayerHost()})}if(m.info("Sending change owner message",s),this._sendDataToPeersWithIncreasedClock(s,o),t===e){m.info("Sending update message to move the object immediately.");const l=this.owner.getNetworkSyncData(),{messageName:y,messageData:h}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:c,instanceNetworkId:r,objectNetworkSyncData:l,sceneNetworkId:i});this._sendDataToPeersWithIncreasedClock(y,h)}}getPlayerObjectOwnership(){return this.playerNumber}isObjectOwnedByCurrentPlayer(){return this._isOwnerAsPlayerOrHost()}removeObjectOwnership(){this.setPlayerObjectOwnership(0)}takeObjectOwnership(){this.setPlayerObjectOwnership(a.multiplayer.getCurrentPlayerNumber())}getActionOnPlayerDisconnect(){return this.actionOnPlayerDisconnect}enableBehaviorSynchronization(t,n){const e=this.owner.getBehavior(t);if(!e){d.error(`Behavior ${t} does not exist on object ${this.owner.getName()}.`);return}e.enableSynchronization(n)}}a.MultiplayerObjectRuntimeBehavior=g,a.registerBehavior("Multiplayer::MultiplayerObjectBehavior",a.MultiplayerObjectRuntimeBehavior)})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(a){const d=new a.Logger("Multiplayer"),m=new a.Logger("Multiplayer - Debug"),f=window.performance&&typeof window.performance.now=="function"?window.performance.now.bind(window.performance):Date.now;class g extends a.RuntimeBehavior{constructor(t,n,e){super(t,n,e);this.playerNumber=0;this._lastObjectSyncTimestamp=0;this._lastBasicObjectSyncTimestamp=0;this._objectBasicInfoSyncRate=5;this._numberOfForcedBasicObjectUpdates=0;this._lastVariablesSyncTimestamp=0;this._variablesSyncRate=1;this._numberOfForcedVariablesUpdates=0;this._lastEffectsSyncTimestamp=0;this._effectsSyncRate=1;this._numberOfForcedEffectsUpdates=0;this._lastLogTimestamp=0;this._logSyncRate=1;this._clock=0;this._destroyInstanceTimeoutId=null;this._timeBeforeDestroyingObjectWithoutNetworkIdInMs=500;this._sendDataToPeersWithIncreasedClock=async(t,n)=>{this._clock++,n._clock=this._clock;const e=a.multiplayerPeerJsHelper.getAllPeers();await a.multiplayerMessageManager.sendDataTo(e,t,n)};this.playerNumber=n.playerNumber==="Host"?0:parseInt(n.playerNumber,10),this.actionOnPlayerDisconnect=n.actionOnPlayerDisconnect,this._destroyInstanceTimeoutId=setTimeout(()=>{const r=this.owner.getRuntimeScene().networkId;!e.networkId&&a.multiplayer.isLobbyGameRunning()&&r&&(m.info(`Lobby game is running on a synced scene and object ${e.getName()} has not been assigned a networkId after a short delay, destroying it.`),e.deleteFromScene(t))},this._timeBeforeDestroyingObjectWithoutNetworkIdInMs)}_isOwnerAsPlayerOrHost(){const t=a.multiplayer.getCurrentPlayerNumber(),n=a.multiplayer.isCurrentPlayerHost();return t===this.playerNumber||n&&this.playerNumber===0}_hasObjectBeenSyncedWithinMaxRate(){const t=a.multiplayer.getObjectsSynchronizationRate();return f()-this._lastObjectSyncTimestamp<1e3/t}_hasObjectBasicInfoBeenSyncedRecently(){return f()-this._lastBasicObjectSyncTimestamp<1e3/this._objectBasicInfoSyncRate}_haveVariablesBeenSyncedRecently(){return f()-this._lastVariablesSyncTimestamp<1e3/this._variablesSyncRate}_haveEffectsBeenSyncedRecently(){return f()-this._lastEffectsSyncTimestamp<1e3/this._effectsSyncRate}_getOrCreateInstanceNetworkId(){if(!this.owner.networkId){const t=a.makeUuid().substring(0,8);this.owner.networkId=t}return this.owner.networkId}_isBasicObjectNetworkSyncDataDifferentFromLastSync(t){return this._lastSentBasicObjectSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentBasicObjectSyncData):!0}_areVariablesDifferentFromLastSync(t){return this._lastSentVariableSyncData?JSON.stringify(t)!==JSON.stringify(this._lastSentVariableSyncData):!0}_areEffectsDifferentFromLastSync(t){if(!this._lastSentEffectSyncData)return!0;for(const n in t){if(!t.hasOwnProperty(n))continue;const e=t[n],r=e.ena,i=e.fc,c=this._lastSentEffectSyncData[n];if(!c||c.ena!==r)return!0;for(const s in i){if(!i.hasOwnProperty(s))continue;const o=i[s];if(c.fc[s]!==o)return!0}}return!1}doStepPostEvents(){if(!a.multiplayer.isLobbyGameRunning())return;if(this.actionOnPlayerDisconnect!=="DoNothing"&&this.playerNumber!==0&&!a.multiplayerMessageManager.isPlayerConnected(this.playerNumber)){m.info(`Player number ${this.playerNumber} does not exist in the lobby at the moment. Destroying the object.`),this.owner.deleteFromScene(this.owner.getInstanceContainer());return}if(!this._isOwnerAsPlayerOrHost()||this._hasObjectBeenSyncedWithinMaxRate())return;const t=this._getOrCreateInstanceNetworkId(),n=this.owner.getName(),e=this.owner.getNetworkSyncData(),r=this._isBasicObjectNetworkSyncDataDifferentFromLastSync({x:e.x,y:e.y,z:e.z,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy}),i=!this._hasObjectBasicInfoBeenSyncedRecently()||r||this._numberOfForcedBasicObjectUpdates>0;if(r&&(this._numberOfForcedBasicObjectUpdates=3),!i)return;const c=e.var&&this._areVariablesDifferentFromLastSync(e.var),s=!this._haveVariablesBeenSyncedRecently()||c||this._numberOfForcedVariablesUpdates>0;c&&(this._numberOfForcedVariablesUpdates=3),s||delete e.var;const o=e.eff&&this._areEffectsDifferentFromLastSync(e.eff),l=!this._haveEffectsBeenSyncedRecently()||o||this._numberOfForcedEffectsUpdates>0;o&&(this._numberOfForcedEffectsUpdates=3),l||delete e.eff;const y=this.owner.getRuntimeScene().networkId;if(!y)return;const{messageName:h,messageData:b}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:e,sceneNetworkId:y});this._sendDataToPeersWithIncreasedClock(h,b);const u=f();this._lastObjectSyncTimestamp=u,i&&(this._lastBasicObjectSyncTimestamp=u,this._lastSentBasicObjectSyncData={x:e.x,y:e.y,zo:e.zo,a:e.a,hid:e.hid,lay:e.lay,if:e.if,pfx:e.pfx,pfy:e.pfy},this._numberOfForcedBasicObjectUpdates=Math.max(this._numberOfForcedBasicObjectUpdates-1,0)),s&&(this._lastVariablesSyncTimestamp=u,this._lastSentVariableSyncData=e.var,this._numberOfForcedVariablesUpdates=Math.max(this._numberOfForcedVariablesUpdates-1,0)),l&&(this._lastEffectsSyncTimestamp=u,this._lastSentEffectSyncData=e.eff,this._numberOfForcedEffectsUpdates=Math.max(this._numberOfForcedEffectsUpdates-1,0))}onDestroy(){if(this._destroyInstanceTimeoutId&&(clearTimeout(this._destroyInstanceTimeoutId),this._destroyInstanceTimeoutId=null),!a.multiplayer.isLobbyGameRunning()||!this._isOwnerAsPlayerOrHost()&&!a.multiplayer.isCurrentPlayerHost())return;const t=this.owner.networkId,n=this.owner.getName();if(!t){m.info(`Destroying object ${n} without networkId, no need to send a message.`);return}const e=this.owner.getRuntimeScene().networkId;if(!e)return;const{messageName:r,messageData:i}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,objectNetworkSyncData:this.owner.getNetworkSyncData(),sceneNetworkId:e});this._sendDataToPeersWithIncreasedClock(r,i);const c=a.multiplayerPeerJsHelper.getAllPeers(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createDestroyInstanceMessage({objectOwner:this.playerNumber,objectName:n,instanceNetworkId:t,sceneNetworkId:e}),l=a.multiplayerMessageManager.createInstanceDestroyedMessageNameFromDestroyInstanceMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:l,otherPeerIds:c,shouldCancelMessageIfTimesOut:!1}),this._sendDataToPeersWithIncreasedClock(s,o)}setPlayerObjectOwnership(t){if(m.info(`Setting ownership of object ${this.owner.getName()} (networkId: ${this.owner.networkId} to player ${t}.`),t<0){d.error("Invalid player number ("+t+") when setting ownership of an object.");return}const n=this.playerNumber;this.playerNumber=t;const e=a.multiplayer.getCurrentPlayerNumber();if(!a.multiplayer.isLobbyGameRunning())return;let r=this.owner.networkId;if(!r){if(m.info("Object has no networkId, we change the ownership locally, but it will not be synchronized yet if we are not the owner."),t!==e)return;m.info("We are the new owner, creating a networkId for the object."),r=this._getOrCreateInstanceNetworkId()}const i=this.owner.getRuntimeScene().networkId;if(!i)return;const c=this.owner.getName(),{messageName:s,messageData:o}=a.multiplayerMessageManager.createChangeInstanceOwnerMessage({objectOwner:n,objectName:c,instanceNetworkId:r,newObjectOwner:t,instanceX:this.owner.getX(),instanceY:this.owner.getY(),sceneNetworkId:i});if(t===e){const l=a.multiplayerPeerJsHelper.getAllPeers(),y=a.multiplayerMessageManager.createInstanceOwnerChangedMessageNameFromChangeInstanceOwnerMessage(s);a.multiplayerMessageManager.addExpectedMessageAcknowledgement({originalMessageName:s,originalData:{...o,_clock:this._clock+1},expectedMessageName:y,otherPeerIds:l,shouldCancelMessageIfTimesOut:!a.multiplayer.isCurrentPlayerHost()})}if(m.info("Sending change owner message",s),this._sendDataToPeersWithIncreasedClock(s,o),t===e){m.info("Sending update message to move the object immediately.");const l=this.owner.getNetworkSyncData(),{messageName:y,messageData:h}=a.multiplayerMessageManager.createUpdateInstanceMessage({objectOwner:this.playerNumber,objectName:c,instanceNetworkId:r,objectNetworkSyncData:l,sceneNetworkId:i});this._sendDataToPeersWithIncreasedClock(y,h)}}getPlayerObjectOwnership(){return this.playerNumber}isObjectOwnedByCurrentPlayer(){return this._isOwnerAsPlayerOrHost()}removeObjectOwnership(){this.setPlayerObjectOwnership(0)}takeObjectOwnership(){this.setPlayerObjectOwnership(a.multiplayer.getCurrentPlayerNumber())}getActionOnPlayerDisconnect(){return this.actionOnPlayerDisconnect}enableBehaviorSynchronization(t,n){const e=this.owner.getBehavior(t);if(!e){d.error(`Behavior ${t} does not exist on object ${this.owner.getName()}.`);return}e.enableSynchronization(n)}}a.MultiplayerObjectRuntimeBehavior=g,a.registerBehavior("Multiplayer::MultiplayerObjectBehavior",a.MultiplayerObjectRuntimeBehavior)})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=multiplayerobjectruntimebehavior.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/Multiplayer/multiplayerobjectruntimebehavior.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n GDevelop - Multiplayer Object Behavior Extension\n Copyright (c) 2013-2016 Florian Rival (Florian.Rival@gmail.com)\n*/\n\nnamespace gdjs {\n const logger = new gdjs.Logger('Multiplayer');\n const debugLogger = new gdjs.Logger('Multiplayer - Debug');\n const getTimeNow =\n window.performance && typeof window.performance.now === 'function'\n ? window.performance.now.bind(window.performance)\n : Date.now;\n\n /**\n * The MultiplayerObjectRuntimeBehavior represents a behavior that can be added to objects\n * to make them synchronized over the network.\n */\n export class MultiplayerObjectRuntimeBehavior extends gdjs.RuntimeBehavior {\n // Which player is the owner of the object.\n // If 0, then the object is not owned by any player, so the host is the owner.\n playerNumber: number = 0;\n\n // The action to be executed when the player disconnects.\n actionOnPlayerDisconnect: string;\n\n // The last time the object has been synchronized.\n // This is to avoid synchronizing the object too often, see _objectMaxSyncRate.\n _lastObjectSyncTimestamp: number = 0;\n\n // The last time the basic object info has been synchronized.\n _lastBasicObjectSyncTimestamp: number = 0;\n // The number of times per second the object basic info should be synchronized when it doesn't change.\n _objectBasicInfoSyncRate: number = 5;\n // The last data sent to synchronize the basic info of the object.\n _lastSentBasicObjectSyncData: BasicObjectNetworkSyncData | undefined;\n // When we know that the basic info of the object has been updated, we can force sending them\n // on the max SyncRate for a number of times to ensure they are received, without the need of an acknowledgment.\n _numberOfForcedBasicObjectUpdates: number = 0;\n\n // The last time the variables have been synchronized.\n _lastVariablesSyncTimestamp: number = 0;\n // The number of times per second the variables should be synchronized.\n _variablesSyncRate: number = 1;\n // The last data sent to synchronize the variables.\n _lastSentVariableSyncData: VariableNetworkSyncData[] | undefined;\n // When we know that the variables have been updated, we can force sending them\n // on the same syncRate as the object update for a number of times\n // to ensure they are received, without the need of an acknowledgment.\n _numberOfForcedVariablesUpdates: number = 0;\n\n // The last time the effects have been synchronized.\n _lastEffectsSyncTimestamp: number = 0;\n // The number of times per second the effects should be synchronized.\n _effectsSyncRate: number = 1;\n // The last data sent to synchronize the effects.\n _lastSentEffectSyncData:\n | { [effectName: string]: EffectNetworkSyncData }\n | undefined;\n // When we know that the effects have been updated, we can force sending them\n // on the same syncRate as the object update for a number of times\n // to ensure they are received, without the need of an acknowledgment.\n _numberOfForcedEffectsUpdates: number = 0;\n\n // To avoid seeing too many logs.\n _lastLogTimestamp: number = 0;\n _logSyncRate: number = 1;\n // Clock to be incremented every time we send a message, to ensure they are ordered\n // and old messages are ignored.\n _clock: number = 0;\n _destroyInstanceTimeoutId: NodeJS.Timeout | null = null;\n _timeBeforeDestroyingObjectWithoutNetworkIdInMs = 500;\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n behaviorData,\n owner: RuntimeObject\n ) {\n super(instanceContainer, behaviorData, owner);\n this.playerNumber =\n behaviorData.playerNumber === 'Host'\n ? 0\n : parseInt(behaviorData.playerNumber, 10);\n this.actionOnPlayerDisconnect = behaviorData.actionOnPlayerDisconnect;\n\n // When a synchronized object is created, we assume it will be assigned a networkId quickly if:\n // - It is a new object created by the current player. -> will be assigned a networkId when sending the update message.\n // - It is an object created by another player. -> will be assigned a networkId when receiving the update message.\n // There is a small risk that the object is created by us after we receive an update message from the host,\n // ending up with 2 objects created, one with a networkId (from the host) and one without (from us).\n // To handle this case and avoid having an object not synchronized, we set a timeout to destroy the object\n // if it has not been assigned a networkId after a short delay.\n this._destroyInstanceTimeoutId = setTimeout(() => {\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (\n !owner.networkId &&\n gdjs.multiplayer.isLobbyGameRunning() &&\n sceneNetworkId\n ) {\n debugLogger.info(\n `Lobby game is running on a synced scene and object ${owner.getName()} has not been assigned a networkId after a short delay, destroying it.`\n );\n owner.deleteFromScene(instanceContainer);\n }\n }, this._timeBeforeDestroyingObjectWithoutNetworkIdInMs);\n }\n\n private _sendDataToPeersWithIncreasedClock = async (\n messageName: string,\n data: Object\n ) => {\n this._clock++;\n data['_clock'] = this._clock;\n const connectedPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();\n await gdjs.multiplayerMessageManager.sendDataTo(\n connectedPeerIds,\n messageName,\n data\n );\n };\n\n private _isOwnerAsPlayerOrHost() {\n const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();\n const isHost = gdjs.multiplayer.isCurrentPlayerHost();\n\n const isOwnerOfObject =\n currentPlayerNumber === this.playerNumber || // Player as owner.\n (isHost && this.playerNumber === 0); // Host as owner.\n\n return isOwnerOfObject;\n }\n\n private _hasObjectBeenSyncedWithinMaxRate() {\n const objectMaxSyncRate = gdjs.multiplayer.getObjectsSynchronizationRate();\n return (\n getTimeNow() - this._lastObjectSyncTimestamp < 1000 / objectMaxSyncRate\n );\n }\n\n private _hasObjectBasicInfoBeenSyncedRecently() {\n return (\n getTimeNow() - this._lastBasicObjectSyncTimestamp <\n 1000 / this._objectBasicInfoSyncRate\n );\n }\n\n private _haveVariablesBeenSyncedRecently() {\n return (\n getTimeNow() - this._lastVariablesSyncTimestamp <\n 1000 / this._variablesSyncRate\n );\n }\n\n private _haveEffectsBeenSyncedRecently() {\n return (\n getTimeNow() - this._lastEffectsSyncTimestamp <\n 1000 / this._effectsSyncRate\n );\n }\n\n // private _logToConsoleWithThrottle(message: string) {\n // if (getTimeNow() - this._lastLogTimestamp > 1000 / this._logSyncRate) {\n // logger.info(message);\n // this._lastLogTimestamp = getTimeNow();\n // }\n // }\n\n private _getOrCreateInstanceNetworkId() {\n if (!this.owner.networkId) {\n // No ID for this object, let's generate one so it can be identified by other players.\n // Keep it short to avoid sending too much data.\n const newID = gdjs.makeUuid().substring(0, 8);\n this.owner.networkId = newID;\n }\n\n return this.owner.networkId;\n }\n\n private _isBasicObjectNetworkSyncDataDifferentFromLastSync(\n basicObjectNetworkSyncData: BasicObjectNetworkSyncData\n ) {\n if (!this._lastSentBasicObjectSyncData) {\n return true;\n }\n\n // Compare the json of the basicObjectNetworkSyncData to check if they are different.\n // This is not the most efficient way to do it, but it's simple and should work.\n const haveBasicObjectNetworkSyncDataChanged =\n JSON.stringify(basicObjectNetworkSyncData) !==\n JSON.stringify(this._lastSentBasicObjectSyncData);\n\n return haveBasicObjectNetworkSyncDataChanged;\n }\n\n private _areVariablesDifferentFromLastSync(\n variablesSyncData: VariableNetworkSyncData[]\n ) {\n if (!this._lastSentVariableSyncData) {\n return true;\n }\n\n // Compare the json of the variables to check if they are different.\n // This is not the most efficient way to do it, but it's simple and should work.\n const haveVariableSyncDataChanged =\n JSON.stringify(variablesSyncData) !==\n JSON.stringify(this._lastSentVariableSyncData);\n\n return haveVariableSyncDataChanged;\n }\n\n private _areEffectsDifferentFromLastSync(effectsSyncData: {\n [effectName: string]: EffectNetworkSyncData;\n }) {\n if (!this._lastSentEffectSyncData) {\n return true;\n }\n\n for (const effectName in effectsSyncData) {\n if (!effectsSyncData.hasOwnProperty(effectName)) {\n continue;\n }\n\n const effectSyncData = effectsSyncData[effectName];\n const effectEnabled = effectSyncData.ena;\n const effectFilterCreator = effectSyncData.fc;\n\n const effectInLastSync = this._lastSentEffectSyncData[effectName];\n\n if (!effectInLastSync || effectInLastSync.ena !== effectEnabled) {\n return true;\n }\n\n for (const parameterName in effectFilterCreator) {\n if (!effectFilterCreator.hasOwnProperty(parameterName)) {\n continue;\n }\n\n const parameterValue = effectFilterCreator[parameterName];\n const lastParameterValueSent = effectInLastSync.fc[parameterName];\n if (lastParameterValueSent !== parameterValue) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n doStepPostEvents() {\n // Before doing anything, check if the game is running, if not, return.\n if (!gdjs.multiplayer.isLobbyGameRunning()) {\n return;\n }\n\n // If game is running and the object belongs to a player who is not connected, destroy the object.\n // As the game may create objects before the lobby game starts, we don't want to destroy them if it's not running.\n if (\n this.playerNumber !== 0 && // Host is always connected.\n !gdjs.multiplayerMessageManager.isPlayerConnected(this.playerNumber)\n ) {\n debugLogger.info(\n `Player number ${this.playerNumber} does not exist in the lobby at the moment. Destroying the object.`\n );\n this.owner.deleteFromScene(this.owner.getInstanceContainer());\n return;\n }\n\n if (!this._isOwnerAsPlayerOrHost()) {\n return;\n }\n\n // If the object has been synchronized recently at the max rate, then return.\n // This is to avoid sending data on every frame, which would be too much.\n if (this._hasObjectBeenSyncedWithinMaxRate()) {\n return;\n }\n\n const instanceNetworkId = this._getOrCreateInstanceNetworkId();\n const objectName = this.owner.getName();\n const objectNetworkSyncData = this.owner.getNetworkSyncData();\n\n // this._logToConsoleWithThrottle(\n // `Synchronizing object ${this.owner.getName()} (instance ${\n // this.owner.networkId\n // }) with player ${this.playerNumber} and data ${JSON.stringify(\n // objectNetworkSyncData\n // )}`\n // );\n\n const areBasicObjectNetworkSyncDataDifferent = this._isBasicObjectNetworkSyncDataDifferentFromLastSync(\n {\n x: objectNetworkSyncData.x,\n y: objectNetworkSyncData.y,\n z: objectNetworkSyncData.z,\n zo: objectNetworkSyncData.zo,\n a: objectNetworkSyncData.a,\n hid: objectNetworkSyncData.hid,\n lay: objectNetworkSyncData.lay,\n if: objectNetworkSyncData.if,\n pfx: objectNetworkSyncData.pfx,\n pfy: objectNetworkSyncData.pfy,\n }\n );\n const shouldSyncObjectBasicInfo =\n !this._hasObjectBasicInfoBeenSyncedRecently() ||\n areBasicObjectNetworkSyncDataDifferent ||\n this._numberOfForcedBasicObjectUpdates > 0;\n if (areBasicObjectNetworkSyncDataDifferent) {\n this._numberOfForcedBasicObjectUpdates = 3;\n }\n if (!shouldSyncObjectBasicInfo) {\n // If the basic info has not changed, assume we don't need to sync the whole object data at a high rate.\n // TODO: allow sending the variables, behaviors and effects still?\n return;\n }\n\n const areVariablesDifferent =\n objectNetworkSyncData.var &&\n this._areVariablesDifferentFromLastSync(objectNetworkSyncData.var);\n const shouldSyncVariables =\n !this._haveVariablesBeenSyncedRecently() ||\n areVariablesDifferent ||\n this._numberOfForcedVariablesUpdates > 0;\n if (areVariablesDifferent) {\n this._numberOfForcedVariablesUpdates = 3;\n }\n if (!shouldSyncVariables) {\n delete objectNetworkSyncData.var;\n }\n\n const areEffectsDifferent =\n objectNetworkSyncData.eff &&\n this._areEffectsDifferentFromLastSync(objectNetworkSyncData.eff);\n const shoundSyncEffects =\n !this._haveEffectsBeenSyncedRecently() ||\n areEffectsDifferent ||\n this._numberOfForcedEffectsUpdates > 0;\n if (areEffectsDifferent) {\n this._numberOfForcedEffectsUpdates = 3;\n }\n if (!shoundSyncEffects) {\n delete objectNetworkSyncData.eff;\n }\n\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (!sceneNetworkId) {\n // No networkId for the scene yet, it will be set soon, let's not sync the object yet.\n return;\n }\n\n const {\n messageName: updateMessageName,\n messageData: updateMessageData,\n } = gdjs.multiplayerMessageManager.createUpdateInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n objectNetworkSyncData,\n sceneNetworkId,\n });\n this._sendDataToPeersWithIncreasedClock(\n updateMessageName,\n updateMessageData\n );\n\n const now = getTimeNow();\n\n this._lastObjectSyncTimestamp = now;\n if (shouldSyncObjectBasicInfo) {\n this._lastBasicObjectSyncTimestamp = now;\n this._lastSentBasicObjectSyncData = {\n x: objectNetworkSyncData.x,\n y: objectNetworkSyncData.y,\n zo: objectNetworkSyncData.zo,\n a: objectNetworkSyncData.a,\n hid: objectNetworkSyncData.hid,\n lay: objectNetworkSyncData.lay,\n if: objectNetworkSyncData.if,\n pfx: objectNetworkSyncData.pfx,\n pfy: objectNetworkSyncData.pfy,\n };\n this._numberOfForcedBasicObjectUpdates = Math.max(\n this._numberOfForcedBasicObjectUpdates - 1,\n 0\n );\n }\n if (shouldSyncVariables) {\n this._lastVariablesSyncTimestamp = now;\n this._lastSentVariableSyncData = objectNetworkSyncData.var;\n this._numberOfForcedVariablesUpdates = Math.max(\n this._numberOfForcedVariablesUpdates - 1,\n 0\n );\n }\n if (shoundSyncEffects) {\n this._lastEffectsSyncTimestamp = now;\n this._lastSentEffectSyncData = objectNetworkSyncData.eff;\n this._numberOfForcedEffectsUpdates = Math.max(\n this._numberOfForcedEffectsUpdates - 1,\n 0\n );\n }\n }\n\n onDestroy() {\n if (this._destroyInstanceTimeoutId) {\n clearTimeout(this._destroyInstanceTimeoutId);\n this._destroyInstanceTimeoutId = null;\n }\n\n // If the lobby game is not running, no need to send a message to destroy the object.\n if (!gdjs.multiplayer.isLobbyGameRunning()) {\n return;\n }\n\n // For destruction of objects, we allow the host to destroy the object even if it is not the owner.\n // This is particularly helpful when a player disconnects, so the host can destroy the object they were owning.\n if (\n !this._isOwnerAsPlayerOrHost() &&\n !gdjs.multiplayer.isCurrentPlayerHost()\n ) {\n return;\n }\n\n const instanceNetworkId = this.owner.networkId;\n const objectName = this.owner.getName();\n\n // If it had no networkId, then it was not synchronized and we don't need to send a message.\n if (!instanceNetworkId) {\n debugLogger.info(\n `Destroying object ${objectName} without networkId, no need to send a message.`\n );\n return;\n }\n\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (!sceneNetworkId) {\n // No networkId for the scene yet, it will be set soon, let's not sync the object yet.\n return;\n }\n\n // Ensure we send a final update before the object is destroyed, if it had a networkId.\n const {\n messageName: updateMessageName,\n messageData: updateMessageData,\n } = gdjs.multiplayerMessageManager.createUpdateInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n objectNetworkSyncData: this.owner.getNetworkSyncData(),\n sceneNetworkId,\n });\n this._sendDataToPeersWithIncreasedClock(\n updateMessageName,\n updateMessageData\n );\n\n // Before sending the destroy message, we set up the object representing the peers\n // that we need an acknowledgment from.\n // If we are the host, we are connected to everyone, so we expect an acknowledgment from everyone.\n // If we are another player, we are only connected to the host, so we expect an acknowledgment from the host.\n // In both cases, this represents the list of peers the current user is connected to.\n const otherPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();\n const {\n messageName: destroyMessageName,\n messageData: destroyMessageData,\n } = gdjs.multiplayerMessageManager.createDestroyInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n sceneNetworkId,\n });\n const destroyedMessageName = gdjs.multiplayerMessageManager.createInstanceDestroyedMessageNameFromDestroyInstanceMessage(\n destroyMessageName\n );\n gdjs.multiplayerMessageManager.addExpectedMessageAcknowledgement({\n originalMessageName: destroyMessageName,\n originalData: {\n ...destroyMessageData,\n // As the method `sendDataToPeersWithIncreasedClock` will increment the clock,\n // we increment it here to ensure we can resend the same message if we don't receive an acknowledgment.\n _clock: this._clock + 1,\n },\n expectedMessageName: destroyedMessageName,\n otherPeerIds,\n // Destruction of objects are not reverted, as they will eventually be recreated by an update message.\n shouldCancelMessageIfTimesOut: false,\n });\n\n this._sendDataToPeersWithIncreasedClock(\n destroyMessageName,\n destroyMessageData\n );\n }\n\n setPlayerObjectOwnership(newObjectPlayerNumber: number) {\n debugLogger.info(\n `Setting ownership of object ${this.owner.getName()} (networkId: ${\n this.owner.networkId\n } to player ${newObjectPlayerNumber}.`\n );\n if (newObjectPlayerNumber < 0) {\n logger.error(\n 'Invalid player number (' +\n newObjectPlayerNumber +\n ') when setting ownership of an object.'\n );\n return;\n }\n\n // Update the ownership locally, so the object can be used immediately.\n // This is a prediction to allow snappy interactions.\n // If we are host, we will have the ownership immediately anyway.\n // If we are another player, we will have the ownership as soon as the host acknowledges the change.\n // If the host does not send an acknowledgment, we will revert the ownership.\n const previousObjectPlayerNumber = this.playerNumber;\n this.playerNumber = newObjectPlayerNumber;\n const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();\n\n // If the lobby game is not running, do not try to update the ownership over the network,\n // as the game may create & update objects before the lobby game starts.\n if (!gdjs.multiplayer.isLobbyGameRunning()) {\n return;\n }\n\n let instanceNetworkId = this.owner.networkId;\n if (!instanceNetworkId) {\n debugLogger.info(\n 'Object has no networkId, we change the ownership locally, but it will not be synchronized yet if we are not the owner.'\n );\n if (newObjectPlayerNumber !== currentPlayerNumber) {\n // If we are not the new owner, we should not send a message to the host to change the ownership.\n // Just return and wait to receive an update message to reconcile this object.\n return;\n }\n // If we don't have a networkId, we need to create one now that we are the owner.\n // We are probably in a case where we created the object and then changed the ownership.\n debugLogger.info(\n 'We are the new owner, creating a networkId for the object.'\n );\n instanceNetworkId = this._getOrCreateInstanceNetworkId();\n }\n\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (!sceneNetworkId) {\n // No networkId for the scene yet, it will be set soon, let's not sync the object yet.\n return;\n }\n\n const objectName = this.owner.getName();\n\n // When changing the ownership of an object with a networkId, we send a message to the host to ensure it is aware of the change,\n // and can either accept it and broadcast it to other players, or reject it and do nothing with it.\n // We expect an acknowledgment from the host, if not, we will retry and eventually revert the ownership.\n const {\n messageName,\n messageData,\n } = gdjs.multiplayerMessageManager.createChangeInstanceOwnerMessage({\n objectOwner: previousObjectPlayerNumber,\n objectName,\n instanceNetworkId,\n newObjectOwner: newObjectPlayerNumber,\n instanceX: this.owner.getX(),\n instanceY: this.owner.getY(),\n sceneNetworkId,\n });\n // Before sending the changeOwner message, if we are becoming the new owner,\n // we want to ensure this message is acknowledged, by everyone we're connected to.\n // If we are the host, we are connected to everyone, so we expect an acknowledgment from everyone.\n // If we are another player, we are only connected to the host, so we expect an acknowledgment from the host.\n // In both cases, this represents the list of peers the current user is connected to.\n if (newObjectPlayerNumber === currentPlayerNumber) {\n const otherPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();\n const changeOwnerAcknowledgedMessageName = gdjs.multiplayerMessageManager.createInstanceOwnerChangedMessageNameFromChangeInstanceOwnerMessage(\n messageName\n );\n gdjs.multiplayerMessageManager.addExpectedMessageAcknowledgement({\n originalMessageName: messageName,\n originalData: {\n ...messageData,\n _clock: this._clock + 1, // Will be incremented by the time the message is sent.\n },\n expectedMessageName: changeOwnerAcknowledgedMessageName,\n otherPeerIds,\n // If we are not the host, we should revert the ownership if the host does not acknowledge the change.\n shouldCancelMessageIfTimesOut: !gdjs.multiplayer.isCurrentPlayerHost(),\n });\n }\n\n debugLogger.info('Sending change owner message', messageName);\n this._sendDataToPeersWithIncreasedClock(messageName, messageData);\n\n // If we are the new owner, also send directly an update of the position,\n // so that the object is immediately moved on the screen and we don't wait for the next tick.\n if (newObjectPlayerNumber === currentPlayerNumber) {\n debugLogger.info(\n 'Sending update message to move the object immediately.'\n );\n const objectNetworkSyncData = this.owner.getNetworkSyncData();\n const {\n messageName: updateMessageName,\n messageData: updateMessageData,\n } = gdjs.multiplayerMessageManager.createUpdateInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n objectNetworkSyncData,\n sceneNetworkId,\n });\n this._sendDataToPeersWithIncreasedClock(\n updateMessageName,\n updateMessageData\n );\n }\n }\n\n getPlayerObjectOwnership(): number {\n return this.playerNumber;\n }\n\n isObjectOwnedByCurrentPlayer(): boolean {\n return this._isOwnerAsPlayerOrHost();\n }\n\n removeObjectOwnership() {\n // 0 means the host is the owner.\n this.setPlayerObjectOwnership(0);\n }\n\n takeObjectOwnership() {\n this.setPlayerObjectOwnership(gdjs.multiplayer.getCurrentPlayerNumber());\n }\n\n getActionOnPlayerDisconnect() {\n return this.actionOnPlayerDisconnect;\n }\n\n enableBehaviorSynchronization(behaviorName: string, enable: boolean) {\n const behavior = this.owner.getBehavior(behaviorName);\n if (!behavior) {\n logger.error(\n `Behavior ${behaviorName} does not exist on object ${this.owner.getName()}.`\n );\n return;\n }\n\n behavior.enableSynchronization(enable);\n }\n }\n gdjs.registerBehavior(\n 'Multiplayer::MultiplayerObjectBehavior',\n gdjs.MultiplayerObjectRuntimeBehavior\n );\n}\n"],
|
|
5
|
-
"mappings": "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
|
|
4
|
+
"sourcesContent": ["/*\n GDevelop - Multiplayer Object Behavior Extension\n Copyright (c) 2013-2016 Florian Rival (Florian.Rival@gmail.com)\n*/\n\nnamespace gdjs {\n const logger = new gdjs.Logger('Multiplayer');\n const debugLogger = new gdjs.Logger('Multiplayer - Debug');\n const getTimeNow =\n window.performance && typeof window.performance.now === 'function'\n ? window.performance.now.bind(window.performance)\n : Date.now;\n\n /**\n * The MultiplayerObjectRuntimeBehavior represents a behavior that can be added to objects\n * to make them synchronized over the network.\n */\n export class MultiplayerObjectRuntimeBehavior extends gdjs.RuntimeBehavior {\n // Which player is the owner of the object.\n // If 0, then the object is not owned by any player, so the host is the owner.\n playerNumber: number = 0;\n\n // The action to be executed when the player disconnects.\n actionOnPlayerDisconnect: string;\n\n // The last time the object has been synchronized.\n // This is to avoid synchronizing the object too often, see _objectMaxSyncRate.\n _lastObjectSyncTimestamp: number = 0;\n\n // The last time the basic object info has been synchronized.\n _lastBasicObjectSyncTimestamp: number = 0;\n // The number of times per second the object basic info should be synchronized when it doesn't change.\n _objectBasicInfoSyncRate: number = 5;\n // The last data sent to synchronize the basic info of the object.\n _lastSentBasicObjectSyncData: BasicObjectNetworkSyncData | undefined;\n // When we know that the basic info of the object has been updated, we can force sending them\n // on the max SyncRate for a number of times to ensure they are received, without the need of an acknowledgment.\n _numberOfForcedBasicObjectUpdates: number = 0;\n\n // The last time the variables have been synchronized.\n _lastVariablesSyncTimestamp: number = 0;\n // The number of times per second the variables should be synchronized.\n _variablesSyncRate: number = 1;\n // The last data sent to synchronize the variables.\n _lastSentVariableSyncData: VariableNetworkSyncData[] | undefined;\n // When we know that the variables have been updated, we can force sending them\n // on the same syncRate as the object update for a number of times\n // to ensure they are received, without the need of an acknowledgment.\n _numberOfForcedVariablesUpdates: number = 0;\n\n // The last time the effects have been synchronized.\n _lastEffectsSyncTimestamp: number = 0;\n // The number of times per second the effects should be synchronized.\n _effectsSyncRate: number = 1;\n // The last data sent to synchronize the effects.\n _lastSentEffectSyncData:\n | { [effectName: string]: EffectNetworkSyncData }\n | undefined;\n // When we know that the effects have been updated, we can force sending them\n // on the same syncRate as the object update for a number of times\n // to ensure they are received, without the need of an acknowledgment.\n _numberOfForcedEffectsUpdates: number = 0;\n\n // To avoid seeing too many logs.\n _lastLogTimestamp: number = 0;\n _logSyncRate: number = 1;\n // Clock to be incremented every time we send a message, to ensure they are ordered\n // and old messages are ignored.\n _clock: number = 0;\n _destroyInstanceTimeoutId: NodeJS.Timeout | null = null;\n _timeBeforeDestroyingObjectWithoutNetworkIdInMs = 500;\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n behaviorData,\n owner: RuntimeObject\n ) {\n super(instanceContainer, behaviorData, owner);\n this.playerNumber =\n behaviorData.playerNumber === 'Host'\n ? 0\n : parseInt(behaviorData.playerNumber, 10);\n this.actionOnPlayerDisconnect = behaviorData.actionOnPlayerDisconnect;\n\n // When a synchronized object is created, we assume it will be assigned a networkId quickly if:\n // - It is a new object created by the current player. -> will be assigned a networkId when sending the update message.\n // - It is an object created by another player. -> will be assigned a networkId when receiving the update message.\n // There is a small risk that the object is created by us after we receive an update message from the host,\n // ending up with 2 objects created, one with a networkId (from the host) and one without (from us).\n // To handle this case and avoid having an object not synchronized, we set a timeout to destroy the object\n // if it has not been assigned a networkId after a short delay.\n this._destroyInstanceTimeoutId = setTimeout(() => {\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (\n !owner.networkId &&\n gdjs.multiplayer.isLobbyGameRunning() &&\n sceneNetworkId\n ) {\n debugLogger.info(\n `Lobby game is running on a synced scene and object ${owner.getName()} has not been assigned a networkId after a short delay, destroying it.`\n );\n owner.deleteFromScene(instanceContainer);\n }\n }, this._timeBeforeDestroyingObjectWithoutNetworkIdInMs);\n }\n\n private _sendDataToPeersWithIncreasedClock = async (\n messageName: string,\n data: Object\n ) => {\n this._clock++;\n data['_clock'] = this._clock;\n const connectedPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();\n await gdjs.multiplayerMessageManager.sendDataTo(\n connectedPeerIds,\n messageName,\n data\n );\n };\n\n private _isOwnerAsPlayerOrHost() {\n const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();\n const isHost = gdjs.multiplayer.isCurrentPlayerHost();\n\n const isOwnerOfObject =\n currentPlayerNumber === this.playerNumber || // Player as owner.\n (isHost && this.playerNumber === 0); // Host as owner.\n\n return isOwnerOfObject;\n }\n\n private _hasObjectBeenSyncedWithinMaxRate() {\n const objectMaxSyncRate = gdjs.multiplayer.getObjectsSynchronizationRate();\n return (\n getTimeNow() - this._lastObjectSyncTimestamp < 1000 / objectMaxSyncRate\n );\n }\n\n private _hasObjectBasicInfoBeenSyncedRecently() {\n return (\n getTimeNow() - this._lastBasicObjectSyncTimestamp <\n 1000 / this._objectBasicInfoSyncRate\n );\n }\n\n private _haveVariablesBeenSyncedRecently() {\n return (\n getTimeNow() - this._lastVariablesSyncTimestamp <\n 1000 / this._variablesSyncRate\n );\n }\n\n private _haveEffectsBeenSyncedRecently() {\n return (\n getTimeNow() - this._lastEffectsSyncTimestamp <\n 1000 / this._effectsSyncRate\n );\n }\n\n // private _logToConsoleWithThrottle(message: string) {\n // if (getTimeNow() - this._lastLogTimestamp > 1000 / this._logSyncRate) {\n // logger.info(message);\n // this._lastLogTimestamp = getTimeNow();\n // }\n // }\n\n private _getOrCreateInstanceNetworkId() {\n if (!this.owner.networkId) {\n // No ID for this object, let's generate one so it can be identified by other players.\n // Keep it short to avoid sending too much data.\n const newID = gdjs.makeUuid().substring(0, 8);\n this.owner.networkId = newID;\n }\n\n return this.owner.networkId;\n }\n\n private _isBasicObjectNetworkSyncDataDifferentFromLastSync(\n basicObjectNetworkSyncData: BasicObjectNetworkSyncData\n ) {\n if (!this._lastSentBasicObjectSyncData) {\n return true;\n }\n\n // Compare the json of the basicObjectNetworkSyncData to check if they are different.\n // This is not the most efficient way to do it, but it's simple and should work.\n const haveBasicObjectNetworkSyncDataChanged =\n JSON.stringify(basicObjectNetworkSyncData) !==\n JSON.stringify(this._lastSentBasicObjectSyncData);\n\n return haveBasicObjectNetworkSyncDataChanged;\n }\n\n private _areVariablesDifferentFromLastSync(\n variablesSyncData: VariableNetworkSyncData[]\n ) {\n if (!this._lastSentVariableSyncData) {\n return true;\n }\n\n // Compare the json of the variables to check if they are different.\n // This is not the most efficient way to do it, but it's simple and should work.\n const haveVariableSyncDataChanged =\n JSON.stringify(variablesSyncData) !==\n JSON.stringify(this._lastSentVariableSyncData);\n\n return haveVariableSyncDataChanged;\n }\n\n private _areEffectsDifferentFromLastSync(effectsSyncData: {\n [effectName: string]: EffectNetworkSyncData;\n }) {\n if (!this._lastSentEffectSyncData) {\n return true;\n }\n\n for (const effectName in effectsSyncData) {\n if (!effectsSyncData.hasOwnProperty(effectName)) {\n continue;\n }\n\n const effectSyncData = effectsSyncData[effectName];\n const effectEnabled = effectSyncData.ena;\n const effectFilterCreator = effectSyncData.fc;\n\n const effectInLastSync = this._lastSentEffectSyncData[effectName];\n\n if (!effectInLastSync || effectInLastSync.ena !== effectEnabled) {\n return true;\n }\n\n for (const parameterName in effectFilterCreator) {\n if (!effectFilterCreator.hasOwnProperty(parameterName)) {\n continue;\n }\n\n const parameterValue = effectFilterCreator[parameterName];\n const lastParameterValueSent = effectInLastSync.fc[parameterName];\n if (lastParameterValueSent !== parameterValue) {\n return true;\n }\n }\n }\n\n return false;\n }\n\n doStepPostEvents() {\n // Before doing anything, check if the game is running, if not, return.\n if (!gdjs.multiplayer.isLobbyGameRunning()) {\n return;\n }\n\n // If game is running and the object belongs to a player who is not connected, destroy the object.\n // As the game may create objects before the lobby game starts, we don't want to destroy them if it's not running.\n if (\n this.actionOnPlayerDisconnect !== 'DoNothing' && // Should not delete if flagged as such.\n this.playerNumber !== 0 && // Host is always connected.\n !gdjs.multiplayerMessageManager.isPlayerConnected(this.playerNumber)\n ) {\n debugLogger.info(\n `Player number ${this.playerNumber} does not exist in the lobby at the moment. Destroying the object.`\n );\n this.owner.deleteFromScene(this.owner.getInstanceContainer());\n return;\n }\n\n if (!this._isOwnerAsPlayerOrHost()) {\n return;\n }\n\n // If the object has been synchronized recently at the max rate, then return.\n // This is to avoid sending data on every frame, which would be too much.\n if (this._hasObjectBeenSyncedWithinMaxRate()) {\n return;\n }\n\n const instanceNetworkId = this._getOrCreateInstanceNetworkId();\n const objectName = this.owner.getName();\n const objectNetworkSyncData = this.owner.getNetworkSyncData();\n\n // this._logToConsoleWithThrottle(\n // `Synchronizing object ${this.owner.getName()} (instance ${\n // this.owner.networkId\n // }) with player ${this.playerNumber} and data ${JSON.stringify(\n // objectNetworkSyncData\n // )}`\n // );\n\n const areBasicObjectNetworkSyncDataDifferent = this._isBasicObjectNetworkSyncDataDifferentFromLastSync(\n {\n x: objectNetworkSyncData.x,\n y: objectNetworkSyncData.y,\n z: objectNetworkSyncData.z,\n zo: objectNetworkSyncData.zo,\n a: objectNetworkSyncData.a,\n hid: objectNetworkSyncData.hid,\n lay: objectNetworkSyncData.lay,\n if: objectNetworkSyncData.if,\n pfx: objectNetworkSyncData.pfx,\n pfy: objectNetworkSyncData.pfy,\n }\n );\n const shouldSyncObjectBasicInfo =\n !this._hasObjectBasicInfoBeenSyncedRecently() ||\n areBasicObjectNetworkSyncDataDifferent ||\n this._numberOfForcedBasicObjectUpdates > 0;\n if (areBasicObjectNetworkSyncDataDifferent) {\n this._numberOfForcedBasicObjectUpdates = 3;\n }\n if (!shouldSyncObjectBasicInfo) {\n // If the basic info has not changed, assume we don't need to sync the whole object data at a high rate.\n // TODO: allow sending the variables, behaviors and effects still?\n return;\n }\n\n const areVariablesDifferent =\n objectNetworkSyncData.var &&\n this._areVariablesDifferentFromLastSync(objectNetworkSyncData.var);\n const shouldSyncVariables =\n !this._haveVariablesBeenSyncedRecently() ||\n areVariablesDifferent ||\n this._numberOfForcedVariablesUpdates > 0;\n if (areVariablesDifferent) {\n this._numberOfForcedVariablesUpdates = 3;\n }\n if (!shouldSyncVariables) {\n delete objectNetworkSyncData.var;\n }\n\n const areEffectsDifferent =\n objectNetworkSyncData.eff &&\n this._areEffectsDifferentFromLastSync(objectNetworkSyncData.eff);\n const shoundSyncEffects =\n !this._haveEffectsBeenSyncedRecently() ||\n areEffectsDifferent ||\n this._numberOfForcedEffectsUpdates > 0;\n if (areEffectsDifferent) {\n this._numberOfForcedEffectsUpdates = 3;\n }\n if (!shoundSyncEffects) {\n delete objectNetworkSyncData.eff;\n }\n\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (!sceneNetworkId) {\n // No networkId for the scene yet, it will be set soon, let's not sync the object yet.\n return;\n }\n\n const {\n messageName: updateMessageName,\n messageData: updateMessageData,\n } = gdjs.multiplayerMessageManager.createUpdateInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n objectNetworkSyncData,\n sceneNetworkId,\n });\n this._sendDataToPeersWithIncreasedClock(\n updateMessageName,\n updateMessageData\n );\n\n const now = getTimeNow();\n\n this._lastObjectSyncTimestamp = now;\n if (shouldSyncObjectBasicInfo) {\n this._lastBasicObjectSyncTimestamp = now;\n this._lastSentBasicObjectSyncData = {\n x: objectNetworkSyncData.x,\n y: objectNetworkSyncData.y,\n zo: objectNetworkSyncData.zo,\n a: objectNetworkSyncData.a,\n hid: objectNetworkSyncData.hid,\n lay: objectNetworkSyncData.lay,\n if: objectNetworkSyncData.if,\n pfx: objectNetworkSyncData.pfx,\n pfy: objectNetworkSyncData.pfy,\n };\n this._numberOfForcedBasicObjectUpdates = Math.max(\n this._numberOfForcedBasicObjectUpdates - 1,\n 0\n );\n }\n if (shouldSyncVariables) {\n this._lastVariablesSyncTimestamp = now;\n this._lastSentVariableSyncData = objectNetworkSyncData.var;\n this._numberOfForcedVariablesUpdates = Math.max(\n this._numberOfForcedVariablesUpdates - 1,\n 0\n );\n }\n if (shoundSyncEffects) {\n this._lastEffectsSyncTimestamp = now;\n this._lastSentEffectSyncData = objectNetworkSyncData.eff;\n this._numberOfForcedEffectsUpdates = Math.max(\n this._numberOfForcedEffectsUpdates - 1,\n 0\n );\n }\n }\n\n onDestroy() {\n if (this._destroyInstanceTimeoutId) {\n clearTimeout(this._destroyInstanceTimeoutId);\n this._destroyInstanceTimeoutId = null;\n }\n\n // If the lobby game is not running, no need to send a message to destroy the object.\n if (!gdjs.multiplayer.isLobbyGameRunning()) {\n return;\n }\n\n // For destruction of objects, we allow the host to destroy the object even if it is not the owner.\n // This is particularly helpful when a player disconnects, so the host can destroy the object they were owning.\n if (\n !this._isOwnerAsPlayerOrHost() &&\n !gdjs.multiplayer.isCurrentPlayerHost()\n ) {\n return;\n }\n\n const instanceNetworkId = this.owner.networkId;\n const objectName = this.owner.getName();\n\n // If it had no networkId, then it was not synchronized and we don't need to send a message.\n if (!instanceNetworkId) {\n debugLogger.info(\n `Destroying object ${objectName} without networkId, no need to send a message.`\n );\n return;\n }\n\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (!sceneNetworkId) {\n // No networkId for the scene yet, it will be set soon, let's not sync the object yet.\n return;\n }\n\n // Ensure we send a final update before the object is destroyed, if it had a networkId.\n const {\n messageName: updateMessageName,\n messageData: updateMessageData,\n } = gdjs.multiplayerMessageManager.createUpdateInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n objectNetworkSyncData: this.owner.getNetworkSyncData(),\n sceneNetworkId,\n });\n this._sendDataToPeersWithIncreasedClock(\n updateMessageName,\n updateMessageData\n );\n\n // Before sending the destroy message, we set up the object representing the peers\n // that we need an acknowledgment from.\n // If we are the host, we are connected to everyone, so we expect an acknowledgment from everyone.\n // If we are another player, we are only connected to the host, so we expect an acknowledgment from the host.\n // In both cases, this represents the list of peers the current user is connected to.\n const otherPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();\n const {\n messageName: destroyMessageName,\n messageData: destroyMessageData,\n } = gdjs.multiplayerMessageManager.createDestroyInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n sceneNetworkId,\n });\n const destroyedMessageName = gdjs.multiplayerMessageManager.createInstanceDestroyedMessageNameFromDestroyInstanceMessage(\n destroyMessageName\n );\n gdjs.multiplayerMessageManager.addExpectedMessageAcknowledgement({\n originalMessageName: destroyMessageName,\n originalData: {\n ...destroyMessageData,\n // As the method `sendDataToPeersWithIncreasedClock` will increment the clock,\n // we increment it here to ensure we can resend the same message if we don't receive an acknowledgment.\n _clock: this._clock + 1,\n },\n expectedMessageName: destroyedMessageName,\n otherPeerIds,\n // Destruction of objects are not reverted, as they will eventually be recreated by an update message.\n shouldCancelMessageIfTimesOut: false,\n });\n\n this._sendDataToPeersWithIncreasedClock(\n destroyMessageName,\n destroyMessageData\n );\n }\n\n setPlayerObjectOwnership(newObjectPlayerNumber: number) {\n debugLogger.info(\n `Setting ownership of object ${this.owner.getName()} (networkId: ${\n this.owner.networkId\n } to player ${newObjectPlayerNumber}.`\n );\n if (newObjectPlayerNumber < 0) {\n logger.error(\n 'Invalid player number (' +\n newObjectPlayerNumber +\n ') when setting ownership of an object.'\n );\n return;\n }\n\n // Update the ownership locally, so the object can be used immediately.\n // This is a prediction to allow snappy interactions.\n // If we are host, we will have the ownership immediately anyway.\n // If we are another player, we will have the ownership as soon as the host acknowledges the change.\n // If the host does not send an acknowledgment, we will revert the ownership.\n const previousObjectPlayerNumber = this.playerNumber;\n this.playerNumber = newObjectPlayerNumber;\n const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();\n\n // If the lobby game is not running, do not try to update the ownership over the network,\n // as the game may create & update objects before the lobby game starts.\n if (!gdjs.multiplayer.isLobbyGameRunning()) {\n return;\n }\n\n let instanceNetworkId = this.owner.networkId;\n if (!instanceNetworkId) {\n debugLogger.info(\n 'Object has no networkId, we change the ownership locally, but it will not be synchronized yet if we are not the owner.'\n );\n if (newObjectPlayerNumber !== currentPlayerNumber) {\n // If we are not the new owner, we should not send a message to the host to change the ownership.\n // Just return and wait to receive an update message to reconcile this object.\n return;\n }\n // If we don't have a networkId, we need to create one now that we are the owner.\n // We are probably in a case where we created the object and then changed the ownership.\n debugLogger.info(\n 'We are the new owner, creating a networkId for the object.'\n );\n instanceNetworkId = this._getOrCreateInstanceNetworkId();\n }\n\n const sceneNetworkId = this.owner.getRuntimeScene().networkId;\n if (!sceneNetworkId) {\n // No networkId for the scene yet, it will be set soon, let's not sync the object yet.\n return;\n }\n\n const objectName = this.owner.getName();\n\n // When changing the ownership of an object with a networkId, we send a message to the host to ensure it is aware of the change,\n // and can either accept it and broadcast it to other players, or reject it and do nothing with it.\n // We expect an acknowledgment from the host, if not, we will retry and eventually revert the ownership.\n const {\n messageName,\n messageData,\n } = gdjs.multiplayerMessageManager.createChangeInstanceOwnerMessage({\n objectOwner: previousObjectPlayerNumber,\n objectName,\n instanceNetworkId,\n newObjectOwner: newObjectPlayerNumber,\n instanceX: this.owner.getX(),\n instanceY: this.owner.getY(),\n sceneNetworkId,\n });\n // Before sending the changeOwner message, if we are becoming the new owner,\n // we want to ensure this message is acknowledged, by everyone we're connected to.\n // If we are the host, we are connected to everyone, so we expect an acknowledgment from everyone.\n // If we are another player, we are only connected to the host, so we expect an acknowledgment from the host.\n // In both cases, this represents the list of peers the current user is connected to.\n if (newObjectPlayerNumber === currentPlayerNumber) {\n const otherPeerIds = gdjs.multiplayerPeerJsHelper.getAllPeers();\n const changeOwnerAcknowledgedMessageName = gdjs.multiplayerMessageManager.createInstanceOwnerChangedMessageNameFromChangeInstanceOwnerMessage(\n messageName\n );\n gdjs.multiplayerMessageManager.addExpectedMessageAcknowledgement({\n originalMessageName: messageName,\n originalData: {\n ...messageData,\n _clock: this._clock + 1, // Will be incremented by the time the message is sent.\n },\n expectedMessageName: changeOwnerAcknowledgedMessageName,\n otherPeerIds,\n // If we are not the host, we should revert the ownership if the host does not acknowledge the change.\n shouldCancelMessageIfTimesOut: !gdjs.multiplayer.isCurrentPlayerHost(),\n });\n }\n\n debugLogger.info('Sending change owner message', messageName);\n this._sendDataToPeersWithIncreasedClock(messageName, messageData);\n\n // If we are the new owner, also send directly an update of the position,\n // so that the object is immediately moved on the screen and we don't wait for the next tick.\n if (newObjectPlayerNumber === currentPlayerNumber) {\n debugLogger.info(\n 'Sending update message to move the object immediately.'\n );\n const objectNetworkSyncData = this.owner.getNetworkSyncData();\n const {\n messageName: updateMessageName,\n messageData: updateMessageData,\n } = gdjs.multiplayerMessageManager.createUpdateInstanceMessage({\n objectOwner: this.playerNumber,\n objectName,\n instanceNetworkId,\n objectNetworkSyncData,\n sceneNetworkId,\n });\n this._sendDataToPeersWithIncreasedClock(\n updateMessageName,\n updateMessageData\n );\n }\n }\n\n getPlayerObjectOwnership(): number {\n return this.playerNumber;\n }\n\n isObjectOwnedByCurrentPlayer(): boolean {\n return this._isOwnerAsPlayerOrHost();\n }\n\n removeObjectOwnership() {\n // 0 means the host is the owner.\n this.setPlayerObjectOwnership(0);\n }\n\n takeObjectOwnership() {\n this.setPlayerObjectOwnership(gdjs.multiplayer.getCurrentPlayerNumber());\n }\n\n getActionOnPlayerDisconnect() {\n return this.actionOnPlayerDisconnect;\n }\n\n enableBehaviorSynchronization(behaviorName: string, enable: boolean) {\n const behavior = this.owner.getBehavior(behaviorName);\n if (!behavior) {\n logger.error(\n `Behavior ${behaviorName} does not exist on object ${this.owner.getName()}.`\n );\n return;\n }\n\n behavior.enableSynchronization(enable);\n }\n }\n gdjs.registerBehavior(\n 'Multiplayer::MultiplayerObjectBehavior',\n gdjs.MultiplayerObjectRuntimeBehavior\n );\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(l){class x{constructor(e,t){this.frameTime=0;this.stepped=!1;this.timeScale=1;this._nextJointId=1;this.joints={};this._registeredBehaviors=new Set,this.gravityX=t.gravityX,this.gravityY=t.gravityY,this.scaleX=t.scaleX||100,this.scaleY=t.scaleY||100,this.invScaleX=1/this.scaleX,this.invScaleY=1/this.scaleY,this.worldScale=t.worldScale||Math.sqrt(this.scaleX*this.scaleY),this.worldInvScale=1/this.worldScale,this.timeStep=1/60,this.world=new Box2D.b2World(new Box2D.b2Vec2(this.gravityX,this.gravityY)),this.world.SetAutoClearForces(!1),this.staticBody=this.world.CreateBody(new Box2D.b2BodyDef),this.contactListener=new Box2D.JSContactListener,this.contactListener.BeginContact=function(i){const o=Box2D.wrapPointer(i,Box2D.b2Contact);if(o.GetFixtureA().GetBody()===null||o.GetFixtureB().GetBody()===null)return;const s=o.GetFixtureA().GetBody().gdjsAssociatedBehavior,n=o.GetFixtureB().GetBody().gdjsAssociatedBehavior;!s||!n||(s.onContactBegin(n),n.onContactBegin(s))},this.contactListener.EndContact=function(i){const o=Box2D.wrapPointer(i,Box2D.b2Contact);if(o.GetFixtureA().GetBody()===null||o.GetFixtureB().GetBody()===null)return;const s=o.GetFixtureA().GetBody().gdjsAssociatedBehavior,n=o.GetFixtureB().GetBody().gdjsAssociatedBehavior;!s||!n||(s.onContactEnd(n),n.onContactEnd(s))},this.contactListener.PreSolve=function(){},this.contactListener.PostSolve=function(){},this.world.SetContactListener(this.contactListener)}static getSharedData(e,t){if(!e.physics2SharedData){const i=e.getInitialSharedDataForBehavior(t);e.physics2SharedData=new l.Physics2SharedData(e,i)}return e.physics2SharedData}addToBehaviorsList(e){this._registeredBehaviors.add(e)}removeFromBehaviorsList(e){this._registeredBehaviors.delete(e)}resetStartedAndEndedCollisions(){for(const e of this._registeredBehaviors)e.contactsStartedThisFrame.length=0,e.contactsEndedThisFrame.length=0}updateBodiesFromObjects(){for(const e of this._registeredBehaviors)e.updateBodyFromObject()}step(e){this.frameTime+=e;let t=Math.max(0,Math.round(this.frameTime/this.timeStep));this.frameTime-=t*this.timeStep,t>5&&(t=5);for(let i=0;i<t;i++)this.world.Step(this.timeStep*this.timeScale,8,10);this.world.ClearForces(),this.stepped=!0}clearBodyJoints(e){for(const t in this.joints)this.joints.hasOwnProperty(t)&&(this.joints[t].GetBodyA()===e||this.joints[t].GetBodyB()===e)&&this.removeJoint(t)}addJoint(e){return this.joints[this._nextJointId.toString(10)]=e,this._nextJointId++}getJoint(e){return e=e.toString(10),this.joints.hasOwnProperty(e)?this.joints[e]:null}getJointId(e){for(const t in this.joints)if(this.joints.hasOwnProperty(t)&&this.joints[t]===e)return parseInt(t,10);return 0}removeJoint(e){if(e=e.toString(10),this.joints.hasOwnProperty(e)){const t=this.joints[e];if(t.GetType()===Box2D.e_revoluteJoint||t.GetType()===Box2D.e_prismaticJoint)for(const i in this.joints)this.joints.hasOwnProperty(i)&&this.joints[i].GetType()===Box2D.e_gearJoint&&(Box2D.getPointer(this.joints[i].GetJoint1())===Box2D.getPointer(t)||Box2D.getPointer(this.joints[i].GetJoint2())===Box2D.getPointer(t))&&this.removeJoint(parseInt(i,10));this.world.DestroyJoint(t),delete this.joints[e]}}}l.Physics2SharedData=x,l.registerRuntimeSceneUnloadedCallback(function(J){J.physics2SharedData&&J.physics2SharedData.world&&Box2D.destroy(J.physics2SharedData.world)});const B=class extends l.RuntimeBehavior{constructor(e,t,i){super(e,t,i);this.shapeScale=1;this._body=null;this._objectOldX=0;this._objectOldY=0;this._objectOldAngle=0;this._objectOldWidth=0;this._objectOldHeight=0;this._verticesBuffer=0;this.bodyType=t.bodyType,this.bullet=t.bullet,this.fixedRotation=t.fixedRotation,this.canSleep=t.canSleep,this.shape=t.shape,this.shapeDimensionA=t.shapeDimensionA,this.shapeDimensionB=t.shapeDimensionB,this.shapeOffsetX=t.shapeOffsetX,this.shapeOffsetY=t.shapeOffsetY,this.polygonOrigin=t.polygonOrigin,this.polygon=this.shape==="Polygon"?B.getPolygon(t.vertices):null,this.density=t.density,this.friction=t.friction,this.restitution=t.restitution,this.linearDamping=Math.max(0,t.linearDamping),this.angularDamping=Math.max(0,t.angularDamping),this.gravityScale=t.gravityScale,this.layers=t.layers,this.masks=t.masks,this.contactsStartedThisFrame=[],this.contactsEndedThisFrame=[],this.currentContacts=[],this.currentContacts.length=0,this.destroyedDuringFrameLogic=!1,this._sharedData=x.getSharedData(e.getScene(),t.name),this._tempb2Vec2=new Box2D.b2Vec2,this._tempb2Vec2Sec=new Box2D.b2Vec2,this._sharedData.addToBehaviorsList(this)}b2Vec2(e,t){return this._tempb2Vec2.set_x(e),this._tempb2Vec2.set_y(t),this._tempb2Vec2}b2Vec2Sec(e,t){return this._tempb2Vec2Sec.set_x(e),this._tempb2Vec2Sec.set_y(t),this._tempb2Vec2Sec}updateFromBehaviorData(e,t){return e.bullet!==t.bullet&&this.setBullet(t.bullet),e.fixedRotation!==t.fixedRotation&&this.setFixedRotation(t.fixedRotation),e.canSleep!==t.canSleep&&this.setSleepingAllowed(t.canSleep),e.shapeDimensionA!==t.shapeDimensionA&&(this.shapeDimensionA=t.shapeDimensionA,this.recreateShape()),e.shapeDimensionB!==t.shapeDimensionB&&(this.shapeDimensionB=t.shapeDimensionB,this.recreateShape()),e.shapeOffsetX!==t.shapeOffsetX&&(this.shapeOffsetX=t.shapeOffsetX,this.recreateShape()),e.shapeOffsetY!==t.shapeOffsetY&&(this.shapeOffsetY=t.shapeOffsetY,this.recreateShape()),e.polygonOrigin!==t.polygonOrigin&&(this.polygonOrigin=t.polygonOrigin,this.recreateShape()),e.density!==t.density&&this.setDensity(t.density),e.friction!==t.friction&&this.setFriction(t.friction),e.restitution!==t.restitution&&this.setRestitution(t.restitution),e.linearDamping!==t.linearDamping&&this.setLinearDamping(t.linearDamping),e.angularDamping!==t.angularDamping&&this.setAngularDamping(t.angularDamping),e.gravityScale!==t.gravityScale&&this.setGravityScale(t.gravityScale),!(e.layers!==t.layers||e.masks!==t.masks||e.vertices!==t.vertices||e.bodyType!==t.bodyType||e.shape!==t.shape)}getNetworkSyncData(){const e=this._body?{tpx:this._body.GetTransform().get_p().get_x(),tpy:this._body.GetTransform().get_p().get_y(),tqa:this._body.GetTransform().get_q().GetAngle(),lvx:this._body.GetLinearVelocity().get_x(),lvy:this._body.GetLinearVelocity().get_y(),av:this._body.GetAngularVelocity(),aw:this._body.IsAwake()}:{tpx:void 0,tpy:void 0,tqa:void 0,lvx:void 0,lvy:void 0,av:void 0,aw:void 0};return{...super.getNetworkSyncData(),props:{...e,layers:this.layers,masks:this.masks}}}updateFromNetworkSyncData(e){super.updateFromNetworkSyncData(e);const t=e.props;t.tpx!==void 0&&t.tpy!==void 0&&t.tqa!==void 0&&this._body&&this._body.SetTransform(this.b2Vec2(t.tpx,t.tpy),t.tqa),t.lvx!==void 0&&t.lvy!==void 0&&this._body&&this._body.SetLinearVelocity(this.b2Vec2(t.lvx,t.lvy)),t.av!==void 0&&this._body&&this._body.SetAngularVelocity(t.av),t.aw!==void 0&&this._body&&this._body.SetAwake(t.aw),t.layers!==void 0&&(this.layers=t.layers),t.masks!==void 0&&(this.masks=t.masks)}onDeActivate(){this._sharedData.removeFromBehaviorsList(this),this._body!==null&&(this._sharedData.clearBodyJoints(this._body),this._verticesBuffer&&(Box2D._free(this._verticesBuffer),this._verticesBuffer=0),this._sharedData.world.DestroyBody(this._body),this._body=null),this.contactsEndedThisFrame.length=0,this.contactsStartedThisFrame.length=0,this.currentContacts.length=0}onActivate(){this._sharedData.addToBehaviorsList(this),this.contactsEndedThisFrame.length=0,this.contactsStartedThisFrame.length=0,this.currentContacts.length=0,this.updateBodyFromObject()}onDestroy(){this.destroyedDuringFrameLogic=!0,this.onDeActivate()}static getPolygon(e){if(!e)return null;const t=new l.Polygon,i=8;for(let o=0,s=e.length;o<Math.min(s,i);o++)t.vertices.push([e[o].x,e[o].y]);return t}static isPolygonConvex(e){if(!e.isConvex())return!1;let t=!0,i=!0;for(let o=0;o<e.vertices.length-1;++o){for(let s=o+1;s<e.vertices.length;++s)if(e.vertices[o][0]===e.vertices[s][0]&&e.vertices[o][1]===e.vertices[s][1])return!1;e.vertices[o][0]!==e.vertices[o+1][0]&&(t=!1),e.vertices[o][1]!==e.vertices[o+1][1]&&(i=!1)}return!(t||i)}createShape(){const e=this.shapeOffsetX?this.shapeOffsetX*this.shapeScale*this._sharedData.worldInvScale:0,t=this.shapeOffsetY?this.shapeOffsetY*this.shapeScale*this._sharedData.worldInvScale:0;let i;if(this.shape==="Circle"){if(i=new Box2D.b2CircleShape,this.shapeDimensionA>0)i.set_m_radius(this.shapeDimensionA*this.shapeScale*this._sharedData.worldInvScale);else{const n=(this.owner.getWidth()*this._sharedData.worldInvScale+this.owner.getHeight()*this._sharedData.worldInvScale)/4;i.set_m_radius(n>0?n:1)}i.set_m_p(this.b2Vec2(e,t))}else if(this.shape==="Polygon")if(i=new Box2D.b2PolygonShape,!this.polygon||!B.isPolygonConvex(this.polygon)){let n=(this.owner.getWidth()>0?this.owner.getWidth():1)*this._sharedData.worldInvScale,a=(this.owner.getHeight()>0?this.owner.getHeight():1)*this._sharedData.worldInvScale;i.SetAsBox(n/2,a/2,this.b2Vec2(e,t),0)}else{let n=0,a=0;if(this.polygonOrigin==="Origin"?(n=(this.owner.getWidth()>0?-this.owner.getWidth()/2:0)+(this.owner.getX()-this.owner.getDrawableX()),a=(this.owner.getHeight()>0?-this.owner.getHeight()/2:0)+(this.owner.getY()-this.owner.getDrawableY())):this.polygonOrigin==="TopLeft"&&(n=this.owner.getWidth()>0?-this.owner.getWidth()/2:0,a=this.owner.getHeight()>0?-this.owner.getHeight()/2:0),!this._verticesBuffer){const c=Box2D._malloc(this.polygon.vertices.length*8,"float",Box2D.ALLOC_STACK);this._verticesBuffer=c}let h=0;for(let c=0,u=this.polygon.vertices.length;c<u;c++)Box2D.HEAPF32[this._verticesBuffer+h>>2]=(this.polygon.vertices[c][0]*this.shapeScale+n)*this._sharedData.worldInvScale+e,Box2D.HEAPF32[this._verticesBuffer+(h+4)>>2]=(this.polygon.vertices[c][1]*this.shapeScale+a)*this._sharedData.worldInvScale+t,h+=8;const d=Box2D.wrapPointer(this._verticesBuffer,Box2D.b2Vec2);i.Set(d,this.polygon.vertices.length)}else if(this.shape==="Edge"){i=new Box2D.b2EdgeShape;const n=(this.shapeDimensionA>0?this.shapeDimensionA*this.shapeScale:this.owner.getWidth()>0?this.owner.getWidth():1)*this._sharedData.worldInvScale;let a=this.owner.getHeight()>0?this.owner.getHeight()*this._sharedData.worldInvScale:0;const h=this.shapeDimensionB?l.toRad(this.shapeDimensionB):0;i.Set(this.b2Vec2(-n/2*Math.cos(h)+e,a/2-n/2*Math.sin(h)+t),this.b2Vec2Sec(n/2*Math.cos(h)+e,a/2+n/2*Math.sin(h)+t))}else{i=new Box2D.b2PolygonShape;let n=(this.shapeDimensionA>0?this.shapeDimensionA*this.shapeScale:this.owner.getWidth()>0?this.owner.getWidth():1)*this._sharedData.worldInvScale,a=(this.shapeDimensionB>0?this.shapeDimensionB*this.shapeScale:this.owner.getHeight()>0?this.owner.getHeight():1)*this._sharedData.worldInvScale;i.SetAsBox(n/2,a/2,this.b2Vec2(e,t),0)}const o=new Box2D.b2Filter;o.set_categoryBits(this.layers),o.set_maskBits(this.masks);const s=new Box2D.b2FixtureDef;return s.set_shape(i),s.set_filter(o),this.density<0&&(this.density=0),s.set_density(this.density),this.friction<0&&(this.friction=0),s.set_friction(this.friction),this.restitution<0&&(this.restitution=0),s.set_restitution(this.restitution),s}recreateShape(){if(this._body===null&&!this.createBody())return;const e=this._body;e.DestroyFixture(e.GetFixtureList()),e.CreateFixture(this.createShape()),this._objectOldWidth=this.owner.getWidth(),this._objectOldHeight=this.owner.getHeight()}getShapeScale(){return this.shapeScale}setShapeScale(e){e!==this.shapeScale&&e>0&&(this.shapeScale=e,this.recreateShape())}getBody(){return this._body===null&&this.createBody(),this._body}createBody(){if(!this.activated()||this.destroyedDuringFrameLogic)return!1;const e=new Box2D.b2BodyDef,t=(this.owner.getDrawableX()+this.owner.getWidth()/2)*this._sharedData.worldInvScale,i=(this.owner.getDrawableY()+this.owner.getHeight()/2)*this._sharedData.worldInvScale;e.set_position(this.b2Vec2(Number.isFinite(t)?t:0,Number.isFinite(i)?i:0));const o=l.toRad(this.owner.getAngle());return Number.isFinite(o)&&e.set_angle(o),e.set_type(this.bodyType==="Static"?Box2D.b2_staticBody:this.bodyType==="Kinematic"?Box2D.b2_kinematicBody:Box2D.b2_dynamicBody),e.set_bullet(this.bullet),e.set_fixedRotation(this.fixedRotation),e.set_allowSleep(this.canSleep),e.set_linearDamping(this.linearDamping),e.set_angularDamping(this.angularDamping),e.set_gravityScale(this.gravityScale),this._body=this._sharedData.world.CreateBody(e),this._body.CreateFixture(this.createShape()),this._body.gdjsAssociatedBehavior=this,this._objectOldWidth=this.owner.getWidth(),this._objectOldHeight=this.owner.getHeight(),!0}doStepPreEvents(e){!this._sharedData.stepped&&!e.getScene().getTimeManager().isFirstFrame()&&(this._sharedData.resetStartedAndEndedCollisions(),this._sharedData.updateBodiesFromObjects(),this._sharedData.step(e.getScene().getTimeManager().getElapsedTime()/1e3)),this._body!==null&&(this.owner.setX(this._body.GetPosition().get_x()*this._sharedData.worldScale-this.owner.getWidth()/2+this.owner.getX()-this.owner.getDrawableX()),this.owner.setY(this._body.GetPosition().get_y()*this._sharedData.worldScale-this.owner.getHeight()/2+this.owner.getY()-this.owner.getDrawableY()),this.owner.setAngle(l.toDegrees(this._body.GetAngle()))),this._objectOldX=this.owner.getX(),this._objectOldY=this.owner.getY(),this._objectOldAngle=this.owner.getAngle()}doStepPostEvents(e){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}updateBodyFromObject(){if(this._body===null&&!this.createBody())return;const e=this._body;if((this._objectOldWidth!==this.owner.getWidth()&&this.shapeDimensionA<=0||this._objectOldHeight!==this.owner.getHeight()&&this.shape!=="Edge"&&!(this.shape==="Box"&&this.shapeDimensionB>0)&&!(this.shape==="Circle"&&this.shapeDimensionA>0))&&this.recreateShape(),this._objectOldX!==this.owner.getX()||this._objectOldY!==this.owner.getY()||this._objectOldAngle!==this.owner.getAngle()){const t=(this.owner.getDrawableX()+this.owner.getWidth()/2)*this._sharedData.worldInvScale,i=(this.owner.getDrawableY()+this.owner.getHeight()/2)*this._sharedData.worldInvScale,o=this.b2Vec2(Number.isFinite(t)?t:e.GetPosition().x,Number.isFinite(i)?i:e.GetPosition().y),s=l.toRad(this.owner.getAngle());e.SetTransform(o,Number.isFinite(s)?s:e.GetAngle()),e.SetAwake(!0)}}getWorldScale(){return this._sharedData.worldScale}getGravityX(){return this._sharedData.gravityX}getGravityY(){return this._sharedData.gravityY}setGravity(e,t){this._sharedData.gravityX===e&&this._sharedData.gravityY===t||(this._sharedData.gravityX=e,this._sharedData.gravityY=t,this._sharedData.world.SetGravity(this.b2Vec2(this._sharedData.gravityX,this._sharedData.gravityY)))}getTimeScale(){return this._sharedData.timeScale}setTimeScale(e){e<0||(this._sharedData.timeScale=e)}static setTimeScaleFromObject(e,t,i){e===null||!e.hasBehavior(t)||e.getBehavior(t).setTimeScale(i)}isDynamic(){return this.bodyType==="Dynamic"}setDynamic(){if(this.bodyType==="Dynamic"||(this.bodyType="Dynamic",this._body===null&&!this.createBody()))return;const e=this._body;e.SetType(Box2D.b2_dynamicBody),e.SetAwake(!0)}isStatic(){return this.bodyType==="Static"}setStatic(){if(this.bodyType==="Static"||(this.bodyType="Static",this._body===null&&!this.createBody()))return;const e=this._body;e.SetType(Box2D.b2_staticBody),e.SetAwake(!0)}isKinematic(){return this.bodyType==="Kinematic"}setKinematic(){if(this.bodyType==="Kinematic"||(this.bodyType="Kinematic",this._body===null&&!this.createBody()))return;const e=this._body;e.SetType(Box2D.b2_kinematicBody),e.SetAwake(!0)}isBullet(){return this.bullet}setBullet(e){if(this.bullet===e||(this.bullet=e,this._body===null&&!this.createBody()))return;this._body.SetBullet(this.bullet)}hasFixedRotation(){return this.fixedRotation}setFixedRotation(e){if(this.fixedRotation=e,this._body===null&&!this.createBody())return;this._body.SetFixedRotation(this.fixedRotation)}isSleepingAllowed(){return this.canSleep}setSleepingAllowed(e){if(this.canSleep=e,this._body===null&&!this.createBody())return;this._body.SetSleepingAllowed(this.canSleep)}isSleeping(){return this._body===null&&!this.createBody()?!0:!this._body.IsAwake()}getDensity(){return this.density}setDensity(e){if(e<0&&(e=0),this.density===e||(this.density=e,this._body===null&&!this.createBody()))return;const t=this._body;t.GetFixtureList().SetDensity(this.density),t.ResetMassData()}getFriction(){return this.friction}setFriction(e){if(e<0&&(e=0),this.friction===e||(this.friction=e,this._body===null&&!this.createBody()))return;const t=this._body;t.GetFixtureList().SetFriction(this.friction);let i=t.GetContactList();for(;Box2D.getPointer(i);)i.get_contact().ResetFriction(),i=i.get_next()}getRestitution(){return this.restitution}setRestitution(e){if(e<0&&(e=0),this.restitution===e||(this.restitution=e,this._body===null&&!this.createBody()))return;const t=this._body;t.GetFixtureList().SetRestitution(this.restitution);let i=t.GetContactList();for(;Box2D.getPointer(i);)i.get_contact().ResetRestitution(),i=i.get_next()}getLinearDamping(){return this.linearDamping}setLinearDamping(e){if(e<0&&(e=0),this.linearDamping===e||(this.linearDamping=e,this._body===null&&!this.createBody()))return;this._body.SetLinearDamping(this.linearDamping)}getAngularDamping(){return this.angularDamping}setAngularDamping(e){if(e<0&&(e=0),this.angularDamping===e||(this.angularDamping=e,this._body===null&&!this.createBody()))return;this._body.SetAngularDamping(this.angularDamping)}getGravityScale(){return this.gravityScale}setGravityScale(e){if(this.gravityScale===e||(this.gravityScale=e,this._body===null&&!this.createBody()))return;this._body.SetGravityScale(this.gravityScale)}layerEnabled(e){return e=Math.floor(e),e<1||e>16?!1:!!(this.layers&1<<e-1)}enableLayer(e,t){if(e=Math.floor(e),e<1||e>16||(t?this.layers|=1<<e-1:this.layers&=~(1<<e-1),this._body===null&&!this.createBody()))return;const i=this._body,o=i.GetFixtureList().GetFilterData();o.set_categoryBits(this.layers),i.GetFixtureList().SetFilterData(o)}maskEnabled(e){return e=Math.floor(e),e<1||e>16?!1:!!(this.masks&1<<e-1)}enableMask(e,t){if(e=Math.floor(e),e<1||e>16||(t?this.masks|=1<<e-1:this.masks&=~(1<<e-1),this._body===null&&!this.createBody()))return;const i=this._body,o=i.GetFixtureList().GetFilterData();o.set_maskBits(this.masks),i.GetFixtureList().SetFilterData(o)}getLinearVelocityX(){return this._body===null&&!this.createBody()?0:this._body.GetLinearVelocity().get_x()*this._sharedData.worldScale}setLinearVelocityX(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetLinearVelocity(this.b2Vec2(e*this._sharedData.worldInvScale,t.GetLinearVelocity().get_y()))}getLinearVelocityY(){return this._body===null&&!this.createBody()?0:this._body.GetLinearVelocity().get_y()*this._sharedData.worldScale}setLinearVelocityY(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetLinearVelocity(this.b2Vec2(t.GetLinearVelocity().get_x(),e*this._sharedData.worldInvScale))}getLinearVelocityLength(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return this.b2Vec2(e.GetLinearVelocity().get_x()*this._sharedData.worldScale,e.GetLinearVelocity().get_y()*this._sharedData.worldScale).Length()}getLinearVelocityAngle(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return l.toDegrees(Math.atan2(e.GetLinearVelocity().get_y()*this._sharedData.worldScale,e.GetLinearVelocity().get_x()*this._sharedData.worldScale))}setLinearVelocityAngle(e,t){if(this._body===null&&!this.createBody())return;const i=this._body;e=l.toRad(e),i.SetLinearVelocity(this.b2Vec2(t*Math.cos(e)*this._sharedData.worldInvScale,t*Math.sin(e)*this._sharedData.worldInvScale))}isLinearVelocityAngleAround(e,t){return Math.abs(l.evtTools.common.angleDifference(this.getLinearVelocityAngle(),e))<=t}getAngularVelocity(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return l.toDegrees(e.GetAngularVelocity())}setAngularVelocity(e){if(this._body===null&&!this.createBody())return;this._body.SetAngularVelocity(l.toRad(e))}applyForce(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),s.ApplyForce(this.b2Vec2(e,t),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyPolarForce(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),e=l.toRad(e),s.ApplyForce(this.b2Vec2(t*Math.cos(e),t*Math.sin(e)),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyForceTowardPosition(e,t,i,o,s){if(this._body===null&&!this.createBody())return;const n=this._body;n.SetAwake(!0);const a=Math.atan2(i*this._sharedData.worldInvScale-n.GetPosition().get_y(),t*this._sharedData.worldInvScale-n.GetPosition().get_x());n.ApplyForce(this.b2Vec2(e*Math.cos(a),e*Math.sin(a)),this.b2Vec2Sec(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale),!1)}applyImpulse(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),s.ApplyLinearImpulse(this.b2Vec2(e,t),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyPolarImpulse(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),e=l.toRad(e),s.ApplyLinearImpulse(this.b2Vec2(t*Math.cos(e),t*Math.sin(e)),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyImpulseTowardPosition(e,t,i,o,s){if(this._body===null&&!this.createBody())return;const n=this._body;n.SetAwake(!0);const a=Math.atan2(i*this._sharedData.worldInvScale-n.GetPosition().get_y(),t*this._sharedData.worldInvScale-n.GetPosition().get_x());n.ApplyLinearImpulse(this.b2Vec2(e*Math.cos(a),e*Math.sin(a)),this.b2Vec2Sec(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale),!1)}applyTorque(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetAwake(!0),t.ApplyTorque(e,!1)}applyAngularImpulse(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetAwake(!0),t.ApplyAngularImpulse(e,!1)}getMass(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return e.SetAwake(!0),e.GetMass()}getInertia(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return e.SetAwake(!0),e.GetInertia()}getMassCenterX(){return this._body===null&&!this.createBody()?0:this._body.GetWorldCenter().get_x()*this._sharedData.worldScale}getMassCenterY(){return this._body===null&&!this.createBody()?0:this._body.GetWorldCenter().get_y()*this._sharedData.worldScale}isJointFirstObject(e){if(this._body===null&&!this.createBody())return!1;const t=this._sharedData.getJoint(e);return t===null?!1:t.GetBodyA()===this._body}isJointSecondObject(e){if(this._body===null&&!this.createBody())return!1;const t=this._sharedData.getJoint(e);return t===null?!1:t.GetBodyB()===this._body}getJointFirstAnchorX(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyA().GetWorldPoint(t.GetLocalAnchorA()).get_x()}getJointFirstAnchorY(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyA().GetWorldPoint(t.GetLocalAnchorA()).get_y()}getJointSecondAnchorX(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyB().GetWorldPoint(t.GetLocalAnchorB()).get_x()}getJointSecondAnchorY(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyB().GetWorldPoint(t.GetLocalAnchorB()).get_y()}getJointReactionForce(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetReactionForce(1/this._sharedData.timeStep).Length()}getJointReactionTorque(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetReactionTorque(1/this._sharedData.timeStep)}removeJoint(e){this._sharedData.removeJoint(e)}addDistanceJoint(e,t,i,o,s,n,a,h,d,c){if(this._body===null&&!this.createBody())return;const u=this._body;if(i==null||!i.hasBehavior(this.name))return;const r=i.getBehavior(this.name).getBody();if(this._body===r)return;const f=new Box2D.b2DistanceJointDef;f.set_bodyA(u),f.set_localAnchorA(u.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),f.set_bodyB(r),f.set_localAnchorB(r.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),f.set_length(n>0?n*this._sharedData.worldInvScale:this.b2Vec2((o-e)*this._sharedData.worldInvScale,(s-t)*this._sharedData.worldInvScale).Length()),f.set_frequencyHz(a>=0?a:0),f.set_dampingRatio(h>=0?h:1),f.set_collideConnected(d);const D=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(f),Box2D.b2DistanceJoint));c.setNumber(D)}getDistanceJointLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_distanceJoint?0:t.GetLength()*this._sharedData.worldScale}setDistanceJointLength(e,t){if(t<=0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_distanceJoint||(i.SetLength(t*this._sharedData.worldInvScale),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}getDistanceJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_distanceJoint?0:t.GetFrequency()}setDistanceJointFrequency(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_distanceJoint||i.SetFrequency(t)}getDistanceJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_distanceJoint?0:t.GetDampingRatio()}setDistanceJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_distanceJoint,i.SetDampingRatio(t)}addRevoluteJoint(e,t,i,o,s,n,a,h,d,c){if(this._body===null&&!this.createBody())return;const u=this._body,r=new Box2D.b2RevoluteJointDef;if(r.set_bodyA(this._sharedData.staticBody),r.set_localAnchorA(this._sharedData.staticBody.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),r.set_bodyB(u),r.set_localAnchorB(u.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),r.set_enableLimit(i),r.set_referenceAngle(l.toRad(o)),n<s){const D=s;s=n,n=D}r.set_lowerAngle(l.toRad(s)),r.set_upperAngle(l.toRad(n)),r.set_enableMotor(a),r.set_motorSpeed(l.toRad(h)),r.set_maxMotorTorque(d>=0?d:0),r.set_collideConnected(!1);const f=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(r),Box2D.b2RevoluteJoint));c.setNumber(f)}addRevoluteJointBetweenTwoBodies(e,t,i,o,s,n,a,h,d,c,u,r,f,D){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const b=i.getBehavior(this.name).getBody();if(this._body===b)return;const _=this._body,g=new Box2D.b2RevoluteJointDef;if(g.set_bodyA(_),g.set_localAnchorA(_.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),g.set_bodyB(b),g.set_localAnchorB(b.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),g.set_enableLimit(n),g.set_referenceAngle(l.toRad(a)),d<h){const p=h;h=d,d=p}g.set_lowerAngle(l.toRad(h)),g.set_upperAngle(l.toRad(d)),g.set_enableMotor(c),g.set_motorSpeed(l.toRad(u)),g.set_maxMotorTorque(r>=0?r:0),g.set_collideConnected(f);const y=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2RevoluteJoint));D.setNumber(y)}getRevoluteJointReferenceAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetReferenceAngle())}getRevoluteJointAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetJointAngle())}getRevoluteJointSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetJointSpeed())}isRevoluteJointLimitsEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?!1:t.IsLimitEnabled()}enableRevoluteJointLimits(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.EnableLimit(t)}getRevoluteJointMinAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetLowerLimit())}getRevoluteJointMaxAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetUpperLimit())}setRevoluteJointLimits(e,t,i){const o=this._sharedData.getJoint(e);if(!(o===null||o.GetType()!==Box2D.e_revoluteJoint)){if(i<t){const s=t;t=i,i=s}o.SetLimits(l.toRad(t),l.toRad(i))}}isRevoluteJointMotorEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?!1:t.IsMotorEnabled()}enableRevoluteJointMotor(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.EnableMotor(t)}getRevoluteJointMotorSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetMotorSpeed())}setRevoluteJointMotorSpeed(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.SetMotorSpeed(l.toRad(t))}getRevoluteJointMaxMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:t.GetMaxMotorTorque()}setRevoluteJointMaxMotorTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.SetMaxMotorTorque(t)}getRevoluteJointMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:t.GetMotorTorque(1/this._sharedData.timeStep)}addPrismaticJoint(e,t,i,o,s,n,a,h,d,c,u,r,f,D,b){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const _=i.getBehavior(this.name).getBody();if(this._body===_)return;const g=this._body,y=new Box2D.b2PrismaticJointDef;if(y.set_bodyA(g),y.set_localAnchorA(g.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),y.set_bodyB(_),y.set_localAnchorB(_.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-g.GetAngle(),y.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),y.set_referenceAngle(l.toRad(a)),y.set_enableLimit(h),c<d){const m=d;d=c,c=m}y.set_lowerTranslation(d<0?d*this._sharedData.worldInvScale:0),y.set_upperTranslation(c>0?c*this._sharedData.worldInvScale:0),y.set_enableMotor(u),y.set_motorSpeed(r*this._sharedData.worldInvScale),y.set_maxMotorForce(f),y.set_collideConnected(D);const p=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(y),Box2D.b2PrismaticJoint));b.setNumber(p)}getPrismaticJointAxisAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:l.toDegrees(Math.atan2(t.GetLocalAxisA().get_y(),t.GetLocalAxisA().get_x())+t.GetBodyA().GetAngle())}getPrismaticJointReferenceAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:l.toDegrees(t.GetReferenceAngle())}getPrismaticJointTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetJointTranslation()*this._sharedData.worldScale}getPrismaticJointSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetJointSpeed()*this._sharedData.worldScale}isPrismaticJointLimitsEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?!1:t.IsLimitEnabled()}enablePrismaticJointLimits(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.EnableLimit(t)}getPrismaticJointMinTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetLowerLimit()*this._sharedData.worldScale}getPrismaticJointMaxTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetUpperLimit()*this._sharedData.worldScale}setPrismaticJointLimits(e,t,i){const o=this._sharedData.getJoint(e);if(!(o===null||o.GetType()!==Box2D.e_prismaticJoint)){if(i<t){const s=t;t=i,i=s}t=t<0?t:0,i=i>0?i:0,o.SetLimits(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale)}}isPrismaticJointMotorEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?!1:t.IsMotorEnabled()}enablePrismaticJointMotor(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.EnableMotor(t)}getPrismaticJointMotorSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetMotorSpeed()*this._sharedData.worldScale}setPrismaticJointMotorSpeed(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.SetMotorSpeed(t*this._sharedData.worldInvScale)}getPrismaticJointMaxMotorForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetMaxMotorForce()}setPrismaticJointMaxMotorForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.SetMaxMotorForce(t)}getPrismaticJointMotorForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetMotorForce(1/this._sharedData.timeStep)}addPulleyJoint(e,t,i,o,s,n,a,h,d,c,u,r,f,D){if(this._body===null&&!this.createBody())return;const b=this._body;if(i==null||!i.hasBehavior(this.name))return;const _=i.getBehavior(this.name).getBody();if(this._body===_)return;const g=new Box2D.b2PulleyJointDef;g.set_bodyA(b),g.set_localAnchorA(b.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),g.set_bodyB(_),g.set_localAnchorB(_.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),g.set_groundAnchorA(this.b2Vec2(n*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale)),g.set_groundAnchorB(this.b2Vec2(h*this._sharedData.worldInvScale,d*this._sharedData.worldInvScale)),g.set_lengthA(c>0?c*this._sharedData.worldInvScale:this.b2Vec2((n-e)*this._sharedData.worldInvScale,(a-t)*this._sharedData.worldInvScale).Length()),g.set_lengthB(u>0?u*this._sharedData.worldInvScale:this.b2Vec2((h-o)*this._sharedData.worldInvScale,(d-s)*this._sharedData.worldInvScale).Length()),g.set_ratio(r>0?r:1),g.set_collideConnected(f);const y=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2PulleyJoint));D.setNumber(y)}getPulleyJointFirstGroundAnchorX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorA().get_x()*this._sharedData.worldScale}getPulleyJointFirstGroundAnchorY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorA().get_y()*this._sharedData.worldScale}getPulleyJointSecondGroundAnchorX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorB().get_x()*this._sharedData.worldScale}getPulleyJointSecondGroundAnchorY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorB().get_y()*this._sharedData.worldScale}getPulleyJointFirstLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetCurrentLengthA()*this._sharedData.worldScale}getPulleyJointSecondLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetCurrentLengthB()*this._sharedData.worldScale}getPulleyJointRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetRatio()}addGearJoint(e,t,i,o,s){if(this._body===null&&!this.createBody())return;const n=this._body,a=this._sharedData.getJoint(e);if(a===null||a.GetType()!==Box2D.e_revoluteJoint&&a.GetType()!==Box2D.e_prismaticJoint)return;const h=this._sharedData.getJoint(t);if(h===null||h.GetType()!==Box2D.e_revoluteJoint&&h.GetType()!==Box2D.e_prismaticJoint||a===h)return;const d=new Box2D.b2GearJointDef;d.set_bodyA(this._sharedData.staticBody),d.set_bodyB(n),d.set_joint1(a),d.set_joint2(h),d.set_ratio(i),d.set_collideConnected(o);const c=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(d),Box2D.b2GearJoint));s.setNumber(c)}getGearJointFirstJoint(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_gearJoint?0:this._sharedData.getJointId(t.GetJoint1())}getGearJointSecondJoint(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_gearJoint?0:this._sharedData.getJointId(t.GetJoint2())}getGearJointRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_gearJoint?0:t.GetRatio()}setGearJointRatio(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_gearJoint||(i.SetRatio(t),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}addMouseJoint(e,t,i,o,s,n){if(this._body===null&&!this.createBody())return;const a=this._body,h=new Box2D.b2MouseJointDef;h.set_bodyA(this._sharedData.staticBody),h.set_bodyB(a),h.set_target(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale)),h.set_maxForce(i>=0?i:0),h.set_frequencyHz(o>0?o:1),h.set_dampingRatio(s>=0?s:0);const d=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(h),Box2D.b2MouseJoint));n.setNumber(d)}getMouseJointTargetX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetTarget().get_x()*this._sharedData.worldScale}getMouseJointTargetY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetTarget().get_y()*this._sharedData.worldScale}setMouseJointTarget(e,t,i){const o=this._sharedData.getJoint(e);o===null||o.GetType()!==Box2D.e_mouseJoint||(o.SetTarget(this.b2Vec2(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale)),o.GetBodyB().SetAwake(!0))}getMouseJointMaxForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetMaxForce()}setMouseJointMaxForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_mouseJoint||i.SetMaxForce(t)}getMouseJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetFrequency()}setMouseJointFrequency(e,t){if(t<=0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_mouseJoint||i.SetFrequency(t)}getMouseJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetDampingRatio()}setMouseJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_mouseJoint||i.SetDampingRatio(t)}addWheelJoint(e,t,i,o,s,n,a,h,d,c,u,r,f){if(this._body===null&&!this.createBody())return;const D=this._body;if(i==null||!i.hasBehavior(this.name))return;const b=i.getBehavior(this.name).getBody();if(this._body===b)return;const _=new Box2D.b2WheelJointDef;_.set_bodyA(D),_.set_localAnchorA(D.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),_.set_bodyB(b),_.set_localAnchorB(b.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-D.GetAngle(),_.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),_.set_frequencyHz(a>0?a:1),_.set_dampingRatio(h>=0?h:0),_.set_enableMotor(d),_.set_motorSpeed(l.toRad(c)),_.set_maxMotorTorque(u),_.set_collideConnected(r);const g=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(_),Box2D.b2WheelJoint));f.setNumber(g)}getWheelJointAxisAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:l.toDegrees(Math.atan2(t.GetLocalAxisA().get_y(),t.GetLocalAxisA().get_x())+t.GetBodyA().GetAngle())}getWheelJointTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetJointTranslation()*this._sharedData.worldScale}getWheelJointSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:l.toDegrees(t.GetJointSpeed())}isWheelJointMotorEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?!1:t.IsMotorEnabled()}enableWheelJointMotor(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.EnableMotor(t)}getWheelJointMotorSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:l.toDegrees(t.GetMotorSpeed())}setWheelJointMotorSpeed(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetMotorSpeed(l.toRad(t))}getWheelJointMaxMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetMaxMotorTorque()}setWheelJointMaxMotorTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetMaxMotorTorque(t)}getWheelJointMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetMotorTorque(1/this._sharedData.timeStep)}getWheelJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetSpringFrequencyHz()}setWheelJointFrequency(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetSpringFrequencyHz(t)}getWheelJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetSpringDampingRatio()}setWheelJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetSpringDampingRatio(t)}addWeldJoint(e,t,i,o,s,n,a,h,d,c){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const u=i.getBehavior(this.name).getBody();if(this._body===u)return;const r=this._body,f=new Box2D.b2WeldJointDef;f.set_bodyA(r),f.set_localAnchorA(r.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),f.set_bodyB(u),f.set_localAnchorB(u.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),f.set_referenceAngle(l.toRad(n)),f.set_frequencyHz(a>0?a:1),f.set_dampingRatio(h>=0?h:0),f.set_collideConnected(d);const D=Box2D.castObject(this._sharedData.world.CreateJoint(f),Box2D.b2WeldJoint);D.referenceAngle=f.get_referenceAngle(),c.setNumber(this._sharedData.addJoint(D))}getWeldJointReferenceAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_weldJoint?0:l.toDegrees(t.referenceAngle)}getWeldJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_weldJoint?0:t.GetFrequency()}setWeldJointFrequency(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_weldJoint||i.SetFrequency(t)}getWeldJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_weldJoint?0:t.GetDampingRatio()}setWeldJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_weldJoint||i.SetDampingRatio(t)}addRopeJoint(e,t,i,o,s,n,a,h){if(this._body===null&&!this.createBody())return;const d=this._body;if(i==null||!i.hasBehavior(this.name))return;const c=i.getBehavior(this.name).getBody();if(this._body===c)return;const u=new Box2D.b2RopeJointDef;u.set_bodyA(d),u.set_localAnchorA(d.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),u.set_bodyB(c),u.set_localAnchorB(c.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),u.set_maxLength(n>0?n*this._sharedData.worldInvScale:this.b2Vec2((o-e)*this._sharedData.worldInvScale,(s-t)*this._sharedData.worldInvScale).Length()),u.set_collideConnected(a);const r=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(u),Box2D.b2RopeJoint));h.setNumber(r)}getRopeJointMaxLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_ropeJoint?0:t.GetMaxLength()*this._sharedData.worldScale}setRopeJointMaxLength(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_ropeJoint||(i.SetMaxLength(t*this._sharedData.worldInvScale),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}addFrictionJoint(e,t,i,o,s,n,a,h,d){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const c=i.getBehavior(this.name).getBody();if(this._body===c)return;const u=this._body,r=new Box2D.b2FrictionJointDef;r.set_bodyA(u),r.set_localAnchorA(u.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),r.set_bodyB(c),r.set_localAnchorB(c.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),r.set_maxForce(n>=0?n:0),r.set_maxTorque(a>=0?a:0),r.set_collideConnected(h);const f=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(r),Box2D.b2FrictionJoint));d.setNumber(f)}getFrictionJointMaxForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_frictionJoint?0:t.GetMaxForce()}setFrictionJointMaxForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_frictionJoint||i.SetMaxForce(t)}getFrictionJointMaxTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_frictionJoint?0:t.GetMaxTorque()}setFrictionJointMaxTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_frictionJoint||i.SetMaxTorque(t)}addMotorJoint(e,t,i,o,s,n,a,h,d){if(this._body===null&&!this.createBody())return;const c=this._body;if(e==null||!e.hasBehavior(this.name))return;const u=e.getBehavior(this.name).getBody();if(this._body===u)return;const r=new Box2D.b2MotorJointDef;r.set_bodyA(c),r.set_bodyB(u),r.set_linearOffset(this.b2Vec2(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale)),r.set_angularOffset(l.toRad(o)),r.set_maxForce(s>=0?s:0),r.set_maxTorque(n>=0?n:0),r.set_correctionFactor(a<0?0:a>1?1:a),r.set_collideConnected(h);const f=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(r),Box2D.b2MotorJoint));d.setNumber(f)}getMotorJointOffsetX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetLinearOffset().get_x()*this._sharedData.worldScale}getMotorJointOffsetY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetLinearOffset().get_y()*this._sharedData.worldScale}setMotorJointOffset(e,t,i){const o=this._sharedData.getJoint(e);o===null||o.GetType()!==Box2D.e_motorJoint||o.SetLinearOffset(this.b2Vec2(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale))}getMotorJointAngularOffset(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:l.toDegrees(t.GetAngularOffset())}setMotorJointAngularOffset(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||i.SetAngularOffset(l.toRad(t))}getMotorJointMaxForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetMaxForce()}setMotorJointMaxForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||i.SetMaxForce(t)}getMotorJointMaxTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetMaxTorque()}setMotorJointMaxTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||(i.SetMaxTorque(t),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}getMotorJointCorrectionFactor(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetCorrectionFactor()}setMotorJointCorrectionFactor(e,t){if(t<0||t>1)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||(i.SetCorrectionFactor(t),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}onContactBegin(e){this.currentContacts.push(e);let t=this.contactsEndedThisFrame.indexOf(e);t!==-1?this.contactsEndedThisFrame.splice(t,1):this.contactsStartedThisFrame.push(e)}onContactEnd(e){this.contactsEndedThisFrame.push(e);const t=this.currentContacts.indexOf(e);t!==-1&&this.currentContacts.splice(t,1)}static areObjectsColliding(e,t,i){const o=e.getBehavior(i);return o?!!(o.currentContacts.some(s=>s.owner===t)||o.contactsStartedThisFrame.some(s=>s.owner===t)):!1}static hasCollisionStartedBetween(e,t,i){const o=e.getBehavior(i);return o?o.contactsStartedThisFrame.some(s=>s.owner===t):!1}static hasCollisionStoppedBetween(e,t,i){const o=e.getBehavior(i);return o?o.contactsEndedThisFrame.some(s=>s.owner===t):!1}};let S=B;S.collisionTest=B.areObjectsColliding,l.Physics2RuntimeBehavior=S,l.registerBehavior("Physics2::Physics2Behavior",l.Physics2RuntimeBehavior)})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(l){class x{constructor(e,t){this.frameTime=0;this.stepped=!1;this.timeScale=1;this._nextJointId=1;this.joints={};this._tempb2Vec2=new Box2D.b2Vec2(0,0);this._tempb2Vec2Sec=new Box2D.b2Vec2(0,0);this._registeredBehaviors=new Set,this.gravityX=t.gravityX,this.gravityY=t.gravityY,this.scaleX=t.scaleX||100,this.scaleY=t.scaleY||100,this.invScaleX=1/this.scaleX,this.invScaleY=1/this.scaleY,this.worldScale=t.worldScale||Math.sqrt(this.scaleX*this.scaleY),this.worldInvScale=1/this.worldScale,this.timeStep=1/60,this.world=new Box2D.b2World(this.b2Vec2(this.gravityX,this.gravityY)),this.world.SetAutoClearForces(!1),this.staticBody=this.world.CreateBody(new Box2D.b2BodyDef),this.contactListener=new Box2D.JSContactListener,this.contactListener.BeginContact=function(i){const o=Box2D.wrapPointer(i,Box2D.b2Contact);if(o.GetFixtureA().GetBody()===null||o.GetFixtureB().GetBody()===null)return;const s=o.GetFixtureA().GetBody().gdjsAssociatedBehavior,n=o.GetFixtureB().GetBody().gdjsAssociatedBehavior;!s||!n||(s.onContactBegin(n),n.onContactBegin(s))},this.contactListener.EndContact=function(i){const o=Box2D.wrapPointer(i,Box2D.b2Contact);if(o.GetFixtureA().GetBody()===null||o.GetFixtureB().GetBody()===null)return;const s=o.GetFixtureA().GetBody().gdjsAssociatedBehavior,n=o.GetFixtureB().GetBody().gdjsAssociatedBehavior;!s||!n||(s.onContactEnd(n),n.onContactEnd(s))},this.contactListener.PreSolve=function(){},this.contactListener.PostSolve=function(){},this.world.SetContactListener(this.contactListener)}b2Vec2(e,t){const i=this._tempb2Vec2;return i.set_x(e),i.set_y(t),i}static getSharedData(e,t){if(!e.physics2SharedData){const i=e.getInitialSharedDataForBehavior(t);e.physics2SharedData=new l.Physics2SharedData(e,i)}return e.physics2SharedData}addToBehaviorsList(e){this._registeredBehaviors.add(e)}removeFromBehaviorsList(e){this._registeredBehaviors.delete(e)}resetStartedAndEndedCollisions(){for(const e of this._registeredBehaviors)e.contactsStartedThisFrame.length=0,e.contactsEndedThisFrame.length=0}updateBodiesFromObjects(){for(const e of this._registeredBehaviors)e.updateBodyFromObject()}step(e){this.frameTime+=e;let t=Math.max(0,Math.round(this.frameTime/this.timeStep));this.frameTime-=t*this.timeStep,t>5&&(t=5);for(let i=0;i<t;i++)this.world.Step(this.timeStep*this.timeScale,8,10);this.world.ClearForces(),this.stepped=!0}clearBodyJoints(e){for(const t in this.joints)this.joints.hasOwnProperty(t)&&(this.joints[t].GetBodyA()===e||this.joints[t].GetBodyB()===e)&&this.removeJoint(t)}addJoint(e){return this.joints[this._nextJointId.toString(10)]=e,this._nextJointId++}getJoint(e){return e=e.toString(10),this.joints.hasOwnProperty(e)?this.joints[e]:null}getJointId(e){for(const t in this.joints)if(this.joints.hasOwnProperty(t)&&this.joints[t]===e)return parseInt(t,10);return 0}removeJoint(e){if(e=e.toString(10),this.joints.hasOwnProperty(e)){const t=this.joints[e];if(t.GetType()===Box2D.e_revoluteJoint||t.GetType()===Box2D.e_prismaticJoint)for(const i in this.joints)this.joints.hasOwnProperty(i)&&this.joints[i].GetType()===Box2D.e_gearJoint&&(Box2D.getPointer(this.joints[i].GetJoint1())===Box2D.getPointer(t)||Box2D.getPointer(this.joints[i].GetJoint2())===Box2D.getPointer(t))&&this.removeJoint(parseInt(i,10));this.world.DestroyJoint(t),delete this.joints[e]}}}l.Physics2SharedData=x,l.registerRuntimeSceneUnloadedCallback(function(S){const e=S.physics2SharedData;e&&e.world&&(Box2D.destroy(e.world),Box2D.destroy(e._tempb2Vec2),Box2D.destroy(e._tempb2Vec2Sec))});const B=class extends l.RuntimeBehavior{constructor(e,t,i){super(e,t,i);this.shapeScale=1;this._body=null;this._objectOldX=0;this._objectOldY=0;this._objectOldAngle=0;this._objectOldWidth=0;this._objectOldHeight=0;this._verticesBuffer=0;this.bodyType=t.bodyType,this.bullet=t.bullet,this.fixedRotation=t.fixedRotation,this.canSleep=t.canSleep,this.shape=t.shape,this.shapeDimensionA=t.shapeDimensionA,this.shapeDimensionB=t.shapeDimensionB,this.shapeOffsetX=t.shapeOffsetX,this.shapeOffsetY=t.shapeOffsetY,this.polygonOrigin=t.polygonOrigin,this.polygon=this.shape==="Polygon"?B.getPolygon(t.vertices):null,this.density=t.density,this.friction=t.friction,this.restitution=t.restitution,this.linearDamping=Math.max(0,t.linearDamping),this.angularDamping=Math.max(0,t.angularDamping),this.gravityScale=t.gravityScale,this.layers=t.layers,this.masks=t.masks,this.contactsStartedThisFrame=[],this.contactsEndedThisFrame=[],this.currentContacts=[],this.currentContacts.length=0,this.destroyedDuringFrameLogic=!1,this._sharedData=x.getSharedData(e.getScene(),t.name),this._sharedData.addToBehaviorsList(this)}b2Vec2(e,t){const i=this._sharedData._tempb2Vec2;return i.set_x(e),i.set_y(t),i}b2Vec2Sec(e,t){const i=this._sharedData._tempb2Vec2Sec;return i.set_x(e),i.set_y(t),i}updateFromBehaviorData(e,t){return e.bullet!==t.bullet&&this.setBullet(t.bullet),e.fixedRotation!==t.fixedRotation&&this.setFixedRotation(t.fixedRotation),e.canSleep!==t.canSleep&&this.setSleepingAllowed(t.canSleep),e.shapeDimensionA!==t.shapeDimensionA&&(this.shapeDimensionA=t.shapeDimensionA,this.recreateShape()),e.shapeDimensionB!==t.shapeDimensionB&&(this.shapeDimensionB=t.shapeDimensionB,this.recreateShape()),e.shapeOffsetX!==t.shapeOffsetX&&(this.shapeOffsetX=t.shapeOffsetX,this.recreateShape()),e.shapeOffsetY!==t.shapeOffsetY&&(this.shapeOffsetY=t.shapeOffsetY,this.recreateShape()),e.polygonOrigin!==t.polygonOrigin&&(this.polygonOrigin=t.polygonOrigin,this.recreateShape()),e.density!==t.density&&this.setDensity(t.density),e.friction!==t.friction&&this.setFriction(t.friction),e.restitution!==t.restitution&&this.setRestitution(t.restitution),e.linearDamping!==t.linearDamping&&this.setLinearDamping(t.linearDamping),e.angularDamping!==t.angularDamping&&this.setAngularDamping(t.angularDamping),e.gravityScale!==t.gravityScale&&this.setGravityScale(t.gravityScale),!(e.layers!==t.layers||e.masks!==t.masks||e.vertices!==t.vertices||e.bodyType!==t.bodyType||e.shape!==t.shape)}getNetworkSyncData(){const e=this._body?{tpx:this._body.GetTransform().get_p().get_x(),tpy:this._body.GetTransform().get_p().get_y(),tqa:this._body.GetTransform().get_q().GetAngle(),lvx:this._body.GetLinearVelocity().get_x(),lvy:this._body.GetLinearVelocity().get_y(),av:this._body.GetAngularVelocity(),aw:this._body.IsAwake()}:{tpx:void 0,tpy:void 0,tqa:void 0,lvx:void 0,lvy:void 0,av:void 0,aw:void 0};return{...super.getNetworkSyncData(),props:{...e,layers:this.layers,masks:this.masks}}}updateFromNetworkSyncData(e){super.updateFromNetworkSyncData(e);const t=e.props;t.tpx!==void 0&&t.tpy!==void 0&&t.tqa!==void 0&&this._body&&this._body.SetTransform(this.b2Vec2(t.tpx,t.tpy),t.tqa),t.lvx!==void 0&&t.lvy!==void 0&&this._body&&this._body.SetLinearVelocity(this.b2Vec2(t.lvx,t.lvy)),t.av!==void 0&&this._body&&this._body.SetAngularVelocity(t.av),t.aw!==void 0&&this._body&&this._body.SetAwake(t.aw),t.layers!==void 0&&(this.layers=t.layers),t.masks!==void 0&&(this.masks=t.masks)}onDeActivate(){this._sharedData.removeFromBehaviorsList(this),this._body!==null&&(this._sharedData.clearBodyJoints(this._body),this._verticesBuffer&&(Box2D._free(this._verticesBuffer),this._verticesBuffer=0),this._sharedData.world.DestroyBody(this._body),this._body=null),this.contactsEndedThisFrame.length=0,this.contactsStartedThisFrame.length=0,this.currentContacts.length=0}onActivate(){this._sharedData.addToBehaviorsList(this),this.contactsEndedThisFrame.length=0,this.contactsStartedThisFrame.length=0,this.currentContacts.length=0,this.updateBodyFromObject()}onDestroy(){this.destroyedDuringFrameLogic=!0,this.onDeActivate()}static getPolygon(e){if(!e)return null;const t=new l.Polygon,i=8;for(let o=0,s=e.length;o<Math.min(s,i);o++)t.vertices.push([e[o].x,e[o].y]);return t}static isPolygonConvex(e){if(!e.isConvex())return!1;let t=!0,i=!0;for(let o=0;o<e.vertices.length-1;++o){for(let s=o+1;s<e.vertices.length;++s)if(e.vertices[o][0]===e.vertices[s][0]&&e.vertices[o][1]===e.vertices[s][1])return!1;e.vertices[o][0]!==e.vertices[o+1][0]&&(t=!1),e.vertices[o][1]!==e.vertices[o+1][1]&&(i=!1)}return!(t||i)}createShape(){const e=this.shapeOffsetX?this.shapeOffsetX*this.shapeScale*this._sharedData.worldInvScale:0,t=this.shapeOffsetY?this.shapeOffsetY*this.shapeScale*this._sharedData.worldInvScale:0;let i;if(this.shape==="Circle"){if(i=new Box2D.b2CircleShape,this.shapeDimensionA>0)i.set_m_radius(this.shapeDimensionA*this.shapeScale*this._sharedData.worldInvScale);else{const n=(this.owner.getWidth()*this._sharedData.worldInvScale+this.owner.getHeight()*this._sharedData.worldInvScale)/4;i.set_m_radius(n>0?n:1)}i.set_m_p(this.b2Vec2(e,t))}else if(this.shape==="Polygon")if(i=new Box2D.b2PolygonShape,!this.polygon||!B.isPolygonConvex(this.polygon)){let n=(this.owner.getWidth()>0?this.owner.getWidth():1)*this._sharedData.worldInvScale,a=(this.owner.getHeight()>0?this.owner.getHeight():1)*this._sharedData.worldInvScale;i.SetAsBox(n/2,a/2,this.b2Vec2(e,t),0)}else{let n=0,a=0;if(this.polygonOrigin==="Origin"?(n=(this.owner.getWidth()>0?-this.owner.getWidth()/2:0)+(this.owner.getX()-this.owner.getDrawableX()),a=(this.owner.getHeight()>0?-this.owner.getHeight()/2:0)+(this.owner.getY()-this.owner.getDrawableY())):this.polygonOrigin==="TopLeft"&&(n=this.owner.getWidth()>0?-this.owner.getWidth()/2:0,a=this.owner.getHeight()>0?-this.owner.getHeight()/2:0),!this._verticesBuffer){const c=Box2D._malloc(this.polygon.vertices.length*8,"float",Box2D.ALLOC_STACK);this._verticesBuffer=c}let h=0;for(let c=0,u=this.polygon.vertices.length;c<u;c++)Box2D.HEAPF32[this._verticesBuffer+h>>2]=(this.polygon.vertices[c][0]*this.shapeScale+n)*this._sharedData.worldInvScale+e,Box2D.HEAPF32[this._verticesBuffer+(h+4)>>2]=(this.polygon.vertices[c][1]*this.shapeScale+a)*this._sharedData.worldInvScale+t,h+=8;const d=Box2D.wrapPointer(this._verticesBuffer,Box2D.b2Vec2);i.Set(d,this.polygon.vertices.length)}else if(this.shape==="Edge"){i=new Box2D.b2EdgeShape;const n=(this.shapeDimensionA>0?this.shapeDimensionA*this.shapeScale:this.owner.getWidth()>0?this.owner.getWidth():1)*this._sharedData.worldInvScale;let a=this.owner.getHeight()>0?this.owner.getHeight()*this._sharedData.worldInvScale:0;const h=this.shapeDimensionB?l.toRad(this.shapeDimensionB):0;i.Set(this.b2Vec2(-n/2*Math.cos(h)+e,a/2-n/2*Math.sin(h)+t),this.b2Vec2Sec(n/2*Math.cos(h)+e,a/2+n/2*Math.sin(h)+t))}else{i=new Box2D.b2PolygonShape;let n=(this.shapeDimensionA>0?this.shapeDimensionA*this.shapeScale:this.owner.getWidth()>0?this.owner.getWidth():1)*this._sharedData.worldInvScale,a=(this.shapeDimensionB>0?this.shapeDimensionB*this.shapeScale:this.owner.getHeight()>0?this.owner.getHeight():1)*this._sharedData.worldInvScale;i.SetAsBox(n/2,a/2,this.b2Vec2(e,t),0)}const o=new Box2D.b2Filter;o.set_categoryBits(this.layers),o.set_maskBits(this.masks);const s=new Box2D.b2FixtureDef;return s.set_shape(i),s.set_filter(o),this.density<0&&(this.density=0),s.set_density(this.density),this.friction<0&&(this.friction=0),s.set_friction(this.friction),this.restitution<0&&(this.restitution=0),s.set_restitution(this.restitution),s}recreateShape(){if(this._body===null&&!this.createBody())return;const e=this._body;e.DestroyFixture(e.GetFixtureList()),e.CreateFixture(this.createShape()),this._objectOldWidth=this.owner.getWidth(),this._objectOldHeight=this.owner.getHeight()}getShapeScale(){return this.shapeScale}setShapeScale(e){e!==this.shapeScale&&e>0&&(this.shapeScale=e,this.recreateShape())}getBody(){return this._body===null&&this.createBody(),this._body}createBody(){if(!this.activated()||this.destroyedDuringFrameLogic)return!1;const e=new Box2D.b2BodyDef,t=(this.owner.getDrawableX()+this.owner.getWidth()/2)*this._sharedData.worldInvScale,i=(this.owner.getDrawableY()+this.owner.getHeight()/2)*this._sharedData.worldInvScale;e.set_position(this.b2Vec2(Number.isFinite(t)?t:0,Number.isFinite(i)?i:0));const o=l.toRad(this.owner.getAngle());return Number.isFinite(o)&&e.set_angle(o),e.set_type(this.bodyType==="Static"?Box2D.b2_staticBody:this.bodyType==="Kinematic"?Box2D.b2_kinematicBody:Box2D.b2_dynamicBody),e.set_bullet(this.bullet),e.set_fixedRotation(this.fixedRotation),e.set_allowSleep(this.canSleep),e.set_linearDamping(this.linearDamping),e.set_angularDamping(this.angularDamping),e.set_gravityScale(this.gravityScale),this._body=this._sharedData.world.CreateBody(e),this._body.CreateFixture(this.createShape()),this._body.gdjsAssociatedBehavior=this,this._objectOldWidth=this.owner.getWidth(),this._objectOldHeight=this.owner.getHeight(),!0}doStepPreEvents(e){!this._sharedData.stepped&&!e.getScene().getTimeManager().isFirstFrame()&&(this._sharedData.resetStartedAndEndedCollisions(),this._sharedData.updateBodiesFromObjects(),this._sharedData.step(e.getScene().getTimeManager().getElapsedTime()/1e3)),this._body!==null&&(this.owner.setX(this._body.GetPosition().get_x()*this._sharedData.worldScale-this.owner.getWidth()/2+this.owner.getX()-this.owner.getDrawableX()),this.owner.setY(this._body.GetPosition().get_y()*this._sharedData.worldScale-this.owner.getHeight()/2+this.owner.getY()-this.owner.getDrawableY()),this.owner.setAngle(l.toDegrees(this._body.GetAngle()))),this._objectOldX=this.owner.getX(),this._objectOldY=this.owner.getY(),this._objectOldAngle=this.owner.getAngle()}doStepPostEvents(e){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}updateBodyFromObject(){if(this._body===null&&!this.createBody())return;const e=this._body;if((this._objectOldWidth!==this.owner.getWidth()&&this.shapeDimensionA<=0||this._objectOldHeight!==this.owner.getHeight()&&this.shape!=="Edge"&&!(this.shape==="Box"&&this.shapeDimensionB>0)&&!(this.shape==="Circle"&&this.shapeDimensionA>0))&&this.recreateShape(),this._objectOldX!==this.owner.getX()||this._objectOldY!==this.owner.getY()||this._objectOldAngle!==this.owner.getAngle()){const t=(this.owner.getDrawableX()+this.owner.getWidth()/2)*this._sharedData.worldInvScale,i=(this.owner.getDrawableY()+this.owner.getHeight()/2)*this._sharedData.worldInvScale,o=this.b2Vec2(Number.isFinite(t)?t:e.GetPosition().x,Number.isFinite(i)?i:e.GetPosition().y),s=l.toRad(this.owner.getAngle());e.SetTransform(o,Number.isFinite(s)?s:e.GetAngle()),e.SetAwake(!0)}}getWorldScale(){return this._sharedData.worldScale}getGravityX(){return this._sharedData.gravityX}getGravityY(){return this._sharedData.gravityY}setGravity(e,t){this._sharedData.gravityX===e&&this._sharedData.gravityY===t||(this._sharedData.gravityX=e,this._sharedData.gravityY=t,this._sharedData.world.SetGravity(this.b2Vec2(this._sharedData.gravityX,this._sharedData.gravityY)))}getTimeScale(){return this._sharedData.timeScale}setTimeScale(e){e<0||(this._sharedData.timeScale=e)}static setTimeScaleFromObject(e,t,i){e===null||!e.hasBehavior(t)||e.getBehavior(t).setTimeScale(i)}isDynamic(){return this.bodyType==="Dynamic"}setDynamic(){if(this.bodyType==="Dynamic"||(this.bodyType="Dynamic",this._body===null&&!this.createBody()))return;const e=this._body;e.SetType(Box2D.b2_dynamicBody),e.SetAwake(!0)}isStatic(){return this.bodyType==="Static"}setStatic(){if(this.bodyType==="Static"||(this.bodyType="Static",this._body===null&&!this.createBody()))return;const e=this._body;e.SetType(Box2D.b2_staticBody),e.SetAwake(!0)}isKinematic(){return this.bodyType==="Kinematic"}setKinematic(){if(this.bodyType==="Kinematic"||(this.bodyType="Kinematic",this._body===null&&!this.createBody()))return;const e=this._body;e.SetType(Box2D.b2_kinematicBody),e.SetAwake(!0)}isBullet(){return this.bullet}setBullet(e){if(this.bullet===e||(this.bullet=e,this._body===null&&!this.createBody()))return;this._body.SetBullet(this.bullet)}hasFixedRotation(){return this.fixedRotation}setFixedRotation(e){if(this.fixedRotation=e,this._body===null&&!this.createBody())return;this._body.SetFixedRotation(this.fixedRotation)}isSleepingAllowed(){return this.canSleep}setSleepingAllowed(e){if(this.canSleep=e,this._body===null&&!this.createBody())return;this._body.SetSleepingAllowed(this.canSleep)}isSleeping(){return this._body===null&&!this.createBody()?!0:!this._body.IsAwake()}getDensity(){return this.density}setDensity(e){if(e<0&&(e=0),this.density===e||(this.density=e,this._body===null&&!this.createBody()))return;const t=this._body;t.GetFixtureList().SetDensity(this.density),t.ResetMassData()}getFriction(){return this.friction}setFriction(e){if(e<0&&(e=0),this.friction===e||(this.friction=e,this._body===null&&!this.createBody()))return;const t=this._body;t.GetFixtureList().SetFriction(this.friction);let i=t.GetContactList();for(;Box2D.getPointer(i);)i.get_contact().ResetFriction(),i=i.get_next()}getRestitution(){return this.restitution}setRestitution(e){if(e<0&&(e=0),this.restitution===e||(this.restitution=e,this._body===null&&!this.createBody()))return;const t=this._body;t.GetFixtureList().SetRestitution(this.restitution);let i=t.GetContactList();for(;Box2D.getPointer(i);)i.get_contact().ResetRestitution(),i=i.get_next()}getLinearDamping(){return this.linearDamping}setLinearDamping(e){if(e<0&&(e=0),this.linearDamping===e||(this.linearDamping=e,this._body===null&&!this.createBody()))return;this._body.SetLinearDamping(this.linearDamping)}getAngularDamping(){return this.angularDamping}setAngularDamping(e){if(e<0&&(e=0),this.angularDamping===e||(this.angularDamping=e,this._body===null&&!this.createBody()))return;this._body.SetAngularDamping(this.angularDamping)}getGravityScale(){return this.gravityScale}setGravityScale(e){if(this.gravityScale===e||(this.gravityScale=e,this._body===null&&!this.createBody()))return;this._body.SetGravityScale(this.gravityScale)}layerEnabled(e){return e=Math.floor(e),e<1||e>16?!1:!!(this.layers&1<<e-1)}enableLayer(e,t){if(e=Math.floor(e),e<1||e>16||(t?this.layers|=1<<e-1:this.layers&=~(1<<e-1),this._body===null&&!this.createBody()))return;const i=this._body,o=i.GetFixtureList().GetFilterData();o.set_categoryBits(this.layers),i.GetFixtureList().SetFilterData(o)}maskEnabled(e){return e=Math.floor(e),e<1||e>16?!1:!!(this.masks&1<<e-1)}enableMask(e,t){if(e=Math.floor(e),e<1||e>16||(t?this.masks|=1<<e-1:this.masks&=~(1<<e-1),this._body===null&&!this.createBody()))return;const i=this._body,o=i.GetFixtureList().GetFilterData();o.set_maskBits(this.masks),i.GetFixtureList().SetFilterData(o)}getLinearVelocityX(){return this._body===null&&!this.createBody()?0:this._body.GetLinearVelocity().get_x()*this._sharedData.worldScale}setLinearVelocityX(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetLinearVelocity(this.b2Vec2(e*this._sharedData.worldInvScale,t.GetLinearVelocity().get_y()))}getLinearVelocityY(){return this._body===null&&!this.createBody()?0:this._body.GetLinearVelocity().get_y()*this._sharedData.worldScale}setLinearVelocityY(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetLinearVelocity(this.b2Vec2(t.GetLinearVelocity().get_x(),e*this._sharedData.worldInvScale))}getLinearVelocityLength(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return this.b2Vec2(e.GetLinearVelocity().get_x()*this._sharedData.worldScale,e.GetLinearVelocity().get_y()*this._sharedData.worldScale).Length()}getLinearVelocityAngle(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return l.toDegrees(Math.atan2(e.GetLinearVelocity().get_y()*this._sharedData.worldScale,e.GetLinearVelocity().get_x()*this._sharedData.worldScale))}setLinearVelocityAngle(e,t){if(this._body===null&&!this.createBody())return;const i=this._body;e=l.toRad(e),i.SetLinearVelocity(this.b2Vec2(t*Math.cos(e)*this._sharedData.worldInvScale,t*Math.sin(e)*this._sharedData.worldInvScale))}isLinearVelocityAngleAround(e,t){return Math.abs(l.evtTools.common.angleDifference(this.getLinearVelocityAngle(),e))<=t}getAngularVelocity(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return l.toDegrees(e.GetAngularVelocity())}setAngularVelocity(e){if(this._body===null&&!this.createBody())return;this._body.SetAngularVelocity(l.toRad(e))}applyForce(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),s.ApplyForce(this.b2Vec2(e,t),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyPolarForce(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),e=l.toRad(e),s.ApplyForce(this.b2Vec2(t*Math.cos(e),t*Math.sin(e)),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyForceTowardPosition(e,t,i,o,s){if(this._body===null&&!this.createBody())return;const n=this._body;n.SetAwake(!0);const a=Math.atan2(i*this._sharedData.worldInvScale-n.GetPosition().get_y(),t*this._sharedData.worldInvScale-n.GetPosition().get_x());n.ApplyForce(this.b2Vec2(e*Math.cos(a),e*Math.sin(a)),this.b2Vec2Sec(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale),!1)}applyImpulse(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),s.ApplyLinearImpulse(this.b2Vec2(e,t),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyPolarImpulse(e,t,i,o){if(this._body===null&&!this.createBody())return;const s=this._body;s.SetAwake(!0),e=l.toRad(e),s.ApplyLinearImpulse(this.b2Vec2(t*Math.cos(e),t*Math.sin(e)),this.b2Vec2Sec(i*this._sharedData.worldInvScale,o*this._sharedData.worldInvScale),!1)}applyImpulseTowardPosition(e,t,i,o,s){if(this._body===null&&!this.createBody())return;const n=this._body;n.SetAwake(!0);const a=Math.atan2(i*this._sharedData.worldInvScale-n.GetPosition().get_y(),t*this._sharedData.worldInvScale-n.GetPosition().get_x());n.ApplyLinearImpulse(this.b2Vec2(e*Math.cos(a),e*Math.sin(a)),this.b2Vec2Sec(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale),!1)}applyTorque(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetAwake(!0),t.ApplyTorque(e,!1)}applyAngularImpulse(e){if(this._body===null&&!this.createBody())return;const t=this._body;t.SetAwake(!0),t.ApplyAngularImpulse(e,!1)}getMass(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return e.SetAwake(!0),e.GetMass()}getInertia(){if(this._body===null&&!this.createBody())return 0;const e=this._body;return e.SetAwake(!0),e.GetInertia()}getMassCenterX(){return this._body===null&&!this.createBody()?0:this._body.GetWorldCenter().get_x()*this._sharedData.worldScale}getMassCenterY(){return this._body===null&&!this.createBody()?0:this._body.GetWorldCenter().get_y()*this._sharedData.worldScale}isJointFirstObject(e){if(this._body===null&&!this.createBody())return!1;const t=this._sharedData.getJoint(e);return t===null?!1:t.GetBodyA()===this._body}isJointSecondObject(e){if(this._body===null&&!this.createBody())return!1;const t=this._sharedData.getJoint(e);return t===null?!1:t.GetBodyB()===this._body}getJointFirstAnchorX(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyA().GetWorldPoint(t.GetLocalAnchorA()).get_x()}getJointFirstAnchorY(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyA().GetWorldPoint(t.GetLocalAnchorA()).get_y()}getJointSecondAnchorX(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyB().GetWorldPoint(t.GetLocalAnchorB()).get_x()}getJointSecondAnchorY(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetBodyB().GetWorldPoint(t.GetLocalAnchorB()).get_y()}getJointReactionForce(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetReactionForce(1/this._sharedData.timeStep).Length()}getJointReactionTorque(e){const t=this._sharedData.getJoint(e);return t===null?0:t.GetReactionTorque(1/this._sharedData.timeStep)}removeJoint(e){this._sharedData.removeJoint(e)}addDistanceJoint(e,t,i,o,s,n,a,h,d,c){if(this._body===null&&!this.createBody())return;const u=this._body;if(i==null||!i.hasBehavior(this.name))return;const r=i.getBehavior(this.name).getBody();if(this._body===r)return;const f=new Box2D.b2DistanceJointDef;f.set_bodyA(u),f.set_localAnchorA(u.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),f.set_bodyB(r),f.set_localAnchorB(r.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),f.set_length(n>0?n*this._sharedData.worldInvScale:this.b2Vec2((o-e)*this._sharedData.worldInvScale,(s-t)*this._sharedData.worldInvScale).Length()),f.set_frequencyHz(a>=0?a:0),f.set_dampingRatio(h>=0?h:1),f.set_collideConnected(d);const D=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(f),Box2D.b2DistanceJoint));c.setNumber(D)}getDistanceJointLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_distanceJoint?0:t.GetLength()*this._sharedData.worldScale}setDistanceJointLength(e,t){if(t<=0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_distanceJoint||(i.SetLength(t*this._sharedData.worldInvScale),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}getDistanceJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_distanceJoint?0:t.GetFrequency()}setDistanceJointFrequency(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_distanceJoint||i.SetFrequency(t)}getDistanceJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_distanceJoint?0:t.GetDampingRatio()}setDistanceJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_distanceJoint,i.SetDampingRatio(t)}addRevoluteJoint(e,t,i,o,s,n,a,h,d,c){if(this._body===null&&!this.createBody())return;const u=this._body,r=new Box2D.b2RevoluteJointDef;if(r.set_bodyA(this._sharedData.staticBody),r.set_localAnchorA(this._sharedData.staticBody.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),r.set_bodyB(u),r.set_localAnchorB(u.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),r.set_enableLimit(i),r.set_referenceAngle(l.toRad(o)),n<s){const D=s;s=n,n=D}r.set_lowerAngle(l.toRad(s)),r.set_upperAngle(l.toRad(n)),r.set_enableMotor(a),r.set_motorSpeed(l.toRad(h)),r.set_maxMotorTorque(d>=0?d:0),r.set_collideConnected(!1);const f=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(r),Box2D.b2RevoluteJoint));c.setNumber(f)}addRevoluteJointBetweenTwoBodies(e,t,i,o,s,n,a,h,d,c,u,r,f,D){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const b=i.getBehavior(this.name).getBody();if(this._body===b)return;const _=this._body,g=new Box2D.b2RevoluteJointDef;if(g.set_bodyA(_),g.set_localAnchorA(_.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),g.set_bodyB(b),g.set_localAnchorB(b.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),g.set_enableLimit(n),g.set_referenceAngle(l.toRad(a)),d<h){const J=h;h=d,d=J}g.set_lowerAngle(l.toRad(h)),g.set_upperAngle(l.toRad(d)),g.set_enableMotor(c),g.set_motorSpeed(l.toRad(u)),g.set_maxMotorTorque(r>=0?r:0),g.set_collideConnected(f);const y=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2RevoluteJoint));D.setNumber(y)}getRevoluteJointReferenceAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetReferenceAngle())}getRevoluteJointAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetJointAngle())}getRevoluteJointSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetJointSpeed())}isRevoluteJointLimitsEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?!1:t.IsLimitEnabled()}enableRevoluteJointLimits(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.EnableLimit(t)}getRevoluteJointMinAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetLowerLimit())}getRevoluteJointMaxAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetUpperLimit())}setRevoluteJointLimits(e,t,i){const o=this._sharedData.getJoint(e);if(!(o===null||o.GetType()!==Box2D.e_revoluteJoint)){if(i<t){const s=t;t=i,i=s}o.SetLimits(l.toRad(t),l.toRad(i))}}isRevoluteJointMotorEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?!1:t.IsMotorEnabled()}enableRevoluteJointMotor(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.EnableMotor(t)}getRevoluteJointMotorSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:l.toDegrees(t.GetMotorSpeed())}setRevoluteJointMotorSpeed(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.SetMotorSpeed(l.toRad(t))}getRevoluteJointMaxMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:t.GetMaxMotorTorque()}setRevoluteJointMaxMotorTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_revoluteJoint||i.SetMaxMotorTorque(t)}getRevoluteJointMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_revoluteJoint?0:t.GetMotorTorque(1/this._sharedData.timeStep)}addPrismaticJoint(e,t,i,o,s,n,a,h,d,c,u,r,f,D,b){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const _=i.getBehavior(this.name).getBody();if(this._body===_)return;const g=this._body,y=new Box2D.b2PrismaticJointDef;if(y.set_bodyA(g),y.set_localAnchorA(g.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),y.set_bodyB(_),y.set_localAnchorB(_.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-g.GetAngle(),y.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),y.set_referenceAngle(l.toRad(a)),y.set_enableLimit(h),c<d){const m=d;d=c,c=m}y.set_lowerTranslation(d<0?d*this._sharedData.worldInvScale:0),y.set_upperTranslation(c>0?c*this._sharedData.worldInvScale:0),y.set_enableMotor(u),y.set_motorSpeed(r*this._sharedData.worldInvScale),y.set_maxMotorForce(f),y.set_collideConnected(D);const J=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(y),Box2D.b2PrismaticJoint));b.setNumber(J)}getPrismaticJointAxisAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:l.toDegrees(Math.atan2(t.GetLocalAxisA().get_y(),t.GetLocalAxisA().get_x())+t.GetBodyA().GetAngle())}getPrismaticJointReferenceAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:l.toDegrees(t.GetReferenceAngle())}getPrismaticJointTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetJointTranslation()*this._sharedData.worldScale}getPrismaticJointSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetJointSpeed()*this._sharedData.worldScale}isPrismaticJointLimitsEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?!1:t.IsLimitEnabled()}enablePrismaticJointLimits(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.EnableLimit(t)}getPrismaticJointMinTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetLowerLimit()*this._sharedData.worldScale}getPrismaticJointMaxTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetUpperLimit()*this._sharedData.worldScale}setPrismaticJointLimits(e,t,i){const o=this._sharedData.getJoint(e);if(!(o===null||o.GetType()!==Box2D.e_prismaticJoint)){if(i<t){const s=t;t=i,i=s}t=t<0?t:0,i=i>0?i:0,o.SetLimits(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale)}}isPrismaticJointMotorEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?!1:t.IsMotorEnabled()}enablePrismaticJointMotor(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.EnableMotor(t)}getPrismaticJointMotorSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetMotorSpeed()*this._sharedData.worldScale}setPrismaticJointMotorSpeed(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.SetMotorSpeed(t*this._sharedData.worldInvScale)}getPrismaticJointMaxMotorForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetMaxMotorForce()}setPrismaticJointMaxMotorForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_prismaticJoint||i.SetMaxMotorForce(t)}getPrismaticJointMotorForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_prismaticJoint?0:t.GetMotorForce(1/this._sharedData.timeStep)}addPulleyJoint(e,t,i,o,s,n,a,h,d,c,u,r,f,D){if(this._body===null&&!this.createBody())return;const b=this._body;if(i==null||!i.hasBehavior(this.name))return;const _=i.getBehavior(this.name).getBody();if(this._body===_)return;const g=new Box2D.b2PulleyJointDef;g.set_bodyA(b),g.set_localAnchorA(b.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),g.set_bodyB(_),g.set_localAnchorB(_.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),g.set_groundAnchorA(this.b2Vec2(n*this._sharedData.worldInvScale,a*this._sharedData.worldInvScale)),g.set_groundAnchorB(this.b2Vec2(h*this._sharedData.worldInvScale,d*this._sharedData.worldInvScale)),g.set_lengthA(c>0?c*this._sharedData.worldInvScale:this.b2Vec2((n-e)*this._sharedData.worldInvScale,(a-t)*this._sharedData.worldInvScale).Length()),g.set_lengthB(u>0?u*this._sharedData.worldInvScale:this.b2Vec2((h-o)*this._sharedData.worldInvScale,(d-s)*this._sharedData.worldInvScale).Length()),g.set_ratio(r>0?r:1),g.set_collideConnected(f);const y=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2PulleyJoint));D.setNumber(y)}getPulleyJointFirstGroundAnchorX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorA().get_x()*this._sharedData.worldScale}getPulleyJointFirstGroundAnchorY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorA().get_y()*this._sharedData.worldScale}getPulleyJointSecondGroundAnchorX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorB().get_x()*this._sharedData.worldScale}getPulleyJointSecondGroundAnchorY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetGroundAnchorB().get_y()*this._sharedData.worldScale}getPulleyJointFirstLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetCurrentLengthA()*this._sharedData.worldScale}getPulleyJointSecondLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetCurrentLengthB()*this._sharedData.worldScale}getPulleyJointRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_pulleyJoint?0:t.GetRatio()}addGearJoint(e,t,i,o,s){if(this._body===null&&!this.createBody())return;const n=this._body,a=this._sharedData.getJoint(e);if(a===null||a.GetType()!==Box2D.e_revoluteJoint&&a.GetType()!==Box2D.e_prismaticJoint)return;const h=this._sharedData.getJoint(t);if(h===null||h.GetType()!==Box2D.e_revoluteJoint&&h.GetType()!==Box2D.e_prismaticJoint||a===h)return;const d=new Box2D.b2GearJointDef;d.set_bodyA(this._sharedData.staticBody),d.set_bodyB(n),d.set_joint1(a),d.set_joint2(h),d.set_ratio(i),d.set_collideConnected(o);const c=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(d),Box2D.b2GearJoint));s.setNumber(c)}getGearJointFirstJoint(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_gearJoint?0:this._sharedData.getJointId(t.GetJoint1())}getGearJointSecondJoint(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_gearJoint?0:this._sharedData.getJointId(t.GetJoint2())}getGearJointRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_gearJoint?0:t.GetRatio()}setGearJointRatio(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_gearJoint||(i.SetRatio(t),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}addMouseJoint(e,t,i,o,s,n){if(this._body===null&&!this.createBody())return;const a=this._body,h=new Box2D.b2MouseJointDef;h.set_bodyA(this._sharedData.staticBody),h.set_bodyB(a),h.set_target(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale)),h.set_maxForce(i>=0?i:0),h.set_frequencyHz(o>0?o:1),h.set_dampingRatio(s>=0?s:0);const d=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(h),Box2D.b2MouseJoint));n.setNumber(d)}getMouseJointTargetX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetTarget().get_x()*this._sharedData.worldScale}getMouseJointTargetY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetTarget().get_y()*this._sharedData.worldScale}setMouseJointTarget(e,t,i){const o=this._sharedData.getJoint(e);o===null||o.GetType()!==Box2D.e_mouseJoint||(o.SetTarget(this.b2Vec2(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale)),o.GetBodyB().SetAwake(!0))}getMouseJointMaxForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetMaxForce()}setMouseJointMaxForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_mouseJoint||i.SetMaxForce(t)}getMouseJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetFrequency()}setMouseJointFrequency(e,t){if(t<=0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_mouseJoint||i.SetFrequency(t)}getMouseJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_mouseJoint?0:t.GetDampingRatio()}setMouseJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_mouseJoint||i.SetDampingRatio(t)}addWheelJoint(e,t,i,o,s,n,a,h,d,c,u,r,f){if(this._body===null&&!this.createBody())return;const D=this._body;if(i==null||!i.hasBehavior(this.name))return;const b=i.getBehavior(this.name).getBody();if(this._body===b)return;const _=new Box2D.b2WheelJointDef;_.set_bodyA(D),_.set_localAnchorA(D.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),_.set_bodyB(b),_.set_localAnchorB(b.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-D.GetAngle(),_.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),_.set_frequencyHz(a>0?a:1),_.set_dampingRatio(h>=0?h:0),_.set_enableMotor(d),_.set_motorSpeed(l.toRad(c)),_.set_maxMotorTorque(u),_.set_collideConnected(r);const g=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(_),Box2D.b2WheelJoint));f.setNumber(g)}getWheelJointAxisAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:l.toDegrees(Math.atan2(t.GetLocalAxisA().get_y(),t.GetLocalAxisA().get_x())+t.GetBodyA().GetAngle())}getWheelJointTranslation(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetJointTranslation()*this._sharedData.worldScale}getWheelJointSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:l.toDegrees(t.GetJointSpeed())}isWheelJointMotorEnabled(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?!1:t.IsMotorEnabled()}enableWheelJointMotor(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.EnableMotor(t)}getWheelJointMotorSpeed(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:l.toDegrees(t.GetMotorSpeed())}setWheelJointMotorSpeed(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetMotorSpeed(l.toRad(t))}getWheelJointMaxMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetMaxMotorTorque()}setWheelJointMaxMotorTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetMaxMotorTorque(t)}getWheelJointMotorTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetMotorTorque(1/this._sharedData.timeStep)}getWheelJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetSpringFrequencyHz()}setWheelJointFrequency(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetSpringFrequencyHz(t)}getWheelJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_wheelJoint?0:t.GetSpringDampingRatio()}setWheelJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_wheelJoint||i.SetSpringDampingRatio(t)}addWeldJoint(e,t,i,o,s,n,a,h,d,c){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const u=i.getBehavior(this.name).getBody();if(this._body===u)return;const r=this._body,f=new Box2D.b2WeldJointDef;f.set_bodyA(r),f.set_localAnchorA(r.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),f.set_bodyB(u),f.set_localAnchorB(u.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),f.set_referenceAngle(l.toRad(n)),f.set_frequencyHz(a>0?a:1),f.set_dampingRatio(h>=0?h:0),f.set_collideConnected(d);const D=Box2D.castObject(this._sharedData.world.CreateJoint(f),Box2D.b2WeldJoint);D.referenceAngle=f.get_referenceAngle(),c.setNumber(this._sharedData.addJoint(D))}getWeldJointReferenceAngle(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_weldJoint?0:l.toDegrees(t.referenceAngle)}getWeldJointFrequency(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_weldJoint?0:t.GetFrequency()}setWeldJointFrequency(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_weldJoint||i.SetFrequency(t)}getWeldJointDampingRatio(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_weldJoint?0:t.GetDampingRatio()}setWeldJointDampingRatio(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_weldJoint||i.SetDampingRatio(t)}addRopeJoint(e,t,i,o,s,n,a,h){if(this._body===null&&!this.createBody())return;const d=this._body;if(i==null||!i.hasBehavior(this.name))return;const c=i.getBehavior(this.name).getBody();if(this._body===c)return;const u=new Box2D.b2RopeJointDef;u.set_bodyA(d),u.set_localAnchorA(d.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),u.set_bodyB(c),u.set_localAnchorB(c.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),u.set_maxLength(n>0?n*this._sharedData.worldInvScale:this.b2Vec2((o-e)*this._sharedData.worldInvScale,(s-t)*this._sharedData.worldInvScale).Length()),u.set_collideConnected(a);const r=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(u),Box2D.b2RopeJoint));h.setNumber(r)}getRopeJointMaxLength(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_ropeJoint?0:t.GetMaxLength()*this._sharedData.worldScale}setRopeJointMaxLength(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_ropeJoint||(i.SetMaxLength(t*this._sharedData.worldInvScale),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}addFrictionJoint(e,t,i,o,s,n,a,h,d){if(this._body===null&&!this.createBody()||i==null||!i.hasBehavior(this.name))return;const c=i.getBehavior(this.name).getBody();if(this._body===c)return;const u=this._body,r=new Box2D.b2FrictionJointDef;r.set_bodyA(u),r.set_localAnchorA(u.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),r.set_bodyB(c),r.set_localAnchorB(c.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),r.set_maxForce(n>=0?n:0),r.set_maxTorque(a>=0?a:0),r.set_collideConnected(h);const f=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(r),Box2D.b2FrictionJoint));d.setNumber(f)}getFrictionJointMaxForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_frictionJoint?0:t.GetMaxForce()}setFrictionJointMaxForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_frictionJoint||i.SetMaxForce(t)}getFrictionJointMaxTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_frictionJoint?0:t.GetMaxTorque()}setFrictionJointMaxTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_frictionJoint||i.SetMaxTorque(t)}addMotorJoint(e,t,i,o,s,n,a,h,d){if(this._body===null&&!this.createBody())return;const c=this._body;if(e==null||!e.hasBehavior(this.name))return;const u=e.getBehavior(this.name).getBody();if(this._body===u)return;const r=new Box2D.b2MotorJointDef;r.set_bodyA(c),r.set_bodyB(u),r.set_linearOffset(this.b2Vec2(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale)),r.set_angularOffset(l.toRad(o)),r.set_maxForce(s>=0?s:0),r.set_maxTorque(n>=0?n:0),r.set_correctionFactor(a<0?0:a>1?1:a),r.set_collideConnected(h);const f=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(r),Box2D.b2MotorJoint));d.setNumber(f)}getMotorJointOffsetX(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetLinearOffset().get_x()*this._sharedData.worldScale}getMotorJointOffsetY(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetLinearOffset().get_y()*this._sharedData.worldScale}setMotorJointOffset(e,t,i){const o=this._sharedData.getJoint(e);o===null||o.GetType()!==Box2D.e_motorJoint||o.SetLinearOffset(this.b2Vec2(t*this._sharedData.worldInvScale,i*this._sharedData.worldInvScale))}getMotorJointAngularOffset(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:l.toDegrees(t.GetAngularOffset())}setMotorJointAngularOffset(e,t){const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||i.SetAngularOffset(l.toRad(t))}getMotorJointMaxForce(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetMaxForce()}setMotorJointMaxForce(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||i.SetMaxForce(t)}getMotorJointMaxTorque(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetMaxTorque()}setMotorJointMaxTorque(e,t){if(t<0)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||(i.SetMaxTorque(t),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}getMotorJointCorrectionFactor(e){const t=this._sharedData.getJoint(e);return t===null||t.GetType()!==Box2D.e_motorJoint?0:t.GetCorrectionFactor()}setMotorJointCorrectionFactor(e,t){if(t<0||t>1)return;const i=this._sharedData.getJoint(e);i===null||i.GetType()!==Box2D.e_motorJoint||(i.SetCorrectionFactor(t),i.GetBodyA().SetAwake(!0),i.GetBodyB().SetAwake(!0))}onContactBegin(e){this.currentContacts.push(e);let t=this.contactsEndedThisFrame.indexOf(e);t!==-1?this.contactsEndedThisFrame.splice(t,1):this.contactsStartedThisFrame.push(e)}onContactEnd(e){this.contactsEndedThisFrame.push(e);const t=this.currentContacts.indexOf(e);t!==-1&&this.currentContacts.splice(t,1)}static areObjectsColliding(e,t,i){const o=e.getBehavior(i);return o?!!(o.currentContacts.some(s=>s.owner===t)||o.contactsStartedThisFrame.some(s=>s.owner===t)):!1}static hasCollisionStartedBetween(e,t,i){const o=e.getBehavior(i);return o?o.contactsStartedThisFrame.some(s=>s.owner===t):!1}static hasCollisionStoppedBetween(e,t,i){const o=e.getBehavior(i);return o?o.contactsEndedThisFrame.some(s=>s.owner===t):!1}};let p=B;p.collisionTest=B.areObjectsColliding,l.Physics2RuntimeBehavior=p,l.registerBehavior("Physics2::Physics2Behavior",l.Physics2RuntimeBehavior)})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=physics2runtimebehavior.js.map
|