@petkoneo/phaser3-rex-plugins
Version:
2 lines (1 loc) • 35 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};const i=Phaser.Game;var r=function(t){return t instanceof i};const n=Phaser.Utils.Objects.GetValue;class h{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(n(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:s(e)?e:e.scene&&s(e.scene)?e.scene:e.parent&&e.parent.scene&&s(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:r(t)?t:r(t.game)?t.game:s(t)?t.sys.game:s(t.scene)?t.scene.sys.game:void 0}(t),this}}function a(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}Object.assign(h.prototype,t);var o={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,s="~";function i(){}function r(t,e,s){this.fn=t,this.context=e,this.once=s||!1}function n(t,e,i,n,h){if("function"!=typeof i)throw new TypeError("The listener must be a function");var a=new r(i,n||t,h),o=s?s+e:e;return t._events[o]?t._events[o].fn?t._events[o]=[t._events[o],a]:t._events[o].push(a):(t._events[o]=a,t._eventsCount++),t}function h(t,e){0==--t._eventsCount?t._events=new i:delete t._events[e]}function a(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(s=!1)),a.prototype.eventNames=function(){var t,i,r=[];if(0===this._eventsCount)return r;for(i in t=this._events)e.call(t,i)&&r.push(s?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},a.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 r=0,n=i.length,h=new Array(n);r<n;r++)h[r]=i[r].fn;return h},a.prototype.listenerCount=function(t){var e=s?s+t:t,i=this._events[e];return i?i.fn?1:i.length:0},a.prototype.emit=function(t,e,i,r,n,h){var a=s?s+t:t;if(!this._events[a])return!1;var o,l,c=this._events[a],d=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),d){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,i),!0;case 4:return c.fn.call(c.context,e,i,r),!0;case 5:return c.fn.call(c.context,e,i,r,n),!0;case 6:return c.fn.call(c.context,e,i,r,n,h),!0}for(l=1,o=new Array(d-1);l<d;l++)o[l-1]=arguments[l];c.fn.apply(c.context,o)}else{var u,p=c.length;for(l=0;l<p;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),d){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,e);break;case 3:c[l].fn.call(c[l].context,e,i);break;case 4:c[l].fn.call(c[l].context,e,i,r);break;default:if(!o)for(u=1,o=new Array(d-1);u<d;u++)o[u-1]=arguments[u];c[l].fn.apply(c[l].context,o)}}return!0},a.prototype.on=function(t,e,s){return n(this,t,e,s,!1)},a.prototype.once=function(t,e,s){return n(this,t,e,s,!0)},a.prototype.removeListener=function(t,e,i,r){var n=s?s+t:t;if(!this._events[n])return this;if(!e)return h(this,n),this;var a=this._events[n];if(a.fn)a.fn!==e||r&&!a.once||i&&a.context!==i||h(this,n);else{for(var o=0,l=[],c=a.length;o<c;o++)(a[o].fn!==e||r&&!a[o].once||i&&a[o].context!==i)&&l.push(a[o]);l.length?this._events[n]=1===l.length?l[0]:l:h(this,n)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=s?s+t:t,this._events[e]&&h(this,e)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=s,a.EventEmitter=a,t.exports=a}(o);var l=a(o.exports);class c extends l{shutdown(){this.removeAllListeners()}destroy(){this.removeAllListeners()}}var d={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):[]}},u=function(t,e,s){if(!t||"number"==typeof t)return s;if("string"==typeof e){if(t.hasOwnProperty(e))return t[e];if(-1===e.indexOf("."))return s;e=e.split(".")}for(var i=e,r=t,n=s,h=0;h<i.length;h++){if(e=i[h],!r.hasOwnProperty(e)){n=s;break}r=n=r[e]}return n};const p=["next","exit","enter"];let v=class{constructor(t){var e=u(t,"states",void 0);e&&this.addStates(e);var s=u(t,"extend",void 0);if(s)for(var i in s)this.hasOwnProperty(i)&&void 0!==this[i]||(this[i]=s[i]);var r=u(t,"eventEmitter",void 0),n=u(t,"EventEmitterClass",void 0);this.setEventEmitter(r,n),this._stateLock=!1,this.resetFromJSON(t)}shutdown(){this.destroyEventEmitter()}destroy(){this.shutdown()}resetFromJSON(t){this.setEnable(u(t,"enable",!0)),this.start(u(t,"start",void 0));var e=u(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,r=this[i];r&&r.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 p}addState(t,e){"string"!=typeof t&&(t=(e=t).name);for(var s=this.stateProperties,i=0,r=s.length;i<r;i++){var n=s[i],h=e[n];h&&(this[`${n}_${t}`]=h)}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,r,n){var h=this[t+"_"+this.state];if(h){var a=arguments.length;switch(a){case 1:return h.call(this);case 2:return h.call(this,e);case 3:return h.call(this,e,s);case 4:return h.call(this,e,s,i);case 5:return h.call(this,e,s,i,r);case 6:return h.call(this,e,s,i,r,n)}for(var o=new Array(a-1),l=1;l<a;l++)o[l-1]=arguments[l];return h.apply(this,o)}}};Object.assign(v.prototype,d);var m=function(t,e,s,i,r){void 0===r&&(r=!1);var n=t._events[e];if(!n)return!1;for(var h=0,a=n.length;h<a;h++){var o=n[h];if(o.fn===s&&o.context===i&&o.once===r)return!0}return!1};const b=["next","exit","enter","update","preupdate","postupdate"];class y extends v{shutdown(){this.stopUpdate(),this.stopPreUpdate(),this.stopPostUpdate(),this._scene=void 0,super.shutdown()}resetFromJSON(t){return super.resetFromJSON(t),this._scene=u(t,"scene",void 0),this}get stateProperties(){return b}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 m(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 m(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 m(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 f extends y{constructor(t,e){super(e),this.bejeweled=t,this.board=t.board,this.waitEvents=t.waitEvents}shutdown(){super.shutdown(),this.bejeweled=void 0,this.board=void 0,this.waitEvents=void 0}destroy(){return this.shutdown(),this}next(){this.waitEvents.noWaitEvent?super.next():this.waitEvents.setCompleteCallback(this.next,this)}}const E=Phaser.Utils.Objects.GetValue;class w extends h{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(E(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},_=Phaser.Utils.Objects.GetValue;class S extends w{constructor(t,e){super(t,e);var s=this.scene?"update":"step";this.tickEventName=_(e,"tickEventName",s),this.isSceneTicker=!T(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 T=function(t){return"step"===t||"poststep"===t};const C=Phaser.Utils.Objects.GetValue,A=Phaser.Math.Clamp;class x{constructor(t){this.resetFromJSON(t)}resetFromJSON(t){this.state=C(t,"state",k),this.timeScale=C(t,"timeScale",1),this.delay=C(t,"delay",0),this.repeat=C(t,"repeat",0),this.repeatCounter=C(t,"repeatCounter",0),this.repeatDelay=C(t,"repeatDelay",0),this.duration=C(t,"duration",0),this.nowTime=C(t,"nowTime",0),this.justRestart=C(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?L:j,this.repeatCounter=0,this}stop(){return this.state=k,this}update(t,e){this.state!==k&&this.state!==R&&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=M)):(this.nowTime=this.duration,this.state=R):this.nowTime>=0&&(this.state=L))}get t(){var t;switch(this.state){case k:case j:case M:t=0;break;case L:t=this.nowTime/this.duration;break;case R:t=1}return A(t,0,1)}set t(t){(t=A(t,-1,1))<0?(this.state=j,this.nowTime=-this.delay*t):(this.state=L,this.nowTime=this.duration*t,1===t&&0!==this.repeat&&this.repeatCounter++)}setT(t){return this.t=t,this}get isIdle(){return this.state===k}get isDelay(){return this.state===j}get isCountDown(){return this.state===L}get isRunning(){return this.state===j||this.state===L}get isDone(){return this.state===R}get isOddIteration(){return!(1&~this.repeatCounter)}get isEvenIteration(){return!(1&this.repeatCounter)}}const k=0,j=1,L=2,M=3,R=-1;class O extends S{constructor(t,e){super(t,e),this.timer=new x}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 P=Phaser.Utils.Objects.GetValue,D=Phaser.Utils.Objects.GetAdvancedValue,N=Phaser.Tweens.Builders.GetEaseFunction;class X extends O{resetFromJSON(t){return this.timer.resetFromJSON(P(t,"timer")),this.setEnable(P(t,"enable",!0)),this.setTarget(P(t,"target",this.parent)),this.setDelay(D(t,"delay",0)),this.setDuration(D(t,"duration",1e3)),this.setEase(P(t,"ease","Linear")),this.setRepeat(P(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=N(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 Y=Phaser.Utils.Objects.GetValue,G=Phaser.Utils.Objects.GetAdvancedValue,I=Phaser.Math.Linear;class U extends X{constructor(t,e){super(t,e),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return super.resetFromJSON(t),this.setMode(Y(t,"mode",0)),this.setAlphaRange(G(t,"start",this.parent.alpha),G(t,"end",0)),this}setMode(t){return"string"==typeof t&&(t=Z[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=I(this.alphaStart,this.alphaEnd,s)}complete(){return super.complete(),1===this.mode&&this.parent.destroy(),this}}const Z={stop:0,destroy:1,yoyo:2};var F=function(t,e,s,i){s instanceof U&&(i=s,s=void 0),void 0===s&&(s=!0);var r={mode:s?1:0,end:0,duration:e};return void 0===i?i=new U(t,r):i.resetFromJSON(r),i.restart(),i},B=function(t,e,s){for(var i=0,r=t.length;i<r;i++){var n=F(t[i],500);s.waitEvent(n,"complete")}},J=function(t,e){for(var s,i,r=e.getChessTileZ(),n=t.height-1;n>=0;n--)for(var h=0,a=t.width;h<a;h++)if(null!==(s=t.tileXYZToChess(h,n,r))){i=e.getChessMoveTo(s);do{i.moveToward(1)}while(i.lastMoveResult);i.isRunning&&e.waitEvent(i,"complete")}},V=function(t){return t&&"function"==typeof t.then};const W=Phaser.Utils.Objects.GetValue,H=Phaser.Structs.Set;let z=class extends f{constructor(t,e){super(t,e),this.totalMatchedLinesCount=0,this.eliminatedChessArray,this.eliminatingAction=W(e,"eliminatingAction",B),this.fallingAction=W(e,"fallingAction",J),W(e,"debug",!1)&&this.on("statechange",this.printState,this)}shutdown(){return super.shutdown(),this.eliminatedChessArray=void 0,this.eliminatingAction=void 0,this.fallingAction=void 0,this}destroy(){return this.shutdown(),this}enter_START(){this.totalMatchedLinesCount=0,this.bejeweled.emit("match-start",this.board.board,this.bejeweled),this.next()}next_START(){return"MATCH3"}enter_MATCH3(){var t=this.board.getAllMatch();this.bejeweled.emit("match",t,this.board.board,this.bejeweled);var e=t.length;switch(this.totalMatchedLinesCount+=e,e){case 0:this.eliminatedChessArray=[];break;case 1:this.eliminatedChessArray=t[0].entries;break;default:for(var s=new H,i=0;i<e;i++)t[i].entries.forEach((function(t){s.set(t)}));this.eliminatedChessArray=s.entries}this.next()}next_MATCH3(){return 0===this.eliminatedChessArray.length?"END":"ELIMINATING"}enter_ELIMINATING(){var t=this.board.board,e=this.bejeweled,s=this.eliminatedChessArray;this.bejeweled.emit("eliminate",s,t,e);var i=this.eliminatingAction(s,t,e);V(i)&&(e.waitEvent(e,"eliminate.complete"),i.then((function(){e.emit("eliminate.complete")}))),s.forEach(t.removeChess,t),this.next()}next_ELIMINATING(){return"FALLING"}exit_ELIMINATING(){this.eliminatedChessArray=void 0}enter_FALLING(){var t=this.board.board,e=this.bejeweled;this.bejeweled.emit("fall",t,e);var s=this.fallingAction(t,e);V(s)&&(e.waitEvent(e,"fall.complete"),s.then((function(){e.emit("fall.complete")}))),this.next()}next_FALLING(){return"FILL"}enter_FILL(){this.board.fill(!0),this.bejeweled.emit("fill",this.board.board,this.bejeweled),this.next()}next_FILL(){return"MATCH3"}enter_END(){this.bejeweled.emit("match-end",this.board.board,this.bejeweled),this.emit("complete")}printState(){console.log("Match state: "+this.prevState+" -> "+this.state)}};const $=Phaser.Utils.Objects.GetValue,q=Phaser.Utils.Objects.GetAdvancedValue,K=Phaser.Math.Linear;class Q extends X{constructor(t,e){super(t,e),this.scaleStart={},this.scaleEnd={},this.resetFromJSON(e),this.boot()}resetFromJSON(t){return super.resetFromJSON(t),this.setMode($(t,"mode",0)),this.setScaleRange(q(t,"start",void 0),q(t,"end",0)),this}setMode(t){return"string"==typeof t&&(t=tt[t]),this.mode=t,this}setScaleRange(t,e){return"number"==typeof t?(this.startX=t,this.startY=t):(this.startX=q(t,"x",this.parent.scaleX),this.startY=q(t,"y",this.parent.scaleY)),"number"==typeof e?(this.endX=e,this.endY=e):(this.endX=q(e,"x",void 0),this.endY=q(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=K(this.startX,this.endX,s)),this.hasScaleY&&(t.scaleY=K(this.startY,this.endY,s))}complete(){return super.complete(),1===this.mode&&this.parent.destroy(),this}}const tt={stop:0,destroy:1,yoyo:2};var et=function(t,e,s,i,r){var n,h;switch(void 0===i&&(i="Cubic"),s){case 0:case"x":n={x:0},h={x:t.scaleX};break;case 1:case"y":n={y:0},h={y:t.scaleY};break;default:n=0,h=t.scale}var a={mode:0,start:n,end:h,duration:e,ease:i};return void 0===r?r=new Q(t,a):r.resetFromJSON(a),r.restart(),r},st=function(t,e,s){for(var i=0,r=t.length;i<r;i++){var n=et(t[i],500);s.waitEvent(n,"complete")}},it=function(t,e,s){},rt=function(t,e,s,i){var r=s.chessToTileXYZ(t),n=s.chessToTileXYZ(e),h=r.x,a=r.y,o=n.x,l=n.y,c=r.z;s.setChessTileZ(e,`#${c}`);var d=i.getChessMoveTo(t),u=i.getChessMoveTo(e);d.moveTo(o,l),u.moveTo(h,a),s.setChessTileZ(e,c),d.isRunning&&i.waitEvent(d,"complete"),u.isRunning&&i.waitEvent(u,"complete")};const nt=Phaser.Utils.Objects.GetValue;class ht extends f{constructor(t,e){super(t,e),this.selectedChess1,this.selectedChess2,this.matchState=new z(t,e),this.placeAction=nt(e,"placeAction",st),this.select1Action=nt(e,"select1Action",it),this.select2Action=nt(e,"select2Action",this.select1Action),this.swapAction=nt(e,"swapAction",rt),this.undoSwapAction=nt(e,"undoSwapAction",this.swapAction),nt(e,"debug",!1)&&this.on("statechange",this.printState,this)}shutdown(){return super.shutdown(),this.matchState.shutdown(),this.matchState=void 0,this.selectedChess1=void 0,this.selectedChess2=void 0,this}enter_START(){this.board.init(),this.next()}next_START(){return"RESET"}enter_RESET(){for(var t=this.board,e=!1;!e;)t.reset(),e=t.preTest();this.next()}next_RESET(){return"PLACE"}enter_PLACE(){var t=this.board.board,e=this.bejeweled;e.emit("place",t,e);var s=this.board.getChessArray("lower"),i=this.placeAction(s,t,e);V(i)&&(e.waitEvent(e,"place.complete"),i.then((function(){e.emit("place.complete")}))),this.next()}next_PLACE(){return"SELECT1START"}enter_SELECT1START(){this.selectedChess1=void 0,this.selectedChess2=void 0,this.bejeweled.emit("select1-start",this.board.board,this.bejeweled)}selectChess1(t){return"SELECT1START"===this.state&&(this.selectedChess1=t,this.next()),this}next_SELECT1START(){var t;return this.selectedChess1&&(t="SELECT1"),t}enter_SELECT1(){var t=this.board.board,e=this.bejeweled,s=this.selectedChess1;this.bejeweled.emit("select1",s,t,e);var i=this.select1Action(s,t,e);V(i)&&(e.waitEvent(e,"select1.complete"),i.then((function(){e.emit("select1.complete")}))),this.next()}next_SELECT1(){return"SELECT2START"}enter_SELECT2START(){this.bejeweled.emit("select2-start",this.board.board,this.bejeweled)}selectChess2(t){return"SELECT2START"===this.state&&(this.selectedChess2=t,this.next()),this}next_SELECT2START(){return this.selectedChess2&&this.board.board.areNeighbors(this.selectedChess1,this.selectedChess2)?"SELECT2":"SELECT1START"}enter_SELECT2(){var t=this.board.board,e=this.bejeweled,s=this.selectedChess2;this.bejeweled.emit("select2",s,t,e);var i=this.select2Action(s,t,e);V(i)&&(e.waitEvent(e,"select2.complete"),i.then((function(){e.emit("select2.complete")}))),this.next()}next_SELECT2(){return"SWAP"}enter_SWAP(){var t=this.board.board,e=this.bejeweled,s=this.selectedChess1,i=this.selectedChess2;this.bejeweled.emit("swap",s,i,t,e);var r=this.swapAction(s,i,t,e);V(r)&&(e.waitEvent(e,"swap.complete"),r.then((function(){e.emit("swap.complete")}))),this.next()}next_SWAP(){return"MATCH3"}enter_MATCH3(){this.matchState.once("complete",this.next,this).goto("START")}next_MATCH3(){return 0===this.matchState.totalMatchedLinesCount?"UNDOSWAP":this.board.preTest()?"SELECT1START":"RESET"}enter_UNDOSWAP(){var t=this.board.board,e=this.bejeweled,s=this.selectedChess1,i=this.selectedChess2;this.bejeweled.emit("undo-swap",s,i,t,e);var r=this.undoSwapAction(s,i,t,e);V(r)&&(e.waitEvent(e,"undo-swap.complete"),r.then((function(){e.emit("undo-swap.complete")}))),this.next()}next_UNDOSWAP(){return"SELECT1START"}printState(){console.log("Main state: "+this.prevState+" -> "+this.state)}}const at=Phaser.Utils.Array.GetRandom;var ot=function(t,e,s,i,r,n){var h;if(Array.isArray(i)){var a=i;if(void 0!==n){for(var o=0,l=a.length;o<l;o++)h=a[o],-1===n.indexOf(h)&<.push(h);h=at(lt),lt.length=0}else h=at(a)}else h="function"==typeof obj?r?i.call(r,t,e,s,n):i(t,e,s,n):i;return h},lt=[],ct=function(){var t=this.chessTileZ;this.match.refreshSymbols((function(e,s){if(e.y<s.height/2)return null;var i=s.tileXYZToChess(e.x,e.y,t);return null==i?null:i.getData("symbol")}))},dt=function(t,e,s){return this.match.match(t,e,s),this};const ut=Phaser.Utils.Array.GetRandom;var pt=function(t){return this.match.anyMatch(t)},vt=function(t,e,s){var i=t.getSymbol(e.x,e.y),r=t.getSymbol(s.x,s.y);t.setSymbol(e.x,e.y,r),t.setSymbol(s.x,s.y,i)},mt={x:0,y:0};const bt=Phaser.Structs.Set;var yt=function(t,e){for(var s=t.entries,i=0,r=s.length;i<r;i++)if(!e.contains(s[i]))return!1;return!0},ft={init:function(){return this},reset:function(){this.board.removeAllChess(!0);var t=this.initSymbols;this.initSymbols=void 0,this.fill(t),this.breakMatch3()},createChess:function(t,e,s){this.scene;var i,r=this.board,n=this.chessCallbackScope,h=Array.isArray(s)?ot(r,t,e,s,n):s;(i=n?this.chessCreateCallback.call(n,r):this.chessCreateCallback(r)).setData("symbol",h),r.addChess(i,t,e,this.chessTileZ,!0),i.rexMoveTo=this.rexBoard.add.moveTo(i,this.chessMoveTo),this.layer&&this.layer.add(i)},fill:function(t){var e=!1;"boolean"==typeof t&&(e=t,t=void 0);var s=void 0!==t,i=this.board,r=i.height,n=this.chessTileZ;e&&(r/=2);for(var h=0;h<r;h++)for(var a=0,o=i.width;a<o;a++)if(!i.contains(a,h,n)){var l=this.candidateSymbols;if(s){var c=t[h][a];"?"!==c&&(l=c)}this.createChess(a,h,l)}},breakMatch3:function(){var t=this.chessTileZ,e=this.chessCallbackScope,s=this.candidateSymbols;ct.call(this),dt.call(this,3,(function(i,r){for(var n=ut(i.tileXY),h=r.tileXYZToChess(n.x,n.y,t),a=r.getNeighborChess(h,null),o=[],l=0,c=a.length;l<c;l++)o.push(a[l].getData("symbol"));var d=ot(r,n.x,n.y,s,e,o);null!=d&&h.setData("symbol",d)}))},preTest:function(){var t,e=this.match,s=this.board.grid.halfDirections;ct.call(this);for(var i=this.board.height/2,r=this.board.height;i<r;i++)for(var n=0,h=this.board.width;n<h;n++){mt.x=n,mt.y=i;for(var a=0,o=s.length;a<o;a++)if(t=this.board.getNeighborTileXY(mt,a),vt(e,mt,t),this.preTestResult=pt.call(this,3),vt(e,mt,t),this.preTestResult)return!0}return!1},getAllMatch:function(){ct.call(this);for(var t=this,e=[],s=5;s>=3;s--)dt.call(this,s,(function(s,i){for(var r=new bt(i.tileXYArrayToChessArray(s.tileXY,t.chessTileZ)),n=0,h=e.length;n<h;n++)if(yt(e[n],r))return;e.push(r)}));return e},getChessArray:function(t){t=t.toLowerCase();var e,s,i=this.board,r=i.height;switch(t){case"upper":e=0,s=r/2;break;case"lower":e=r/2,s=r;break;default:e=0,s=r}for(var n=this.chessTileZ,h=[],a=e;a<s;a++)for(var o=0,l=i.width;o<l;o++){var c=i.tileXYZToChess(o,a,n);null!==c&&h.push(c)}return h},dumpSymbols:function(){for(var t=this.board,e=this.chessTileZ,s=[],i=0,r=t.height;i<r;i++){var n=[];s.push(n);for(var h=0,a=t.width;h<a;h++){var o=t.tileXYZToChess(h,i,e),l=null==o?null:o.getData("symbol");n.push(l)}}return s}};const Et=Phaser.Utils.Objects.GetValue;class wt{constructor(t,e){var s=t.scene;this.scene=s,this.rexBoard=t.rexBoard,this.board=this.rexBoard.add.board(Et(e,"board",void 0)),this.match=this.rexBoard.add.match(Et(e,"match",void 0)),this.match.setBoard(this.board),this.initSymbols=Et(e,"initSymbols",void 0),this.chessTileZ=Et(e,"chess.tileZ",1),this.candidateSymbols=Et(e,"chess.symbols",void 0),this.chessCallbackScope=Et(e,"chess.scope",void 0),this.chessCreateCallback=Et(e,"chess.create",void 0),this.chessMoveTo=Et(e,"chess.moveTo",{}),this.chessMoveTo.occupiedTest=!0,this.rowMaskGameObject=void 0,this.rowMask=void 0,this.layer=void 0,Et(e,"mask",!1)&&this.resetBoardMask(),Et(e,"layer",!1)&&this.enableBoardLayer()}shutdown(){return this.match.destroy(),this.board.destroy(),this.rowMaskGameObject&&(this.layer.setMask(),this.rowMaskGameObject.destroy(),this.rowMask.destroy()),this.layer&&this.layer.destroy(),this.board=void 0,this.match=void 0,this.initSymbols=void 0,this.candidateSymbols=void 0,this.chessCallbackScope=void 0,this.chessCreateCallback=void 0,this.chessMoveTo=void 0,this}destroy(){return this.shutdown(),this}setBoardWidth(t){return this.board.setBoardWidth(t),this}setBoardHeight(t){return this.board.setBoardHeight(t),this}setInitSymbols(t){return this.initSymbols=t,this}enableBoardLayer(){return this.layer||(this.layer=this.scene.add.layer()),this}resetBoardMask(){this.rowMaskGameObject||(this.rowMaskGameObject=this.scene.make.graphics().setVisible(!1),this.rowMask=this.rowMaskGameObject.createGeometryMask().setInvertAlpha(),this.enableBoardLayer(),this.layer.setMask(this.rowMask));var t=this.board,e=t.grid,s=e.x-e.width/2,i=e.y-e.height/2,r=t.width*e.width,n=t.height/2*e.height;return this.rowMaskGameObject.fillRect(s,i,r,n),this}worldXYToChess(t,e){return this.board.worldXYToChess(t,e,this.chessTileZ)}tileXYToChess(t,e){return this.board.tileXYZToChess(t,e,this.chessTileZ)}getNeighborChessAtAngle(t,e){var s=this.board.angleSnapToDirection(t,e);return this.getNeighborChessAtDirection(t,s)}getNeighborChessAtDirection(t,e){var s=this.board.getNeighborTileXY(t,e);return s?this.board.tileXYZToChess(s.x,s.y,this.chessTileZ):null}}Object.assign(wt.prototype,ft);const gt=Phaser.Utils.Objects.GetValue;class _t{constructor(t,e){this.bejeweled=t,this.scene=t.scene,this.setEnable(gt(e,"input.enable",!0)),this.boot()}boot(){this.scene.input.on("pointerdown",this.selectChess1,this).on("pointermove",this.selectChess2,this)}shutdown(){this.scene.input.off("pointerdown",this.selectChess1,this).off("pointermove",this.selectChess2,this),this.bejeweled=void 0,this.scene=void 0}destroy(){return this.shutdown(),this}setEnable(t){return void 0===t&&(t=!0),this.enable=t,this}selectChess1(t){if(!this.enable)return this;var e=this.bejeweled.worldXYToChess(t.worldX,t.worldY);e&&this.bejeweled.selectChess1(e)}selectChess2(t){if(!this.enable)return this;if(t.isDown){var e=this.bejeweled.worldXYToChess(t.worldX,t.worldY);e&&e!==this.bejeweled.getSelectedChess1()&&this.bejeweled.selectChess2(e)}}}const St=Phaser.Structs.Set;class Tt{constructor(t,e){this.setCompleteCallback(t,e),this.events=new St}shutdown(){return this.setCompleteCallback(void 0,void 0),this.events.clear(),this.event=void 0,this}destroy(){return this.shutdown(),this}setCompleteCallback(t,e){return this.completeCallback=t,this.scope=e,this}waitCallback(){var t=this,e=function(){t.remove(e)};return this.events.set(e),e}waitEvent(t,e){return t.once(e,this.waitCallback()),this}remove(t){return this.events.delete(t),this.noWaitEvent&&(this.scope?this.completeCallback.call(this.scope):this.completeCallback()),this}clear(){return this.events.clear(),this}get noWaitEvent(){return 0===this.events.size}}var Ct={getSelectedChess1(){return this.mainState.selectedChess1},getSelectedChess2(){return this.mainState.selectedChess2},selectChess1(t){return this.mainState.selectChess1(t),this},selectChess2(t){return this.mainState.selectChess2(t),this},setInputEnable(t){return this.input&&this.input.setEnable(t),this}},At={setBoardSize(t,e){return this.board.setBoardWidth(t).setBoardHeight(e),this},getChessMoveTo:t=>t?t.rexMoveTo:void 0,getChessTileZ(){return this.board.chessTileZ},worldXYToChess(t,e){return this.board.worldXYToChess(t,e)},tileXYToChess(t,e){return this.board.tileXYToChess(t,e)},getNeighborChessAtAngle(t,e){return this.board.getNeighborChessAtAngle(t,e)},getNeighborChessAtDirection(t,e){return this.board.getNeighborChessAtDirection(t,e)},isAwaitingInput(){return"SELECT1START"===this.mainState.state},dumpSymbols(){return this.board.dumpSymbols()},loadSymbols(t){return this.board.setInitSymbols(t),this.mainState.goto("RESET"),this},getBoard(){return this.board.board},getMatch(){return this.board.match}},xt={waitEvent(t,e){return void 0===e&&(e="complete"),this.waitEvents.waitEvent(t,e),this},waitCallback(){return this.waitEvents.waitCallback()},isWaitingEvent(){return!this.waitEvents.noWaitEvent}};const kt=Phaser.Data.DataManager;var jt={destroyDataManager(){this.data&&(this.data.destroy(),this.data=void 0)},setDataEnabled(){return this.data||(this.data=new kt(this)),this},setData(t,e){return this.data||(this.data=new kt(this)),this.data.set(t,e),this},incData(t,e){return this.data||(this.data=new kt(this)),this.data.inc(t,e),this},toggleData(t){return this.data||(this.data=new kt(this)),this.data.toggle(t),this},getData(t){return this.data||(this.data=new kt(this)),this.data.get(t)}};const Lt=Phaser.Utils.Objects.GetValue;class Mt extends h{constructor(t,e){super(t,e);var s=Lt(e,"rexBoard","rexBoard");this.rexBoard=t[s],this.board=new wt(this,e);var i=Lt(e,"input",!0);this.input=i?new _t(this,e):void 0,this.waitEvents=new Tt,this.mainState=new ht(this,e),this.boot()}boot(){this.scene.events.once("shutdown",this.destroy,this)}shutdown(t){return super.shutdown(t),this.input&&this.input.destroy(),this.board.destroy(),this.mainState.destroy(),this.waitEvents.destroy(),this.destroyDataManager(),this.board=void 0,this.mainState=void 0,this.input=void 0,this.waitEvents=void 0,this}destroy(t){return this.emit("destroy"),super.destroy(t),this}start(){return this.mainState.goto("START"),this}}return Object.assign(Mt.prototype,Ct,At,xt,jt),Mt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexbejeweled=e();