diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index a940df73..484a048a 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -94,6 +94,7 @@ const char* const kArgRequired[] = { "--export-wsea-json", "--import-wsea-json", "--gen-mounts", "--gen-mounts-racial", "--gen-mounts-flying", "--info-wmou", "--validate-wmou", + "--export-wmou-json", "--import-wmou-json", "--gen-bg", "--gen-bg-classic", "--gen-bg-arena", "--info-wbgd", "--validate-wbgd", "--gen-weather-temperate", "--gen-weather-arctic", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 1d3997b1..27b4062e 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1161,6 +1161,10 @@ void printUsage(const char* argv0) { std::printf(" Print WMOU entries (id / kind / speed / required riding rank / faction / category / name)\n"); std::printf(" --validate-wmou [--json]\n"); std::printf(" Static checks: id>0+unique, name not empty, summonSpellId>0, flying needs rank>=150, racial needs raceMask\n"); + std::printf(" --export-wmou-json [out.json]\n"); + std::printf(" Export binary .wmou to a human-editable JSON sidecar (defaults to .wmou.json)\n"); + std::printf(" --import-wmou-json [out-base]\n"); + std::printf(" Import a .wmou.json sidecar back into binary .wmou (accepts kind/faction/category int OR name forms)\n"); std::printf(" --gen-bg [name]\n"); std::printf(" Emit .wbgd starter: 1 king-of-hill BG (10v10, 3-cap to win, 30 min limit)\n"); std::printf(" --gen-bg-classic [name]\n"); diff --git a/tools/editor/cli_mounts_catalog.cpp b/tools/editor/cli_mounts_catalog.cpp index 87fccc1e..483ce766 100644 --- a/tools/editor/cli_mounts_catalog.cpp +++ b/tools/editor/cli_mounts_catalog.cpp @@ -130,6 +130,166 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int handleExportJson(int& i, int argc, char** argv) { + // Mirrors the JSON pairs added for every other novel + // open format. Each mount emits all 14 scalar fields + // plus dual int + name forms for kind / faction / + // category. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWmouExt(base); + if (outPath.empty()) outPath = base + ".wmou.json"; + if (!wowee::pipeline::WoweeMountLoader::exists(base)) { + std::fprintf(stderr, + "export-wmou-json: WMOU not found: %s.wmou\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMountLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"mountId", e.mountId}, + {"name", e.name}, + {"description", e.description}, + {"iconPath", e.iconPath}, + {"displayId", e.displayId}, + {"summonSpellId", e.summonSpellId}, + {"itemIdToLearn", e.itemIdToLearn}, + {"requiredSkillId", e.requiredSkillId}, + {"requiredSkillRank", e.requiredSkillRank}, + {"speedPercent", e.speedPercent}, + {"mountKind", e.mountKind}, + {"mountKindName", wowee::pipeline::WoweeMount::kindName(e.mountKind)}, + {"factionId", e.factionId}, + {"factionName", wowee::pipeline::WoweeMount::factionName(e.factionId)}, + {"categoryId", e.categoryId}, + {"categoryName", wowee::pipeline::WoweeMount::categoryName(e.categoryId)}, + {"raceMask", e.raceMask}, + }); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wmou-json: cannot write %s\n", outPath.c_str()); + return 1; + } + out << j.dump(2) << "\n"; + out.close(); + std::printf("Wrote %s\n", outPath.c_str()); + std::printf(" source : %s.wmou\n", base.c_str()); + std::printf(" mounts : %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]; + if (outBase.empty()) { + outBase = jsonPath; + std::string suffix = ".wmou.json"; + if (outBase.size() > suffix.size() && + outBase.substr(outBase.size() - suffix.size()) == suffix) { + outBase = outBase.substr(0, outBase.size() - suffix.size()); + } else if (outBase.size() > 5 && + outBase.substr(outBase.size() - 5) == ".json") { + outBase = outBase.substr(0, outBase.size() - 5); + } + } + outBase = stripWmouExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wmou-json: cannot read %s\n", jsonPath.c_str()); + return 1; + } + nlohmann::json j; + try { in >> j; } + catch (const std::exception& e) { + std::fprintf(stderr, + "import-wmou-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto kindFromName = [](const std::string& s) -> uint8_t { + if (s == "ground") return wowee::pipeline::WoweeMount::Ground; + if (s == "flying") return wowee::pipeline::WoweeMount::Flying; + if (s == "swimming") return wowee::pipeline::WoweeMount::Swimming; + if (s == "hybrid") return wowee::pipeline::WoweeMount::Hybrid; + if (s == "aquatic") return wowee::pipeline::WoweeMount::Aquatic; + return wowee::pipeline::WoweeMount::Ground; + }; + auto factionFromName = [](const std::string& s) -> uint8_t { + if (s == "both") return wowee::pipeline::WoweeMount::Both; + if (s == "alliance") return wowee::pipeline::WoweeMount::Alliance; + if (s == "horde") return wowee::pipeline::WoweeMount::Horde; + return wowee::pipeline::WoweeMount::Both; + }; + auto categoryFromName = [](const std::string& s) -> uint8_t { + if (s == "common") return wowee::pipeline::WoweeMount::Common; + if (s == "epic") return wowee::pipeline::WoweeMount::Epic; + if (s == "racial") return wowee::pipeline::WoweeMount::Racial; + if (s == "event") return wowee::pipeline::WoweeMount::Event; + if (s == "achievement") return wowee::pipeline::WoweeMount::Achievement; + if (s == "pvp") return wowee::pipeline::WoweeMount::Pvp; + if (s == "quest") return wowee::pipeline::WoweeMount::Quest; + if (s == "class") return wowee::pipeline::WoweeMount::ClassMount; + return wowee::pipeline::WoweeMount::Common; + }; + wowee::pipeline::WoweeMount c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeMount::Entry e; + e.mountId = je.value("mountId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.iconPath = je.value("iconPath", std::string{}); + e.displayId = je.value("displayId", 0u); + e.summonSpellId = je.value("summonSpellId", 0u); + e.itemIdToLearn = je.value("itemIdToLearn", 0u); + e.requiredSkillId = je.value("requiredSkillId", 0u); + e.requiredSkillRank = static_cast( + je.value("requiredSkillRank", 0)); + e.speedPercent = static_cast( + je.value("speedPercent", 60)); + if (je.contains("mountKind") && je["mountKind"].is_number_integer()) { + e.mountKind = static_cast(je["mountKind"].get()); + } else if (je.contains("mountKindName") && + je["mountKindName"].is_string()) { + e.mountKind = kindFromName(je["mountKindName"].get()); + } + if (je.contains("factionId") && je["factionId"].is_number_integer()) { + e.factionId = static_cast(je["factionId"].get()); + } else if (je.contains("factionName") && + je["factionName"].is_string()) { + e.factionId = factionFromName(je["factionName"].get()); + } + if (je.contains("categoryId") && je["categoryId"].is_number_integer()) { + e.categoryId = static_cast(je["categoryId"].get()); + } else if (je.contains("categoryName") && + je["categoryName"].is_string()) { + e.categoryId = categoryFromName(je["categoryName"].get()); + } + e.raceMask = je.value("raceMask", 0u); + c.entries.push_back(std::move(e)); + } + } + if (!wowee::pipeline::WoweeMountLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wmou-json: failed to save %s.wmou\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wmou\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" mounts : %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 +402,12 @@ bool handleMountsCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wmou") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wmou-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wmou-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }