From 9f5678f67e5adb1b91eb422a18b804d4cddd6be9 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 22:51:40 -0700 Subject: [PATCH] feat(editor): add WSEF JSON round-trip (--export/--import-wsef-json) Closes the editing loop on the spell-effect-type catalog: dump a .wsef to JSON, hand-edit effectKind / behaviorFlags / baseAmount (e.g. tag a server-custom effect ID as Damage kind, add IgnoresImmunities to a custom dispel, retune ScriptedHeal's default baseAmount), re-import to a byte-identical binary. Two dual-encoded fields: - effectKind: int 0..9 OR "damage" / "heal" / "aura" / "energize" / "trigger" / "movement" / "summon" / "dispel" / "dummy" / "misc" - behaviorFlags: int bitfield OR pipe-separated label string ("RequiresTarget|IsHostileEffect|TriggersGCD"). Importer prefers int form when both present so unknown bits round- trip losslessly. Verified byte-identical round-trip on all three presets (damage / healing / aura). CLI flag count 994 -> 996. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + .../editor/cli_spell_effect_types_catalog.cpp | 175 ++++++++++++++++++ 3 files changed, 180 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index e48327a7..b0f13d8f 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -253,6 +253,7 @@ const char* const kArgRequired[] = { "--export-wacr-json", "--import-wacr-json", "--gen-sef", "--gen-sef-healing", "--gen-sef-aura", "--info-wsef", "--validate-wsef", + "--export-wsef-json", "--import-wsef-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 3649ba40..565d94db 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1905,6 +1905,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSEF entries (id / kind / baseAmount / behavior flags / name) — flags decoded as label list\n"); std::printf(" --validate-wsef [--json]\n"); std::printf(" Static checks: name required, effectKind 0..9, no duplicate ids; warns on Hostile+Beneficial conflict, Damage without TriggersGCD, Heal without IsBeneficialEffect\n"); + std::printf(" --export-wsef-json [out.json]\n"); + std::printf(" Export binary .wsef to a human-editable JSON sidecar (defaults to .wsef.json)\n"); + std::printf(" --import-wsef-json [out-base]\n"); + std::printf(" Import a .wsef.json sidecar back into binary .wsef (accepts effectKind int OR effectKindName string; behaviorFlags int OR pipe-separated label 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_effect_types_catalog.cpp b/tools/editor/cli_spell_effect_types_catalog.cpp index c8dfd6b9..f30b7c51 100644 --- a/tools/editor/cli_spell_effect_types_catalog.cpp +++ b/tools/editor/cli_spell_effect_types_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_spell_effect_types.hpp" #include +#include #include #include #include @@ -140,6 +141,174 @@ 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 = stripWsefExt(base); + if (!wowee::pipeline::WoweeSpellEffectTypeLoader::exists(base)) { + std::fprintf(stderr, + "export-wsef-json: WSEF not found: %s.wsef\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeSpellEffectTypeLoader::load(base); + if (outPath.empty()) outPath = base + ".wsef.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + std::string flagNames; + appendBehaviorFlagNames(e.behaviorFlags, flagNames); + nlohmann::json je; + je["effectId"] = e.effectId; + je["name"] = e.name; + je["description"] = e.description; + je["effectKind"] = e.effectKind; + je["effectKindName"] = + wowee::pipeline::WoweeSpellEffectType::effectKindName(e.effectKind); + je["behaviorFlags"] = e.behaviorFlags; + je["behaviorFlagsLabels"] = flagNames; + je["baseAmount"] = e.baseAmount; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wsef-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(" effects : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseEffectKindToken(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::WoweeSpellEffectType::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 == "damage") return wowee::pipeline::WoweeSpellEffectType::Damage; + if (s == "heal") return wowee::pipeline::WoweeSpellEffectType::Heal; + if (s == "aura") return wowee::pipeline::WoweeSpellEffectType::Aura; + if (s == "energize") return wowee::pipeline::WoweeSpellEffectType::Energize; + if (s == "trigger") return wowee::pipeline::WoweeSpellEffectType::Trigger; + if (s == "movement") return wowee::pipeline::WoweeSpellEffectType::Movement; + if (s == "summon") return wowee::pipeline::WoweeSpellEffectType::Summon; + if (s == "dispel") return wowee::pipeline::WoweeSpellEffectType::Dispel; + if (s == "dummy") return wowee::pipeline::WoweeSpellEffectType::Dummy; + if (s == "misc") return wowee::pipeline::WoweeSpellEffectType::Misc; + } + return fallback; +} + +uint8_t parseBehaviorFlagsField(const nlohmann::json& jv) { + using F = wowee::pipeline::WoweeSpellEffectType; + if (jv.is_number_integer() || jv.is_number_unsigned()) + return jv.get(); + if (jv.is_string()) { + std::string s = jv.get(); + uint8_t out = 0; + size_t pos = 0; + while (pos < s.size()) { + size_t end = s.find('|', pos); + if (end == std::string::npos) end = s.size(); + std::string tok = s.substr(pos, end - pos); + for (auto& ch : tok) ch = static_cast(std::tolower(ch)); + if (tok == "requirestarget") out |= F::RequiresTarget; + else if (tok == "requireslineofsight") out |= F::RequiresLineOfSight; + else if (tok == "ishostileeffect") out |= F::IsHostileEffect; + else if (tok == "isbeneficialeffect") out |= F::IsBeneficialEffect; + else if (tok == "ignoresimmunities") out |= F::IgnoresImmunities; + else if (tok == "triggersgcd") out |= F::TriggersGCD; + pos = end + 1; + } + return out; + } + 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]; + std::ifstream is(jsonPath); + if (!is) { + std::fprintf(stderr, + "import-wsef-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-wsef-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeSpellEffectType 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::WoweeSpellEffectType::Entry e; + if (je.contains("effectId")) e.effectId = je["effectId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + uint8_t kind = wowee::pipeline::WoweeSpellEffectType::Damage; + if (je.contains("effectKind")) + kind = parseEffectKindToken(je["effectKind"], kind); + else if (je.contains("effectKindName")) + kind = parseEffectKindToken(je["effectKindName"], kind); + e.effectKind = kind; + if (je.contains("behaviorFlags")) + e.behaviorFlags = parseBehaviorFlagsField(je["behaviorFlags"]); + else if (je.contains("behaviorFlagsLabels")) + e.behaviorFlags = parseBehaviorFlagsField(je["behaviorFlagsLabels"]); + if (je.contains("baseAmount")) e.baseAmount = je["baseAmount"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wsef.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 = stripWsefExt(outBase); + if (!wowee::pipeline::WoweeSpellEffectTypeLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wsef-json: failed to save %s.wsef\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wsef\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" effects : %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); @@ -261,6 +430,12 @@ bool handleSpellEffectTypesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wsef") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wsef-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wsef-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }