!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).rexclockplugin=e()}(this,function(){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(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,n.key,n)}}function u(t,e,i){return e&&n(t.prototype,e),i&&n(t,i),t}function c(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}}),e&&i(t,e)}function h(t){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function r(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function a(n){var s=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 t,e=h(n);if(s){var i=h(this).constructor;t=Reflect.construct(e,arguments,i)}else t=e.apply(this,arguments);return r(this,t)}}function l(t,e,i){return(l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=h(t)););return t}(t,e);if(n){var s=Object.getOwnPropertyDescriptor(n,e);return s.get?s.get.call(i):s.value}})(t,e,i||t)}var t={setEventEmitter:function(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=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):[]}},s=Phaser.Utils.Objects.GetValue,e=function(){function i(t,e){o(this,i),this.parent=t,this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setEventEmitter(s(e,"eventEmitter",void 0)),this.setTickingMode(s(e,"tickingMode",1))}return u(i,[{key:"boot",value:function(){2!==this.tickingMode||this.tickingState||this.startTicking()}},{key:"shutdown",value:function(){this.destroyEventEmitter(),this.tickingState&&this.stopTicking()}},{key:"destroy",value:function(){this.shutdown()}},{key:"setTickingMode",value:function(t){"string"==typeof t&&(t=v[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)}}]),i}();Object.assign(e.prototype,t);function f(t){return t instanceof p}var v={no:0,lazy:1,always:2},p=Phaser.Scene,y=Phaser.Utils.Objects.GetValue,d=function(){c(r,e);var s=a(r);function r(t,e){var i,n;return o(this,r),(i=s.call(this,t,e)).parent=t,i.scene=f(n=t)?n:n.scene&&f(n.scene)?n.scene:n.parent&&n.parent.scene&&f(n.parent.scene)?n.parent.scene:void 0,i.resetFromJSON(e),i.boot(),i}return u(r,[{key:"resetFromJSON",value:function(t){return this.isRunning=y(t,"isRunning",!1),this.timeScale=y(t,"timeScale",1),this.now=y(t,"now",0),this}},{key:"toJSON",value:function(){return{isRunning:this.isRunning,timeScale:this.timeScale,now:this.now,tickingMode:this.tickingMode}}},{key:"boot",value:function(){l(h(r.prototype),"boot",this).call(this);var t,e=(t=this.parent,f(t)?t.events:t.on?t:void 0);e&&e.on("destroy",this.destroy,this)}},{key:"shutdown",value:function(){l(h(r.prototype),"shutdown",this).call(this),this.parent=void 0,this.scene=void 0}},{key:"start",value:function(t){return void 0===t&&(t=0),this.delta=0,this.now=t,l(h(r.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}}]),r}(),m=function(){c(e,d);var t=a(e);function e(){return o(this,e),t.apply(this,arguments)}return u(e,[{key:"startTicking",value:function(){l(h(e.prototype),"startTicking",this).call(this),this.scene.events.on("update",this.update,this)}},{key:"stopTicking",value:function(){l(h(e.prototype),"stopTicking",this).call(this),this.scene&&this.scene.events.off("update",this.update,this)}},{key:"update",value:function(t,e){return this.isRunning&&0!==this.timeScale&&this.tick(e),this}}]),e}();return function(){c(i,Phaser.Plugins.BasePlugin);var e=a(i);function i(t){return o(this,i),e.call(this,t)}return u(i,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this)}},{key:"add",value:function(t,e){return new m(t,e)}}]),i}()});
