phaser3-rex-plugins
Version:
2 lines (1 loc) • 31.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 s=function(t){return t instanceof e},i=function(t){return null==t||"object"!=typeof t?null:s(t)?t:t.scene&&s(t.scene)?t.scene:t.parent&&t.parent.scene&&s(t.parent.scene)?t.parent.scene:null};const n=Phaser.Game;var r=function(t){return t instanceof n};const a=Phaser.Utils.Objects.GetValue;class o{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(a(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=i(t),this.game=null==(e=t)||"object"!=typeof e?null:r(e)?e:r(e.game)?e.game:s(e)?e.sys.game:s(e.scene)?e.scene.sys.game:void 0,this}}function h(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,s="~";function i(){}function n(t,e,s){this.fn=t,this.context=e,this.once=s||!1}function r(t,e,i,r,a){if("function"!=typeof i)throw new TypeError("The listener must be a function");var o=new n(i,r||t,a),h=s?s+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],o]:t._events[h].push(o):(t._events[h]=o,t._eventsCount++),t}function a(t,e){0==--t._eventsCount?t._events=new i:delete t._events[e]}function o(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(s=!1)),o.prototype.eventNames=function(){var t,i,n=[];if(0===this._eventsCount)return n;for(i in t=this._events)e.call(t,i)&&n.push(s?i.slice(1):i);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},o.prototype.listeners=function(t){var e=s?s+t:t,i=this._events[e];if(!i)return[];if(i.fn)return[i.fn];for(var n=0,r=i.length,a=new Array(r);n<r;n++)a[n]=i[n].fn;return a},o.prototype.listenerCount=function(t){var e=s?s+t:t,i=this._events[e];return i?i.fn?1:i.length:0},o.prototype.emit=function(t,e,i,n,r,a){var o=s?s+t:t;if(!this._events[o])return!1;var h,u,l=this._events[o],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){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,i),!0;case 4:return l.fn.call(l.context,e,i,n),!0;case 5:return l.fn.call(l.context,e,i,n,r),!0;case 6:return l.fn.call(l.context,e,i,n,r,a),!0}for(u=1,h=new Array(c-1);u<c;u++)h[u-1]=arguments[u];l.fn.apply(l.context,h)}else{var p,d=l.length;for(u=0;u<d;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),c){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,i);break;case 4:l[u].fn.call(l[u].context,e,i,n);break;default:if(!h)for(p=1,h=new Array(c-1);p<c;p++)h[p-1]=arguments[p];l[u].fn.apply(l[u].context,h)}}return!0},o.prototype.on=function(t,e,s){return r(this,t,e,s,!1)},o.prototype.once=function(t,e,s){return r(this,t,e,s,!0)},o.prototype.removeListener=function(t,e,i,n){var r=s?s+t:t;if(!this._events[r])return this;if(!e)return a(this,r),this;var o=this._events[r];if(o.fn)o.fn!==e||n&&!o.once||i&&o.context!==i||a(this,r);else{for(var h=0,u=[],l=o.length;h<l;h++)(o[h].fn!==e||n&&!o[h].once||i&&o[h].context!==i)&&u.push(o[h]);u.length?this._events[r]=1===u.length?u[0]:u:a(this,r)}return this},o.prototype.removeAllListeners=function(t){var e;return t?(e=s?s+t:t,this._events[e]&&a(this,e)):(this._events=new i,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=s,o.EventEmitter=o,t.exports=o}(u);var l=h(u.exports);class c extends l{shutdown(){this.removeAllListeners()}destroy(){this.removeAllListeners()}}var p={setEventEmitter(t,e){return void 0===e&&(e=c),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):[]}},d=function(t,e,s,i){var n=t&&("object"==typeof t||"function"==typeof t),r=i&&("object"==typeof i||"function"==typeof i);if(!n&&!r)return s;var a=String(e);if(n&&a in t)return t[a];if(r&&a in i)return i[a];if(-1===a.indexOf("."))return s;var o=a.split(".");if(n){var h=v(t,o,s);if(h.found)return h.value}if(r){var u=v(i,o,s);if(u.found)return u.value}return s},v=function(t,e,s){for(var i=t,n=s,r=0,a=e.length;r<a;r++){var o=e[r];if(!i||"object"!=typeof i&&"function"!=typeof i||!(o in i))return m.found=!1,m;i=n=i[o]}return m.found=!0,m.value=n,m},m={};const f=["next","exit","enter"];let y=class{constructor(t){var e=d(t,"states",void 0);e&&this.addStates(e);var s=d(t,"extend",void 0);if(s)for(var i in s)this.hasOwnProperty(i)&&void 0!==this[i]||(this[i]=s[i]);var n=d(t,"eventEmitter",void 0),r=d(t,"EventEmitterClass",void 0);this.setEventEmitter(n,r),this._stateLock=!1,this.resetFromJSON(t)}shutdown(){this.destroyEventEmitter()}destroy(){this.shutdown()}resetFromJSON(t){this.setEnable(d(t,"enable",!0)),this.start(d(t,"start",void 0));var e=d(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,s=this[e];s&&s.call(this),this.emit(e,this)}if(this._stateLock=!1,null!=this._state){var i="enter_"+this._state,n=this[i];n&&n.call(this),this.emit(i,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 f}addState(t,e){"string"!=typeof t&&(t=(e=t).name);for(var s=this.stateProperties,i=0,n=s.length;i<n;i++){var r=s[i],a=e[r];a&&(this[`${r}_${t}`]=a)}return this}addStates(t){if(Array.isArray(t))for(var e=0,s=t.length;e<s;e++)this.addState(t[e]);else for(var i in t)this.addState(i,t[i]);return this}runMethod(t,e,s,i,n,r){var a=this[t+"_"+this.state];if(a){var o=arguments.length;switch(o){case 1:return a.call(this);case 2:return a.call(this,e);case 3:return a.call(this,e,s);case 4:return a.call(this,e,s,i);case 5:return a.call(this,e,s,i,n);case 6:return a.call(this,e,s,i,n,r)}for(var h=new Array(o-1),u=1;u<o;u++)h[u-1]=arguments[u];return a.apply(this,h)}}};Object.assign(y.prototype,p);var _=function(t,e,s,i,n){void 0===n&&(n=!1);var r=t._events[e];if(!r)return!1;for(var a=0,o=r.length;a<o;a++){var h=r[a];if(h.fn===s&&h.context===i&&h.once===n)return!0}return!1};const E=["next","exit","enter","update","preupdate","postupdate"];class g extends y{shutdown(){this.stopUpdate(),this.stopPreUpdate(),this.stopPostUpdate(),this._scene=void 0,super.shutdown()}resetFromJSON(t){return super.resetFromJSON(t),this._scene=d(t,"scene",void 0),this}get stateProperties(){return E}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 _(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 _(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 _(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}}class O extends g{constructor(t,e){super(e),this.parent=t;var s=e.initState||"IDLE";this.start(s)}init(){this.start("IDLE")}next_IDLE(){return"TRANS_OPNE"}next_TRANS_OPNE(){return"OPEN"}enter_TRANS_OPNE(){var t=this.parent;if(t.transitInTime>0){var e=t.runTransitionInCallback();t.delayCall(e,this.next,this)}else this.next()}exit_TRANS_OPNE(){this.parent.removeDelayCall()}next_OPEN(){return"TRANS_CLOSE"}enter_OPEN(){this.parent.onOpen()}exit_OPEN(){this.parent.removeDelayCall()}next_TRANS_CLOSE(){return"CLOSE"}enter_TRANS_CLOSE(){var t=this.parent;if(t.transitOutTime>0){var e=t.runTransitionOutCallback();t.delayCall(e,this.next,this)}else this.next()}exit_TRANS_CLOSE(){this.parent.removeDelayCall()}next_CLOSE(){return"TRANS_OPNE"}enter_CLOSE(){this.parent.onClose()}exit_CLOSE(){}canOpen(){return"IDLE"===this.state||"CLOSE"===this.state}canClose(){return"IDLE"===this.state||"OPEN"===this.state}}var C={delayCall(t,e,s){return this.delayCallTimer=function(t,e,s,n,r){var a=i(t);return a.time.delayedCall(e,(function(){a.game.events.once("poststep",(function(){s.call(n,r)}))}))}(this,t,e,s),this},removeDelayCall(){return this.delayCallTimer&&(this.delayCallTimer.remove(!1),this.delayCallTimer=void 0),this}},S=function(){},T={setTransitInTime(t){return this.transitInTime=t,this},setTransitOutTime(t){return this.transitOutTime=t,this},setTransitInCallback(t){return t||(t=S),this.transitInCallback=t,this},setTransitOutCallback(t){return t||(t=S),this.transitOutCallback=t,this}},b={runTransitionInCallback(){return this.transitInCallback(this.parent,this.transitInTime),this.transitInTime},onOpen(){},requestOpen(t,e){if(!this._state.canOpen())return this;this.openEventData=arguments.length>0?t:this.parent;var s=this.transitInTime;return void 0!==e&&(this.transitInTime=e),this._state.goto("TRANS_OPNE"),this.transitInTime=s,this}},w={runTransitionOutCallback(){return this.transitOutCallback(this.parent,this.transitOutTime),this.transitOutTime},onClose(){this.oneShotMode&&this.parent.destroy()},requestClose(t,e){if(!this._state.canClose)return this;this.closeEventData=arguments.length>0?t:this.parent;var s=this.transitOutTime;return void 0!==e&&(this.transitOutTime=e),this._state.goto("TRANS_CLOSE"),this.transitOutTime=s,this}},x={};Object.assign(x,C,T,b,w);const k=Phaser.Utils.Objects.GetValue;class P extends o{constructor(t,e){super(t,e),this.setTransitInTime(k(e,"duration.in",200)),this.setTransitOutTime(k(e,"duration.out",200)),this.setTransitInCallback(k(e,"transitIn")),this.setTransitOutCallback(k(e,"transitOut")),this.oneShotMode=k(e,"destroy",!1),this.delayCallTimer=void 0,this._state=new O(this,{eventEmitter:!1,initState:k(e,"initState","IDLE")}),this.openEventData=void 0,this.closeEventData=void 0}get state(){return this._state.state}shutdown(t){this.isShutdown||(this.transitInCallback=void 0,this.transitOutCallback=void 0,this.openEventData=void 0,this.closeEventData=void 0,this.removeDelayCall(),super.shutdown(t))}}Object.assign(P.prototype,x);const D=Phaser.GameObjects.Layer;var L=function(t){var e=t.displayList;return function(t){return t instanceof D}(e)?e:null},N=function(t){if(t.parentContainer)return N(t.parentContainer);var e=L(t);return e?N(e):t};class R extends o{constructor(t,e){super(t),this.targetCamera=void 0,this.boot()}boot(){this.scene.sys.events.on("prerender",this.resize,this)}destroy(){this.scene&&(this.scene.sys.events.off("prerender",this.resize,this),super.destroy())}resize(){var t=this.scene,e=this.parent,s=function(t){for(var e,s=N(t).cameraFilter,i=t.scene.sys.cameras.cameras,n=0,r=i.length;n<r;n++)if(!((s&(e=i[n]).id)>0))return e;return null}(e);if(s){e.setScrollFactor(0).setOrigin(.5);var i=t.sys.scale.gameSize,n=i.width,r=i.height,a=1/s.zoom,o=n/2,h=r/2,u=n*a,l=r*a;e.x===o&&e.y===h||e.setPosition(o,h),e.width===u&&e.height===l||e.setSize(u,l)}}}const A=Phaser.GameObjects.Rectangle;class I extends A{constructor(t,e,s){super(t,0,0,2,2,e,1),this.fullWindow=new R(this),this.setAlpha(s)}get tint(){return this.fillColor}set tint(t){this.setFillStyle(t,this.fillAlpha)}}const j=Phaser.Utils.Objects.GetValue;class M extends o{constructor(t,e){super(t,{eventEmitter:!1}),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.setHitAreaMode(j(t,"hitAreaMode",0)),this.setEnable(j(t,"enable",!0)),this.setStopMode(j(t,"stopAllLevels",!0)),this}boot(){this.parent.on("pointerdown",(function(t,e,s,i){this.stopAllLevels&&i.stopPropagation()}),this).on("pointerup",(function(t,e,s,i){this.stopAllLevels&&i.stopPropagation()}),this).on("pointermove",(function(t,e,s,i){this.stopAllLevels&&i.stopPropagation()}),this).on("pointerover",(function(t,e,s,i){this.stopAllLevels&&i.stopPropagation()}),this).on("pointerout",(function(t,e){this.stopAllLevels&&e.stopPropagation()}),this)}setHitAreaMode(t){"string"==typeof t&&(t=U[t]);var e=this.parent;return e.input&&e.removeInteractive(),0===t?e.setInteractive():e.setInteractive({hitArea:{},hitAreaCallback:function(){return!0}}),this}setEnable(t){return void 0===t&&(t=!0),t?this.parent.setInteractive():this.parent.disableInteractive(),this.enable=t,this}setStopMode(t){return void 0===t&&(t=!0),this.stopAllLevels=t,this}toggleEnable(){return this.setEnable(!this.enable),this}}var U={default:0,fullWindow:1};const F=Phaser.Utils.Objects.GetValue;class X extends I{constructor(t,e){super(t,F(e,"color",0),F(e,"alpha",.8)),this.touchEventStop=new M(this,{hitAreaMode:1})}}const J=Phaser.Utils.Objects.GetValue;class Y extends o{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(J(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=G[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 G={no:0,lazy:1,always:2},V=Phaser.Utils.Objects.GetValue;class B extends Y{constructor(t,e){super(t,e);var s=this.scene?"update":"step";this.tickEventName=V(e,"tickEventName",s),this.isSceneTicker=!q(this.tickEventName)}startTicking(){super.startTicking(),this.isSceneTicker?this.scene.sys.events.on(this.tickEventName,this.update,this):this.game.events.on(this.tickEventName,this.update,this)}stopTicking(){super.stopTicking(),this.isSceneTicker&&this.scene?this.scene.sys.events.off(this.tickEventName,this.update,this):this.game&&this.game.events.off(this.tickEventName,this.update,this)}}var q=function(t){return"step"===t||"poststep"===t};const z=Phaser.Utils.Objects.GetValue,H=Phaser.Math.Clamp;class W{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.state=z(t,"state",$),this.timeScale=z(t,"timeScale",1),this.delay=z(t,"delay",0),this.repeat=z(t,"repeat",0),this.repeatCounter=z(t,"repeatCounter",0),this.repeatDelay=z(t,"repeatDelay",0),this.duration=z(t,"duration",0),this.nowTime=z(t,"nowTime",0),this.justRestart=z(t,"justRestart",!1)}toJSON(){return{state:this.state,timeScale:this.timeScale,delay:this.delay,repeat:this.repeat,repeatCounter:this.repeatCounter,repeatDelay:this.repeatDelay,duration:this.duration,nowTime:this.nowTime,justRestart:this.justRestart}}destroy(){}setTimeScale(t){return this.timeScale=t,this}setDelay(t){return void 0===t&&(t=0),this.delay=t,this}setDuration(t){return this.duration=t,this}setRepeat(t){return this.repeat=t,this}setRepeatInfinity(){return this.repeat=-1,this}setRepeatDelay(t){return this.repeatDelay=t,this}start(){return this.nowTime=this.delay>0?-this.delay:0,this.state=this.nowTime>=0?Q:K,this.repeatCounter=0,this}stop(){return this.state=$,this}update(t,e){this.state!==$&&this.state!==tt&&0!==e&&0!==this.timeScale&&(this.nowTime+=e*this.timeScale,this.justRestart=!1,this.nowTime>=this.duration?-1===this.repeat||this.repeatCounter<this.repeat?(this.repeatCounter++,this.justRestart=!0,this.nowTime-=this.duration,this.repeatDelay>0&&(this.nowTime-=this.repeatDelay,this.state=Z)):(this.nowTime=this.duration,this.state=tt):this.nowTime>=0&&(this.state=Q))}get t(){var t;switch(this.state){case $:case K:case Z:t=0;break;case Q:t=this.nowTime/this.duration;break;case tt:t=1}return H(t,0,1)}set t(t){(t=H(t,-1,1))<0?(this.state=K,this.nowTime=-this.delay*t):(this.state=Q,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++)}setT(t){return this.t=t,this}get isIdle(){return this.state===$}get isDelay(){return this.state===K}get isCountDown(){return this.state===Q}get isRunning(){return this.state===K||this.state===Q}get isDone(){return this.state===tt}get isOddIteration(){return!(1&~this.repeatCounter)}get isEvenIteration(){return!(1&this.repeatCounter)}}const $=0,K=1,Q=2,Z=3,tt=-1;class et extends B{constructor(t,e){super(t,e),this.timer=new W}shutdown(t){this.isShutdown||(super.shutdown(t),this.timer.destroy(),this.timer=void 0)}start(){return this.timer.start(),super.start(),this}stop(){return this.timer.stop(),super.stop(),this}complete(){return this.timer.stop(),super.complete(),this}}const st=Phaser.Utils.Objects.GetValue,it=Phaser.Utils.Objects.GetAdvancedValue,nt=Phaser.Tweens.Builders.GetEaseFunction;class rt extends et{resetFromJSON(t){return this.timer.resetFromJSON(st(t,"timer")),this.setEnable(st(t,"enable",!0)),this.setTarget(st(t,"target",this.parent)),this.setDelay(it(t,"delay",0)),this.setDuration(it(t,"duration",1e3)),this.setEase(st(t,"ease","Linear")),this.setRepeat(st(t,"repeat",0)),this}setEnable(t){return null==t&&(t=!0),this.enable=t,this}setTarget(t){return void 0===t&&(t=this.parent),this.target=t,this}setDelay(t){return this.delay=t,this}setDuration(t){return this.duration=t,this}setRepeat(t){return this.repeat=t,this}setRepeatDelay(t){return this.repeatDelay=t,this}setEase(t){return void 0===t&&(t="Linear"),this.ease=t,this.easeFn=nt(t),this}start(){return this.timer.isRunning||super.start(),this}restart(){return this.timer.stop(),this.start.apply(this,arguments),this}stop(t){return void 0===t&&(t=!1),super.stop(),t&&(this.timer.setT(1),this.updateTarget(this.target,this.timer),this.complete()),this}update(t,e){if(!this.isRunning||!this.enable||this.parent.hasOwnProperty("active")&&!this.parent.active)return this;var s=this.target,i=this.timer;return i.update(t,e),i.isDelay||this.updateTarget(s,i),this.emit("update",s,this),i.isDone&&this.complete(),this}updateTarget(t,e){}}const at=Phaser.Utils.Objects.GetValue,ot=Phaser.Utils.Objects.GetAdvancedValue,ht=Phaser.Math.Linear;class ut extends rt{constructor(t,e){super(t,e),this.scaleStart={},this.scaleEnd={},this.resetFromJSON(e),this.boot()}resetFromJSON(t){return super.resetFromJSON(t),this.setMode(at(t,"mode",0)),this.setScaleRange(ot(t,"start",void 0),ot(t,"end",0)),this}setMode(t){return"string"==typeof t&&(t=lt[t]),this.mode=t,this}setScaleRange(t,e){return"number"==typeof t?(this.startX=t,this.startY=t):(this.startX=ot(t,"x",this.parent.scaleX),this.startY=ot(t,"y",this.parent.scaleY)),"number"==typeof e?(this.endX=e,this.endY=e):(this.endX=ot(e,"x",void 0),this.endY=ot(e,"y",void 0)),this.hasScaleX=void 0!==this.startX&&void 0!==this.endX,this.hasScaleY=void 0!==this.startY&&void 0!==this.endY,this}start(){if(this.timer.isRunning)return this;var t=this.parent;this.hasScaleX&&(t.scaleX=this.startX),this.hasScaleY&&(t.scaleY=this.startY);var e=this.repeat;return 2===this.mode&&-1!==e&&(e=2*(e+1)-1),this.timer.setDelay(this.delay).setDuration(this.duration).setRepeat(e),super.start(),this}updateTarget(t,e){var s=e.t;e.isOddIteration&&(s=1-s),s=this.easeFn(s),this.hasScaleX&&(t.scaleX=ht(this.startX,this.endX,s)),this.hasScaleY&&(t.scaleY=ht(this.startY,this.endY,s))}complete(){return super.complete(),1===this.mode&&this.parent.destroy(),this}}const lt={stop:0,destroy:1,yoyo:2},ct=Phaser.Utils.Objects.GetValue,pt=Phaser.Utils.Objects.GetAdvancedValue,dt=Phaser.Math.Linear;class vt extends rt{constructor(t,e){super(t,e),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return super.resetFromJSON(t),this.setMode(ct(t,"mode",0)),this.setAlphaRange(pt(t,"start",this.parent.alpha),pt(t,"end",0)),this}setMode(t){return"string"==typeof t&&(t=mt[t]),this.mode=t,this}setAlphaRange(t,e){return this.alphaStart=t,this.alphaEnd=e,this}start(){return this.timer.isRunning||(this.parent.setAlpha(this.alphaStart),this.timer.setDelay(this.delay).setDuration(this.duration).setRepeat(2===this.mode?-1:0),super.start()),this}updateTarget(t,e){var s=e.t;e.isOddIteration&&(s=1-s),t.alpha=dt(this.alphaStart,this.alphaEnd,s)}complete(){return super.complete(),1===this.mode&&this.parent.destroy(),this}}const mt={stop:0,destroy:1,yoyo:2},ft=Phaser.Utils.Objects.IsPlainObject;var yt=function(t,e,s,i){var n,r;ft(s)?(n=s.start,r=s.end):r=s,void 0===n&&(n=0),void 0===r&&(r=1);var a={mode:0,start:n,end:r,duration:e};return void 0===i?i=new vt(t,a):i.resetFromJSON(a),i.restart(),i},_t=function(t,e,s,i){s instanceof vt&&(i=s,s=void 0),void 0===s&&(s=!0);var n={mode:s?1:0,end:0,duration:e};return void 0===i?i=new vt(t,n):i.resetFromJSON(n),i.restart(),i},Et={popUp(t,e){void 0!==t._modalScaleSave?(t.scaleX=t._modalScaleSave,t.scaleY=t._modalScaleSave):t._modalScaleSave=t.scaleX,function(t,e,s,i,n){var r,a;switch(void 0===i&&(i="Cubic"),s){case 0:case"x":r={x:0},a={x:t.scaleX};break;case 1:case"y":r={y:0},a={y:t.scaleY};break;default:r=0,a=t.scale}var o={mode:0,start:r,end:a,duration:e,ease:i};void 0===n?n=new ut(t,o):n.resetFromJSON(o),n.restart()}(t,e)},scaleDown(t,e){!function(t,e,s,i,n,r){void 0===i&&(i="Linear"),n instanceof ut&&(r=n,n=void 0),void 0===n&&(n=!0);var a={};switch(a.mode=n?1:0,s){case 0:case"x":a.end={x:0};break;case 1:case"y":a.end={y:0};break;default:a.end=0}a.duration=e,a.ease=i,void 0===r?r=new ut(t,a):r.resetFromJSON(a),r.restart()}(t,e,void 0,void 0,!1)},fadeIn(t,e){void 0!==t._modalAlphaSave?t.alpha=t._modalAlphaSave:t._modalAlphaSave=t.alpha,yt(t,e)},fadeOut(t,e){_t(t,e,!1)}},gt=function(t,e){void 0!==t._modalAlphaSave?t.alpha=t._modalAlphaSave:t._modalAlphaSave=t.alpha,yt(t,e,t.alpha)},Ot=function(t,e){_t(t,e,!1)},Ct=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},St=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height};const Tt=Phaser.Geom.Rectangle,bt=Phaser.Math.Vector2,wt=Phaser.Math.RotateAround,xt=Phaser.GameObjects.Container;var kt=void 0,Pt=function(t,e,s){return void 0===e?e=new bt:!0===e&&(void 0===Rt&&(Rt=new bt),e=Rt),t.getTopLeft?t.getTopLeft(e,s):(e.x=t.x-Ct(t)*t.originX,e.y=t.y-St(t)*t.originY,At(t,e,s))},Dt=function(t,e,s){return void 0===e?e=new bt:!0===e&&(void 0===Rt&&(Rt=new bt),e=Rt),t.getTopRight?t.getTopRight(e,s):(e.x=t.x-Ct(t)*t.originX+Ct(t),e.y=t.y-St(t)*t.originY,At(t,e,s))},Lt=function(t,e,s){return void 0===e?e=new bt:!0===e&&(void 0===Rt&&(Rt=new bt),e=Rt),t.getBottomLeft?t.getBottomLeft(e,s):(e.x=t.x-Ct(t)*t.originX,e.y=t.y-St(t)*t.originY+St(t),At(t,e,s))},Nt=function(t,e,s){return void 0===e?e=new bt:!0===e&&(void 0===Rt&&(Rt=new bt),e=Rt),t.getBottomRight?t.getBottomRight(e,s):(e.x=t.x-Ct(t)*t.originX+Ct(t),e.y=t.y-St(t)*t.originY+St(t),At(t,e,s))},Rt=void 0,At=function(t,e,s){return void 0===s&&(s=!1),0!==t.rotation&&wt(e,t.x,t.y,t.rotation),s&&t.parentContainer&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e),e},It=function(t,e,s,i,n){if(!t)return!1;if(i&&!i(t,e,s))return!1;var r=function(t,e){if(void 0===e?e=new Tt:!0===e&&(void 0===kt&&(kt=new Tt),e=kt),t.getBounds&&!(t instanceof xt))return t.getBounds(e);var s,i,n,r,a,o,h,u;if(t.parentContainer){var l=t.parentContainer.getBoundsTransformMatrix();Pt(t,e),l.transformPoint(e.x,e.y,e),s=e.x,i=e.y,Dt(t,e),l.transformPoint(e.x,e.y,e),n=e.x,r=e.y,Lt(t,e),l.transformPoint(e.x,e.y,e),a=e.x,o=e.y,Nt(t,e),l.transformPoint(e.x,e.y,e),h=e.x,u=e.y}else Pt(t,e),s=e.x,i=e.y,Dt(t,e),n=e.x,r=e.y,Lt(t,e),a=e.x,o=e.y,Nt(t,e),h=e.x,u=e.y;return e.x=Math.min(s,n,a,h),e.y=Math.min(i,r,o,u),e.width=Math.max(s,n,a,h)-e.x,e.height=Math.max(i,r,o,u)-e.y,e}(t,!0);return!(!r.contains(e,s)||n&&!n(t,e,s))};const jt=Phaser.Utils.Objects.GetValue;let Mt=class extends P{constructor(t,e){void 0===e&&(e={}),null==e.transitIn&&(e.transitIn=Ut.popUp),null==e.transitOut&&(e.transitOut=Ut.scaleDown),e.destroy=jt(e,"destroy",!0),super(t,e);var s=jt(e,"cover");this.cover=!1!==s?function(t,e){var s=t.scene,i=new X(s,e);return s.add.existing(i),t.isRexContainerLite?(t.pin(i,{syncPosition:!1,syncRotation:!1,syncScale:!1,syncAlpha:!1,syncScrollFactor:!1}),t.moveDepthBelow(i)):s.children.moveBelow(i,t),i}(t,s):void 0,this.cover&&(this.setCoverTransitInCallback(jt(s,"transitIn",gt)),this.setCoverTransitOutCallback(jt(s,"transitOut",Ot)));var i=jt(e,"touchOutsideClose",!1),n=jt(e,"duration.hold",-1),r=jt(e,"timeOutClose",n>=0),a=jt(e,"anyTouchClose",!1);jt(e,"manualClose",!1)&&(i=!1,a=!1,r=!1),a&&(i=!1),r?this.setDisplayTime(n):this.setDisplayTime(-1),a?this.once("open",this.anyTouchClose,this):i&&this.once("open",this.touchOutsideClose,this),jt(e,"openOnStart",!0)&&this.delayCall(0,this.requestOpen,this)}shutdown(t){this.isShutdown||(this.cover||this.scene.input.off("pointerup",this.touchCloseCallback,this),this.cover&&!t&&(this.cover.destroy(),this.cover=void 0),super.shutdown(t))}touchOutsideClose(){return this.cover?this.cover.on("pointerup",this.touchCloseCallback,this):this.scene.input.on("pointerup",this.touchCloseCallback,this),this.clickOutsideTest=!0,this}anyTouchClose(){return this.cover?this.cover.once("pointerup",this.touchCloseCallback,this):this.scene.input.once("pointerup",this.touchCloseCallback,this),this}touchCloseCallback(t){this.clickOutsideTest&&It(this.parent,t.worldX,t.worldY)||this.requestClose()}runTransitionInCallback(){var t=super.runTransitionInCallback(),e=this.cover;return e&&this.coverTransitInCallback&&this.coverTransitInCallback(e,t),t}runTransitionOutCallback(){var t=super.runTransitionOutCallback(),e=this.cover;return e&&this.coverTransitOutCallback&&this.coverTransitOutCallback(e,t),t}onOpen(){var t=this.displayTime;t>=0&&this.delayCall(t,this.requestClose,this),this.emit("open",this.parent,this),super.onOpen()}onClose(){this.emit("close",this.closeEventData),super.onClose()}setDisplayTime(t){return this.displayTime=t,this}setTransitInCallback(t){switch("string"==typeof t&&(t=Ut[t]),t){case Ut.popUp:t=Et.popUp;break;case Ut.fadeIn:t=Et.fadeIn}return super.setTransitInCallback(t),this}setTransitOutCallback(t){switch("string"==typeof t&&(t=Ut[t]),t){case Ut.scaleDown:t=Et.scaleDown;break;case Ut.fadeOut:t=Et.fadeOut}return super.setTransitOutCallback(t),this}setCoverTransitInCallback(t){return this.coverTransitInCallback=t,this}setCoverTransitOutCallback(t){return this.coverTransitOutCallback=t,this}};const Ut={popUp:0,fadeIn:1,scaleDown:0,fadeOut:1};var Ft=function(t,e){var s=new Mt(t,e);return s.on("open",(function(){t.emit("modal.open",s)})),s.on("close",(function(e){t.emit("modal.close",e,s)})),t.on("modal.requestClose",s.requestClose,s),s};class Xt extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e){return new Mt(t,e)}modal(t,e){return Ft(t,e)}promise(t,e){return function(t,e){var s=Ft(t,e);return new Promise((function(t,e){s.once("close",(function(e){t(e)}))}))}(t,e)}close(t,e){return function(t,e){t.emit("modal.requestClose",e)}(t,e)}}return Xt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexmodalplugin=e();