From 650651ee2b69fea5ef856ca890d01976b64c2905 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 18:20:43 -0700 Subject: [PATCH] feat(editor): add WGLD JSON round-trip authoring workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes the WGLD open-format loop with --export-wgld-json / --import-wgld-json, mirroring the JSON pairs added for every other novel binary format. All 30 binary formats added since WOL now have full JSON round-trip authoring. Each guild round-trips header scalars (12 fields) plus the 4 sub-arrays: • ranks[] — rank ladder with permissions + money cap • members[] — character roster with rank + notes • bankTabs[] — per-tab name + 3 permission masks • perks[] — purchased buffs with WSPL spell refs factionId emits dual int + name forms (alliance / horde). Verified byte-identical round-trip on the full preset (1 guild with 6 ranks + 8 members + 4 bank tabs + 3 perks; all permission masks and per-rank money caps preserved through the JSON layer). Adds 2 flags (658 documented total now). --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_guilds_catalog.cpp | 215 ++++++++++++++++++++++++++++ tools/editor/cli_help.cpp | 4 + 3 files changed, 220 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index fe37d8bb..3c59ae1d 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -106,6 +106,7 @@ const char* const kArgRequired[] = { "--export-wgem-json", "--import-wgem-json", "--gen-guilds", "--gen-guilds-full", "--gen-guilds-pair", "--info-wgld", "--validate-wgld", + "--export-wgld-json", "--import-wgld-json", "--gen-conditions", "--gen-conditions-gated", "--gen-conditions-event", "--info-wpcd", "--validate-wpcd", "--gen-weather-temperate", "--gen-weather-arctic", diff --git a/tools/editor/cli_guilds_catalog.cpp b/tools/editor/cli_guilds_catalog.cpp index 6061e7e2..572dbf10 100644 --- a/tools/editor/cli_guilds_catalog.cpp +++ b/tools/editor/cli_guilds_catalog.cpp @@ -172,6 +172,215 @@ 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 guild emits header scalars plus the + // ranks / members / bankTabs / perks sub-arrays. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWgldExt(base); + if (outPath.empty()) outPath = base + ".wgld.json"; + if (!wowee::pipeline::WoweeGuildLoader::exists(base)) { + std::fprintf(stderr, + "export-wgld-json: WGLD not found: %s.wgld\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeGuildLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["guildId"] = e.guildId; + je["name"] = e.name; + je["leaderName"] = e.leaderName; + je["motd"] = e.motd; + je["info"] = e.info; + je["creationDate"] = e.creationDate; + je["experience"] = e.experience; + je["level"] = e.level; + je["factionId"] = e.factionId; + je["factionName"] = wowee::pipeline::WoweeGuild::factionName(e.factionId); + je["bankCopper"] = e.bankCopper; + je["emblem"] = e.emblem; + nlohmann::json ranks = nlohmann::json::array(); + for (const auto& r : e.ranks) { + ranks.push_back({ + {"rankIndex", r.rankIndex}, + {"name", r.name}, + {"permissionsMask", r.permissionsMask}, + {"moneyPerDayCopper", r.moneyPerDayCopper}, + }); + } + je["ranks"] = ranks; + nlohmann::json members = nlohmann::json::array(); + for (const auto& m : e.members) { + members.push_back({ + {"characterName", m.characterName}, + {"rankIndex", m.rankIndex}, + {"joinedDate", m.joinedDate}, + {"publicNote", m.publicNote}, + {"officerNote", m.officerNote}, + }); + } + je["members"] = members; + nlohmann::json tabs = nlohmann::json::array(); + for (const auto& t : e.bankTabs) { + tabs.push_back({ + {"tabIndex", t.tabIndex}, + {"name", t.name}, + {"iconPath", t.iconPath}, + {"depositPermissionMask", t.depositPermissionMask}, + {"withdrawPermissionMask", t.withdrawPermissionMask}, + {"viewPermissionMask", t.viewPermissionMask}, + }); + } + je["bankTabs"] = tabs; + nlohmann::json perks = nlohmann::json::array(); + for (const auto& p : e.perks) { + perks.push_back({ + {"perkId", p.perkId}, + {"name", p.name}, + {"spellId", p.spellId}, + {"requiredGuildLevel", p.requiredGuildLevel}, + }); + } + je["perks"] = perks; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wgld-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.wgld\n", base.c_str()); + std::printf(" guilds : %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 = ".wgld.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 = stripWgldExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wgld-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-wgld-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto factionFromName = [](const std::string& s) -> uint8_t { + if (s == "alliance") return wowee::pipeline::WoweeGuild::Alliance; + if (s == "horde") return wowee::pipeline::WoweeGuild::Horde; + return wowee::pipeline::WoweeGuild::Alliance; + }; + wowee::pipeline::WoweeGuild c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeGuild::Entry e; + e.guildId = je.value("guildId", 0u); + e.name = je.value("name", std::string{}); + e.leaderName = je.value("leaderName", std::string{}); + e.motd = je.value("motd", std::string{}); + e.info = je.value("info", std::string{}); + e.creationDate = je.value("creationDate", + static_cast(0)); + e.experience = je.value("experience", + static_cast(0)); + e.level = static_cast(je.value("level", 1)); + if (je.contains("factionId") && je["factionId"].is_number_integer()) { + e.factionId = static_cast(je["factionId"].get()); + } else if (je.contains("factionName") && + je["factionName"].is_string()) { + e.factionId = factionFromName(je["factionName"].get()); + } + e.bankCopper = je.value("bankCopper", 0u); + e.emblem = je.value("emblem", 0u); + if (je.contains("ranks") && je["ranks"].is_array()) { + for (const auto& jr : je["ranks"]) { + wowee::pipeline::WoweeGuild::Rank r; + r.rankIndex = static_cast(jr.value("rankIndex", 0)); + r.name = jr.value("name", std::string{}); + r.permissionsMask = jr.value("permissionsMask", 0u); + r.moneyPerDayCopper = jr.value("moneyPerDayCopper", 0u); + e.ranks.push_back(r); + } + } + if (je.contains("members") && je["members"].is_array()) { + for (const auto& jm : je["members"]) { + wowee::pipeline::WoweeGuild::Member m; + m.characterName = jm.value("characterName", std::string{}); + m.rankIndex = static_cast(jm.value("rankIndex", 0)); + m.joinedDate = jm.value("joinedDate", + static_cast(0)); + m.publicNote = jm.value("publicNote", std::string{}); + m.officerNote = jm.value("officerNote", std::string{}); + e.members.push_back(m); + } + } + if (je.contains("bankTabs") && je["bankTabs"].is_array()) { + for (const auto& jt : je["bankTabs"]) { + wowee::pipeline::WoweeGuild::BankTab t; + t.tabIndex = static_cast(jt.value("tabIndex", 0)); + t.name = jt.value("name", std::string{}); + t.iconPath = jt.value("iconPath", std::string{}); + t.depositPermissionMask = jt.value("depositPermissionMask", 0u); + t.withdrawPermissionMask = jt.value("withdrawPermissionMask", 0u); + t.viewPermissionMask = jt.value("viewPermissionMask", 0u); + e.bankTabs.push_back(t); + } + } + if (je.contains("perks") && je["perks"].is_array()) { + for (const auto& jp : je["perks"]) { + wowee::pipeline::WoweeGuild::Perk p; + p.perkId = jp.value("perkId", 0u); + p.name = jp.value("name", std::string{}); + p.spellId = jp.value("spellId", 0u); + p.requiredGuildLevel = static_cast( + jp.value("requiredGuildLevel", 1)); + e.perks.push_back(p); + } + } + c.entries.push_back(std::move(e)); + } + } + if (!wowee::pipeline::WoweeGuildLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wgld-json: failed to save %s.wgld\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wgld\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" guilds : %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); @@ -301,6 +510,12 @@ bool handleGuildsCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wgld") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wgld-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wgld-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index d6cb8c87..870af7c0 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1217,6 +1217,10 @@ void printUsage(const char* argv0) { std::printf(" Print WGLD entries (id / faction / level / leader + motd / rank+member+tab+perk counts)\n"); std::printf(" --validate-wgld [--json]\n"); std::printf(" Static checks: id>0+unique, name+leader not empty, faction 0..1, members reference valid ranks, unique tab indices\n"); + std::printf(" --export-wgld-json [out.json]\n"); + std::printf(" Export binary .wgld to a human-editable JSON sidecar (defaults to .wgld.json)\n"); + std::printf(" --import-wgld-json [out-base]\n"); + std::printf(" Import a .wgld.json sidecar back into binary .wgld (accepts faction int OR name string)\n"); std::printf(" --gen-conditions [name]\n"); std::printf(" Emit .wpcd starter: 4 conditions covering quest-done / has-item / min-level / class kinds\n"); std::printf(" --gen-conditions-gated [name]\n");