phaser3-rex-plugins
Version:
2 lines (1 loc) • 7.79 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexlevelcounter=t();}(undefined,(function(){function e(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function t(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(i=r.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(i,"string"))?o:String(o)),r);}var i,o;}function n(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&o(e,t);}function i(e){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},i(e)}function o(e,t){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},o(e,t)}function s(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function u(e){var t=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(e){return !1}}();return function(){var n,r=i(e);if(t){var o=i(this).constructor;n=Reflect.construct(r,arguments,o);}else n=r.apply(this,arguments);return s(this,n)}}function l(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var c={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1;}function o(e,t,r,o,s){if("function"!=typeof r)throw new TypeError("The listener must be a function");var u=new i(r,o||e,s),l=n?n+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],u]:e._events[l].push(u):(e._events[l]=u,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new r:delete e._events[t];}function u(){this._events=new r,this._eventsCount=0;}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),u.prototype.eventNames=function(){var e,r,i=[];if(0===this._eventsCount)return i;for(r in e=this._events)t.call(e,r)&&i.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},u.prototype.listeners=function(e){var t=n?n+e:e,r=this._events[t];if(!r)return [];if(r.fn)return [r.fn];for(var i=0,o=r.length,s=new Array(o);i<o;i++)s[i]=r[i].fn;return s},u.prototype.listenerCount=function(e){var t=n?n+e:e,r=this._events[t];return r?r.fn?1:r.length:0},u.prototype.emit=function(e,t,r,i,o,s){var u=n?n+e:e;if(!this._events[u])return !1;var l,c,a=this._events[u],f=arguments.length;if(a.fn){switch(a.once&&this.removeListener(e,a.fn,void 0,!0),f){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,t),!0;case 3:return a.fn.call(a.context,t,r),!0;case 4:return a.fn.call(a.context,t,r,i),!0;case 5:return a.fn.call(a.context,t,r,i,o),!0;case 6:return a.fn.call(a.context,t,r,i,o,s),!0}for(c=1,l=new Array(f-1);c<f;c++)l[c-1]=arguments[c];a.fn.apply(a.context,l);}else {var h,p=a.length;for(c=0;c<p;c++)switch(a[c].once&&this.removeListener(e,a[c].fn,void 0,!0),f){case 1:a[c].fn.call(a[c].context);break;case 2:a[c].fn.call(a[c].context,t);break;case 3:a[c].fn.call(a[c].context,t,r);break;case 4:a[c].fn.call(a[c].context,t,r,i);break;default:if(!l)for(h=1,l=new Array(f-1);h<f;h++)l[h-1]=arguments[h];a[c].fn.apply(a[c].context,l);}}return !0},u.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},u.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},u.prototype.removeListener=function(e,t,r,i){var o=n?n+e:e;if(!this._events[o])return this;if(!t)return s(this,o),this;var u=this._events[o];if(u.fn)u.fn!==t||i&&!u.once||r&&u.context!==r||s(this,o);else {for(var l=0,c=[],a=u.length;l<a;l++)(u[l].fn!==t||i&&!u[l].once||r&&u[l].context!==r)&&c.push(u[l]);c.length?this._events[o]=1===c.length?c[0]:c:s(this,o);}return this},u.prototype.removeAllListeners=function(e){var t;return e?(t=n?n+e:e,this._events[t]&&s(this,t)):(this._events=new r,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=n,u.EventEmitter=u,e.exports=u;}(c);var a=function(t){r(o,t);var i=u(o);function o(){return e(this,o),i.apply(this,arguments)}return n(o,[{key:"shutdown",value:function(){this.removeAllListeners();}},{key:"destroy",value:function(){this.removeAllListeners();}}]),o}(l(c.exports)),f=function(e,t,n){if(e&&"number"!=typeof e){if(e.hasOwnProperty(t))return e[t];if(-1!==t.indexOf(".")){for(var r=t.split("."),i=e,o=n,s=0;s<r.length;s++){if(!i.hasOwnProperty(r[s])){o=n;break}o=i[r[s]],i=i[r[s]];}return o}return n}return n};return function(t){r(o,t);var i=u(o);function o(t){var n;e(this,o),(n=i.call(this)).setTable(f(t,"table")),n.setMaxLevel(f(t,"maxLevel"));var r=f(t,"exp",0),s=f(t,"level",void 0);return void 0===s||n.checkLevel(s,r)||(console.error("Level ".concat(s," and Exp ").concat(r," are mismatch")),s=void 0),n.resetExp(r,s),n}return n(o,[{key:"setTable",value:function(e){var t;return this.levelTable=e,this.isLevelMapFunction=(t=e)&&"function"==typeof t,this}},{key:"setMaxLevel",value:function(e){var t;return void 0===e&&(e=Array.isArray(this.levelTable)?this.levelTable.length-1:-1),t=-1!==e?this.getExp(e):-1,this.hasMaxLevel=-1!==e,this.maxLevel=e,this.maxExp=t,this}},{key:"resetExp",value:function(e,t){return this.hasMaxLevel&&e>this.maxExp&&(e=this.maxExp),void 0===t&&(t=this.getLevel(e)),this._exp=e,this._level=t,this._requiredExp=this.getRequiredExpToNextLevel(t,e),this}},{key:"exp",get:function(){return this._exp},set:function(e){if(this.hasMaxLevel&&e>this.maxExp&&(e=this.maxExp),e<this._exp)this.resetExp(e);else if(e!==this._exp){for(var t,n=this.getLevel(e,this._level),r=this._level,i=this._exp;;){var o=this.getExp(r),s=this.getExp(r+1);if(t=Math.min(s,e),this.emit("levelup",r,i,t,o,s),r===n&&t===e)break;r++,i=s;}this.resetExp(e,n);}}},{key:"level",get:function(){return this._level},set:function(e){this.hasMaxLevel&&e>this.maxLevel?this.exp=this.maxExp:this.exp=this.getExp(e);}},{key:"requiredExp",get:function(){return this._requiredExp}},{key:"getExp",value:function(e){return void 0===e?this._exp:this.isLevelMapFunction?this.levelTable(e):(this.hasMaxLevel&&e>this.maxLevel&&(e=this.maxLevel),this.levelTable[e])}},{key:"getLevel",value:function(e,t){if(void 0===e)return this._level;for(void 0===t&&(t=0);;){var n=this.getExp(t+1);if(n>e)break;if(t++,this.hasMaxLevel&&n===this.maxExp)break}return t}},{key:"getRequiredExpToNextLevel",value:function(e,t){return void 0===e&&(e=this.level),void 0===t&&(t=this.exp),this.getExp(e+1)-t}},{key:"checkLevel",value:function(e,t){return t>=this.getExp(e)&&t<this.getExp(e+1)}},{key:"gainExp",value:function(e){return this.exp+=e,this}},{key:"setExp",value:function(e){return this.exp=e,this}},{key:"setLevel",value:function(e){return this.level=e,this}}]),o}(a)}));