gdcore-tools 2.0.0-gd-v5.5.242-autobuild → 2.0.0-gd-v5.5.243-autobuild
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Runtime/AsyncTasksManager.js +2 -2
- package/dist/Runtime/AsyncTasksManager.js.map +2 -2
- package/dist/Runtime/CustomRuntimeObject.js +1 -1
- package/dist/Runtime/CustomRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/A_RuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/Cube3DRuntimeObject.js +1 -1
- package/dist/Runtime/Extensions/3D/Cube3DRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/3D/JsExtension.js +5 -0
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js +1 -1
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject.js.map +2 -2
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject3DRenderer.js +1 -1
- package/dist/Runtime/Extensions/3D/Model3DRuntimeObject3DRenderer.js.map +2 -2
- package/dist/Runtime/Extensions/BBText/bbtextruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/BBText/bbtextruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/BitmapText/bitmaptextruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/BitmapText/bitmaptextruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/DebuggerTools/JsExtension.js +3 -1
- package/dist/Runtime/Extensions/DestroyOutsideBehavior/destroyoutsideruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/DestroyOutsideBehavior/destroyoutsideruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Lighting/lightruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Lighting/lightruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/messageManager.js.map +2 -2
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Multiplayer/multiplayerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/PanelSpriteObject/panelspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject.js +1 -1
- package/dist/Runtime/Extensions/ParticleSystem/particleemitterobject.js.map +2 -2
- package/dist/Runtime/Extensions/PathfindingBehavior/pathfindingruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/PathfindingBehavior/pathfindingruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCar3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PlatformBehavior/platformerobjectruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/PlatformBehavior/platformerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PlatformBehavior/platformruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/PlatformBehavior/platformruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/PrimitiveDrawing/shapepainterruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/PrimitiveDrawing/shapepainterruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/SaveState/JsExtension.js +488 -0
- package/dist/Runtime/Extensions/SaveState/SaveConfigurationRuntimeBehavior.js +2 -0
- package/dist/Runtime/Extensions/SaveState/SaveConfigurationRuntimeBehavior.js.map +7 -0
- package/dist/Runtime/Extensions/SaveState/SaveStateTools.js +2 -0
- package/dist/Runtime/Extensions/SaveState/SaveStateTools.js.map +7 -0
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Spine/spineruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TextInput/textinputruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TextObject/textruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TextObject/textruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/helper/dts/model/TileMapModel.d.ts +4 -4
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapcollisionmaskruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/tilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TiledSpriteObject/tiledspriteruntimeobject.js.map +2 -2
- package/dist/Runtime/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/TopDownMovementBehavior/topdownmovementruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/TweenManager.js +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/TweenManager.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/tweenruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/TweenBehavior/tweenruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/TweenBehavior/tweentools.js +1 -1
- package/dist/Runtime/Extensions/TweenBehavior/tweentools.js.map +2 -2
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/Video/videoruntimeobject.js.map +2 -2
- package/dist/Runtime/RuntimeInstanceContainer.js +1 -1
- package/dist/Runtime/RuntimeInstanceContainer.js.map +2 -2
- package/dist/Runtime/RuntimeLayer.js +1 -1
- package/dist/Runtime/RuntimeLayer.js.map +2 -2
- package/dist/Runtime/debugger-client/hot-reloader.js +1 -1
- package/dist/Runtime/debugger-client/hot-reloader.js.map +2 -2
- package/dist/Runtime/events-tools/objecttools.js +1 -1
- package/dist/Runtime/events-tools/objecttools.js.map +2 -2
- package/dist/Runtime/events-tools/runtimescenetools.js +1 -1
- package/dist/Runtime/events-tools/runtimescenetools.js.map +2 -2
- package/dist/Runtime/gd.js +1 -1
- package/dist/Runtime/gd.js.map +2 -2
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js +1 -1
- package/dist/Runtime/howler-sound-manager/howler-sound-manager.js.map +2 -2
- package/dist/Runtime/indexeddb.js +2 -0
- package/dist/Runtime/indexeddb.js.map +7 -0
- package/dist/Runtime/oncetriggers.js +1 -1
- package/dist/Runtime/oncetriggers.js.map +2 -2
- package/dist/Runtime/runtimebehavior.js +1 -1
- package/dist/Runtime/runtimebehavior.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/runtimeobject.js +1 -1
- package/dist/Runtime/runtimeobject.js.map +2 -2
- package/dist/Runtime/runtimescene.js +1 -1
- package/dist/Runtime/runtimescene.js.map +2 -2
- package/dist/Runtime/scenestack.js +1 -1
- package/dist/Runtime/scenestack.js.map +2 -2
- package/dist/Runtime/spriteruntimeobject.js +1 -1
- package/dist/Runtime/spriteruntimeobject.js.map +2 -2
- package/dist/Runtime/timemanager.js +1 -1
- package/dist/Runtime/timemanager.js.map +2 -2
- package/dist/Runtime/timer.js +1 -1
- package/dist/Runtime/timer.js.map +2 -2
- package/dist/Runtime/types/global-types.d.ts +29 -0
- package/dist/Runtime/types/project-data.d.ts +144 -3
- package/dist/Runtime/types/save-state.d.ts +9 -0
- package/dist/Runtime/variable.js +1 -1
- package/dist/Runtime/variable.js.map +2 -2
- package/dist/Runtime/variablescontainer.js +1 -1
- package/dist/Runtime/variablescontainer.js.map +2 -2
- package/dist/lib/libGD.cjs +1 -1
- package/dist/lib/libGD.wasm +0 -0
- package/dist/loaders.cjs +1 -1
- package/gd.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(o){const p=new o.Logger("Pathfinding behavior");class f extends o.RuntimeBehavior{constructor(s,e,l){super(s,e,l);this._path=[];this._pathFound=!1;this._speed=0;this._angularSpeed=0;this._distanceOnSegment=0;this._totalSegmentDistance=0;this._currentSegment=0;this._reachedEnd=!1;this._movementAngle=0;this._path===void 0||(this._path.length=0),this._allowDiagonals=e.allowDiagonals,this._acceleration=e.acceleration,this._maxSpeed=e.maxSpeed,this._angularMaxSpeed=e.angularMaxSpeed,this._rotateObject=e.rotateObject,this._angleOffset=e.angleOffset,this._cellWidth=e.cellWidth,this._cellHeight=e.cellHeight,this._gridOffsetX=e.gridOffsetX||0,this._gridOffsetY=e.gridOffsetY||0,this._extraBorder=e.extraBorder,this._smoothingMaxCellGap=e.smoothingMaxCellGap||0,this._manager=o.PathfindingObstaclesManager.getManager(s),this._searchContext=new o.PathfindingRuntimeBehavior.SearchContext(this._manager)}updateFromBehaviorData(s,e){return s.allowDiagonals!==e.allowDiagonals&&this.allowDiagonals(e.allowDiagonals),s.acceleration!==e.acceleration&&this.setAcceleration(e.acceleration),s.maxSpeed!==e.maxSpeed&&this.setMaxSpeed(e.maxSpeed),s.angularMaxSpeed!==e.angularMaxSpeed&&this.setAngularMaxSpeed(e.angularMaxSpeed),s.rotateObject!==e.rotateObject&&this.setRotateObject(e.rotateObject),s.angleOffset!==e.angleOffset&&this.setAngleOffset(e.angleOffset),s.cellWidth!==e.cellWidth&&this.setCellWidth(e.cellWidth),s.cellHeight!==e.cellHeight&&this.setCellHeight(e.cellHeight),s.gridOffsetX!==e.gridOffsetX&&(this._gridOffsetX=e.gridOffsetX),s.gridOffsetY!==e.gridOffsetY&&(this._gridOffsetY=e.gridOffsetY),s.extraBorder!==e.extraBorder&&this.setExtraBorder(e.extraBorder),s.smoothingMaxCellGap!==e.smoothingMaxCellGap&&(this._smoothingMaxCellGap=e.smoothingMaxCellGap),!0}getNetworkSyncData(){return{...super.getNetworkSyncData(),props:{path:this._path,pf:this._pathFound,sp:this._speed,as:this._angularSpeed,cs:this._currentSegment,tss:this._totalSegmentDistance,re:this._reachedEnd,ma:this._movementAngle}}}updateFromNetworkSyncData(s){super.updateFromNetworkSyncData(s);const e=s.props;e.path!==void 0&&(this._path=e.path),e.pf!==void 0&&(this._pathFound=e.pf),e.sp!==void 0&&(this._speed=e.sp),e.as!==void 0&&(this._angularSpeed=e.as),e.cs!==void 0&&e.cs!==this._currentSegment&&(this._currentSegment=e.cs),e.tss!==void 0&&(this._totalSegmentDistance=e.tss),e.re!==void 0&&(this._reachedEnd=e.re),e.ma!==void 0&&(this._movementAngle=e.ma)}setCellWidth(s){this._cellWidth=s}getCellWidth(){return this._cellWidth}setCellHeight(s){this._cellHeight=s}getCellHeight(){return this._cellHeight}setGridOffsetX(s){this._gridOffsetX=s}getGridOffsetX(){return this._gridOffsetX}setGridOffsetY(s){this._gridOffsetY=s}getGridOffsetY(){return this._gridOffsetY}setAcceleration(s){this._acceleration=s}getAcceleration(){return this._acceleration}setMaxSpeed(s){this._maxSpeed=s}getMaxSpeed(){return this._maxSpeed}setSpeed(s){this._speed=s}getSpeed(){return this._speed}getMovementAngle(){return this._movementAngle}movementAngleIsAround(s,e){return Math.abs(o.evtTools.common.angleDifference(this._movementAngle,s))<=e}setAngularMaxSpeed(s){this._angularMaxSpeed=s}getAngularMaxSpeed(){return this._angularMaxSpeed}setAngleOffset(s){this._angleOffset=s}getAngleOffset(){return this._angleOffset}setExtraBorder(s){this._extraBorder=s}getExtraBorder(){return this._extraBorder}allowDiagonals(s){this._allowDiagonals=s}diagonalsAllowed(){return this._allowDiagonals}setRotateObject(s){this._rotateObject=s}isObjectRotated(){return this._rotateObject}getNodeX(s){return s<this._path.length?this._path[s][0]:0}getNodeY(s){return s<this._path.length?this._path[s][1]:0}getNextNodeIndex(){return this._currentSegment+1<this._path.length?this._currentSegment+1:this._path.length-1}getNodeCount(){return this._path.length}getNextNodeX(){return this._path.length===0?0:this._currentSegment+1<this._path.length?this._path[this._currentSegment+1][0]:this._path[this._path.length-1][0]}getNextNodeY(){return this._path.length===0?0:this._currentSegment+1<this._path.length?this._path[this._currentSegment+1][1]:this._path[this._path.length-1][1]}getLastNodeX(){return this._path.length<2?0:this._currentSegment<this._path.length-1?this._path[this._currentSegment][0]:this._path[this._path.length-1][0]}getLastNodeY(){return this._path.length<2?0:this._currentSegment<this._path.length-1?this._path[this._currentSegment][1]:this._path[this._path.length-1][1]}getDestinationX(){return this._path.length===0?0:this._path[this._path.length-1][0]}getDestinationY(){return this._path.length===0?0:this._path[this._path.length-1][1]}pathFound(){return this._pathFound}destinationReached(){return this._reachedEnd}moveTo(s,e,l){const t=this.owner,i=Math.round((e-this._gridOffsetX)/this._cellWidth),n=Math.round((l-this._gridOffsetY)/this._cellHeight),r=Math.round((t.getX()-this._gridOffsetX)/this._cellWidth),h=Math.round((t.getY()-this._gridOffsetY)/this._cellHeight);if(r==i&&h==n){this._path.length=0,this._path.push([t.getX(),t.getY()]),this._path.push([e,l]),this._enterSegment(0),this._pathFound=!0;return}if(this._searchContext.allowDiagonals(this._allowDiagonals),this._searchContext.setObstacles(this._manager),this._searchContext.setCellSize(this._cellWidth,this._cellHeight),this._searchContext.setGridOffset(this._gridOffsetX,this._gridOffsetY),this._searchContext.setStartPosition(t.getX(),t.getY()),this._searchContext.setObjectSize(t.getX()-t.getDrawableX()+this._extraBorder,t.getY()-t.getDrawableY()+this._extraBorder,t.getWidth()-(t.getX()-t.getDrawableX())+this._extraBorder,t.getHeight()-(t.getY()-t.getDrawableY())+this._extraBorder),this._searchContext.computePathTo(e,l)){let a=this._searchContext.getFinalNode(),_=0;for(;a;)_===this._path.length&&this._path.push([0,0]),this._path[_][0]=a.pos[0]*this._cellWidth+this._gridOffsetX,this._path[_][1]=a.pos[1]*this._cellHeight+this._gridOffsetY,a=a.parent,_++;if(this._path.length=_,this._path.reverse(),this._path[0][0]=t.getX(),this._path[0][1]=t.getY(),this._allowDiagonals&&this._smoothingMaxCellGap>0){o.pathfinding.simplifyPath(this._path,this._smoothingMaxCellGap*Math.min(this._cellWidth,this._cellHeight),o.PathfindingRuntimeBehavior._smoothingResultVertices,o.PathfindingRuntimeBehavior._smoothingWorkingVertices);let g=this._path;this._path=o.PathfindingRuntimeBehavior._smoothingResultVertices,o.PathfindingRuntimeBehavior._smoothingResultVertices=g}this._enterSegment(0),this._pathFound=!0;return}this._pathFound=!1}_enterSegment(s){if(this._path.length!==0)if(this._currentSegment=s,this._currentSegment<this._path.length-1){const e=this._path[this._currentSegment+1][0]-this._path[this._currentSegment][0],l=this._path[this._currentSegment+1][1]-this._path[this._currentSegment][1];this._totalSegmentDistance=Math.sqrt(e*e+l*l),this._distanceOnSegment=0,this._reachedEnd=!1,this._movementAngle=(o.toDegrees(Math.atan2(l,e))+360)%360}else this._reachedEnd=!0,this._speed=0}doStepPreEvents(s){if(this._path.length===0||this._reachedEnd)return;const e=this.owner.getElapsedTime()/1e3,l=this._speed;this._speed!==this._maxSpeed&&(this._speed+=this._acceleration*e,this._speed>this._maxSpeed&&(this._speed=this._maxSpeed)),this._angularSpeed=this._angularMaxSpeed,this._distanceOnSegment+=(this._speed+l)/2*e;const t=this._totalSegmentDistance-this._distanceOnSegment;t<=0&&this._currentSegment<this._path.length&&(this._enterSegment(this._currentSegment+1),this._distanceOnSegment=-t);let i=[0,0];this._currentSegment<this._path.length-1?(i[0]=o.evtTools.common.lerp(this._path[this._currentSegment][0],this._path[this._currentSegment+1][0],this._distanceOnSegment/this._totalSegmentDistance),i[1]=o.evtTools.common.lerp(this._path[this._currentSegment][1],this._path[this._currentSegment+1][1],this._distanceOnSegment/this._totalSegmentDistance),this._rotateObject&&this.owner.getAngle()!==this._movementAngle+this._angleOffset&&this.owner.rotateTowardAngle(this._movementAngle+this._angleOffset,this._angularSpeed)):i=this._path[this._path.length-1],this.owner.setX(i[0]),this.owner.setY(i[1])}doStepPostEvents(s){}static euclideanDistance(s,e){return Math.sqrt((s[0]-e[0])*(s[0]-e[0])+(s[1]-e[1])*(s[1]-e[1]))}static manhattanDistance(s,e){return Math.abs(s[0]-e[0])+Math.abs(s[1]-e[1])}}f._smoothingResultVertices=[],f._smoothingWorkingVertices=[],o.PathfindingRuntimeBehavior=f,o.registerBehavior("PathfindingBehavior::PathfindingBehavior",o.PathfindingRuntimeBehavior),function(e){class c{constructor(t,i){this.cost=0;this.smallestCost=-1;this.estimateCost=-1;this.parent=null;this.open=!0;this.pos=[t,i]}reinitialize(t,i){this.pos[0]=t,this.pos[1]=i,this.cost=0,this.smallestCost=-1,this.estimateCost=-1,this.parent=null,this.open=!0}}e.Node=c;class s{constructor(t){this._finalNode=null;this._destination=[0,0];this._start=[0,0];this._startX=0;this._startY=0;this._allowDiagonals=!0;this._maxComplexityFactor=50;this._cellWidth=20;this._cellHeight=20;this._gridOffsetX=0;this._gridOffsetY=0;this._leftBorder=0;this._rightBorder=0;this._topBorder=0;this._bottomBorder=0;this._allNodes=[];this._openNodes=[];this._closeObstacles=[];this._nodeCache=[];this._obstacles=t,this._distanceFunction=e.euclideanDistance}setObstacles(t){return this._obstacles=t,this}getFinalNode(){return this._finalNode}allowDiagonals(t){return this._allowDiagonals=t,this._distanceFunction=t?e.euclideanDistance:e.manhattanDistance,this}setStartPosition(t,i){return this._startX=t,this._startY=i,this}setObjectSize(t,i,n,r){return this._leftBorder=t,this._rightBorder=n,this._topBorder=i,this._bottomBorder=r,this}setCellSize(t,i){return this._cellWidth=t,this._cellHeight=i,this}setGridOffset(t,i){return this._gridOffsetX=t,this._gridOffsetY=i,this}computePathTo(t,i){if(this._obstacles===null){p.log("You tried to compute a path without specifying the obstacles");return}this._destination[0]=Math.round((t-this._gridOffsetX)/this._cellWidth),this._destination[1]=Math.round((i-this._gridOffsetY)/this._cellHeight),this._start[0]=Math.round((this._startX-this._gridOffsetX)/this._cellWidth),this._start[1]=Math.round((this._startY-this._gridOffsetY)/this._cellHeight),this._freeAllNodes();const n=this._getNode(this._start[0],this._start[1]);n.smallestCost=0,n.estimateCost=0+this._distanceFunction(this._start,this._destination),this._openNodes.length=0,this._openNodes.push(n);let r=0;const h=n.estimateCost*this._maxComplexityFactor;for(;this._openNodes.length!==0;){if(r++>h)return console.warn(`No path was found after covering ${h} cells.`),!1;const a=this._openNodes.shift();if(a.open=!1,a.pos[0]==this._destination[0]&&a.pos[1]==this._destination[1])return this._finalNode=a,!0;this._insertNeighbors(a)}return!1}_freeAllNodes(){if(this._nodeCache.length<=32e3){for(const t in this._allNodes)if(this._allNodes.hasOwnProperty(t)){const i=this._allNodes[t];for(const n in i)i.hasOwnProperty(n)&&this._nodeCache.push(i[n])}}this._allNodes=[]}_insertNeighbors(t){this._addOrUpdateNode(t.pos[0]+1,t.pos[1],t,1),this._addOrUpdateNode(t.pos[0]-1,t.pos[1],t,1),this._addOrUpdateNode(t.pos[0],t.pos[1]+1,t,1),this._addOrUpdateNode(t.pos[0],t.pos[1]-1,t,1),this._allowDiagonals&&(this._addOrUpdateNode(t.pos[0]+1,t.pos[1]+1,t,1.414213562),this._addOrUpdateNode(t.pos[0]+1,t.pos[1]-1,t,1.414213562),this._addOrUpdateNode(t.pos[0]-1,t.pos[1]-1,t,1.414213562),this._addOrUpdateNode(t.pos[0]-1,t.pos[1]+1,t,1.414213562))}_getNode(t,i){if(this._allNodes.hasOwnProperty(t)){if(this._allNodes[t].hasOwnProperty(i))return this._allNodes[t][i]}else this._allNodes[t]=[];let n;this._nodeCache.length!==0?(n=this._nodeCache.shift(),n.reinitialize(t,i)):n=new c(t,i);const r=t*this._cellWidth+this._gridOffsetX,h=i*this._cellHeight+this._gridOffsetY;let a=!1;const _=this._cellHeight>this._cellWidth?this._cellHeight*2:this._cellWidth*2;this._obstacles.getAllObstaclesAround(r,h,_,this._closeObstacles);for(let g=0;g<this._closeObstacles.length;++g){const d=this._closeObstacles[g].owner,u=Math.floor((d.getDrawableX()-this._rightBorder-this._gridOffsetX)/this._cellWidth),m=Math.floor((d.getDrawableY()-this._bottomBorder-this._gridOffsetY)/this._cellHeight),O=Math.ceil((d.getDrawableX()+d.getWidth()+this._leftBorder-this._gridOffsetX)/this._cellWidth),S=Math.ceil((d.getDrawableY()+d.getHeight()+this._topBorder-this._gridOffsetY)/this._cellHeight);if(u<t&&t<O&&m<i&&i<S)if(a=!0,this._closeObstacles[g].isImpassable()){n.cost=-1;break}else n.cost+=this._closeObstacles[g].getCost()}return a||(n.cost=1),this._allNodes[t][i]=n,n}_addOrUpdateNode(t,i,n,r){const h=this._getNode(t,i);if(!(!h.open||h.cost<0)&&(h.smallestCost===-1||h.smallestCost>n.smallestCost+(n.cost+h.cost)/2*r)){if(h.smallestCost!=-1){for(let a=0;a<this._openNodes.length;++a)if(this._openNodes[a].pos[0]==h.pos[0]&&this._openNodes[a].pos[1]==h.pos[1]){this._openNodes.splice(a,1);break}}if(h.smallestCost=n.smallestCost+(n.cost+h.cost)/2*r,h.parent=n,h.estimateCost=h.smallestCost+this._distanceFunction(h.pos,this._destination),this._openNodes.length===0||this._openNodes[this._openNodes.length-1].estimateCost<h.estimateCost)this._openNodes.push(h);else for(let a=0;a<this._openNodes.length;++a)if(this._openNodes[a].estimateCost>=h.estimateCost){this._openNodes.splice(a,0,h);break}}}}e.SearchContext=s}(f=o.PathfindingRuntimeBehavior||(o.PathfindingRuntimeBehavior={}))})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(l){const p=new l.Logger("Pathfinding behavior");class f extends l.RuntimeBehavior{constructor(e,s,n){super(e,s,n);this._path=[];this._pathFound=!1;this._speed=0;this._angularSpeed=0;this._distanceOnSegment=0;this._totalSegmentDistance=0;this._currentSegment=0;this._reachedEnd=!1;this._movementAngle=0;this._path===void 0||(this._path.length=0),this._allowDiagonals=s.allowDiagonals,this._acceleration=s.acceleration,this._maxSpeed=s.maxSpeed,this._angularMaxSpeed=s.angularMaxSpeed,this._rotateObject=s.rotateObject,this._angleOffset=s.angleOffset,this._cellWidth=s.cellWidth,this._cellHeight=s.cellHeight,this._gridOffsetX=s.gridOffsetX||0,this._gridOffsetY=s.gridOffsetY||0,this._extraBorder=s.extraBorder,this._smoothingMaxCellGap=s.smoothingMaxCellGap||0,this._manager=l.PathfindingObstaclesManager.getManager(e),this._searchContext=new l.PathfindingRuntimeBehavior.SearchContext(this._manager)}updateFromBehaviorData(e,s){return e.allowDiagonals!==s.allowDiagonals&&this.allowDiagonals(s.allowDiagonals),e.acceleration!==s.acceleration&&this.setAcceleration(s.acceleration),e.maxSpeed!==s.maxSpeed&&this.setMaxSpeed(s.maxSpeed),e.angularMaxSpeed!==s.angularMaxSpeed&&this.setAngularMaxSpeed(s.angularMaxSpeed),e.rotateObject!==s.rotateObject&&this.setRotateObject(s.rotateObject),e.angleOffset!==s.angleOffset&&this.setAngleOffset(s.angleOffset),e.cellWidth!==s.cellWidth&&this.setCellWidth(s.cellWidth),e.cellHeight!==s.cellHeight&&this.setCellHeight(s.cellHeight),e.gridOffsetX!==s.gridOffsetX&&(this._gridOffsetX=s.gridOffsetX),e.gridOffsetY!==s.gridOffsetY&&(this._gridOffsetY=s.gridOffsetY),e.extraBorder!==s.extraBorder&&this.setExtraBorder(s.extraBorder),e.smoothingMaxCellGap!==s.smoothingMaxCellGap&&(this._smoothingMaxCellGap=s.smoothingMaxCellGap),!0}getNetworkSyncData(e){return{...super.getNetworkSyncData(e),props:{path:this._path,pf:this._pathFound,sp:this._speed,as:this._angularSpeed,cs:this._currentSegment,tss:this._totalSegmentDistance,re:this._reachedEnd,ma:this._movementAngle,dos:this._distanceOnSegment}}}updateFromNetworkSyncData(e,s){super.updateFromNetworkSyncData(e,s);const n=e.props;n.path!==void 0&&(this._path=n.path),n.pf!==void 0&&(this._pathFound=n.pf),n.sp!==void 0&&(this._speed=n.sp),n.as!==void 0&&(this._angularSpeed=n.as),n.cs!==void 0&&n.cs!==this._currentSegment&&(this._currentSegment=n.cs),n.tss!==void 0&&(this._totalSegmentDistance=n.tss),n.re!==void 0&&(this._reachedEnd=n.re),n.ma!==void 0&&(this._movementAngle=n.ma),n.dos!==void 0&&(this._distanceOnSegment=n.dos)}setCellWidth(e){this._cellWidth=e}getCellWidth(){return this._cellWidth}setCellHeight(e){this._cellHeight=e}getCellHeight(){return this._cellHeight}setGridOffsetX(e){this._gridOffsetX=e}getGridOffsetX(){return this._gridOffsetX}setGridOffsetY(e){this._gridOffsetY=e}getGridOffsetY(){return this._gridOffsetY}setAcceleration(e){this._acceleration=e}getAcceleration(){return this._acceleration}setMaxSpeed(e){this._maxSpeed=e}getMaxSpeed(){return this._maxSpeed}setSpeed(e){this._speed=e}getSpeed(){return this._speed}getMovementAngle(){return this._movementAngle}movementAngleIsAround(e,s){return Math.abs(l.evtTools.common.angleDifference(this._movementAngle,e))<=s}setAngularMaxSpeed(e){this._angularMaxSpeed=e}getAngularMaxSpeed(){return this._angularMaxSpeed}setAngleOffset(e){this._angleOffset=e}getAngleOffset(){return this._angleOffset}setExtraBorder(e){this._extraBorder=e}getExtraBorder(){return this._extraBorder}allowDiagonals(e){this._allowDiagonals=e}diagonalsAllowed(){return this._allowDiagonals}setRotateObject(e){this._rotateObject=e}isObjectRotated(){return this._rotateObject}getNodeX(e){return e<this._path.length?this._path[e][0]:0}getNodeY(e){return e<this._path.length?this._path[e][1]:0}getNextNodeIndex(){return this._currentSegment+1<this._path.length?this._currentSegment+1:this._path.length-1}getNodeCount(){return this._path.length}getNextNodeX(){return this._path.length===0?0:this._currentSegment+1<this._path.length?this._path[this._currentSegment+1][0]:this._path[this._path.length-1][0]}getNextNodeY(){return this._path.length===0?0:this._currentSegment+1<this._path.length?this._path[this._currentSegment+1][1]:this._path[this._path.length-1][1]}getLastNodeX(){return this._path.length<2?0:this._currentSegment<this._path.length-1?this._path[this._currentSegment][0]:this._path[this._path.length-1][0]}getLastNodeY(){return this._path.length<2?0:this._currentSegment<this._path.length-1?this._path[this._currentSegment][1]:this._path[this._path.length-1][1]}getDestinationX(){return this._path.length===0?0:this._path[this._path.length-1][0]}getDestinationY(){return this._path.length===0?0:this._path[this._path.length-1][1]}pathFound(){return this._pathFound}destinationReached(){return this._reachedEnd}moveTo(e,s,n){const t=this.owner,i=Math.round((s-this._gridOffsetX)/this._cellWidth),h=Math.round((n-this._gridOffsetY)/this._cellHeight),r=Math.round((t.getX()-this._gridOffsetX)/this._cellWidth),a=Math.round((t.getY()-this._gridOffsetY)/this._cellHeight);if(r==i&&a==h){this._path.length=0,this._path.push([t.getX(),t.getY()]),this._path.push([s,n]),this._enterSegment(0),this._pathFound=!0;return}if(this._searchContext.allowDiagonals(this._allowDiagonals),this._searchContext.setObstacles(this._manager),this._searchContext.setCellSize(this._cellWidth,this._cellHeight),this._searchContext.setGridOffset(this._gridOffsetX,this._gridOffsetY),this._searchContext.setStartPosition(t.getX(),t.getY()),this._searchContext.setObjectSize(t.getX()-t.getDrawableX()+this._extraBorder,t.getY()-t.getDrawableY()+this._extraBorder,t.getWidth()-(t.getX()-t.getDrawableX())+this._extraBorder,t.getHeight()-(t.getY()-t.getDrawableY())+this._extraBorder),this._searchContext.computePathTo(s,n)){let o=this._searchContext.getFinalNode(),_=0;for(;o;)_===this._path.length&&this._path.push([0,0]),this._path[_][0]=o.pos[0]*this._cellWidth+this._gridOffsetX,this._path[_][1]=o.pos[1]*this._cellHeight+this._gridOffsetY,o=o.parent,_++;if(this._path.length=_,this._path.reverse(),this._path[0][0]=t.getX(),this._path[0][1]=t.getY(),this._allowDiagonals&&this._smoothingMaxCellGap>0){l.pathfinding.simplifyPath(this._path,this._smoothingMaxCellGap*Math.min(this._cellWidth,this._cellHeight),l.PathfindingRuntimeBehavior._smoothingResultVertices,l.PathfindingRuntimeBehavior._smoothingWorkingVertices);let g=this._path;this._path=l.PathfindingRuntimeBehavior._smoothingResultVertices,l.PathfindingRuntimeBehavior._smoothingResultVertices=g}this._enterSegment(0),this._pathFound=!0;return}this._pathFound=!1}_enterSegment(e){if(this._path.length!==0)if(this._currentSegment=e,this._currentSegment<this._path.length-1){const s=this._path[this._currentSegment+1][0]-this._path[this._currentSegment][0],n=this._path[this._currentSegment+1][1]-this._path[this._currentSegment][1];this._totalSegmentDistance=Math.sqrt(s*s+n*n),this._distanceOnSegment=0,this._reachedEnd=!1,this._movementAngle=(l.toDegrees(Math.atan2(n,s))+360)%360}else this._reachedEnd=!0,this._speed=0}doStepPreEvents(e){if(this._path.length===0||this._reachedEnd)return;const s=this.owner.getElapsedTime()/1e3,n=this._speed;this._speed!==this._maxSpeed&&(this._speed+=this._acceleration*s,this._speed>this._maxSpeed&&(this._speed=this._maxSpeed)),this._angularSpeed=this._angularMaxSpeed,this._distanceOnSegment+=(this._speed+n)/2*s;const t=this._totalSegmentDistance-this._distanceOnSegment;t<=0&&this._currentSegment<this._path.length&&(this._enterSegment(this._currentSegment+1),this._distanceOnSegment=-t);let i=[0,0];this._currentSegment<this._path.length-1?(i[0]=l.evtTools.common.lerp(this._path[this._currentSegment][0],this._path[this._currentSegment+1][0],this._distanceOnSegment/this._totalSegmentDistance),i[1]=l.evtTools.common.lerp(this._path[this._currentSegment][1],this._path[this._currentSegment+1][1],this._distanceOnSegment/this._totalSegmentDistance),this._rotateObject&&this.owner.getAngle()!==this._movementAngle+this._angleOffset&&this.owner.rotateTowardAngle(this._movementAngle+this._angleOffset,this._angularSpeed)):i=this._path[this._path.length-1],this.owner.setX(i[0]),this.owner.setY(i[1])}doStepPostEvents(e){}static euclideanDistance(e,s){return Math.sqrt((e[0]-s[0])*(e[0]-s[0])+(e[1]-s[1])*(e[1]-s[1]))}static manhattanDistance(e,s){return Math.abs(e[0]-s[0])+Math.abs(e[1]-s[1])}}f._smoothingResultVertices=[],f._smoothingWorkingVertices=[],l.PathfindingRuntimeBehavior=f,l.registerBehavior("PathfindingBehavior::PathfindingBehavior",l.PathfindingRuntimeBehavior),function(s){class c{constructor(t,i){this.cost=0;this.smallestCost=-1;this.estimateCost=-1;this.parent=null;this.open=!0;this.pos=[t,i]}reinitialize(t,i){this.pos[0]=t,this.pos[1]=i,this.cost=0,this.smallestCost=-1,this.estimateCost=-1,this.parent=null,this.open=!0}}s.Node=c;class e{constructor(t){this._finalNode=null;this._destination=[0,0];this._start=[0,0];this._startX=0;this._startY=0;this._allowDiagonals=!0;this._maxComplexityFactor=50;this._cellWidth=20;this._cellHeight=20;this._gridOffsetX=0;this._gridOffsetY=0;this._leftBorder=0;this._rightBorder=0;this._topBorder=0;this._bottomBorder=0;this._allNodes=[];this._openNodes=[];this._closeObstacles=[];this._nodeCache=[];this._obstacles=t,this._distanceFunction=s.euclideanDistance}setObstacles(t){return this._obstacles=t,this}getFinalNode(){return this._finalNode}allowDiagonals(t){return this._allowDiagonals=t,this._distanceFunction=t?s.euclideanDistance:s.manhattanDistance,this}setStartPosition(t,i){return this._startX=t,this._startY=i,this}setObjectSize(t,i,h,r){return this._leftBorder=t,this._rightBorder=h,this._topBorder=i,this._bottomBorder=r,this}setCellSize(t,i){return this._cellWidth=t,this._cellHeight=i,this}setGridOffset(t,i){return this._gridOffsetX=t,this._gridOffsetY=i,this}computePathTo(t,i){if(this._obstacles===null){p.log("You tried to compute a path without specifying the obstacles");return}this._destination[0]=Math.round((t-this._gridOffsetX)/this._cellWidth),this._destination[1]=Math.round((i-this._gridOffsetY)/this._cellHeight),this._start[0]=Math.round((this._startX-this._gridOffsetX)/this._cellWidth),this._start[1]=Math.round((this._startY-this._gridOffsetY)/this._cellHeight),this._freeAllNodes();const h=this._getNode(this._start[0],this._start[1]);h.smallestCost=0,h.estimateCost=0+this._distanceFunction(this._start,this._destination),this._openNodes.length=0,this._openNodes.push(h);let r=0;const a=h.estimateCost*this._maxComplexityFactor;for(;this._openNodes.length!==0;){if(r++>a)return console.warn(`No path was found after covering ${a} cells.`),!1;const o=this._openNodes.shift();if(o.open=!1,o.pos[0]==this._destination[0]&&o.pos[1]==this._destination[1])return this._finalNode=o,!0;this._insertNeighbors(o)}return!1}_freeAllNodes(){if(this._nodeCache.length<=32e3){for(const t in this._allNodes)if(this._allNodes.hasOwnProperty(t)){const i=this._allNodes[t];for(const h in i)i.hasOwnProperty(h)&&this._nodeCache.push(i[h])}}this._allNodes=[]}_insertNeighbors(t){this._addOrUpdateNode(t.pos[0]+1,t.pos[1],t,1),this._addOrUpdateNode(t.pos[0]-1,t.pos[1],t,1),this._addOrUpdateNode(t.pos[0],t.pos[1]+1,t,1),this._addOrUpdateNode(t.pos[0],t.pos[1]-1,t,1),this._allowDiagonals&&(this._addOrUpdateNode(t.pos[0]+1,t.pos[1]+1,t,1.414213562),this._addOrUpdateNode(t.pos[0]+1,t.pos[1]-1,t,1.414213562),this._addOrUpdateNode(t.pos[0]-1,t.pos[1]-1,t,1.414213562),this._addOrUpdateNode(t.pos[0]-1,t.pos[1]+1,t,1.414213562))}_getNode(t,i){if(this._allNodes.hasOwnProperty(t)){if(this._allNodes[t].hasOwnProperty(i))return this._allNodes[t][i]}else this._allNodes[t]=[];let h;this._nodeCache.length!==0?(h=this._nodeCache.shift(),h.reinitialize(t,i)):h=new c(t,i);const r=t*this._cellWidth+this._gridOffsetX,a=i*this._cellHeight+this._gridOffsetY;let o=!1;const _=this._cellHeight>this._cellWidth?this._cellHeight*2:this._cellWidth*2;this._obstacles.getAllObstaclesAround(r,a,_,this._closeObstacles);for(let g=0;g<this._closeObstacles.length;++g){const d=this._closeObstacles[g].owner,u=Math.floor((d.getDrawableX()-this._rightBorder-this._gridOffsetX)/this._cellWidth),m=Math.floor((d.getDrawableY()-this._bottomBorder-this._gridOffsetY)/this._cellHeight),O=Math.ceil((d.getDrawableX()+d.getWidth()+this._leftBorder-this._gridOffsetX)/this._cellWidth),S=Math.ceil((d.getDrawableY()+d.getHeight()+this._topBorder-this._gridOffsetY)/this._cellHeight);if(u<t&&t<O&&m<i&&i<S)if(o=!0,this._closeObstacles[g].isImpassable()){h.cost=-1;break}else h.cost+=this._closeObstacles[g].getCost()}return o||(h.cost=1),this._allNodes[t][i]=h,h}_addOrUpdateNode(t,i,h,r){const a=this._getNode(t,i);if(!(!a.open||a.cost<0)&&(a.smallestCost===-1||a.smallestCost>h.smallestCost+(h.cost+a.cost)/2*r)){if(a.smallestCost!=-1){for(let o=0;o<this._openNodes.length;++o)if(this._openNodes[o].pos[0]==a.pos[0]&&this._openNodes[o].pos[1]==a.pos[1]){this._openNodes.splice(o,1);break}}if(a.smallestCost=h.smallestCost+(h.cost+a.cost)/2*r,a.parent=h,a.estimateCost=a.smallestCost+this._distanceFunction(a.pos,this._destination),this._openNodes.length===0||this._openNodes[this._openNodes.length-1].estimateCost<a.estimateCost)this._openNodes.push(a);else for(let o=0;o<this._openNodes.length;++o)if(this._openNodes[o].estimateCost>=a.estimateCost){this._openNodes.splice(o,0,a);break}}}}s.SearchContext=e}(f=l.PathfindingRuntimeBehavior||(l.PathfindingRuntimeBehavior={}))})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=pathfindingruntimebehavior.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/PathfindingBehavior/pathfindingruntimebehavior.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nGDevelop - Pathfinding Behavior Extension\nCopyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com)\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Pathfinding behavior');\n\n interface PathfindingNetworkSyncDataType {\n // Syncing the path should be enough to have a good prediction.\n path: FloatPoint[];\n pf: boolean;\n sp: number;\n as: number;\n cs: number;\n tss: number;\n re: boolean;\n ma: number;\n }\n\n export interface PathfindingNetworkSyncData extends BehaviorNetworkSyncData {\n props: PathfindingNetworkSyncDataType;\n }\n\n /**\n * PathfindingRuntimeBehavior represents a behavior allowing objects to\n * follow a path computed to avoid obstacles.\n */\n export class PathfindingRuntimeBehavior extends gdjs.RuntimeBehavior {\n _path: Array<FloatPoint> = [];\n /** Used by the path simplification algorithm */\n static _smoothingResultVertices: Array<FloatPoint> = [];\n /** Used by the path simplification algorithm */\n static _smoothingWorkingVertices: Array<FloatPoint> = [];\n\n //Behavior configuration:\n _allowDiagonals: boolean;\n _acceleration: float;\n _maxSpeed: float;\n _angularMaxSpeed: float;\n _rotateObject: boolean;\n _angleOffset: float;\n _cellWidth: float;\n _cellHeight: float;\n _gridOffsetX: float;\n _gridOffsetY: float;\n _extraBorder: float;\n _smoothingMaxCellGap: float;\n\n //Attributes used for traveling on the path:\n _pathFound: boolean = false;\n _speed: float = 0;\n _angularSpeed: float = 0;\n _distanceOnSegment: float = 0;\n _totalSegmentDistance: float = 0;\n _currentSegment: integer = 0;\n _reachedEnd: boolean = false;\n _manager: PathfindingObstaclesManager;\n _searchContext: PathfindingRuntimeBehavior.SearchContext;\n\n _movementAngle: float = 0;\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n behaviorData,\n owner: gdjs.RuntimeObject\n ) {\n super(instanceContainer, behaviorData, owner);\n\n //The path computed and followed by the object (Array of arrays containing x and y position)\n if (this._path === undefined) {\n } else {\n this._path.length = 0;\n }\n this._allowDiagonals = behaviorData.allowDiagonals;\n this._acceleration = behaviorData.acceleration;\n this._maxSpeed = behaviorData.maxSpeed;\n this._angularMaxSpeed = behaviorData.angularMaxSpeed;\n this._rotateObject = behaviorData.rotateObject;\n this._angleOffset = behaviorData.angleOffset;\n this._cellWidth = behaviorData.cellWidth;\n this._cellHeight = behaviorData.cellHeight;\n this._gridOffsetX = behaviorData.gridOffsetX || 0;\n this._gridOffsetY = behaviorData.gridOffsetY || 0;\n this._extraBorder = behaviorData.extraBorder;\n this._smoothingMaxCellGap = behaviorData.smoothingMaxCellGap || 0;\n this._manager =\n gdjs.PathfindingObstaclesManager.getManager(instanceContainer);\n this._searchContext = new gdjs.PathfindingRuntimeBehavior.SearchContext(\n this._manager\n );\n }\n\n updateFromBehaviorData(oldBehaviorData, newBehaviorData): boolean {\n if (oldBehaviorData.allowDiagonals !== newBehaviorData.allowDiagonals) {\n this.allowDiagonals(newBehaviorData.allowDiagonals);\n }\n if (oldBehaviorData.acceleration !== newBehaviorData.acceleration) {\n this.setAcceleration(newBehaviorData.acceleration);\n }\n if (oldBehaviorData.maxSpeed !== newBehaviorData.maxSpeed) {\n this.setMaxSpeed(newBehaviorData.maxSpeed);\n }\n if (oldBehaviorData.angularMaxSpeed !== newBehaviorData.angularMaxSpeed) {\n this.setAngularMaxSpeed(newBehaviorData.angularMaxSpeed);\n }\n if (oldBehaviorData.rotateObject !== newBehaviorData.rotateObject) {\n this.setRotateObject(newBehaviorData.rotateObject);\n }\n if (oldBehaviorData.angleOffset !== newBehaviorData.angleOffset) {\n this.setAngleOffset(newBehaviorData.angleOffset);\n }\n if (oldBehaviorData.cellWidth !== newBehaviorData.cellWidth) {\n this.setCellWidth(newBehaviorData.cellWidth);\n }\n if (oldBehaviorData.cellHeight !== newBehaviorData.cellHeight) {\n this.setCellHeight(newBehaviorData.cellHeight);\n }\n if (oldBehaviorData.gridOffsetX !== newBehaviorData.gridOffsetX) {\n this._gridOffsetX = newBehaviorData.gridOffsetX;\n }\n if (oldBehaviorData.gridOffsetY !== newBehaviorData.gridOffsetY) {\n this._gridOffsetY = newBehaviorData.gridOffsetY;\n }\n if (oldBehaviorData.extraBorder !== newBehaviorData.extraBorder) {\n this.setExtraBorder(newBehaviorData.extraBorder);\n }\n if (\n oldBehaviorData.smoothingMaxCellGap !==\n newBehaviorData.smoothingMaxCellGap\n ) {\n this._smoothingMaxCellGap = newBehaviorData.smoothingMaxCellGap;\n }\n return true;\n }\n\n getNetworkSyncData(): PathfindingNetworkSyncData {\n return {\n ...super.getNetworkSyncData(),\n props: {\n path: this._path,\n pf: this._pathFound,\n sp: this._speed,\n as: this._angularSpeed,\n cs: this._currentSegment,\n tss: this._totalSegmentDistance,\n re: this._reachedEnd,\n ma: this._movementAngle,\n },\n };\n }\n\n updateFromNetworkSyncData(\n networkSyncData: PathfindingNetworkSyncData\n ): void {\n super.updateFromNetworkSyncData(networkSyncData);\n const behaviorSpecificProps = networkSyncData.props;\n if (behaviorSpecificProps.path !== undefined) {\n this._path = behaviorSpecificProps.path;\n }\n if (behaviorSpecificProps.pf !== undefined) {\n this._pathFound = behaviorSpecificProps.pf;\n }\n if (behaviorSpecificProps.sp !== undefined) {\n this._speed = behaviorSpecificProps.sp;\n }\n if (behaviorSpecificProps.as !== undefined) {\n this._angularSpeed = behaviorSpecificProps.as;\n }\n if (\n behaviorSpecificProps.cs !== undefined &&\n behaviorSpecificProps.cs !== this._currentSegment\n ) {\n this._currentSegment = behaviorSpecificProps.cs;\n }\n if (behaviorSpecificProps.tss !== undefined) {\n this._totalSegmentDistance = behaviorSpecificProps.tss;\n }\n if (behaviorSpecificProps.re !== undefined) {\n this._reachedEnd = behaviorSpecificProps.re;\n }\n if (behaviorSpecificProps.ma !== undefined) {\n this._movementAngle = behaviorSpecificProps.ma;\n }\n }\n\n setCellWidth(width: float): void {\n this._cellWidth = width;\n }\n\n getCellWidth(): float {\n return this._cellWidth;\n }\n\n setCellHeight(height: float): void {\n this._cellHeight = height;\n }\n\n getCellHeight(): float {\n return this._cellHeight;\n }\n\n setGridOffsetX(gridOffsetX: float): void {\n this._gridOffsetX = gridOffsetX;\n }\n\n getGridOffsetX(): float {\n return this._gridOffsetX;\n }\n\n setGridOffsetY(gridOffsetY: float): void {\n this._gridOffsetY = gridOffsetY;\n }\n\n getGridOffsetY(): float {\n return this._gridOffsetY;\n }\n\n setAcceleration(acceleration: float): void {\n this._acceleration = acceleration;\n }\n\n getAcceleration() {\n return this._acceleration;\n }\n\n setMaxSpeed(maxSpeed: float): void {\n this._maxSpeed = maxSpeed;\n }\n\n getMaxSpeed() {\n return this._maxSpeed;\n }\n\n setSpeed(speed: float): void {\n this._speed = speed;\n }\n\n getSpeed() {\n return this._speed;\n }\n\n getMovementAngle() {\n return this._movementAngle;\n }\n\n movementAngleIsAround(degreeAngle: float, tolerance: float) {\n return (\n Math.abs(\n gdjs.evtTools.common.angleDifference(this._movementAngle, degreeAngle)\n ) <= tolerance\n );\n }\n\n setAngularMaxSpeed(angularMaxSpeed: float): void {\n this._angularMaxSpeed = angularMaxSpeed;\n }\n\n getAngularMaxSpeed() {\n return this._angularMaxSpeed;\n }\n\n setAngleOffset(angleOffset: float): void {\n this._angleOffset = angleOffset;\n }\n\n getAngleOffset() {\n return this._angleOffset;\n }\n\n setExtraBorder(extraBorder): void {\n this._extraBorder = extraBorder;\n }\n\n getExtraBorder() {\n return this._extraBorder;\n }\n\n allowDiagonals(allow: boolean) {\n this._allowDiagonals = allow;\n }\n\n diagonalsAllowed() {\n return this._allowDiagonals;\n }\n\n setRotateObject(allow: boolean): void {\n this._rotateObject = allow;\n }\n\n isObjectRotated(): boolean {\n return this._rotateObject;\n }\n\n getNodeX(index: integer): float {\n if (index < this._path.length) {\n return this._path[index][0];\n }\n return 0;\n }\n\n getNodeY(index: integer): float {\n if (index < this._path.length) {\n return this._path[index][1];\n }\n return 0;\n }\n\n getNextNodeIndex() {\n if (this._currentSegment + 1 < this._path.length) {\n return this._currentSegment + 1;\n } else {\n return this._path.length - 1;\n }\n }\n\n getNodeCount(): integer {\n return this._path.length;\n }\n\n getNextNodeX(): float {\n if (this._path.length === 0) {\n return 0;\n }\n if (this._currentSegment + 1 < this._path.length) {\n return this._path[this._currentSegment + 1][0];\n } else {\n return this._path[this._path.length - 1][0];\n }\n }\n\n getNextNodeY(): float {\n if (this._path.length === 0) {\n return 0;\n }\n if (this._currentSegment + 1 < this._path.length) {\n return this._path[this._currentSegment + 1][1];\n } else {\n return this._path[this._path.length - 1][1];\n }\n }\n\n getLastNodeX(): float {\n if (this._path.length < 2) {\n return 0;\n }\n if (this._currentSegment < this._path.length - 1) {\n return this._path[this._currentSegment][0];\n } else {\n return this._path[this._path.length - 1][0];\n }\n }\n\n getLastNodeY(): float {\n if (this._path.length < 2) {\n return 0;\n }\n if (this._currentSegment < this._path.length - 1) {\n return this._path[this._currentSegment][1];\n } else {\n return this._path[this._path.length - 1][1];\n }\n }\n\n getDestinationX(): float {\n if (this._path.length === 0) {\n return 0;\n }\n return this._path[this._path.length - 1][0];\n }\n\n getDestinationY(): float {\n if (this._path.length === 0) {\n return 0;\n }\n return this._path[this._path.length - 1][1];\n }\n\n /**\n * Return true if the latest call to moveTo succeeded.\n */\n pathFound() {\n return this._pathFound;\n }\n\n /**\n * Return true if the object reached its destination.\n */\n destinationReached() {\n return this._reachedEnd;\n }\n\n /**\n * Compute and move on the path to the specified destination.\n */\n moveTo(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n x: float,\n y: float\n ) {\n const owner = this.owner;\n\n //First be sure that there is a path to compute.\n const targetCellX = Math.round((x - this._gridOffsetX) / this._cellWidth);\n const targetCellY = Math.round(\n (y - this._gridOffsetY) / this._cellHeight\n );\n const startCellX = Math.round(\n (owner.getX() - this._gridOffsetX) / this._cellWidth\n );\n const startCellY = Math.round(\n (owner.getY() - this._gridOffsetY) / this._cellHeight\n );\n if (startCellX == targetCellX && startCellY == targetCellY) {\n this._path.length = 0;\n this._path.push([owner.getX(), owner.getY()]);\n this._path.push([x, y]);\n this._enterSegment(0);\n this._pathFound = true;\n return;\n }\n\n //Start searching for a path\n this._searchContext.allowDiagonals(this._allowDiagonals);\n this._searchContext.setObstacles(this._manager);\n this._searchContext.setCellSize(this._cellWidth, this._cellHeight);\n this._searchContext.setGridOffset(this._gridOffsetX, this._gridOffsetY);\n this._searchContext.setStartPosition(owner.getX(), owner.getY());\n this._searchContext.setObjectSize(\n owner.getX() - owner.getDrawableX() + this._extraBorder,\n owner.getY() - owner.getDrawableY() + this._extraBorder,\n owner.getWidth() -\n (owner.getX() - owner.getDrawableX()) +\n this._extraBorder,\n owner.getHeight() -\n (owner.getY() - owner.getDrawableY()) +\n this._extraBorder\n );\n if (this._searchContext.computePathTo(x, y)) {\n //Path found: memorize it\n let node = this._searchContext.getFinalNode();\n let finalPathLength = 0;\n while (node) {\n if (finalPathLength === this._path.length) {\n this._path.push([0, 0]);\n }\n this._path[finalPathLength][0] =\n node.pos[0] * this._cellWidth + this._gridOffsetX;\n this._path[finalPathLength][1] =\n node.pos[1] * this._cellHeight + this._gridOffsetY;\n node = node.parent;\n finalPathLength++;\n }\n this._path.length = finalPathLength;\n this._path.reverse();\n this._path[0][0] = owner.getX();\n this._path[0][1] = owner.getY();\n\n if (this._allowDiagonals && this._smoothingMaxCellGap > 0) {\n gdjs.pathfinding.simplifyPath(\n this._path,\n this._smoothingMaxCellGap *\n Math.min(this._cellWidth, this._cellHeight),\n gdjs.PathfindingRuntimeBehavior._smoothingResultVertices,\n gdjs.PathfindingRuntimeBehavior._smoothingWorkingVertices\n );\n let swapArray = this._path;\n this._path = gdjs.PathfindingRuntimeBehavior._smoothingResultVertices;\n gdjs.PathfindingRuntimeBehavior._smoothingResultVertices = swapArray;\n }\n\n this._enterSegment(0);\n this._pathFound = true;\n return;\n }\n\n // No path found\n this._pathFound = false;\n }\n\n _enterSegment(segmentNumber: integer) {\n if (this._path.length === 0) {\n return;\n }\n this._currentSegment = segmentNumber;\n if (this._currentSegment < this._path.length - 1) {\n const pathX =\n this._path[this._currentSegment + 1][0] -\n this._path[this._currentSegment][0];\n const pathY =\n this._path[this._currentSegment + 1][1] -\n this._path[this._currentSegment][1];\n this._totalSegmentDistance = Math.sqrt(pathX * pathX + pathY * pathY);\n this._distanceOnSegment = 0;\n this._reachedEnd = false;\n this._movementAngle =\n (gdjs.toDegrees(Math.atan2(pathY, pathX)) + 360) % 360;\n } else {\n this._reachedEnd = true;\n this._speed = 0;\n }\n }\n\n doStepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {\n if (this._path.length === 0 || this._reachedEnd) {\n return;\n }\n\n // Update the speed of the object\n const timeDelta = this.owner.getElapsedTime() / 1000;\n const previousSpeed = this._speed;\n if (this._speed !== this._maxSpeed) {\n this._speed += this._acceleration * timeDelta;\n if (this._speed > this._maxSpeed) {\n this._speed = this._maxSpeed;\n }\n }\n this._angularSpeed = this._angularMaxSpeed;\n\n // Update the time on the segment and change segment if needed\n // Use a Verlet integration to be frame rate independent.\n this._distanceOnSegment +=\n ((this._speed + previousSpeed) / 2) * timeDelta;\n const remainingDistanceOnSegment =\n this._totalSegmentDistance - this._distanceOnSegment;\n if (\n remainingDistanceOnSegment <= 0 &&\n this._currentSegment < this._path.length\n ) {\n this._enterSegment(this._currentSegment + 1);\n this._distanceOnSegment = -remainingDistanceOnSegment;\n }\n\n // Position object on the segment and update its angle\n let newPos = [0, 0];\n if (this._currentSegment < this._path.length - 1) {\n newPos[0] = gdjs.evtTools.common.lerp(\n this._path[this._currentSegment][0],\n this._path[this._currentSegment + 1][0],\n this._distanceOnSegment / this._totalSegmentDistance\n );\n newPos[1] = gdjs.evtTools.common.lerp(\n this._path[this._currentSegment][1],\n this._path[this._currentSegment + 1][1],\n this._distanceOnSegment / this._totalSegmentDistance\n );\n if (\n this._rotateObject &&\n this.owner.getAngle() !== this._movementAngle + this._angleOffset\n ) {\n this.owner.rotateTowardAngle(\n this._movementAngle + this._angleOffset,\n this._angularSpeed\n );\n }\n } else {\n newPos = this._path[this._path.length - 1];\n }\n this.owner.setX(newPos[0]);\n this.owner.setY(newPos[1]);\n }\n\n doStepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}\n\n /**\n * Compute the euclidean distance between two positions.\n * @memberof gdjs.PathfindingRuntimeBehavior\n */\n static euclideanDistance(a: FloatPoint, b: FloatPoint) {\n return Math.sqrt(\n (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])\n );\n }\n\n /**\n * Compute the taxi distance between two positions.\n * @memberof gdjs.PathfindingRuntimeBehavior\n */\n static manhattanDistance(a: FloatPoint, b: FloatPoint) {\n return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]);\n }\n }\n gdjs.registerBehavior(\n 'PathfindingBehavior::PathfindingBehavior',\n gdjs.PathfindingRuntimeBehavior\n );\n\n export namespace PathfindingRuntimeBehavior {\n /**\n * Internal tool class representing a node when looking for a path\n */\n export class Node {\n pos: FloatPoint;\n cost: integer = 0;\n smallestCost: integer = -1;\n estimateCost: integer = -1;\n parent: Node | null = null;\n open: boolean = true;\n\n constructor(xPos: integer, yPos: integer) {\n this.pos = [xPos, yPos];\n }\n\n reinitialize(xPos: integer, yPos: integer) {\n this.pos[0] = xPos;\n this.pos[1] = yPos;\n this.cost = 0;\n this.smallestCost = -1;\n this.estimateCost = -1;\n this.parent = null;\n this.open = true;\n }\n }\n\n /**\n * Internal tool class containing the structures used by A* and members functions related\n * to them.\n * @ignore\n */\n export class SearchContext {\n _obstacles: PathfindingObstaclesManager;\n _finalNode: Node | null = null;\n _destination: FloatPoint = [0, 0];\n _start: FloatPoint = [0, 0];\n _startX: float = 0;\n _startY: float = 0;\n _allowDiagonals: boolean = true;\n _maxComplexityFactor: integer = 50;\n _cellWidth: float = 20;\n _cellHeight: float = 20;\n _gridOffsetX: float = 0;\n _gridOffsetY: float = 0;\n\n _leftBorder: integer = 0;\n _rightBorder: integer = 0;\n _topBorder: integer = 0;\n _bottomBorder: integer = 0;\n _distanceFunction: (pt1: FloatPoint, pt2: FloatPoint) => float;\n //An array of array. Nodes are indexed by their x position, and then by their y position.\n _allNodes: Node[][] = [];\n //An array of nodes sorted by their estimate cost (First node = Lower estimate cost).\n _openNodes: Node[] = [];\n //Used by getNodes to temporarily store obstacles near a position.\n _closeObstacles: gdjs.PathfindingObstacleRuntimeBehavior[] = [];\n //Old nodes constructed in a previous search are stored here to avoid temporary objects (see _freeAllNodes method).\n _nodeCache: Node[] = [];\n\n constructor(obstacles: PathfindingObstaclesManager) {\n this._obstacles = obstacles;\n this._distanceFunction = PathfindingRuntimeBehavior.euclideanDistance;\n }\n\n setObstacles(\n obstacles: PathfindingObstaclesManager\n ): PathfindingRuntimeBehavior.SearchContext {\n this._obstacles = obstacles;\n return this;\n }\n\n getFinalNode() {\n return this._finalNode;\n }\n\n allowDiagonals(allowDiagonals: boolean) {\n this._allowDiagonals = allowDiagonals;\n this._distanceFunction = allowDiagonals\n ? PathfindingRuntimeBehavior.euclideanDistance\n : PathfindingRuntimeBehavior.manhattanDistance;\n return this;\n }\n\n setStartPosition(\n x: float,\n y: float\n ): PathfindingRuntimeBehavior.SearchContext {\n this._startX = x;\n this._startY = y;\n return this;\n }\n\n setObjectSize(\n leftBorder: integer,\n topBorder: integer,\n rightBorder: integer,\n bottomBorder: integer\n ): PathfindingRuntimeBehavior.SearchContext {\n this._leftBorder = leftBorder;\n this._rightBorder = rightBorder;\n this._topBorder = topBorder;\n this._bottomBorder = bottomBorder;\n return this;\n }\n\n setCellSize(\n cellWidth: float,\n cellHeight: float\n ): PathfindingRuntimeBehavior.SearchContext {\n this._cellWidth = cellWidth;\n this._cellHeight = cellHeight;\n return this;\n }\n\n setGridOffset(\n gridOffsetX: float,\n gridOffsetY: float\n ): PathfindingRuntimeBehavior.SearchContext {\n this._gridOffsetX = gridOffsetX;\n this._gridOffsetY = gridOffsetY;\n return this;\n }\n\n computePathTo(targetX: float, targetY: float) {\n if (this._obstacles === null) {\n logger.log(\n 'You tried to compute a path without specifying the obstacles'\n );\n return;\n }\n this._destination[0] = Math.round(\n (targetX - this._gridOffsetX) / this._cellWidth\n );\n this._destination[1] = Math.round(\n (targetY - this._gridOffsetY) / this._cellHeight\n );\n this._start[0] = Math.round(\n (this._startX - this._gridOffsetX) / this._cellWidth\n );\n this._start[1] = Math.round(\n (this._startY - this._gridOffsetY) / this._cellHeight\n );\n\n //Initialize the algorithm\n this._freeAllNodes();\n const startNode = this._getNode(this._start[0], this._start[1]);\n startNode.smallestCost = 0;\n startNode.estimateCost =\n 0 + this._distanceFunction(this._start, this._destination);\n this._openNodes.length = 0;\n this._openNodes.push(startNode);\n\n //A* algorithm main loop\n let iterationCount = 0;\n const maxIterationCount =\n startNode.estimateCost * this._maxComplexityFactor;\n while (this._openNodes.length !== 0) {\n //Make sure we do not search forever.\n if (iterationCount++ > maxIterationCount) {\n console.warn(\n `No path was found after covering ${maxIterationCount} cells.`\n );\n return false;\n }\n\n //Get the most promising node...\n const n = this._openNodes.shift()!;\n //...and flag it as explored\n n.open = false;\n\n //Check if we reached destination?\n if (\n n.pos[0] == this._destination[0] &&\n n.pos[1] == this._destination[1]\n ) {\n this._finalNode = n;\n return true;\n }\n\n //No, so add neighbors to the nodes to explore.\n this._insertNeighbors(n);\n }\n return false;\n }\n\n _freeAllNodes() {\n if (this._nodeCache.length <= 32000) {\n for (const i in this._allNodes) {\n if (this._allNodes.hasOwnProperty(i)) {\n const nodeArray = this._allNodes[i];\n for (const j in nodeArray) {\n if (nodeArray.hasOwnProperty(j)) {\n this._nodeCache.push(nodeArray[j]);\n }\n }\n }\n }\n }\n this._allNodes = [];\n }\n\n /**\n * Insert the neighbors of the current node in the open list\n * (Only if they are not closed, and if the cost is better than the already existing smallest cost).\n */\n _insertNeighbors(currentNode: Node) {\n this._addOrUpdateNode(\n currentNode.pos[0] + 1,\n currentNode.pos[1],\n currentNode,\n 1\n );\n this._addOrUpdateNode(\n currentNode.pos[0] - 1,\n currentNode.pos[1],\n currentNode,\n 1\n );\n this._addOrUpdateNode(\n currentNode.pos[0],\n currentNode.pos[1] + 1,\n currentNode,\n 1\n );\n this._addOrUpdateNode(\n currentNode.pos[0],\n currentNode.pos[1] - 1,\n currentNode,\n 1\n );\n if (this._allowDiagonals) {\n this._addOrUpdateNode(\n currentNode.pos[0] + 1,\n currentNode.pos[1] + 1,\n currentNode,\n 1.414213562\n );\n this._addOrUpdateNode(\n currentNode.pos[0] + 1,\n currentNode.pos[1] - 1,\n currentNode,\n 1.414213562\n );\n this._addOrUpdateNode(\n currentNode.pos[0] - 1,\n currentNode.pos[1] - 1,\n currentNode,\n 1.414213562\n );\n this._addOrUpdateNode(\n currentNode.pos[0] - 1,\n currentNode.pos[1] + 1,\n currentNode,\n 1.414213562\n );\n }\n }\n\n /**\n * Get (or dynamically construct) a node.\n *\n * *All* nodes should be created using this method: The cost of the node is computed thanks\n * to the objects flagged as obstacles.\n */\n _getNode(xPos: integer, yPos: integer): Node {\n //First check if their is a node a the specified position.\n if (this._allNodes.hasOwnProperty(xPos)) {\n if (this._allNodes[xPos].hasOwnProperty(yPos)) {\n return this._allNodes[xPos][yPos];\n }\n } else {\n this._allNodes[xPos] = [];\n }\n\n //No so construct a new node (or get it from the cache)...\n let newNode: Node;\n if (this._nodeCache.length !== 0) {\n newNode = this._nodeCache.shift()!;\n newNode.reinitialize(xPos, yPos);\n } else {\n newNode = new Node(xPos, yPos);\n }\n\n const nodeCenterX = xPos * this._cellWidth + this._gridOffsetX;\n const nodeCenterY = yPos * this._cellHeight + this._gridOffsetY;\n\n //...and update its cost according to obstacles\n let objectsOnCell = false;\n const radius =\n this._cellHeight > this._cellWidth\n ? this._cellHeight * 2\n : this._cellWidth * 2;\n this._obstacles.getAllObstaclesAround(\n nodeCenterX,\n nodeCenterY,\n radius,\n this._closeObstacles\n );\n for (let k = 0; k < this._closeObstacles.length; ++k) {\n const obj = this._closeObstacles[k].owner;\n const topLeftCellX = Math.floor(\n (obj.getDrawableX() - this._rightBorder - this._gridOffsetX) /\n this._cellWidth\n );\n const topLeftCellY = Math.floor(\n (obj.getDrawableY() - this._bottomBorder - this._gridOffsetY) /\n this._cellHeight\n );\n const bottomRightCellX = Math.ceil(\n (obj.getDrawableX() +\n obj.getWidth() +\n this._leftBorder -\n this._gridOffsetX) /\n this._cellWidth\n );\n const bottomRightCellY = Math.ceil(\n (obj.getDrawableY() +\n obj.getHeight() +\n this._topBorder -\n this._gridOffsetY) /\n this._cellHeight\n );\n if (\n topLeftCellX < xPos &&\n xPos < bottomRightCellX &&\n topLeftCellY < yPos &&\n yPos < bottomRightCellY\n ) {\n objectsOnCell = true;\n if (this._closeObstacles[k].isImpassable()) {\n //The cell is impassable, stop here.\n newNode.cost = -1;\n break;\n } else {\n //Superimpose obstacles\n newNode.cost += this._closeObstacles[k].getCost();\n }\n }\n }\n if (!objectsOnCell) {\n newNode.cost = 1;\n }\n\n //Default cost when no objects put on the cell.\n this._allNodes[xPos][yPos] = newNode;\n return newNode;\n }\n\n /**\n * Add a node to the openNodes (only if the cost to reach it is less than the existing cost, if any).\n */\n _addOrUpdateNode(\n newNodeX: integer,\n newNodeY: integer,\n currentNode: Node,\n factor: float\n ) {\n const neighbor = this._getNode(newNodeX, newNodeY);\n\n //cost < 0 means impassable obstacle\n if (!neighbor.open || neighbor.cost < 0) {\n return;\n }\n\n //Update the node costs and parent if the path coming from currentNode is better:\n if (\n neighbor.smallestCost === -1 ||\n neighbor.smallestCost >\n currentNode.smallestCost +\n ((currentNode.cost + neighbor.cost) / 2.0) * factor\n ) {\n if (neighbor.smallestCost != -1) {\n //The node is already in the open list..\n for (let i = 0; i < this._openNodes.length; ++i) {\n if (\n this._openNodes[i].pos[0] == neighbor.pos[0] &&\n this._openNodes[i].pos[1] == neighbor.pos[1]\n ) {\n this._openNodes.splice(\n i,\n //..so remove it as its estimate cost will be updated.\n 1\n );\n break;\n }\n }\n }\n neighbor.smallestCost =\n currentNode.smallestCost +\n ((currentNode.cost + neighbor.cost) / 2.0) * factor;\n neighbor.parent = currentNode;\n neighbor.estimateCost =\n neighbor.smallestCost +\n this._distanceFunction(neighbor.pos, this._destination);\n\n //Add the neighbor to open nodes, which are sorted by their estimate cost:\n if (\n this._openNodes.length === 0 ||\n this._openNodes[this._openNodes.length - 1].estimateCost <\n neighbor.estimateCost\n ) {\n this._openNodes.push(neighbor);\n } else {\n for (let i = 0; i < this._openNodes.length; ++i) {\n if (this._openNodes[i].estimateCost >= neighbor.estimateCost) {\n this._openNodes.splice(i, 0, neighbor);\n break;\n }\n }\n }\n }\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAIA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,wBAsBxB,eAAyC,GAAK,eAAgB,CAkCnE,YACE,EACA,EACA,EACA,CACA,MAAM,EAAmB,EAAc,GAtCzC,WAA2B,GAqB3B,gBAAsB,GACtB,YAAgB,EAChB,mBAAuB,EACvB,wBAA4B,EAC5B,2BAA+B,EAC/B,qBAA2B,EAC3B,iBAAuB,GAIvB,oBAAwB,EAUtB,AAAI,KAAK,QAAU,QAEjB,MAAK,MAAM,OAAS,GAEtB,KAAK,gBAAkB,EAAa,eACpC,KAAK,cAAgB,EAAa,aAClC,KAAK,UAAY,EAAa,SAC9B,KAAK,iBAAmB,EAAa,gBACrC,KAAK,cAAgB,EAAa,aAClC,KAAK,aAAe,EAAa,YACjC,KAAK,WAAa,EAAa,UAC/B,KAAK,YAAc,EAAa,WAChC,KAAK,aAAe,EAAa,aAAe,EAChD,KAAK,aAAe,EAAa,aAAe,EAChD,KAAK,aAAe,EAAa,YACjC,KAAK,qBAAuB,EAAa,qBAAuB,EAChE,KAAK,SACH,EAAK,4BAA4B,WAAW,GAC9C,KAAK,eAAiB,GAAI,GAAK,2BAA2B,cACxD,KAAK,UAIT,uBAAuB,EAAiB,EAA0B,CAChE,MAAI,GAAgB,iB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EAAS,MAAQ,EAAS,KAAO,IAMpC,GAAS,eAAiB,IAC1B,EAAS,aACP,EAAY,aACR,GAAY,KAAO,EAAS,MAAQ,EAAO,GACjD,CACA,GAAI,EAAS,cAAgB,IAE3B,OAAS,GAAI,EAAG,EAAI,KAAK,WAAW,OAAQ,EAAE,EAC5C,GACE,KAAK,WAAW,GAAG,IAAI,IAAM,EAAS,IAAI,IAC1C,KAAK,WAAW,GAAG,IAAI,IAAM,EAAS,IAAI,GAC1C,CACA,KAAK,WAAW,OACd,EAEA,GAEF,OAaN,GATA,EAAS,aACP,EAAY,aACV,GAAY,KAAO,EAAS,MAAQ,EAAO,EAC/C,EAAS,OAAS,EAClB,EAAS,aACP,EAAS,aACT,KAAK,kBAAkB,EAAS,IAAK,KAAK,cAI1C,KAAK,WAAW,SAAW,GAC3B,KAAK,WAAW,KAAK,WAAW,OAAS,GAAG,aAC1C,EAAS,aAEX,KAAK,WAAW,KAAK,OAErB,QAAS,GAAI,EAAG,EAAI,KAAK,WAAW,OAAQ,EAAE,EAC5C,GAAI,KAAK,WAAW,GAAG,cAAgB,EAAS,aAAc,CAC5D,KAAK,WAAW,OAAO,EAAG,EAAG,GAC7B,SAvXL,EAAM,iBAhCE,qEAtkBT",
|
|
4
|
+
"sourcesContent": ["/*\nGDevelop - Pathfinding Behavior Extension\nCopyright (c) 2010-2016 Florian Rival (Florian.Rival@gmail.com)\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('Pathfinding behavior');\n\n interface PathfindingNetworkSyncDataType {\n // Syncing the path and its position on it should be enough to have a good prediction.\n path: FloatPoint[];\n pf: boolean;\n sp: number;\n as: number;\n cs: number;\n tss: number;\n re: boolean;\n ma: number;\n dos: number;\n }\n\n export interface PathfindingNetworkSyncData extends BehaviorNetworkSyncData {\n props: PathfindingNetworkSyncDataType;\n }\n\n /**\n * PathfindingRuntimeBehavior represents a behavior allowing objects to\n * follow a path computed to avoid obstacles.\n */\n export class PathfindingRuntimeBehavior extends gdjs.RuntimeBehavior {\n _path: Array<FloatPoint> = [];\n /** Used by the path simplification algorithm */\n static _smoothingResultVertices: Array<FloatPoint> = [];\n /** Used by the path simplification algorithm */\n static _smoothingWorkingVertices: Array<FloatPoint> = [];\n\n //Behavior configuration:\n _allowDiagonals: boolean;\n _acceleration: float;\n _maxSpeed: float;\n _angularMaxSpeed: float;\n _rotateObject: boolean;\n _angleOffset: float;\n _cellWidth: float;\n _cellHeight: float;\n _gridOffsetX: float;\n _gridOffsetY: float;\n _extraBorder: float;\n _smoothingMaxCellGap: float;\n\n //Attributes used for traveling on the path:\n _pathFound: boolean = false;\n _speed: float = 0;\n _angularSpeed: float = 0;\n _distanceOnSegment: float = 0;\n _totalSegmentDistance: float = 0;\n _currentSegment: integer = 0;\n _reachedEnd: boolean = false;\n _manager: PathfindingObstaclesManager;\n _searchContext: PathfindingRuntimeBehavior.SearchContext;\n\n _movementAngle: float = 0;\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n behaviorData,\n owner: gdjs.RuntimeObject\n ) {\n super(instanceContainer, behaviorData, owner);\n\n //The path computed and followed by the object (Array of arrays containing x and y position)\n if (this._path === undefined) {\n } else {\n this._path.length = 0;\n }\n this._allowDiagonals = behaviorData.allowDiagonals;\n this._acceleration = behaviorData.acceleration;\n this._maxSpeed = behaviorData.maxSpeed;\n this._angularMaxSpeed = behaviorData.angularMaxSpeed;\n this._rotateObject = behaviorData.rotateObject;\n this._angleOffset = behaviorData.angleOffset;\n this._cellWidth = behaviorData.cellWidth;\n this._cellHeight = behaviorData.cellHeight;\n this._gridOffsetX = behaviorData.gridOffsetX || 0;\n this._gridOffsetY = behaviorData.gridOffsetY || 0;\n this._extraBorder = behaviorData.extraBorder;\n this._smoothingMaxCellGap = behaviorData.smoothingMaxCellGap || 0;\n this._manager =\n gdjs.PathfindingObstaclesManager.getManager(instanceContainer);\n this._searchContext = new gdjs.PathfindingRuntimeBehavior.SearchContext(\n this._manager\n );\n }\n\n updateFromBehaviorData(oldBehaviorData, newBehaviorData): boolean {\n if (oldBehaviorData.allowDiagonals !== newBehaviorData.allowDiagonals) {\n this.allowDiagonals(newBehaviorData.allowDiagonals);\n }\n if (oldBehaviorData.acceleration !== newBehaviorData.acceleration) {\n this.setAcceleration(newBehaviorData.acceleration);\n }\n if (oldBehaviorData.maxSpeed !== newBehaviorData.maxSpeed) {\n this.setMaxSpeed(newBehaviorData.maxSpeed);\n }\n if (oldBehaviorData.angularMaxSpeed !== newBehaviorData.angularMaxSpeed) {\n this.setAngularMaxSpeed(newBehaviorData.angularMaxSpeed);\n }\n if (oldBehaviorData.rotateObject !== newBehaviorData.rotateObject) {\n this.setRotateObject(newBehaviorData.rotateObject);\n }\n if (oldBehaviorData.angleOffset !== newBehaviorData.angleOffset) {\n this.setAngleOffset(newBehaviorData.angleOffset);\n }\n if (oldBehaviorData.cellWidth !== newBehaviorData.cellWidth) {\n this.setCellWidth(newBehaviorData.cellWidth);\n }\n if (oldBehaviorData.cellHeight !== newBehaviorData.cellHeight) {\n this.setCellHeight(newBehaviorData.cellHeight);\n }\n if (oldBehaviorData.gridOffsetX !== newBehaviorData.gridOffsetX) {\n this._gridOffsetX = newBehaviorData.gridOffsetX;\n }\n if (oldBehaviorData.gridOffsetY !== newBehaviorData.gridOffsetY) {\n this._gridOffsetY = newBehaviorData.gridOffsetY;\n }\n if (oldBehaviorData.extraBorder !== newBehaviorData.extraBorder) {\n this.setExtraBorder(newBehaviorData.extraBorder);\n }\n if (\n oldBehaviorData.smoothingMaxCellGap !==\n newBehaviorData.smoothingMaxCellGap\n ) {\n this._smoothingMaxCellGap = newBehaviorData.smoothingMaxCellGap;\n }\n return true;\n }\n\n getNetworkSyncData(\n options: GetNetworkSyncDataOptions\n ): PathfindingNetworkSyncData {\n return {\n ...super.getNetworkSyncData(options),\n props: {\n path: this._path,\n pf: this._pathFound,\n sp: this._speed,\n as: this._angularSpeed,\n cs: this._currentSegment,\n tss: this._totalSegmentDistance,\n re: this._reachedEnd,\n ma: this._movementAngle,\n dos: this._distanceOnSegment,\n },\n };\n }\n\n updateFromNetworkSyncData(\n networkSyncData: PathfindingNetworkSyncData,\n options: UpdateFromNetworkSyncDataOptions\n ): void {\n super.updateFromNetworkSyncData(networkSyncData, options);\n const behaviorSpecificProps = networkSyncData.props;\n if (behaviorSpecificProps.path !== undefined) {\n this._path = behaviorSpecificProps.path;\n }\n if (behaviorSpecificProps.pf !== undefined) {\n this._pathFound = behaviorSpecificProps.pf;\n }\n if (behaviorSpecificProps.sp !== undefined) {\n this._speed = behaviorSpecificProps.sp;\n }\n if (behaviorSpecificProps.as !== undefined) {\n this._angularSpeed = behaviorSpecificProps.as;\n }\n if (\n behaviorSpecificProps.cs !== undefined &&\n behaviorSpecificProps.cs !== this._currentSegment\n ) {\n this._currentSegment = behaviorSpecificProps.cs;\n }\n if (behaviorSpecificProps.tss !== undefined) {\n this._totalSegmentDistance = behaviorSpecificProps.tss;\n }\n if (behaviorSpecificProps.re !== undefined) {\n this._reachedEnd = behaviorSpecificProps.re;\n }\n if (behaviorSpecificProps.ma !== undefined) {\n this._movementAngle = behaviorSpecificProps.ma;\n }\n if (behaviorSpecificProps.dos !== undefined) {\n this._distanceOnSegment = behaviorSpecificProps.dos;\n }\n }\n\n setCellWidth(width: float): void {\n this._cellWidth = width;\n }\n\n getCellWidth(): float {\n return this._cellWidth;\n }\n\n setCellHeight(height: float): void {\n this._cellHeight = height;\n }\n\n getCellHeight(): float {\n return this._cellHeight;\n }\n\n setGridOffsetX(gridOffsetX: float): void {\n this._gridOffsetX = gridOffsetX;\n }\n\n getGridOffsetX(): float {\n return this._gridOffsetX;\n }\n\n setGridOffsetY(gridOffsetY: float): void {\n this._gridOffsetY = gridOffsetY;\n }\n\n getGridOffsetY(): float {\n return this._gridOffsetY;\n }\n\n setAcceleration(acceleration: float): void {\n this._acceleration = acceleration;\n }\n\n getAcceleration() {\n return this._acceleration;\n }\n\n setMaxSpeed(maxSpeed: float): void {\n this._maxSpeed = maxSpeed;\n }\n\n getMaxSpeed() {\n return this._maxSpeed;\n }\n\n setSpeed(speed: float): void {\n this._speed = speed;\n }\n\n getSpeed() {\n return this._speed;\n }\n\n getMovementAngle() {\n return this._movementAngle;\n }\n\n movementAngleIsAround(degreeAngle: float, tolerance: float) {\n return (\n Math.abs(\n gdjs.evtTools.common.angleDifference(this._movementAngle, degreeAngle)\n ) <= tolerance\n );\n }\n\n setAngularMaxSpeed(angularMaxSpeed: float): void {\n this._angularMaxSpeed = angularMaxSpeed;\n }\n\n getAngularMaxSpeed() {\n return this._angularMaxSpeed;\n }\n\n setAngleOffset(angleOffset: float): void {\n this._angleOffset = angleOffset;\n }\n\n getAngleOffset() {\n return this._angleOffset;\n }\n\n setExtraBorder(extraBorder): void {\n this._extraBorder = extraBorder;\n }\n\n getExtraBorder() {\n return this._extraBorder;\n }\n\n allowDiagonals(allow: boolean) {\n this._allowDiagonals = allow;\n }\n\n diagonalsAllowed() {\n return this._allowDiagonals;\n }\n\n setRotateObject(allow: boolean): void {\n this._rotateObject = allow;\n }\n\n isObjectRotated(): boolean {\n return this._rotateObject;\n }\n\n getNodeX(index: integer): float {\n if (index < this._path.length) {\n return this._path[index][0];\n }\n return 0;\n }\n\n getNodeY(index: integer): float {\n if (index < this._path.length) {\n return this._path[index][1];\n }\n return 0;\n }\n\n getNextNodeIndex() {\n if (this._currentSegment + 1 < this._path.length) {\n return this._currentSegment + 1;\n } else {\n return this._path.length - 1;\n }\n }\n\n getNodeCount(): integer {\n return this._path.length;\n }\n\n getNextNodeX(): float {\n if (this._path.length === 0) {\n return 0;\n }\n if (this._currentSegment + 1 < this._path.length) {\n return this._path[this._currentSegment + 1][0];\n } else {\n return this._path[this._path.length - 1][0];\n }\n }\n\n getNextNodeY(): float {\n if (this._path.length === 0) {\n return 0;\n }\n if (this._currentSegment + 1 < this._path.length) {\n return this._path[this._currentSegment + 1][1];\n } else {\n return this._path[this._path.length - 1][1];\n }\n }\n\n getLastNodeX(): float {\n if (this._path.length < 2) {\n return 0;\n }\n if (this._currentSegment < this._path.length - 1) {\n return this._path[this._currentSegment][0];\n } else {\n return this._path[this._path.length - 1][0];\n }\n }\n\n getLastNodeY(): float {\n if (this._path.length < 2) {\n return 0;\n }\n if (this._currentSegment < this._path.length - 1) {\n return this._path[this._currentSegment][1];\n } else {\n return this._path[this._path.length - 1][1];\n }\n }\n\n getDestinationX(): float {\n if (this._path.length === 0) {\n return 0;\n }\n return this._path[this._path.length - 1][0];\n }\n\n getDestinationY(): float {\n if (this._path.length === 0) {\n return 0;\n }\n return this._path[this._path.length - 1][1];\n }\n\n /**\n * Return true if the latest call to moveTo succeeded.\n */\n pathFound() {\n return this._pathFound;\n }\n\n /**\n * Return true if the object reached its destination.\n */\n destinationReached() {\n return this._reachedEnd;\n }\n\n /**\n * Compute and move on the path to the specified destination.\n */\n moveTo(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n x: float,\n y: float\n ) {\n const owner = this.owner;\n\n //First be sure that there is a path to compute.\n const targetCellX = Math.round((x - this._gridOffsetX) / this._cellWidth);\n const targetCellY = Math.round(\n (y - this._gridOffsetY) / this._cellHeight\n );\n const startCellX = Math.round(\n (owner.getX() - this._gridOffsetX) / this._cellWidth\n );\n const startCellY = Math.round(\n (owner.getY() - this._gridOffsetY) / this._cellHeight\n );\n if (startCellX == targetCellX && startCellY == targetCellY) {\n this._path.length = 0;\n this._path.push([owner.getX(), owner.getY()]);\n this._path.push([x, y]);\n this._enterSegment(0);\n this._pathFound = true;\n return;\n }\n\n //Start searching for a path\n this._searchContext.allowDiagonals(this._allowDiagonals);\n this._searchContext.setObstacles(this._manager);\n this._searchContext.setCellSize(this._cellWidth, this._cellHeight);\n this._searchContext.setGridOffset(this._gridOffsetX, this._gridOffsetY);\n this._searchContext.setStartPosition(owner.getX(), owner.getY());\n this._searchContext.setObjectSize(\n owner.getX() - owner.getDrawableX() + this._extraBorder,\n owner.getY() - owner.getDrawableY() + this._extraBorder,\n owner.getWidth() -\n (owner.getX() - owner.getDrawableX()) +\n this._extraBorder,\n owner.getHeight() -\n (owner.getY() - owner.getDrawableY()) +\n this._extraBorder\n );\n if (this._searchContext.computePathTo(x, y)) {\n //Path found: memorize it\n let node = this._searchContext.getFinalNode();\n let finalPathLength = 0;\n while (node) {\n if (finalPathLength === this._path.length) {\n this._path.push([0, 0]);\n }\n this._path[finalPathLength][0] =\n node.pos[0] * this._cellWidth + this._gridOffsetX;\n this._path[finalPathLength][1] =\n node.pos[1] * this._cellHeight + this._gridOffsetY;\n node = node.parent;\n finalPathLength++;\n }\n this._path.length = finalPathLength;\n this._path.reverse();\n this._path[0][0] = owner.getX();\n this._path[0][1] = owner.getY();\n\n if (this._allowDiagonals && this._smoothingMaxCellGap > 0) {\n gdjs.pathfinding.simplifyPath(\n this._path,\n this._smoothingMaxCellGap *\n Math.min(this._cellWidth, this._cellHeight),\n gdjs.PathfindingRuntimeBehavior._smoothingResultVertices,\n gdjs.PathfindingRuntimeBehavior._smoothingWorkingVertices\n );\n let swapArray = this._path;\n this._path = gdjs.PathfindingRuntimeBehavior._smoothingResultVertices;\n gdjs.PathfindingRuntimeBehavior._smoothingResultVertices = swapArray;\n }\n\n this._enterSegment(0);\n this._pathFound = true;\n return;\n }\n\n // No path found\n this._pathFound = false;\n }\n\n _enterSegment(segmentNumber: integer) {\n if (this._path.length === 0) {\n return;\n }\n this._currentSegment = segmentNumber;\n if (this._currentSegment < this._path.length - 1) {\n const pathX =\n this._path[this._currentSegment + 1][0] -\n this._path[this._currentSegment][0];\n const pathY =\n this._path[this._currentSegment + 1][1] -\n this._path[this._currentSegment][1];\n this._totalSegmentDistance = Math.sqrt(pathX * pathX + pathY * pathY);\n this._distanceOnSegment = 0;\n this._reachedEnd = false;\n this._movementAngle =\n (gdjs.toDegrees(Math.atan2(pathY, pathX)) + 360) % 360;\n } else {\n this._reachedEnd = true;\n this._speed = 0;\n }\n }\n\n doStepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {\n if (this._path.length === 0 || this._reachedEnd) {\n return;\n }\n\n // Update the speed of the object\n const timeDelta = this.owner.getElapsedTime() / 1000;\n const previousSpeed = this._speed;\n if (this._speed !== this._maxSpeed) {\n this._speed += this._acceleration * timeDelta;\n if (this._speed > this._maxSpeed) {\n this._speed = this._maxSpeed;\n }\n }\n this._angularSpeed = this._angularMaxSpeed;\n\n // Update the time on the segment and change segment if needed\n // Use a Verlet integration to be frame rate independent.\n this._distanceOnSegment +=\n ((this._speed + previousSpeed) / 2) * timeDelta;\n const remainingDistanceOnSegment =\n this._totalSegmentDistance - this._distanceOnSegment;\n if (\n remainingDistanceOnSegment <= 0 &&\n this._currentSegment < this._path.length\n ) {\n this._enterSegment(this._currentSegment + 1);\n this._distanceOnSegment = -remainingDistanceOnSegment;\n }\n\n // Position object on the segment and update its angle\n let newPos = [0, 0];\n if (this._currentSegment < this._path.length - 1) {\n newPos[0] = gdjs.evtTools.common.lerp(\n this._path[this._currentSegment][0],\n this._path[this._currentSegment + 1][0],\n this._distanceOnSegment / this._totalSegmentDistance\n );\n newPos[1] = gdjs.evtTools.common.lerp(\n this._path[this._currentSegment][1],\n this._path[this._currentSegment + 1][1],\n this._distanceOnSegment / this._totalSegmentDistance\n );\n if (\n this._rotateObject &&\n this.owner.getAngle() !== this._movementAngle + this._angleOffset\n ) {\n this.owner.rotateTowardAngle(\n this._movementAngle + this._angleOffset,\n this._angularSpeed\n );\n }\n } else {\n newPos = this._path[this._path.length - 1];\n }\n this.owner.setX(newPos[0]);\n this.owner.setY(newPos[1]);\n }\n\n doStepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}\n\n /**\n * Compute the euclidean distance between two positions.\n * @memberof gdjs.PathfindingRuntimeBehavior\n */\n static euclideanDistance(a: FloatPoint, b: FloatPoint) {\n return Math.sqrt(\n (a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1])\n );\n }\n\n /**\n * Compute the taxi distance between two positions.\n * @memberof gdjs.PathfindingRuntimeBehavior\n */\n static manhattanDistance(a: FloatPoint, b: FloatPoint) {\n return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]);\n }\n }\n gdjs.registerBehavior(\n 'PathfindingBehavior::PathfindingBehavior',\n gdjs.PathfindingRuntimeBehavior\n );\n\n export namespace PathfindingRuntimeBehavior {\n /**\n * Internal tool class representing a node when looking for a path\n */\n export class Node {\n pos: FloatPoint;\n cost: integer = 0;\n smallestCost: integer = -1;\n estimateCost: integer = -1;\n parent: Node | null = null;\n open: boolean = true;\n\n constructor(xPos: integer, yPos: integer) {\n this.pos = [xPos, yPos];\n }\n\n reinitialize(xPos: integer, yPos: integer) {\n this.pos[0] = xPos;\n this.pos[1] = yPos;\n this.cost = 0;\n this.smallestCost = -1;\n this.estimateCost = -1;\n this.parent = null;\n this.open = true;\n }\n }\n\n /**\n * Internal tool class containing the structures used by A* and members functions related\n * to them.\n * @ignore\n */\n export class SearchContext {\n _obstacles: PathfindingObstaclesManager;\n _finalNode: Node | null = null;\n _destination: FloatPoint = [0, 0];\n _start: FloatPoint = [0, 0];\n _startX: float = 0;\n _startY: float = 0;\n _allowDiagonals: boolean = true;\n _maxComplexityFactor: integer = 50;\n _cellWidth: float = 20;\n _cellHeight: float = 20;\n _gridOffsetX: float = 0;\n _gridOffsetY: float = 0;\n\n _leftBorder: integer = 0;\n _rightBorder: integer = 0;\n _topBorder: integer = 0;\n _bottomBorder: integer = 0;\n _distanceFunction: (pt1: FloatPoint, pt2: FloatPoint) => float;\n //An array of array. Nodes are indexed by their x position, and then by their y position.\n _allNodes: Node[][] = [];\n //An array of nodes sorted by their estimate cost (First node = Lower estimate cost).\n _openNodes: Node[] = [];\n //Used by getNodes to temporarily store obstacles near a position.\n _closeObstacles: gdjs.PathfindingObstacleRuntimeBehavior[] = [];\n //Old nodes constructed in a previous search are stored here to avoid temporary objects (see _freeAllNodes method).\n _nodeCache: Node[] = [];\n\n constructor(obstacles: PathfindingObstaclesManager) {\n this._obstacles = obstacles;\n this._distanceFunction = PathfindingRuntimeBehavior.euclideanDistance;\n }\n\n setObstacles(\n obstacles: PathfindingObstaclesManager\n ): PathfindingRuntimeBehavior.SearchContext {\n this._obstacles = obstacles;\n return this;\n }\n\n getFinalNode() {\n return this._finalNode;\n }\n\n allowDiagonals(allowDiagonals: boolean) {\n this._allowDiagonals = allowDiagonals;\n this._distanceFunction = allowDiagonals\n ? PathfindingRuntimeBehavior.euclideanDistance\n : PathfindingRuntimeBehavior.manhattanDistance;\n return this;\n }\n\n setStartPosition(\n x: float,\n y: float\n ): PathfindingRuntimeBehavior.SearchContext {\n this._startX = x;\n this._startY = y;\n return this;\n }\n\n setObjectSize(\n leftBorder: integer,\n topBorder: integer,\n rightBorder: integer,\n bottomBorder: integer\n ): PathfindingRuntimeBehavior.SearchContext {\n this._leftBorder = leftBorder;\n this._rightBorder = rightBorder;\n this._topBorder = topBorder;\n this._bottomBorder = bottomBorder;\n return this;\n }\n\n setCellSize(\n cellWidth: float,\n cellHeight: float\n ): PathfindingRuntimeBehavior.SearchContext {\n this._cellWidth = cellWidth;\n this._cellHeight = cellHeight;\n return this;\n }\n\n setGridOffset(\n gridOffsetX: float,\n gridOffsetY: float\n ): PathfindingRuntimeBehavior.SearchContext {\n this._gridOffsetX = gridOffsetX;\n this._gridOffsetY = gridOffsetY;\n return this;\n }\n\n computePathTo(targetX: float, targetY: float) {\n if (this._obstacles === null) {\n logger.log(\n 'You tried to compute a path without specifying the obstacles'\n );\n return;\n }\n this._destination[0] = Math.round(\n (targetX - this._gridOffsetX) / this._cellWidth\n );\n this._destination[1] = Math.round(\n (targetY - this._gridOffsetY) / this._cellHeight\n );\n this._start[0] = Math.round(\n (this._startX - this._gridOffsetX) / this._cellWidth\n );\n this._start[1] = Math.round(\n (this._startY - this._gridOffsetY) / this._cellHeight\n );\n\n //Initialize the algorithm\n this._freeAllNodes();\n const startNode = this._getNode(this._start[0], this._start[1]);\n startNode.smallestCost = 0;\n startNode.estimateCost =\n 0 + this._distanceFunction(this._start, this._destination);\n this._openNodes.length = 0;\n this._openNodes.push(startNode);\n\n //A* algorithm main loop\n let iterationCount = 0;\n const maxIterationCount =\n startNode.estimateCost * this._maxComplexityFactor;\n while (this._openNodes.length !== 0) {\n //Make sure we do not search forever.\n if (iterationCount++ > maxIterationCount) {\n console.warn(\n `No path was found after covering ${maxIterationCount} cells.`\n );\n return false;\n }\n\n //Get the most promising node...\n const n = this._openNodes.shift()!;\n //...and flag it as explored\n n.open = false;\n\n //Check if we reached destination?\n if (\n n.pos[0] == this._destination[0] &&\n n.pos[1] == this._destination[1]\n ) {\n this._finalNode = n;\n return true;\n }\n\n //No, so add neighbors to the nodes to explore.\n this._insertNeighbors(n);\n }\n return false;\n }\n\n _freeAllNodes() {\n if (this._nodeCache.length <= 32000) {\n for (const i in this._allNodes) {\n if (this._allNodes.hasOwnProperty(i)) {\n const nodeArray = this._allNodes[i];\n for (const j in nodeArray) {\n if (nodeArray.hasOwnProperty(j)) {\n this._nodeCache.push(nodeArray[j]);\n }\n }\n }\n }\n }\n this._allNodes = [];\n }\n\n /**\n * Insert the neighbors of the current node in the open list\n * (Only if they are not closed, and if the cost is better than the already existing smallest cost).\n */\n _insertNeighbors(currentNode: Node) {\n this._addOrUpdateNode(\n currentNode.pos[0] + 1,\n currentNode.pos[1],\n currentNode,\n 1\n );\n this._addOrUpdateNode(\n currentNode.pos[0] - 1,\n currentNode.pos[1],\n currentNode,\n 1\n );\n this._addOrUpdateNode(\n currentNode.pos[0],\n currentNode.pos[1] + 1,\n currentNode,\n 1\n );\n this._addOrUpdateNode(\n currentNode.pos[0],\n currentNode.pos[1] - 1,\n currentNode,\n 1\n );\n if (this._allowDiagonals) {\n this._addOrUpdateNode(\n currentNode.pos[0] + 1,\n currentNode.pos[1] + 1,\n currentNode,\n 1.414213562\n );\n this._addOrUpdateNode(\n currentNode.pos[0] + 1,\n currentNode.pos[1] - 1,\n currentNode,\n 1.414213562\n );\n this._addOrUpdateNode(\n currentNode.pos[0] - 1,\n currentNode.pos[1] - 1,\n currentNode,\n 1.414213562\n );\n this._addOrUpdateNode(\n currentNode.pos[0] - 1,\n currentNode.pos[1] + 1,\n currentNode,\n 1.414213562\n );\n }\n }\n\n /**\n * Get (or dynamically construct) a node.\n *\n * *All* nodes should be created using this method: The cost of the node is computed thanks\n * to the objects flagged as obstacles.\n */\n _getNode(xPos: integer, yPos: integer): Node {\n //First check if their is a node a the specified position.\n if (this._allNodes.hasOwnProperty(xPos)) {\n if (this._allNodes[xPos].hasOwnProperty(yPos)) {\n return this._allNodes[xPos][yPos];\n }\n } else {\n this._allNodes[xPos] = [];\n }\n\n //No so construct a new node (or get it from the cache)...\n let newNode: Node;\n if (this._nodeCache.length !== 0) {\n newNode = this._nodeCache.shift()!;\n newNode.reinitialize(xPos, yPos);\n } else {\n newNode = new Node(xPos, yPos);\n }\n\n const nodeCenterX = xPos * this._cellWidth + this._gridOffsetX;\n const nodeCenterY = yPos * this._cellHeight + this._gridOffsetY;\n\n //...and update its cost according to obstacles\n let objectsOnCell = false;\n const radius =\n this._cellHeight > this._cellWidth\n ? this._cellHeight * 2\n : this._cellWidth * 2;\n this._obstacles.getAllObstaclesAround(\n nodeCenterX,\n nodeCenterY,\n radius,\n this._closeObstacles\n );\n for (let k = 0; k < this._closeObstacles.length; ++k) {\n const obj = this._closeObstacles[k].owner;\n const topLeftCellX = Math.floor(\n (obj.getDrawableX() - this._rightBorder - this._gridOffsetX) /\n this._cellWidth\n );\n const topLeftCellY = Math.floor(\n (obj.getDrawableY() - this._bottomBorder - this._gridOffsetY) /\n this._cellHeight\n );\n const bottomRightCellX = Math.ceil(\n (obj.getDrawableX() +\n obj.getWidth() +\n this._leftBorder -\n this._gridOffsetX) /\n this._cellWidth\n );\n const bottomRightCellY = Math.ceil(\n (obj.getDrawableY() +\n obj.getHeight() +\n this._topBorder -\n this._gridOffsetY) /\n this._cellHeight\n );\n if (\n topLeftCellX < xPos &&\n xPos < bottomRightCellX &&\n topLeftCellY < yPos &&\n yPos < bottomRightCellY\n ) {\n objectsOnCell = true;\n if (this._closeObstacles[k].isImpassable()) {\n //The cell is impassable, stop here.\n newNode.cost = -1;\n break;\n } else {\n //Superimpose obstacles\n newNode.cost += this._closeObstacles[k].getCost();\n }\n }\n }\n if (!objectsOnCell) {\n newNode.cost = 1;\n }\n\n //Default cost when no objects put on the cell.\n this._allNodes[xPos][yPos] = newNode;\n return newNode;\n }\n\n /**\n * Add a node to the openNodes (only if the cost to reach it is less than the existing cost, if any).\n */\n _addOrUpdateNode(\n newNodeX: integer,\n newNodeY: integer,\n currentNode: Node,\n factor: float\n ) {\n const neighbor = this._getNode(newNodeX, newNodeY);\n\n //cost < 0 means impassable obstacle\n if (!neighbor.open || neighbor.cost < 0) {\n return;\n }\n\n //Update the node costs and parent if the path coming from currentNode is better:\n if (\n neighbor.smallestCost === -1 ||\n neighbor.smallestCost >\n currentNode.smallestCost +\n ((currentNode.cost + neighbor.cost) / 2.0) * factor\n ) {\n if (neighbor.smallestCost != -1) {\n //The node is already in the open list..\n for (let i = 0; i < this._openNodes.length; ++i) {\n if (\n this._openNodes[i].pos[0] == neighbor.pos[0] &&\n this._openNodes[i].pos[1] == neighbor.pos[1]\n ) {\n this._openNodes.splice(\n i,\n //..so remove it as its estimate cost will be updated.\n 1\n );\n break;\n }\n }\n }\n neighbor.smallestCost =\n currentNode.smallestCost +\n ((currentNode.cost + neighbor.cost) / 2.0) * factor;\n neighbor.parent = currentNode;\n neighbor.estimateCost =\n neighbor.smallestCost +\n this._distanceFunction(neighbor.pos, this._destination);\n\n //Add the neighbor to open nodes, which are sorted by their estimate cost:\n if (\n this._openNodes.length === 0 ||\n this._openNodes[this._openNodes.length - 1].estimateCost <\n neighbor.estimateCost\n ) {\n this._openNodes.push(neighbor);\n } else {\n for (let i = 0; i < this._openNodes.length; ++i) {\n if (this._openNodes[i].estimateCost >= neighbor.estimateCost) {\n this._openNodes.splice(i, 0, neighbor);\n break;\n }\n }\n }\n }\n }\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAIA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ATA,EAAS,aACP,EAAY,aACV,GAAY,KAAO,EAAS,MAAQ,EAAO,EAC/C,EAAS,OAAS,EAClB,EAAS,aACP,EAAS,aACT,KAAK,kBAAkB,EAAS,IAAK,KAAK,cAI1C,KAAK,WAAW,SAAW,GAC3B,KAAK,WAAW,KAAK,WAAW,OAAS,GAAG,aAC1C,EAAS,aAEX,KAAK,WAAW,KAAK,OAErB,QAAS,GAAI,EAAG,EAAI,KAAK,WAAW,OAAQ,EAAE,EAC5C,GAAI,KAAK,WAAW,GAAG,cAAgB,EAAS,aAAc,CAC5D,KAAK,WAAW,OAAO,EAAG,EAAG,GAC7B,SAvXL,EAAM,iBAhCE,qEA9kBT",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(l){class S{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)}step(e){for(const i of this._registeredBehaviors)i.contactsStartedThisFrame.length=0,i.contactsEndedThisFrame.length=0;for(const i of this._registeredBehaviors)i.updateBodyFromObject();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;for(const i of this._registeredBehaviors)i.updateObjectFromBody()}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=S,l.registerRuntimeSceneUnloadedCallback(function(x){const e=x.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=S.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(Math.max(.1,this.shapeDimensionA)*this.shapeScale*this._sharedData.worldInvScale);else{const n=(Math.max(.1,this.owner.getWidth())*this._sharedData.worldInvScale+Math.max(.1,this.owner.getHeight())*this._sharedData.worldInvScale)/4;i.set_m_radius(n)}i.set_m_p(this.b2Vec2(e,t))}else if(this.shape==="Polygon")if(i=new Box2D.b2PolygonShape,!this.polygon||!B.isPolygonConvex(this.polygon)){const n=Math.max(.1,this.owner.getWidth())*this._sharedData.worldInvScale,a=Math.max(.1,this.owner.getHeight())*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?Math.max(.1,this.shapeDimensionA*this.shapeScale):Math.max(.1,this.owner.getWidth()))*this._sharedData.worldInvScale,a=Math.max(.1,this.owner.getHeight())*this._sharedData.worldInvScale,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;const n=(this.shapeDimensionA>0?Math.max(.1,this.shapeDimensionA*this.shapeScale):Math.max(.1,this.owner.getWidth()))*this._sharedData.worldInvScale,a=(this.shapeDimensionB>0?Math.max(.1,this.shapeDimensionB*this.shapeScale):Math.max(.1,this.owner.getHeight()))*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.step(e.getScene().getTimeManager().getElapsedTime()/1e3)}doStepPostEvents(e){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}updateObjectFromBody(){this._body!==null&&!this.isStatic()&&this._body.IsAwake()&&(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()}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 y=this._body,g=new Box2D.b2RevoluteJointDef;if(g.set_bodyA(y),g.set_localAnchorA(y.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 _=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2RevoluteJoint));D.setNumber(_)}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 y=i.getBehavior(this.name).getBody();if(this._body===y)return;const g=this._body,_=new Box2D.b2PrismaticJointDef;if(_.set_bodyA(g),_.set_localAnchorA(g.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),_.set_bodyB(y),_.set_localAnchorB(y.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-g.GetAngle(),_.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),_.set_referenceAngle(l.toRad(a)),_.set_enableLimit(h),c<d){const m=d;d=c,c=m}_.set_lowerTranslation(d<0?d*this._sharedData.worldInvScale:0),_.set_upperTranslation(c>0?c*this._sharedData.worldInvScale:0),_.set_enableMotor(u),_.set_motorSpeed(r*this._sharedData.worldInvScale),_.set_maxMotorForce(f),_.set_collideConnected(D);const J=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(_),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 y=i.getBehavior(this.name).getBody();if(this._body===y)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(y),g.set_localAnchorB(y.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 _=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2PulleyJoint));D.setNumber(_)}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 y=new Box2D.b2WheelJointDef;y.set_bodyA(D),y.set_localAnchorA(D.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),y.set_bodyB(b),y.set_localAnchorB(b.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-D.GetAngle(),y.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),y.set_frequencyHz(a>0?a:1),y.set_dampingRatio(h>=0?h:0),y.set_enableMotor(d),y.set_motorSpeed(l.toRad(c)),y.set_maxMotorTorque(u),y.set_collideConnected(r);const g=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(y),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={}));
|
|
1
|
+
var gdjs;(function(l){class S{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)}step(e){for(const i of this._registeredBehaviors)i.contactsStartedThisFrame.length=0,i.contactsEndedThisFrame.length=0;for(const i of this._registeredBehaviors)i.updateBodyFromObject();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;for(const i of this._registeredBehaviors)i.updateObjectFromBody()}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=S,l.registerRuntimeSceneUnloadedCallback(function(x){const e=x.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=S.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(e){const t=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(e),props:{...t,layers:this.layers,masks:this.masks}}}updateFromNetworkSyncData(e,t){super.updateFromNetworkSyncData(e,t);const i=e.props;i.layers!==void 0&&(this.layers=i.layers),i.masks!==void 0&&(this.masks=i.masks),this.updateBodyFromObject(),!!this._body&&(i.tpx!==void 0&&i.tpy!==void 0&&i.tqa!==void 0&&this._body.SetTransform(this.b2Vec2(i.tpx,i.tpy),i.tqa),i.lvx!==void 0&&i.lvy!==void 0&&this._body.SetLinearVelocity(this.b2Vec2(i.lvx,i.lvy)),i.av!==void 0&&this._body.SetAngularVelocity(i.av),i.aw!==void 0&&this._body.SetAwake(i.aw))}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(Math.max(.1,this.shapeDimensionA)*this.shapeScale*this._sharedData.worldInvScale);else{const n=(Math.max(.1,this.owner.getWidth())*this._sharedData.worldInvScale+Math.max(.1,this.owner.getHeight())*this._sharedData.worldInvScale)/4;i.set_m_radius(n)}i.set_m_p(this.b2Vec2(e,t))}else if(this.shape==="Polygon")if(i=new Box2D.b2PolygonShape,!this.polygon||!B.isPolygonConvex(this.polygon)){const n=Math.max(.1,this.owner.getWidth())*this._sharedData.worldInvScale,a=Math.max(.1,this.owner.getHeight())*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?Math.max(.1,this.shapeDimensionA*this.shapeScale):Math.max(.1,this.owner.getWidth()))*this._sharedData.worldInvScale,a=Math.max(.1,this.owner.getHeight())*this._sharedData.worldInvScale,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;const n=(this.shapeDimensionA>0?Math.max(.1,this.shapeDimensionA*this.shapeScale):Math.max(.1,this.owner.getWidth()))*this._sharedData.worldInvScale,a=(this.shapeDimensionB>0?Math.max(.1,this.shapeDimensionB*this.shapeScale):Math.max(.1,this.owner.getHeight()))*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.step(e.getScene().getTimeManager().getElapsedTime()/1e3)}doStepPostEvents(e){this._sharedData.stepped=!1}onObjectHotReloaded(){this.updateBodyFromObject()}updateObjectFromBody(){this._body!==null&&!this.isStatic()&&this._body.IsAwake()&&(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()}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 y=this._body,g=new Box2D.b2RevoluteJointDef;if(g.set_bodyA(y),g.set_localAnchorA(y.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 _=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2RevoluteJoint));D.setNumber(_)}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 y=i.getBehavior(this.name).getBody();if(this._body===y)return;const g=this._body,_=new Box2D.b2PrismaticJointDef;if(_.set_bodyA(g),_.set_localAnchorA(g.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),_.set_bodyB(y),_.set_localAnchorB(y.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-g.GetAngle(),_.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),_.set_referenceAngle(l.toRad(a)),_.set_enableLimit(h),c<d){const m=d;d=c,c=m}_.set_lowerTranslation(d<0?d*this._sharedData.worldInvScale:0),_.set_upperTranslation(c>0?c*this._sharedData.worldInvScale:0),_.set_enableMotor(u),_.set_motorSpeed(r*this._sharedData.worldInvScale),_.set_maxMotorForce(f),_.set_collideConnected(D);const J=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(_),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 y=i.getBehavior(this.name).getBody();if(this._body===y)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(y),g.set_localAnchorB(y.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 _=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(g),Box2D.b2PulleyJoint));D.setNumber(_)}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 y=new Box2D.b2WheelJointDef;y.set_bodyA(D),y.set_localAnchorA(D.GetLocalPoint(this.b2Vec2(e*this._sharedData.worldInvScale,t*this._sharedData.worldInvScale))),y.set_bodyB(b),y.set_localAnchorB(b.GetLocalPoint(this.b2Vec2(o*this._sharedData.worldInvScale,s*this._sharedData.worldInvScale))),n=l.toRad(n)-D.GetAngle(),y.set_localAxisA(this.b2Vec2(Math.cos(n),Math.sin(n))),y.set_frequencyHz(a>0?a:1),y.set_dampingRatio(h>=0?h:0),y.set_enableMotor(d),y.set_motorSpeed(l.toRad(c)),y.set_maxMotorTorque(u),y.set_collideConnected(r);const g=this._sharedData.addJoint(Box2D.castObject(this._sharedData.world.CreateJoint(y),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
|