UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 3.48 kB
var s,t;s=void 0,t=function(){class s{constructor(){this.buffs={}}setEnable(s,e){return void 0===e&&(e=!0),this.buffs.hasOwnProperty(s)||(this.buffs[s]={enable:!0,value:0,type:t}),this.buffs[s].enable=e,this}set(s,i){this.setEnable(s);var u=typeof i;"number"===u?u=t:"string"===u&&(-1!==i.indexOf("%")?(u=e,i=parseFloat(i)/100):(u=t,i=parseFloat(i)));var r=this.buffs[s];return r.value=i,r.type=u,this}remove(s){return this.buffs.hasOwnProperty(s)&&delete this.buffs[s],this}buff(s){var i,u,r=s,n=this.buffs;for(var h in n)if((i=n[h]).enable)switch(u=i.type,i=i.value,u){case t:r+=i;break;case e:r+=s*i}return r}}const t=0,e=1,i=Phaser.Utils.Objects.IsPlainObject,u=Phaser.Utils.Objects.GetValue;class r{constructor(s,t){if(i(s)){var e=s;s=u(e,"min",void 0),t=u(e,"max",void 0)}this.setMin(s),this.setMax(t)}setMin(s){return this.min=s,this}setMax(s){return this.max=s,this}clamp(s){return void 0!==this.min&&s<this.min?s=this.min:void 0!==this.max&&s>this.max&&(s=this.max),s}}var n={setBaseValue(s,t){return this.baseValues[s]=t,this.set(s,this.getBuffResult(s)),this},removeBaseValue(s){return this.baseValues.hasOwnProperty(s)&&(delete this.baseValues[s],this.remove(s)),this},setBuff(t,e,i){return this.buffs.hasOwnProperty(t)||(this.buffs[t]=new s),this.buffs[t].set(e,i),this.set(t,this.getBuffResult(t)),this},enableBuff(t,e,i){return this.buffs.hasOwnProperty(t)||(this.buffs[t]=new s),this.buffs[t].setEnable(e,i),this.set(t,this.getBuffResult(t)),this},removeBuff(s,t){return this.buffs.hasOwnProperty(s)&&(void 0===t?delete this.buffs[s]:this.buffs[s].remove(t)),this.set(s,this.getBuffResult(s)),this},setMin(s,t){return this.bounds.hasOwnProperty(s)||(this.bounds[s]=new r),this.bounds[s].setMin(t),this.set(s,this.getBuffResult(s)),this},setMax(s,t){return this.bounds.hasOwnProperty(s)||(this.bounds[s]=new r),this.bounds[s].setMax(t),this.set(s,this.getBuffResult(s)),this},setBounds(s,t,e){return this.bounds.hasOwnProperty(s)||(this.bounds[s]=new r),this.bounds[s].setMin(t).setMax(e),this.set(s,this.getBuffResult(s)),this},getBuffResult(s){return this.clamp(s,this.buff(s))},buff(s,t){return void 0===t&&(t=this.getBaseValue(s)),this.buffs.hasOwnProperty(s)?this.buffs[s].buff(t):t},clamp(s,t){return void 0===t&&(t=this.list[s]),this.bounds.hasOwnProperty(s)?this.bounds[s].clamp(t):t},getBaseValue(s){return this.baseValues.hasOwnProperty(s)||(this.baseValues[s]=0),this.baseValues[s]},getBuffs(s,t){var e=this.buffs[s];return void 0===t?e:e&&e.hasOwnProperty(t)?e[t]:void 0},getBuffValue(s,t){return this.getBuffs(s,t).value},getBounds(s){return this.bounds.hasOwnProperty(s)||(this.bounds[s]=new r),this.bounds[s]},getMinBound(s){return this.getBounds(s).min},getMaxBound(s){return this.getBounds(s).max}},h=function(s){return void 0===s.buffs&&(s.baseValues={},s.buffs={},s.bounds={}),void 0===s.addBuff&&Object.assign(s,n),s};const a=Phaser.Data.DataManager,f=Phaser.Events.EventEmitter;class o extends a{constructor(s,t){var e=void 0===t;if(e&&(t=new f),super(s,t),e){var i=s.events?s.events:s;i&&i.once("destroy",this.destroy,this)}h(this)}}Object.assign(o.prototype,n);class b extends Phaser.Plugins.BasePlugin{constructor(s){super(s)}start(){this.game.events.on("destroy",this.destroy,this)}add(s,t){return new o(s,t)}extend(s){return h(s)}}return b},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(s="undefined"!=typeof globalThis?globalThis:s||self).rexbuffdataplugin=t();