diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 92121aa7..c103fc9f 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -268,6 +268,7 @@ const char* const kArgRequired[] = { "--export-wifs-json", "--import-wifs-json", "--gen-bkd", "--gen-bkd-battle", "--gen-bkd-profession", "--info-wbkd", "--validate-wbkd", + "--export-wbkd-json", "--import-wbkd-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 6ce9aa89..f7b0a030 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1977,6 +1977,10 @@ void printUsage(const char* argv0) { std::printf(" Print WBKD entries (id / kind / gold cost / faction gate / gossip text id / name)\n"); std::printf(" --validate-wbkd [--json]\n"); std::printf(" Static checks: id+name required, serviceKind 0..11, no duplicate ids; warns on Mailbox+gossip (no NPC dialog), Innkeeper+no-gossip (silent bind), Battlemaster+gold (queues are free)\n"); + std::printf(" --export-wbkd-json [out.json]\n"); + std::printf(" Export binary .wbkd to a human-editable JSON sidecar (defaults to .wbkd.json)\n"); + std::printf(" --import-wbkd-json [out-base]\n"); + std::printf(" Import a .wbkd.json sidecar back into binary .wbkd (accepts serviceKind int OR serviceKindName 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_npc_services_catalog.cpp b/tools/editor/cli_npc_services_catalog.cpp index 2dab86da..b973a3c3 100644 --- a/tools/editor/cli_npc_services_catalog.cpp +++ b/tools/editor/cli_npc_services_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_npc_services.hpp" #include +#include #include #include #include @@ -120,6 +121,151 @@ 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 = stripWbkdExt(base); + if (!wowee::pipeline::WoweeNPCServiceLoader::exists(base)) { + std::fprintf(stderr, + "export-wbkd-json: WBKD not found: %s.wbkd\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeNPCServiceLoader::load(base); + if (outPath.empty()) outPath = base + ".wbkd.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["serviceId"] = e.serviceId; + je["name"] = e.name; + je["description"] = e.description; + je["serviceKind"] = e.serviceKind; + je["serviceKindName"] = + wowee::pipeline::WoweeNPCService::serviceKindName(e.serviceKind); + je["requiresGold"] = e.requiresGold; + je["factionRequiredId"] = e.factionRequiredId; + je["gossipTextId"] = e.gossipTextId; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wbkd-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(" services : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseServiceKindToken(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::WoweeNPCService::Misc) + 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 == "banker") return wowee::pipeline::WoweeNPCService::Banker; + if (s == "mailbox") return wowee::pipeline::WoweeNPCService::Mailbox; + if (s == "auctioneer") return wowee::pipeline::WoweeNPCService::Auctioneer; + if (s == "stable-master" || + s == "stablemaster") return wowee::pipeline::WoweeNPCService::StableMaster; + if (s == "flight-master" || + s == "flightmaster") return wowee::pipeline::WoweeNPCService::FlightMaster; + if (s == "trainer") return wowee::pipeline::WoweeNPCService::Trainer; + if (s == "innkeeper") return wowee::pipeline::WoweeNPCService::Innkeeper; + if (s == "battlemaster") return wowee::pipeline::WoweeNPCService::Battlemaster; + if (s == "guild-banker" || + s == "guildbanker") return wowee::pipeline::WoweeNPCService::GuildBanker; + if (s == "reagent-vendor" || + s == "reagentvendor") return wowee::pipeline::WoweeNPCService::ReagentVendor; + if (s == "tabard-vendor" || + s == "tabardvendor") return wowee::pipeline::WoweeNPCService::TabardVendor; + if (s == "misc") return wowee::pipeline::WoweeNPCService::Misc; + } + 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-wbkd-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-wbkd-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeNPCService 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::WoweeNPCService::Entry e; + if (je.contains("serviceId")) e.serviceId = je["serviceId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + uint8_t kind = wowee::pipeline::WoweeNPCService::Banker; + if (je.contains("serviceKind")) + kind = parseServiceKindToken(je["serviceKind"], kind); + else if (je.contains("serviceKindName")) + kind = parseServiceKindToken(je["serviceKindName"], kind); + e.serviceKind = kind; + if (je.contains("requiresGold")) e.requiresGold = je["requiresGold"].get(); + if (je.contains("factionRequiredId")) e.factionRequiredId = je["factionRequiredId"].get(); + if (je.contains("gossipTextId")) e.gossipTextId = je["gossipTextId"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wbkd.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 = stripWbkdExt(outBase); + if (!wowee::pipeline::WoweeNPCServiceLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wbkd-json: failed to save %s.wbkd\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wbkd\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" services : %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); @@ -234,6 +380,12 @@ bool handleNPCServicesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wbkd") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wbkd-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wbkd-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }