mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 11:33:52 +00:00
feat(editor): WPRC JSON round-trip closure
Adds --export-wprc-json / --import-wprc-json with the established
readEnumField template factoring int+name dual encoding for
triggerEvent ("onhit"/"oncrit"/"oncast"/"ontakedamage"/"onheal"/
"ondodge"/"onparry"/"onblock"/"onkill").
All 3 presets (weapon/ret/rage) byte-identical binary roundtrip
OK including the rage preset's previously-fixed Berserker Rage
proc rule (sourceSpellId=18499, procEffectSpellId=23691 distinct).
Live-tested self-loop validator a second time: re-introduced the
Berserker Rage source==effect bug via JSON edit (set effect back
to 18499). Validator correctly errored: "sourceSpellId ==
procEffectSpellId=18499 on OnCast trigger — infinite proc loop
(effect re-casts itself)". Confirms the round-trip path
preserves the self-loop guard and that the validator is ready
to catch this class of bug whenever a hand-edit reintroduces it.
CLI flag count 1443 -> 1445.
This commit is contained in:
parent
73d66a04d0
commit
e49567da3c
3 changed files with 178 additions and 0 deletions
|
|
@ -424,6 +424,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wirc-json", "--import-wirc-json",
|
||||
"--gen-prc-weapon", "--gen-prc-ret", "--gen-prc-rage",
|
||||
"--info-wprc", "--validate-wprc",
|
||||
"--export-wprc-json", "--import-wprc-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -2695,6 +2695,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WPRC entries (id / sourceSpellId / procEffectSpellId / triggerEvent / procChancePct / ICD ms / max stacks / flags / name)\n");
|
||||
std::printf(" --validate-wprc <wprc-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name+sourceSpellId+procEffectSpellId required, triggerEvent 0..8, procChancePct in 1..10000 (basis points; 0 = never fires, > 10000 = > 100%%); CRITICAL: sourceSpellId == procEffectSpellId on OnCast trigger errors (infinite proc loop — effect re-casts itself). Warns on 100%% chance + 0ms ICD on high-frequency event (OnHit/OnCrit/OnTakeDamage) — would spam every swing without rate limiting (performance footgun)\n");
|
||||
std::printf(" --export-wprc-json <wprc-base> [out.json]\n");
|
||||
std::printf(" Export binary .wprc to a human-editable JSON sidecar (defaults to <base>.wprc.json; emits triggerEvent as int + name string)\n");
|
||||
std::printf(" --import-wprc-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wprc.json sidecar back into binary .wprc (triggerEvent int OR \"onhit\"/\"oncrit\"/\"oncast\"/\"ontakedamage\"/\"onheal\"/\"ondodge\"/\"onparry\"/\"onblock\"/\"onkill\" — round-trips proc rule tables byte-identical)\n");
|
||||
std::printf(" --catalog-pluck <wXXX-file> <id> [--json]\n");
|
||||
std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n");
|
||||
std::printf(" --catalog-find <directory> <id> [--magic <WXXX>] [--json]\n");
|
||||
|
|
|
|||
|
|
@ -145,6 +145,58 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parseTriggerEventToken(const std::string& s) {
|
||||
using P = wowee::pipeline::WoweeSpellProcRules;
|
||||
if (s == "onhit") return P::OnHit;
|
||||
if (s == "oncrit") return P::OnCrit;
|
||||
if (s == "oncast") return P::OnCast;
|
||||
if (s == "ontakedamage") return P::OnTakeDamage;
|
||||
if (s == "onheal") return P::OnHeal;
|
||||
if (s == "ondodge") return P::OnDodge;
|
||||
if (s == "onparry") return P::OnParry;
|
||||
if (s == "onblock") return P::OnBlock;
|
||||
if (s == "onkill") return P::OnKill;
|
||||
return -1;
|
||||
}
|
||||
|
||||
template <typename ParseFn>
|
||||
bool readEnumField(const nlohmann::json& je,
|
||||
const char* intKey,
|
||||
const char* nameKey,
|
||||
ParseFn parseFn,
|
||||
const char* label,
|
||||
uint32_t entryId,
|
||||
uint8_t& outValue) {
|
||||
if (je.contains(intKey)) {
|
||||
const auto& v = je[intKey];
|
||||
if (v.is_string()) {
|
||||
int parsed = parseFn(v.get<std::string>());
|
||||
if (parsed < 0) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprc-json: unknown %s token "
|
||||
"'%s' on entry id=%u\n",
|
||||
label, v.get<std::string>().c_str(),
|
||||
entryId);
|
||||
return false;
|
||||
}
|
||||
outValue = static_cast<uint8_t>(parsed);
|
||||
return true;
|
||||
}
|
||||
if (v.is_number_integer()) {
|
||||
outValue = static_cast<uint8_t>(v.get<int>());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (je.contains(nameKey) && je[nameKey].is_string()) {
|
||||
int parsed = parseFn(je[nameKey].get<std::string>());
|
||||
if (parsed >= 0) {
|
||||
outValue = static_cast<uint8_t>(parsed);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int handleValidate(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
|
|
@ -267,6 +319,119 @@ int handleValidate(int& i, int argc, char** argv) {
|
|||
return ok ? 0 : 1;
|
||||
}
|
||||
|
||||
int handleExportJson(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string out;
|
||||
if (parseOptArg(i, argc, argv)) out = argv[++i];
|
||||
base = stripWprcExt(base);
|
||||
if (out.empty()) out = base + ".wprc.json";
|
||||
if (!wowee::pipeline::WoweeSpellProcRulesLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wprc-json: WPRC not found: %s.wprc\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeSpellProcRulesLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WPRC";
|
||||
j["version"] = 1;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"procRuleId", e.procRuleId},
|
||||
{"name", e.name},
|
||||
{"sourceSpellId", e.sourceSpellId},
|
||||
{"procEffectSpellId", e.procEffectSpellId},
|
||||
{"triggerEvent", e.triggerEvent},
|
||||
{"triggerEventName",
|
||||
triggerEventName(e.triggerEvent)},
|
||||
{"maxStacksOnTarget", e.maxStacksOnTarget},
|
||||
{"procChancePct", e.procChancePct},
|
||||
{"internalCooldownMs", e.internalCooldownMs},
|
||||
{"procFlagsMask", e.procFlagsMask},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wprc-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu procs)\n",
|
||||
out.c_str(), c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleImportJson(int& i, int argc, char** argv) {
|
||||
std::string in = argv[++i];
|
||||
std::string outBase;
|
||||
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
|
||||
if (outBase.empty()) {
|
||||
outBase = in;
|
||||
if (outBase.size() >= 10 &&
|
||||
outBase.substr(outBase.size() - 10) == ".wprc.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wprc");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprc-json: cannot open %s\n", in.c_str());
|
||||
return 1;
|
||||
}
|
||||
nlohmann::json j;
|
||||
try {
|
||||
is >> j;
|
||||
} catch (const std::exception& ex) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprc-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeSpellProcRules c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprc-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeSpellProcRules::Entry e;
|
||||
e.procRuleId = je.value("procRuleId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.sourceSpellId = je.value("sourceSpellId", 0u);
|
||||
e.procEffectSpellId = je.value("procEffectSpellId", 0u);
|
||||
if (!readEnumField(je, "triggerEvent", "triggerEventName",
|
||||
parseTriggerEventToken, "triggerEvent",
|
||||
e.procRuleId, e.triggerEvent))
|
||||
return 1;
|
||||
e.maxStacksOnTarget = static_cast<uint8_t>(
|
||||
je.value("maxStacksOnTarget", 0));
|
||||
e.procChancePct = static_cast<uint16_t>(
|
||||
je.value("procChancePct", 0));
|
||||
e.internalCooldownMs =
|
||||
je.value("internalCooldownMs", 0u);
|
||||
e.procFlagsMask = static_cast<uint16_t>(
|
||||
je.value("procFlagsMask", 0));
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweeSpellProcRulesLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprc-json: failed to save %s.wprc\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wprc (%zu procs)\n",
|
||||
outBase.c_str(), c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool handleSpellProcRulesCatalog(int& i, int argc, char** argv,
|
||||
|
|
@ -290,6 +455,14 @@ bool handleSpellProcRulesCatalog(int& i, int argc, char** argv,
|
|||
i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wprc-json") == 0 &&
|
||||
i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wprc-json") == 0 &&
|
||||
i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue