diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 7105cf4a..0113a71f 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -55,6 +55,7 @@ const char* const kArgRequired[] = { "--export-wlck-json", "--import-wlck-json", "--gen-skills", "--gen-skills-professions", "--gen-skills-weapons", "--info-wskl", "--validate-wskl", + "--export-wskl-json", "--import-wskl-json", "--gen-spells", "--gen-spells-mage", "--gen-spells-warrior", "--info-wspl", "--validate-wspl", "--gen-weather-temperate", "--gen-weather-arctic", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 7338efaa..6ae98c87 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -975,6 +975,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSKL entries (id / category / max rank / per-level grow / trainer-required / name)\n"); std::printf(" --validate-wskl [--json]\n"); std::printf(" Static checks: skillId>0+unique, name not empty, maxRank>0, weapon needs rankPerLevel>0\n"); + std::printf(" --export-wskl-json [out.json]\n"); + std::printf(" Export binary .wskl to a human-editable JSON sidecar (defaults to .wskl.json)\n"); + std::printf(" --import-wskl-json [out-base]\n"); + std::printf(" Import a .wskl.json sidecar back into binary .wskl (accepts category int OR categoryName string)\n"); std::printf(" --gen-spells [name]\n"); std::printf(" Emit .wspl starter spell catalog: 4 spells covering damage / heal / buff / teleport effect kinds\n"); std::printf(" --gen-spells-mage [name]\n"); diff --git a/tools/editor/cli_skills_catalog.cpp b/tools/editor/cli_skills_catalog.cpp index de4a17dd..b8efd6bb 100644 --- a/tools/editor/cli_skills_catalog.cpp +++ b/tools/editor/cli_skills_catalog.cpp @@ -121,6 +121,124 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int handleExportJson(int& i, int argc, char** argv) { + // Mirrors the JSON pairs added for every other novel + // open format. Each skill emits all 8 scalar fields plus + // dual int + name forms for categoryId. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWsklExt(base); + if (outPath.empty()) outPath = base + ".wskl.json"; + if (!wowee::pipeline::WoweeSkillLoader::exists(base)) { + std::fprintf(stderr, + "export-wskl-json: WSKL not found: %s.wskl\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeSkillLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"skillId", e.skillId}, + {"name", e.name}, + {"description", e.description}, + {"categoryId", e.categoryId}, + {"categoryName", wowee::pipeline::WoweeSkill::categoryName(e.categoryId)}, + {"canTrain", e.canTrain}, + {"maxRank", e.maxRank}, + {"rankPerLevel", e.rankPerLevel}, + {"iconPath", e.iconPath}, + }); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wskl-json: cannot write %s\n", outPath.c_str()); + return 1; + } + out << j.dump(2) << "\n"; + out.close(); + std::printf("Wrote %s\n", outPath.c_str()); + std::printf(" source : %s.wskl\n", base.c_str()); + std::printf(" skills : %zu\n", c.entries.size()); + 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]; + if (outBase.empty()) { + outBase = jsonPath; + std::string suffix = ".wskl.json"; + if (outBase.size() > suffix.size() && + outBase.substr(outBase.size() - suffix.size()) == suffix) { + outBase = outBase.substr(0, outBase.size() - suffix.size()); + } else if (outBase.size() > 5 && + outBase.substr(outBase.size() - 5) == ".json") { + outBase = outBase.substr(0, outBase.size() - 5); + } + } + outBase = stripWsklExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wskl-json: cannot read %s\n", jsonPath.c_str()); + return 1; + } + nlohmann::json j; + try { in >> j; } + catch (const std::exception& e) { + std::fprintf(stderr, + "import-wskl-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto categoryFromName = [](const std::string& s) -> uint8_t { + if (s == "weapon") return wowee::pipeline::WoweeSkill::Weapon; + if (s == "class") return wowee::pipeline::WoweeSkill::Class; + if (s == "profession") return wowee::pipeline::WoweeSkill::Profession; + if (s == "secondary") return wowee::pipeline::WoweeSkill::SecondaryProfession; + if (s == "language") return wowee::pipeline::WoweeSkill::Language; + if (s == "armor") return wowee::pipeline::WoweeSkill::ArmorProficiency; + if (s == "riding") return wowee::pipeline::WoweeSkill::Riding; + if (s == "weapon-spec") return wowee::pipeline::WoweeSkill::WeaponSpec; + return wowee::pipeline::WoweeSkill::Profession; + }; + wowee::pipeline::WoweeSkill c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeSkill::Entry e; + e.skillId = je.value("skillId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + if (je.contains("categoryId") && je["categoryId"].is_number_integer()) { + e.categoryId = static_cast(je["categoryId"].get()); + } else if (je.contains("categoryName") && je["categoryName"].is_string()) { + e.categoryId = categoryFromName(je["categoryName"].get()); + } + e.canTrain = static_cast(je.value("canTrain", 1)); + e.maxRank = static_cast(je.value("maxRank", 300)); + e.rankPerLevel = static_cast(je.value("rankPerLevel", 0)); + e.iconPath = je.value("iconPath", std::string{}); + c.entries.push_back(std::move(e)); + } + } + if (!wowee::pipeline::WoweeSkillLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wskl-json: failed to save %s.wskl\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wskl\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" skills : %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); @@ -225,6 +343,12 @@ bool handleSkillsCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wskl") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wskl-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wskl-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }