feat(editor): add WSCT JSON round-trip (--export/--import-wsct-json)

Closes the editing loop on the spell-cast-time bucket catalog:
dump a .wsct to JSON, hand-edit baseCastMs / perLevelMs / clamp
bounds (retune a Pyroblast bucket from 3000ms to 2800ms across
every spell that references it), re-import to a byte-identical
binary. The exporter emits both castKind (int 0..4) and the
human-readable castKindName ("instant", "cast", "channel",
"delayed", "charge"); the importer accepts either.

Verified byte-identical round-trip on all three presets
(starter / channel / ramp). CLI flag count 897 -> 899.
This commit is contained in:
Kelsi 2026-05-09 21:38:56 -07:00
parent 8dcbd08a16
commit 479e96a68a
3 changed files with 149 additions and 0 deletions

View file

@ -211,6 +211,7 @@ const char* const kArgRequired[] = {
"--export-wsrg-json", "--import-wsrg-json",
"--gen-sct", "--gen-sct-channel", "--gen-sct-ramp",
"--info-wsct", "--validate-wsct",
"--export-wsct-json", "--import-wsct-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -1711,6 +1711,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WSCT entries (id / kind / baseMs / perLevelMs / minMs / maxMs / iconColor / name)\n");
std::printf(" --validate-wsct <wsct-base> [--json]\n");
std::printf(" Static checks: id+name required, castKind 0..4, baseMs>=0, min<=max, no duplicate ids; warns on Instant+nonzero base, errors on Channel+0 base\n");
std::printf(" --export-wsct-json <wsct-base> [out.json]\n");
std::printf(" Export binary .wsct to a human-editable JSON sidecar (defaults to <base>.wsct.json)\n");
std::printf(" --import-wsct-json <json-path> [out-base]\n");
std::printf(" Import a .wsct.json sidecar back into binary .wsct (accepts castKind int OR castKindName string)\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

@ -5,6 +5,7 @@
#include "pipeline/wowee_spell_cast_times.hpp"
#include <nlohmann/json.hpp>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstring>
@ -122,6 +123,143 @@ 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 = stripWsctExt(base);
if (!wowee::pipeline::WoweeSpellCastTimeLoader::exists(base)) {
std::fprintf(stderr,
"export-wsct-json: WSCT not found: %s.wsct\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeSpellCastTimeLoader::load(base);
if (outPath.empty()) outPath = base + ".wsct.json";
nlohmann::json j;
j["catalog"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
nlohmann::json je;
je["castTimeId"] = e.castTimeId;
je["name"] = e.name;
je["description"] = e.description;
je["castKind"] = e.castKind;
je["castKindName"] =
wowee::pipeline::WoweeSpellCastTime::castKindName(e.castKind);
je["baseCastMs"] = e.baseCastMs;
je["perLevelMs"] = e.perLevelMs;
je["minCastMs"] = e.minCastMs;
je["maxCastMs"] = e.maxCastMs;
je["iconColorRGBA"] = e.iconColorRGBA;
arr.push_back(je);
}
j["entries"] = arr;
std::ofstream os(outPath);
if (!os) {
std::fprintf(stderr,
"export-wsct-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(" buckets : %zu\n", c.entries.size());
return 0;
}
uint8_t parseCastKindToken(const nlohmann::json& jv,
uint8_t fallback) {
if (jv.is_number_integer() || jv.is_number_unsigned()) {
int v = jv.get<int>();
if (v < 0 || v > wowee::pipeline::WoweeSpellCastTime::ChargeCast)
return fallback;
return static_cast<uint8_t>(v);
}
if (jv.is_string()) {
std::string s = jv.get<std::string>();
for (auto& ch : s) ch = static_cast<char>(std::tolower(ch));
if (s == "instant") return wowee::pipeline::WoweeSpellCastTime::Instant;
if (s == "cast") return wowee::pipeline::WoweeSpellCastTime::Cast;
if (s == "channel") return wowee::pipeline::WoweeSpellCastTime::Channel;
if (s == "delayed" ||
s == "delayedcast") return wowee::pipeline::WoweeSpellCastTime::DelayedCast;
if (s == "charge" ||
s == "chargecast") return wowee::pipeline::WoweeSpellCastTime::ChargeCast;
}
return fallback;
}
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-wsct-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-wsct-json: parse error in %s: %s\n",
jsonPath.c_str(), ex.what());
return 1;
}
wowee::pipeline::WoweeSpellCastTime 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::WoweeSpellCastTime::Entry e;
if (je.contains("castTimeId")) e.castTimeId = je["castTimeId"].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>();
uint8_t kind = wowee::pipeline::WoweeSpellCastTime::Cast;
if (je.contains("castKind"))
kind = parseCastKindToken(je["castKind"], kind);
else if (je.contains("castKindName"))
kind = parseCastKindToken(je["castKindName"], kind);
e.castKind = kind;
if (je.contains("baseCastMs")) e.baseCastMs = je["baseCastMs"].get<int32_t>();
if (je.contains("perLevelMs")) e.perLevelMs = je["perLevelMs"].get<int32_t>();
if (je.contains("minCastMs")) e.minCastMs = je["minCastMs"].get<int32_t>();
if (je.contains("maxCastMs")) e.maxCastMs = je["maxCastMs"].get<int32_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 = ".wsct.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 = stripWsctExt(outBase);
if (!wowee::pipeline::WoweeSpellCastTimeLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wsct-json: failed to save %s.wsct\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wsct\n", outBase.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" buckets : %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);
@ -237,6 +375,12 @@ bool handleSpellCastTimesCatalog(int& i, int argc, char** argv,
if (std::strcmp(argv[i], "--validate-wsct") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wsct-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wsct-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}