mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
feat(editor): add WMOU JSON round-trip authoring workflow
Closes the WMOU open-format loop with --export-wmou-json /
--import-wmou-json, mirroring the JSON pairs added for
every other novel binary format. All 26 binary formats
added since WOL now have full JSON round-trip authoring.
Each mount round-trips all 14 scalar fields. Three
enum-typed fields emit dual int + name forms:
• mountKind (ground / flying / swimming / hybrid / aquatic)
• factionId (both / alliance / horde)
• categoryId (common / epic / racial / event / achievement /
pvp / quest / class)
Verified byte-identical round-trip on the flying preset
(4 mounts spanning common/epic/achievement/pvp tiers with
full WSPL spell + WIT item + WSKL riding skill cross-refs
preserved through the JSON layer).
Adds 2 flags (630 documented total now).
This commit is contained in:
parent
1b385fb39c
commit
b5995073b9
3 changed files with 171 additions and 0 deletions
|
|
@ -130,6 +130,166 @@ 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. Each mount emits all 14 scalar fields
|
||||
// plus dual int + name forms for kind / faction /
|
||||
// category.
|
||||
std::string base = argv[++i];
|
||||
std::string outPath;
|
||||
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
|
||||
base = stripWmouExt(base);
|
||||
if (outPath.empty()) outPath = base + ".wmou.json";
|
||||
if (!wowee::pipeline::WoweeMountLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wmou-json: WMOU not found: %s.wmou\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeMountLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"mountId", e.mountId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"iconPath", e.iconPath},
|
||||
{"displayId", e.displayId},
|
||||
{"summonSpellId", e.summonSpellId},
|
||||
{"itemIdToLearn", e.itemIdToLearn},
|
||||
{"requiredSkillId", e.requiredSkillId},
|
||||
{"requiredSkillRank", e.requiredSkillRank},
|
||||
{"speedPercent", e.speedPercent},
|
||||
{"mountKind", e.mountKind},
|
||||
{"mountKindName", wowee::pipeline::WoweeMount::kindName(e.mountKind)},
|
||||
{"factionId", e.factionId},
|
||||
{"factionName", wowee::pipeline::WoweeMount::factionName(e.factionId)},
|
||||
{"categoryId", e.categoryId},
|
||||
{"categoryName", wowee::pipeline::WoweeMount::categoryName(e.categoryId)},
|
||||
{"raceMask", e.raceMask},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream out(outPath);
|
||||
if (!out) {
|
||||
std::fprintf(stderr,
|
||||
"export-wmou-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.wmou\n", base.c_str());
|
||||
std::printf(" mounts : %zu\n", c.entries.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 = ".wmou.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 = stripWmouExt(outBase);
|
||||
std::ifstream in(jsonPath);
|
||||
if (!in) {
|
||||
std::fprintf(stderr,
|
||||
"import-wmou-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-wmou-json: bad JSON in %s: %s\n",
|
||||
jsonPath.c_str(), e.what());
|
||||
return 1;
|
||||
}
|
||||
auto kindFromName = [](const std::string& s) -> uint8_t {
|
||||
if (s == "ground") return wowee::pipeline::WoweeMount::Ground;
|
||||
if (s == "flying") return wowee::pipeline::WoweeMount::Flying;
|
||||
if (s == "swimming") return wowee::pipeline::WoweeMount::Swimming;
|
||||
if (s == "hybrid") return wowee::pipeline::WoweeMount::Hybrid;
|
||||
if (s == "aquatic") return wowee::pipeline::WoweeMount::Aquatic;
|
||||
return wowee::pipeline::WoweeMount::Ground;
|
||||
};
|
||||
auto factionFromName = [](const std::string& s) -> uint8_t {
|
||||
if (s == "both") return wowee::pipeline::WoweeMount::Both;
|
||||
if (s == "alliance") return wowee::pipeline::WoweeMount::Alliance;
|
||||
if (s == "horde") return wowee::pipeline::WoweeMount::Horde;
|
||||
return wowee::pipeline::WoweeMount::Both;
|
||||
};
|
||||
auto categoryFromName = [](const std::string& s) -> uint8_t {
|
||||
if (s == "common") return wowee::pipeline::WoweeMount::Common;
|
||||
if (s == "epic") return wowee::pipeline::WoweeMount::Epic;
|
||||
if (s == "racial") return wowee::pipeline::WoweeMount::Racial;
|
||||
if (s == "event") return wowee::pipeline::WoweeMount::Event;
|
||||
if (s == "achievement") return wowee::pipeline::WoweeMount::Achievement;
|
||||
if (s == "pvp") return wowee::pipeline::WoweeMount::Pvp;
|
||||
if (s == "quest") return wowee::pipeline::WoweeMount::Quest;
|
||||
if (s == "class") return wowee::pipeline::WoweeMount::ClassMount;
|
||||
return wowee::pipeline::WoweeMount::Common;
|
||||
};
|
||||
wowee::pipeline::WoweeMount c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (j.contains("entries") && j["entries"].is_array()) {
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeMount::Entry e;
|
||||
e.mountId = je.value("mountId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
e.iconPath = je.value("iconPath", std::string{});
|
||||
e.displayId = je.value("displayId", 0u);
|
||||
e.summonSpellId = je.value("summonSpellId", 0u);
|
||||
e.itemIdToLearn = je.value("itemIdToLearn", 0u);
|
||||
e.requiredSkillId = je.value("requiredSkillId", 0u);
|
||||
e.requiredSkillRank = static_cast<uint16_t>(
|
||||
je.value("requiredSkillRank", 0));
|
||||
e.speedPercent = static_cast<uint16_t>(
|
||||
je.value("speedPercent", 60));
|
||||
if (je.contains("mountKind") && je["mountKind"].is_number_integer()) {
|
||||
e.mountKind = static_cast<uint8_t>(je["mountKind"].get<int>());
|
||||
} else if (je.contains("mountKindName") &&
|
||||
je["mountKindName"].is_string()) {
|
||||
e.mountKind = kindFromName(je["mountKindName"].get<std::string>());
|
||||
}
|
||||
if (je.contains("factionId") && je["factionId"].is_number_integer()) {
|
||||
e.factionId = static_cast<uint8_t>(je["factionId"].get<int>());
|
||||
} else if (je.contains("factionName") &&
|
||||
je["factionName"].is_string()) {
|
||||
e.factionId = factionFromName(je["factionName"].get<std::string>());
|
||||
}
|
||||
if (je.contains("categoryId") && je["categoryId"].is_number_integer()) {
|
||||
e.categoryId = static_cast<uint8_t>(je["categoryId"].get<int>());
|
||||
} else if (je.contains("categoryName") &&
|
||||
je["categoryName"].is_string()) {
|
||||
e.categoryId = categoryFromName(je["categoryName"].get<std::string>());
|
||||
}
|
||||
e.raceMask = je.value("raceMask", 0u);
|
||||
c.entries.push_back(std::move(e));
|
||||
}
|
||||
}
|
||||
if (!wowee::pipeline::WoweeMountLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wmou-json: failed to save %s.wmou\n", outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wmou\n", outBase.c_str());
|
||||
std::printf(" source : %s\n", jsonPath.c_str());
|
||||
std::printf(" mounts : %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);
|
||||
|
|
@ -242,6 +402,12 @@ bool handleMountsCatalog(int& i, int argc, char** argv, int& outRc) {
|
|||
if (std::strcmp(argv[i], "--validate-wmou") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wmou-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wmou-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