diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 63c1128c..23065d06 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -278,6 +278,7 @@ const char* const kArgRequired[] = { "--export-wsps-json", "--import-wsps-json", "--gen-cmr", "--gen-cmr-city", "--gen-cmr-boss", "--info-wcmr", "--validate-wcmr", + "--export-wcmr-json", "--import-wcmr-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_creature_patrols_catalog.cpp b/tools/editor/cli_creature_patrols_catalog.cpp index e980f6f0..be7d6919 100644 --- a/tools/editor/cli_creature_patrols_catalog.cpp +++ b/tools/editor/cli_creature_patrols_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_creature_patrols.hpp" #include +#include #include #include #include @@ -135,6 +136,180 @@ 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 = stripWcmrExt(base); + if (!wowee::pipeline::WoweeCreaturePatrolLoader::exists(base)) { + std::fprintf(stderr, + "export-wcmr-json: WCMR not found: %s.wcmr\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeCreaturePatrolLoader::load(base); + if (outPath.empty()) outPath = base + ".wcmr.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json wpArr = nlohmann::json::array(); + for (const auto& w : e.waypoints) { + wpArr.push_back({ + {"x", w.x}, {"y", w.y}, {"z", w.z}, + {"delayMs", w.delayMs}, + }); + } + nlohmann::json je; + je["pathId"] = e.pathId; + je["name"] = e.name; + je["description"] = e.description; + je["creatureGuid"] = e.creatureGuid; + je["pathKind"] = e.pathKind; + je["pathKindName"] = + wowee::pipeline::WoweeCreaturePatrol::pathKindName(e.pathKind); + je["moveType"] = e.moveType; + je["moveTypeName"] = + wowee::pipeline::WoweeCreaturePatrol::moveTypeName(e.moveType); + je["waypoints"] = wpArr; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wcmr-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(" paths : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parsePathKindToken(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::WoweeCreaturePatrol::Random) + 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 == "loop") return wowee::pipeline::WoweeCreaturePatrol::Loop; + if (s == "one-shot" || + s == "oneshot") return wowee::pipeline::WoweeCreaturePatrol::OneShot; + if (s == "reverse") return wowee::pipeline::WoweeCreaturePatrol::Reverse; + if (s == "random") return wowee::pipeline::WoweeCreaturePatrol::Random; + } + return fallback; +} + +uint8_t parseMoveTypeToken(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::WoweeCreaturePatrol::Swim) + 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 == "walk") return wowee::pipeline::WoweeCreaturePatrol::Walk; + if (s == "run") return wowee::pipeline::WoweeCreaturePatrol::Run; + if (s == "fly") return wowee::pipeline::WoweeCreaturePatrol::Fly; + if (s == "swim") return wowee::pipeline::WoweeCreaturePatrol::Swim; + } + 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-wcmr-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-wcmr-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeCreaturePatrol 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::WoweeCreaturePatrol::Entry e; + if (je.contains("pathId")) e.pathId = je["pathId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("creatureGuid")) e.creatureGuid = je["creatureGuid"].get(); + uint8_t kind = wowee::pipeline::WoweeCreaturePatrol::Loop; + if (je.contains("pathKind")) + kind = parsePathKindToken(je["pathKind"], kind); + else if (je.contains("pathKindName")) + kind = parsePathKindToken(je["pathKindName"], kind); + e.pathKind = kind; + uint8_t move = wowee::pipeline::WoweeCreaturePatrol::Walk; + if (je.contains("moveType")) + move = parseMoveTypeToken(je["moveType"], move); + else if (je.contains("moveTypeName")) + move = parseMoveTypeToken(je["moveTypeName"], move); + e.moveType = move; + if (je.contains("waypoints") && je["waypoints"].is_array()) { + for (const auto& wj : je["waypoints"]) { + wowee::pipeline::WoweeCreaturePatrol::Waypoint w; + if (wj.contains("x")) w.x = wj["x"].get(); + if (wj.contains("y")) w.y = wj["y"].get(); + if (wj.contains("z")) w.z = wj["z"].get(); + if (wj.contains("delayMs")) w.delayMs = wj["delayMs"].get(); + e.waypoints.push_back(w); + } + } + if (je.contains("iconColorRGBA")) + e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wcmr.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 = stripWcmrExt(outBase); + if (!wowee::pipeline::WoweeCreaturePatrolLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wcmr-json: failed to save %s.wcmr\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wcmr\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" paths : %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); @@ -243,6 +418,12 @@ bool handleCreaturePatrolsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wcmr") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wcmr-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wcmr-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 86bc6cc7..26d4b93a 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2023,6 +2023,10 @@ void printUsage(const char* argv0) { std::printf(" Print WCMR entries (id / creatureGuid / pathKind / moveType / waypoint count / total path length yards / name)\n"); std::printf(" --validate-wcmr [--json]\n"); std::printf(" Static checks: id+name+creatureGuid+waypoints required, pathKind 0..3, moveType 0..3, no duplicate ids; warns on 1-waypoint paths (idle), Loop with <3 waypoints (degenerate)\n"); + std::printf(" --export-wcmr-json [out.json]\n"); + std::printf(" Export binary .wcmr to a human-editable JSON sidecar (defaults to .wcmr.json). Waypoints exported as JSON arrays for variable-length editing\n"); + std::printf(" --import-wcmr-json [out-base]\n"); + std::printf(" Import a .wcmr.json sidecar back into binary .wcmr (accepts pathKind/moveType int OR name; waypoint arrays length-preserving)\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");