feat(editor): WCST JSON round-trip closure

Adds --export-wcst-json / --import-wcst-json. Eight uint stat
fields per entry serialize as JSON ints; className field on
export is informational (classId is the authoritative key).
All 3 presets (warrior/mage/starting) byte-identical binary
roundtrip OK including the 9-entry starting-stats preset that
spans 9 different vanilla classes.

Live-tested monotonicity validator: hand-mutated Mage L20
baseStrength to 21 (below L10=22), validator correctly emitted:
"monotonicity: Mage baseStrength regresses from 22 (L10) to 21
(L20) — likely typo". The level-sorting + adjacent-pair walk
correctly identified the violation across the sparse 6-level
sample.

CLI flag count 1371 -> 1373.
This commit is contained in:
Kelsi 2026-05-10 04:10:57 -07:00
parent b66e41df87
commit fab32a1cff
3 changed files with 127 additions and 0 deletions

View file

@ -400,6 +400,7 @@ const char* const kArgRequired[] = {
"--export-wprt-json", "--import-wprt-json",
"--gen-cst-warrior", "--gen-cst-mage", "--gen-cst-starting",
"--info-wcst", "--validate-wcst",
"--export-wcst-json", "--import-wcst-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -295,6 +295,120 @@ int handleValidate(int& i, int argc, char** argv) {
return ok ? 0 : 1;
}
int handleExportJson(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string out;
if (parseOptArg(i, argc, argv)) out = argv[++i];
base = stripWcstExt(base);
if (out.empty()) out = base + ".wcst.json";
if (!wowee::pipeline::WoweeCombatStatsLoader::exists(base)) {
std::fprintf(stderr,
"export-wcst-json: WCST not found: %s.wcst\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeCombatStatsLoader::load(base);
nlohmann::json j;
j["magic"] = "WCST";
j["version"] = 1;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"statId", e.statId},
{"classId", e.classId},
{"className", classIdName(e.classId)},
{"level", e.level},
{"baseHealth", e.baseHealth},
{"baseMana", e.baseMana},
{"baseStrength", e.baseStrength},
{"baseAgility", e.baseAgility},
{"baseStamina", e.baseStamina},
{"baseIntellect", e.baseIntellect},
{"baseSpirit", e.baseSpirit},
{"baseArmor", e.baseArmor},
});
}
j["entries"] = arr;
std::ofstream os(out);
if (!os) {
std::fprintf(stderr,
"export-wcst-json: failed to open %s for write\n",
out.c_str());
return 1;
}
os << j.dump(2) << "\n";
std::printf("Wrote %s (%zu entries)\n",
out.c_str(), c.entries.size());
return 0;
}
int handleImportJson(int& i, int argc, char** argv) {
std::string in = argv[++i];
std::string outBase;
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
if (outBase.empty()) {
outBase = in;
if (outBase.size() >= 10 &&
outBase.substr(outBase.size() - 10) == ".wcst.json") {
outBase.resize(outBase.size() - 10);
} else {
stripExt(outBase, ".json");
stripExt(outBase, ".wcst");
}
}
std::ifstream is(in);
if (!is) {
std::fprintf(stderr,
"import-wcst-json: cannot open %s\n", in.c_str());
return 1;
}
nlohmann::json j;
try {
is >> j;
} catch (const std::exception& ex) {
std::fprintf(stderr,
"import-wcst-json: JSON parse error: %s\n", ex.what());
return 1;
}
wowee::pipeline::WoweeCombatStats c;
c.name = j.value("name", std::string{});
if (!j.contains("entries") || !j["entries"].is_array()) {
std::fprintf(stderr,
"import-wcst-json: missing or non-array 'entries'\n");
return 1;
}
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeCombatStats::Entry e;
e.statId = je.value("statId", 0u);
e.classId = static_cast<uint8_t>(je.value("classId", 0));
e.level = static_cast<uint8_t>(je.value("level", 0));
e.baseHealth = je.value("baseHealth", 0u);
e.baseMana = je.value("baseMana", 0u);
e.baseStrength = static_cast<uint16_t>(
je.value("baseStrength", 0));
e.baseAgility = static_cast<uint16_t>(
je.value("baseAgility", 0));
e.baseStamina = static_cast<uint16_t>(
je.value("baseStamina", 0));
e.baseIntellect = static_cast<uint16_t>(
je.value("baseIntellect", 0));
e.baseSpirit = static_cast<uint16_t>(
je.value("baseSpirit", 0));
e.baseArmor = je.value("baseArmor", 0u);
c.entries.push_back(e);
}
if (!wowee::pipeline::WoweeCombatStatsLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wcst-json: failed to save %s.wcst\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wcst (%zu entries)\n",
outBase.c_str(), c.entries.size());
return 0;
}
} // namespace
bool handleCombatStatsCatalog(int& i, int argc, char** argv,
@ -318,6 +432,14 @@ bool handleCombatStatsCatalog(int& i, int argc, char** argv,
i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wcst-json") == 0 &&
i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wcst-json") == 0 &&
i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}

View file

@ -2583,6 +2583,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WCST entries (statId / class / level / hp / mana / Str/Agi/Sta/Int/Spi / armor)\n");
std::printf(" --validate-wcst <wcst-base> [--json]\n");
std::printf(" Static checks: statId+classId+level required, classId 1..11, level 1..60, no zero baseHealth (player would die instantly), no duplicate statIds, no duplicate (classId,level) pairs (runtime stat-lookup tie); warns on classId 6/10 (DK/Monk gap unused in vanilla), Warrior/Rogue baseMana > 0 (these classes use Rage/Energy not mana — likely typo), and per-class monotonicity violations across all 8 stats (any stat regressing as level increases)\n");
std::printf(" --export-wcst-json <wcst-base> [out.json]\n");
std::printf(" Export binary .wcst to a human-editable JSON sidecar (defaults to <base>.wcst.json; emits classId as int + className string for readability)\n");
std::printf(" --import-wcst-json <json-path> [out-base]\n");
std::printf(" Import a .wcst.json sidecar back into binary .wcst (className field is informational; classId int is authoritative — round-trips per-class per-level stat tables byte-identical)\n");
std::printf(" --catalog-pluck <wXXX-file> <id> [--json]\n");
std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n");
std::printf(" --catalog-find <directory> <id> [--magic <WXXX>] [--json]\n");