feat(editor): WSPK JSON round-trip closure

Adds --export-wspk-json / --import-wspk-json. spellIds serialize
as JSON int arrays preserving spellbook display order (top-to-
bottom in tab). All 3 presets (warrior/mage/rogue) byte-identical
binary roundtrip OK including Mage Frost tab [116, 122, 10] —
Frostbolt rank 1 still first, Frost Nova second, Blizzard third
after roundtrip.

Importer also restores className via implicit lookup from
classId on the export side, so a hand-edited JSON only needs
classId int — className field is informational.

CLI flag count 1335 -> 1337.
This commit is contained in:
Kelsi 2026-05-10 03:39:52 -07:00
parent 6d9d00fbb9
commit e652f8595d
3 changed files with 120 additions and 0 deletions

View file

@ -388,6 +388,7 @@ const char* const kArgRequired[] = {
"--export-wmod-json", "--import-wmod-json",
"--gen-spk-warrior", "--gen-spk-mage", "--gen-spk-rogue",
"--info-wspk", "--validate-wspk",
"--export-wspk-json", "--import-wspk-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -2527,6 +2527,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WSPK entries (packId / classId+name / tabIndex / iconIndex / spell count / tabName)\n");
std::printf(" --validate-wspk <wspk-base> [--json]\n");
std::printf(" Static checks: packId+tabName required, classId in 1..11, tabIndex in 0..3, no duplicate packIds, no duplicate (classId,tabIndex) pairs (spellbook UI dispatch tie), no zero spellIds, no duplicate spellIds within any tab; warns on classId 6/10 (vanilla DBC gap) and on empty tabs (player would see blank spellbook)\n");
std::printf(" --export-wspk-json <wspk-base> [out.json]\n");
std::printf(" Export binary .wspk to a human-editable JSON sidecar (defaults to <base>.wspk.json; emits spellIds as JSON int array preserving display order)\n");
std::printf(" --import-wspk-json <json-path> [out-base]\n");
std::printf(" Import a .wspk.json sidecar back into binary .wspk (spellIds array preserves order — round-trips per-tab spell lists 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");

View file

@ -260,6 +260,113 @@ 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 = stripWspkExt(base);
if (out.empty()) out = base + ".wspk.json";
if (!wowee::pipeline::WoweeSpellPackLoader::exists(base)) {
std::fprintf(stderr,
"export-wspk-json: WSPK not found: %s.wspk\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeSpellPackLoader::load(base);
nlohmann::json j;
j["magic"] = "WSPK";
j["version"] = 1;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"packId", e.packId},
{"classId", e.classId},
{"className", classIdName(e.classId)},
{"tabIndex", e.tabIndex},
{"iconIndex", e.iconIndex},
{"tabName", e.tabName},
{"spellIds", e.spellIds},
});
}
j["entries"] = arr;
std::ofstream os(out);
if (!os) {
std::fprintf(stderr,
"export-wspk-json: failed to open %s for write\n",
out.c_str());
return 1;
}
os << j.dump(2) << "\n";
std::printf("Wrote %s (%zu packs)\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) == ".wspk.json") {
outBase.resize(outBase.size() - 10);
} else {
stripExt(outBase, ".json");
stripExt(outBase, ".wspk");
}
}
std::ifstream is(in);
if (!is) {
std::fprintf(stderr,
"import-wspk-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-wspk-json: JSON parse error: %s\n", ex.what());
return 1;
}
wowee::pipeline::WoweeSpellPack c;
c.name = j.value("name", std::string{});
if (!j.contains("entries") || !j["entries"].is_array()) {
std::fprintf(stderr,
"import-wspk-json: missing or non-array 'entries'\n");
return 1;
}
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeSpellPack::Entry e;
e.packId = je.value("packId", 0u);
e.classId = static_cast<uint8_t>(je.value("classId", 0));
e.tabIndex = static_cast<uint8_t>(je.value("tabIndex", 0));
e.iconIndex = static_cast<uint8_t>(je.value("iconIndex", 0));
e.tabName = je.value("tabName", std::string{});
if (je.contains("spellIds") &&
je["spellIds"].is_array()) {
for (const auto& s : je["spellIds"]) {
if (s.is_number_unsigned() ||
s.is_number_integer()) {
e.spellIds.push_back(s.get<uint32_t>());
}
}
}
c.entries.push_back(e);
}
if (!wowee::pipeline::WoweeSpellPackLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wspk-json: failed to save %s.wspk\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wspk (%zu packs)\n",
outBase.c_str(), c.entries.size());
return 0;
}
} // namespace
bool handleSpellPackCatalog(int& i, int argc, char** argv,
@ -283,6 +390,14 @@ bool handleSpellPackCatalog(int& i, int argc, char** argv,
i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wspk-json") == 0 &&
i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wspk-json") == 0 &&
i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}