phaser3-rex-plugins
Version:
12 lines (11 loc) • 9.41 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).rexuniqueitemlistplugin=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 i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(r=n.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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)}(r,"string"))?s:String(s)),n);}var r,s;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(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 i,n=r(t);if(e){var s=r(this).constructor;i=Reflect.construct(n,arguments,s);}else i=n.apply(this,arguments);return o(this,i)}}var h=function(t,e,i){if(t&&"number"!=typeof t){if(t.hasOwnProperty(e))return t[e];if(-1!==e.indexOf(".")){for(var n=e.split("."),r=t,s=i,o=0;o<n.length;o++){if(!r.hasOwnProperty(n[o])){s=i;break}s=r[n[o]],r=r[n[o]];}return s}return i}return i},l=function(t){return "[object Array]"===Object.prototype.toString.call(t)},f={setAutoCleanupEnable:function(t){return void 0===t&&(t=!0),this.autoCleanupEnable=t,this},addDestroyCallback:function(t){if(!t||!this.autoCleanupEnable)return this;if(l(t)){for(var e=t,i=0,n=e.length;i<n;i++)this.addDestroyCallback(e[i]);return this}return t.on&&t.once("destroy",this.onChildDestroy,this),this},removeDestroyCallback:function(t){if(!t||!this.autoCleanupEnable)return this;if(l(t)){for(var e=t,i=0,n=e.length;i<n;i++)this.removeDestroyCallback(e[i]);return this}return t.off&&t.off("destroy",this.onChildDestroy,this),this}},a=function(t,e){return Math.floor(Math.random()*(e-t+1)+t)},c=function(e,i){var n=Array.isArray(e);if(void 0===i?i=n?[]:{}:function(e){if("object"!==t(e)||null===e)return e;if(Array.isArray(e))e.length=0;else for(var i in e)delete e[i];}(i),n){i.length=e.length;for(var r=0,s=e.length;r<s;r++)i[r]=e[r];}else for(var o in e)i[o]=e[o];return i},d={isEmpty:function(){return 0===this.items.length},get:function(t){return this.items[t]},getFirst:function(){return this.items[0]},getLast:function(){return this.items[this.items.length-1]},getRandom:function(){var t=a(0,this.items.length-1);return this.items[t]},add:function(t,e,i){var n=this.items.indexOf(t);return -1!==n?(i&&e!==n&&(this.remove(void 0,n),this.add(t,e)),this):(void 0===e||e>=this.items.length?this.items.push(t):this.items.splice(e,0,t),this.addDestroyCallback(t),this)},addFirst:function(t,e){return this.add(t,0,e),this},addLast:function(t,e){return this.add(t,void 0,e),this},addMultiple:function(t,e,i){if(void 0===e)for(var n=0,r=t.length;n<r;n++)this.add(t[n]);else for(n=0,r=t.length;n<r;n++)this.contains(t[n])||(this.add(t[n],e,i),e++);return this},remove:function(t,e){if(t){if(-1===(e=this.items.indexOf(t)))return this}else if(!(t=this.items[e]))return this;return e===this.items.length-1?this.items.length-=1:function(t,e){if(!(e>=t.length)){for(var i=t.length-1,n=t[e],r=e;r<i;r++)t[r]=t[r+1];t.length=i;}}(this.items,e),this.removeDestroyCallback(t),this},onChildDestroy:function(t,e){this.remove(t);},removeFirst:function(){return this.remove(void 0,0),this},removeLast:function(){return this.remove(void 0,this.item.length-1),this},removeMultiple:function(t){for(var e=t.length;e>0;e--)this.remove(t[e-1]);return this},clear:function(t){var e;if(t&&(e=this.cloneItems()),this.removeDestroyCallback(this.items),this.items.length=0,t)for(var i=e.length;i>0;i--)e[i].destroy();return this},clone:function(t){return t===this?this:(void 0===t&&(t=this.newList()),t.clear(),c(this.items,t.items),t.addDestroyCallback(t.items),t)},pop:function(t){void 0===t&&(t=0);var e=this.items[t];return this.remove(void 0,t),e},popFirst:function(){return this.pop(0)},popLast:function(){return this.pop(this.items.length-1)},popRandom:function(){var t=a(0,this.items.length-1);return this.pop(t)},slice:function(t,e,i){var n=this.items.slice(t,e+1);return void 0===i&&(i=this.newList()),i.clear(),c(n,i.items),i.addDestroyCallback(i.items),i},reverse:function(){return this.items.reverse(),this},sort:function(t){return this.items.sort(t),this},shuffle:function(){return function(t){for(var e=t.length-1;e>0;e--){var i=Math.floor(Math.random()*(e+1)),n=t[e];t[e]=t[i],t[i]=n;}}(this.items),this}},m={union:function(t,e){return this===t?this!==e&&(e=this.clone(e)):this===e?this.addMultiple(t.items):t===e?t.addMultiple(this.items):this.items.length>=t.items.length?(e=this.clone(e)).addMultiple(t.items):(e=t.clone(e)).addMultiple(this.items),e},intersect:function(t,e){if(this===t)this!==e&&(e=this.clone(e));else if(this===e){var i=c(this.items);this.clear();for(var n=0,r=i.length;n<r;n++)o=i[n],t.contains(o)&&this.add(o);}else if(t===e){var s=c(t.items);t.clear();for(n=0,r=i.length;n<r;n++)o=s[n],this.contains(o)&&t.add(o);}else if(e=this.newList(),this.items.length>=t.items.length)for(n=0,r=(s=t.items).length;n<r;n++)o=s[n],this.contains(o)&&e.add(o);else {var o;for(n=0,r=(i=this.items).length;n<r;n++)o=i[n],t.contains(o)&&e.add(o);}return e},difference:function(t,e){if(this===t)this===e?this.clear():e=this.newList();else if(this===e){var i=c(this.items);this.clear();for(var n=0,r=i.length;n<r;n++)o=i[n],t.contains(o)||this.add(o);}else if(t===e){var s=c(t.items);t.clear();for(n=0,r=i.length;n<r;n++)o=s[n],this.contains(o)||t.add(o);}else if(e=this.newList(),this.items.length>=t.items.length)for(n=0,r=(s=t.items).length;n<r;n++)o=s[n],this.contains(o)||e.add(o);else {var o;for(n=0,r=(i=this.items).length;n<r;n++)o=i[n],t.contains(o)||e.add(o);}return e}},p=function(){function i(n,r){e(this,i),function(e){if("object"!==t(e)||e.nodeType||e===e.window)return !1;try{if(e.constructor&&!{}.hasOwnProperty.call(e.constructor.prototype,"isPrototypeOf"))return !1}catch(t){return !1}return !0}(n)&&(n=h(r=n,"items",void 0)),this.items=[],this.setAutoCleanupEnable(h(r,"autoCleanup",!0)),n&&this.addMultiple(n);}return n(i,[{key:"destroy",value:function(t){this.clear(t),this.items=void 0;}},{key:"getItems",value:function(){return this.items}},{key:"cloneItems",value:function(t){return c(this.items,t)}},{key:"isList",value:function(t){return t instanceof i}},{key:"newList",value:function(t){return new i(t,{autoCleanup:this.autoCleanupEnable})}},{key:"length",get:function(){return this.items.length}},{key:"call",value:function(t,e){if(0===this.items.length)return this;if("string"==typeof t){var i,n=t;!function(t,e,i,n){void 0===i&&(i=0),void 0===n&&(n=e.length),t.length=n-i;for(var r=0,s=t.length;r<s;r++)t[r]=e[r+i];}(y,arguments,1);for(var r=0,s=this.items.length;r<s;r++)(i=this.items[r])[n].apply(i,y);y.length=0;}else for(r=0,s=this.items.length;r<s;r++)e?t.call(e,this.items[r],r):t(this.items[r],r);return this}}]),i}(),y=[];
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/return Object.assign(p.prototype,f,{contains:function(t){return -1!==this.items.indexOf(t)},any:function(t){for(var e=this.isList(t)?t.items:t,i=0,n=e;i<n;i++)if(this.contains(e[i]))return !0;return !1},all:function(t){for(var e=this.isList(t)?t.items:t,i=0,n=e;i<n;i++)if(!this.contains(e[i]))return !1;return !0}},d,m),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);}(r,Phaser.Plugins.BasePlugin);var i=u(r);function r(t){return e(this,r),i.call(this,t)}return n(r,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t){return new p(t)}}]),r}()}));