phaser3-rex-plugins
Version:
7 lines (6 loc) • 7.69 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).rexsequenceplugin=e();}(undefined,(function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(r=n.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(r,"string"))?s:String(s)),n);}var r,s;}function i(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,e){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},r(t,e)}function s(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 function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function o(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,r=n(t);if(e){var o=n(this).constructor;i=Reflect.construct(r,arguments,o);}else i=r.apply(this,arguments);return s(this,i)}}var u={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):[]}},h=function(t,e,i){if(t&&"number"!=typeof t){if(t.hasOwnProperty(e))return t[e];if(-1!==e.indexOf(".")){for(var n=e.split("."),r=t,s=i,o=0;o<n.length;o++){if(!r.hasOwnProperty(n[o])){s=i;break}s=r[n[o]],r=r[n[o]];}return s}return i}return i},a=function(t,e,i,n){void 0===i&&(i=0),void 0===n&&(n=e.length),t.length=n-i;for(var r=0,s=t.length;r<s;r++)t[r]=e[r+i];return t},f=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,c=/^0x[0-9A-F]+$/i,p=function(t){if("string"!=typeof t)return t;if(""===t)t=null;else if(f.test(t))t=parseFloat(t);else if(c.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},l=function t(e,i,n){var r,s,o=h(n,"reverse",!1);if(s=e[0],"[object Array]"===Object.prototype.toString.call(s))if(o)for(u=(a=e.length)-1;u>=0;u--)r=t(e[u],i,n);else for(var u=0,a=e.length;u<a;u++)r=t(e[u],i,n);else r=v(e,i,n);return r},v=function(t,e,i){var n,r=h(i,"argsConvert",void 0),s=h(i,"argsConvertScope",void 0),o=t[0];if(d=a(d,t,1),r){!0===r&&(r=p,s=void 0);for(var u=0,f=d.length;u<f;u++)d[u]=s?r.call(s,d[u],t):r(d[u],t);}return "string"==typeof o?null==(n=e[o])&&(n=h(e,o,null)):n=o,n.apply(e,d)},d=[],m=function(){function e(i){t(this,e),this.setEventEmitter(h(i,"eventEmitter",void 0)),this.commands=[],this.scope=void 0,this.config=void 0,this.index=0,this.indexStep=1,this.setYoyo(h(i,"yoyo",!1)),this.setRepeat(h(i,"repeat",0)),this.setLoop(h(i,"loop",!1)),this.state=0,this.task=void 0;}return i(e,[{key:"shutdown",value:function(){this.stop(),this.destroyEventEmitter(),this.commands.length=0,this.scope=void 0,this.config=void 0;}},{key:"destroy",value:function(){this.shutdown();}},{key:"load",value:function(t,e,i){return this.stop(),this.setYoyo(h(i,"yoyo",this.yoyo)),this.setRepeat(h(i,"repeat",this.repeat)),this.setLoop(h(i,"loop",this.loop)),this.commands=a(this.commands,t),this.scope=e,this.config=i,this}},{key:"start",value:function(){return this.stop(),this.resetRepeatCount(),this.index=0,this.indexStep=1,this.state=1,this.commands.length>0?this.runNextCommands():this.complete(),this}},{key:"stop",value:function(){return this.task&&(this.task.off("complete",this.runNextCommands,this),this.task=void 0),this.state=0,this}},{key:"setYoyo",value:function(t){return void 0===t&&(t=!0),this.yoyo=t,this}},{key:"setRepeat",value:function(t){return this.repeat=t,this.resetRepeatCount(),this}},{key:"setLoop",value:function(t){return void 0===t&&(t=!0),this.loop=t,this.resetRepeatCount(),this}},{key:"resetRepeatCount",value:function(){return this.repeatCount=-1===this.repeat||this.loop?999999999999:this.repeat,this}},{key:"completed",get:function(){return 3===this.state}},{key:"currentCommandIndex",get:function(){return this.index-1}},{key:"runNextCommands",value:function(){for(var t,e,i;;){if(2===this.state)return void this.complete();if((t=l(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}}},{key:"complete",value:function(){this.state=3,this.emit("complete",this.scope,this);}}]),e}();
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/return Object.assign(m.prototype,u),function(e){!function(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&&r(t,e);}(s,Phaser.Plugins.BasePlugin);var n=o(s);function s(e){return t(this,s),n.call(this,e)}return i(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new m(t)}}]),s}()}));