feat(editor): add WMNL JSON round-trip (--export/--import-wmnl-json)

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.
This commit is contained in:
Kelsi 2026-05-10 02:04:47 -07:00
parent d49080db92
commit cf886ec94b
3 changed files with 120 additions and 0 deletions

View file

@ -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",

View file

@ -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 <wmnl-base> [--json]\n");
std::printf(" Static checks: id+name+areaId required, minZ<maxZ, no duplicate levelIds; per-area: no two levels at same levelIndex (picker UI conflict), no Z-range overlap between sibling levels (minimap flicker in overlap region); warns on empty texturePath (untextured layer) or empty displayName (blank picker entry)\n");
std::printf(" --export-wmnl-json <wmnl-base> [out.json]\n");
std::printf(" Export binary .wmnl to a human-editable JSON sidecar (defaults to <base>.wmnl.json; minZ/maxZ as floats, all string fields as plain strings)\n");
std::printf(" --import-wmnl-json <json-path> [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 <wXXX-file> <id> [--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 <directory> <id> [--magic <WXXX>] [--json]\n");

View file

@ -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<uint8_t>(
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;
}