mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WSPV JSON round-trip (--export/--import-wspv-json)
Dual encoding for conditionKind (int 0..5 OR token "stance"/"form"/"talent"/"race"/"equippedweapon"/ "auraactive"). conditionValue stays as raw uint32 since its semantics depend on conditionKind — pretty-printing would require six different lookup paths (stance spellId, talent ID, race bit, etc.) which is more complexity than benefit. All 3 presets (warrior/talent/racial) byte-identical roundtrip OK. CLI flag count 1218 -> 1220.
This commit is contained in:
parent
6403d84a28
commit
a5a16cae52
3 changed files with 153 additions and 0 deletions
|
|
@ -349,6 +349,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wmvc-json", "--import-wmvc-json",
|
||||
"--gen-spv", "--gen-spv-talent", "--gen-spv-racial",
|
||||
"--info-wspv", "--validate-wspv",
|
||||
"--export-wspv-json", "--import-wspv-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -2345,6 +2345,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WSPV entries (id / baseSpellId / variantSpellId / conditionKind / conditionValue / priority / name)\n");
|
||||
std::printf(" --validate-wspv <wspv-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name+baseSpellId+variantSpellId required, conditionKind 0..5, no duplicate variantIds, no two variants binding the same (baseSpell, conditionKind, conditionValue, priority) tuple (would tie at runtime and resolve non-deterministically); warns on conditionValue=0 (always-zero default match — gate becomes no-op)\n");
|
||||
std::printf(" --export-wspv-json <wspv-base> [out.json]\n");
|
||||
std::printf(" Export binary .wspv to a human-editable JSON sidecar (defaults to <base>.wspv.json; emits conditionKind as both int AND name string; conditionValue stays as raw uint32 — its semantics depend on conditionKind so no general-purpose pretty-printing)\n");
|
||||
std::printf(" --import-wspv-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wspv.json sidecar back into binary .wspv (conditionKind int OR \"stance\"/\"form\"/\"talent\"/\"race\"/\"equippedweapon\"/\"auraactive\")\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");
|
||||
|
|
|
|||
|
|
@ -138,6 +138,148 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parseConditionKindToken(const std::string& s) {
|
||||
using V = wowee::pipeline::WoweeSpellVariants;
|
||||
if (s == "stance") return V::Stance;
|
||||
if (s == "form") return V::Form;
|
||||
if (s == "talent") return V::Talent;
|
||||
if (s == "race") return V::Race;
|
||||
if (s == "equippedweapon") return V::EquippedWeapon;
|
||||
if (s == "auraactive") return V::AuraActive;
|
||||
return -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 = stripWspvExt(base);
|
||||
if (out.empty()) out = base + ".wspv.json";
|
||||
if (!wowee::pipeline::WoweeSpellVariantsLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wspv-json: WSPV not found: %s.wspv\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeSpellVariantsLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WSPV";
|
||||
j["version"] = 1;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"variantId", e.variantId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"baseSpellId", e.baseSpellId},
|
||||
{"variantSpellId", e.variantSpellId},
|
||||
{"conditionKind", e.conditionKind},
|
||||
{"conditionKindName", conditionKindName(e.conditionKind)},
|
||||
{"priority", e.priority},
|
||||
{"conditionValue", e.conditionValue},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wspv-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu variants)\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) == ".wspv.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wspv");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wspv-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-wspv-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeSpellVariants c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wspv-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeSpellVariants::Entry e;
|
||||
e.variantId = je.value("variantId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
e.baseSpellId = je.value("baseSpellId", 0u);
|
||||
e.variantSpellId = je.value("variantSpellId", 0u);
|
||||
if (je.contains("conditionKind")) {
|
||||
const auto& v = je["conditionKind"];
|
||||
if (v.is_string()) {
|
||||
int parsed = parseConditionKindToken(
|
||||
v.get<std::string>());
|
||||
if (parsed < 0) {
|
||||
std::fprintf(stderr,
|
||||
"import-wspv-json: unknown "
|
||||
"conditionKind token '%s' on "
|
||||
"entry id=%u\n",
|
||||
v.get<std::string>().c_str(),
|
||||
e.variantId);
|
||||
return 1;
|
||||
}
|
||||
e.conditionKind = static_cast<uint8_t>(parsed);
|
||||
} else if (v.is_number_integer()) {
|
||||
e.conditionKind = static_cast<uint8_t>(
|
||||
v.get<int>());
|
||||
}
|
||||
} else if (je.contains("conditionKindName") &&
|
||||
je["conditionKindName"].is_string()) {
|
||||
int parsed = parseConditionKindToken(
|
||||
je["conditionKindName"].get<std::string>());
|
||||
if (parsed >= 0)
|
||||
e.conditionKind = static_cast<uint8_t>(parsed);
|
||||
}
|
||||
e.priority = static_cast<uint8_t>(
|
||||
je.value("priority", 1u));
|
||||
e.conditionValue = je.value("conditionValue", 0u);
|
||||
e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu);
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweeSpellVariantsLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wspv-json: failed to save %s.wspv\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wspv (%zu variants)\n",
|
||||
outBase.c_str(), c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleValidate(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
|
|
@ -277,6 +419,12 @@ bool handleSpellVariantsCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wspv") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wspv-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wspv-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