Skip to content

Instantly share code, notes, and snippets.

@tashcan
Created January 8, 2024 01:28
Show Gist options
  • Save tashcan/48e8faef59f3bda519d569f3fe8089e7 to your computer and use it in GitHub Desktop.
Save tashcan/48e8faef59f3bda519d569f3fe8089e7 to your computer and use it in GitHub Desktop.
STFC Battle Journal Parse code
import fs from "fs";
const battleJson = JSON.parse(fs.readFileSync("battle.json"));
let readingAbilitiesApply = false;
let readingFTs = false;
let readingAttack = false;
let idx = 0;
while (idx < battleJson.length) {
const entry = battleJson[idx];
var skip = false;
switch (entry) {
case -96:
console.log("Round Start");
break;
case -90:
console.log("Sub round start");
break;
case -88:
console.log("Officer abilities apply start");
readingAbilitiesApply = true;
break;
case -86:
console.log("Officer ability apply start");
idx++;
var OfficerId = battleJson[idx];
idx++;
var AbilityId = battleJson[idx];
idx++;
var value = battleJson[idx];
break;
case -85:
console.log("Officer ability apply end");
break;
case -87:
console.log("Officer abilities apply end");
readingAbilitiesApply = false;
break;
case -84:
console.log("Forbidden techs apply start");
readingFTs = true;
break;
case -82:
console.log("Ft apply start");
idx++;
var FtId = battleJson[idx];
idx++;
var AbilityId = battleJson[idx];
idx++;
var value = battleJson[idx];
break;
case -81:
console.log("Ft apply end");
break;
case -83:
console.log("Forbidden techs apply end");
readingFTs = false;
break;
case -98:
console.log("Start attack");
readingAttack = true;
break;
case -95:
console.log("Charging");
idx++;
var charge = battleJson[idx];
break;
case -99:
console.log("End attack");
readingAttack = false;
break;
case -89:
console.log("Sub round end");
break;
case -97:
console.log("Round End");
break;
default:
if (readingAbilitiesApply) {
var OfficerAbilityAppliedShipId = entry;
} else if (readingFTs) {
idx++;
var ftShipId = battleJson[idx];
} else if (readingAttack) {
var weaponId = entry;
idx++;
var targetShip = battleJson[idx];
if (targetShip == -95) {
idx++;
var charge = battleJson[idx];
} else {
idx++;
var accuracy = battleJson[idx];
idx++;
var dodge = battleJson[idx];
idx++;
var missed = battleJson[idx];
idx++;
var crit = battleJson[idx];
idx++;
var hpdamage = battleJson[idx];
idx++;
var remainingHp = battleJson[idx];
idx++;
var shieldDamage = battleJson[idx];
idx++;
var remainingShield = battleJson[idx];
idx++;
var mitigatedDamage = battleJson[idx];
idx++;
var isoDamage = battleJson[idx];
idx++;
var isoMitigated = battleJson[idx];
}
} else {
var attackingShip = entry;
}
break;
}
if (!skip) {
idx++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment