From 4426f26f79f182cd78392ab5ede056f8d2633e91 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 22:33:12 -0700 Subject: [PATCH] feat(editor): add WCTR JSON round-trip (--export/--import-wctr-json) Closes the editing loop on the currency-type catalog: dump a .wctr to JSON, hand-edit currencyKind / cap values / categoryId / isAccountWide / iconPath (e.g. raise Conquest Points weekly cap from 1650 to 2200, retag a server-custom currency from Misc to FactionToken kind, mark Honor Points as account-wide for a casual server), re-import to a byte-identical binary. The exporter emits both currencyKind (int 0..5) and the human- readable currencyKindName ("pvp-honor" / "pve-raid" / "faction-token" / "event-token" / "crafting" / "misc"); the importer accepts either form. isAccountWide round-trips as a JSON bool but accepts int as well so machine-generated sidecars work too. Verified byte-identical round-trip on all three presets (pvp / pve / faction). CLI flag count 970 -> 972. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_currency_types_catalog.cpp | 156 ++++++++++++++++++++ tools/editor/cli_help.cpp | 4 + 3 files changed, 161 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index ae38d126..84c7a089 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -242,6 +242,7 @@ const char* const kArgRequired[] = { "--export-wtle-json", "--import-wtle-json", "--gen-ctr", "--gen-ctr-pve", "--gen-ctr-faction", "--info-wctr", "--validate-wctr", + "--export-wctr-json", "--import-wctr-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_currency_types_catalog.cpp b/tools/editor/cli_currency_types_catalog.cpp index 08be939d..bf899200 100644 --- a/tools/editor/cli_currency_types_catalog.cpp +++ b/tools/editor/cli_currency_types_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_currency_types.hpp" #include +#include #include #include #include @@ -126,6 +127,155 @@ 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 outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWctrExt(base); + if (!wowee::pipeline::WoweeCurrencyTypeLoader::exists(base)) { + std::fprintf(stderr, + "export-wctr-json: WCTR not found: %s.wctr\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeCurrencyTypeLoader::load(base); + if (outPath.empty()) outPath = base + ".wctr.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["currencyId"] = e.currencyId; + je["name"] = e.name; + je["description"] = e.description; + je["itemId"] = e.itemId; + je["maxQuantity"] = e.maxQuantity; + je["maxQuantityWeekly"] = e.maxQuantityWeekly; + je["categoryId"] = e.categoryId; + je["currencyKind"] = e.currencyKind; + je["currencyKindName"] = + wowee::pipeline::WoweeCurrencyType::currencyKindName(e.currencyKind); + je["isAccountWide"] = e.isAccountWide != 0; + je["iconPath"] = e.iconPath; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wctr-json: failed to open %s for write\n", + outPath.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s\n", outPath.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" currencies : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseCurrencyKindToken(const nlohmann::json& jv, + uint8_t fallback) { + if (jv.is_number_integer() || jv.is_number_unsigned()) { + int v = jv.get(); + if (v < 0 || v > wowee::pipeline::WoweeCurrencyType::Misc) + return fallback; + return static_cast(v); + } + if (jv.is_string()) { + std::string s = jv.get(); + for (auto& ch : s) ch = static_cast(std::tolower(ch)); + if (s == "pvp-honor" || + s == "pvphonor") return wowee::pipeline::WoweeCurrencyType::PvPHonor; + if (s == "pve-raid" || + s == "pveraid") return wowee::pipeline::WoweeCurrencyType::PvERaid; + if (s == "faction-token" || + s == "factiontoken") return wowee::pipeline::WoweeCurrencyType::FactionToken; + if (s == "event-token" || + s == "eventtoken") return wowee::pipeline::WoweeCurrencyType::EventToken; + if (s == "crafting") return wowee::pipeline::WoweeCurrencyType::Crafting; + if (s == "misc") return wowee::pipeline::WoweeCurrencyType::Misc; + } + return fallback; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string jsonPath = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + std::ifstream is(jsonPath); + if (!is) { + std::fprintf(stderr, + "import-wctr-json: failed to open %s\n", jsonPath.c_str()); + return 1; + } + nlohmann::json j; + try { + is >> j; + } catch (const std::exception& ex) { + std::fprintf(stderr, + "import-wctr-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeCurrencyType c; + if (j.contains("catalog") && j["catalog"].is_string()) + c.name = j["catalog"].get(); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeCurrencyType::Entry e; + if (je.contains("currencyId")) e.currencyId = je["currencyId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("itemId")) e.itemId = je["itemId"].get(); + if (je.contains("maxQuantity")) e.maxQuantity = je["maxQuantity"].get(); + if (je.contains("maxQuantityWeekly")) e.maxQuantityWeekly = je["maxQuantityWeekly"].get(); + if (je.contains("categoryId")) e.categoryId = je["categoryId"].get(); + uint8_t kind = wowee::pipeline::WoweeCurrencyType::PvPHonor; + if (je.contains("currencyKind")) + kind = parseCurrencyKindToken(je["currencyKind"], kind); + else if (je.contains("currencyKindName")) + kind = parseCurrencyKindToken(je["currencyKindName"], kind); + e.currencyKind = kind; + if (je.contains("isAccountWide")) { + if (je["isAccountWide"].is_boolean()) + e.isAccountWide = je["isAccountWide"].get() ? 1 : 0; + else + e.isAccountWide = je["isAccountWide"].get() ? 1 : 0; + } + if (je.contains("iconPath")) e.iconPath = je["iconPath"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wctr.json"; + const std::string suffix2 = ".json"; + if (outBase.size() >= suffix1.size() && + outBase.compare(outBase.size() - suffix1.size(), + suffix1.size(), suffix1) == 0) { + outBase.resize(outBase.size() - suffix1.size()); + } else if (outBase.size() >= suffix2.size() && + outBase.compare(outBase.size() - suffix2.size(), + suffix2.size(), suffix2) == 0) { + outBase.resize(outBase.size() - suffix2.size()); + } + } + outBase = stripWctrExt(outBase); + if (!wowee::pipeline::WoweeCurrencyTypeLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wctr-json: failed to save %s.wctr\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wctr\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" currencies : %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); @@ -241,6 +391,12 @@ bool handleCurrencyTypesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wctr") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wctr-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wctr-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 2b53c369..9e8140b8 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1857,6 +1857,10 @@ void printUsage(const char* argv0) { std::printf(" Print WCTR entries (id / kind / itemId / max+weekly caps / categoryId / accountWide / name)\n"); std::printf(" --validate-wctr [--json]\n"); std::printf(" Static checks: id+name required, currencyKind 0..5, no duplicate ids; warns on weekly>absolute, FactionToken+cat=0, no caps+no item+no icon\n"); + std::printf(" --export-wctr-json [out.json]\n"); + std::printf(" Export binary .wctr to a human-editable JSON sidecar (defaults to .wctr.json)\n"); + std::printf(" --import-wctr-json [out-base]\n"); + std::printf(" Import a .wctr.json sidecar back into binary .wctr (accepts currencyKind int OR currencyKindName string; isAccountWide bool OR int)\n"); std::printf(" --gen-weather-temperate [zoneName]\n"); std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n"); std::printf(" --gen-weather-arctic [zoneName]\n");