From 3f65e63ca174b1ea5b1df49eaef0304b7fdbc6d3 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 23:54:26 -0700 Subject: [PATCH] feat(editor): add WHLD JSON round-trip (--export/--import-whld-json) Closes the editing loop on the instance-lockout catalog: dump a .whld to JSON, hand-edit raidLockoutKind / resetIntervalMs / maxBossKillsPerLockout / raidGroupSize / bonusRolls (e.g. switch ICC 25-Heroic from Weekly to SemiWeekly for a faster server, raise Wintergrasp's reset from 2.5h to 3h, mark a custom heroic+ tier with bonus rolls), re-import to a byte-identical binary. raidLockoutKind dual-encoded: int 0..3 OR human-readable name ("daily" / "weekly" / "semi-weekly" / "custom"). All other fields are scalar uint32/uint8 so no dual encoding needed. Verified byte-identical round-trip on all three presets (raid / dungeon / event). The event preset's mixed kinds (2 Daily + 1 Custom 2.5h) round-trip exactly, confirming that the Custom kind's arbitrary intervalMs preserves through the JSON serialization. CLI flag count 1067 -> 1069. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + .../editor/cli_instance_lockouts_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 c74991e5..26195ebb 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -284,6 +284,7 @@ const char* const kArgRequired[] = { "--export-wbos-json", "--import-wbos-json", "--gen-hld", "--gen-hld-dungeon", "--gen-hld-event", "--info-whld", "--validate-whld", + "--export-whld-json", "--import-whld-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 22c3253f..80525757 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2051,6 +2051,10 @@ void printUsage(const char* argv0) { std::printf(" Print WHLD entries (id / map / diff / kind / interval (formatted) / boss kills / size / bonus rolls / name)\n"); std::printf(" --validate-whld [--json]\n"); std::printf(" Static checks: id+name+kind+interval required, no duplicate ids; warns on non-standard group size, kind/interval mismatches (Daily not 24h, Weekly not 7d), 0 boss kill cap\n"); + std::printf(" --export-whld-json [out.json]\n"); + std::printf(" Export binary .whld to a human-editable JSON sidecar (defaults to .whld.json)\n"); + std::printf(" --import-whld-json [out-base]\n"); + std::printf(" Import a .whld.json sidecar back into binary .whld (accepts raidLockoutKind int OR raidLockoutKindName string)\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"); diff --git a/tools/editor/cli_instance_lockouts_catalog.cpp b/tools/editor/cli_instance_lockouts_catalog.cpp index 7e51095e..277c871a 100644 --- a/tools/editor/cli_instance_lockouts_catalog.cpp +++ b/tools/editor/cli_instance_lockouts_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_instance_lockouts.hpp" #include +#include #include #include #include @@ -140,6 +141,145 @@ 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 = stripWhldExt(base); + if (!wowee::pipeline::WoweeInstanceLockoutLoader::exists(base)) { + std::fprintf(stderr, + "export-whld-json: WHLD not found: %s.whld\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeInstanceLockoutLoader::load(base); + if (outPath.empty()) outPath = base + ".whld.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["lockoutId"] = e.lockoutId; + je["name"] = e.name; + je["description"] = e.description; + je["mapId"] = e.mapId; + je["difficultyId"] = e.difficultyId; + je["resetIntervalMs"] = e.resetIntervalMs; + je["maxBossKillsPerLockout"] = e.maxBossKillsPerLockout; + je["bonusRolls"] = e.bonusRolls; + je["raidLockoutKind"] = e.raidLockoutKind; + je["raidLockoutKindName"] = + wowee::pipeline::WoweeInstanceLockout::lockoutKindName(e.raidLockoutKind); + je["raidGroupSize"] = e.raidGroupSize; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-whld-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(" lockouts : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseLockoutKindToken(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::WoweeInstanceLockout::Custom) + 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 == "daily") return wowee::pipeline::WoweeInstanceLockout::Daily; + if (s == "weekly") return wowee::pipeline::WoweeInstanceLockout::Weekly; + if (s == "semi-weekly" || + s == "semiweekly") return wowee::pipeline::WoweeInstanceLockout::SemiWeekly; + if (s == "custom") return wowee::pipeline::WoweeInstanceLockout::Custom; + } + 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-whld-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-whld-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeInstanceLockout 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::WoweeInstanceLockout::Entry e; + if (je.contains("lockoutId")) e.lockoutId = je["lockoutId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("mapId")) e.mapId = je["mapId"].get(); + if (je.contains("difficultyId")) e.difficultyId = je["difficultyId"].get(); + if (je.contains("resetIntervalMs")) e.resetIntervalMs = je["resetIntervalMs"].get(); + if (je.contains("maxBossKillsPerLockout")) e.maxBossKillsPerLockout = je["maxBossKillsPerLockout"].get(); + if (je.contains("bonusRolls")) e.bonusRolls = je["bonusRolls"].get(); + uint8_t kind = wowee::pipeline::WoweeInstanceLockout::Weekly; + if (je.contains("raidLockoutKind")) + kind = parseLockoutKindToken(je["raidLockoutKind"], kind); + else if (je.contains("raidLockoutKindName")) + kind = parseLockoutKindToken(je["raidLockoutKindName"], kind); + e.raidLockoutKind = kind; + if (je.contains("raidGroupSize")) e.raidGroupSize = je["raidGroupSize"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".whld.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 = stripWhldExt(outBase); + if (!wowee::pipeline::WoweeInstanceLockoutLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-whld-json: failed to save %s.whld\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.whld\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" lockouts : %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); @@ -258,6 +398,12 @@ bool handleInstanceLockoutsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-whld") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-whld-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-whld-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }