UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 5.28 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).rexlocalstoragedataplugin=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 r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(o=r.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 r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(o,"string"))?i:String(i)),r);}var o,i;}function r(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(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);}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return 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 n,r=i(t);if(e){var o=i(this).constructor;n=Reflect.construct(r,arguments,o);}else n=r.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 a(t)}(this,n)}}var c=function(t,e){return e&&""!==e?"".concat(e,".").concat(t):t},f=function(t,e,n){n=JSON.stringify([n]),localStorage.setItem(c(t,e),n);},l=function(t,e){var n=localStorage.getItem(c(t,e));return null==n?void 0:n=JSON.parse(n)[0]},y=function(t,e){return localStorage.removeItem(c(t,e)),this},h={getStoreKey:function(t){return c(t,this.name)},getDataKey:function(t){return e=t,(n=this.name)&&""!==n?e.substring(n.length+1):e;var e,n;},setItem:function(t,e){return f(t,this.name,e),this},getItem:function(t){return l(t,this.name)},removeItem:function(t){return y(t,this.name),this}},d=function(){this.dataKeys.clear();var t=this.getItem("__keys__");if(t)for(var e=0,n=t.length;e<n;e++)this.dataKeys.set(t[e]);return this},v=Phaser.Utils.Objects.GetValue,p=Phaser.Structs.Set,m={load:function(t,e){if(void 0===t&&(e=!1),d.call(this),this.defaultData=t,this._syncEnable=!1,this.reset(),e||this.dataKeys.iterate((function(t,e){this.set(t,this.getItem(t));}),this),this._syncEnable=!0,t){var n,r;for(var o in t)n=void 0===(r=e?void 0:this.getItem(o))?t[o]:r,this.set(o,n);this.setItem("__keys__",this.dataKeys.entries);}return this},getDefaultValue:function(t){return this.defaultData?this.defaultData[t]:void 0}},b=function(e,n){if(e.hasOwnProperty("_syncEnable"))return e;if(e._syncEnable=!0,e.dataKeys=new p,e.defaultData=void 0,Object.assign(e,h,m),function(e){e.events.on("changedata",(function(e,n,r,o){this._syncEnable&&("object"!==t(r)&&r===o||(this.setItem(n,r),this.dataKeys.contains(n)||(this.dataKeys.set(n),this.setItem("__keys__",this.dataKeys.entries))));}),e).on("setdata",(function(t,e,n){this._syncEnable&&(this.setItem(e,n),this.dataKeys.set(e),this.setItem("__keys__",this.dataKeys.entries));}),e).on("removedata",(function(t,e,n){this._syncEnable&&(this.removeItem(e),this.dataKeys.delete(e),this.setItem("__keys__",this.dataKeys.entries));}),e);}(e),e.name=v(n,"name",""),v(n,"load",!0)){var r=v(n,"default",void 0),o=v(n,"reset",!1);e.load(r,o);}return e},g=Phaser.Data.DataManager,_=Phaser.Events.EventEmitter,O=Phaser.Utils.Objects.IsPlainObject,P=function(t){o(i,t);var n=u(i);function i(t,r,o){var s;e(this,i),O(t)?(o=t,t=void 0,r=void 0):O(r)&&(o=r,r=void 0);var u=void 0===r;if(u&&(r=new _),void 0===t&&(t=r),s=n.call(this,t,r),u){var c=t.events?t.events:t;c&&c.once("destroy",s.destroy,a(s));}return b(a(s),o),s}return r(i)}(g);return function(t){o(i,Phaser.Plugins.BasePlugin);var n=u(i);function i(t){return e(this,i),n.call(this,t)}return r(i,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e,n){return new P(t,e,n)}},{key:"extend",value:function(t,e){return b(t,e)}},{key:"setItem",value:function(t,e,n){return f(t,e,n),this}},{key:"getItem",value:function(t,e){return l(t,e)}},{key:"removeItem",value:function(t,e){return y(t,e),this}}]),i}()}));