diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index c47708de..a667cfa7 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -430,6 +430,7 @@ const char* const kArgRequired[] = { "--export-wauh-json", "--import-wauh-json", "--gen-brd-av", "--gen-brd-wsg", "--gen-brd-ab", "--info-wbrd", "--validate-wbrd", + "--export-wbrd-json", "--import-wbrd-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_battleground_rewards_catalog.cpp b/tools/editor/cli_battleground_rewards_catalog.cpp index cc63309d..a0292c2a 100644 --- a/tools/editor/cli_battleground_rewards_catalog.cpp +++ b/tools/editor/cli_battleground_rewards_catalog.cpp @@ -266,6 +266,121 @@ 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 = stripWbrdExt(base); + if (out.empty()) out = base + ".wbrd.json"; + if (!wowee::pipeline::WoweeBattlegroundRewardsLoader::exists(base)) { + std::fprintf(stderr, + "export-wbrd-json: WBRD not found: %s.wbrd\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeBattlegroundRewardsLoader::load(base); + nlohmann::json j; + j["magic"] = "WBRD"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"rewardId", e.rewardId}, + {"battlegroundId", e.battlegroundId}, + {"battlegroundName", bgName(e.battlegroundId)}, + {"bracketIndex", e.bracketIndex}, + {"minPlayersToStart", e.minPlayersToStart}, + {"winHonor", e.winHonor}, + {"lossHonor", e.lossHonor}, + {"markItemId", e.markItemId}, + {"winMarks", e.winMarks}, + {"lossMarks", e.lossMarks}, + {"bonusItemId", e.bonusItemId}, + {"bonusItemCount", e.bonusItemCount}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wbrd-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu stages)\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) == ".wbrd.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wbrd"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wbrd-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-wbrd-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeBattlegroundRewards c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wbrd-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeBattlegroundRewards::Entry e; + e.rewardId = je.value("rewardId", 0u); + e.battlegroundId = static_cast( + je.value("battlegroundId", 0)); + e.bracketIndex = static_cast( + je.value("bracketIndex", 0)); + e.minPlayersToStart = static_cast( + je.value("minPlayersToStart", 0)); + e.winHonor = je.value("winHonor", 0u); + e.lossHonor = je.value("lossHonor", 0u); + e.markItemId = je.value("markItemId", 0u); + e.winMarks = static_cast( + je.value("winMarks", 0)); + e.lossMarks = static_cast( + je.value("lossMarks", 0)); + e.bonusItemId = je.value("bonusItemId", 0u); + e.bonusItemCount = static_cast( + je.value("bonusItemCount", 0)); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeBattlegroundRewardsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wbrd-json: failed to save %s.wbrd\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wbrd (%zu stages)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + } // namespace bool handleBattlegroundRewardsCatalog(int& i, int argc, char** argv, @@ -289,6 +404,14 @@ bool handleBattlegroundRewardsCatalog(int& i, int argc, char** argv, i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wbrd-json") == 0 && + i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wbrd-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 17fec9e1..0d69e06c 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2723,6 +2723,10 @@ void printUsage(const char* argv0) { std::printf(" Print WBRD entries (id / bg / bracket / minPlayers / win+loss honor / markId / win+loss marks / bonusItem)\n"); std::printf(" --validate-wbrd [--json]\n"); std::printf(" Static checks: id+battlegroundId required, bracketIndex 1..6 (vanilla), minPlayersToStart > 0 (else queue would never start a match), no duplicate rewardIds, no duplicate (bgId,bracket) pairs (runtime reward-lookup tie), bonusItemCount > 0 requires bonusItemId; CRITICAL: lossHonor <= winHonor (else losing rewards more than winning, no incentive to play to win). Warns on winMarks=0 with markItemId set (vanilla wins always granted at least 1 mark)\n"); + std::printf(" --export-wbrd-json [out.json]\n"); + std::printf(" Export binary .wbrd to a human-editable JSON sidecar (defaults to .wbrd.json; battlegroundName field is informational; battlegroundId int is authoritative)\n"); + std::printf(" --import-wbrd-json [out-base]\n"); + std::printf(" Import a .wbrd.json sidecar back into binary .wbrd (battlegroundName ignored; bgId int authoritative — round-trips per-bracket reward tables 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");