From 0c732a9133bc6bbcf598911965778a6d71cac5f8 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 19:07:08 -0700 Subject: [PATCH] feat(editor): add WHOL JSON round-trip (export/import sidecar) Closes the JSON round-trip gap on the holiday catalog format shipped last batch. --export-whol-json emits all 13 scalar fields plus dual int + name forms for holidayKind and recurrence so hand-edits can use either representation. --import-whol-json accepts either form, falling back to the int when both are present. Verified byte-identical round-trip on all three preset emitters (starter / weekly / special). 709 documented CLI flags. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + tools/editor/cli_holidays_catalog.cpp | 156 ++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 292574a6..5ee42e0b 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -130,6 +130,7 @@ const char* const kArgRequired[] = { "--export-wvhc-json", "--import-wvhc-json", "--gen-holidays", "--gen-holidays-weekly", "--gen-holidays-special", "--info-whol", "--validate-whol", + "--export-whol-json", "--import-whol-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 d4b1109b..c51268e6 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1329,6 +1329,10 @@ void printUsage(const char* argv0) { std::printf(" Print WHOL entries (id / kind / recurrence / start MM/DD / duration / quest+boss+reward IDs / name)\n"); std::printf(" --validate-whol [--json]\n"); std::printf(" Static checks: id>0+unique, kind 0..5, recurrence 0..3, duration>0, valid month/day for non-weekly, calendar-only warning\n"); + std::printf(" --export-whol-json [out.json]\n"); + std::printf(" Export binary .whol to a human-editable JSON sidecar (defaults to .whol.json)\n"); + std::printf(" --import-whol-json [out-base]\n"); + std::printf(" Import a .whol.json sidecar back into binary .whol (accepts holidayKind/recurrence int OR name 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_holidays_catalog.cpp b/tools/editor/cli_holidays_catalog.cpp index 509ccdd2..87814aa5 100644 --- a/tools/editor/cli_holidays_catalog.cpp +++ b/tools/editor/cli_holidays_catalog.cpp @@ -132,6 +132,156 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int handleExportJson(int& i, int argc, char** argv) { + // Mirrors the JSON pairs added for every other novel + // open format. Each holiday emits all 13 scalar fields + // plus dual int + name forms for holidayKind and + // recurrence so hand-edits can use either representation. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWholExt(base); + if (outPath.empty()) outPath = base + ".whol.json"; + if (!wowee::pipeline::WoweeHolidayLoader::exists(base)) { + std::fprintf(stderr, + "export-whol-json: WHOL not found: %s.whol\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeHolidayLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"holidayId", e.holidayId}, + {"name", e.name}, + {"description", e.description}, + {"iconPath", e.iconPath}, + {"holidayKind", e.holidayKind}, + {"holidayKindName", wowee::pipeline::WoweeHoliday::holidayKindName(e.holidayKind)}, + {"recurrence", e.recurrence}, + {"recurrenceName", wowee::pipeline::WoweeHoliday::recurrenceName(e.recurrence)}, + {"startMonth", e.startMonth}, + {"startDay", e.startDay}, + {"durationHours", e.durationHours}, + {"holidayQuestId", e.holidayQuestId}, + {"bossCreatureId", e.bossCreatureId}, + {"itemRewardId", e.itemRewardId}, + {"areaIdGate", e.areaIdGate}, + {"mapIdGate", e.mapIdGate}, + }); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-whol-json: cannot write %s\n", outPath.c_str()); + return 1; + } + out << j.dump(2) << "\n"; + out.close(); + std::printf("Wrote %s\n", outPath.c_str()); + std::printf(" source : %s.whol\n", base.c_str()); + std::printf(" holidays : %zu\n", c.entries.size()); + return 0; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string jsonPath = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + if (outBase.empty()) { + outBase = jsonPath; + std::string suffix = ".whol.json"; + if (outBase.size() > suffix.size() && + outBase.substr(outBase.size() - suffix.size()) == suffix) { + outBase = outBase.substr(0, outBase.size() - suffix.size()); + } else if (outBase.size() > 5 && + outBase.substr(outBase.size() - 5) == ".json") { + outBase = outBase.substr(0, outBase.size() - 5); + } + } + outBase = stripWholExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-whol-json: cannot read %s\n", jsonPath.c_str()); + return 1; + } + nlohmann::json j; + try { in >> j; } + catch (const std::exception& e) { + std::fprintf(stderr, + "import-whol-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto kindFromName = [](const std::string& s) -> uint8_t { + if (s == "seasonal") return wowee::pipeline::WoweeHoliday::Seasonal; + if (s == "weekly") return wowee::pipeline::WoweeHoliday::Weekly; + if (s == "daily") return wowee::pipeline::WoweeHoliday::Daily; + if (s == "world-pvp") return wowee::pipeline::WoweeHoliday::WorldPvp; + if (s == "one-shot") return wowee::pipeline::WoweeHoliday::OneShot; + if (s == "special") return wowee::pipeline::WoweeHoliday::Special; + return wowee::pipeline::WoweeHoliday::Seasonal; + }; + auto recurFromName = [](const std::string& s) -> uint8_t { + if (s == "annual") return wowee::pipeline::WoweeHoliday::Annual; + if (s == "monthly") return wowee::pipeline::WoweeHoliday::Monthly; + if (s == "weekly") return wowee::pipeline::WoweeHoliday::WeeklyRecur; + if (s == "one-time") return wowee::pipeline::WoweeHoliday::OneTime; + return wowee::pipeline::WoweeHoliday::Annual; + }; + wowee::pipeline::WoweeHoliday c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeHoliday::Entry e; + e.holidayId = je.value("holidayId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.iconPath = je.value("iconPath", std::string{}); + if (je.contains("holidayKind") && + je["holidayKind"].is_number_integer()) { + e.holidayKind = static_cast( + je["holidayKind"].get()); + } else if (je.contains("holidayKindName") && + je["holidayKindName"].is_string()) { + e.holidayKind = kindFromName( + je["holidayKindName"].get()); + } + if (je.contains("recurrence") && + je["recurrence"].is_number_integer()) { + e.recurrence = static_cast( + je["recurrence"].get()); + } else if (je.contains("recurrenceName") && + je["recurrenceName"].is_string()) { + e.recurrence = recurFromName( + je["recurrenceName"].get()); + } + e.startMonth = static_cast(je.value("startMonth", 0)); + e.startDay = static_cast(je.value("startDay", 0)); + e.durationHours = static_cast( + je.value("durationHours", 168)); + e.holidayQuestId = je.value("holidayQuestId", 0u); + e.bossCreatureId = je.value("bossCreatureId", 0u); + e.itemRewardId = je.value("itemRewardId", 0u); + e.areaIdGate = je.value("areaIdGate", 0u); + e.mapIdGate = je.value("mapIdGate", 0u); + c.entries.push_back(e); + } + } + if (!wowee::pipeline::WoweeHolidayLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-whol-json: failed to save %s.whol\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.whol\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" holidays : %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); @@ -247,6 +397,12 @@ bool handleHolidaysCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-whol") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-whol-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-whol-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }