From cf886ec94bfa26a93c92a518903e3b133f73faa3 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 10 May 2026 02:04:47 -0700 Subject: [PATCH] feat(editor): add WMNL JSON round-trip (--export/--import-wmnl-json) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plain-shape JSON sidecar — WMNL has no enum fields to coerce, just positional + textual data: levelIndex (uint8), minZ/maxZ (floats), texturePath/displayName (strings). Float-precise round-trip preserved (the Stormwind/Dalaran/Undercity Z-range boundaries don't have any rounding artifacts since they were authored as integer-multiple values like 80.0, 130.0, 200.0). All 3 presets (Stormwind/Dalaran/Undercity, 3+4+5 = 12 levels total across the city stack) byte-identical roundtrip OK. CLI flag count 1196 -> 1198. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + tools/editor/cli_minimap_levels_catalog.cpp | 115 ++++++++++++++++++++ 3 files changed, 120 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 4538218e..b2e12091 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -339,6 +339,7 @@ const char* const kArgRequired[] = { "--export-wrpr-json", "--import-wrpr-json", "--gen-mnl", "--gen-mnl-dalaran", "--gen-mnl-undercity", "--info-wmnl", "--validate-wmnl", + "--export-wmnl-json", "--import-wmnl-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 f783a42e..c9169b8c 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2303,6 +2303,10 @@ void printUsage(const char* argv0) { std::printf(" Print WMNL entries (id / map / area / levelIndex / Z-range / displayName / name)\n"); std::printf(" --validate-wmnl [--json]\n"); std::printf(" Static checks: id+name+areaId required, minZ [out.json]\n"); + std::printf(" Export binary .wmnl to a human-editable JSON sidecar (defaults to .wmnl.json; minZ/maxZ as floats, all string fields as plain strings)\n"); + std::printf(" --import-wmnl-json [out-base]\n"); + std::printf(" Import a .wmnl.json sidecar back into binary .wmnl (no enums to coerce — pure positional/textual data; minZ/maxZ float-precise round-trip)\n"); std::printf(" --catalog-pluck [--json]\n"); std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n"); std::printf(" --catalog-find [--magic ] [--json]\n"); diff --git a/tools/editor/cli_minimap_levels_catalog.cpp b/tools/editor/cli_minimap_levels_catalog.cpp index a050a897..7d0a45d7 100644 --- a/tools/editor/cli_minimap_levels_catalog.cpp +++ b/tools/editor/cli_minimap_levels_catalog.cpp @@ -125,6 +125,115 @@ 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 out; + if (parseOptArg(i, argc, argv)) out = argv[++i]; + base = stripWmnlExt(base); + if (out.empty()) out = base + ".wmnl.json"; + if (!wowee::pipeline::WoweeMinimapLevelsLoader::exists(base)) { + std::fprintf(stderr, + "export-wmnl-json: WMNL not found: %s.wmnl\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMinimapLevelsLoader::load(base); + nlohmann::json j; + j["magic"] = "WMNL"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"levelId", e.levelId}, + {"name", e.name}, + {"description", e.description}, + {"mapId", e.mapId}, + {"areaId", e.areaId}, + {"levelIndex", e.levelIndex}, + {"minZ", e.minZ}, + {"maxZ", e.maxZ}, + {"texturePath", e.texturePath}, + {"displayName", e.displayName}, + {"iconColorRGBA", e.iconColorRGBA}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wmnl-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu levels)\n", + out.c_str(), c.entries.size()); + return 0; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string in = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + if (outBase.empty()) { + outBase = in; + if (outBase.size() >= 10 && + outBase.substr(outBase.size() - 10) == ".wmnl.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wmnl"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wmnl-json: cannot open %s\n", in.c_str()); + return 1; + } + nlohmann::json j; + try { + is >> j; + } catch (const std::exception& ex) { + std::fprintf(stderr, + "import-wmnl-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeMinimapLevels c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wmnl-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeMinimapLevels::Entry e; + e.levelId = je.value("levelId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.mapId = je.value("mapId", 0u); + e.areaId = je.value("areaId", 0u); + e.levelIndex = static_cast( + je.value("levelIndex", 0u)); + e.minZ = je.value("minZ", 0.0f); + e.maxZ = je.value("maxZ", 0.0f); + e.texturePath = je.value("texturePath", std::string{}); + e.displayName = je.value("displayName", std::string{}); + e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeMinimapLevelsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wmnl-json: failed to save %s.wmnl\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wmnl (%zu levels)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -295,6 +404,12 @@ bool handleMinimapLevelsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wmnl") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wmnl-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wmnl-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }