diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index af7692fc..dde80d2e 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -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", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index f8e36848..2077c6e2 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -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 [--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 [out.json]\n"); + std::printf(" Export binary .wspk to a human-editable JSON sidecar (defaults to .wspk.json; emits spellIds as JSON int array preserving display order)\n"); + std::printf(" --import-wspk-json [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 [--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 [--magic ] [--json]\n"); diff --git a/tools/editor/cli_spell_pack_catalog.cpp b/tools/editor/cli_spell_pack_catalog.cpp index 89833270..7870d33c 100644 --- a/tools/editor/cli_spell_pack_catalog.cpp +++ b/tools/editor/cli_spell_pack_catalog.cpp @@ -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(je.value("classId", 0)); + e.tabIndex = static_cast(je.value("tabIndex", 0)); + e.iconIndex = static_cast(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()); + } + } + } + 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; }