phaser4-rex-plugins
Version:
2 lines (1 loc) • 11.9 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 n=function(t){return t instanceof i};const r=Phaser.Utils.Objects.GetValue;class h{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(r(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:n(t)?t:n(t.game)?t.game:s(t)?t.sys.game:s(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(h.prototype,t);const o=Phaser.Utils.Objects.GetValue;class a extends h{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(o(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=c[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 c={no:0,lazy:1,always:2},u=Phaser.Utils.Objects.GetValue;class d extends a{constructor(t,e){super(t,e),this.resetFromJSON(e),this.boot()}resetFromJSON(t){return this.isRunning=u(t,"isRunning",!1),this.timeScale=u(t,"timeScale",1),this.now=u(t,"now",0),this}toJSON(){return{isRunning:this.isRunning,timeScale:this.timeScale,now:this.now,tickingMode:this.tickingMode}}start(t){return void 0===t&&(t=0),this.delta=0,this.now=t,super.start(),this}seek(t){return this.now=t,this}setTimeScale(t){return this.timeScale=t,this}tick(t){return t*=this.timeScale,this.now+=t,this.delta=t,this.emit("update",this.now,this.delta),this}}class m extends d{startTicking(){super.startTicking(),this.scene.sys.events.on("update",this.update,this)}stopTicking(){super.stopTicking(),this.scene&&this.scene.sys.events.off("update",this.update,this)}update(t,e){return this.isRunning&&0!==this.timeScale?(this.tick(e),this):this}}var l=function(t,e){var s=Array.isArray(t);if(void 0===e?e=s?[]:{}:function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e]}(e),s){e.length=t.length;for(var i=0,n=t.length;i<n;i++)e[i]=t[i]}else for(var r in t)e[r]=t[r];return e};const p=Phaser.Utils.Objects.GetValue;let v=class extends h{constructor(t,e){super(t,e);var s=p(e,"clock",void 0);s||(s=new m(t)),this.clock=s,this.resetFromJSON(e)}resetFromJSON(t){return this.clock.resetFromJSON(p(t,"clock",void 0)),this.commands=p(t,"commands",[]),this}toJSON(){return{clock:this.clock.toJSON(),commands:this.commands}}shutdown(t){this.isShutdown||(this.commands=void 0,this.clock.shutdown(t),super.shutdown(t))}start(t){return this.clear(),this.clock.start(t),this.emit("start",this.parent,this),this}pause(){return this.clock.pause(),this.emit("pause",this.parent,this),this}resume(){return this.clock.resume(),this.emit("resume",this.parent,this),this}stop(){return this.clock.stop(),this.emit("stop",this.parent,this),this}seek(t){return this.clock.seek(t),this}get isRecording(){return this.clock.isRunning}get timeScale(){return this.clock.timeScale}set timeScale(t){this.clock.timeScale=t}setTimeScale(t){return this.timeScale=t,this}get now(){return this.clock.now}addCommand(t,e){if(!this.isRecording)return this;void 0===e&&(e=0);var s=this.clock.now+e;return this.commands.push([s,t]),this}getCommands(t){return void 0===t&&(t=!1),t?this.commands:l(this.commands)}clear(){return this.commands.length=0,this}};class g extends d{startTicking(){super.startTicking(),this.scene.physics.world.on("worldstep",this.update,this)}stopTicking(){super.stopTicking(),this.scene&&this.scene.physics.world.off("worldstep",this.update,this)}update(){return this.isRunning&&0!==this.timeScale?(this.tick(1),this):this}}var f=function(t,e,s,i){void 0===s&&(s=0),void 0===i&&(i=e.length),t.length=i-s;for(var n=0,r=t.length;n<r;n++)t[n]=e[n+s];return t},k=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,n=t,r=s,h=0;h<i.length;h++){if(e=i[h],!n.hasOwnProperty(e)){r=s;break}n=r=n[e]}return r},y=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,E=/^0x[0-9A-F]+$/i,w=function(t){if("string"!=typeof t)return t;if(""===t)t=null;else if(y.test(t))t=parseFloat(t);else if(E.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},S=function(t){return"[object Array]"===Object.prototype.toString.call(t)},_=function(t,e,s){var i,n=k(s,"reverse",!1);if(S(t[0]))if(n)for(r=(h=t.length)-1;r>=0;r--)i=_(t[r],e,s);else for(var r=0,h=t.length;r<h;r++)i=_(t[r],e,s);else i=x(t,e,s);return i},x=function(t,e,s){var i,n=k(s,"argsConvert",void 0),r=k(s,"argsConvertScope",void 0),h=t[0];if(T=f(T,t,1),n){!0===n&&(n=w,r=void 0);for(var o=0,a=T.length;o<a;o++)T[o]=r?n.call(r,T[o],t):n(T[o],t)}return"string"==typeof h?null==(i=e[h])&&(i=k(e,h,null)):i=h,i.apply(e,T)},T=[];const R=Phaser.Utils.Objects.GetValue;let P=class extends h{constructor(t,e){super(t,e);var s=R(e,"clock",void 0);s||(s=new m(t)),this.clock=s,this.clock.on("update",this.update,this),this.commands=[],this.resetFromJSON(e)}resetFromJSON(t){return this.clock.resetFromJSON(R(t,"clock",void 0)),this.state=R(t,"state",0),this.commands=R(t,"commands",[]),this.scope=R(t,"scope",void 0),this.setTimeUnit(R(t,"timeUnit",0)),this.setDtMode(R(t,"dtMode",0)),this.index=R(t,"index",0),this.nextTime=R(t,"nextTime",0),this}toJSON(){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}}shutdown(t){this.isShutdown||(this.clock.shutdown(t),this.commands=void 0,super.shutdown(t))}load(t,e,s){this.stop();var i=R(s,"timeUnit",void 0);void 0!==i&&this.setTimeUnit(i);var n=R(s,"dtMode",void 0);return void 0!==n&&this.setDtMode(n),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 s=t[0],i=e[0];return s>i?1:s<i?-1:0})),f(this.commands,t),this.scope=e,this}clear(){return this.commands.length=0,this}append(t,e,...s){var i;return i=Array.isArray(e)?e:[e,...s],this.commands.push([t,i]),this}start(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}pause(){return this.clock.pause(),this.emit("pause",this.parent,this),this}resume(){return this.clock.resume(),this.emit("resume",this.parent,this),this}stop(){return this.clock.stop(),this.state=0,this.emit("stop",this.parent,this),this}seek(t){return this.clock.seek(t),this}seekToNext(){return this.seek(this.nextTime),this}get isPlaying(){return this.clock.isRunning}get completed(){return 2===this.state}get timeScale(){return this.clock.timeScale}set timeScale(t){this.clock.timeScale=t}setTimeScale(t){return this.timeScale=t,this}get now(){return this.clock.now}update(t){if(this.nextTime>t)return this;for(var e=this.commands;;){var s=e[this.index],i=s[1];if(S(i)||(i=f(b,s,1)),_(i,this.scope),this.emit("runcommand",i,this.scope),this.index>=e.length-1)return this.nextTime=0,this.complete(),this;if(this.index++,this.nextTime=this.getNextDt(this.nextTime),this.nextTime>t)return this}}complete(){this.clock.stop(),this.state=2,this.emit("complete",this.parent,this)}getNextDt(t){var e=this.commands[this.index][0];return 1===this.timeUnit&&(e*=1e3),1===this.dtMode&&(e+=t),e}setDtMode(t){return"string"==typeof t&&(t=N[t]),this.dtMode=t,this}setTimeUnit(t){return"string"==typeof t&&(t=O[t]),this.timeUnit=t,this}};var b=[];const O={ms:0,s:1,sec:1},N={abs:0,absolute:0,inc:1,increment:1};var M={Recorder:class extends v{constructor(t,e){void 0===e&&(e={}),e.clock=new g(t),super(t,e)}},Player:class extends P{constructor(t,e){void 0===e&&(e={}),e.clock=new g(t),e.timeUnit=0,e.dtMode=0,super(t,e)}load(t,e,s){return super.load(t,e),this}},StepRunner:class extends h{constructor(t){super(t,{eventEmitter:!1}),this.commands=[],this.boot()}boot(){this.scene.physics.world.on("worldstep",this.update,this)}shutdown(t){this.isShutdown||(this.scene.physics.world.off("worldstep",this.update,this),this.commands=void 0,super.shutdown(t))}add(t,e){return this.commands.push([t,e]),this}update(){if(0!==this.commands.length){for(var t,e=0,s=this.commands.length;e<s;e++)t=this.commands[e],_(t[0],t[1]);this.commands.length=0}}},RunCommands:_};const U=M.Recorder,D=M.Player,j=M.StepRunner;class J extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}addRecorder(t,e){return new U(t,e)}addPlayer(t,e){return new D(t,e)}addStepRunner(t){return new j(t)}}var F={runCommands:M.RunCommands};return Object.assign(J.prototype,F),J},"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();