let BaseNode=require("../Utils/BaseNode").BaseNode,APJS=require("../../../amazingpro"),PointerState={UNINIT:"UNINIT",RIGHT:"RIGHT",FINISH:"FINISH"};class Pointer{constructor(){this.Idle=!0,this.OnStart=!1,this.Stay=!1,this.OnStop=!1,this.id=void 0,this.currentPos=new APJS.Vector2f(-1,-1),this.lastPos=new APJS.Vector2f(-1,-1),this.state=PointerState.UNINIT}}class FingerTouch extends BaseNode{constructor(){super(),this.Pointer0=new Pointer,this.Pointer1=new Pointer,this.touchIdxMap={"Touch 0":0,"Touch 1":1},this.pointers=[this.Pointer0,this.Pointer1]}onEvent(t,e){e.type===APJS.EventType.Touch&&this._handleTouchEvent(e)}onLateUpdate(t,e){this.selectedIndex=this.touchIdxMap[this.inputs[0]()],this.selectedPointer=this.pointers[this.selectedIndex],this.outputs[4]=this.selectedPointer.currentPos,this.outputs[5]=this.selectedPointer.lastPos,this._excuteTouchPoint(this.selectedIndex)}_handleTouchEvent(t){var e,t=t.args[0];void 0!==t&&((e=t.phase)===APJS.TouchPhase.Began?(this.Pointer0.state===PointerState.UNINIT||this.Pointer0.state===PointerState.FINISH?this._setPointer(this.Pointer0,t.touchId,PointerState.RIGHT,!1,!0,!1,!1,new APJS.Vector2f(t.position.x,1-t.position.y),this.Pointer0.lastPos):this.Pointer1.state!==PointerState.UNINIT&&this.Pointer1.state!==PointerState.UNINIT||t.touchId!==this.Pointer0.id&&this._setPointer(this.Pointer1,t.touchId,PointerState.RIGHT,!1,!0,!1,!1,new APJS.Vector2f(t.position.x,1-t.position.y),this.Pointer1.lastPos),this._excuteTouchPoint(this.selectedIndex)):e===APJS.TouchPhase.Moved?this.Pointer0.state===PointerState.RIGHT&&t.touchId===this.Pointer0.id?this._setPointer(this.Pointer0,t.touchId,PointerState.RIGHT,!1,!1,!0,!1,new APJS.Vector2f(t.position.x,1-t.position.y),this.Pointer0.currentPos):this.Pointer1.state===PointerState.RIGHT&&t.touchId===this.Pointer1.id&&this._setPointer(this.Pointer1,t.touchId,PointerState.RIGHT,!1,!1,!0,!1,new APJS.Vector2f(t.position.x,1-t.position.y),this.Pointer1.currentPos):e!==APJS.TouchPhase.Ended&&e!==APJS.TouchPhase.Canceled||(this.Pointer0.state===PointerState.RIGHT&&t.touchId===this.Pointer0.id?this._setPointer(this.Pointer0,t.touchId,PointerState.FINISH,!1,!1,!1,!0,new APJS.Vector2f(t.position.x,1-t.position.y),this.Pointer0.currentPos):this.Pointer1.state===PointerState.RIGHT&&t.touchId===this.Pointer1.id&&this._setPointer(this.Pointer1,t.touchId,PointerState.FINISH,!1,!1,!1,!0,new APJS.Vector2f(t.position.x,1-t.position.y),this.Pointer1.currentPos)))}_setPointer(t,e,i,s,o,n,r,h,P){t.Idle=s,t.OnStart=o,t.Stay=n,t.OnStop=r,t.lastPos=P,t.currentPos=h,t.id=e,t.state=i}_excuteTouchPoint(t){t=this.pointers[t];this.outputs[4]=t.currentPos,this.outputs[5]=t.lastPos,this.selectedPointer.Idle&&this.nexts[0]?this.nexts[0]():t.OnStart?(this._setPointer(t,t.id,PointerState.RIGHT,!1,!1,!0,!1,t.currentPos,t.lastPos),this.nexts[1]&&this.nexts[1](),this.nexts[2]&&this.nexts[2]()):t.Stay&&this.nexts[2]?this.nexts[2]():t.OnStop&&(this._setPointer(this.selectedPointer,void 0,PointerState.UNINIT,!0,!1,!1,!1,new APJS.Vector2f(-1,-1),this.selectedPointer.currentPos),this.nexts[3])&&this.nexts[3]()}_reset(){for(var t of this.pointers)this._setPointer(t,void 0,PointerState.UNINIT,!0,!1,!1,!1,new APJS.Vector2f(-1,-1),new APJS.Vector2f(-1,-1));this.outputs[4]=new APJS.Vector2f(-1,-1),this.outputs[5]=new APJS.Vector2f(-1,-1)}beforeStart(t){this._reset()}resetOnRecord(t){this._reset()}}exports.FingerTouch=FingerTouch;