phaser3-rex-plugins
Version:
2 lines (1 loc) • 16.9 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).rexarcadetcrpplugin=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 n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(s=n.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 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)}(s,"string"))?r:String(r)),n);}var s,r;}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function s(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&&o(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function u(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(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,n=r(t);if(e){var s=r(this).constructor;i=Reflect.construct(n,arguments,s);}else i=n.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 u(t)}(this,i)}}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=r(t)););return t}(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(arguments.length<3?t:i):s.value}},h.apply(this,arguments)}var a={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,f=function(t){return t instanceof l},d=Phaser.Game,p=function(t){return t instanceof d},v=Phaser.Utils.Objects.GetValue,m=function(){function i(t,n){e(this,i),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(v(n,"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 n(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:f(i)?i:i.scene&&f(i.scene)?i.scene:i.parent&&i.parent.scene&&f(i.parent.scene)?i.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:p(e)?e:p(e.game)?e.game:f(e)?e.sys.game:f(e.scene)?e.scene.sys.game:void 0}(e),this}}]),i}();Object.assign(m.prototype,a);var y=Phaser.Utils.Objects.GetValue,k=function(t){s(o,t);var i=c(o);function o(t,n){var s;return e(this,o),(s=i.call(this,t,n))._isRunning=!1,s.isPaused=!1,s.tickingState=!1,s.setTickingMode(y(n,"tickingMode",1)),s}return n(o,[{key:"boot",value:function(){2!==this.tickingMode||this.tickingState||this.startTicking();}},{key:"shutdown",value:function(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),h(r(o.prototype),"shutdown",this).call(this,t));}},{key:"setTickingMode",value:function(t){"string"==typeof t&&(t=g[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);}}]),o}(m),g={no:0,lazy:1,always:2},w=Phaser.Utils.Objects.GetValue,b=function(t){s(o,t);var i=c(o);function o(t,n){var s;return e(this,o),(s=i.call(this,t,n)).resetFromJSON(n),s.boot(),s}return n(o,[{key:"resetFromJSON",value:function(t){return this.isRunning=w(t,"isRunning",!1),this.timeScale=w(t,"timeScale",1),this.now=w(t,"now",0),this}},{key:"toJSON",value:function(){return {isRunning:this.isRunning,timeScale:this.timeScale,now:this.now,tickingMode:this.tickingMode}}},{key:"start",value:function(t){return void 0===t&&(t=0),this.delta=0,this.now=t,h(r(o.prototype),"start",this).call(this),this}},{key:"seek",value:function(t){return this.now=t,this}},{key:"setTimeScale",value:function(t){return this.timeScale=t,this}},{key:"tick",value:function(t){return t*=this.timeScale,this.now+=t,this.delta=t,this.emit("update",this.now,this.delta),this}}]),o}(k),E=function(t){s(o,t);var i=c(o);function o(){return e(this,o),i.apply(this,arguments)}return n(o,[{key:"startTicking",value:function(){h(r(o.prototype),"startTicking",this).call(this),this.scene.sys.events.on("update",this.update,this);}},{key:"stopTicking",value:function(){h(r(o.prototype),"stopTicking",this).call(this),this.scene&&this.scene.sys.events.off("update",this.update,this);}},{key:"update",value:function(t,e){return this.isRunning&&0!==this.timeScale?(this.tick(e),this):this}}]),o}(b),S=function(e,i){var n=Array.isArray(e);if(void 0===i?i=n?[]:{}:function(e){if("object"!==t(e)||null===e)return e;if(Array.isArray(e))e.length=0;else for(var i in e)delete e[i];}(i),n){i.length=e.length;for(var s=0,r=e.length;s<r;s++)i[s]=e[s];}else for(var o in e)i[o]=e[o];return i},_=Phaser.Utils.Objects.GetValue,O=function(t){s(o,t);var i=c(o);function o(t,n){var s;e(this,o),s=i.call(this,t,n);var r=_(n,"clock",void 0);return r||(r=new E(t)),s.clock=r,s.resetFromJSON(n),s}return n(o,[{key:"resetFromJSON",value:function(t){return this.clock.resetFromJSON(_(t,"clock",void 0)),this.commands=_(t,"commands",[]),this}},{key:"toJSON",value:function(){return {clock:this.clock.toJSON(),commands:this.commands}}},{key:"shutdown",value:function(t){this.isShutdown||(this.commands=void 0,this.clock.shutdown(t),h(r(o.prototype),"shutdown",this).call(this,t));}},{key:"start",value:function(t){return this.clear(),this.clock.start(t),this.emit("start",this.parent,this),this}},{key:"pause",value:function(){return this.clock.pause(),this.emit("pause",this.parent,this),this}},{key:"resume",value:function(){return this.clock.resume(),this.emit("resume",this.parent,this),this}},{key:"stop",value:function(){return this.clock.stop(),this.emit("stop",this.parent,this),this}},{key:"seek",value:function(t){return this.clock.seek(t),this}},{key:"isRecording",get:function(){return this.clock.isRunning}},{key:"timeScale",get:function(){return this.clock.timeScale},set:function(t){this.clock.timeScale=t;}},{key:"setTimeScale",value:function(t){return this.timeScale=t,this}},{key:"now",get:function(){return this.clock.now}},{key:"addCommand",value:function(t,e){if(!this.isRecording)return this;void 0===e&&(e=0);var i=this.clock.now+e;return this.commands.push([i,t]),this}},{key:"getCommands",value:function(t){return void 0===t&&(t=!1),t?this.commands:S(this.commands)}},{key:"clear",value:function(){return this.commands.length=0,this}}]),o}(m),P=function(t){s(o,t);var i=c(o);function o(){return e(this,o),i.apply(this,arguments)}return n(o,[{key:"startTicking",value:function(){h(r(o.prototype),"startTicking",this).call(this),this.scene.physics.world.on("worldstep",this.update,this);}},{key:"stopTicking",value:function(){h(r(o.prototype),"stopTicking",this).call(this),this.scene&&this.scene.physics.world.off("worldstep",this.update,this);}},{key:"update",value:function(){return this.isRunning&&0!==this.timeScale?(this.tick(1),this):this}}]),o}(b),T=function(t){s(r,t);var i=c(r);function r(t,n){return e(this,r),void 0===n&&(n={}),n.clock=new P(t),i.call(this,t,n)}return n(r)}(O),R=function(t,e,i,n){void 0===i&&(i=0),void 0===n&&(n=e.length),t.length=n-i;for(var s=0,r=t.length;s<r;s++)t[s]=e[s+i];return t},x=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("."),s=t,r=i,o=0;o<n.length;o++){if(!s.hasOwnProperty(n[o])){r=i;break}r=s[n[o]],s=s[n[o]];}return r}return i}return i},j=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,N=/^0x[0-9A-F]+$/i,M=function(t){if("string"!=typeof t)return t;if(""===t)t=null;else if(j.test(t))t=parseFloat(t);else if(N.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},D=function(t){return "[object Array]"===Object.prototype.toString.call(t)},U=function t(e,i,n){var s,r=x(n,"reverse",!1);if(D(e[0]))if(r)for(o=(u=e.length)-1;o>=0;o--)s=t(e[o],i,n);else for(var o=0,u=e.length;o<u;o++)s=t(e[o],i,n);else s=J(e,i,n);return s},J=function(t,e,i){var n,s=x(i,"argsConvert",void 0),r=x(i,"argsConvertScope",void 0),o=t[0];if(F=R(F,t,1),s){!0===s&&(s=M,r=void 0);for(var u=0,c=F.length;u<c;u++)F[u]=r?s.call(r,F[u],t):s(F[u],t);}return "string"==typeof o?null==(n=e[o])&&(n=x(e,o,null)):n=o,n.apply(e,F)},F=[],C=Phaser.Utils.Objects.GetValue,A=function(t){s(o,t);var i=c(o);function o(t,n){var s;e(this,o),s=i.call(this,t,n);var r=C(n,"clock",void 0);return r||(r=new E(t)),s.clock=r,s.clock.on("update",s.update,u(s)),s.resetFromJSON(n),s}return n(o,[{key:"resetFromJSON",value:function(t){return this.clock.resetFromJSON(C(t,"clock",void 0)),this.state=C(t,"state",0),this.commands=C(t,"commands",[]),this.scope=C(t,"scope",void 0),this.setTimeUnit(C(t,"timeUnit",0)),this.setDtMode(C(t,"dtMode",0)),this.index=C(t,"index",0),this.nextTime=C(t,"nextTime",0),this}},{key:"toJSON",value:function(){return {clock:this.clock.toJSON(),state:this.state,commands:this.commands,scope:this.scope,timeUnit:this.timeUnit,dtMode:this.dtMode,index:this.index,nextTime:this.nextTime}}},{key:"shutdown",value:function(t){this.isShutdown||(this.clock.shutdown(t),this.commands=void 0,h(r(o.prototype),"shutdown",this).call(this,t));}},{key:"load",value:function(t,e,i){this.stop();var n=C(i,"timeUnit",void 0);void 0!==n&&this.setTimeUnit(n);var s=C(i,"dtMode",void 0);return void 0!==s&&this.setDtMode(s),t=t.filter((function(t){var e=t[0];return !isNaN(e)})).map((function(t){return "string"==typeof t[0]&&(t[0]=parseFloat(t[0])),t})),0===this.dtMode&&t.sort((function(t,e){var i=t[0],n=e[0];return i>n?1:i<n?-1:0})),this.commands=t,this.scope=e,this}},{key:"start",value:function(t){return void 0===t&&(t=0),this.stop(),this.index=0,this.state=1,this.nextTime=this.getNextDt(0),this.clock.start(t),this.update(t),this.emit("start",this.parent,this),this}},{key:"pause",value:function(){return this.clock.pause(),this.emit("pause",this.parent,this),this}},{key:"resume",value:function(){return this.clock.resume(),this.emit("resume",this.parent,this),this}},{key:"stop",value:function(){return this.clock.stop(),this.state=0,this.emit("stop",this.parent,this),this}},{key:"seek",value:function(t){return this.clock.seek(t),this}},{key:"seekToNext",value:function(){return this.seek(this.nextTime),this}},{key:"isPlaying",get:function(){return this.clock.isRunning}},{key:"completed",get:function(){return 2===this.state}},{key:"timeScale",get:function(){return this.clock.timeScale},set:function(t){this.clock.timeScale=t;}},{key:"setTimeScale",value:function(t){return this.timeScale=t,this}},{key:"now",get:function(){return this.clock.now}},{key:"update",value:function(t){if(this.nextTime>t)return this;for(var e=this.commands.length-1;;){var i=this.commands[this.index],n=i[1];if(D(n)||(n=R(G,i,1)),U(n,this.scope),this.emit("runcommand",n,this.scope),this.index===e)return this.complete(),this;if(this.index++,this.nextTime=this.getNextDt(this.nextTime),this.nextTime>t)return this}}},{key:"complete",value:function(){this.clock.stop(),this.state=2,this.emit("complete",this.parent,this);}},{key:"getNextDt",value:function(t){var e=this.commands[this.index][0];return 1===this.timeUnit&&(e*=1e3),1===this.dtMode&&(e+=t),e}},{key:"setDtMode",value:function(t){return "string"==typeof t&&(t=V[t]),this.dtMode=t,this}},{key:"setTimeUnit",value:function(t){return "string"==typeof t&&(t=L[t]),this.timeUnit=t,this}}]),o}(m),G=[],L={ms:0,s:1,sec:1},V={abs:0,absolute:0,inc:1,increment:1},B=function(t){s(o,t);var i=c(o);function o(t,n){return e(this,o),void 0===n&&(n={}),n.clock=new P(t),n.timeUnit=0,n.dtMode=0,i.call(this,t,n)}return n(o,[{key:"load",value:function(t,e,i){return h(r(o.prototype),"load",this).call(this,t,e),this}}]),o}(A),$=function(t){s(o,t);var i=c(o);function o(t){var n;return e(this,o),(n=i.call(this,t,{eventEmitter:!1})).commands=[],n.boot(),n}return n(o,[{key:"boot",value:function(){this.scene.physics.world.on("worldstep",this.update,this);}},{key:"shutdown",value:function(t){this.isShutdown||(this.scene.physics.world.off("worldstep",this.update,this),this.commands=void 0,h(r(o.prototype),"shutdown",this).call(this,t));}},{key:"add",value:function(t,e){return this.commands.push([t,e]),this}},{key:"update",value:function(){if(0!==this.commands.length){for(var t,e=0,i=this.commands.length;e<i;e++)t=this.commands[e],U(t[0],t[1]);this.commands.length=0;}}}]),o}(m),z={Recorder:T,Player:B,StepRunner:$,RunCommands:U},I=z.Recorder,q=z.Player,H=z.StepRunner,K=function(t){s(r,Phaser.Plugins.BasePlugin);var i=c(r);function r(t){return e(this,r),i.call(this,t)}return n(r,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"addRecorder",value:function(t,e){return new I(t,e)}},{key:"addPlayer",value:function(t,e){return new q(t,e)}},{key:"addStepRunner",value:function(t){return new H(t)}}]),r}(),Q={runCommands:z.RunCommands};return Object.assign(K.prototype,Q),K}));