mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
feat(editor): add WMS JSON round-trip authoring workflow
Closes the WMS open-format loop with --export-wms-json /
--import-wms-json, mirroring the JSON pairs added for
every other novel binary format. All 20 binary formats
added since WOL now have full JSON round-trip authoring.
Two top-level arrays mirror the binary layout:
• maps[] — mapId / name / shortName / mapType (dual int +
name) / expansionId (dual int + name) / maxPlayers
• areas[] — areaId / mapId / parentAreaId / name /
minLevel..maxLevel / factionGroup (dual int +
name) / explorationXP / ambienceSoundId
Three enum-typed fields (mapType, expansionId, factionGroup)
emit dual int + name forms — a hand-author can write
"continent" / "wotlk" / "alliance" instead of remembering
the integer values.
Verified byte-identical round-trip on the classic preset
(3 maps including Deadmines instance, 6 areas with full
parent-chain hierarchy + WSND ambient cross-refs preserved).
Adds 2 flags (587 documented total now).
This commit is contained in:
parent
e66601c208
commit
68812b6c41
3 changed files with 183 additions and 0 deletions
|
|
@ -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<uint8_t>(jm["mapType"].get<int>());
|
||||
} else if (jm.contains("mapTypeName") && jm["mapTypeName"].is_string()) {
|
||||
m.mapType = mapTypeFromName(jm["mapTypeName"].get<std::string>());
|
||||
}
|
||||
if (jm.contains("expansionId") && jm["expansionId"].is_number_integer()) {
|
||||
m.expansionId = static_cast<uint8_t>(jm["expansionId"].get<int>());
|
||||
} else if (jm.contains("expansionName") && jm["expansionName"].is_string()) {
|
||||
m.expansionId = expansionFromName(jm["expansionName"].get<std::string>());
|
||||
}
|
||||
m.maxPlayers = static_cast<uint16_t>(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<uint16_t>(ja.value("minLevel", 1));
|
||||
a.maxLevel = static_cast<uint16_t>(ja.value("maxLevel", 1));
|
||||
if (ja.contains("factionGroup") &&
|
||||
ja["factionGroup"].is_number_integer()) {
|
||||
a.factionGroup = static_cast<uint8_t>(ja["factionGroup"].get<int>());
|
||||
} else if (ja.contains("factionGroupName") &&
|
||||
ja["factionGroupName"].is_string()) {
|
||||
a.factionGroup = factionFromName(ja["factionGroupName"].get<std::string>());
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue