fetch.open("GET", txtfile, false);
fetch.send();
+ function merge(obj, file) {
+ for (each in file) {
+ if (Array.isArray(obj[each]) && Array.isArray(file[each])) obj[each] = [ ...obj[each], ...file[each] ];
+ else if (Array.isArray(obj[each])) obj[each] = [ ...obj[each], file[each] ];
+ else if (Array.isArray(file[each])) obj[each] = [ obj[each], ...file[each] ];
+ else if (each in obj) obj[each] = [ obj[each], file[each] ];
+ else obj[each] = file[each];
+ }
+ }
+
var line, key, value, ref = this, section;
for (line of fetch.responseText.split('\n')) switch(true) {
+ // INCLUDE file
+ case /^INCLUDE .+$/.test(line):
+ //console.log("Including: " + line.split(/ /)[1]);
+ merge(ref, new Textfile(line.split(/ /)[1]));
+ break;
// section headers that always become array elements
case /^\[(npc|event|layer|dialog)\]$/.test(line):
section = line.split(/[\]\[]/)[1]; ref = {};
else if (!Array.isArray(this[section])) this[section] = [this[section],ref];
else if ( Array.isArray(this[section])) this[section].push(ref);
break;
+ // Clear section on empty line
+ case /^ *$/.test(line):
+ ref = this;
+ break;
// frame definition from animation files
// frame=#frame,direction,srcX,srcY,width,height,dstX,dstY
case /^frame=[0-9]+,[0-7](,[0-9-]+){6}$/.test(line):