phaser3-rex-plugins
Version:
9 lines (8 loc) • 37.2 kB
JavaScript
!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).rexcsvscenarioplugin=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 i(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(r=n.key,s=void 0,"symbol"==typeof(s=function(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(r,"string"))?s:String(s)),n);}var r,s;}function n(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(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&&a(e,t);}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function o(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 function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(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 i,n=s(e);if(t){var r=s(this).constructor;i=Reflect.construct(n,arguments,r);}else i=n.apply(this,arguments);return o(this,i)}}var h={setEventEmitter:function(e,t){return void 0===t&&(t=Phaser.Events.EventEmitter),this._privateEE=!0===e||void 0===e,this._eventEmitter=this._privateEE?new t:e,this},destroyEventEmitter:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(e){return this._eventEmitter&&e&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},l=function(e,t,i){if(e&&"number"!=typeof e){if(e.hasOwnProperty(t))return e[t];if(-1!==t.indexOf(".")){for(var n=t.split("."),r=e,s=i,a=0;a<n.length;a++){if(!r.hasOwnProperty(n[a])){s=i;break}s=r[n[a]],r=r[n[a]];}return s}return i}return i};
function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var f={exports:{}};
/* @license
Papa Parse
v5.4.1
https://github.com/mholt/PapaParse
License: MIT
*/!function(e,t){e.exports=function e(){var t="undefined"!=typeof self?self:"undefined"!=typeof window?window:void 0!==t?t:{},i=!t.document&&!!t.postMessage,n=t.IS_PAPA_WORKER||!1,r={},s=0,a={parse:function(i,n){var o=(n=n||{}).dynamicTyping||!1;if(k(o)&&(n.dynamicTypingFunction=o,o={}),n.dynamicTyping=o,n.transform=!!k(n.transform)&&n.transform,n.worker&&a.WORKERS_SUPPORTED){var u=function(){if(!a.WORKERS_SUPPORTED)return !1;var i,n,o=(i=t.URL||t.webkitURL||null,n=e.toString(),a.BLOB_URL||(a.BLOB_URL=i.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",n,")();"],{type:"text/javascript"})))),u=new t.Worker(o);return u.onmessage=v,u.id=s++,r[u.id]=u}();return u.userStep=n.step,u.userChunk=n.chunk,u.userComplete=n.complete,u.userError=n.error,n.step=k(n.step),n.chunk=k(n.chunk),n.complete=k(n.complete),n.error=k(n.error),delete n.worker,void u.postMessage({input:i,config:n,workerId:u.id})}var d=null;return a.NODE_STREAM_INPUT,"string"==typeof i?(i=function(e){return 65279===e.charCodeAt(0)?e.slice(1):e}(i),d=n.download?new h(n):new c(n)):!0===i.readable&&k(i.read)&&k(i.on)?d=new f(n):(t.File&&i instanceof File||i instanceof Object)&&(d=new l(n)),d.stream(i)},unparse:function(e,t){var i=!1,n=!0,r=",",s="\r\n",o='"',u=o+o,h=!1,l=null,c=!1;!function(){if("object"==typeof t){if("string"!=typeof t.delimiter||a.BAD_DELIMITERS.filter((function(e){return -1!==t.delimiter.indexOf(e)})).length||(r=t.delimiter),("boolean"==typeof t.quotes||"function"==typeof t.quotes||Array.isArray(t.quotes))&&(i=t.quotes),"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(h=t.skipEmptyLines),"string"==typeof t.newline&&(s=t.newline),"string"==typeof t.quoteChar&&(o=t.quoteChar),"boolean"==typeof t.header&&(n=t.header),Array.isArray(t.columns)){if(0===t.columns.length)throw new Error("Option columns is empty");l=t.columns;}void 0!==t.escapeChar&&(u=t.escapeChar+o),("boolean"==typeof t.escapeFormulae||t.escapeFormulae instanceof RegExp)&&(c=t.escapeFormulae instanceof RegExp?t.escapeFormulae:/^[=+\-@\t\r].*$/);}}();var f=new RegExp(p(o),"g");if("string"==typeof e&&(e=JSON.parse(e)),Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return d(null,e,h);if("object"==typeof e[0])return d(l||Object.keys(e[0]),e,h)}else if("object"==typeof e)return "string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields||l),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:"object"==typeof e.data[0]?Object.keys(e.data[0]):[]),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),d(e.fields||[],e.data||[],h);throw new Error("Unable to serialize unrecognized input");function d(e,t,i){var a="";"string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t));var o=Array.isArray(e)&&0<e.length,u=!Array.isArray(t[0]);if(o&&n){for(var h=0;h<e.length;h++)0<h&&(a+=r),a+=m(e[h],h);0<t.length&&(a+=s);}for(var l=0;l<t.length;l++){var c=o?e.length:t[l].length,f=!1,d=o?0===Object.keys(t[l]).length:0===t[l].length;if(i&&!o&&(f="greedy"===i?""===t[l].join("").trim():1===t[l].length&&0===t[l][0].length),"greedy"===i&&o){for(var p=[],v=0;v<c;v++){var g=u?e[v]:v;p.push(t[l][g]);}f=""===p.join("").trim();}if(!f){for(var y=0;y<c;y++){0<y&&!d&&(a+=r);var _=o&&u?e[y]:y;a+=m(t[l][_],y);}l<t.length-1&&(!i||0<c&&!d)&&(a+=s);}}return a}function m(e,t){if(null==e)return "";if(e.constructor===Date)return JSON.stringify(e).slice(1,25);var n=!1;c&&"string"==typeof e&&c.test(e)&&(e="'"+e,n=!0);var s=e.toString().replace(f,u);return (n=n||!0===i||"function"==typeof i&&i(e,t)||Array.isArray(i)&&i[t]||function(e,t){for(var i=0;i<t.length;i++)if(-1<e.indexOf(t[i]))return !0;return !1}(s,a.BAD_DELIMITERS)||-1<s.indexOf(r)||" "===s.charAt(0)||" "===s.charAt(s.length-1))?o+s+o:s}}};if(a.RECORD_SEP=String.fromCharCode(30),a.UNIT_SEP=String.fromCharCode(31),a.BYTE_ORDER_MARK="\ufeff",a.BAD_DELIMITERS=["\r","\n",'"',a.BYTE_ORDER_MARK],a.WORKERS_SUPPORTED=!i&&!!t.Worker,a.NODE_STREAM_INPUT=1,a.LocalChunkSize=10485760,a.RemoteChunkSize=5242880,a.DefaultDelimiter=",",a.Parser=m,a.ParserHandle=d,a.NetworkStreamer=h,a.FileStreamer=l,a.StringStreamer=c,a.ReadableStreamStreamer=f,t.jQuery){var o=t.jQuery;o.fn.parse=function(e){var i=e.config||{},n=[];return this.each((function(e){if("INPUT"!==o(this).prop("tagName").toUpperCase()||"file"!==o(this).attr("type").toLowerCase()||!t.FileReader||!this.files||0===this.files.length)return !0;for(var r=0;r<this.files.length;r++)n.push({file:this.files[r],inputElem:this,instanceConfig:o.extend({},i)});})),r(),this;function r(){if(0!==n.length){var t,i,r,u,h=n[0];if(k(e.before)){var l=e.before(h.file,h.inputElem);if("object"==typeof l){if("abort"===l.action)return t="AbortError",i=h.file,r=h.inputElem,u=l.reason,void(k(e.error)&&e.error({name:t},i,r,u));if("skip"===l.action)return void s();"object"==typeof l.config&&(h.instanceConfig=o.extend(h.instanceConfig,l.config));}else if("skip"===l)return void s()}var c=h.instanceConfig.complete;h.instanceConfig.complete=function(e){k(c)&&c(e,h.file,h.inputElem),s();},a.parse(h.file,h.instanceConfig);}else k(e.complete)&&e.complete();}function s(){n.splice(0,1),r();}};}function u(e){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(e){var t=_(e);t.chunkSize=parseInt(t.chunkSize),e.step||e.chunk||(t.chunkSize=null),this._handle=new d(t),(this._handle.streamer=this)._config=t;}.call(this,e),this.parseChunk=function(e,i){if(this.isFirstChunk&&k(this._config.beforeFirstChunk)){var r=this._config.beforeFirstChunk(e);void 0!==r&&(e=r);}this.isFirstChunk=!1,this._halted=!1;var s=this._partialLine+e;this._partialLine="";var o=this._handle.parse(s,this._baseIndex,!this._finished);if(!this._handle.paused()&&!this._handle.aborted()){var u=o.meta.cursor;this._finished||(this._partialLine=s.substring(u-this._baseIndex),this._baseIndex=u),o&&o.data&&(this._rowCount+=o.data.length);var h=this._finished||this._config.preview&&this._rowCount>=this._config.preview;if(n)t.postMessage({results:o,workerId:a.WORKER_ID,finished:h});else if(k(this._config.chunk)&&!i){if(this._config.chunk(o,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);o=void 0,this._completeResults=void 0;}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(o.data),this._completeResults.errors=this._completeResults.errors.concat(o.errors),this._completeResults.meta=o.meta),this._completed||!h||!k(this._config.complete)||o&&o.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),h||o&&o.meta.paused||this._nextChunk(),o}this._halted=!0;},this._sendError=function(e){k(this._config.error)?this._config.error(e):n&&this._config.error&&t.postMessage({workerId:a.WORKER_ID,error:e,finished:!1});};}function h(e){var t;(e=e||{}).chunkSize||(e.chunkSize=a.RemoteChunkSize),u.call(this,e),this._nextChunk=i?function(){this._readChunk(),this._chunkLoaded();}:function(){this._readChunk();},this.stream=function(e){this._input=e,this._nextChunk();},this._readChunk=function(){if(this._finished)this._chunkLoaded();else {if(t=new XMLHttpRequest,this._config.withCredentials&&(t.withCredentials=this._config.withCredentials),i||(t.onload=b(this._chunkLoaded,this),t.onerror=b(this._chunkError,this)),t.open(this._config.downloadRequestBody?"POST":"GET",this._input,!i),this._config.downloadRequestHeaders){var e=this._config.downloadRequestHeaders;for(var n in e)t.setRequestHeader(n,e[n]);}if(this._config.chunkSize){var r=this._start+this._config.chunkSize-1;t.setRequestHeader("Range","bytes="+this._start+"-"+r);}try{t.send(this._config.downloadRequestBody);}catch(e){this._chunkError(e.message);}i&&0===t.status&&this._chunkError();}},this._chunkLoaded=function(){4===t.readyState&&(t.status<200||400<=t.status?this._chunkError():(this._start+=this._config.chunkSize?this._config.chunkSize:t.responseText.length,this._finished=!this._config.chunkSize||this._start>=function(e){var t=e.getResponseHeader("Content-Range");return null===t?-1:parseInt(t.substring(t.lastIndexOf("/")+1))}(t),this.parseChunk(t.responseText)));},this._chunkError=function(e){var i=t.statusText||e;this._sendError(new Error(i));};}function l(e){var t,i;(e=e||{}).chunkSize||(e.chunkSize=a.LocalChunkSize),u.call(this,e);var n="undefined"!=typeof FileReader;this.stream=function(e){this._input=e,i=e.slice||e.webkitSlice||e.mozSlice,n?((t=new FileReader).onload=b(this._chunkLoaded,this),t.onerror=b(this._chunkError,this)):t=new FileReaderSync,this._nextChunk();},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk();},this._readChunk=function(){var e=this._input;if(this._config.chunkSize){var r=Math.min(this._start+this._config.chunkSize,this._input.size);e=i.call(e,this._start,r);}var s=t.readAsText(e,this._config.encoding);n||this._chunkLoaded({target:{result:s}});},this._chunkLoaded=function(e){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(e.target.result);},this._chunkError=function(){this._sendError(t.error);};}function c(e){var t;u.call(this,e=e||{}),this.stream=function(e){return t=e,this._nextChunk()},this._nextChunk=function(){if(!this._finished){var e,i=this._config.chunkSize;return i?(e=t.substring(0,i),t=t.substring(i)):(e=t,t=""),this._finished=!t,this.parseChunk(e)}};}function f(e){u.call(this,e=e||{});var t=[],i=!0,n=!1;this.pause=function(){u.prototype.pause.apply(this,arguments),this._input.pause();},this.resume=function(){u.prototype.resume.apply(this,arguments),this._input.resume();},this.stream=function(e){this._input=e,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError);},this._checkIsFinished=function(){n&&1===t.length&&(this._finished=!0);},this._nextChunk=function(){this._checkIsFinished(),t.length?this.parseChunk(t.shift()):i=!0;},this._streamData=b((function(e){try{t.push("string"==typeof e?e:e.toString(this._config.encoding)),i&&(i=!1,this._checkIsFinished(),this.parseChunk(t.shift()));}catch(e){this._streamError(e);}}),this),this._streamError=b((function(e){this._streamCleanUp(),this._sendError(e);}),this),this._streamEnd=b((function(){this._streamCleanUp(),n=!0,this._streamData("");}),this),this._streamCleanUp=b((function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError);}),this);}function d(e){var t,i,n,r=Math.pow(2,53),s=-r,o=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,u=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,h=this,l=0,c=0,f=!1,d=!1,v=[],g={data:[],errors:[],meta:{}};if(k(e.step)){var y=e.step;e.step=function(t){if(g=t,w())E();else {if(E(),0===g.data.length)return;l+=t.data.length,e.preview&&l>e.preview?i.abort():(g.data=g.data[0],y(g,h));}};}function b(t){return "greedy"===e.skipEmptyLines?""===t.join("").trim():1===t.length&&0===t[0].length}function E(){return g&&n&&(S("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+a.DefaultDelimiter+"'"),n=!1),e.skipEmptyLines&&(g.data=g.data.filter((function(e){return !b(e)}))),w()&&function(){if(g)if(Array.isArray(g.data[0])){for(var t=0;w()&&t<g.data.length;t++)g.data[t].forEach(i);g.data.splice(0,1);}else g.data.forEach(i);function i(t,i){k(e.transformHeader)&&(t=e.transformHeader(t,i)),v.push(t);}}(),function(){if(!g||!e.header&&!e.dynamicTyping&&!e.transform)return g;function t(t,i){var n,r=e.header?{}:[];for(n=0;n<t.length;n++){var s=n,a=t[n];e.header&&(s=n>=v.length?"__parsed_extra":v[n]),e.transform&&(a=e.transform(a,s)),a=C(s,a),"__parsed_extra"===s?(r[s]=r[s]||[],r[s].push(a)):r[s]=a;}return e.header&&(n>v.length?S("FieldMismatch","TooManyFields","Too many fields: expected "+v.length+" fields but parsed "+n,c+i):n<v.length&&S("FieldMismatch","TooFewFields","Too few fields: expected "+v.length+" fields but parsed "+n,c+i)),r}var i=1;return !g.data.length||Array.isArray(g.data[0])?(g.data=g.data.map(t),i=g.data.length):g.data=t(g.data,0),e.header&&g.meta&&(g.meta.fields=v),c+=i,g}()}function w(){return e.header&&0===v.length}function C(t,i){return n=t,e.dynamicTypingFunction&&void 0===e.dynamicTyping[n]&&(e.dynamicTyping[n]=e.dynamicTypingFunction(n)),!0===(e.dynamicTyping[n]||e.dynamicTyping)?"true"===i||"TRUE"===i||"false"!==i&&"FALSE"!==i&&(function(e){if(o.test(e)){var t=parseFloat(e);if(s<t&&t<r)return !0}return !1}(i)?parseFloat(i):u.test(i)?new Date(i):""===i?null:i):i;var n;}function S(e,t,i,n){var r={type:e,code:t,message:i};void 0!==n&&(r.row=n),g.errors.push(r);}this.parse=function(r,s,o){var u=e.quoteChar||'"';if(e.newline||(e.newline=function(e,t){e=e.substring(0,1048576);var i=new RegExp(p(t)+"([^]*?)"+p(t),"gm"),n=(e=e.replace(i,"")).split("\r"),r=e.split("\n"),s=1<r.length&&r[0].length<n[0].length;if(1===n.length||s)return "\n";for(var a=0,o=0;o<n.length;o++)"\n"===n[o][0]&&a++;return a>=n.length/2?"\r\n":"\r"}(r,u)),n=!1,e.delimiter)k(e.delimiter)&&(e.delimiter=e.delimiter(r),g.meta.delimiter=e.delimiter);else {var h=function(t,i,n,r,s){var o,u,h,l;s=s||[",","\t","|",";",a.RECORD_SEP,a.UNIT_SEP];for(var c=0;c<s.length;c++){var f=s[c],d=0,p=0,v=0;h=void 0;for(var g=new m({comments:r,delimiter:f,newline:i,preview:10}).parse(t),y=0;y<g.data.length;y++)if(n&&b(g.data[y]))v++;else {var _=g.data[y].length;p+=_,void 0!==h?0<_&&(d+=Math.abs(_-h),h=_):h=_;}0<g.data.length&&(p/=g.data.length-v),(void 0===u||d<=u)&&(void 0===l||l<p)&&1.99<p&&(u=d,o=f,l=p);}return {successful:!!(e.delimiter=o),bestDelimiter:o}}(r,e.newline,e.skipEmptyLines,e.comments,e.delimitersToGuess);h.successful?e.delimiter=h.bestDelimiter:(n=!0,e.delimiter=a.DefaultDelimiter),g.meta.delimiter=e.delimiter;}var l=_(e);return e.preview&&e.header&&l.preview++,t=r,i=new m(l),g=i.parse(t,s,o),E(),f?{meta:{paused:!0}}:g||{meta:{paused:!1}}},this.paused=function(){return f},this.pause=function(){f=!0,i.abort(),t=k(e.chunk)?"":t.substring(i.getCharIndex());},this.resume=function(){h.streamer._halted?(f=!1,h.streamer.parseChunk(t,!0)):setTimeout(h.resume,3);},this.aborted=function(){return d},this.abort=function(){d=!0,i.abort(),g.meta.aborted=!0,k(e.complete)&&e.complete(g),t="";};}function p(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function m(e){var t,i=(e=e||{}).delimiter,n=e.newline,r=e.comments,s=e.step,o=e.preview,u=e.fastMode,h=t=void 0===e.quoteChar||null===e.quoteChar?'"':e.quoteChar;if(void 0!==e.escapeChar&&(h=e.escapeChar),("string"!=typeof i||-1<a.BAD_DELIMITERS.indexOf(i))&&(i=","),r===i)throw new Error("Comment character same as delimiter");!0===r?r="#":("string"!=typeof r||-1<a.BAD_DELIMITERS.indexOf(r))&&(r=!1),"\n"!==n&&"\r"!==n&&"\r\n"!==n&&(n="\n");var l=0,c=!1;this.parse=function(a,f,d){if("string"!=typeof a)throw new Error("Input must be a string");var m=a.length,v=i.length,g=n.length,y=r.length,_=k(s),b=[],E=[],w=[],C=l=0;if(!a)return K();if(e.header&&!f){var S=a.split(n)[0].split(i),O=[],x={},R=!1;for(var L in S){var I=S[L];k(e.transformHeader)&&(I=e.transformHeader(I,L));var N=I,P=x[I]||0;for(0<P&&(R=!0,N=I+"_"+P),x[I]=P+1;O.includes(N);)N=N+"_"+P;O.push(N);}if(R){var T=a.split(n);T[0]=O.join(i),a=T.join(n);}}if(u||!1!==u&&-1===a.indexOf(t)){for(var A=a.split(n),F=0;F<A.length;F++){if(w=A[F],l+=w.length,F!==A.length-1)l+=n.length;else if(d)return K();if(!r||w.substring(0,y)!==r){if(_){if(b=[],J(w.split(i)),G(),c)return K()}else J(w.split(i));if(o&&o<=F)return b=b.slice(0,o),K(!0)}}return K()}for(var D=a.indexOf(i,l),j=a.indexOf(n,l),M=new RegExp(p(h)+p(t),"g"),U=a.indexOf(t,l);;)if(a[l]!==t)if(r&&0===w.length&&a.substring(l,l+y)===r){if(-1===j)return K();l=j+g,j=a.indexOf(n,l),D=a.indexOf(i,l);}else if(-1!==D&&(D<j||-1===j))w.push(a.substring(l,D)),l=D+v,D=a.indexOf(i,l);else {if(-1===j)break;if(w.push(a.substring(l,j)),W(j+g),_&&(G(),c))return K();if(o&&b.length>=o)return K(!0)}else for(U=l,l++;;){if(-1===(U=a.indexOf(t,U+1)))return d||E.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:b.length,index:l}),B();if(U===m-1)return B(a.substring(l,U).replace(M,t));if(t!==h||a[U+1]!==h){if(t===h||0===U||a[U-1]!==h){-1!==D&&D<U+1&&(D=a.indexOf(i,U+1)),-1!==j&&j<U+1&&(j=a.indexOf(n,U+1));var q=H(-1===j?D:Math.min(D,j));if(a.substr(U+1+q,v)===i){w.push(a.substring(l,U).replace(M,t)),a[l=U+1+q+v]!==t&&(U=a.indexOf(t,l)),D=a.indexOf(i,l),j=a.indexOf(n,l);break}var z=H(j);if(a.substring(U+1+z,U+1+z+g)===n){if(w.push(a.substring(l,U).replace(M,t)),W(U+1+z+g),D=a.indexOf(i,l),U=a.indexOf(t,l),_&&(G(),c))return K();if(o&&b.length>=o)return K(!0);break}E.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:b.length,index:l}),U++;}}else U++;}return B();function J(e){b.push(e),C=l;}function H(e){var t=0;if(-1!==e){var i=a.substring(U+1,e);i&&""===i.trim()&&(t=i.length);}return t}function B(e){return d||(void 0===e&&(e=a.substring(l)),w.push(e),l=m,J(w),_&&G()),K()}function W(e){l=e,J(w),w=[],j=a.indexOf(n,l);}function K(e){return {data:b,errors:E,meta:{delimiter:i,linebreak:n,aborted:c,truncated:!!e,cursor:C+(f||0)}}}function G(){s(K()),b=[],E=[];}},this.abort=function(){c=!0;},this.getCharIndex=function(){return l};}function v(e){var t=e.data,i=r[t.workerId],n=!1;if(t.error)i.userError(t.error,t.file);else if(t.results&&t.results.data){var s={abort:function(){n=!0,g(t.workerId,{data:[],errors:[],meta:{aborted:!0}});},pause:y,resume:y};if(k(i.userStep)){for(var a=0;a<t.results.data.length&&(i.userStep({data:t.results.data[a],errors:t.results.errors,meta:t.results.meta},s),!n);a++);delete t.results;}else k(i.userChunk)&&(i.userChunk(t.results,s,t.file),delete t.results);}t.finished&&!n&&g(t.workerId,t.results);}function g(e,t){var i=r[e];k(i.userComplete)&&i.userComplete(t),i.terminate(),delete r[e];}function y(){throw new Error("Not implemented.")}function _(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var i in e)t[i]=_(e[i]);return t}function b(e,t){return function(){e.apply(t,arguments);}}function k(e){return "function"==typeof e}return n&&(t.onmessage=function(e){var i=e.data;if(void 0===a.WORKER_ID&&i&&(a.WORKER_ID=i.workerId),"string"==typeof i.input)t.postMessage({workerId:a.WORKER_ID,results:a.parse(i.input,i.config),finished:!0});else if(t.File&&i.input instanceof File||i.input instanceof Object){var n=a.parse(i.input,i.config);n&&t.postMessage({workerId:a.WORKER_ID,results:n,finished:!0});}}),(h.prototype=Object.create(u.prototype)).constructor=h,(l.prototype=Object.create(u.prototype)).constructor=l,(c.prototype=Object.create(c.prototype)).constructor=c,(f.prototype=Object.create(u.prototype)).constructor=f,a}();}(f);var d=c(f.exports),p=function(t){if("object"!==e(t)||null===t)return t;if(Array.isArray(t))t.length=0;else for(var i in t)delete t[i];return t},m=function(e,t){var i=Array.isArray(e);if(void 0===t?t=i?[]:{}:p(t),i){t.length=e.length;for(var n=0,r=e.length;n<r;n++)t[n]=e[n];}else for(var s in e)t[s]=e[s];return t},v=Phaser.Utils.Objects.GetValue,g=function(){function e(i){t(this,e),this.scenario=i,this.queue=[],this.currentIdx=-1,this.nextIdx=0;}return n(e,[{key:"resetFromJSON",value:function(e){var t=v(e,"queue",void 0);return void 0===t?p(this.queue):m(t,this.queue),this.currentIdx=v(e,"curIdx",-1),this.nextIdx=v(e,"nextIdx",0),this}},{key:"clear",value:function(){return this.currentIdx=-1,this.nextIdx=0,this.queue.length=0,this}},{key:"append",value:function(e){return this.queue.push(e),this}},{key:"setNextIndex",value:function(e){return void 0===e&&(e=this.currentIdx+1),this.nextIdx=e,this}},{key:"get",value:function(e){return void 0===e&&(e=this.nextIdx),this.currentIdx=e,this.queue[e]}},{key:"length",get:function(){return this.queue.length}}]),e}(),y=function(){function e(i,n){t(this,e),this.scenario=i,this.type=n;}return n(e,[{key:"resetFromJSON",value:function(e){}},{key:"toJSON",value:function(){return {}}},{key:"parse",value:function(e,t){return e}},{key:"run",value:function(e){}}]),e}(),_=/^\s*-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?\s*$/i,b=/^0x[0-9A-F]+$/i,k=function(e){if("string"!=typeof e)return e;if(""===e)e=null;else if(_.test(e))e=parseFloat(e);else if(b.test(e))e=parseInt(e,16);else switch(e){case"false":e=!1;break;case"true":e=!0;break;case"null":e=null;break;case"undefined":e=void 0;}return e},E=function e(t,i,n){var r,s,a=l(n,"reverse",!1);if(s=t[0],"[object Array]"===Object.prototype.toString.call(s))if(a)for(o=(u=t.length)-1;o>=0;o--)r=e(t[o],i,n);else for(var o=0,u=t.length;o<u;o++)r=e(t[o],i,n);else r=w(t,i,n);return r},w=function(e,t,i){var n,r=l(i,"argsConvert",void 0),s=l(i,"argsConvertScope",void 0),a=e[0];if(C=function(e,t,i,n){void 0===i&&(i=0),void 0===n&&(n=t.length),e.length=n-i;for(var r=0,s=e.length;r<s;r++)e[r]=t[r+i];return e}(C,e,1),r){!0===r&&(r=k,s=void 0);for(var o=0,u=C.length;o<u;o++)C[o]=s?r.call(s,C[o],e):r(C[o],e);}return "string"==typeof a?null==(n=t[a])&&(n=l(t,a,null)):n=a,n.apply(t,C)},C=[],S=Phaser.Utils.Array.SpliceOne,O=function(e){r(s,e);var i=u(s);function s(e){var n;return t(this,s),(n=i.call(this,e,"-")).task=void 0,n.lastMethodName=void 0,n}return n(s,[{key:"resetFromJSON",value:function(e){this.task&&(this.task.off("complete",this.resume,this),this.task=void 0);}},{key:"parse",value:function(e,t){var i=S(e,0),n=this.scenario,r=n.argsConvert,s=n.argsConvertScope;if(r){!0===r&&(r=k,s=void 0);for(var a=1,o=e.length;a<o;a++)e[a]=s?r.call(s,e[a],e):r(e[a],e);}return e=[i,e]}},{key:"run",value:function(e){if(this.validate(e)){var t=e[1];this.lastMethodName=t[0];var i=E(t,this.scenario.scope);i&&"function"==typeof i.once?(i.once("complete",this.resume,this),this.pause(),this.task=i):this.task=void 0;}else this.scenario.error("Command '".concat(x(e),"' is not found in scope"));}},{key:"validate",value:function(e){var t=x(e);if(null===t)return !1;var i=this.scenario.scope,n=i[t];return null==n&&(n=l(i,t,null)),!!n}},{key:"pause",value:function(){this.scenario.pause();}},{key:"resume",value:function(){this.task=void 0;var e=this.scenario;e.resume(),e.runNextCmd();}}]),s}(y),x=function(e){var t=e[1];if(!t)return null;var i=t[0];return i||null},R=function(e){r(s,e);var i=u(s);function s(e){return t(this,s),i.call(this,e,"wait")}return n(s,[{key:"parse",value:function(e,t){e.length=2;var i=this.getEventName(e);return isNaN(i)||(e[1]=parseFloat(i)),e}},{key:"run",value:function(e){var t=this.getEventName(e);"number"==typeof t?this.waitTime(t):this.waitEvent(t);}},{key:"waitTime",value:function(e){e>this.scenario.offset?(e-=this.scenario.offset,this.scenario.offset=0,this.scenario.isDebugMode&&this.scenario.log("#WAIT: "+e),this.scenario.wait(e)):this.scenario.offset-=e;}},{key:"waitEvent",value:function(e){this.scenario.isDebugMode&&this.scenario.log("#WAIT: "+e),this.scenario.wait(e);}},{key:"getEventName",value:function(e){var t=e[1];return null==t&&(t="",e[1]=t),t}}]),s}(y),L=Phaser.Utils.Objects.GetValue,I=function(e){r(s,e);var i=u(s);function s(e){var n;return t(this,s),(n=i.call(this,e,"label")).labels={},n.prevLabel="",n.lastLabel="",n}return n(s,[{key:"resetFromJSON",value:function(e){this.prevLabel=L(e,"preLabel",""),this.lastLabel=L(e,"lastLabel","");var t=L(e,"labels",void 0);void 0===t?p(this.labels):m(t,this.labels);}},{key:"toJSON",value:function(){return {preLabel:this.prevLabel,lastLabel:this.lastLabel,labels:this.labels}}},{key:"parse",value:function(e,t){e.length=2;var i=this.getLabel(e);return this.addLabel(i,t),e}},{key:"run",value:function(e){var t=this.getLabel(e);this.scenario.isDebugMode&&this.scenario.log("#LABEL: "+t),this.prevLabel=this.lastLabel,this.lastLabel=t;var i=this.scenario;i.emit("labelchange",this.lastLabel,this.prevLabel,i.scope,i);}},{key:"getLabel",value:function(e){var t=e[1];return null==t&&(t="",e[1]=t),t}},{key:"addLabel",value:function(e,t){this.labels[e]=t;}},{key:"getIndex",value:function(e){return ""!==e&&this.hasLabel(e)?this.labels[e]:0}},{key:"hasLabel",value:function(e){return this.labels.hasOwnProperty(e)}}]),s}(y),N=function(e){r(s,e);var i=u(s);function s(e){return t(this,s),i.call(this,e,"exit")}return n(s,[{key:"parse",value:function(e,t){return e.length=1,e}},{key:"run",value:function(e){this.scenario.log("#EXIT"),this.scenario.complete();}}]),s}(y),P=function(e){r(s,e);var i=u(s);function s(e){return t(this,s),i.call(this,e,"goto")}return n(s,[{key:"parse",value:function(e,t){return e.length=2,e}},{key:"run",value:function(e){var t=this.getLabel(e);this.scenario.isDebugMode&&this.scenario.log("#GOTO label: "+t),this.scenario.goto(t);}},{key:"getLabel",value:function(e){var t=e[1];return null==t&&(t="",e[1]=t),t}}]),s}(y),T=function(e){r(s,e);var i=u(s);function s(e){return t(this,s),i.call(this,e,"if")}return n(s,[{key:"parse",value:function(e,t){e.length=4;var i="("+this.getCond(e)+")";return e[1]=new Function("return "+i),e}},{key:"run",value:function(e){var t=this.getCond(e).call(this.scenario.scope),i=t?this.getTrueLabel(e):this.getFalseLabel(e);""!==i&&(this.scenario.isDebugMode&&this.scenario.log("#IF "+t+"- GOTO label: "+i),this.scenario.goto(i));}},{key:"getCond",value:function(e){var t=e[1];return null!=t&&""!==t||(t="true",e[1]=t),t}},{key:"getTrueLabel",value:function(e){var t=e[2];return null==t&&(t="",e[2]=t),t}},{key:"getFalseLabel",value:function(e){var t=e[3];return null==t&&(t="",e[3]=t),t}}]),s}(y),A=Phaser.Utils.Objects.GetValue,F=function(){function e(i){t(this,e),this.cmds={"-":new O(i),wait:new R(i),label:new I(i),exit:new N(i),goto:new P(i),if:new T(i)};}return n(e,[{key:"resetFromJSON",value:function(e){for(var t in this.cmds)this.cmds[t].resetFromJSON(A(e,t,void 0));return this}},{key:"toJSON",value:function(){var e={};for(var t in this.cmds)e[t]=this.cmds[t].toJSON();return e}},{key:"get",value:function(e){return this.cmds[e]}},{key:"isValidCmdName",value:function(e){return this.cmds.hasOwnProperty(e)}}]),e}(),D=function(e){return function(e,t){return new Promise((function(i,n){e.once(t,(function(){i();}));}))}(e,"complete")},j=function(){function e(i,n){t(this,e),this.setEventEmitter(l(n,"eventEmitter",void 0)),this.scene=i,this.timer=void 0,this._timeScale=1,this.instMem=new g(this),this.cmdHandlers=new F(this),this.resetFromJSON(n),this.boot();}return n(e,[{key:"resetFromJSON",value:function(e){return this._inRunCmdLoop=!1,this.isRunning=l(e,"state",!1),this.isPaused=l(e,"pause",!1),this.waitEvent=l(e,"wait",void 0),this.scope=l(e,"scope",void 0),this.timeUnit=l(e,"timeUnit",0),this.cmdPrefix=l(e,"prefix",U),this.argsConvert=l(e,"argsConvert",!0),this.argsConvertScope=l(e,"argsConvertScope",void 0),this.cmdHandlers.resetFromJSON(l(e,"handlers",void 0)),this.instMem.resetFromJSON(l(e,"instMem",void 0)),this.delimiter=l(e,"delimiter",","),this.translateCommandNameCallback=l(e,"translateCommandNameCallback",void 0),this}},{key:"toJSON",value:function(){return {state:this.isRunning,pause:this.isPaused,wait:this.waitEvent,scope:this.scope,timeUnit:this.timeUnit,prefix:this.cmdPrefix,argsConvert:this.argsConvert,argsConvertScope:this.argsConvertScope,handlers:this.cmdHandlers.toJSON(),instMem:this.instMem.toJSON(),delimiter:this.delimiter}}},{key:"boot",value:function(){this.scene.sys.events.once("shutdown",this.destroy,this);}},{key:"shutdown",value:function(){this.scene&&(this.destroyEventEmitter(),this.clear(),this.scene.sys.events.off("shutdown",this.destroy,this),this.scene=void 0);}},{key:"destroy",value:function(){this.shutdown();}},{key:"load",value:function(e,t,i){return this.clear(),this.timeUnit=l(i,"timeUnit",this.timeUnit),"string"==typeof this.timeUnit&&(this.timeUnit=M[this.timeUnit]),this.cmdPrefix=l(i,"prefix",this.cmdPrefix),"string"==typeof this.cmdPrefix&&(this.cmdPrefix=new RegExp(this.cmdPrefix)),this.argsConvert=l(i,"argsConvert",this.argsConvert),this.argsConvertScope=l(i,"argsConvertScope",this.argsConvertScope),this.scope=t,this.delimiter=l(i,"delimiter",this.delimiter),this.translateCommandNameCallback=l(i,"translateCommandNameCallback",this.translateCommandNameCallback),this.append(e),this}},{key:"clear",value:function(){this.stop(),this.instMem.resetFromJSON(),this.cmdHandlers.resetFromJSON();}},{key:"start",value:function(e){this.stop();var t=l(e,"label","");return this.offset=l(e,"offset",0),this.isDebugMode&&this.log("Start at Label: "+t),!!this.goto(t)&&(this.isRunning=!0,this.runNextCmd(),!0)}},{key:"play",value:function(e){return this.start(e),this}},{key:"playPromise",value:function(e){var t=D(this);return this.start(e),t}},{key:"getIndex",value:function(e){var t=this.getCmdHandler("label").getIndex(e);return null==t&&this.error("Label: ".concat(e," is not found")),t}},{key:"goto",value:function(e){var t;return null!=(t="string"==typeof e?this.getIndex(e):e)&&(this.instMem.setNextIndex(t),!0)}},{key:"timeScale",get:function(){return this._timeScale},set:function(e){this._timeScale=e,this.timer&&(this.timer.timeScale=e);}},{key:"setTimeScale",value:function(e){return this.timeScale=e,this}},{key:"wait",value:function(e){if(this.waitEvent=e,"number"==typeof e){var t=e;1===this.timeUnit&&(t*=1e3),this.timer=this.scene.time.delayedCall(t,this.continue,[e],this),this.timer.timeScale=this._timeScale;}else this.emit("wait.".concat(e),this);return this.emit("wait",e,this),this}},{key:"stop",value:function(){return this.isRunning?(this.isRunning=!1,this.isPaused=!1,this.waitEvent=void 0,this.timer&&(this.timer.remove(),this.timer=void 0),this):this}},{key:"complete",value:function(){return this.emit("complete",this.scope,this),this.stop(),this}},{key:"append",value:function(e){var t=d.parse(e,{delimiter:this.delimiter}).data;return this.parse(t),this}},{key:"pause",value:function(){return this.isRunning?(this.isPaused||(this.isPaused=!0,this.timer&&(this.timer.paused=!0)),this):this}},{key:"resume",value:function(){return this.isRunning&&this.isPaused?(this.isPaused=!1,this.timer&&(this.timer.paused=!1),this):this}},{key:"continue",value:function(e){return !this.isRunning||this.isPaused||void 0===this.waitEvent||!0!==e&&e!==this.waitEvent||(this.waitEvent=void 0,this.timer&&(this.timer.remove(),this.timer=void 0),this.runNextCmd()),this}},{key:"lastLabel",get:function(){return this.cmdHandlers.cmds.label.lastLabel}},{key:"previousLabel",get:function(){return this.cmdHandlers.cmds.label.prevLabel}},{key:"lastCustomCommandName",get:function(){return this.cmdHandlers.cmds["-"].lastMethodName}},{key:"getCmdHandler",value:function(e){return "string"!=typeof e&&(e=e[0]),this.cmdHandlers.get(e)}},{key:"parse",value:function(e){for(var t,i,n=this.cmdPrefix,r=0,s=e.length;r<s;r++)if("-"===(i=(t=e[r])[0]))this.appendCustomCommand(t);else if(isNaN(i))if(n.test(i)){var a=i.match(n);t[0]=a[1].toLowerCase(),this.appendCommand(t)||this.error("Line ".concat(r,": ").concat(JSON.stringify(t)," is not a valid command"));}else this.appendCommand(["wait",i]),t[0]="-",this.appendCommand(t);else {var o=parseFloat(i);o>0&&this.appendCommand(["wait",o]),this.appendCustomCommand(t);}return this}},{key:"appendCommand",value:function(e){var t=this.getCmdHandler(e);return null!=t&&((e=t.parse(e,this.instMem.length))&&this.instMem.append(e),!0)}},{key:"appendCustomCommand",value:function(e){return e[0]="-",this.translateCommandNameCallback&&(e[1]=this.translateCommandNameCallback(e[1])),this.appendCommand(e)}},{key:"runNextCmd",value:function(){if(!this._inRunCmdLoop){var e,t=this.instMem;for(this._inRunCmdLoop=!0;this.isRunning&&!this.isPaused&&void 0===this.waitEvent;){if(e=t.get(),t.setNextIndex(),null==e){this.complete();break}this.getCmdHandler(e).run(e);}return this._inRunCmdLoop=!1,this}}},{key:"log",value:function(e){return this.emit("log",e,this.scope,this),this}},{key:"isDebugMode",get:function(){return this.listenerCount("log")>0}},{key:"error",value:function(e){return this.emit("error",e,this.scope,this),this}}]),e}();Object.assign(j.prototype,h);var M={ms:0,s:1,sec:1},U=/^#([a-zA-Z]+)/;return function(e){r(s,Phaser.Plugins.BasePlugin);var i=u(s);function s(e){return t(this,s),i.call(this,e)}return n(s,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(e,t){return new j(e,t)}}]),s}()}));