From c41db0e0bebc8630c4afcaa38061103b7a67cf12 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 20:10:59 -0700 Subject: [PATCH] feat(editor): add WSMC JSON round-trip (export/import sidecar) Closes the JSON round-trip gap on the spell mechanic catalog format shipped this batch. --export-wsmc-json emits all 9 scalar fields plus dual int + name forms for drCategory (8 values) and dispelType (7 values). --import-wsmc-json accepts either form. conflictsMask is dumped/parsed as a raw uint32 since it's a free-form bitmask of OTHER mechanic IDs (no enum to widen). Verified byte-identical round-trip on all three preset emitters (starter / hard-CC with conflictsMask bits set / roots with stacking flag). 791 documented CLI flags. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + tools/editor/cli_spell_mechanics_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 a759abb5..4a692005 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -165,6 +165,7 @@ const char* const kArgRequired[] = { "--export-wcmp-json", "--import-wcmp-json", "--gen-smc", "--gen-smc-hard", "--gen-smc-roots", "--info-wsmc", "--validate-wsmc", + "--export-wsmc-json", "--import-wsmc-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 0f86cfde..083d1065 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1495,6 +1495,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSMC entries (id / DR category / dispel type / breaks / dispellable / duration / max stacks / conflicts mask / name)\n"); std::printf(" --validate-wsmc [--json]\n"); std::printf(" Static checks: id+name required, DR 0..7 / dispel 0..6, maxStacks>0, dispellable+none-dispel inconsistency, self-conflict bit\n"); + std::printf(" --export-wsmc-json [out.json]\n"); + std::printf(" Export binary .wsmc to a human-editable JSON sidecar (defaults to .wsmc.json)\n"); + std::printf(" --import-wsmc-json [out-base]\n"); + std::printf(" Import a .wsmc.json sidecar back into binary .wsmc (accepts drCategory/dispelType 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_spell_mechanics_catalog.cpp b/tools/editor/cli_spell_mechanics_catalog.cpp index 0880d0a7..336ffdcf 100644 --- a/tools/editor/cli_spell_mechanics_catalog.cpp +++ b/tools/editor/cli_spell_mechanics_catalog.cpp @@ -126,6 +126,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 mechanic emits all 9 scalar fields + // plus dual int + name forms for drCategory and dispelType. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWsmcExt(base); + if (outPath.empty()) outPath = base + ".wsmc.json"; + if (!wowee::pipeline::WoweeSpellMechanicLoader::exists(base)) { + std::fprintf(stderr, + "export-wsmc-json: WSMC not found: %s.wsmc\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeSpellMechanicLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"mechanicId", e.mechanicId}, + {"name", e.name}, + {"description", e.description}, + {"iconPath", e.iconPath}, + {"breaksOnDamage", e.breaksOnDamage}, + {"canBeDispelled", e.canBeDispelled}, + {"drCategory", e.drCategory}, + {"drCategoryName", wowee::pipeline::WoweeSpellMechanic::drCategoryName(e.drCategory)}, + {"dispelType", e.dispelType}, + {"dispelTypeName", wowee::pipeline::WoweeSpellMechanic::dispelTypeName(e.dispelType)}, + {"defaultDurationMs", e.defaultDurationMs}, + {"maxStacks", e.maxStacks}, + {"conflictsMask", e.conflictsMask}, + }); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wsmc-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.wsmc\n", base.c_str()); + std::printf(" mechanics : %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 = ".wsmc.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 = stripWsmcExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wsmc-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-wsmc-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto drFromName = [](const std::string& s) -> uint8_t { + if (s == "none") return wowee::pipeline::WoweeSpellMechanic::DRNone; + if (s == "stun") return wowee::pipeline::WoweeSpellMechanic::DRStun; + if (s == "disorient") return wowee::pipeline::WoweeSpellMechanic::DRDisorient; + if (s == "silence") return wowee::pipeline::WoweeSpellMechanic::DRSilence; + if (s == "root") return wowee::pipeline::WoweeSpellMechanic::DRRoot; + if (s == "polymorph") return wowee::pipeline::WoweeSpellMechanic::DRPolymorph; + if (s == "controlled") return wowee::pipeline::WoweeSpellMechanic::DRControlled; + if (s == "misc") return wowee::pipeline::WoweeSpellMechanic::DRMisc; + return wowee::pipeline::WoweeSpellMechanic::DRNone; + }; + auto dispelFromName = [](const std::string& s) -> uint8_t { + if (s == "none") return wowee::pipeline::WoweeSpellMechanic::DispelNone; + if (s == "magic") return wowee::pipeline::WoweeSpellMechanic::DispelMagic; + if (s == "curse") return wowee::pipeline::WoweeSpellMechanic::DispelCurse; + if (s == "disease") return wowee::pipeline::WoweeSpellMechanic::DispelDisease; + if (s == "poison") return wowee::pipeline::WoweeSpellMechanic::DispelPoison; + if (s == "enrage") return wowee::pipeline::WoweeSpellMechanic::DispelEnrage; + if (s == "stealth") return wowee::pipeline::WoweeSpellMechanic::DispelStealth; + return wowee::pipeline::WoweeSpellMechanic::DispelNone; + }; + wowee::pipeline::WoweeSpellMechanic c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeSpellMechanic::Entry e; + e.mechanicId = je.value("mechanicId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.iconPath = je.value("iconPath", std::string{}); + e.breaksOnDamage = static_cast( + je.value("breaksOnDamage", 0)); + e.canBeDispelled = static_cast( + je.value("canBeDispelled", 0)); + if (je.contains("drCategory") && + je["drCategory"].is_number_integer()) { + e.drCategory = static_cast( + je["drCategory"].get()); + } else if (je.contains("drCategoryName") && + je["drCategoryName"].is_string()) { + e.drCategory = drFromName( + je["drCategoryName"].get()); + } + if (je.contains("dispelType") && + je["dispelType"].is_number_integer()) { + e.dispelType = static_cast( + je["dispelType"].get()); + } else if (je.contains("dispelTypeName") && + je["dispelTypeName"].is_string()) { + e.dispelType = dispelFromName( + je["dispelTypeName"].get()); + } + e.defaultDurationMs = je.value("defaultDurationMs", 0u); + e.maxStacks = static_cast( + je.value("maxStacks", 1)); + e.conflictsMask = je.value("conflictsMask", 0u); + c.entries.push_back(e); + } + } + if (!wowee::pipeline::WoweeSpellMechanicLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wsmc-json: failed to save %s.wsmc\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wsmc\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" mechanics : %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); @@ -238,6 +388,12 @@ bool handleSpellMechanicsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wsmc") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wsmc-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wsmc-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }