UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 6.28 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexrestorabledataplugin=t();}(undefined,(function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,(n=i.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(n,"string"))?o:String(o)),i);}var n,o;}function i(e,t,i){return t&&r(e.prototype,t),i&&r(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&s(e,t);}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}function a(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e){var t=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(e){return !1}}();return function(){var r,i=o(e);if(t){var n=o(this).constructor;r=Reflect.construct(i,arguments,n);}else r=i.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return a(e)}(this,r)}}function l(){return l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var i=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=o(e)););return e}(e,t);if(i){var n=Object.getOwnPropertyDescriptor(i,t);return n.get?n.get.call(arguments.length<3?e:r):n.value}},l.apply(this,arguments)}var h=function(t){if("object"!==e(t)||null===t)return t;if(Array.isArray(t))t.length=0;else for(var r in t)delete t[r];return t},c=Phaser.Data.DataManager,f=Phaser.Utils.Objects.GetValue,v=Phaser.Events.EventEmitter,y=function(e){n(s,e);var r=u(s);function s(e,i,n){var o;t(this,s);var u=void 0===i;if(u&&(i=new v),o=r.call(this,e,i),u){var l=e.events?e.events:e;l&&l.once("destroy",o.destroy,a(o));}return o._recordEnable=!0,o.resetFromJSON(n),o.events.on("changedata",o.onValueChange,a(o)).on("setdata",(function(e,t,r){this.onValueChange(e,t,r,null);}),a(o)).on("removedata",(function(e,t,r){this.onValueChange(e,t,null,r);}),a(o)),o}return i(s,[{key:"resetFromJSON",value:function(e){this._version=f(e,"version",0),this._versionAlias=f(e,"versionAlias",""),this._repository=f(e,"repository",[]),this._versionAliases=f(e,"versionAliases",{});var t=f(e,"changeList",{}),r=f(e,"data",void 0);if(r)this._recordEnable=!1,this.set(r),this._recordEnable=!0;else {var i=""!==this._versionAlias?this._versionAlias:this._version;for(var n in this._version=0,this.restore(i),this._recordEnable=!1,t)this.setValue(n,t[n][0]);this._recordEnable=!0;}this._changeList=t;}},{key:"toJSON",value:function(e){void 0===e&&(e=!1);var t={version:this._version,versionAlias:this._versionAlias,changeList:this._changeList,repository:this._repository,versionAliases:this._versionAliases};return e&&(t.data=this.list),t}},{key:"version",get:function(){return this._version},set:function(e){var t;if("string"==typeof e&&(t=e,e=this._versionAliases[e]),"number"==typeof e){if(this._versionAlias=t||"",0===e)return this._recordEnable=!1,l(o(s.prototype),"reset",this).call(this),this._version=0,h(this._changeList),void(this._recordEnable=!0);e=Math.min(e,this._repository.length);var r,i={};for(var n in this._changeList)i[n]=this._changeList[n][1],delete this._changeList[n];if(this._version===e);else if(this._version<e)for(var a=this._version;a<e;a++)for(var n in r=this._repository[a])i[n]=r[n][0];else for(a=this._version-1;a>=e;a--)for(var n in r=this._repository[a])i[n]=r[n][1];for(var n in this._version=e,this._recordEnable=!1,i)null===(e=i[n])?this.removeValue(n):this.setValue(n,e);this._recordEnable=!0;}else this._versionAlias="";}},{key:"versionAlias",get:function(){return this._versionAlias}},{key:"lastVersion",get:function(){return this._repository.length}},{key:"versionAliases",get:function(){var e=[];for(var t in this._versionAliases)e.push(t);return e}},{key:"commit",value:function(e){for(var t in this._repository.length=this._version,this._versionAliases)this._versionAliases[t]>this._version&&delete this._versionAliases[t];return this._repository.push(this._changeList),this._changeList={},this._version++,"string"==typeof e&&(this._versionAlias=e,this._versionAliases[e]=this._version),this}},{key:"restore",value:function(e,t){return void 0===e&&(e=""!==this._versionAlias?this._versionAlias:this._version),void 0===t&&(t=!1),t&&(this.version=0),this.version=e,this}},{key:"reset",value:function(){return this.restore(0),this._repository.length=0,h(this._versionAliases),this}},{key:"onValueChange",value:function(e,t,r,i){this._recordEnable&&(this._changeList.hasOwnProperty(t)?this._changeList[t][0]=r:this._changeList[t]=[r,i]);}}]),s}(c);return function(e){n(o,Phaser.Plugins.BasePlugin);var r=u(o);function o(e){return t(this,o),r.call(this,e)}return i(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(e,t,r){return new y(e,t,r)}}]),o}()}));