UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 39 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexgesturesplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(s=n.key,r=void 0,"symbol"==typeof(r=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(s,"string"))?r:String(r)),n);}var s,r;}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function h(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var i,n=r(t);if(e){var s=r(this).constructor;i=Reflect.construct(n,arguments,s);}else i=n.apply(this,arguments);return function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return a(t)}(this,i)}}function u(){return u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(arguments.length<3?t:i):s.value}},u.apply(this,arguments)}var c=function(){function t(i){e(this,t),this.scene=i;}return n(t,null,[{key:"register",value:function(e,i){t.prototype[e]=i;}}]),t}(),l={setEventEmitter:function(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:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){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):[]}},p=Phaser.Scene,v=function(t){return t instanceof p},f=function(e){return null==e||"object"!==t(e)?null:v(e)?e:e.scene&&v(e.scene)?e.scene:e.parent&&e.parent.scene&&v(e.parent.scene)?e.parent.scene:null},d=Phaser.Game,y=function(t){return t instanceof d},g=function(e){return null==e||"object"!==t(e)?null:y(e)?e:y(e.game)?e.game:v(e)?e.sys.game:v(e.scene)?e.scene.sys.game:void 0},m=Phaser.Utils.Objects.GetValue,E=function(){function t(i,n){e(this,t),this.setParent(i),this.isShutdown=!1,this.setEventEmitter(m(n,"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));}return n(t,[{key:"shutdown",value:function(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);}},{key:"destroy",value:function(t){this.shutdown(t);}},{key:"onEnvDestroy",value:function(){this.destroy(!0);}},{key:"onParentDestroy",value:function(t,e){this.destroy(e);}},{key:"setParent",value:function(t){return this.parent=t,this.scene=f(t),this.game=g(t),this}}]),t}();Object.assign(E.prototype,l);var k=Phaser.Utils.Objects.GetValue,b=function(t){s(o,t);var i=h(o);function o(t,n){var s;return e(this,o),(s=i.call(this,t,n))._isRunning=!1,s.isPaused=!1,s.tickingState=!1,s.setTickingMode(k(n,"tickingMode",1)),s}return n(o,[{key:"boot",value:function(){2!==this.tickingMode||this.tickingState||this.startTicking();}},{key:"shutdown",value:function(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),u(r(o.prototype),"shutdown",this).call(this,t));}},{key:"setTickingMode",value:function(t){"string"==typeof t&&(t=w[t]),this.tickingMode=t;}},{key:"startTicking",value:function(){this.tickingState=!0;}},{key:"stopTicking",value:function(){this.tickingState=!1;}},{key:"isRunning",get:function(){return this._isRunning},set:function(t){this._isRunning!==t&&(this._isRunning=t,1===this.tickingMode&&t!=this.tickingState&&(t?this.startTicking():this.stopTicking()));}},{key:"start",value:function(){return this.isPaused=!1,this.isRunning=!0,this}},{key:"pause",value:function(){return this.isRunning&&(this.isPaused=!0,this.isRunning=!1),this}},{key:"resume",value:function(){return this.isPaused&&(this.isRunning=!0),this}},{key:"stop",value:function(){return this.isPaused=!1,this.isRunning=!1,this}},{key:"complete",value:function(){this.isPaused=!1,this.isRunning=!1,this.emit("complete",this.parent,this);}}]),o}(E),w={no:0,lazy:1,always:2},_=Phaser.Utils.Objects.GetValue,D=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=f(t);return r===t&&(t=void 0),(s=i.call(this,r,n)).gameObject=t,t&&t.setInteractive(_(n,"inputConfig",void 0)),s._enable=void 0,s.resetFromJSON(n),s.boot(),s}return n(o,[{key:"resetFromJSON",value:function(t){return this.setEnable(_(t,"enable",!0)),this.setDetectBounds(),void 0===this.gameObject?this.setDetectBounds(_(t,"bounds",void 0)):this.setDetectBounds(),this.tracerState=S,this.pointer=void 0,this.lastPointer=void 0,this.movedState=!1,this.isTouchingAnyObject=!1,this}},{key:"boot",value:function(){u(r(o.prototype),"boot",this).call(this),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);}},{key:"shutdown",value:function(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,u(r(o.prototype),"shutdown",this).call(this,t));}},{key:"enable",get:function(){return this._enable},set:function(t){if(this._enable!==t)return t||this.dragCancel(),this._enable=t,this}},{key:"setEnable",value:function(t){return void 0===t&&(t=!0),this.enable=t,this}},{key:"setDetectBounds",value:function(t){return this.bounds=t,this}},{key:"toggleEnable",value:function(){return this.setEnable(!this.enable),this}},{key:"onPointerDown",value:function(t,e){this.enable&&(void 0===this.pointer&&(!this.bounds||this.bounds.contains(t.x,t.y))&&this.pointer!==t&&(this.pointer=t,this.lastPointer=t,this.movedState=!1,this.tracerState=P,void 0===this.gameObject&&(this.isTouchingAnyObject=e.length>0),this.onDragStart()));}},{key:"onPointerUp",value:function(t){this.enable&&((!this.bounds||this.bounds.contains(t.x,t.y))&&this.pointer===t&&(this.pointer=void 0,this.movedState=!1,this.tracerState=S,this.onDragEnd()));}},{key:"onPointerMove",value:function(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()));}}},{key:"dragCancel",value:function(){return this.tracerState===P&&this.onDragEnd(),this.pointer=void 0,this.tracerState=S,this}},{key:"onDragStart",value:function(){this.emit("dragstart",this);}},{key:"onDragEnd",value:function(){this.emit("dragend",this);}},{key:"onDrag",value:function(){this.emit("drag",this);}},{key:"preUpdate",value:function(t,e){}},{key:"postUpdate",value:function(t,e){}},{key:"startTicking",value:function(){u(r(o.prototype),"startTicking",this).call(this),this.scene.sys.events.on("preupdate",this.preUpdate,this),this.scene.sys.events.on("postupdate",this.postUpdate,this);}},{key:"stopTicking",value:function(){u(r(o.prototype),"stopTicking",this).call(this),this.scene&&(this.scene.sys.events.off("preupdate",this.preUpdate,this),this.scene.sys.events.off("postupdate",this.postUpdate,this));}},{key:"setRecongizedStateObject",value:function(t){return this.recongizedState=t,this}},{key:"state",get:function(){return this.recongizedState.state},set:function(t){this.recongizedState.state=t;}},{key:"cancel",value:function(){return this.state=O,this}}]),o}(b),S=0,P=1,O="IDLE";function x(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var T={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,i="~";function n(){}function s(t,e,i){this.fn=t,this.context=e,this.once=i||!1;}function r(t,e,n,r,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new s(n,r||t,o),h=i?i+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function o(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e];}function a(){this._events=new n,this._eventsCount=0;}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(i=!1)),a.prototype.eventNames=function(){var t,n,s=[];if(0===this._eventsCount)return s;for(n in t=this._events)e.call(t,n)&&s.push(i?n.slice(1):n);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(t)):s},a.prototype.listeners=function(t){var e=i?i+t:t,n=this._events[e];if(!n)return [];if(n.fn)return [n.fn];for(var s=0,r=n.length,o=new Array(r);s<r;s++)o[s]=n[s].fn;return o},a.prototype.listenerCount=function(t){var e=i?i+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,s,r,o){var a=i?i+t:t;if(!this._events[a])return !1;var h,u,c=this._events[a],l=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,s),!0;case 5:return c.fn.call(c.context,e,n,s,r),!0;case 6:return c.fn.call(c.context,e,n,s,r,o),!0}for(u=1,h=new Array(l-1);u<l;u++)h[u-1]=arguments[u];c.fn.apply(c.context,h);}else {var p,v=c.length;for(u=0;u<v;u++)switch(c[u].once&&this.removeListener(t,c[u].fn,void 0,!0),l){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,e);break;case 3:c[u].fn.call(c[u].context,e,n);break;case 4:c[u].fn.call(c[u].context,e,n,s);break;default:if(!h)for(p=1,h=new Array(l-1);p<l;p++)h[p-1]=arguments[p];c[u].fn.apply(c[u].context,h);}}return !0},a.prototype.on=function(t,e,i){return r(this,t,e,i,!1)},a.prototype.once=function(t,e,i){return r(this,t,e,i,!0)},a.prototype.removeListener=function(t,e,n,s){var r=i?i+t:t;if(!this._events[r])return this;if(!e)return o(this,r),this;var a=this._events[r];if(a.fn)a.fn!==e||s&&!a.once||n&&a.context!==n||o(this,r);else {for(var h=0,u=[],c=a.length;h<c;h++)(a[h].fn!==e||s&&!a[h].once||n&&a[h].context!==n)&&u.push(a[h]);u.length?this._events[r]=1===u.length?u[0]:u:o(this,r);}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&o(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=i,a.EventEmitter=a,t.exports=a;}(T);var j=function(t){s(r,t);var i=h(r);function r(){return e(this,r),i.apply(this,arguments)}return n(r,[{key:"shutdown",value:function(){this.removeAllListeners();}},{key:"destroy",value:function(){this.removeAllListeners();}}]),r}(x(T.exports)),R={setEventEmitter:function(t,e){return void 0===e&&(e=j),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){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):[]}},N=function(t,e,i){if(t&&"number"!=typeof t){if(t.hasOwnProperty(e))return t[e];if(-1!==e.indexOf(".")){for(var n=e.split("."),s=t,r=i,o=0;o<n.length;o++){if(!s.hasOwnProperty(n[o])){r=i;break}r=s[n[o]],s=s[n[o]];}return r}return i}return i},C=["next","exit","enter"],I=function(){function t(i){e(this,t);var n=N(i,"states",void 0);n&&this.addStates(n);var s=N(i,"extend",void 0);if(s)for(var r in s)this.hasOwnProperty(r)&&void 0!==this[r]||(this[r]=s[r]);var o=N(i,"eventEmitter",void 0),a=N(i,"EventEmitterClass",void 0);this.setEventEmitter(o,a),this._stateLock=!1,this.resetFromJSON(i);}return n(t,[{key:"shutdown",value:function(){this.destroyEventEmitter();}},{key:"destroy",value:function(){this.shutdown();}},{key:"resetFromJSON",value:function(t){this.setEnable(N(t,"enable",!0)),this.start(N(t,"start",void 0));var e=N(t,"init",void 0);return e&&e.call(this),this}},{key:"toJSON",value:function(){return {curState:this.state,prevState:this.prevState,enable:this.enable,start:this._start}}},{key:"setEnable",value:function(t){return void 0===t&&(t=!0),this.enable=t,this}},{key:"toggleEnable",value:function(){return this.setEnable(!this.enable),this}},{key:"state",get:function(){return this._state},set:function(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 n="enter_"+this._state,s=this[n];s&&s.call(this),this.emit(n,this);}}}},{key:"prevState",get:function(){return this._prevState}},{key:"start",value:function(t){return this._start=t,this._prevState=void 0,this._state=t,this}},{key:"goto",value:function(t){return null!=t&&(this.state=t),this}},{key:"next",value:function(){var t,e=this["next_"+this.state];return e&&(t="string"==typeof e?e:e.call(this)),this.goto(t),this}},{key:"stateProperties",get:function(){return C}},{key:"addState",value:function(t,e){"string"!=typeof t&&(t=(e=t).name);for(var i=this.stateProperties,n=0,s=i.length;n<s;n++){var r=i[n],o=e[r];o&&(this["".concat(r,"_").concat(t)]=o);}return this}},{key:"addStates",value:function(t){if(Array.isArray(t))for(var e=0,i=t.length;e<i;e++)this.addState(t[e]);else for(var n in t)this.addState(n,t[n]);return this}},{key:"runMethod",value:function(t,e,i,n,s,r){var o=this[t+"_"+this.state];if(o){var a=arguments.length;switch(a){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,n);case 5:return o.call(this,e,i,n,s);case 6:return o.call(this,e,i,n,s,r)}for(var h=new Array(a-1),u=1;u<a;u++)h[u-1]=arguments[u];return o.apply(this,h)}}}]),t}();Object.assign(I.prototype,R);var G=function(t,e,i,n,s){void 0===s&&(s=!1);var r=t._events[e];if(!r)return !1;for(var o=0,a=r.length;o<a;o++){var h=r[o];if(h.fn===i&&h.context===n&&h.once===s)return !0}return !1},M=["next","exit","enter","update","preupdate","postupdate"],L=function(t){s(o,t);var i=h(o);function o(){return e(this,o),i.apply(this,arguments)}return n(o,[{key:"shutdown",value:function(){this.stopUpdate(),this.stopPreUpdate(),this.stopPostUpdate(),this._scene=void 0,u(r(o.prototype),"shutdown",this).call(this);}},{key:"resetFromJSON",value:function(t){return u(r(o.prototype),"resetFromJSON",this).call(this,t),this._scene=N(t,"scene",void 0),this}},{key:"stateProperties",get:function(){return M}},{key:"update",value:function(t,e){this.runMethod("update",t,e);}},{key:"preupdate",value:function(t,e){this.runMethod("preupdate",t,e);}},{key:"postupdate",value:function(t,e){this.runMethod("postupdate",t,e);}},{key:"startUpdate",value:function(t){t||(t=this._scene);var e=t.sys.events;return G(e,"update",this.update,this)||(this._scene=t,e.on("update",this.update,this)),this}},{key:"stopUpdate",value:function(){return this._scene?(this._scene.sys.events.off("update",this.update,this),this):this}},{key:"startPreUpdate",value:function(t){t||(t=this._scene);var e=t.sys.events;return G(e,"preupdate",this.preupdate,this)||(this._scene=t,e.on("preupdate",this.preupdate,this)),this}},{key:"stopPreUpdate",value:function(){return this._scene?(this._scene.sys.events.off("preupdate",this.preupdate,this),this):this}},{key:"startPostUpdate",value:function(t){t||(t=this._scene);var e=t.sys.events;return G(e,"postupdate",this.postupdate,this)||(this._scene=t,e.on("postupdate",this.postupdate,this)),this}},{key:"stopPostUpdate",value:function(){return this._scene?(this._scene.sys.events.off("postupdate",this.postupdate,this),this):this}}]),o}(I),U=Phaser.Utils.Objects.GetValue,A=Phaser.Math.Distance.Between,B=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=a(s=i.call(this,t,n)),h={states:{IDLE:{enter:function(){r.stop(),r.tapsCount=0,r.x=0,r.y=0,r.worldX=0,r.worldY=0;},exit:function(){var t=r.lastPointer;r.x=t.x,r.y=t.y,r.worldX=t.worldX,r.worldY=t.worldY;}},BEGIN:{enter:function(){r.start(),r.tapsCount=0,r.emit("tappingstart",r,r.gameObject,r.lastPointer);}},RECOGNIZED:{enter:function(){r.start(),r.emit("tap",r,r.gameObject,r.lastPointer),r.emit("".concat(r.tapsCount,"tap"),r,r.gameObject,r.lastPointer);}}},init:function(){this.state=X;},eventEmitter:!1};return s.setRecongizedStateObject(new L(h)),s}return n(o,[{key:"resetFromJSON",value:function(t){u(r(o.prototype),"resetFromJSON",this).call(this,t),this.setHoldTime(U(t,"time",250)),this.setTapInterval(U(t,"tapInterval",200)),this.setDragThreshold(U(t,"threshold",9)),this.setTapOffset(U(t,"tapOffset",10));var e=U(t,"taps",void 0);return void 0!==e?this.setTaps(e):(this.setMaxTaps(U(t,"maxTaps",void 0)),this.setMinTaps(U(t,"minTaps",void 0))),this}},{key:"onDragStart",value:function(){switch(this.state){case X:this.state=Y;break;case Y:var t=this.lastPointer;A(t.upX,t.upY,t.x,t.y)>this.tapOffset&&(this.state=F,this.state=Y);break;case F:this.state=Y;}}},{key:"onDragEnd",value:function(){this.state===Y&&(this.tapsCount++,this.emit("tapping",this,this.gameObject,this.lastPointer),void 0!==this.maxTaps&&this.tapsCount===this.maxTaps&&(this.state=F));}},{key:"onDrag",value:function(){this.state!==X&&this.pointer.getDistance()>this.dragThreshold&&(this.state=X);}},{key:"preUpdate",value:function(t,e){if(this.isRunning&&this.enable&&this.state===Y){var i=this.lastPointer;if(i.isDown)t-i.downTime>this.holdTime&&(this.state=X);else t-i.upTime>this.tapInterval&&(void 0===this.minTaps||this.tapsCount>=this.minTaps?this.state=F:this.state=X);}}},{key:"postUpdate",value:function(t,e){this.isRunning&&this.enable&&this.state===F&&(this.state=X);}},{key:"isTapped",get:function(){return this.state===F}},{key:"setHoldTime",value:function(t){return this.holdTime=t,this}},{key:"setTapInterval",value:function(t){return this.tapInterval=t,this}},{key:"setDragThreshold",value:function(t){return this.dragThreshold=t,this}},{key:"setTapOffset",value:function(t){return this.tapOffset=t,this}},{key:"setMaxTaps",value:function(t){return this.maxTaps=t,this}},{key:"setMinTaps",value:function(t){return this.minTaps=t,this}},{key:"setTaps",value:function(t,e){return void 0===e&&(e=t),this.setMinTaps(t).setMaxTaps(e),this}}]),o}(D),X="IDLE",Y="BEGIN",F="RECOGNIZED",V=function(t){return null==t||""===t||0===t.length},J=function(e,i,n,s){if(void 0===s&&(s="."),"object"===t(e)){if(V(i)){if(null==n)return;"object"===t(n)&&(e=n);}else {"string"==typeof i&&(i=i.split(s));var r=i.pop(),o=function(e,i,n){var s=e;if(V(i));else {var r;"string"==typeof i&&(i=i.split("."));for(var o=0,a=i.length;o<a;o++){var h;null!=s[r=i[o]]&&"object"===t(s[r])||(h=o===a-1?void 0===n?{}:n:{},s[r]=h),s=s[r];}}return s}(e,i);o[r]=n;}return e}},z=Phaser.GameObjects.GameObject,Z=function(t){return t instanceof z};c.register("tap",(function(t,e){return Z(t)||(e=t,t=this.scene),new B(t,e)})),J(window,"RexPlugins.Gestures.Tap",B);var W=Phaser.Utils.Objects.GetValue,H=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=a(s=i.call(this,t,n)),h={states:{IDLE:{enter:function(){r.x=0,r.y=0,r.worldX=0,r.worldY=0;},exit:function(){var t=r.lastPointer;r.x=t.x,r.y=t.y,r.worldX=t.worldX,r.worldY=t.worldY;}},BEGIN:{enter:function(){r.start();},exit:function(){r.stop();}},RECOGNIZED:{enter:function(){r.emit("pressstart",r,r.gameObject,r.lastPointer);},exit:function(){r.emit("pressend",r,r.gameObject,r.lastPointer);}}},init:function(){this.state=q;},eventEmitter:!1};return s.setRecongizedStateObject(new L(h)),s}return n(o,[{key:"resetFromJSON",value:function(t){return u(r(o.prototype),"resetFromJSON",this).call(this,t),this.setDragThreshold(W(t,"threshold",9)),this.setHoldTime(W(t,"time",251)),this}},{key:"onDragStart",value:function(){this.state=K,0===this.holdTime&&(this.state=Q);}},{key:"onDragEnd",value:function(){this.state=q;}},{key:"onDrag",value:function(){this.state!==q&&this.pointer.getDistance()>this.dragThreshold&&(this.state=q);}},{key:"preUpdate",value:function(t,e){this.isRunning&&this.enable&&(this.state===K&&t-this.pointer.downTime>=this.holdTime&&(this.state=Q));}},{key:"isPressed",get:function(){return this.state===Q}},{key:"setHoldTime",value:function(t){return this.holdTime=t,this}},{key:"setDragThreshold",value:function(t){return this.dragThreshold=t,this}}]),o}(D),q="IDLE",K="BEGIN",Q="RECOGNIZED";c.register("press",(function(t,e){return Z(t)||(e=t,t=this.scene),new H(t,e)})),J(window,"RexPlugins.Gestures.Press",H);var $=Phaser.Utils.Objects.GetValue,tt=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=a(s=i.call(this,t,n)),h={states:{IDLE:{},BEGIN:{enter:function(){var t=r.pointer;r.startX=t.x,r.startY=t.y,r.startWorldX=t.worldX,r.startWorldY=t.worldY;}},RECOGNIZED:{enter:function(){r.emit("panstart",r,r.gameObject,r.lastPointer);},exit:function(){var t=r.lastPointer;r.endX=t.x,r.endY=t.y,r.endWorldX=t.worldX,r.endWorldY=t.worldY,r.emit("panend",r,r.gameObject,r.lastPointer);}}},init:function(){this.state=et;},eventEmitter:!1};return s.setRecongizedStateObject(new L(h)),s}return n(o,[{key:"resetFromJSON",value:function(t){return u(r(o.prototype),"resetFromJSON",this).call(this,t),this.setDragThreshold($(t,"threshold",10)),this}},{key:"onDragStart",value:function(){this.state=it,0===this.dragThreshold&&(this.state=nt);}},{key:"onDragEnd",value:function(){this.state=et;}},{key:"onDrag",value:function(){switch(this.state){case it:this.pointer.getDistance()>=this.dragThreshold&&(this.state=nt);break;case nt:var t=this.pointer.position,e=this.pointer.prevPosition;this.dx=t.x-e.x,this.dy=t.y-e.y;var i=this.pointer;this.x=i.x,this.y=i.y,this.worldX=i.worldX,this.worldY=i.worldY,this.emit("pan",this,this.gameObject,this.lastPointer);}}},{key:"isPanned",get:function(){return this.state===nt}},{key:"setDragThreshold",value:function(t){return this.dragThreshold=t,this}}]),o}(D),et="IDLE",it="BEGIN",nt="RECOGNIZED";c.register("pan",(function(t,e){return Z(t)||(e=t,t=this.scene),new tt(t,e)})),J(window,"RexPlugins.Gestures.Pan",tt);var st=Phaser.Math.Distance.Between,rt=Phaser.Math.Angle.Between,ot={getDt:function(){var t;return t=this.scene,g(t).loop.delta},getVelocity:function(){var t=this.pointer.position,e=this.pointer.prevPosition;return st(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 rt(e.x,e.y,t.x,t.y)}},at={"up&down":0,"left&right":1,"4dir":2,"8dir":3},ht={},ut=Phaser.Utils.Objects.GetValue,ct=Phaser.Math.RadToDeg,lt=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=a(s=i.call(this,t,n)),h={states:{IDLE:{enter:function(){r.x=0,r.y=0,r.worldX=0,r.worldY=0;},exit:function(){var t=r.lastPointer;r.x=t.x,r.y=t.y,r.worldX=t.worldX,r.worldY=t.worldY;}},BEGIN:{enter:function(){r.validDrag=!1;}},RECOGNIZED:{enter:function(){r.start(),r.updateDirectionStates(),r.emit("swipe",r,r.gameObject,r.lastPointer);},exit:function(){r.stop(),r.clearDirectionStates();}}},init:function(){this.state=pt;},eventEmitter:!1};return s.setRecongizedStateObject(new L(h)),s.clearDirectionStates(),s}return n(o,[{key:"resetFromJSON",value:function(t){return u(r(o.prototype),"resetFromJSON",this).call(this,t),this.setDragThreshold(ut(t,"threshold",10)),this.setVelocityThreshold(ut(t,"velocityThreshold",1e3)),this.setDirectionMode(ut(t,"dir","8dir")),this}},{key:"onDragStart",value:function(){this.state=vt;}},{key:"onDragEnd",value:function(){this.state=pt;}},{key:"onDrag",value:function(){this.state===vt&&(this.validDrag||(this.validDrag=0===this.dragThreshold||this.pointer.getDistance()>=this.dragThreshold),this.validDrag&&this.dragVelocity>this.velocityThreshold&&(this.state=ft));}},{key:"postUpdate",value:function(t,e){this.isRunning&&this.enable&&this.state===ft&&(this.state=pt);}},{key:"isSwiped",get:function(){return this.state===ft}},{key:"dragVelocity",get:function(){var t;switch(this.dirMode){case 0:t=this.getVelocityY();break;case 1:t=this.getVelocityX();break;default:t=this.getVelocity();}return t}},{key:"setDragThreshold",value:function(t){return this.dragThreshold=t,this}},{key:"setVelocityThreshold",value:function(t){return this.velocityThreshold=t,this}},{key:"setDirectionMode",value:function(t){return "string"==typeof t&&(t=at[t]),this.dirMode=t,this}},{key:"updateDirectionStates",value:function(){return function(t,e,i){switch(void 0===i?i={}:!0===i&&(i=ht),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;}}(ct(this.getVelocityAngle()),this.dirMode,this),this}},{key:"clearDirectionStates",value:function(){return this.left=!1,this.right=!1,this.up=!1,this.down=!1,this}}]),o}(D);Object.assign(lt.prototype,ot);var pt="IDLE",vt="BEGIN",ft="RECOGNIZED";c.register("swipe",(function(t,e){return Z(t)||(e=t,t=this.scene),new lt(t,e)})),J(window,"RexPlugins.Gestures.Swipe",lt);var dt=function(e){if("object"!==t(e)||null===e)return e;if(Array.isArray(e))e.length=0;else for(var i in e)delete e[i];return e},yt=Phaser.Utils.Objects.GetValue,gt=Phaser.Utils.Array.SpliceOne,mt=Phaser.Math.Distance.Between,Et=Phaser.Math.Angle.Between,kt=function(){function t(i,n){e(this,t);var s=i.input.manager.pointersTotal-1;s<2&&i.input.addPointer(2-s),this.scene=i,this.setEventEmitter(yt(n,"eventEmitter",void 0)),this._enable=void 0,this.pointers=[],this.movedState={},this.resetFromJSON(n),this.boot();}return n(t,[{key:"resetFromJSON",value:function(t){return this.setEnable(yt(t,"enable",!0)),this.bounds=yt(t,"bounds",void 0),this.tracerState=wt,this.pointers.length=0,dt(this.movedState),this}},{key:"boot",value:function(){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);}},{key:"shutdown",value:function(){this.scene&&(this.destroyEventEmitter(),this.pointers.length=0,dt(this.movedState),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);}},{key:"destroy",value:function(){this.shutdown();}},{key:"enable",get:function(){return this._enable},set:function(t){if(this._enable!==t)return t||this.dragCancel(),this._enable=t,this}},{key:"setEnable",value:function(t){return void 0===t&&(t=!0),this.enable=t,this}},{key:"toggleEnable",value:function(){return this.setEnable(!this.enable),this}},{key:"onPointerDown",value:function(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.tracerState){case wt:this.tracerState=_t,this.onDrag1Start();break;case _t:this.tracerState=Dt,this.onDrag2Start();}}},{key:"onPointerUp",value:function(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],gt(this.pointers,e),this.tracerState){case _t:this.tracerState=wt,this.onDrag1End();break;case Dt:this.tracerState=_t,this.onDrag2End(),this.onDrag1Start();}}}},{key:"onPointerMove",value:function(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 _t:this.onDrag1();break;case Dt:this.onDrag2();}}}},{key:"dragCancel",value:function(){return this.tracerState===Dt&&this.onDrag2End(),this.pointers.length=0,dt(this.movedState),this.tracerState=wt,this}},{key:"onDrag1Start",value:function(){this.emit("drag1start",this);}},{key:"onDrag1End",value:function(){this.emit("drag1end",this);}},{key:"onDrag1",value:function(){this.emit("drag1",this);}},{key:"onDrag2Start",value:function(){this.emit("drag2start",this);}},{key:"onDrag2End",value:function(){this.emit("drag2end",this);}},{key:"onDrag2",value:function(){this.emit("drag2",this);}},{key:"distanceBetween",get:function(){if(this.tracerState!==Dt)return 0;var t=this.pointers[0],e=this.pointers[1];return mt(t.x,t.y,e.x,e.y)}},{key:"angleBetween",get:function(){if(this.tracerState!==Dt)return 0;var t=this.pointers[0],e=this.pointers[1];return Et(t.x,t.y,e.x,e.y)}},{key:"drag1Vector",get:function(){var t=this.pointers[0];if(t&&this.movedState[t.id]){var e=t.position,i=t.prevPosition;bt.x=e.x-i.x,bt.y=e.y-i.y;}else bt.x=0,bt.y=0;return bt}},{key:"centerX",get:function(){if(this.tracerState!==Dt)return 0;var t=this.pointers[0].position,e=this.pointers[1].position;return (t.x+e.x)/2}},{key:"centerY",get:function(){if(this.tracerState!==Dt)return 0;var t=this.pointers[0].position,e=this.pointers[1].position;return (t.y+e.y)/2}},{key:"prevCenterX",get:function(){if(this.tracerState!==Dt)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}},{key:"prevCenterY",get:function(){if(this.tracerState!==Dt)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}},{key:"movementCenterX",get:function(){return this.centerX-this.prevCenterX}},{key:"movementCenterY",get:function(){return this.centerY-this.prevCenterY}},{key:"setRecongizedStateObject",value:function(t){return this.recongizedState=t,this}},{key:"state",get:function(){return this.recongizedState.state},set:function(t){this.recongizedState.state=t;}},{key:"cancel",value:function(){return this.state=St,this}}]),t}();Object.assign(kt.prototype,l);var bt={},wt=0,_t=1,Dt=2,St="IDLE",Pt=Phaser.Utils.Objects.GetValue,Ot=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=a(s=i.call(this,t,n)),h={states:{IDLE:{enter:function(){r.prevDistance=void 0,r.scaleFactor=1;}},BEGIN:{},RECOGNIZED:{enter:function(){r.emit("pinchstart",r);},exit:function(){r.emit("pinchend",r);}}},init:function(){this.state=xt;},eventEmitter:!1};return s.setRecongizedStateObject(new L(h)),s}return n(o,[{key:"resetFromJSON",value:function(t){return u(r(o.prototype),"resetFromJSON",this).call(this,t),this.setDragThreshold(Pt(t,"threshold",0)),this}},{key:"onDrag2Start",value:function(){this.scaleFactor=1,this.prevDistance=this.distanceBetween,this.state=Tt,0===this.dragThreshold&&(this.state=jt);}},{key:"onDrag2End",value:function(){this.state=xt;}},{key:"onDrag2",value:function(){switch(this.state){case Tt:if(this.pointers[0].getDistance()>=this.dragThreshold&&this.pointers[1].getDistance()>=this.dragThreshold){var t=this.distanceBetween;this.scaleFactor=t/this.prevDistance,this.prevDistance=t,this.state=jt;}break;case jt:t=this.distanceBetween;this.scaleFactor=t/this.prevDistance,this.emit("pinch",this),this.prevDistance=t;}}},{key:"isPinched",get:function(){return this.state===jt}},{key:"setDragThreshold",value:function(t){return this.dragThreshold=t,this}}]),o}(kt),xt="IDLE",Tt="BEGIN",jt="RECOGNIZED";c.register("pinch",(function(t){return new Ot(this.scene,t)})),J(window,"RexPlugins.Gestures.Pinch",Ot);var Rt=Phaser.Math.RotateAround,Nt=function(t,e,i,n){return Rt(t,e,i,n),t.rotation+=n,t},Ct={},It=Phaser.Utils.Objects.GetValue,Gt=Phaser.Math.Angle.WrapDegrees,Mt=Phaser.Math.Angle.ShortestBetween,Lt=Phaser.Math.RadToDeg,Ut=Phaser.Math.DegToRad,At=function(t){s(o,t);var i=h(o);function o(t,n){var s;e(this,o);var r=a(s=i.call(this,t,n)),h={states:{IDLE:{enter:function(){r.prevAngle=void 0,r.angle=0;}},BEGIN:{},RECOGNIZED:{enter:function(){r.emit("rotatestart",r);},exit:function(){r.emit("rotateend",r);}}},init:function(){this.state=Xt;},eventEmitter:!1};return s.setRecongizedStateObject(new L(h)),s}return n(o,[{key:"resetFromJSON",value:function(t){return u(r(o.prototype),"resetFromJSON",this).call(this,t),this.setDragThreshold(It(t,"threshold",0)),this}},{key:"onDrag2Start",value:function(){this.prevAngle=Gt(Lt(this.angleBetween)),this.state=Yt,0===this.dragThreshold&&(this.state=Ft);}},{key:"onDrag2End",value:function(){this.state=Xt;}},{key:"onDrag2",value:function(){switch(this.state){case Yt:if(this.pointers[0].getDistance()>=this.dragThreshold&&this.pointers[1].getDistance()>=this.dragThreshold){var t=Gt(Lt(this.angleBetween));this.angle=Mt(this.prevAngle,t),this.prevAngle=t,this.state=Ft;}break;case Ft:t=Gt(Lt(this.angleBetween));this.angle=Mt(this.prevAngle,t),this.prevAngle=t,this.emit("rotate",this);}}},{key:"isRotated",get:function(){return this.state===Ft}},{key:"rotation",get:function(){return Ut(this.angle)}},{key:"setDragThreshold",value:function(t){return this.dragThreshold=t,this}}]),o}(kt),Bt={spinObject:function(t,e){if(!this.isRotation)return this;void 0===e&&(e=this.pointers[0].camera);var i=this.movementCenterX,n=this.movementCenterY,s=function(t,e,i,n){return void 0===n?n={}:!0===n&&(n=Ct),i.getWorldPoint(t,e,n),n}(this.centerX,this.centerY,e,!0),r=s.x,o=s.y,a=this.rotation;if(Array.isArray(t))for(var h=t,u=0,c=h.length;u<c;u++)(t=h[u]).x+=i,t.y+=n,Nt(t,r,o,a);else t.x+=i,t.y+=n,Nt(t,r,o,a);return this}};Object.assign(At.prototype,Bt);var Xt="IDLE",Yt="BEGIN",Ft="RECOGNIZED";return c.register("rotate",(function(t){return new At(this.scene,t)})),J(window,"RexPlugins.Gestures.Rotate",At),function(t){s(r,Phaser.Plugins.ScenePlugin);var i=h(r);function r(t,n){var s;return e(this,r),(s=i.call(this,t,n)).add=new c(t),s}return n(r)}()}));