diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 6ddae2d2..5d835831 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -281,6 +281,7 @@ const char* const kArgRequired[] = { "--export-wcmr-json", "--import-wcmr-json", "--gen-bos", "--gen-bos-raid10", "--gen-bos-world", "--info-wbos", "--validate-wbos", + "--export-wbos-json", "--import-wbos-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_boss_encounters_catalog.cpp b/tools/editor/cli_boss_encounters_catalog.cpp index 13441241..481b7729 100644 --- a/tools/editor/cli_boss_encounters_catalog.cpp +++ b/tools/editor/cli_boss_encounters_catalog.cpp @@ -131,6 +131,120 @@ 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 = stripWbosExt(base); + if (!wowee::pipeline::WoweeBossEncounterLoader::exists(base)) { + std::fprintf(stderr, + "export-wbos-json: WBOS not found: %s.wbos\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeBossEncounterLoader::load(base); + if (outPath.empty()) outPath = base + ".wbos.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["encounterId"] = e.encounterId; + je["name"] = e.name; + je["description"] = e.description; + je["bossCreatureId"] = e.bossCreatureId; + je["mapId"] = e.mapId; + je["difficultyId"] = e.difficultyId; + je["berserkSpellId"] = e.berserkSpellId; + je["enrageTimerMs"] = e.enrageTimerMs; + je["phaseCount"] = e.phaseCount; + je["requiredPartySize"] = e.requiredPartySize; + je["recommendedItemLevel"] = e.recommendedItemLevel; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wbos-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(" encounters : %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]; + std::ifstream is(jsonPath); + if (!is) { + std::fprintf(stderr, + "import-wbos-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-wbos-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeBossEncounter 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::WoweeBossEncounter::Entry e; + if (je.contains("encounterId")) e.encounterId = je["encounterId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("bossCreatureId")) e.bossCreatureId = je["bossCreatureId"].get(); + if (je.contains("mapId")) e.mapId = je["mapId"].get(); + if (je.contains("difficultyId")) e.difficultyId = je["difficultyId"].get(); + if (je.contains("berserkSpellId")) e.berserkSpellId = je["berserkSpellId"].get(); + if (je.contains("enrageTimerMs")) e.enrageTimerMs = je["enrageTimerMs"].get(); + if (je.contains("phaseCount")) e.phaseCount = je["phaseCount"].get(); + if (je.contains("requiredPartySize")) e.requiredPartySize = je["requiredPartySize"].get(); + if (je.contains("recommendedItemLevel")) e.recommendedItemLevel = je["recommendedItemLevel"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wbos.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 = stripWbosExt(outBase); + if (!wowee::pipeline::WoweeBossEncounterLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wbos-json: failed to save %s.wbos\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wbos\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" encounters : %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); @@ -257,6 +371,12 @@ bool handleBossEncountersCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wbos") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wbos-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wbos-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index f3bfce27..ee316595 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2037,6 +2037,10 @@ void printUsage(const char* argv0) { std::printf(" Print WBOS entries (id / boss creature / map / difficulty / phases / size / ilvl / soft-enrage minutes / berserk spell / name)\n"); std::printf(" --validate-wbos [--json]\n"); std::printf(" Static checks: id+name+boss+map+phases+size required, no duplicate ids; warns on non-standard party size, berserkSpellId set without enrageTimerMs, enrage > 30 min\n"); + std::printf(" --export-wbos-json [out.json]\n"); + std::printf(" Export binary .wbos to a human-editable JSON sidecar (defaults to .wbos.json)\n"); + std::printf(" --import-wbos-json [out-base]\n"); + std::printf(" Import a .wbos.json sidecar back into binary .wbos (all per-entry fields preserved verbatim)\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");