phaser4-rex-plugins
Version:
2 lines (1 loc) • 2.53 kB
JavaScript
var t,r;t=void 0,r=function(){class t{constructor(t){this.buf=t,this.lastPointer=this.buf.length,this.pointer=0}seek(t){return this.pointer=t,this}seekBack(t){return this.pointer-=t,this}seekForward(t){return this.pointer+=t,this}readUint8(){var t=this.buf[this.pointer];return this.pointer++,t}readUint32(t){return void 0===t&&(t=!1),function(t,r,e,i,n){return void 0===n&&(n=!1),n?t<<24|r<<16|e<<8|i:t|r<<8|e<<16|i<<24}(this.readUint8(),this.readUint8(),this.readUint8(),this.readUint8(),t)}readString(t){for(var r="",e=0;e<t;e++)r+=String.fromCharCode(this.readUint8());return r}readUint8Array(t){var r;return r=void 0!==t?this.buf.slice(this.pointer,this.pointer+t):this.buf.slice(this.pointer),this.pointer+=r.length,r}get outOfArray(){return this.pointer>=this.lastPointer}}var r=function(r,e){var i;for((i=r instanceof t?r:new t(r)).seek(8);!i.outOfArray;){var n=i.readUint32(!0);if(e===i.readString(4))return i.pointer+n+4;i.seekForward(n+4)}return-1};class e{constructor(t){this.buf=new Uint8Array(t),this.pointer=0}seek(t){return this.pointer=t,this}writeUint8(t){return this.buf[this.pointer]=t,this.pointer++,this}writeUint8Array(t){return this.buf.set(t,this.pointer),this.pointer+=t.length,this}writeUint32(t,r){var e=function(t,r,e){return void 0===r&&(r=!1),void 0===e&&(e=[]),e.length=4,r?(e[0]=t>>24&255,e[1]=t>>16&255,e[2]=t>>8&255,e[3]=255&t):(e[0]=255&t,e[1]=t>>8&255,e[2]=t>>16&255,e[3]=t>>24&255),e}(t,r);return this.writeUint8Array(e),this}writeString(t){var r=(new TextEncoder).encode(t);return this.writeUint8Array(r),this}get outOfArray(){return this.pointer===this.buf.length}}var i={append:function(t,i){var n,s=r(t,"IEND"),o="object"==typeof obj&&obj.constructor===Uint8Array,a=o?1:0;o?n=i:null!=i?(i=JSON.stringify(i),n=(new TextEncoder).encode(i)):n=new Uint8Array(0);var u=s+8+n.length;return new e(u).writeUint8Array(t.slice(0,s)).writeUint32(a).writeUint32(0).writeUint8Array(n).buf},extract:function(e){var i=new t(e),n=r(i,"IEND");if(i.seek(n),i.outOfArray)return null;var s=15&i.readUint32();i.readUint32();var o=i.readUint8Array();if(0===s){if(0===o.length)return null;o=(new TextDecoder).decode(o),o=JSON.parse(o)}return o}};class n extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}}return Object.assign(n.prototype,i),n},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).rexpngappenderplugin=r();