phaser4-rex-plugins
Version:
2 lines (1 loc) • 27.8 kB
JavaScript
var t,e;t=void 0,e=function(){var t={setEventEmitter(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){return this._eventEmitter},on(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}};const e=Phaser.Scene;var i=function(t){return t instanceof e},s=function(t){return null==t||"object"!=typeof t?null:i(t)?t:t.scene&&i(t.scene)?t.scene:t.parent&&t.parent.scene&&i(t.parent.scene)?t.parent.scene:null};const n=Phaser.Game;var r=function(t){return t instanceof n},o=function(t){return null==t||"object"!=typeof t?null:r(t)?t:r(t.game)?t.game:i(t)?t.sys.game:i(t.scene)?t.scene.sys.game:void 0};const h=Phaser.Utils.Objects.GetValue;class a{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(h(e,"eventEmitter",!0)),this.parent&&(this.parent===this.scene?this.scene.sys.events.once("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.once("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.once("destroy",this.onParentDestroy,this))}shutdown(t){this.isShutdown||(this.parent&&(this.parent===this.scene?this.scene.sys.events.off("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.off("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.off("destroy",this.onParentDestroy,this)),this.destroyEventEmitter(),this.parent=void 0,this.scene=void 0,this.game=void 0,this.isShutdown=!0)}destroy(t){this.shutdown(t)}onEnvDestroy(){this.destroy(!0)}onParentDestroy(t,e){this.destroy(e)}setParent(t){return this.parent=t,this.scene=s(t),this.game=o(t),this}}Object.assign(a.prototype,t);const c=Phaser.Utils.Objects.GetValue;class u extends a{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(c(e,"tickingMode",1))}boot(){2!==this.tickingMode||this.tickingState||this.startTicking()}shutdown(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),super.shutdown(t))}setTickingMode(t){"string"==typeof t&&(t=p[t]),this.tickingMode=t}startTicking(){this.tickingState=!0}stopTicking(){this.tickingState=!1}get isRunning(){return this._isRunning}set isRunning(t){this._isRunning!==t&&(this._isRunning=t,1===this.tickingMode&&t!=this.tickingState&&(t?this.startTicking():this.stopTicking()))}start(){return this.isPaused=!1,this.isRunning=!0,this}pause(){return this.isRunning&&(this.isPaused=!0,this.isRunning=!1),this}resume(){return this.isPaused&&(this.isPaused=!1,this.isRunning=!0),this}stop(){return this.isPaused=!1,this.isRunning=!1,this}complete(){this.isPaused=!1,this.isRunning=!1,this.emit("complete",this.parent,this)}}const p={no:0,lazy:1,always:2};var d=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},v=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height};const l=Phaser.Geom.Rectangle,g=Phaser.Math.Vector2,f=Phaser.Math.RotateAround,m=Phaser.GameObjects.Container;var y=void 0,E=function(t,e,i){return void 0===e?e=new g:!0===e&&(void 0===S&&(S=new g),e=S),t.getTopLeft?t.getTopLeft(e,i):(e.x=t.x-d(t)*t.originX,e.y=t.y-v(t)*t.originY,x(t,e,i))},_=function(t,e,i){return void 0===e?e=new g:!0===e&&(void 0===S&&(S=new g),e=S),t.getTopRight?t.getTopRight(e,i):(e.x=t.x-d(t)*t.originX+d(t),e.y=t.y-v(t)*t.originY,x(t,e,i))},b=function(t,e,i){return void 0===e?e=new g:!0===e&&(void 0===S&&(S=new g),e=S),t.getBottomLeft?t.getBottomLeft(e,i):(e.x=t.x-d(t)*t.originX,e.y=t.y-v(t)*t.originY+v(t),x(t,e,i))},w=function(t,e,i){return void 0===e?e=new g:!0===e&&(void 0===S&&(S=new g),e=S),t.getBottomRight?t.getBottomRight(e,i):(e.x=t.x-d(t)*t.originX+d(t),e.y=t.y-v(t)*t.originY+v(t),x(t,e,i))},S=void 0,x=function(t,e,i){return void 0===i&&(i=!1),0!==t.rotation&&f(e,t.x,t.y,t.rotation),i&&t.parentContainer&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e),e},P=function(t,e,i,s,n){if(!t)return!1;if(s&&!s(t,e,i))return!1;var r=function(t,e){if(void 0===e?e=new l:!0===e&&(void 0===y&&(y=new l),e=y),t.getBounds&&!(t instanceof m))return t.getBounds(e);var i,s,n,r,o,h,a,c;if(t.parentContainer){var u=t.parentContainer.getBoundsTransformMatrix();E(t,e),u.transformPoint(e.x,e.y,e),i=e.x,s=e.y,_(t,e),u.transformPoint(e.x,e.y,e),n=e.x,r=e.y,b(t,e),u.transformPoint(e.x,e.y,e),o=e.x,h=e.y,w(t,e),u.transformPoint(e.x,e.y,e),a=e.x,c=e.y}else E(t,e),i=e.x,s=e.y,_(t,e),n=e.x,r=e.y,b(t,e),o=e.x,h=e.y,w(t,e),a=e.x,c=e.y;return e.x=Math.min(i,n,o,a),e.y=Math.min(s,r,h,c),e.width=Math.max(i,n,o,a)-e.x,e.height=Math.max(s,r,h,c)-e.y,e}(t,!0);return!(!r.contains(e,i)||n&&!n(t,e,i))},D=function(t,e,i){var s=t.camera;return s?(void 0===i?i={}:!0===i&&(i=O),s===e?(i.x=t.worldX,i.y=t.worldY):s.getWorldPoint(t.x,t.y,i),i):null},O={},j=function(t,e,i,s){return function(t,e,i,s,n){var r,o=t.scene.sys.cameras.main,h=0===t.scrollFactorX&&0===t.scrollFactorY;if(e)return h?i(t,e.x,e.y,s,n):!!(r=D(e,o,!0))&&i(t,r.x,r.y,s,n);for(var a=t.scene.input.manager,c=a.pointersTotal,u=a.pointers,p=0;p<c;p++)if(e=u[p],h){if(i(t,e.x,e.y,s,n))return!0}else{if(!(r=D(e,o,!0)))continue;if(i(t,r.x,r.y,s,n))return!0}return!1}(t,e,P,i,s)};const T=Phaser.Utils.Objects.GetValue;class M extends u{constructor(t,e){var i=s(t);i===t&&(t=void 0),super(i,e),this.gameObject=t,t&&t.setInteractive(T(e,"inputConfig",void 0)),this._enable=void 0,this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.setEnable(T(t,"enable",!0)),this.setDetectBounds(),void 0===this.gameObject?this.setDetectBounds(T(t,"bounds",void 0)):this.setDetectBounds(),this.tracerState=C,this.pointer=void 0,this.lastPointer=void 0,this.movedState=!1,this.isTouchingAnyObject=!1,this}boot(){super.boot(),this.gameObject?this.gameObject.on("pointerdown",this.onPointerDown,this):this.scene.input.on("pointerdown",this.onPointerDown,this),this.scene.input.on("pointerup",this.onPointerUp,this),this.scene.input.on("gameout",this.dragCancel,this),this.scene.input.on("pointermove",this.onPointerMove,this),this.scene.sys.events.once("shutdown",this.destroy,this)}shutdown(t){this.scene&&(this.gameObject||this.scene.input.off("pointerdown",this.onPointerDown,this),this.scene.input.off("pointerup",this.onPointerUp,this),this.scene.input.off("gameout",this.dragCancel,this),this.scene.input.off("pointermove",this.onPointerMove,this),this.scene.sys.events.off("shutdown",this.destroy,this),this.gameObject=void 0,this.bounds=void 0,this.pointer=void 0,this.lastPointer=void 0,this.movedState=!1,super.shutdown(t))}get enable(){return this._enable}set enable(t){if(this._enable!==t)return t||this.dragCancel(),this._enable=t,this}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}setDetectBounds(t){return this.bounds=t,this}toggleEnable(){return this.setEnable(!this.enable),this}onPointerDown(t,e){this.enable&&void 0===this.pointer&&(!this.bounds||this.bounds.contains(t.x,t.y))&&this.pointer!==t&&(this.pointer=t,this.pointerCamera=t.camera,this.lastPointer=t,this.movedState=!1,this.tracerState=k,void 0===this.gameObject&&(this.isTouchingAnyObject=e.length>0),this.onDragStart())}onPointerUp(t){this.enable&&(!this.bounds||this.bounds.contains(t.x,t.y))&&this.pointer===t&&(this.pointer=void 0,this.pointerCamera=void 0,this.movedState=!1,this.tracerState=C,this.onDragEnd())}onPointerMove(t){if(this.enable&&t.isDown){var e=!this.bounds||this.bounds.contains(t.x,t.y),i=this.pointer===t;!i&&e||(i&&!e?this.onPointerUp(t):(this.movedState||(this.movedState=t.x!==t.downX||t.y!==t.downY),this.movedState&&this.onDrag()))}}dragCancel(){return this.tracerState===k&&this.onDragEnd(),this.pointer=void 0,this.tracerState=C,this}onDragStart(){this.emit("dragstart",this)}onDragEnd(){this.emit("dragend",this)}onDrag(){this.emit("drag",this)}preUpdate(t,e){}postUpdate(t,e){}startTicking(){super.startTicking(),this.scene.sys.events.on("preupdate",this.preUpdate,this),this.scene.sys.events.on("postupdate",this.postUpdate,this)}stopTicking(){super.stopTicking(),this.scene&&(this.scene.sys.events.off("preupdate",this.preUpdate,this),this.scene.sys.events.off("postupdate",this.postUpdate,this))}setRecongizedStateObject(t){return this.recongizedState=t,this}get state(){return this.recongizedState.state}set state(t){this.recongizedState.state=t}cancel(){return this.state=R,this}isPointerInGameObject(t,e,i){var s=this.lastPointer;return!!s&&j(t,s,e,i)}}const C=0,k=1,R="IDLE";function U(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var A={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function s(){}function n(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function r(t,e,s,r,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var h=new n(s,r||t,o),a=i?i+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],h]:t._events[a].push(h):(t._events[a]=h,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function h(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),h.prototype.eventNames=function(){var t,s,n=[];if(0===this._eventsCount)return n;for(s in t=this._events)e.call(t,s)&&n.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},h.prototype.listeners=function(t){var e=i?i+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var n=0,r=s.length,o=new Array(r);n<r;n++)o[n]=s[n].fn;return o},h.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},h.prototype.emit=function(t,e,s,n,r,o){var h=i?i+t:t;if(!this._events[h])return!1;var a,c,u=this._events[h],p=arguments.length;if(u.fn){switch(u.once&&this.removeListener(t,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,e),!0;case 3:return u.fn.call(u.context,e,s),!0;case 4:return u.fn.call(u.context,e,s,n),!0;case 5:return u.fn.call(u.context,e,s,n,r),!0;case 6:return u.fn.call(u.context,e,s,n,r,o),!0}for(c=1,a=new Array(p-1);c<p;c++)a[c-1]=arguments[c];u.fn.apply(u.context,a)}else{var d,v=u.length;for(c=0;c<v;c++)switch(u[c].once&&this.removeListener(t,u[c].fn,void 0,!0),p){case 1:u[c].fn.call(u[c].context);break;case 2:u[c].fn.call(u[c].context,e);break;case 3:u[c].fn.call(u[c].context,e,s);break;case 4:u[c].fn.call(u[c].context,e,s,n);break;default:if(!a)for(d=1,a=new Array(p-1);d<p;d++)a[d-1]=arguments[d];u[c].fn.apply(u[c].context,a)}}return!0},h.prototype.on=function(t,e,i){return r(this,t,e,i,!1)},h.prototype.once=function(t,e,i){return r(this,t,e,i,!0)},h.prototype.removeListener=function(t,e,s,n){var r=i?i+t:t;if(!this._events[r])return this;if(!e)return o(this,r),this;var h=this._events[r];if(h.fn)h.fn!==e||n&&!h.once||s&&h.context!==s||o(this,r);else{for(var a=0,c=[],u=h.length;a<u;a++)(h[a].fn!==e||n&&!h[a].once||s&&h[a].context!==s)&&c.push(h[a]);c.length?this._events[r]=1===c.length?c[0]:c:o(this,r)}return this},h.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&o(this,e)):(this._events=new s,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=i,h.EventEmitter=h,t.exports=h}(A);var L=U(A.exports);class B extends L{shutdown(){this.removeAllListeners()}destroy(){this.removeAllListeners()}}var N={setEventEmitter(t,e){return void 0===e&&(e=B),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},G=function(t,e,i){if(!t||"number"==typeof t)return i;if("string"==typeof e){if(t.hasOwnProperty(e))return t[e];if(-1===e.indexOf("."))return i;e=e.split(".")}for(var s=e,n=t,r=i,o=0;o<s.length;o++){if(e=s[o],!n.hasOwnProperty(e)){r=i;break}n=r=n[e]}return r};const V=["next","exit","enter"];let X=class{constructor(t){var e=G(t,"states",void 0);e&&this.addStates(e);var i=G(t,"extend",void 0);if(i)for(var s in i)this.hasOwnProperty(s)&&void 0!==this[s]||(this[s]=i[s]);var n=G(t,"eventEmitter",void 0),r=G(t,"EventEmitterClass",void 0);this.setEventEmitter(n,r),this._stateLock=!1,this.resetFromJSON(t)}shutdown(){this.destroyEventEmitter()}destroy(){this.shutdown()}resetFromJSON(t){this.setEnable(G(t,"enable",!0)),this.start(G(t,"start",void 0));var e=G(t,"init",void 0);return e&&e.call(this),this}toJSON(){return{curState:this.state,prevState:this.prevState,enable:this.enable,start:this._start}}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}toggleEnable(){return this.setEnable(!this.enable),this}set state(t){if(this.enable&&!this._stateLock&&this._state!==t){if(this._prevState=this._state,this._state=t,this._stateLock=!0,this.emit("statechange",this),null!=this._prevState){var e="exit_"+this._prevState,i=this[e];i&&i.call(this),this.emit(e,this)}if(this._stateLock=!1,null!=this._state){var s="enter_"+this._state,n=this[s];n&&n.call(this),this.emit(s,this)}}}get state(){return this._state}get prevState(){return this._prevState}start(t){return this._start=t,this._prevState=void 0,this._state=t,this}goto(t){return null!=t&&(this.state=t),this}next(){var t,e=this["next_"+this.state];return e&&(t="string"==typeof e?e:e.call(this)),this.goto(t),this}get stateProperties(){return V}addState(t,e){"string"!=typeof t&&(t=(e=t).name);for(var i=this.stateProperties,s=0,n=i.length;s<n;s++){var r=i[s],o=e[r];o&&(this[`${r}_${t}`]=o)}return this}addStates(t){if(Array.isArray(t))for(var e=0,i=t.length;e<i;e++)this.addState(t[e]);else for(var s in t)this.addState(s,t[s]);return this}runMethod(t,e,i,s,n,r){var o=this[t+"_"+this.state];if(o){var h=arguments.length;switch(h){case 1:return o.call(this);case 2:return o.call(this,e);case 3:return o.call(this,e,i);case 4:return o.call(this,e,i,s);case 5:return o.call(this,e,i,s,n);case 6:return o.call(this,e,i,s,n,r)}for(var a=new Array(h-1),c=1;c<h;c++)a[c-1]=arguments[c];return o.apply(this,a)}}};Object.assign(X.prototype,N);var Y=function(t,e,i,s,n){void 0===n&&(n=!1);var r=t._events[e];if(!r)return!1;for(var o=0,h=r.length;o<h;o++){var a=r[o];if(a.fn===i&&a.context===s&&a.once===n)return!0}return!1};const I=["next","exit","enter","update","preupdate","postupdate"];class F extends X{shutdown(){this.stopUpdate(),this.stopPreUpdate(),this.stopPostUpdate(),this._scene=void 0,super.shutdown()}resetFromJSON(t){return super.resetFromJSON(t),this._scene=G(t,"scene",void 0),this}get stateProperties(){return I}update(t,e){this.runMethod("update",t,e)}preupdate(t,e){this.runMethod("preupdate",t,e)}postupdate(t,e){this.runMethod("postupdate",t,e)}startUpdate(t){t||(t=this._scene);var e=t.sys.events;return Y(e,"update",this.update,this)||(this._scene=t,e.on("update",this.update,this)),this}stopUpdate(){return this._scene?(this._scene.sys.events.off("update",this.update,this),this):this}startPreUpdate(t){t||(t=this._scene);var e=t.sys.events;return Y(e,"preupdate",this.preupdate,this)||(this._scene=t,e.on("preupdate",this.preupdate,this)),this}stopPreUpdate(){return this._scene?(this._scene.sys.events.off("preupdate",this.preupdate,this),this):this}startPostUpdate(t){t||(t=this._scene);var e=t.sys.events;return Y(e,"postupdate",this.postupdate,this)||(this._scene=t,e.on("postupdate",this.postupdate,this)),this}stopPostUpdate(){return this._scene?(this._scene.sys.events.off("postupdate",this.postupdate,this),this):this}}Phaser.Utils.Objects.GetValue,Phaser.Math.Distance.Between,Phaser.Utils.Objects.GetValue,Phaser.Utils.Objects.GetValue;const J=Phaser.Math.Distance.Between,z=Phaser.Math.Angle.Between;var W={getDt:function(){var t;return t=this.scene,o(t).loop.delta},getVelocity:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return J(e.x,e.y,t.x,t.y)/(.001*this.getDt())},getVelocityX:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return Math.abs(t.x-e.x)/(.001*this.getDt())},getVelocityY:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return Math.abs(t.y-e.y)/(.001*this.getDt())},getVelocityAngle:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return z(e.x,e.y,t.x,t.y)}},Z={"up&down":0,"left&right":1,"4dir":2,"8dir":3},H={};const $=Phaser.Utils.Objects.GetValue,q=Phaser.Math.RadToDeg;class K extends M{constructor(t,e){super(t,e);var i=this,s={states:{IDLE:{enter:function(){i.x=0,i.y=0,i.worldX=0,i.worldY=0},exit:function(){var t=i.lastPointer;i.x=t.x,i.y=t.y,i.worldX=t.worldX,i.worldY=t.worldY}},BEGIN:{enter:function(){i.validDrag=!1}},RECOGNIZED:{enter:function(){i.start(),i.updateDirectionStates(),i.emit("swipe",i,i.gameObject,i.lastPointer)},exit:function(){i.stop(),i.clearDirectionStates()}}},init:function(){this.state=Q},eventEmitter:!1};this.setRecongizedStateObject(new F(s)),this.clearDirectionStates()}resetFromJSON(t){return super.resetFromJSON(t),this.setDragThreshold($(t,"threshold",10)),this.setVelocityThreshold($(t,"velocityThreshold",1e3)),this.setDirectionMode($(t,"dir","8dir")),this}onDragStart(){this.state=tt}onDragEnd(){this.state=Q}onDrag(){this.state===tt&&(this.validDrag||(this.validDrag=0===this.dragThreshold||this.pointer.getDistance()>=this.dragThreshold),this.validDrag&&this.dragVelocity>this.velocityThreshold&&(this.state=et))}postUpdate(t,e){this.isRunning&&this.enable&&this.state===et&&(this.state=Q)}get isSwiping(){return this.state===et}get isSwiped(){return this.isSwiping}get dragVelocity(){var t;switch(this.dirMode){case 0:t=this.getVelocityY();break;case 1:t=this.getVelocityX();break;default:t=this.getVelocity()}return t}setDragThreshold(t){return this.dragThreshold=t,this}setVelocityThreshold(t){return this.velocityThreshold=t,this}setDirectionMode(t){return"string"==typeof t&&(t=Z[t]),this.dirMode=t,this}updateDirectionStates(){return function(t,e,i){switch(void 0===i?i={}:!0===i&&(i=H),i.left=!1,i.right=!1,i.up=!1,i.down=!1,t=(t+360)%360,e){case 0:t<180?i.down=!0:i.up=!0;break;case 1:t>90&&t<=270?i.left=!0:i.right=!0;break;case 2:t>45&&t<=135?i.down=!0:t>135&&t<=225?i.left=!0:t>225&&t<=315?i.up=!0:i.right=!0;break;case 3:t>22.5&&t<=67.5?(i.down=!0,i.right=!0):t>67.5&&t<=112.5?i.down=!0:t>112.5&&t<=157.5?(i.down=!0,i.left=!0):t>157.5&&t<=202.5?i.left=!0:t>202.5&&t<=247.5?(i.left=!0,i.up=!0):t>247.5&&t<=292.5?i.up=!0:t>292.5&&t<=337.5?(i.up=!0,i.right=!0):i.right=!0}}(q(this.getVelocityAngle()),this.dirMode,this),this}clearDirectionStates(){return this.left=!1,this.right=!1,this.up=!1,this.down=!1,this}}Object.assign(K.prototype,W);const Q="IDLE",tt="BEGIN",et="RECOGNIZED";var it=function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e];return t};const st=Phaser.Utils.Objects.GetValue,nt=Phaser.Utils.Array.SpliceOne,rt=Phaser.Math.Distance.Between,ot=Phaser.Math.Angle.Between;class ht{constructor(t,e){var i=s(t);i===t&&(t=void 0);var n=i.input.manager.pointersTotal-1;n<2&&i.input.addPointer(2-n),this.scene=i,this.gameObject=t,t&&t.setInteractive(st(e,"inputConfig",void 0)),this.setEventEmitter(st(e,"eventEmitter",void 0)),this._enable=void 0,this.pointers=[],this.movedState={},this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.setEnable(st(t,"enable",!0)),this.bounds=st(t,"bounds",void 0),this.tracerState=ct,this.pointers.length=0,it(this.movedState),this}boot(){this.gameObject?this.gameObject.on("pointerdown",this.onPointerDown,this):this.scene.input.on("pointerdown",this.onPointerDown,this),this.scene.input.on("pointerup",this.onPointerUp,this),this.scene.input.on("gameout",this.dragCancel,this),this.scene.input.on("pointermove",this.onPointerMove,this),this.scene.sys.events.once("shutdown",this.destroy,this)}shutdown(){this.scene&&(this.destroyEventEmitter(),this.pointers.length=0,it(this.movedState),this.gameObject||this.scene.input.off("pointerdown",this.onPointerDown,this),this.scene.input.off("pointerup",this.onPointerUp,this),this.scene.input.off("gameout",this.dragCancel,this),this.scene.input.off("pointermove",this.onPointerMove,this),this.scene.sys.events.off("shutdown",this.destroy,this),this.scene=void 0,this.gameObject=void 0)}destroy(){this.shutdown()}get enable(){return this._enable}set enable(t){if(this._enable!==t)return t||this.dragCancel(),this._enable=t,this}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}toggleEnable(){return this.setEnable(!this.enable),this}onPointerDown(t){if(this.enable&&2!==this.pointers.length&&(!this.bounds||this.bounds.contains(t.x,t.y))&&-1===this.pointers.indexOf(t))switch(this.movedState[t.id]=!1,this.pointers.push(t),this.pointerCamera=t.camera,this.tracerState){case ct:this.tracerState=ut,this.onDrag1Start();break;case ut:this.tracerState=pt,this.onDrag2Start()}}onPointerUp(t){if(this.enable&&(!this.bounds||this.bounds.contains(t.x,t.y))){var e=this.pointers.indexOf(t);if(-1!==e)switch(delete this.movedState[t.id],nt(this.pointers,e),this.tracerState){case ut:this.tracerState=ct,this.onDrag1End();break;case pt:this.tracerState=ut,this.onDrag2End(),this.onDrag1Start()}}}onPointerMove(t){if(this.enable&&t.isDown){var e=!this.bounds||this.bounds.contains(t.x,t.y),i=-1!==this.pointers.indexOf(t);if(!i&&e);else if(i&&!e)this.onPointerUp(t);else if(this.movedState[t.id]||(this.movedState[t.id]=t.x!==t.downX||t.y!==t.downY),this.movedState[t.id])switch(this.tracerState){case ut:this.onDrag1();break;case pt:this.onDrag2()}}}dragCancel(){return this.tracerState===pt&&this.onDrag2End(),this.pointers.length=0,it(this.movedState),this.tracerState=ct,this}onDrag1Start(){this.emit("drag1start",this)}onDrag1End(){this.emit("drag1end",this)}onDrag1(){this.emit("drag1",this)}onDrag2Start(){this.emit("drag2start",this)}onDrag2End(){this.emit("drag2end",this)}onDrag2(){this.emit("drag2",this)}get distanceBetween(){if(this.tracerState!==pt)return 0;var t=this.pointers[0],e=this.pointers[1];return rt(t.x,t.y,e.x,e.y)}get angleBetween(){if(this.tracerState!==pt)return 0;var t=this.pointers[0],e=this.pointers[1];return ot(t.x,t.y,e.x,e.y)}get drag1Vector(){var t=this.pointers[0];if(t&&this.movedState[t.id]){var e=t.position,i=t.prevPosition;at.x=e.x-i.x,at.y=e.y-i.y}else at.x=0,at.y=0;return at}get centerX(){if(this.tracerState!==pt)return 0;var t=this.pointers[0].position,e=this.pointers[1].position;return(t.x+e.x)/2}get centerY(){if(this.tracerState!==pt)return 0;var t=this.pointers[0].position,e=this.pointers[1].position;return(t.y+e.y)/2}get prevCenterX(){if(this.tracerState!==pt)return 0;var t=this.movedState[this.pointers[0].id]?this.pointers[0].prevPosition:this.pointers[0].position,e=this.movedState[this.pointers[1].id]?this.pointers[1].prevPosition:this.pointers[1].position;return(t.x+e.x)/2}get prevCenterY(){if(this.tracerState!==pt)return 0;var t=this.movedState[this.pointers[0].id]?this.pointers[0].prevPosition:this.pointers[0].position,e=this.movedState[this.pointers[1].id]?this.pointers[1].prevPosition:this.pointers[1].position;return(t.y+e.y)/2}get movementCenterX(){return this.centerX-this.prevCenterX}get movementCenterY(){return this.centerY-this.prevCenterY}setRecongizedStateObject(t){return this.recongizedState=t,this}get state(){return this.recongizedState.state}set state(t){this.recongizedState.state=t}cancel(){return this.state=dt,this}isPointer0InGameObject(t,e,i){var s=this.pointers[0];return!!s&&j(t,s,e,i)}isPointer1InGameObject(t,e,i){var s=this.pointers[1];return!!s&&j(t,s,e,i)}}Object.assign(ht.prototype,t);var at={};const ct=0,ut=1,pt=2,dt="IDLE";Phaser.Utils.Objects.GetValue;const vt=Phaser.Math.RotateAround;var lt=function(t,e,i,s){return vt(t,e,i,s),t.rotation+=s,t},gt={};const ft=Phaser.Utils.Objects.GetValue,mt=Phaser.Math.Angle.WrapDegrees,yt=Phaser.Math.Angle.ShortestBetween,Et=Phaser.Math.RadToDeg,_t=Phaser.Math.DegToRad;var bt={spinObject:function(t,e){if(!this.isRotation)return this;void 0===e&&(e=this.pointers[0].camera);var i=this.movementCenterX,s=this.movementCenterY,n=function(t,e,i,s){return void 0===s?s={}:!0===s&&(s=gt),i.getWorldPoint(t,e,s),s}(this.centerX,this.centerY,e,!0),r=n.x,o=n.y,h=this.rotation;if(Array.isArray(t))for(var a=t,c=0,u=a.length;c<u;c++)(t=a[c]).x+=i,t.y+=s,lt(t,r,o,h);else t.x+=i,t.y+=s,lt(t,r,o,h);return this}};Object.assign(class extends ht{constructor(t,e){super(t,e);var i=this,s={states:{IDLE:{enter:function(){i.prevAngle=void 0,i.angle=0}},BEGIN:{},RECOGNIZED:{enter:function(){i.emit("rotatestart",i)},exit:function(){i.emit("rotateend",i)}}},init:function(){this.state=wt},eventEmitter:!1};this.setRecongizedStateObject(new F(s))}resetFromJSON(t){return super.resetFromJSON(t),this.setDragThreshold(ft(t,"threshold",0)),this}onDrag2Start(){this.prevAngle=mt(Et(this.angleBetween)),this.state=St,0===this.dragThreshold&&(this.state=xt)}onDrag2End(){this.state=wt}onDrag2(){switch(this.state){case St:if(this.pointers[0].getDistance()>=this.dragThreshold&&this.pointers[1].getDistance()>=this.dragThreshold){var t=mt(Et(this.angleBetween));this.angle=yt(this.prevAngle,t),this.prevAngle=t,this.state=xt}break;case xt:t=mt(Et(this.angleBetween)),this.angle=yt(this.prevAngle,t),this.prevAngle=t,this.emit("rotate",this)}}get isRotating(){return this.state===xt}get isRotated(){return this.isRotating}get rotation(){return _t(this.angle)}setDragThreshold(t){return this.dragThreshold=t,this}}.prototype,bt);const wt="IDLE",St="BEGIN",xt="RECOGNIZED";return K},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexswipe=e();