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