phaser4-rex-plugins
Version:
2 lines (1 loc) • 24.3 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};const s=Phaser.Game;var n=function(t){return t instanceof s},r=function(t){return null==t||"object"!=typeof t?null:n(t)?t:n(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 o{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){var e;return this.parent=t,this.scene=null==(e=t)||"object"!=typeof e?null:i(e)?e:e.scene&&i(e.scene)?e.scene:e.parent&&e.parent.scene&&i(e.parent.scene)?e.parent.scene:null,this.game=r(t),this}}function a(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}Object.assign(o.prototype,t);var u={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,h){if("function"!=typeof s)throw new TypeError("The listener must be a function");var o=new n(s,r||t,h),a=i?i+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],o]:t._events[a].push(o):(t._events[a]=o,t._eventsCount++),t}function h(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function o(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),o.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},o.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,h=new Array(r);n<r;n++)h[n]=s[n].fn;return h},o.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},o.prototype.emit=function(t,e,s,n,r,h){var o=i?i+t:t;if(!this._events[o])return!1;var a,u,l=this._events[o],v=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),v){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,s),!0;case 4:return l.fn.call(l.context,e,s,n),!0;case 5:return l.fn.call(l.context,e,s,n,r),!0;case 6:return l.fn.call(l.context,e,s,n,r,h),!0}for(u=1,a=new Array(v-1);u<v;u++)a[u-1]=arguments[u];l.fn.apply(l.context,a)}else{var d,p=l.length;for(u=0;u<p;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),v){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,s);break;case 4:l[u].fn.call(l[u].context,e,s,n);break;default:if(!a)for(d=1,a=new Array(v-1);d<v;d++)a[d-1]=arguments[d];l[u].fn.apply(l[u].context,a)}}return!0},o.prototype.on=function(t,e,i){return r(this,t,e,i,!1)},o.prototype.once=function(t,e,i){return r(this,t,e,i,!0)},o.prototype.removeListener=function(t,e,s,n){var r=i?i+t:t;if(!this._events[r])return this;if(!e)return h(this,r),this;var o=this._events[r];if(o.fn)o.fn!==e||n&&!o.once||s&&o.context!==s||h(this,r);else{for(var a=0,u=[],l=o.length;a<l;a++)(o[a].fn!==e||n&&!o[a].once||s&&o[a].context!==s)&&u.push(o[a]);u.length?this._events[r]=1===u.length?u[0]:u:h(this,r)}return this},o.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&h(this,e)):(this._events=new s,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=i,o.EventEmitter=o,t.exports=o}(u);var l=a(u.exports);class v extends l{shutdown(){this.removeAllListeners()}destroy(){this.removeAllListeners()}}var d={setEventEmitter(t,e){return void 0===e&&(e=v),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):[]}},p=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,h=0;h<s.length;h++){if(e=s[h],!n.hasOwnProperty(e)){r=i;break}n=r=n[e]}return r};const c=["next","exit","enter"];let m=class{constructor(t){var e=p(t,"states",void 0);e&&this.addStates(e);var i=p(t,"extend",void 0);if(i)for(var s in i)this.hasOwnProperty(s)&&void 0!==this[s]||(this[s]=i[s]);var n=p(t,"eventEmitter",void 0),r=p(t,"EventEmitterClass",void 0);this.setEventEmitter(n,r),this._stateLock=!1,this.resetFromJSON(t)}shutdown(){this.destroyEventEmitter()}destroy(){this.shutdown()}resetFromJSON(t){this.setEnable(p(t,"enable",!0)),this.start(p(t,"start",void 0));var e=p(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 c}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],h=e[r];h&&(this[`${r}_${t}`]=h)}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 h=this[t+"_"+this.state];if(h){var o=arguments.length;switch(o){case 1:return h.call(this);case 2:return h.call(this,e);case 3:return h.call(this,e,i);case 4:return h.call(this,e,i,s);case 5:return h.call(this,e,i,s,n);case 6:return h.call(this,e,i,s,n,r)}for(var a=new Array(o-1),u=1;u<o;u++)a[u-1]=arguments[u];return h.apply(this,a)}}};Object.assign(m.prototype,d);var f=function(t,e,i,s,n){void 0===n&&(n=!1);var r=t._events[e];if(!r)return!1;for(var h=0,o=r.length;h<o;h++){var a=r[h];if(a.fn===i&&a.context===s&&a.once===n)return!0}return!1};const _=["next","exit","enter","update","preupdate","postupdate"];class g extends m{shutdown(){this.stopUpdate(),this.stopPreUpdate(),this.stopPostUpdate(),this._scene=void 0,super.shutdown()}resetFromJSON(t){return super.resetFromJSON(t),this._scene=p(t,"scene",void 0),this}get stateProperties(){return _}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 f(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 f(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 f(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}}const y=Phaser.Math.Snap.To;Phaser.Math.Clamp;var E=function(){this.emit("dragstart")},x=function(){this.emit("dragend")},w=function(){this.value+=this.dragDelta},b=function(){var t=this.value,e=this.dragSpeed,i=this.snapStep;if(i){var s=t,n=0===e?0:e*e/(2*this.slidingDeceleration);s=y(s+=e>0?n:-n,i,this.minValue),(n=Math.abs(s-t))>0?(0===e?(r=this.backDeceleration,e=Math.sqrt(2*r*n)):(r=e*e/(2*n),r*=.99),this._slowDown.init(t,void 0,e,r,s)):(this._slowDown.stop(),this._state.next())}else if(0===e)this._slowDown.stop(),this._state.next();else{var r=this.slidingDeceleration;this._slowDown.init(t,e>0,e,r)}},S=function(t,e){e*=.001;var i=this._slowDown.update(e).value;this.overMax(i)?(this.value=this.maxValue,this._slowDown.stop()):this.overMin(i)?(this.value=this.minValue,this._slowDown.stop()):this.value=i},D=function(){var t=this.value,e=this.outOfMinBound?this.minValue:this.maxValue,i=Math.abs(e-t),s=this.backDeceleration,n=Math.sqrt(2*s*i);this._slowDown.init(t,void 0,n,s,e)},P=function(t,e){e*=.001,this.value=this._slowDown.update(e).value,this._slowDown.isMoving||this._state.next()},M=function(){this._slowDown.stop()};class O extends g{constructor(t,e){super(e),this.parent=t,this.init()}init(){this.start("IDLE")}next_IDLE(){var t,e=this.parent;return e.dragState.isDown&&(t=0===e.dragThreshold?"DRAG":"DRAGBEGIN"),t}update_IDLE(t,e){this.next()}next_DRAGBEGIN(){var t=this.parent,e=t.dragState;return e.isDown?e.pointer.getDistance()>=t.dragThreshold?"DRAG":"DRAGBEGIN":"IDLE"}update_DRAGBEGIN(t,e){this.next()}next_DRAG(){var t,e=this.parent;return e.dragState.isUp&&(t=e.outOfBounds?"BACK":e.slidingEnable?"SLIDE":"IDLE"),t}update_DRAG(t,e){var i=this.parent;i.dragState.justMoved&&w.call(i),this.next()}enter_DRAG(){E.call(this.parent)}exit_DRAG(){x.call(this.parent)}next_SLIDE(){var t,e=this.parent;return e.dragState.isDown?t="DRAG":e.isSliding||(t="IDLE"),t}enter_SLIDE(){b.call(this.parent)}exit_SLIDE(){M.call(this.parent)}update_SLIDE(t,e){S.call(this.parent,t,e),this.next()}next_BACK(){var t,e=this.parent;return e.dragState.isDown?t="DRAG":e.isPullBack||(t="IDLE"),t}enter_BACK(){D.call(this.parent)}exit_BACK(){M.call(this.parent)}update_BACK(t,e){P.call(this.parent,t,e),this.next()}}var B=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},L=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height};const I=Phaser.Geom.Rectangle,A=Phaser.Math.Vector2,T=Phaser.Math.RotateAround,R=Phaser.GameObjects.Container;var V=void 0,C=function(t,e,i){return void 0===e?e=new A:!0===e&&(void 0===Y&&(Y=new A),e=Y),t.getTopLeft?t.getTopLeft(e,i):(e.x=t.x-B(t)*t.originX,e.y=t.y-L(t)*t.originY,j(t,e,i))},k=function(t,e,i){return void 0===e?e=new A:!0===e&&(void 0===Y&&(Y=new A),e=Y),t.getTopRight?t.getTopRight(e,i):(e.x=t.x-B(t)*t.originX+B(t),e.y=t.y-L(t)*t.originY,j(t,e,i))},G=function(t,e,i){return void 0===e?e=new A:!0===e&&(void 0===Y&&(Y=new A),e=Y),t.getBottomLeft?t.getBottomLeft(e,i):(e.x=t.x-B(t)*t.originX,e.y=t.y-L(t)*t.originY+L(t),j(t,e,i))},X=function(t,e,i){return void 0===e?e=new A:!0===e&&(void 0===Y&&(Y=new A),e=Y),t.getBottomRight?t.getBottomRight(e,i):(e.x=t.x-B(t)*t.originX+B(t),e.y=t.y-L(t)*t.originY+L(t),j(t,e,i))},Y=void 0,j=function(t,e,i){return void 0===i&&(i=!1),0!==t.rotation&&T(e,t.x,t.y,t.rotation),i&&t.parentContainer&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e),e},N=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 I:!0===e&&(void 0===V&&(V=new I),e=V),t.getBounds&&!(t instanceof R))return t.getBounds(e);var i,s,n,r,h,o,a,u;if(t.parentContainer){var l=t.parentContainer.getBoundsTransformMatrix();C(t,e),l.transformPoint(e.x,e.y,e),i=e.x,s=e.y,k(t,e),l.transformPoint(e.x,e.y,e),n=e.x,r=e.y,G(t,e),l.transformPoint(e.x,e.y,e),h=e.x,o=e.y,X(t,e),l.transformPoint(e.x,e.y,e),a=e.x,u=e.y}else C(t,e),i=e.x,s=e.y,k(t,e),n=e.x,r=e.y,G(t,e),h=e.x,o=e.y,X(t,e),a=e.x,u=e.y;return e.x=Math.min(i,n,h,a),e.y=Math.min(s,r,o,u),e.width=Math.max(i,n,h,a)-e.x,e.height=Math.max(s,r,o,u)-e.y,e}(t,!0);return!(!r.contains(e,i)||n&&!n(t,e,i))},U=function(t,e,i){var s=t.camera;return s?(void 0===i?i={}:!0===i&&(i=F),s===e?(i.x=t.worldX,i.y=t.worldY):s.getWorldPoint(t.x,t.y,i),i):null},F={},J=function(t,e,i,s){return function(t,e,i,s,n){var r,h=t.scene.sys.cameras.main,o=0===t.scrollFactorX&&0===t.scrollFactorY;if(e)return o?i(t,e.x,e.y,s,n):!!(r=U(e,h,!0))&&i(t,r.x,r.y,s,n);for(var a=t.scene.input.manager,u=a.pointersTotal,l=a.pointers,v=0;v<u;v++)if(e=l[v],o){if(i(t,e.x,e.y,s,n))return!0}else{if(!(r=U(e,h,!0)))continue;if(i(t,r.x,r.y,s,n))return!0}return!1}(t,e,N,i,s)};const K=Phaser.Utils.Objects.GetValue,W=Phaser.Math.Distance.Between;class q extends o{constructor(t,e){super(t,e),this._enable=void 0,this.rectBoundsInteractive=K(e,"rectBoundsInteractive",!1),this.rectBoundsInteractive||t.setInteractive(K(e,"inputConfig",void 0)),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.pointer=void 0,this.isInTouched=!1,this.holdStartTime=void 0,this.x=void 0,this.y=void 0,this.preX=void 0,this.preY=void 0,this.localX=void 0,this.localY=void 0,this.justMoved=!1,this.setEnable(K(t,"enable",!0)),this.holdThreshold=K(t,"holdThreshold",50),this.pointerOutReleaseEnable=K(t,"pointerOutRelease",!0),this}boot(){var t=this.scene,e=this.parent;this.rectBoundsInteractive?(t.input.on("pointerdown",this.onPointIn,this),t.input.on("pointerup",this.onPointOut,this),t.input.on("pointermove",this.onPointerMove,this)):(e.on("pointerdown",this.onPointIn,this),e.on("pointerup",this.onPointOut,this),this.pointerOutReleaseEnable&&e.on("pointerout",this.onPointOut,this),e.on("pointermove",this.onPointerMove,this)),t.sys.events.on("preupdate",this.preupdate,this)}shutdown(t){if(!this.isShutdown){var e=this.scene;this.parent,this.rectBoundsInteractive&&(e.input.off("pointerdown",this.onPointIn,this),e.input.off("pointerup",this.onPointOut,this),e.input.off("pointermove",this.onPointerMove,this)),e.sys.events.off("preupdate",this.preupdate,this),this.pointer=void 0,super.shutdown(t)}}get enable(){return this._enable}set enable(t){this._enable!==t&&(t||(this.isInTouched=!1,this.pointer=void 0),this._enable=t)}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}toggleEnable(){return this.setEnable(!this.enable),this}setPointerOutReleaseEnable(t){return void 0===t&&(t=!0),this.pointerOutReleaseEnable=t,this}get isDown(){return this.pointer&&this.pointer.isDown}get isUp(){return!this.isDown}get dx(){return this.x-this.preX}get dy(){return this.y-this.preY}get dt(){var t;return t=this.scene,r(t).loop.delta}get speed(){return this.x===this.preX&&this.y===this.preY?0:W(this.preX,this.preY,this.x,this.y)/(.001*this.dt)}get speedX(){return this.dx/(.001*this.dt)}get speedY(){return this.dy/(.001*this.dt)}onPointIn(t,e,i){this.enable&&t.isDown&&void 0===this.pointer&&(this.rectBoundsInteractive&&!J(this.parent,t)||(this.pointer=t,this.localX=e,this.localY=i))}onPointOut(t){this.enable&&this.pointer===t&&(this.pointer=void 0)}onPointerMove(t,e,i){this.enable&&t.isDown&&this.pointer===t&&(this.rectBoundsInteractive&&this.pointerOutReleaseEnable&&!J(this.parent,t)?this.onPointOut(t):(this.localX=e,this.localY=i))}preupdate(t,e){if(this.enable){var i=this.pointer;this.justMoved=!1,i&&!this.isInTouched?(this.x=i.worldX,this.y=i.worldY,this.preX=i.worldX,this.preY=i.worldY,this.isInTouched=!0,this.holdStartTime=void 0,this.emit("touchstart",i,this.localX,this.localY)):i&&this.isInTouched?this.x===i.x&&this.y===i.y?void 0===this.holdStartTime?this.holdStartTime=t:t-this.holdStartTime>this.holdThreshold&&(this.preX=this.x,this.preY=this.y):(this.preX=this.x,this.preY=this.y,this.x=i.worldX,this.y=i.worldY,this.holdStartTime=void 0,this.justMoved=!0,this.emit("touchmove",i,this.localX,this.localY)):!i&&this.isInTouched&&(this.isInTouched=!1,this.holdStartTime=void 0,this.emit("touchend",i))}}}const H=Phaser.Utils.Objects.GetValue;class ${constructor(t){this.resetFromJSON(t)}resetFromJSON(t){return this.setValue(H(t,"value",0)),this.setSpeed(H(t,"speed",0)),this.setAcceleration(H(t,"acceleration",0)),this}reset(){this.setValue(0),this.setSpeed(0),this.setAcceleration(0)}setValue(t){return this.value=t,this}setSpeed(t){return this.speed=t,this}setAcceleration(t){return this.acceleration=t,this}updateSpeed(t){return 0!==this.acceleration&&(this.speed+=this.acceleration*t,this.speed<0&&(this.speed=0)),this}getDeltaValue(t){return this.updateSpeed(t),this.speed<=0?0:this.speed*t}update(t){return this.updateSpeed(t),this.speed>0&&(this.value+=this.getDeltaValue(t)),this}get isMoving(){return this.speed>0}}class z{constructor(){this.value,this.dir,this.movement=new $}init(t,e,i,s,n){return this.value=t,this.end=n,this.dir=void 0!==n?t<n:e,i=Math.abs(i),this.movement.setSpeed(i).setAcceleration(-s),this}stop(){this.movement.reset()}update(t){var e=this.movement.getDeltaValue(t);return this.dir||(e=-e),void 0===this.end?this.value+=e:0===e?this.value=this.end:(this.value+=e,this.dir?this.value>this.end&&(this.value=this.end):this.value<this.end&&(this.value=this.end)),this}get isMoving(){return this.movement.isMoving}}const Q=Phaser.Utils.Objects.GetValue,Z=Phaser.Math.Clamp;class tt extends o{constructor(t,e){super(t,e);var i=Q(e,"enable",!0);this._state=new O(this,{enable:i,eventEmitter:!1});var s={rectBoundsInteractive:Q(e,"rectBoundsInteractive",!1),inputConfig:Q(e,"inputConfig",void 0),enable:i,pointerOutRelease:Q(e,"pointerOutRelease",!0),eventEmitter:!1};this.dragState=new q(t,s),this._enable=void 0,this._value=void 0,this._slowDown=new z,this.setSnapStep(Q(e,"snapStep",void 0));var n=Q(e,"valuechangeCallback",null);if(null!==n){var r=Q(e,"valuechangeCallbackScope",void 0);this.on("valuechange",n,r)}null!==(n=Q(e,"overmaxCallback",null))&&(r=Q(e,"overmaxCallbackScope",void 0),this.on("overmax",n,r)),null!==(n=Q(e,"overminCallback",null))&&(r=Q(e,"overminCallbackScope",void 0),this.on("overmin",n,r)),this.resetFromJSON(e),this.boot()}resetFromJSON(t){this.setOrientationMode(Q(t,"orientation",0)),this.setDragThreshold(Q(t,"threshold",10)),this.setSlidingDeceleration(Q(t,"slidingDeceleration",5e3)),this.setBackDeceleration(Q(t,"backDeceleration",2e3));var e=Q(t,"dragRate",1);e*=Q(t,"dragReverse",!1)?-1:1,this.setDragRate(e);var i=Q(t,"bounds",void 0);return i?this.setBounds(i):this.setBounds(Q(t,"max",0),Q(t,"min",0)),this.setValue(Q(t,"value",this.maxValue||0)),this.setEnable(Q(t,"enable",!0)),this}boot(){this.scene.sys.events.on("preupdate",this._state.update,this._state)}shutdown(t){this.isShutdown||(this.scene.sys.events.off("preupdate",this._state.update,this._state),this._state.destroy(t),this.dragState.destroy(t),this._state=void 0,this.dragState=void 0,super.shutdown(t))}get enable(){return this._enable}set enable(t){if(this._enable!==t)return this._enable=t,this._state.setEnable(t),this.dragState.setEnable(t),this}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}toggleEnable(){return this.setEnable(!this.enable),this}setOrientationMode(t){return"string"==typeof t&&(t=et[t]),this.orientationMode=t,this}setDragThreshold(t){return this.dragThreshold=t,this}setSlidingDeceleration(t){return this.slidingDeceleration=t,this}setBackDeceleration(t){return this.backDeceleration=t,this}setDragRate(t){return this.dragRate=t,this}setBounds(t,e){if(Array.isArray(t)){var i=t;t=i[0],e=i[1]}return t<e?(this.minValue=t,this.maxValue=e):(this.minValue=e,this.maxValue=t),this}setSnapStep(t){return this.snapStep=t,this}get value(){return this._value}set value(t){if(t!==this._value){var e=this._value,i=this.overMax(t),s=this.overMin(t);i&&this.emit("overmax",t,e),s&&this.emit("overmin",t,e),this.backEnable||(i&&(t=this.maxValue),s&&(t=this.minValue)),this._value=t,this.emit("valuechange",t,e)}}setValue(t,e){return void 0===e&&(e=!1),e&&(t=Z(t,this.minValue,this.maxValue)),this.value=t,this}addValue(t,e){return this.setValue(this.value+t,e),this}get state(){return this._state.state}get isDragging(){return this.dragState.isInTouched}get outOfMaxBound(){return this.overMax(this.value)}get outOfMinBound(){return this.overMin(this.value)}get outOfBounds(){return this.outOfMinBound||this.outOfMaxBound}overMax(t){return null!=this.maxValue&&t>this.maxValue}overMin(t){return null!=this.minValue&&t<this.minValue}get backEnable(){return"number"==typeof this.backDeceleration}get isPullBack(){return this._slowDown.isMoving}get slidingEnable(){return"number"==typeof this.slidingDeceleration}get isSliding(){return this._slowDown.isMoving}get dragDelta(){var t;return t=0===this.orientationMode?this.dragState.dy:1===this.orientationMode?this.dragState.dx:0,t*=this.dragRate}get dragSpeed(){var t;return t=0===this.orientationMode?this.dragState.speedY:1===this.orientationMode?this.dragState.speedX:0,t*=this.dragRate}}const et={y:0,v:0,vertical:0,x:1,h:1,horizontal:1};class it extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e){return new tt(t,e)}}return it},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexscrollerplugin=e();