diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 4925d58a..4b9abe88 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -403,6 +403,7 @@ const char* const kArgRequired[] = { "--export-wcst-json", "--import-wcst-json", "--gen-gbk", "--gen-gbk-raid", "--gen-gbk-small", "--info-wgbk", "--validate-wgbk", + "--export-wgbk-json", "--import-wgbk-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_guild_bank_catalog.cpp b/tools/editor/cli_guild_bank_catalog.cpp index 32f7f7af..f816729d 100644 --- a/tools/editor/cli_guild_bank_catalog.cpp +++ b/tools/editor/cli_guild_bank_catalog.cpp @@ -280,6 +280,127 @@ int handleValidate(int& i, int argc, char** argv) { return ok ? 0 : 1; } +int handleExportJson(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string out; + if (parseOptArg(i, argc, argv)) out = argv[++i]; + base = stripWgbkExt(base); + if (out.empty()) out = base + ".wgbk.json"; + if (!wowee::pipeline::WoweeGuildBankLoader::exists(base)) { + std::fprintf(stderr, + "export-wgbk-json: WGBK not found: %s.wgbk\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeGuildBankLoader::load(base); + nlohmann::json j; + j["magic"] = "WGBK"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json limits = nlohmann::json::array(); + for (uint32_t r = 0; + r < wowee::pipeline::WoweeGuildBank:: + kRankCount; ++r) { + limits.push_back(e.perRankWithdrawalLimit[r]); + } + arr.push_back({ + {"tabId", e.tabId}, + {"guildId", e.guildId}, + {"tabName", e.tabName}, + {"iconIndex", e.iconIndex}, + {"depositOnly", e.depositOnly != 0}, + {"slotCount", e.slotCount}, + {"perRankWithdrawalLimit", limits}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wgbk-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu tabs)\n", + out.c_str(), c.entries.size()); + return 0; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string in = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + if (outBase.empty()) { + outBase = in; + if (outBase.size() >= 10 && + outBase.substr(outBase.size() - 10) == ".wgbk.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wgbk"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wgbk-json: cannot open %s\n", in.c_str()); + return 1; + } + nlohmann::json j; + try { + is >> j; + } catch (const std::exception& ex) { + std::fprintf(stderr, + "import-wgbk-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeGuildBank c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wgbk-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeGuildBank::Entry e; + e.tabId = je.value("tabId", 0u); + e.guildId = je.value("guildId", 0u); + e.tabName = je.value("tabName", std::string{}); + e.iconIndex = je.value("iconIndex", 0u); + e.depositOnly = je.value("depositOnly", false) ? 1 : 0; + e.slotCount = static_cast( + je.value("slotCount", 0)); + if (je.contains("perRankWithdrawalLimit") && + je["perRankWithdrawalLimit"].is_array()) { + uint32_t r = 0; + for (const auto& v : + je["perRankWithdrawalLimit"]) { + if (r >= wowee::pipeline::WoweeGuildBank:: + kRankCount) break; + if (v.is_number_unsigned() || + v.is_number_integer()) { + e.perRankWithdrawalLimit[r] = + v.get(); + } + ++r; + } + } + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeGuildBankLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wgbk-json: failed to save %s.wgbk\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wgbk (%zu tabs)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + } // namespace bool handleGuildBankCatalog(int& i, int argc, char** argv, @@ -302,6 +423,14 @@ bool handleGuildBankCatalog(int& i, int argc, char** argv, i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wgbk-json") == 0 && + i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wgbk-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 f6a0b646..a7e92810 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2597,6 +2597,10 @@ void printUsage(const char* argv0) { std::printf(" Print WGBK entries (id / guildId / slotCount / depositOnly / per-rank-0..7 withdrawal limits / tabName)\n"); std::printf(" --validate-wgbk [--json]\n"); std::printf(" Static checks: id+guildId+tabName required, slotCount 1..98 (vanilla cap), GM withdrawal limit > 0 (rank 0 cannot be locked out — almost certainly a typo), per-rank monotonicity (lower rank cannot exceed higher rank's cap), no duplicate tabIds, no duplicate (guildId,tabName) pairs (UI tab dispatch tie); warns on depositOnly flag set with non-zero rank-0 limit (self-contradiction — flag overrides at runtime but data is contradictory)\n"); + std::printf(" --export-wgbk-json [out.json]\n"); + std::printf(" Export binary .wgbk to a human-editable JSON sidecar (defaults to .wgbk.json; perRankWithdrawalLimit emitted as 8-element JSON int array, kUnlimited = 4294967295)\n"); + std::printf(" --import-wgbk-json [out-base]\n"); + std::printf(" Import a .wgbk.json sidecar back into binary .wgbk (perRankWithdrawalLimit JSON int array, missing entries default to 0; round-trips per-rank caps byte-identical)\n"); std::printf(" --catalog-pluck [--json]\n"); std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n"); std::printf(" --catalog-find [--magic ] [--json]\n");