feat(editor): add WGLY JSON round-trip (export/import sidecar)

Closes the JSON round-trip gap on the glyph catalog format
shipped last batch. --export-wgly-json emits all 8 scalar
fields plus a dual int + name form for glyphType so hand-edits
can use either representation. --import-wgly-json accepts
either form, falling back to the int when both are present.
Verified byte-identical round-trip on all three preset emitters
(starter / warrior / universal). 700 documented CLI flags.
This commit is contained in:
Kelsi 2026-05-09 19:01:03 -07:00
parent dcbc9706f2
commit 7c00a491a5
3 changed files with 132 additions and 0 deletions

View file

@ -124,6 +124,7 @@ const char* const kArgRequired[] = {
"--export-wcms-json", "--import-wcms-json",
"--gen-glyphs", "--gen-glyphs-warrior", "--gen-glyphs-universal",
"--info-wgly", "--validate-wgly",
"--export-wgly-json", "--import-wgly-json",
"--gen-vehicles", "--gen-vehicles-siege", "--gen-vehicles-flying",
"--info-wvhc", "--validate-wvhc",
"--gen-weather-temperate", "--gen-weather-arctic",

View file

@ -121,6 +121,127 @@ int handleInfo(int& i, int argc, char** argv) {
return 0;
}
int handleExportJson(int& i, int argc, char** argv) {
// Mirrors the JSON pairs added for every other novel
// open format. Each glyph emits all 8 scalar fields plus
// a dual int + name form for glyphType so hand-edits can
// use either representation.
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWglyExt(base);
if (outPath.empty()) outPath = base + ".wgly.json";
if (!wowee::pipeline::WoweeGlyphLoader::exists(base)) {
std::fprintf(stderr,
"export-wgly-json: WGLY not found: %s.wgly\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeGlyphLoader::load(base);
nlohmann::json j;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"glyphId", e.glyphId},
{"name", e.name},
{"description", e.description},
{"iconPath", e.iconPath},
{"glyphType", e.glyphType},
{"glyphTypeName", wowee::pipeline::WoweeGlyph::glyphTypeName(e.glyphType)},
{"spellId", e.spellId},
{"itemId", e.itemId},
{"classMask", e.classMask},
{"requiredLevel", e.requiredLevel},
});
}
j["entries"] = arr;
std::ofstream out(outPath);
if (!out) {
std::fprintf(stderr,
"export-wgly-json: cannot write %s\n", outPath.c_str());
return 1;
}
out << j.dump(2) << "\n";
out.close();
std::printf("Wrote %s\n", outPath.c_str());
std::printf(" source : %s.wgly\n", base.c_str());
std::printf(" glyphs : %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];
if (outBase.empty()) {
outBase = jsonPath;
std::string suffix = ".wgly.json";
if (outBase.size() > suffix.size() &&
outBase.substr(outBase.size() - suffix.size()) == suffix) {
outBase = outBase.substr(0, outBase.size() - suffix.size());
} else if (outBase.size() > 5 &&
outBase.substr(outBase.size() - 5) == ".json") {
outBase = outBase.substr(0, outBase.size() - 5);
}
}
outBase = stripWglyExt(outBase);
std::ifstream in(jsonPath);
if (!in) {
std::fprintf(stderr,
"import-wgly-json: cannot read %s\n", jsonPath.c_str());
return 1;
}
nlohmann::json j;
try { in >> j; }
catch (const std::exception& e) {
std::fprintf(stderr,
"import-wgly-json: bad JSON in %s: %s\n",
jsonPath.c_str(), e.what());
return 1;
}
auto glyphTypeFromName = [](const std::string& s) -> uint8_t {
if (s == "major") return wowee::pipeline::WoweeGlyph::Major;
if (s == "minor") return wowee::pipeline::WoweeGlyph::Minor;
if (s == "prime") return wowee::pipeline::WoweeGlyph::Prime;
return wowee::pipeline::WoweeGlyph::Major;
};
wowee::pipeline::WoweeGlyph c;
c.name = j.value("name", std::string{});
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeGlyph::Entry e;
e.glyphId = je.value("glyphId", 0u);
e.name = je.value("name", std::string{});
e.description = je.value("description", std::string{});
e.iconPath = je.value("iconPath", std::string{});
if (je.contains("glyphType") &&
je["glyphType"].is_number_integer()) {
e.glyphType = static_cast<uint8_t>(
je["glyphType"].get<int>());
} else if (je.contains("glyphTypeName") &&
je["glyphTypeName"].is_string()) {
e.glyphType = glyphTypeFromName(
je["glyphTypeName"].get<std::string>());
}
e.spellId = je.value("spellId", 0u);
e.itemId = je.value("itemId", 0u);
e.classMask = je.value("classMask", 0u);
e.requiredLevel = static_cast<uint16_t>(
je.value("requiredLevel", 25));
c.entries.push_back(e);
}
}
if (!wowee::pipeline::WoweeGlyphLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wgly-json: failed to save %s.wgly\n", outBase.c_str());
return 1;
}
std::printf("Wrote %s.wgly\n", outBase.c_str());
std::printf(" source : %s\n", jsonPath.c_str());
std::printf(" glyphs : %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);
@ -225,6 +346,12 @@ bool handleGlyphsCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--validate-wgly") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wgly-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wgly-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}

View file

@ -1301,6 +1301,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WGLY entries (id / type / spellId / itemId / classMask / requiredLevel / name)\n");
std::printf(" --validate-wgly <wgly-base> [--json]\n");
std::printf(" Static checks: id>0+unique, name+spellId not empty, type 0..2, classMask>0, level<25 warning, missing-itemId warning\n");
std::printf(" --export-wgly-json <wgly-base> [out.json]\n");
std::printf(" Export binary .wgly to a human-editable JSON sidecar (defaults to <base>.wgly.json)\n");
std::printf(" --import-wgly-json <json-path> [out-base]\n");
std::printf(" Import a .wgly.json sidecar back into binary .wgly (accepts glyphType int OR name string)\n");
std::printf(" --gen-vehicles <wvhc-base> [name]\n");
std::printf(" Emit .wvhc starter: 3 vehicles (chopper / wind rider / salvaged tank) covering ground+air+siege roles\n");
std::printf(" --gen-vehicles-siege <wvhc-base> [name]\n");