diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index a212634d..ad876054 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -239,6 +239,7 @@ const char* const kArgRequired[] = { "--export-wpsp-json", "--import-wpsp-json", "--gen-tle", "--gen-tle-mage", "--gen-tle-paladin", "--info-wtle", "--validate-wtle", + "--export-wtle-json", "--import-wtle-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 33044b3a..e0c0e8ba 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1843,6 +1843,10 @@ void printUsage(const char* argv0) { std::printf(" Print WTLE entries (id / classMask / displayOrder / role / name / backgroundFile)\n"); std::printf(" --validate-wtle [--json]\n"); std::printf(" Static checks: id+name+classMask required, roleHint 0..4, no duplicate ids; warns on empty icon/background, displayOrder>3, and (classMask+order) UI position collisions\n"); + std::printf(" --export-wtle-json [out.json]\n"); + std::printf(" Export binary .wtle to a human-editable JSON sidecar (defaults to .wtle.json)\n"); + std::printf(" --import-wtle-json [out-base]\n"); + std::printf(" Import a .wtle.json sidecar back into binary .wtle (accepts roleHint int OR roleHintName string)\n"); std::printf(" --gen-weather-temperate [zoneName]\n"); std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n"); std::printf(" --gen-weather-arctic [zoneName]\n"); diff --git a/tools/editor/cli_talent_tabs_catalog.cpp b/tools/editor/cli_talent_tabs_catalog.cpp index 980c4d11..2391b52d 100644 --- a/tools/editor/cli_talent_tabs_catalog.cpp +++ b/tools/editor/cli_talent_tabs_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_talent_tabs.hpp" #include +#include #include #include #include @@ -122,6 +123,142 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int handleExportJson(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWtleExt(base); + if (!wowee::pipeline::WoweeTalentTabLoader::exists(base)) { + std::fprintf(stderr, + "export-wtle-json: WTLE not found: %s.wtle\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeTalentTabLoader::load(base); + if (outPath.empty()) outPath = base + ".wtle.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["tabId"] = e.tabId; + je["name"] = e.name; + je["description"] = e.description; + je["classMask"] = e.classMask; + je["displayOrder"] = e.displayOrder; + je["roleHint"] = e.roleHint; + je["roleHintName"] = + wowee::pipeline::WoweeTalentTab::roleHintName(e.roleHint); + je["iconPath"] = e.iconPath; + je["backgroundFile"] = e.backgroundFile; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wtle-json: failed to open %s for write\n", + outPath.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s\n", outPath.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" tabs : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseRoleHintToken(const nlohmann::json& jv, + uint8_t fallback) { + if (jv.is_number_integer() || jv.is_number_unsigned()) { + int v = jv.get(); + if (v < 0 || v > wowee::pipeline::WoweeTalentTab::PetClass) + return fallback; + return static_cast(v); + } + if (jv.is_string()) { + std::string s = jv.get(); + for (auto& ch : s) ch = static_cast(std::tolower(ch)); + if (s == "dps") return wowee::pipeline::WoweeTalentTab::DPS; + if (s == "tank") return wowee::pipeline::WoweeTalentTab::Tank; + if (s == "healer") return wowee::pipeline::WoweeTalentTab::Healer; + if (s == "hybrid") return wowee::pipeline::WoweeTalentTab::Hybrid; + if (s == "pet" || + s == "petclass") return wowee::pipeline::WoweeTalentTab::PetClass; + } + return fallback; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string jsonPath = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + std::ifstream is(jsonPath); + if (!is) { + std::fprintf(stderr, + "import-wtle-json: failed to open %s\n", jsonPath.c_str()); + return 1; + } + nlohmann::json j; + try { + is >> j; + } catch (const std::exception& ex) { + std::fprintf(stderr, + "import-wtle-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeTalentTab c; + if (j.contains("catalog") && j["catalog"].is_string()) + c.name = j["catalog"].get(); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeTalentTab::Entry e; + if (je.contains("tabId")) e.tabId = je["tabId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("classMask")) e.classMask = je["classMask"].get(); + if (je.contains("displayOrder")) e.displayOrder = je["displayOrder"].get(); + uint8_t role = wowee::pipeline::WoweeTalentTab::DPS; + if (je.contains("roleHint")) + role = parseRoleHintToken(je["roleHint"], role); + else if (je.contains("roleHintName")) + role = parseRoleHintToken(je["roleHintName"], role); + e.roleHint = role; + if (je.contains("iconPath")) e.iconPath = je["iconPath"].get(); + if (je.contains("backgroundFile")) e.backgroundFile = je["backgroundFile"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wtle.json"; + const std::string suffix2 = ".json"; + if (outBase.size() >= suffix1.size() && + outBase.compare(outBase.size() - suffix1.size(), + suffix1.size(), suffix1) == 0) { + outBase.resize(outBase.size() - suffix1.size()); + } else if (outBase.size() >= suffix2.size() && + outBase.compare(outBase.size() - suffix2.size(), + suffix2.size(), suffix2) == 0) { + outBase.resize(outBase.size() - suffix2.size()); + } + } + outBase = stripWtleExt(outBase); + if (!wowee::pipeline::WoweeTalentTabLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wtle-json: failed to save %s.wtle\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wtle\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" tabs : %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); @@ -242,6 +379,12 @@ bool handleTalentTabsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wtle") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wtle-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wtle-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }