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.
This commit is contained in:
Kelsi 2026-05-09 22:51:40 -07:00
parent 24e9a55a10
commit 9f5678f67e
3 changed files with 180 additions and 0 deletions

View file

@ -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",

View file

@ -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 <wsef-base> [--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 <wsef-base> [out.json]\n");
std::printf(" Export binary .wsef to a human-editable JSON sidecar (defaults to <base>.wsef.json)\n");
std::printf(" --import-wsef-json <json-path> [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 <wow-base> [zoneName]\n");
std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n");
std::printf(" --gen-weather-arctic <wow-base> [zoneName]\n");

View file

@ -5,6 +5,7 @@
#include "pipeline/wowee_spell_effect_types.hpp"
#include <nlohmann/json.hpp>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstring>
@ -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<int>();
if (v < 0 || v > wowee::pipeline::WoweeSpellEffectType::Misc)
return fallback;
return static_cast<uint8_t>(v);
}
if (jv.is_string()) {
std::string s = jv.get<std::string>();
for (auto& ch : s) ch = static_cast<char>(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<uint8_t>();
if (jv.is_string()) {
std::string s = jv.get<std::string>();
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<char>(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<std::string>();
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<uint32_t>();
if (je.contains("name")) e.name = je["name"].get<std::string>();
if (je.contains("description")) e.description = je["description"].get<std::string>();
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<int32_t>();
if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get<uint32_t>();
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;
}