feat(editor): add WSTC JSON round-trip (--export/--import-wstc-json)

Closes the editing loop on the hunter-stable-slot catalog: dump
a .wstc to JSON, hand-edit displayOrder / minLevelToUnlock /
copperCost / isPremium (e.g. lower the lvl 50 stable slot 4
unlock to lvl 45, mark slot 5 as premium for a donor server,
raise slot 3 cost from 2g to 5g for a tighter economy),
re-import to a byte-identical binary.

isPremium dual-encoded: bool OR int (machine-generated sidecars
work too). All other fields are scalar so no special handling
needed.

Verified byte-identical round-trip on all three presets
(std / cata / premium). CLI flag count 1074 -> 1076.
This commit is contained in:
Kelsi 2026-05-10 00:00:43 -07:00
parent 8f6f6ac91e
commit 68c20bd152
3 changed files with 122 additions and 0 deletions

View file

@ -287,6 +287,7 @@ const char* const kArgRequired[] = {
"--export-whld-json", "--import-whld-json",
"--gen-stc", "--gen-stc-cata", "--gen-stc-premium",
"--info-wstc", "--validate-wstc",
"--export-wstc-json", "--import-wstc-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -2065,6 +2065,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WSTC entries (id / displayOrder / minLevelToUnlock / cost (formatted) / premium flag / name)\n");
std::printf(" --validate-wstc <wstc-base> [--json]\n");
std::printf(" Static checks: id+name required, no duplicate ids; warns on lvl>80 (unreachable), Premium+nonzero cost (donor slots are free), duplicate displayOrder (UI collision)\n");
std::printf(" --export-wstc-json <wstc-base> [out.json]\n");
std::printf(" Export binary .wstc to a human-editable JSON sidecar (defaults to <base>.wstc.json)\n");
std::printf(" --import-wstc-json <json-path> [out-base]\n");
std::printf(" Import a .wstc.json sidecar back into binary .wstc (isPremium accepts bool OR int)\n");
std::printf(" --gen-weather-temperate <wow-base> [zoneName]\n");
std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n");
std::printf(" --gen-weather-arctic <wow-base> [zoneName]\n");

View file

@ -130,6 +130,117 @@ int handleInfo(int& i, int argc, char** argv) {
return 0;
}
int handleExportJson(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWstcExt(base);
if (!wowee::pipeline::WoweeStableSlotLoader::exists(base)) {
std::fprintf(stderr,
"export-wstc-json: WSTC not found: %s.wstc\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeStableSlotLoader::load(base);
if (outPath.empty()) outPath = base + ".wstc.json";
nlohmann::json j;
j["catalog"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
nlohmann::json je;
je["slotId"] = e.slotId;
je["name"] = e.name;
je["description"] = e.description;
je["displayOrder"] = e.displayOrder;
je["minLevelToUnlock"] = e.minLevelToUnlock;
je["isPremium"] = e.isPremium != 0;
je["copperCost"] = e.copperCost;
je["iconColorRGBA"] = e.iconColorRGBA;
arr.push_back(je);
}
j["entries"] = arr;
std::ofstream os(outPath);
if (!os) {
std::fprintf(stderr,
"export-wstc-json: failed to open %s for write\n",
outPath.c_str());
return 1;
}
os << j.dump(2) << "\n";
std::printf("Wrote %s\n", outPath.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" slots : %zu\n", c.entries.size());
return 0;
}
int handleImportJson(int& i, int argc, char** argv) {
std::string jsonPath = argv[++i];
std::string outBase;
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
std::ifstream is(jsonPath);
if (!is) {
std::fprintf(stderr,
"import-wstc-json: failed to open %s\n", jsonPath.c_str());
return 1;
}
nlohmann::json j;
try {
is >> j;
} catch (const std::exception& ex) {
std::fprintf(stderr,
"import-wstc-json: parse error in %s: %s\n",
jsonPath.c_str(), ex.what());
return 1;
}
wowee::pipeline::WoweeStableSlot c;
if (j.contains("catalog") && j["catalog"].is_string())
c.name = j["catalog"].get<std::string>();
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeStableSlot::Entry e;
if (je.contains("slotId")) e.slotId = je["slotId"].get<uint32_t>();
if (je.contains("name")) e.name = je["name"].get<std::string>();
if (je.contains("description")) e.description = je["description"].get<std::string>();
if (je.contains("displayOrder")) e.displayOrder = je["displayOrder"].get<uint8_t>();
if (je.contains("minLevelToUnlock")) e.minLevelToUnlock = je["minLevelToUnlock"].get<uint8_t>();
if (je.contains("isPremium")) {
if (je["isPremium"].is_boolean())
e.isPremium = je["isPremium"].get<bool>() ? 1 : 0;
else
e.isPremium = je["isPremium"].get<uint8_t>() ? 1 : 0;
}
if (je.contains("copperCost")) e.copperCost = je["copperCost"].get<uint32_t>();
if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get<uint32_t>();
c.entries.push_back(e);
}
}
if (outBase.empty()) {
outBase = jsonPath;
const std::string suffix1 = ".wstc.json";
const std::string suffix2 = ".json";
if (outBase.size() >= suffix1.size() &&
outBase.compare(outBase.size() - suffix1.size(),
suffix1.size(), suffix1) == 0) {
outBase.resize(outBase.size() - suffix1.size());
} else if (outBase.size() >= suffix2.size() &&
outBase.compare(outBase.size() - suffix2.size(),
suffix2.size(), suffix2) == 0) {
outBase.resize(outBase.size() - suffix2.size());
}
}
outBase = stripWstcExt(outBase);
if (!wowee::pipeline::WoweeStableSlotLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wstc-json: failed to save %s.wstc\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wstc\n", outBase.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" slots : %zu\n", c.entries.size());
return 0;
}
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
@ -241,6 +352,12 @@ bool handleStableSlotsCatalog(int& i, int argc, char** argv,
if (std::strcmp(argv[i], "--validate-wstc") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wstc-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wstc-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}