+var gamedata = {};
+var gfx = {};
+
+function Textfile(txtfile) {
+ var lines, fetch = new XMLHttpRequest();
+ fetch.open("GET", txtfile, false);
+ fetch.send();
+
+ var line, key, value, ref = this, section;
+ for (line of fetch.responseText.split('\n')) switch(true) {
+ case /^\[.*\]$/.test(line):
+ section = line.split(/[\]\[]/)[1];
+ if (!this[section]) this[section] = {};
+ else if (!Array.isArray(this[section])) this[section] = [this[section],{}];
+ else if ( Array.isArray(this[section])) this[section].push({});
+ ref = this[section];
+ break;
+ case /^frame=[0-9]+,[0-7](,[0-9-]+){6}$/.test(line):
+ key = line.split(/[=,]/).slice(1,3); value = line.split(/,/).slice(-6);
+ if (!ref.frame) ref.frame = [];
+ if (!ref.frame[key[0]]) ref.frame[key[0]] = [];
+ ref.frame[key[0]][key[1]] = value;
+ break;
+ case /^layer=[0-9]+,/.test(line):
+ key = line.split(/[=,]/)[1]; value = line.split(/,/).slice(1);
+ if (!ref.layer) ref.layer = [];
+ ref.layer[key] = value;
+ break;
+ case /^duration=[0-9]+ms$/.test(line):
+ ref["duration"] = parseInt(line.split(/=|ms$/)[1]);
+ break;
+ case /^duration=[0-9]+s$/.test(line):
+ ref["duration"] = parseInt(line.split(/=|s$/)[1]) * 1000;
+ break;
+ case /^[^#].*=.+$/.test(line):
+ key = line.split(/[=]/)[0]; value = line.split(/=/).slice(1).join("=");
+ if (!ref[key]) ref[key] = value;
+ else if (!Array.isArray(ref[key])) ref[key] = [ref[key],value];
+ else if ( Array.isArray(ref[key])) ref[key].push(value);
+ break;
+ }
+}
+