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

Closes the JSON round-trip gap on the PvP rank catalog
format shipped this batch. --export-wpvp-json emits all 12
scalar fields plus a dual int + name form for rankKind (5
values) so hand-edits can use either representation.
--import-wpvp-json defaults bracket level to 1..80 (no level
gate) when omitted — matches the typical case for vanilla
honor ranks which weren't level-gated beyond the cap.
Verified byte-identical round-trip on all three preset
emitters (starter / alliance vanilla 9-rank ladder / arena
5-tier ladder). 835 documented CLI flags.
This commit is contained in:
Kelsi 2026-05-09 20:42:21 -07:00
parent e9997ed218
commit 791c8b5dd6
3 changed files with 153 additions and 0 deletions

View file

@ -184,6 +184,7 @@ const char* const kArgRequired[] = {
"--export-wchf-json", "--import-wchf-json",
"--gen-pvp", "--gen-pvp-alliance", "--gen-pvp-arena",
"--info-wpvp", "--validate-wpvp",
"--export-wpvp-json", "--import-wpvp-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -1583,6 +1583,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WPVP entries (id / kind / threshold / emblem reward / title+chest cross-refs / alliance / horde names)\n");
std::printf(" --validate-wpvp <wpvp-base> [--json]\n");
std::printf(" Static checks: id+name required, kind 0..4, level range valid, faction alt names paired, threshold monotonic within kind, arena>=1500\n");
std::printf(" --export-wpvp-json <wpvp-base> [out.json]\n");
std::printf(" Export binary .wpvp to a human-editable JSON sidecar (defaults to <base>.wpvp.json)\n");
std::printf(" --import-wpvp-json <json-path> [out-base]\n");
std::printf(" Import a .wpvp.json sidecar back into binary .wpvp (accepts rankKind int OR name string; bracket level defaults to 1..80)\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

@ -131,6 +131,148 @@ 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 rank emits all 12 scalar fields plus
// a dual int + name form for rankKind so hand-edits can
// use either representation.
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWpvpExt(base);
if (outPath.empty()) outPath = base + ".wpvp.json";
if (!wowee::pipeline::WoweePVPRankLoader::exists(base)) {
std::fprintf(stderr,
"export-wpvp-json: WPVP not found: %s.wpvp\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweePVPRankLoader::load(base);
nlohmann::json j;
j["name"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"rankId", e.rankId},
{"name", e.name},
{"factionAllianceName", e.factionAllianceName},
{"factionHordeName", e.factionHordeName},
{"description", e.description},
{"rankKind", e.rankKind},
{"rankKindName", wowee::pipeline::WoweePVPRank::rankKindName(e.rankKind)},
{"minBracketLevel", e.minBracketLevel},
{"maxBracketLevel", e.maxBracketLevel},
{"minHonorOrRating", e.minHonorOrRating},
{"rewardEmblems", e.rewardEmblems},
{"titleId", e.titleId},
{"chestItemId", e.chestItemId},
{"glovesItemId", e.glovesItemId},
{"shouldersItemId", e.shouldersItemId},
{"bracketBgId", e.bracketBgId},
});
}
j["entries"] = arr;
std::ofstream out(outPath);
if (!out) {
std::fprintf(stderr,
"export-wpvp-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.wpvp\n", base.c_str());
std::printf(" ranks : %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 = ".wpvp.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 = stripWpvpExt(outBase);
std::ifstream in(jsonPath);
if (!in) {
std::fprintf(stderr,
"import-wpvp-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-wpvp-json: bad JSON in %s: %s\n",
jsonPath.c_str(), e.what());
return 1;
}
auto kindFromName = [](const std::string& s) -> uint8_t {
if (s == "vanilla-honor") return wowee::pipeline::WoweePVPRank::VanillaHonor;
if (s == "arena") return wowee::pipeline::WoweePVPRank::ArenaRating;
if (s == "rated-bg") return wowee::pipeline::WoweePVPRank::BattlegroundRated;
if (s == "world-pvp") return wowee::pipeline::WoweePVPRank::WorldPvP;
if (s == "conquest") return wowee::pipeline::WoweePVPRank::ConquestPoint;
return wowee::pipeline::WoweePVPRank::VanillaHonor;
};
wowee::pipeline::WoweePVPRank c;
c.name = j.value("name", std::string{});
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweePVPRank::Entry e;
e.rankId = je.value("rankId", 0u);
e.name = je.value("name", std::string{});
e.factionAllianceName = je.value("factionAllianceName",
std::string{});
e.factionHordeName = je.value("factionHordeName",
std::string{});
e.description = je.value("description", std::string{});
if (je.contains("rankKind") &&
je["rankKind"].is_number_integer()) {
e.rankKind = static_cast<uint8_t>(
je["rankKind"].get<int>());
} else if (je.contains("rankKindName") &&
je["rankKindName"].is_string()) {
e.rankKind = kindFromName(
je["rankKindName"].get<std::string>());
}
// Bracket-level defaults to 1..80 (no level gate)
// when omitted — vanilla ranks weren't level-gated
// beyond the cap.
e.minBracketLevel = static_cast<uint8_t>(
je.value("minBracketLevel", 1));
e.maxBracketLevel = static_cast<uint8_t>(
je.value("maxBracketLevel", 80));
e.minHonorOrRating = je.value("minHonorOrRating", 0u);
e.rewardEmblems = static_cast<uint16_t>(
je.value("rewardEmblems", 0));
e.titleId = je.value("titleId", 0u);
e.chestItemId = je.value("chestItemId", 0u);
e.glovesItemId = je.value("glovesItemId", 0u);
e.shouldersItemId = je.value("shouldersItemId", 0u);
e.bracketBgId = je.value("bracketBgId", 0u);
c.entries.push_back(e);
}
}
if (!wowee::pipeline::WoweePVPRankLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wpvp-json: failed to save %s.wpvp\n", outBase.c_str());
return 1;
}
std::printf("Wrote %s.wpvp\n", outBase.c_str());
std::printf(" source : %s\n", jsonPath.c_str());
std::printf(" ranks : %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);
@ -271,6 +413,12 @@ bool handlePVPCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--validate-wpvp") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wpvp-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wpvp-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}