diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 1c4a89a3..56aebb0f 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -76,6 +76,7 @@ const char* const kArgRequired[] = { "--export-wtal-json", "--import-wtal-json", "--gen-maps", "--gen-maps-classic", "--gen-maps-bgarena", "--info-wms", "--validate-wms", + "--export-wms-json", "--import-wms-json", "--gen-chars", "--gen-chars-alliance", "--gen-chars-allraces", "--info-wchc", "--validate-wchc", "--gen-weather-temperate", "--gen-weather-arctic", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 567adc06..99181dad 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1075,6 +1075,10 @@ void printUsage(const char* argv0) { std::printf(" Print WMS maps (id / type / expansion / max players) + areas (id / map / parent / level / faction / xp)\n"); std::printf(" --validate-wms [--json]\n"); std::printf(" Static checks: ids unique, areas reference real maps, parent areas exist + same map, BG/Arena needs maxPlayers\n"); + std::printf(" --export-wms-json [out.json]\n"); + std::printf(" Export binary .wms to a human-editable JSON sidecar (defaults to .wms.json)\n"); + std::printf(" --import-wms-json [out-base]\n"); + std::printf(" Import a .wms.json sidecar back into binary .wms (accepts mapType/expansion/faction int OR name forms)\n"); std::printf(" --gen-chars [name]\n"); std::printf(" Emit .wchc starter: 2 classes (Warrior + Mage) + 2 races (Human + Orc) + 4 outfits with WIT cross-refs\n"); std::printf(" --gen-chars-alliance [name]\n"); diff --git a/tools/editor/cli_maps_catalog.cpp b/tools/editor/cli_maps_catalog.cpp index 366288d6..ef6d8355 100644 --- a/tools/editor/cli_maps_catalog.cpp +++ b/tools/editor/cli_maps_catalog.cpp @@ -153,6 +153,178 @@ 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. Two top-level arrays (maps / areas) + // mirroring the binary layout. Three enum-typed fields + // (mapType, expansionId, factionGroup) emit dual int + + // name forms for hand-edit clarity. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWmsExt(base); + if (outPath.empty()) outPath = base + ".wms.json"; + if (!wowee::pipeline::WoweeMapsLoader::exists(base)) { + std::fprintf(stderr, + "export-wms-json: WMS not found: %s.wms\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMapsLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json ma = nlohmann::json::array(); + for (const auto& m : c.maps) { + ma.push_back({ + {"mapId", m.mapId}, + {"name", m.name}, + {"shortName", m.shortName}, + {"mapType", m.mapType}, + {"mapTypeName", wowee::pipeline::WoweeMaps::mapTypeName(m.mapType)}, + {"expansionId", m.expansionId}, + {"expansionName", wowee::pipeline::WoweeMaps::expansionName(m.expansionId)}, + {"maxPlayers", m.maxPlayers}, + }); + } + j["maps"] = ma; + nlohmann::json aa = nlohmann::json::array(); + for (const auto& a : c.areas) { + aa.push_back({ + {"areaId", a.areaId}, + {"mapId", a.mapId}, + {"parentAreaId", a.parentAreaId}, + {"name", a.name}, + {"minLevel", a.minLevel}, + {"maxLevel", a.maxLevel}, + {"factionGroup", a.factionGroup}, + {"factionGroupName", wowee::pipeline::WoweeMaps::factionGroupName(a.factionGroup)}, + {"explorationXP", a.explorationXP}, + {"ambienceSoundId", a.ambienceSoundId}, + }); + } + j["areas"] = aa; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wms-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.wms\n", base.c_str()); + std::printf(" maps : %zu areas : %zu\n", + c.maps.size(), c.areas.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 = ".wms.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 = stripWmsExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wms-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-wms-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto mapTypeFromName = [](const std::string& s) -> uint8_t { + if (s == "continent") return wowee::pipeline::WoweeMaps::Continent; + if (s == "instance") return wowee::pipeline::WoweeMaps::Instance; + if (s == "raid") return wowee::pipeline::WoweeMaps::Raid; + if (s == "battleground") return wowee::pipeline::WoweeMaps::Battleground; + if (s == "arena") return wowee::pipeline::WoweeMaps::Arena; + return wowee::pipeline::WoweeMaps::Continent; + }; + auto expansionFromName = [](const std::string& s) -> uint8_t { + if (s == "classic") return wowee::pipeline::WoweeMaps::Classic; + if (s == "tbc") return wowee::pipeline::WoweeMaps::Tbc; + if (s == "wotlk") return wowee::pipeline::WoweeMaps::Wotlk; + if (s == "cata") return wowee::pipeline::WoweeMaps::Cata; + if (s == "mop") return wowee::pipeline::WoweeMaps::Mop; + return wowee::pipeline::WoweeMaps::Classic; + }; + auto factionFromName = [](const std::string& s) -> uint8_t { + if (s == "both") return wowee::pipeline::WoweeMaps::FactionBoth; + if (s == "alliance") return wowee::pipeline::WoweeMaps::FactionAlliance; + if (s == "horde") return wowee::pipeline::WoweeMaps::FactionHorde; + if (s == "contested") return wowee::pipeline::WoweeMaps::FactionContested; + return wowee::pipeline::WoweeMaps::FactionBoth; + }; + wowee::pipeline::WoweeMaps c; + c.name = j.value("name", std::string{}); + if (j.contains("maps") && j["maps"].is_array()) { + for (const auto& jm : j["maps"]) { + wowee::pipeline::WoweeMaps::Map m; + m.mapId = jm.value("mapId", 0u); + m.name = jm.value("name", std::string{}); + m.shortName = jm.value("shortName", std::string{}); + if (jm.contains("mapType") && jm["mapType"].is_number_integer()) { + m.mapType = static_cast(jm["mapType"].get()); + } else if (jm.contains("mapTypeName") && jm["mapTypeName"].is_string()) { + m.mapType = mapTypeFromName(jm["mapTypeName"].get()); + } + if (jm.contains("expansionId") && jm["expansionId"].is_number_integer()) { + m.expansionId = static_cast(jm["expansionId"].get()); + } else if (jm.contains("expansionName") && jm["expansionName"].is_string()) { + m.expansionId = expansionFromName(jm["expansionName"].get()); + } + m.maxPlayers = static_cast(jm.value("maxPlayers", 0)); + c.maps.push_back(m); + } + } + if (j.contains("areas") && j["areas"].is_array()) { + for (const auto& ja : j["areas"]) { + wowee::pipeline::WoweeMaps::Area a; + a.areaId = ja.value("areaId", 0u); + a.mapId = ja.value("mapId", 0u); + a.parentAreaId = ja.value("parentAreaId", 0u); + a.name = ja.value("name", std::string{}); + a.minLevel = static_cast(ja.value("minLevel", 1)); + a.maxLevel = static_cast(ja.value("maxLevel", 1)); + if (ja.contains("factionGroup") && + ja["factionGroup"].is_number_integer()) { + a.factionGroup = static_cast(ja["factionGroup"].get()); + } else if (ja.contains("factionGroupName") && + ja["factionGroupName"].is_string()) { + a.factionGroup = factionFromName(ja["factionGroupName"].get()); + } + a.explorationXP = ja.value("explorationXP", 0u); + a.ambienceSoundId = ja.value("ambienceSoundId", 0u); + c.areas.push_back(a); + } + } + if (!wowee::pipeline::WoweeMapsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wms-json: failed to save %s.wms\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wms\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" maps : %zu areas : %zu\n", + c.maps.size(), c.areas.size()); + return 0; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -299,6 +471,12 @@ bool handleMapsCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wms") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wms-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wms-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }