feat(editor): add WGEM JSON round-trip authoring workflow

Closes the WGEM open-format loop with --export-wgem-json /
--import-wgem-json, mirroring the JSON pairs added for
every other novel binary format. All 29 binary formats
added since WOL now have full JSON round-trip authoring.

Two top-level arrays mirror the binary layout:
  • gems[]         — gemId / itemIdToInsert / name / color
                      (dual int + name) / statType+Value /
                      requiredItemQuality / spellId
  • enchantments[] — enchantId / name / description / icon /
                      enchantSlot (dual int + name) /
                      statType+Value / spellId / duration /
                      chargeCount

Verified byte-identical round-trip on the enchants preset
(5 enchantments including 3 proc-based with WSPL spellId
cross-refs in the 28000-29000 placeholder range, plus
ring/cloak slot variants with chargeCount preserved).

Adds 2 flags (651 documented total now).
This commit is contained in:
Kelsi 2026-05-09 18:12:33 -07:00
parent 80ebf1dba5
commit d14f820a14
3 changed files with 179 additions and 0 deletions

View file

@ -103,6 +103,7 @@ const char* const kArgRequired[] = {
"--export-wmal-json", "--import-wmal-json",
"--gen-gems", "--gen-gems-set", "--gen-gems-enchants",
"--info-wgem", "--validate-wgem",
"--export-wgem-json", "--import-wgem-json",
"--gen-guilds", "--gen-guilds-full", "--gen-guilds-pair",
"--info-wgld", "--validate-wgld",
"--gen-weather-temperate", "--gen-weather-arctic",

View file

@ -154,6 +154,174 @@ 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. Two top-level arrays (gems / enchantments)
// mirror the binary layout. color and enchantSlot emit
// dual int + name forms.
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWgemExt(base);
if (outPath.empty()) outPath = base + ".wgem.json";
if (!wowee::pipeline::WoweeGemLoader::exists(base)) {
std::fprintf(stderr,
"export-wgem-json: WGEM not found: %s.wgem\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeGemLoader::load(base);
nlohmann::json j;
j["name"] = c.name;
nlohmann::json ga = nlohmann::json::array();
for (const auto& g : c.gems) {
ga.push_back({
{"gemId", g.gemId},
{"itemIdToInsert", g.itemIdToInsert},
{"name", g.name},
{"color", g.color},
{"colorName", wowee::pipeline::WoweeGem::colorName(g.color)},
{"statType", g.statType},
{"statValue", g.statValue},
{"requiredItemQuality", g.requiredItemQuality},
{"spellId", g.spellId},
});
}
j["gems"] = ga;
nlohmann::json ea = nlohmann::json::array();
for (const auto& e : c.enchantments) {
ea.push_back({
{"enchantId", e.enchantId},
{"name", e.name},
{"description", e.description},
{"iconPath", e.iconPath},
{"enchantSlot", e.enchantSlot},
{"enchantSlotName", wowee::pipeline::WoweeGem::enchantSlotName(e.enchantSlot)},
{"statType", e.statType},
{"statValue", e.statValue},
{"spellId", e.spellId},
{"durationSeconds", e.durationSeconds},
{"chargeCount", e.chargeCount},
});
}
j["enchantments"] = ea;
std::ofstream out(outPath);
if (!out) {
std::fprintf(stderr,
"export-wgem-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.wgem\n", base.c_str());
std::printf(" gems / ench : %zu / %zu\n",
c.gems.size(), c.enchantments.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 = ".wgem.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 = stripWgemExt(outBase);
std::ifstream in(jsonPath);
if (!in) {
std::fprintf(stderr,
"import-wgem-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-wgem-json: bad JSON in %s: %s\n",
jsonPath.c_str(), e.what());
return 1;
}
auto colorFromName = [](const std::string& s) -> uint8_t {
if (s == "meta") return wowee::pipeline::WoweeGem::Meta;
if (s == "red") return wowee::pipeline::WoweeGem::Red;
if (s == "yellow") return wowee::pipeline::WoweeGem::Yellow;
if (s == "blue") return wowee::pipeline::WoweeGem::Blue;
if (s == "purple") return wowee::pipeline::WoweeGem::Purple;
if (s == "green") return wowee::pipeline::WoweeGem::Green;
if (s == "orange") return wowee::pipeline::WoweeGem::Orange;
if (s == "prismatic") return wowee::pipeline::WoweeGem::Prismatic;
return wowee::pipeline::WoweeGem::Red;
};
auto slotFromName = [](const std::string& s) -> uint8_t {
if (s == "permanent") return wowee::pipeline::WoweeGem::Permanent;
if (s == "temporary") return wowee::pipeline::WoweeGem::Temporary;
if (s == "socket") return wowee::pipeline::WoweeGem::SocketColor;
if (s == "ring") return wowee::pipeline::WoweeGem::Ring;
if (s == "cloak") return wowee::pipeline::WoweeGem::Cloak;
return wowee::pipeline::WoweeGem::Permanent;
};
wowee::pipeline::WoweeGem c;
c.name = j.value("name", std::string{});
if (j.contains("gems") && j["gems"].is_array()) {
for (const auto& jg : j["gems"]) {
wowee::pipeline::WoweeGem::GemEntry g;
g.gemId = jg.value("gemId", 0u);
g.itemIdToInsert = jg.value("itemIdToInsert", 0u);
g.name = jg.value("name", std::string{});
if (jg.contains("color") && jg["color"].is_number_integer()) {
g.color = static_cast<uint8_t>(jg["color"].get<int>());
} else if (jg.contains("colorName") && jg["colorName"].is_string()) {
g.color = colorFromName(jg["colorName"].get<std::string>());
}
g.statType = static_cast<uint8_t>(jg.value("statType", 0));
g.statValue = static_cast<int16_t>(jg.value("statValue", 0));
g.requiredItemQuality = static_cast<uint8_t>(
jg.value("requiredItemQuality", 0));
g.spellId = jg.value("spellId", 0u);
c.gems.push_back(g);
}
}
if (j.contains("enchantments") && j["enchantments"].is_array()) {
for (const auto& je : j["enchantments"]) {
wowee::pipeline::WoweeGem::EnchantEntry e;
e.enchantId = je.value("enchantId", 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("enchantSlot") && je["enchantSlot"].is_number_integer()) {
e.enchantSlot = static_cast<uint8_t>(je["enchantSlot"].get<int>());
} else if (je.contains("enchantSlotName") &&
je["enchantSlotName"].is_string()) {
e.enchantSlot = slotFromName(je["enchantSlotName"].get<std::string>());
}
e.statType = static_cast<uint8_t>(je.value("statType", 0));
e.statValue = static_cast<int16_t>(je.value("statValue", 0));
e.spellId = je.value("spellId", 0u);
e.durationSeconds = je.value("durationSeconds", 0u);
e.chargeCount = static_cast<uint16_t>(je.value("chargeCount", 0));
c.enchantments.push_back(e);
}
}
if (!wowee::pipeline::WoweeGemLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wgem-json: failed to save %s.wgem\n", outBase.c_str());
return 1;
}
std::printf("Wrote %s.wgem\n", outBase.c_str());
std::printf(" source : %s\n", jsonPath.c_str());
std::printf(" gems / ench : %zu / %zu\n",
c.gems.size(), c.enchantments.size());
return 0;
}
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
@ -273,6 +441,12 @@ bool handleGemsCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--validate-wgem") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wgem-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wgem-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}

View file

@ -1203,6 +1203,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WGEM gems (id / color / stat / item) + enchantments (id / slot / stat / duration / charges)\n");
std::printf(" --validate-wgem <wgem-base> [--json]\n");
std::printf(" Static checks: ids>0+unique, name not empty, color/slot in range, stat-only entries need non-zero value\n");
std::printf(" --export-wgem-json <wgem-base> [out.json]\n");
std::printf(" Export binary .wgem to a human-editable JSON sidecar (defaults to <base>.wgem.json)\n");
std::printf(" --import-wgem-json <json-path> [out-base]\n");
std::printf(" Import a .wgem.json sidecar back into binary .wgem (accepts color/slot int OR name strings)\n");
std::printf(" --gen-guilds <wgld-base> [name]\n");
std::printf(" Emit .wgld starter: 1 guild (Sentinels of Dawn) with default 5-rank ladder + 3 members\n");
std::printf(" --gen-guilds-full <wgld-base> [name]\n");