UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 4.21 kB
!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).rexawaytimeplugin=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 r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(i=n.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.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)}(i,"string"))?o:String(o)),n);}var i,o;}function r(t,r,n){return r&&e(t.prototype,r),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 i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function o(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 u(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 r,i=n(t);if(e){var u=n(this).constructor;r=Reflect.construct(i,arguments,u);}else r=i.apply(this,arguments);return o(this,r)}}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var i=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=n(t)););return t}(t,e);if(i){var o=Object.getOwnPropertyDescriptor(i,e);return o.get?o.get.call(arguments.length<3?t:r):o.value}},a.apply(this,arguments)}var s=Phaser.Utils.Objects.GetValue,f=function(){function e(r){t(this,e),this.state=c,this.setKey(s(r,"key","away")),this.setPeriod(s(r,"period",1e3));}return r(e,[{key:"destroy",value:function(){this.stop();}},{key:"awayTime",get:function(){var t=localStorage.getItem(this.key);if(this.start(),null==t)return 0;t=parseInt(t);var e=this.curTime;return t<0||t>e?0:e-t}},{key:"curTime",get:function(){return (new Date).getTime()}},{key:"start",value:function(){return this.stop(),this.updateTime(),this.timer=setInterval(this.updateTime.bind(this),this.period),this.state=l,this}},{key:"stop",value:function(){return this.state===c||(clearTimeout(this.timer),this.timer=void 0,this.state=c),this}},{key:"updateTime",value:function(){return localStorage.setItem(this.key,this.curTime),this}},{key:"setKey",value:function(t){return this.key=t,this}},{key:"setPeriod",value:function(t){return this.period=t,this}}]),e}(),c=0,l=1;return 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&&i(t,e);}(s,Phaser.Plugins.BasePlugin);var o=u(s);function s(e){return t(this,s),o.call(this,e)}return r(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"destroy",value:function(){this._defaultAwayTimer&&this._defaultAwayTimer.destroy(),a(n(s.prototype),"destroy",this).call(this);}},{key:"add",value:function(t){return new f(t)}},{key:"defaultAwayTimer",get:function(){return this._defaultAwayTimer||(this._defaultAwayTimer=this.add()),this._defaultAwayTimer}},{key:"awayTime",get:function(){return this.defaultAwayTimer.awayTime}},{key:"setKey",value:function(t){return this.defaultAwayTimer.setKey(t),this}},{key:"setPeriod",value:function(t){return this.defaultAwayTimer.setPeriod(t),this}}]),s}()}));