UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 9.06 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).rexrealtimetimersplugin=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 r(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 n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(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&&s(t,e);}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(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 a(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,n=o(t);if(e){var i=o(this).constructor;r=Reflect.construct(n,arguments,i);}else r=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,r)}}function f(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var c={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,r="~";function n(){}function i(t,e,r){this.fn=t,this.context=e,this.once=r||!1;}function o(t,e,n,o,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var u=new i(n,o||t,s),a=r?r+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],u]:t._events[a].push(u):(t._events[a]=u,t._eventsCount++),t}function s(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e];}function u(){this._events=new n,this._eventsCount=0;}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),u.prototype.eventNames=function(){var t,n,i=[];if(0===this._eventsCount)return i;for(n in t=this._events)e.call(t,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(t)):i},u.prototype.listeners=function(t){var e=r?r+t:t,n=this._events[e];if(!n)return [];if(n.fn)return [n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s},u.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},u.prototype.emit=function(t,e,n,i,o,s){var u=r?r+t:t;if(!this._events[u])return !1;var a,f,c=this._events[u],l=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,e),!0;case 3:return c.fn.call(c.context,e,n),!0;case 4:return c.fn.call(c.context,e,n,i),!0;case 5:return c.fn.call(c.context,e,n,i,o),!0;case 6:return c.fn.call(c.context,e,n,i,o,s),!0}for(f=1,a=new Array(l-1);f<l;f++)a[f-1]=arguments[f];c.fn.apply(c.context,a);}else {var p,h=c.length;for(f=0;f<h;f++)switch(c[f].once&&this.removeListener(t,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,e);break;case 3:c[f].fn.call(c[f].context,e,n);break;case 4:c[f].fn.call(c[f].context,e,n,i);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];c[f].fn.apply(c[f].context,a);}}return !0},u.prototype.on=function(t,e,r){return o(this,t,e,r,!1)},u.prototype.once=function(t,e,r){return o(this,t,e,r,!0)},u.prototype.removeListener=function(t,e,n,i){var o=r?r+t:t;if(!this._events[o])return this;if(!e)return s(this,o),this;var u=this._events[o];if(u.fn)u.fn!==e||i&&!u.once||n&&u.context!==n||s(this,o);else {for(var a=0,f=[],c=u.length;a<c;a++)(u[a].fn!==e||i&&!u[a].once||n&&u[a].context!==n)&&f.push(u[a]);f.length?this._events[o]=1===f.length?f[0]:f:s(this,o);}return this},u.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&s(this,e)):(this._events=new n,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=r,u.EventEmitter=u,t.exports=u;}(c);var l=function(t){i(o,t);var r=a(o);function o(){return e(this,o),r.apply(this,arguments)}return n(o,[{key:"shutdown",value:function(){this.removeAllListeners();}},{key:"destroy",value:function(){this.removeAllListeners();}}]),o}(f(c.exports)),p=function(t,e,r){if(t&&"number"!=typeof t){if(t.hasOwnProperty(e))return t[e];if(-1!==e.indexOf(".")){for(var n=e.split("."),i=t,o=r,s=0;s<n.length;s++){if(!i.hasOwnProperty(n[s])){o=r;break}o=i[n[s]],i=i[n[s]];}return o}return r}return r},h=function(t){if("number"==typeof t)return t;var e=t,r=e.day||e.d||0,n=e.hour||e.h||0,i=e.minute||e.m||0,o=e.second||e.s||0;return t=1e3*(o+=60*(i+=60*(n+=24*r)))},v=function(t,e){if(!(e>=t.length)){for(var r=t.length-1,n=t[e],i=e;i<r;i++)t[i]=t[i+1];return t.length=r,n}},m=function(r){i(s,r);var o=a(s);function s(t){var r;e(this,s),r=o.call(this);var n=p(t,"getTimestampCallback");return n||(r.setStartTimestamp(p(t,"startTimestamp")),n=y.bind(u(r))),r.setGetTimestampCallback(n),r.resetFromJSON(t),r}return n(s,[{key:"resetFromJSON",value:function(t){return this.timers=p(t,"timers",[]),this}},{key:"toJSON",value:function(){return {timers:this.timers}}},{key:"setStartTimestamp",value:function(t){return void 0===t&&(t=(new Date).getTime()),this.startTimestamp=t-window.performance.now(),this}},{key:"setGetTimestampCallback",value:function(t){return this.getCurrentTimestampCallback=t,this}},{key:"addTimer",value:function(t,e,r,n){void 0===n&&(n=this.getCurrentTimestampCallback());var i={name:t,start:n,period:e=h(e),data:r};return void 0!==r&&(i.data=r),this._add(i),this}},{key:"incTimerPeriod",value:function(t,e){e=h(e);for(var r=0,n=this.timers.length;r<n;r++){var i=this.timers[r];i.name===t&&(i.period+=e);}return this.emitUpdateEvent(),this}},{key:"getExpiredTimers",value:function(t){void 0===t&&(t=this.getCurrentTimestampCallback());for(var e=[],r=0,n=this.timers.length;r<n;r++){var i=this.timers[r];t>=i.start+i.period&&e.push(i);}return e}},{key:"popExpiredTimers",value:function(t){var e=this.getExpiredTimers(t);return this._remove(e),e}},{key:"getTimersProgress",value:function(t){void 0===t&&(t=this.getCurrentTimestampCallback());for(var e=[],r=0,n=this.timers.length;r<n;r++){var i=this.timers[r],o=t-i.start,s=i.period,u=(o=Math.min(o,s))/s;e.push({name:i.name,period:s,elapsed:o,progress:u,timer:i});}return e}},{key:"getTimers",value:function(t){if(void 0===t)return this.timers.slice();for(var e=[],r=0,n=this.timers.length;r<n;r++){var i=this.timers[r];i.name===t&&e.push(i);}return e}},{key:"removeTimers",value:function(e){return "object"!==t(e)&&(e=this.getTimers(e)),Array.isArray(e)||(e=[e]),this._remove(e),this}},{key:"clearTimers",value:function(){var t=this.getTimers();return t.reverse(),this.removeTimers(t),this}},{key:"length",get:function(){return this.timers.length}},{key:"lastTimer",get:function(){return this.timers[this.timers.length-1]}},{key:"emitUpdateEvent",value:function(){return this.emit("update",this.timers),this}},{key:"_add",value:function(t){this.timers.push(t),this.emit("add",t,this.timers),this.emitUpdateEvent();}},{key:"_remove",value:function(t){!function(t,e,r,n){var i;if(void 0===n&&(n=t),!Array.isArray(e))return -1!==(i=t.indexOf(e))?(v(t,i),r&&r.call(n,e),e):null;for(var o=e.length-1;o>=0;){var s=e[o];-1!==(i=t.indexOf(s))?(v(t,i),r&&r.call(n,s)):e.pop(),o--;}}(this.timers,t,(function(t){this.emit("remove",t,this.timers);}),this),this.emitUpdateEvent();}}]),s}(l),y=function(){return this.startTimestamp+window.performance.now()};return function(t){i(o,Phaser.Plugins.BasePlugin);var r=a(o);function o(t){return e(this,o),r.call(this,t)}return n(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new m(t)}}]),o}()}));