summaryrefslogtreecommitdiff
path: root/js/mv/parse.js
diff options
context:
space:
mode:
authorFreeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace>2013-04-13 18:10:51 +1200
committerFreeyorp <TheFreeYorp@NOSPAM.G.m.a.i.l.replace>2013-04-13 18:20:57 +1200
commit8f34d7e6ce1142af2171d9ec31e20e9738c8223f (patch)
tree3469c004607cac366bda99d40365dbb8295b8029 /js/mv/parse.js
parent35209fb4ddf117fa0cbde1eef4cff1fb45dfc24f (diff)
downloadmanavis-8f34d7e6ce1142af2171d9ec31e20e9738c8223f.tar.gz
manavis-8f34d7e6ce1142af2171d9ec31e20e9738c8223f.tar.bz2
manavis-8f34d7e6ce1142af2171d9ec31e20e9738c8223f.tar.xz
manavis-8f34d7e6ce1142af2171d9ec31e20e9738c8223f.zip
Refactor mv.js into distinct modules
There are five modules, as follows: load.js handles initialisation and management of files parse.js handles initialisation and management of records heap.js handles initialisation and management of dimensions chart.js handles initialisation and management of charts main.js manages the other modules and status Status and file loading have been decoupled; file loading no longer directly updates the status of the progress bars. This makes the limitations of the current status system more apparent, and should make the system also easier to maintain, as progress bars are now updated at more logical times. The parser remains mostly unchanged. It will need to be altered into a full stateful parser, but this can happen later. Dimension management is now simplified, due to the addition of monoGroup. Most dimension/groups consisted of a single dimension and a group reduced by count. This convenience function combines these and unifies their access, beyond mere naming convention. Charting management is also greatly simplified, adding in chain helpers to categorise types of charts, by aspects such as being wide, being thin, being short, as well as helpers to establish common properties for bar and pie charts. There is now also a helper to take advantage of the unified monoGroup accessors.
Diffstat (limited to 'js/mv/parse.js')
-rw-r--r--js/mv/parse.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/js/mv/parse.js b/js/mv/parse.js
new file mode 100644
index 0000000..23a0f79
--- /dev/null
+++ b/js/mv/parse.js
@@ -0,0 +1,86 @@
+var mv = function(mv) {
+ mv.parser = function() {
+ var parser = {};
+ var pcstat = {};
+ var fullyDefinedCutoff = 0;
+ parser.records = [];
+ parser.fullyDefinedCutoff = function() { return fullyDefinedCutoff; };
+ parser.parseRecords = function(data) {
+ var spl = data.split(/\r?\n/);
+ spl.forEach(function(e, i) {
+ var d;
+ d = e.match(/^(\d+\.\d+) PC(\d+) (\d+):(\d+),(\d+) GAINXP (\d+) (\d+) (\w+)/);
+ if (d) {
+ var mapSID = parseInt(d[3]);
+ var ts = new Date(0);
+ ts.setUTCSeconds(d[1]);
+ var rec = {
+ date: ts,
+ pc: parseInt(d[2]),
+ map: map.nameByServerID(parseInt(d[3]), ts),
+ x: parseInt(d[4]),
+ y: parseInt(d[5]),
+ e: parseInt(d[6]),
+ j: parseInt(d[7]),
+ type: d[8],
+ pcstat: pcstat[d[2]],
+ target: 0,
+ dmg: 0,
+ wpn: 0
+ };
+ if (pcstat[d[2]] == undefined && (!fullyDefinedCutoff || ts > fullyDefinedCutoff)) {
+ fullyDefinedCutoff = ts;
+ }
+ /* XXX: Fragile horrible and unstructured, this whole thing needs a rewrite really */
+ if (i >= 2 && rec.type == "KILLXP") {
+ d = spl[i - 1].match(/^(\d+\.\d+) MOB(\d+) DEAD/);
+ if (d) {
+ var mID = parseInt(d[2]);
+ /* There's a massive wealth of data that can be collected from this. Number of assailants, weapons used, the relationships with the assailants... this can't be done with a simple lookbehind. For now, just extract what mob it was, and what the killing weapon used was. */
+ d = spl[i - 2].match(/^(\d+\.\d+) PC(\d+) (\d+):(\d+),(\d+) WPNDMG MOB(\d+) (\d+) FOR (\d+) WPN (\d+)/);
+ if (d) {
+ softAssert(mID == parseInt(d[6]), "Integrity error: MOB ID mismatch!");
+ // softAssert(rec.pc == parseInt(d[2]), "Integrity error: PC ID mismatch!");
+ rec.target = parseInt(d[7]);
+ rec.dmg = parseInt(d[8]);
+ rec.wpn = parseInt(d[9]);
+ }
+ } else {
+ d = spl[i - 1].match(/^(\d+\.\d+) PC(\d+) (\d+):(\d+),(\d+) GAINXP (\d+) (\d+) (\w+)/);
+ if (d) {
+ var clone = parser.records[parser.records.length - 1];
+ softAssert(rec.map == clone.map, "Integrity error: MAP ID mismatch!");
+ rec.target = clone.target;
+ rec.dmg = clone.dmg; /* FIXME: Take into account actual assist damage */
+ rec.wpn = clone.wpn;
+ }
+ }
+ }
+ parser.records.push(rec);
+ return;
+ }
+ d = e.match(/^(?:\d+\.\d+) PC(\d+) (?:\d+):(?:\d+),(?:\d+) STAT (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) /);
+ if (d) {
+ var s = {
+ str: parseInt(d[2]),
+ agi: parseInt(d[3]),
+ vit: parseInt(d[4]),
+ int: parseInt(d[5]),
+ dex: parseInt(d[6]),
+ luk: parseInt(d[7])
+ };
+ s.blvl = stat.minLevelForStats(s.str, s.agi, s.vit, s.int, s.dex, s.luk);
+ pcstat[d[1]] = s;
+ return;
+ }
+ });
+ };
+ function softAssert(expr, msg) {
+ if (!expr) {
+ console.error("SOFTASSERT FAILURE: " + msg);
+ }
+ }
+ return parser;
+ }();
+ return mv;
+}(mv || {});