diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 5162670e..f37ff968 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -330,6 +330,7 @@ const char* const kArgRequired[] = { "--export-wcre-json", "--import-wcre-json", "--gen-ptt", "--gen-ptt-cunning", "--gen-ptt-tenacity", "--info-wptt", "--validate-wptt", + "--export-wptt-json", "--import-wptt-json", "--gen-hrd", "--gen-hrd-raid25", "--gen-hrd-cm", "--info-whrd", "--validate-whrd", "--gen-weather-temperate", "--gen-weather-arctic", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 880d2371..ae7da40b 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2261,6 +2261,10 @@ void printUsage(const char* argv0) { std::printf(" Print WPTT entries (id / tree / tier / column / max ranks / prereq talentId / loyalty req / name) plus per-talent rank-spell IDs\n"); std::printf(" --validate-wptt [--json]\n"); std::printf(" Static checks: id+name required, treeKind 0..2, tier 0..6, column 0..2, maxRank 1..5, no duplicate talentIds, no two talents in same (tree,tier,col) cell, no self-referencing prereqs, prereqs resolve to existing entries IN SAME TREE at EARLIER TIER, spellIdsByRank.size() == maxRank, no zero-spell-id within array\n"); + std::printf(" --export-wptt-json [out.json]\n"); + std::printf(" Export binary .wptt to a human-editable JSON sidecar (defaults to .wptt.json; emits treeKind as both int AND name string; spellIdsByRank as a JSON array of spell IDs)\n"); + std::printf(" --import-wptt-json [out-base]\n"); + std::printf(" Import a .wptt.json sidecar back into binary .wptt (treeKind int OR \"cunning\"/\"ferocity\"/\"tenacity\")\n"); std::printf(" --gen-hrd [name]\n"); std::printf(" Emit .whrd 5 WotLK 5-man Heroic scalings (Utgarde Keep / Nexus / Azjol-Nerub / Ahn'kahet / Drak'Tharon — +13 ilvl, 2x Emblem of Heroism)\n"); std::printf(" --gen-hrd-raid25 [name]\n"); diff --git a/tools/editor/cli_pet_talents_catalog.cpp b/tools/editor/cli_pet_talents_catalog.cpp index a32070d9..25777aa0 100644 --- a/tools/editor/cli_pet_talents_catalog.cpp +++ b/tools/editor/cli_pet_talents_catalog.cpp @@ -144,6 +144,155 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int parseTreeKindToken(const std::string& s) { + using P = wowee::pipeline::WoweePetTalents; + if (s == "cunning") return P::Cunning; + if (s == "ferocity") return P::Ferocity; + if (s == "tenacity") return P::Tenacity; + 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 = stripWpttExt(base); + if (out.empty()) out = base + ".wptt.json"; + if (!wowee::pipeline::WoweePetTalentsLoader::exists(base)) { + std::fprintf(stderr, + "export-wptt-json: WPTT not found: %s.wptt\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweePetTalentsLoader::load(base); + nlohmann::json j; + j["magic"] = "WPTT"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"talentId", e.talentId}, + {"name", e.name}, + {"description", e.description}, + {"treeKind", e.treeKind}, + {"treeKindName", treeKindName(e.treeKind)}, + {"tier", e.tier}, + {"column", e.column}, + {"maxRank", e.maxRank}, + {"prerequisiteTalentId", e.prerequisiteTalentId}, + {"requiredLoyalty", e.requiredLoyalty}, + {"iconColorRGBA", e.iconColorRGBA}, + {"spellIdsByRank", e.spellIdsByRank}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wptt-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu talents)\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) == ".wptt.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wptt"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wptt-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-wptt-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweePetTalents c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wptt-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweePetTalents::Entry e; + e.talentId = je.value("talentId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + if (je.contains("treeKind")) { + const auto& v = je["treeKind"]; + if (v.is_string()) { + int parsed = parseTreeKindToken( + v.get()); + if (parsed < 0) { + std::fprintf(stderr, + "import-wptt-json: unknown " + "treeKind token '%s' on entry " + "id=%u\n", + v.get().c_str(), + e.talentId); + return 1; + } + e.treeKind = static_cast(parsed); + } else if (v.is_number_integer()) { + e.treeKind = static_cast(v.get()); + } + } else if (je.contains("treeKindName") && + je["treeKindName"].is_string()) { + int parsed = parseTreeKindToken( + je["treeKindName"].get()); + if (parsed >= 0) + e.treeKind = static_cast(parsed); + } + e.tier = static_cast(je.value("tier", 0u)); + e.column = static_cast(je.value("column", 0u)); + e.maxRank = static_cast(je.value("maxRank", 1u)); + e.prerequisiteTalentId = je.value( + "prerequisiteTalentId", 0u); + e.requiredLoyalty = static_cast( + je.value("requiredLoyalty", 0u)); + e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu); + if (je.contains("spellIdsByRank") && + je["spellIdsByRank"].is_array()) { + for (const auto& s : je["spellIdsByRank"]) { + if (s.is_number_integer()) + e.spellIdsByRank.push_back(s.get()); + } + } + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweePetTalentsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wptt-json: failed to save %s.wptt\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wptt (%zu talents)\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); @@ -337,6 +486,12 @@ bool handlePetTalentsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wptt") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wptt-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wptt-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }