From 18f07f1b8aed09a80edfd1fba454bb3e996e1683 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 22:56:20 -0700 Subject: [PATCH] feat(editor): add WAUR JSON round-trip (--export/--import-waur-json) Closes the editing loop on the spell-aura-type catalog: dump a .waur to JSON, hand-edit auraKind / targetingHint / tick interval / stack rules (e.g. retune PeriodicDamage from 3000ms to 2500ms ticks for a faster server, mark a custom aura as HostileOnly+stackable up to 10, switch a server-custom DoT from StatMod to Periodic kind), re-import to a byte-identical binary. Three dual-encoded fields: - auraKind: int 0..8 OR "periodic" / "stat-mod" / "damage-mod" / "movement" / "visual" / "trigger" / "resource" / "control" / "misc" - targetingHint: int 0..3 OR "any" / "self" / "hostile" / "beneficial" - isStackable: bool OR int (machine-generated sidecars work too) Verified byte-identical round-trip on all three presets (periodic / stats / movement). CLI flag count 1001 -> 1003. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + tools/editor/cli_spell_aura_types_catalog.cpp | 183 ++++++++++++++++++ 3 files changed, 188 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 62572a03..9d289526 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -256,6 +256,7 @@ const char* const kArgRequired[] = { "--export-wsef-json", "--import-wsef-json", "--gen-aur", "--gen-aur-stats", "--gen-aur-movement", "--info-waur", "--validate-waur", + "--export-waur-json", "--import-waur-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 69dc3504..f49bf280 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1919,6 +1919,10 @@ void printUsage(const char* argv0) { std::printf(" Print WAUR entries (id / kind / targeting / stack flag / max stack / tick interval / name)\n"); std::printf(" --validate-waur [--json]\n"); std::printf(" Static checks: name required, auraKind 0..8, targetingHint 0..3, no duplicate ids; errors on Periodic without tick interval; warns on non-periodic with tick interval, maxStackCount without isStackable\n"); + std::printf(" --export-waur-json [out.json]\n"); + std::printf(" Export binary .waur to a human-editable JSON sidecar (defaults to .waur.json)\n"); + std::printf(" --import-waur-json [out-base]\n"); + std::printf(" Import a .waur.json sidecar back into binary .waur (accepts auraKind/targetingHint int OR name; isStackable 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"); diff --git a/tools/editor/cli_spell_aura_types_catalog.cpp b/tools/editor/cli_spell_aura_types_catalog.cpp index cd9e14e8..134f082e 100644 --- a/tools/editor/cli_spell_aura_types_catalog.cpp +++ b/tools/editor/cli_spell_aura_types_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_spell_aura_types.hpp" #include +#include #include #include #include @@ -124,6 +125,182 @@ 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 = stripWaurExt(base); + if (!wowee::pipeline::WoweeSpellAuraTypeLoader::exists(base)) { + std::fprintf(stderr, + "export-waur-json: WAUR not found: %s.waur\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeSpellAuraTypeLoader::load(base); + if (outPath.empty()) outPath = base + ".waur.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["auraTypeId"] = e.auraTypeId; + je["name"] = e.name; + je["description"] = e.description; + je["auraKind"] = e.auraKind; + je["auraKindName"] = + wowee::pipeline::WoweeSpellAuraType::auraKindName(e.auraKind); + je["targetingHint"] = e.targetingHint; + je["targetingHintName"] = + wowee::pipeline::WoweeSpellAuraType::targetingHintName(e.targetingHint); + je["isStackable"] = e.isStackable != 0; + je["maxStackCount"] = e.maxStackCount; + je["updateFrequencyMs"] = e.updateFrequencyMs; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-waur-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(" auras : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseAuraKindToken(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::WoweeSpellAuraType::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 == "periodic") return wowee::pipeline::WoweeSpellAuraType::Periodic; + if (s == "stat-mod" || + s == "statmod") return wowee::pipeline::WoweeSpellAuraType::StatMod; + if (s == "damage-mod" || + s == "damagemod") return wowee::pipeline::WoweeSpellAuraType::DamageMod; + if (s == "movement") return wowee::pipeline::WoweeSpellAuraType::Movement; + if (s == "visual") return wowee::pipeline::WoweeSpellAuraType::Visual; + if (s == "trigger") return wowee::pipeline::WoweeSpellAuraType::Trigger; + if (s == "resource") return wowee::pipeline::WoweeSpellAuraType::Resource; + if (s == "control") return wowee::pipeline::WoweeSpellAuraType::Control; + if (s == "misc") return wowee::pipeline::WoweeSpellAuraType::Misc; + } + return fallback; +} + +uint8_t parseTargetingHintToken(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::WoweeSpellAuraType::BeneficialOnly) + 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 == "any" || + s == "anyunit") return wowee::pipeline::WoweeSpellAuraType::AnyUnit; + if (s == "self" || + s == "selfonly") return wowee::pipeline::WoweeSpellAuraType::SelfOnly; + if (s == "hostile" || + s == "hostileonly") return wowee::pipeline::WoweeSpellAuraType::HostileOnly; + if (s == "beneficial" || + s == "beneficialonly") return wowee::pipeline::WoweeSpellAuraType::BeneficialOnly; + } + 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-waur-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-waur-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeSpellAuraType 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::WoweeSpellAuraType::Entry e; + if (je.contains("auraTypeId")) e.auraTypeId = je["auraTypeId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + uint8_t kind = wowee::pipeline::WoweeSpellAuraType::Periodic; + if (je.contains("auraKind")) + kind = parseAuraKindToken(je["auraKind"], kind); + else if (je.contains("auraKindName")) + kind = parseAuraKindToken(je["auraKindName"], kind); + e.auraKind = kind; + uint8_t hint = wowee::pipeline::WoweeSpellAuraType::AnyUnit; + if (je.contains("targetingHint")) + hint = parseTargetingHintToken(je["targetingHint"], hint); + else if (je.contains("targetingHintName")) + hint = parseTargetingHintToken(je["targetingHintName"], hint); + e.targetingHint = hint; + if (je.contains("isStackable")) { + if (je["isStackable"].is_boolean()) + e.isStackable = je["isStackable"].get() ? 1 : 0; + else + e.isStackable = je["isStackable"].get() ? 1 : 0; + } + if (je.contains("maxStackCount")) e.maxStackCount = je["maxStackCount"].get(); + if (je.contains("updateFrequencyMs")) e.updateFrequencyMs = je["updateFrequencyMs"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".waur.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 = stripWaurExt(outBase); + if (!wowee::pipeline::WoweeSpellAuraTypeLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-waur-json: failed to save %s.waur\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.waur\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" auras : %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); @@ -237,6 +414,12 @@ bool handleSpellAuraTypesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-waur") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-waur-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-waur-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }