diff --git a/tools/editor/cli_action_bars_catalog.cpp b/tools/editor/cli_action_bars_catalog.cpp index a702200a..1645a908 100644 --- a/tools/editor/cli_action_bars_catalog.cpp +++ b/tools/editor/cli_action_bars_catalog.cpp @@ -122,6 +122,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 = stripWactExt(base); + if (!wowee::pipeline::WoweeActionBarLoader::exists(base)) { + std::fprintf(stderr, + "export-wact-json: WACT not found: %s.wact\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeActionBarLoader::load(base); + if (outPath.empty()) outPath = base + ".wact.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["bindingId"] = e.bindingId; + je["name"] = e.name; + je["description"] = e.description; + je["classMask"] = e.classMask; + je["spellId"] = e.spellId; + je["itemId"] = e.itemId; + je["buttonSlot"] = e.buttonSlot; + je["barMode"] = e.barMode; + je["barModeName"] = + wowee::pipeline::WoweeActionBar::barModeName(e.barMode); + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wact-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(" bindings : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseBarModeToken(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::WoweeActionBar::Custom) + 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 == "main") return wowee::pipeline::WoweeActionBar::Main; + if (s == "pet") return wowee::pipeline::WoweeActionBar::Pet; + if (s == "vehicle") return wowee::pipeline::WoweeActionBar::Vehicle; + if (s == "stance1") return wowee::pipeline::WoweeActionBar::Stance1; + if (s == "stance2") return wowee::pipeline::WoweeActionBar::Stance2; + if (s == "stance3") return wowee::pipeline::WoweeActionBar::Stance3; + if (s == "custom") return wowee::pipeline::WoweeActionBar::Custom; + } + 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-wact-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-wact-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeActionBar 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::WoweeActionBar::Entry e; + if (je.contains("bindingId")) e.bindingId = je["bindingId"].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("spellId")) e.spellId = je["spellId"].get(); + if (je.contains("itemId")) e.itemId = je["itemId"].get(); + if (je.contains("buttonSlot")) e.buttonSlot = je["buttonSlot"].get(); + uint8_t mode = wowee::pipeline::WoweeActionBar::Main; + if (je.contains("barMode")) + mode = parseBarModeToken(je["barMode"], mode); + else if (je.contains("barModeName")) + mode = parseBarModeToken(je["barModeName"], mode); + e.barMode = mode; + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wact.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 = stripWactExt(outBase); + if (!wowee::pipeline::WoweeActionBarLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wact-json: failed to save %s.wact\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wact\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" bindings : %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); @@ -246,6 +382,12 @@ bool handleActionBarsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wact") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wact-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wact-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index fd2b4d23..90539b4c 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -293,6 +293,7 @@ const char* const kArgRequired[] = { "--export-wstm-json", "--import-wstm-json", "--gen-act", "--gen-act-mage", "--gen-act-pet", "--info-wact", "--validate-wact", + "--export-wact-json", "--import-wact-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 3ae571fb..e41348d2 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2093,6 +2093,10 @@ void printUsage(const char* argv0) { std::printf(" Print WACT entries (id / classMask / barMode / buttonSlot / spellId / itemId / name)\n"); std::printf(" --validate-wact [--json]\n"); std::printf(" Static checks: id+name+classMask required, barMode 0..6, no duplicate ids; warns on slot>143, both spellId+itemId set, both 0 (empty button), and (classMask+barMode+slot) collisions for overlapping classes\n"); + std::printf(" --export-wact-json [out.json]\n"); + std::printf(" Export binary .wact to a human-editable JSON sidecar (defaults to .wact.json)\n"); + std::printf(" --import-wact-json [out-base]\n"); + std::printf(" Import a .wact.json sidecar back into binary .wact (accepts barMode int OR barModeName 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");