var gdjs;(function(l){class p extends l.RuntimeBehavior{constructor(t,e,d){super(t,e,d);this._angle=0;this._xVelocity=0;this._yVelocity=0;this._angularSpeed=0;this._leftKey=!1;this._rightKey=!1;this._upKey=!1;this._downKey=!1;this._leftKeyPressedDuration=0;this._rightKeyPressedDuration=0;this._upKeyPressedDuration=0;this._downKeyPressedDuration=0;this._wasStickUsed=!1;this._stickAngle=0;this._stickForce=0;this._dontClearInputsBetweenFrames=!1;this._ignoreDefaultControlsAsSyncedByNetwork=!1;this._wasLeftKeyPressed=!1;this._wasRightKeyPressed=!1;this._wasUpKeyPressed=!1;this._wasDownKeyPressed=!1;this._temporaryPointForTransformations=[0,0];this._topDownMovementHooks=[];this._allowDiagonals=e.allowDiagonals,this._acceleration=e.acceleration,this._deceleration=e.deceleration,this._maxSpeed=e.maxSpeed,this._angularMaxSpeed=e.angularMaxSpeed,this._rotateObject=e.rotateObject,this._angleOffset=e.angleOffset,this._ignoreDefaultControls=e.ignoreDefaultControls,this.setViewpoint(e.viewpoint,e.customIsometryAngle),this._movementAngleOffset=e.movementAngleOffset||0}getNetworkSyncData(){return this._dontClearInputsBetweenFrames=!1,this._ignoreDefaultControlsAsSyncedByNetwork=!1,{...super.getNetworkSyncData(),props:{a:this._angle,xv:this._xVelocity,yv:this._yVelocity,as:this._angularSpeed,lk:this._wasLeftKeyPressed,rk:this._wasRightKeyPressed,uk:this._wasUpKeyPressed,dk:this._wasDownKeyPressed,wsu:this._wasStickUsed,sa:this._stickAngle,sf:this._stickForce}}}updateFromNetworkSyncData(t){super.updateFromNetworkSyncData(t);const e=t.props;e.a!==void 0&&(this._angle=e.a),e.xv!==void 0&&(this._xVelocity=e.xv),e.yv!==void 0&&(this._yVelocity=e.yv),e.as!==void 0&&(this._angularSpeed=e.as),e.lk!==void 0&&(this._leftKey=e.lk),e.rk!==void 0&&(this._rightKey=e.rk),e.uk!==void 0&&(this._upKey=e.uk),e.dk!==void 0&&(this._downKey=e.dk),e.wsu!==void 0&&(this._wasStickUsed=e.wsu),e.sa!==void 0&&(this._stickAngle=e.sa),e.sf!==void 0&&(this._stickForce=e.sf),this._dontClearInputsBetweenFrames=!0,this._ignoreDefaultControlsAsSyncedByNetwork=!0}updateFromBehaviorData(t,e){return t.allowDiagonals!==e.allowDiagonals&&(this._allowDiagonals=e.allowDiagonals),t.acceleration!==e.acceleration&&(this._acceleration=e.acceleration),t.deceleration!==e.deceleration&&(this._deceleration=e.deceleration),t.maxSpeed!==e.maxSpeed&&(this._maxSpeed=e.maxSpeed),t.angularMaxSpeed!==e.angularMaxSpeed&&(this._angularMaxSpeed=e.angularMaxSpeed),t.rotateObject!==e.rotateObject&&(this._rotateObject=e.rotateObject),t.angleOffset!==e.angleOffset&&(this._angleOffset=e.angleOffset),t.ignoreDefaultControls!==e.ignoreDefaultControls&&(this._ignoreDefaultControls=e.ignoreDefaultControls),(t.platformType!==e.platformType||t.customIsometryAngle!==e.customIsometryAngle)&&this.setViewpoint(e.platformType,e.customIsometryAngle),t.movementAngleOffset!==e.movementAngleOffset&&(this._movementAngleOffset=e.movementAngleOffset),!0}setViewpoint(t,e){t==="PixelIsometry"?this._basisTransformation=new l.TopDownMovementRuntimeBehavior.IsometryTransformation(Math.atan(.5)):t==="TrueIsometry"?this._basisTransformation=new l.TopDownMovementRuntimeBehavior.IsometryTransformation(Math.PI/6):t==="CustomIsometry"?this._basisTransformation=new l.TopDownMovementRuntimeBehavior.IsometryTransformation(e*Math.PI/180):this._basisTransformation=null}setAcceleration(t){this._acceleration=t}getAcceleration(){return this._acceleration}setDeceleration(t){this._deceleration=t}getDeceleration(){return this._deceleration}setMaxSpeed(t){this._maxSpeed=t}getMaxSpeed(){return this._maxSpeed}setAngularMaxSpeed(t){this._angularMaxSpeed=t}getAngularMaxSpeed(){return this._angularMaxSpeed}setAngleOffset(t){this._angleOffset=t}getAngleOffset(){return this._angleOffset}allowDiagonals(t){this._allowDiagonals=t}diagonalsAllowed(){return this._allowDiagonals}setRotateObject(t){this._rotateObject=t}isObjectRotated(){return this._rotateObject}isMoving(){return this._xVelocity!==0||this._yVelocity!==0}getSpeed(){return Math.sqrt(this._xVelocity*this._xVelocity+this._yVelocity*this._yVelocity)}getXVelocity(){return this._xVelocity}setXVelocity(t){this._xVelocity=t}getYVelocity(){return this._yVelocity}setYVelocity(t){this._yVelocity=t}getAngle(){return this._angle}isMovementAngleAround(t,e){return Math.abs(l.evtTools.common.angleDifference(this._angle,t))<=e}setMovementAngleOffset(t){this._movementAngleOffset=t}getMovementAngleOffset(){return this._movementAngleOffset}doStepPreEvents(t){const e=37,d=38,u=39,r=40;this._leftKey||(this._leftKey=!this.shouldIgnoreDefaultControls()&&t.getGame().getInputManager().isKeyPressed(e)),this._rightKey||(this._rightKey=!this.shouldIgnoreDefaultControls()&&t.getGame().getInputManager().isKeyPressed(u)),this._downKey||(this._downKey=!this.shouldIgnoreDefaultControls()&&t.getGame().getInputManager().isKeyPressed(r)),this._upKey||(this._upKey=!this.shouldIgnoreDefaultControls()&&t.getGame().getInputManager().isKeyPressed(d));const _=this.owner.getElapsedTime();this._leftKey?this._leftKeyPressedDuration+=_:this._leftKeyPressedDuration=0,this._rightKey?this._rightKeyPressedDuration+=_:this._rightKeyPressedDuration=0,this._downKey?this._downKeyPressedDuration+=_:this._downKeyPressedDuration=0,this._upKey?this._upKeyPressedDuration+=_:this._upKeyPressedDuration=0;let s=-1;this._allowDiagonals?this._upKey&&!this._downKey?this._leftKey&&!this._rightKey?s=5:!this._leftKey&&this._rightKey?s=7:s=6:!this._upKey&&this._downKey?this._leftKey&&!this._rightKey?s=3:!this._leftKey&&this._rightKey?s=1:s=2:this._leftKey&&!this._rightKey?s=4:!this._leftKey&&this._rightKey&&(s=0):(this._upKey&&!this._downKey?s=6:!this._upKey&&this._downKey&&(s=2),this._leftKey&&!this._rightKey&&(this._upKey===this._downKey||this._upKey&&this._leftKeyPressedDuration=0,M=this._yVelocity>=0;i=Math.cos(f),n=Math.sin(f),(i===-1||i===1)&&(n=0),(n===-1||n===1)&&(i=0),this._xVelocity-=this._deceleration*y*i,this._yVelocity-=this._deceleration*y*n,this._xVelocity>0!==o&&(this._xVelocity=0),this._yVelocity>0!==M&&(this._yVelocity=0)}this._xVelocity*this._xVelocity+this._yVelocity*this._yVelocity>this._maxSpeed*this._maxSpeed&&(this._xVelocity=this._maxSpeed*i,this._yVelocity=this._maxSpeed*n),this._angularSpeed=this._angularMaxSpeed;for(const o of this._topDownMovementHooks)o.beforePositionUpdate(h);const g=(w+this._xVelocity)/2*y,m=(v+this._yVelocity)/2*y;if(this._basisTransformation===null)a.setX(a.getX()+g),a.setY(a.getY()+m);else{const o=this._temporaryPointForTransformations;o[0]=g,o[1]=m,this._basisTransformation.toScreen(o,o),a.setX(a.getX()+o[0]),a.setY(a.getY()+o[1])}(this._xVelocity!==0||this._yVelocity!==0)&&(this._angle=c,this._rotateObject&&a.rotateTowardAngle(c+this._angleOffset,this._angularSpeed)),this._wasLeftKeyPressed=this._leftKey,this._wasRightKeyPressed=this._rightKey,this._wasUpKeyPressed=this._upKey,this._wasDownKeyPressed=this._downKey,this._dontClearInputsBetweenFrames||(this._leftKey=!1,this._rightKey=!1,this._upKey=!1,this._downKey=!1)}simulateControl(t){t==="Left"?this._leftKey=!0:t==="Right"?this._rightKey=!0:t==="Up"?this._upKey=!0:t==="Down"&&(this._downKey=!0)}ignoreDefaultControls(t){this._ignoreDefaultControls=t}shouldIgnoreDefaultControls(){return this._ignoreDefaultControls||this._ignoreDefaultControlsAsSyncedByNetwork}simulateLeftKey(){this._leftKey=!0}simulateRightKey(){this._rightKey=!0}simulateUpKey(){this._upKey=!0}simulateDownKey(){this._downKey=!0}simulateStick(t,e){this._stickAngle=t%360,this._stickForce=Math.max(0,Math.min(1,e))}isUsingControl(t){return t==="Left"?this._leftKeyPressedDuration>0:t==="Right"?this._rightKeyPressedDuration>0:t==="Up"?this._upKeyPressedDuration>0:t==="Down"?this._downKeyPressedDuration>0:t==="Stick"?this._wasStickUsed:!1}getLastStickInputAngle(){return this._stickAngle}registerHook(t){this._topDownMovementHooks.push(t)}}l.TopDownMovementRuntimeBehavior=p,function(d){class K{constructor(){this.direction=-1}getDirection(){return this.direction}_setDirection(r){this.direction=r}}d.TopDownMovementHookContext=K,d._topDownMovementHookContext=new l.TopDownMovementRuntimeBehavior.TopDownMovementHookContext;class e{constructor(r){if(r<=0||r>=Math.PI/4)throw new RangeError("An isometry angle must be in ]0; pi/4] but was: "+r);const _=Math.asin(Math.tan(r)),s=Math.sin(_),h=Math.cos(Math.PI/4),a=h;this._screen=[[h,-a],[s*a,s*h]]}toScreen(r,_){const s=this._screen[0][0]*r[0]+this._screen[0][1]*r[1],h=this._screen[1][0]*r[0]+this._screen[1][1]*r[1];_[0]=s,_[1]=h}}d.IsometryTransformation=e}(p=l.TopDownMovementRuntimeBehavior||(l.TopDownMovementRuntimeBehavior={})),l.registerBehavior("TopDownMovementBehavior::TopDownMovementBehavior",l.TopDownMovementRuntimeBehavior)})(gdjs||(gdjs={})); //# sourceMappingURL=topdownmovementruntimebehavior.js.map