From 4aa21387493714bcff967f1210b0d542d23e8a38 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 10 May 2026 02:00:19 -0700 Subject: [PATCH] feat(editor): add WRPR JSON round-trip (--export/--import-wrpr-json) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two parallel variable-length arrays (unlockedItemIds + unlockedRecipeIds) serialize as plain JSON int arrays — operators editing JSON can add or remove unlock entries without touching either array's parallel partner. grantsTabard and grantsMount accept bool or int. Export adds a derived standingTier label ("Friendly"/"Honored"/"Revered"/"Exalted"/"Neutral"/etc.) alongside the raw minStanding int — purely informational for JSON readability, ignored on import (the int is authoritative). Reuses the standingTierName helper already used by --info-wrpr table display. All 3 presets (argent/kaluak/accord) byte-identical roundtrip OK. CLI flag count 1189 -> 1191. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + .../editor/cli_reputation_rewards_catalog.cpp | 146 ++++++++++++++++++ 3 files changed, 151 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 5233a1d3..cb78bbff 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -336,6 +336,7 @@ const char* const kArgRequired[] = { "--export-whrd-json", "--import-whrd-json", "--gen-rpr", "--gen-rpr-kaluak", "--gen-rpr-accord", "--info-wrpr", "--validate-wrpr", + "--export-wrpr-json", "--import-wrpr-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 5ce4f84f..0c0986fa 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2289,6 +2289,10 @@ void printUsage(const char* argv0) { std::printf(" Print WRPR entries (id / faction / standing / standing tier / discount %% / tabard flag / mount flag / item count / recipe count / name)\n"); std::printf(" --validate-wrpr [--json]\n"); std::printf(" Static checks: id+name+factionId required, minStanding [-42000, 42000], no zero item/recipe IDs, no duplicate tierIds, no two tiers binding same (factionId,minStanding) tuple; warns on discountPct>20%% (exceeds Exalted cap), and PER-FACTION non-monotonic discount progression (higher standing should never give worse discount)\n"); + std::printf(" --export-wrpr-json [out.json]\n"); + std::printf(" Export binary .wrpr to a human-editable JSON sidecar (defaults to .wrpr.json; emits both unlockedItemIds and unlockedRecipeIds as JSON arrays of IDs; standingTier derived label \"Friendly/Honored/Revered/Exalted\" added for readability)\n"); + std::printf(" --import-wrpr-json [out-base]\n"); + std::printf(" Import a .wrpr.json sidecar back into binary .wrpr (grantsTabard/grantsMount accept bool OR int; both unlock arrays serialize as plain JSON int arrays; standingTier label is informational only — minStanding int is authoritative)\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"); diff --git a/tools/editor/cli_reputation_rewards_catalog.cpp b/tools/editor/cli_reputation_rewards_catalog.cpp index 133ae1ae..7b0011b3 100644 --- a/tools/editor/cli_reputation_rewards_catalog.cpp +++ b/tools/editor/cli_reputation_rewards_catalog.cpp @@ -157,6 +157,146 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +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 = stripWrprExt(base); + if (out.empty()) out = base + ".wrpr.json"; + if (!wowee::pipeline::WoweeReputationRewardsLoader::exists( + base)) { + std::fprintf(stderr, + "export-wrpr-json: WRPR not found: %s.wrpr\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeReputationRewardsLoader::load( + base); + nlohmann::json j; + j["magic"] = "WRPR"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"tierId", e.tierId}, + {"name", e.name}, + {"description", e.description}, + {"factionId", e.factionId}, + {"minStanding", e.minStanding}, + {"standingTier", standingTierName(e.minStanding)}, + {"discountPct", e.discountPct}, + {"grantsTabard", e.grantsTabard != 0}, + {"grantsMount", e.grantsMount != 0}, + {"iconColorRGBA", e.iconColorRGBA}, + {"unlockedItemIds", e.unlockedItemIds}, + {"unlockedRecipeIds", e.unlockedRecipeIds}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wrpr-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu tiers)\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) == ".wrpr.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wrpr"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wrpr-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-wrpr-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeReputationRewards c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wrpr-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeReputationRewards::Entry e; + e.tierId = je.value("tierId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.factionId = je.value("factionId", 0u); + e.minStanding = je.value("minStanding", 0); + e.discountPct = static_cast( + je.value("discountPct", 0u)); + if (je.contains("grantsTabard")) { + const auto& v = je["grantsTabard"]; + if (v.is_boolean()) + e.grantsTabard = v.get() ? 1 : 0; + else if (v.is_number_integer()) + e.grantsTabard = static_cast( + v.get() != 0 ? 1 : 0); + } + if (je.contains("grantsMount")) { + const auto& v = je["grantsMount"]; + if (v.is_boolean()) + e.grantsMount = v.get() ? 1 : 0; + else if (v.is_number_integer()) + e.grantsMount = static_cast( + v.get() != 0 ? 1 : 0); + } + e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu); + if (je.contains("unlockedItemIds") && + je["unlockedItemIds"].is_array()) { + for (const auto& s : je["unlockedItemIds"]) { + if (s.is_number_integer()) + e.unlockedItemIds.push_back(s.get()); + } + } + if (je.contains("unlockedRecipeIds") && + je["unlockedRecipeIds"].is_array()) { + for (const auto& s : je["unlockedRecipeIds"]) { + if (s.is_number_integer()) + e.unlockedRecipeIds.push_back( + s.get()); + } + } + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeReputationRewardsLoader::save( + c, outBase)) { + std::fprintf(stderr, + "import-wrpr-json: failed to save %s.wrpr\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wrpr (%zu tiers)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -327,6 +467,12 @@ bool handleReputationRewardsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wrpr") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wrpr-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wrpr-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }