feat(editor): add WQSO JSON round-trip (export/import sidecar)

Closes the JSON round-trip gap on the quest sort catalog
format shipped last batch. --export-wqso-json emits all 9
scalar fields plus a dual int + name form for sortKind (12
values) so hand-edits can use either representation.
--import-wqso-json accepts either form. Verified byte-
identical round-trip on all three preset emitters (starter
3-sort generic / 10-class with WCHC bit masks / 8-profession
with WTSK enum cross-refs). 884 documented CLI flags.
This commit is contained in:
Kelsi 2026-05-09 21:25:12 -07:00
parent 23ba7ed6a0
commit 48984ca375
3 changed files with 140 additions and 0 deletions

View file

@ -205,6 +205,7 @@ const char* const kArgRequired[] = {
"--export-wumv-json", "--import-wumv-json",
"--gen-qso", "--gen-qso-class", "--gen-qso-profession",
"--info-wqso", "--validate-wqso",
"--export-wqso-json", "--import-wqso-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -1681,6 +1681,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WQSO entries (id / kind / display priority / classMask / profession / faction / displayName)\n");
std::printf(" --validate-wqso <wqso-base> [--json]\n");
std::printf(" Static checks: id+name+displayName required, kind 0..11, ClassQuest needs classMask>0, Reputation needs factionId>0\n");
std::printf(" --export-wqso-json <wqso-base> [out.json]\n");
std::printf(" Export binary .wqso to a human-editable JSON sidecar (defaults to <base>.wqso.json)\n");
std::printf(" --import-wqso-json <json-path> [out-base]\n");
std::printf(" Import a .wqso.json sidecar back into binary .wqso (accepts sortKind int OR name string)\n");
std::printf(" --gen-weather-temperate <wow-base> [zoneName]\n");
std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n");
std::printf(" --gen-weather-arctic <wow-base> [zoneName]\n");

View file

@ -124,6 +124,135 @@ 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 outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWqsoExt(base);
if (outPath.empty()) outPath = base + ".wqso.json";
if (!wowee::pipeline::WoweeQuestSortLoader::exists(base)) {
std::fprintf(stderr,
"export-wqso-json: WQSO not found: %s.wqso\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeQuestSortLoader::load(base);
nlohmann::json j;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"sortId", e.sortId},
{"name", e.name},
{"displayName", e.displayName},
{"description", e.description},
{"iconPath", e.iconPath},
{"sortKind", e.sortKind},
{"sortKindName", wowee::pipeline::WoweeQuestSort::sortKindName(e.sortKind)},
{"displayPriority", e.displayPriority},
{"targetProfessionId", e.targetProfessionId},
{"targetClassMask", e.targetClassMask},
{"targetFactionId", e.targetFactionId},
});
}
j["entries"] = arr;
std::ofstream out(outPath);
if (!out) {
std::fprintf(stderr,
"export-wqso-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.wqso\n", base.c_str());
std::printf(" sorts : %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 = ".wqso.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 = stripWqsoExt(outBase);
std::ifstream in(jsonPath);
if (!in) {
std::fprintf(stderr,
"import-wqso-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-wqso-json: bad JSON in %s: %s\n",
jsonPath.c_str(), e.what());
return 1;
}
auto kindFromName = [](const std::string& s) -> uint8_t {
if (s == "general") return wowee::pipeline::WoweeQuestSort::General;
if (s == "class") return wowee::pipeline::WoweeQuestSort::ClassQuest;
if (s == "profession") return wowee::pipeline::WoweeQuestSort::Profession;
if (s == "daily") return wowee::pipeline::WoweeQuestSort::Daily;
if (s == "holiday") return wowee::pipeline::WoweeQuestSort::Holiday;
if (s == "reputation") return wowee::pipeline::WoweeQuestSort::Reputation;
if (s == "dungeon") return wowee::pipeline::WoweeQuestSort::Dungeon;
if (s == "raid") return wowee::pipeline::WoweeQuestSort::Raid;
if (s == "heroic") return wowee::pipeline::WoweeQuestSort::Heroic;
if (s == "repeatable") return wowee::pipeline::WoweeQuestSort::Repeatable;
if (s == "pvp") return wowee::pipeline::WoweeQuestSort::PvP;
if (s == "tournament") return wowee::pipeline::WoweeQuestSort::Tournament;
return wowee::pipeline::WoweeQuestSort::General;
};
wowee::pipeline::WoweeQuestSort c;
c.name = j.value("name", std::string{});
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeQuestSort::Entry e;
e.sortId = je.value("sortId", 0u);
e.name = je.value("name", std::string{});
e.displayName = je.value("displayName", std::string{});
e.description = je.value("description", std::string{});
e.iconPath = je.value("iconPath", std::string{});
if (je.contains("sortKind") &&
je["sortKind"].is_number_integer()) {
e.sortKind = static_cast<uint8_t>(
je["sortKind"].get<int>());
} else if (je.contains("sortKindName") &&
je["sortKindName"].is_string()) {
e.sortKind = kindFromName(
je["sortKindName"].get<std::string>());
}
e.displayPriority = static_cast<uint8_t>(
je.value("displayPriority", 0));
e.targetProfessionId = static_cast<uint8_t>(
je.value("targetProfessionId", 0));
e.targetClassMask = je.value("targetClassMask", 0u);
e.targetFactionId = je.value("targetFactionId", 0u);
c.entries.push_back(e);
}
}
if (!wowee::pipeline::WoweeQuestSortLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wqso-json: failed to save %s.wqso\n", outBase.c_str());
return 1;
}
std::printf("Wrote %s.wqso\n", outBase.c_str());
std::printf(" source : %s\n", jsonPath.c_str());
std::printf(" sorts : %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);
@ -241,6 +370,12 @@ bool handleQuestSortsCatalog(int& i, int argc, char** argv,
if (std::strcmp(argv[i], "--validate-wqso") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wqso-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wqso-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}