UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 6.83 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).rexgashaponplugin=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 i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(n=i.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(n,"string"))?s:String(s)),i);}var n,s;}function i(t,e,i){return e&&r(t.prototype,e),i&&r(t,i),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 s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(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 s=n(this).constructor;r=Reflect.construct(i,arguments,s);}else r=i.apply(this,arguments);return o(this,r)}}var a=function(e,r){var i=Array.isArray(e);if(void 0===r?r=i?[]:{}:function(e){if("object"!==t(e)||null===e)return e;if(Array.isArray(e))e.length=0;else for(var r in e)delete e[r];}(r),i){r.length=e.length;for(var n=0,s=e.length;n<s;n++)r[n]=e[n];}else for(var o in e)r[o]=e[o];return r},h=Phaser.Utils.Objects.GetValue,l=function(){function t(r){e(this,t),this.resetFromJSON(r);}return i(t,[{key:"destroy",value:function(){this.items=void 0,this.remainder=void 0,this._list=void 0;}},{key:"resetFromJSON",value:function(t){null==this.items&&(this.items={}),null==this.remainder&&(this.remainder={}),null==this._list&&(this._list=[]),this.setMode(h(t,"mode",0)),this.setReload(h(t,"reload",!0)),this.setRND(h(t,"rnd",void 0)),this.items=a(h(t,"items",{}),this.items),this._list.length=0,this.result=h(t,"result",null),this._restartFlag=!0,this._restartFlag&&this.startGen();var e=h(t,"remainder",void 0);return e&&(this.remainder=a(e,this.remainder)),this}},{key:"toJSON",value:function(){return {mode:this.mode,reload:this.reload,rnd:this.rnd,items:a(this.items),remainder:a(this.remainder),result:this.result,restart:!0}}},{key:"startGen",value:function(){var t;for(t in this.remainder)this.items.hasOwnProperty(t)||delete this.remainder[t];for(t in this.items){var e=this.items[t];e>0&&(this.remainder[t]=e);}return 1===this.mode&&this.resetItemList(this.remainder),this._restartFlag=!1,this}},{key:"setMode",value:function(t){return "string"==typeof t&&(t=f[t]),this._restartFlag=this.mode!==t,this.mode=t,this}},{key:"setReload",value:function(t){return this.reload=!!t,this}},{key:"setRND",value:function(t){return this.rnd=t,this}},{key:"setItem",value:function(t,e){return this._restartFlag=this.items[t]!==e,this.items[t]=e,this}},{key:"removeItem",value:function(t){return this.items.hasOwnProperty(t)&&(delete this.items[t],this._restartFlag=!0),this}},{key:"removeAllItems",value:function(){for(var t in this.items)delete this.items[t];return this._restartFlag=!0,this}},{key:"getItems",value:function(){return a(this.items)}},{key:"getRemain",value:function(){return a(this.remainder)}},{key:"getItemCount",value:function(t){return this.items[t]||0}},{key:"getRemainCount",value:function(t){return this.remainder[t]||0}},{key:"forEachItem",value:function(t,e){for(var r=[null,void 0],i=2,n=arguments.length;i<n;i++)r.push(arguments[i]);for(var s in this.items)r[0]=s,r[1]=this.items[s],e?t.apply(e,r):t(r);return this}},{key:"forEachRemain",value:function(t,e){for(var r=[null,void 0],i=1;i<arguments.length;i++)r.push(arguments[i]);for(var n in this.remainder)r[1]=n,r[2]=this.remainder[n],e?t.apply(e,r):t(r);return this}},{key:"addItem",value:function(t,e){if(this.items.hasOwnProperty(t)||(this.items[t]=0),this.items[t]+=e,!this._restartFlag)return 0===this.mode?this.addRemainItem(t,e):this.resetItemList(this.remainder),this}},{key:"putItemBack",value:function(t,e){if(1!==this.mode&&this.items.hasOwnProperty(t)&&(2!==this.mode||!this.restartGenFlg))return this.remainder.hasOwnProperty(t)||(this.remainder[t]=0),this.addShadowPattern(t,e,this.items[t]),this}},{key:"next",value:function(t){var e=null;return this._restartFlag&&this.startGen(),null==t?0===this.mode?(this.resetItemList(this.remainder),e=this.getRndItem(this._list),this.addRemainItem(e,-1)):e=this.getRndItem(this._list):this.remainder.hasOwnProperty(t)?(0===this.mode&&this.addRemainItem(t,-1),e=t):e=null,this.result=e,e}},{key:"resetItemList",value:function(t){this._list.length=0;var e,r,i=0;for(e in t)(r=t[e])>0&&(i+=r);for(e in t)(r=t[e])>0&&this._list.push([e,r/i]);return this}},{key:"addRemainItem",value:function(t,e,r){return null==t||0===e||(this.remainder.hasOwnProperty(t)||(this.remainder[t]=0),this.remainder[t]+=e,null!=r&&this.remainder[t]>r&&(this.remainder[t]=r),this.remainder[t]<=0&&delete this.remainder[t],0===this.mode&&this.reload&&function(t){for(var e in t)return !1;return !0}(this.remainder)&&(this._restartFlag=!0)),this}},{key:"getRndItem",value:function(t){var e,r,i=this.rnd?this.rnd.frac():Math.random(),n=null,s=t.length;for(e=0;e<s;e++)if((i-=(r=t[e])[1])<0){n=r[0];break}return n}}]),t}(),f={shuffle:0,random:1};return function(t){!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&&s(t,e);}(n,Phaser.Plugins.BasePlugin);var r=u(n);function n(t){return e(this,n),r.call(this,t)}return i(n,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new l(t)}}]),n}()}));