UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 5.26 kB
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):[]}},e=function(t,e,s,n){var r=t&&("object"==typeof t||"function"==typeof t),o=n&&("object"==typeof n||"function"==typeof n);if(!r&&!o)return s;var h=String(e);if(r&&h in t)return t[h];if(o&&h in n)return n[h];if(-1===h.indexOf("."))return s;var a=h.split(".");if(r){var p=i(t,a,s);if(p.found)return p.value}if(o){var u=i(n,a,s);if(u.found)return u.value}return s},i=function(t,e,i){for(var n=t,r=i,o=0,h=e.length;o<h;o++){var a=e[o];if(!n||"object"!=typeof n&&"function"!=typeof n||!(a in n))return s.found=!1,s;n=r=n[a]}return s.found=!0,s.value=r,s},s={},n=function(t,e,i,s){void 0===i&&(i=0),void 0===s&&(s=e.length),t.length=s-i;for(var n=0,r=t.length;n<r;n++)t[n]=e[n+i];return t},r=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,o=/^0x[0-9A-F]+$/i,h=function(t){if("string"!=typeof t)return t;if(""===t)t=null;else if(r.test(t))t=parseFloat(t);else if(o.test(t))t=parseInt(t,16);else switch(t){case"false":t=!1;break;case"true":t=!0;break;case"null":t=null;break;case"undefined":t=void 0}return t},a=function(t,i,s){var n,r,o=e(s,"reverse",!1);if(r=t[0],"[object Array]"===Object.prototype.toString.call(r))if(o)for(h=(u=t.length)-1;h>=0;h--)n=a(t[h],i,s);else for(var h=0,u=t.length;h<u;h++)n=a(t[h],i,s);else n=p(t,i,s);return n},p=function(t,i,s){var r,o=e(s,"argsConvert",void 0),a=e(s,"argsConvertScope",void 0),p=t[0];if(u=n(u,t,1),o){!0===o&&(o=h,a=void 0);for(var v=0,d=u.length;v<d;v++)u[v]=a?o.call(a,u[v],t):o(u[v],t)}return"string"==typeof p?null==(r=i[p])&&(r=e(i,p,null)):r=p,r.apply(i,u)},u=[];class v{constructor(t){this.setEventEmitter(e(t,"eventEmitter",void 0)),this.commands=[],this.scope=void 0,this.config=void 0,this.index=0,this.indexStep=1,this.setYoyo(e(t,"yoyo",!1)),this.setRepeat(e(t,"repeat",0)),this.setLoop(e(t,"loop",!1)),this.state=0,this.task=void 0}shutdown(){this.stop(),this.destroyEventEmitter(),this.commands.length=0,this.scope=void 0,this.config=void 0}destroy(){this.shutdown()}load(t,i,s){return this.stop(),this.setYoyo(e(s,"yoyo",this.yoyo)),this.setRepeat(e(s,"repeat",this.repeat)),this.setLoop(e(s,"loop",this.loop)),this.commands=n(this.commands,t),this.scope=i,this.config=s,this}start(){return this.stop(),this.resetRepeatCount(),this.index=0,this.indexStep=1,this.state=1,this.commands.length>0?this.runNextCommands():this.complete(),this}stop(){return this.task&&(this.task.off("complete",this.runNextCommands,this),this.task=void 0),this.state=0,this}setYoyo(t){return void 0===t&&(t=!0),this.yoyo=t,this}setRepeat(t){return this.repeat=t,this.resetRepeatCount(),this}setLoop(t){return void 0===t&&(t=!0),this.loop=t,this.resetRepeatCount(),this}resetRepeatCount(){return this.repeatCount=-1===this.repeat||this.loop?999999999999:this.repeat,this}get completed(){return 3===this.state}get currentCommandIndex(){return this.index-1}runNextCommands(){for(var t,e,i;;){if(2===this.state)return void this.complete();if((t=a(this.commands[this.index],this.scope))&&"function"==typeof t.once?(t.once("complete",this.runNextCommands,this),this.task=t):this.task=void 0,e=0===this.index,i=this.index===this.commands.length-1,this.yoyo?this.indexStep>0&&i||this.indexStep<0&&e?(this.indexStep=-this.indexStep,this.index+=this.indexStep,this.repeatCount>0?this.repeatCount--:this.state=2):this.index+=this.indexStep:i?(this.index=0,this.repeatCount>0?this.repeatCount--:this.state=2):this.index+=this.indexStep,this.task)return this}}complete(){this.state=3,this.emit("complete",this.scope,this)}}Object.assign(v.prototype,t);class d extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t){return new v(t)}}return d},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexsequenceplugin=e();