phaser3-rex-plugins
Version:
2 lines (1 loc) • 6.24 kB
JavaScript
!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).rexbuffdataplugin=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 n(t,e){for(var n=0;n<e.length;n++){var s=e[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,(r=s.key,i=void 0,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var s=n.call(t,e||"default");if("object"!=typeof s)return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(r,"string"))?i:String(i)),s);}var r,i;}function s(t,e,s){return e&&n(t.prototype,e),s&&n(t,s),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(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&&u(t,e);}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function f(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 n,s=i(t);if(e){var r=i(this).constructor;n=Reflect.construct(s,arguments,r);}else n=s.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 o(t)}(this,n)}}var a=function(){function n(){e(this,n),this.buffs={};}return s(n,[{key:"setEnable",value:function(t,e){return void 0===e&&(e=!0),this.buffs.hasOwnProperty(t)||(this.buffs[t]={enable:!0,value:0,type:h}),this.buffs[t].enable=e,this}},{key:"set",value:function(e,n){this.setEnable(e);var s=t(n);"number"===s?s=h:"string"===s&&(-1!==n.indexOf("%")?(s=c,n=parseFloat(n)/100):(s=h,n=parseFloat(n)));var r=this.buffs[e];return r.value=n,r.type=s,this}},{key:"remove",value:function(t){return this.buffs.hasOwnProperty(t)&&delete this.buffs[t],this}},{key:"buff",value:function(t){var e,n,s=t,r=this.buffs;for(var i in r)if((e=r[i]).enable)switch(n=e.type,e=e.value,n){case h:s+=e;break;case c:s+=t*e;}return s}}]),n}(),h=0,c=1,l=Phaser.Utils.Objects.IsPlainObject,b=Phaser.Utils.Objects.GetValue,y=function(){function t(n,s){if(e(this,t),l(n)){var r=n;n=b(r,"min",void 0),s=b(r,"max",void 0);}this.setMin(n),this.setMax(s);}return s(t,[{key:"setMin",value:function(t){return this.min=t,this}},{key:"setMax",value:function(t){return this.max=t,this}},{key:"clamp",value:function(t){return void 0!==this.min&&t<this.min?t=this.min:void 0!==this.max&&t>this.max&&(t=this.max),t}}]),t}(),p={setBaseValue:function(t,e){return this.baseValues[t]=e,this.set(t,this.getBuffResult(t)),this},removeBaseValue:function(t){return this.baseValues.hasOwnProperty(t)&&(delete this.baseValues[t],this.remove(t)),this},setBuff:function(t,e,n){return this.buffs.hasOwnProperty(t)||(this.buffs[t]=new a),this.buffs[t].set(e,n),this.set(t,this.getBuffResult(t)),this},enableBuff:function(t,e,n){return this.buffs.hasOwnProperty(t)||(this.buffs[t]=new a),this.buffs[t].setEnable(e,n),this.set(t,this.getBuffResult(t)),this},removeBuff:function(t,e){return this.buffs.hasOwnProperty(t)&&(void 0===e?delete this.buffs[t]:this.buffs[t].remove(e)),this.set(t,this.getBuffResult(t)),this},setMin:function(t,e){return this.bounds.hasOwnProperty(t)||(this.bounds[t]=new y),this.bounds[t].setMin(e),this.set(t,this.getBuffResult(t)),this},setMax:function(t,e){return this.bounds.hasOwnProperty(t)||(this.bounds[t]=new y),this.bounds[t].setMax(e),this.set(t,this.getBuffResult(t)),this},setBounds:function(t,e,n){return this.bounds.hasOwnProperty(t)||(this.bounds[t]=new y),this.bounds[t].setMin(e).setMax(n),this.set(t,this.getBuffResult(t)),this},getBuffResult:function(t){return this.clamp(t,this.buff(t))},buff:function(t,e){return void 0===e&&(e=this.getBaseValue(t)),this.buffs.hasOwnProperty(t)?this.buffs[t].buff(e):e},clamp:function(t,e){return void 0===e&&(e=this.list[t]),this.bounds.hasOwnProperty(t)?this.bounds[t].clamp(e):e},getBaseValue:function(t){return this.baseValues.hasOwnProperty(t)||(this.baseValues[t]=0),this.baseValues[t]},getBuffs:function(t,e){var n=this.buffs[t];return void 0===e?n:n&&n.hasOwnProperty(e)?n[e]:void 0},getBuffValue:function(t,e){return this.getBuffs(t,e).value},getBounds:function(t){return this.bounds.hasOwnProperty(t)||(this.bounds[t]=new y),this.bounds[t]},getMinBound:function(t){return this.getBounds(t).min},getMaxBound:function(t){return this.getBounds(t).max}},d=function(t){return void 0===t.buffs&&(t.baseValues={},t.buffs={},t.bounds={}),void 0===t.addBuff&&Object.assign(t,p),t},v=Phaser.Data.DataManager,m=Phaser.Events.EventEmitter,g=function(t){r(i,t);var n=f(i);function i(t,s){var r;e(this,i);var u=void 0===s;if(u&&(s=new m),r=n.call(this,t,s),u){var f=t.events?t.events:t;f&&f.once("destroy",r.destroy,o(r));}return d(o(r)),r}return s(i)}(v);return Object.assign(g.prototype,p),function(t){r(i,Phaser.Plugins.BasePlugin);var n=f(i);function i(t){return e(this,i),n.call(this,t)}return s(i,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e){return new g(t,e)}},{key:"extend",value:function(t){return d(t)}}]),i}()}));