mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WPRG JSON round-trip (--export/--import-wprg-json)
Dual encoding for factionFilter (int 1=Alliance / 2=Horde OR token "alliance" / "horde"). titlePrefix as plain JSON string — round-trip preserves the spaces and hyphens in titles like "Knight-Lieutenant" exactly. honorRequiredWeekly + honorRequiredAchieve serialize as plain uint32 — vanilla rank thresholds top out around 1,000,000 lifetime RP, well within uint32 range. All 3 presets (alliance/horde/high-tier) byte-identical roundtrip OK. CLI flag count 1281 -> 1283.
This commit is contained in:
parent
4ce07d5ca9
commit
2f1cb271a8
3 changed files with 152 additions and 0 deletions
|
|
@ -376,6 +376,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wanv-json", "--import-wanv-json",
|
||||
"--gen-prg", "--gen-prg-horde", "--gen-prg-high",
|
||||
"--info-wprg", "--validate-wprg",
|
||||
"--export-wprg-json", "--import-wprg-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -2471,6 +2471,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WPRG entries (id / faction / tier / weekly RP / lifetime RP / gear / title / name)\n");
|
||||
std::printf(" --validate-wprg <wprg-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name required, factionFilter 1=Alliance OR 2=Horde, tier 1..14 (vanilla ladder), no duplicate rankIds, no two ranks at same (faction, tier) tuple (runtime lookup tie); warns on empty titlePrefix, per-faction honor threshold non-monotonic (higher tier should require more honor)\n");
|
||||
std::printf(" --export-wprg-json <wprg-base> [out.json]\n");
|
||||
std::printf(" Export binary .wprg to a human-editable JSON sidecar (defaults to <base>.wprg.json; emits factionFilter as both int AND name string)\n");
|
||||
std::printf(" --import-wprg-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wprg.json sidecar back into binary .wprg (factionFilter int OR \"alliance\"/\"horde\"; titlePrefix as plain string)\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");
|
||||
|
|
|
|||
|
|
@ -135,6 +135,147 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parseFactionFilterToken(const std::string& s) {
|
||||
using P = wowee::pipeline::WoweePvPRanks;
|
||||
if (s == "alliance") return P::AllianceOnly;
|
||||
if (s == "horde") return P::HordeOnly;
|
||||
return -1;
|
||||
}
|
||||
|
||||
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 = stripWprgExt(base);
|
||||
if (out.empty()) out = base + ".wprg.json";
|
||||
if (!wowee::pipeline::WoweePvPRanksLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wprg-json: WPRG not found: %s.wprg\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweePvPRanksLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WPRG";
|
||||
j["version"] = 1;
|
||||
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},
|
||||
{"description", e.description},
|
||||
{"factionFilter", e.factionFilter},
|
||||
{"factionFilterName",
|
||||
factionFilterName(e.factionFilter)},
|
||||
{"tier", e.tier},
|
||||
{"honorRequiredWeekly", e.honorRequiredWeekly},
|
||||
{"honorRequiredAchieve", e.honorRequiredAchieve},
|
||||
{"titlePrefix", e.titlePrefix},
|
||||
{"gearItemId", e.gearItemId},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wprg-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu ranks)\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) == ".wprg.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wprg");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprg-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-wprg-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweePvPRanks c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprg-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweePvPRanks::Entry e;
|
||||
e.rankId = je.value("rankId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
if (je.contains("factionFilter")) {
|
||||
const auto& v = je["factionFilter"];
|
||||
if (v.is_string()) {
|
||||
int parsed = parseFactionFilterToken(
|
||||
v.get<std::string>());
|
||||
if (parsed < 0) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprg-json: unknown "
|
||||
"factionFilter token '%s' on "
|
||||
"entry id=%u\n",
|
||||
v.get<std::string>().c_str(),
|
||||
e.rankId);
|
||||
return 1;
|
||||
}
|
||||
e.factionFilter = static_cast<uint8_t>(parsed);
|
||||
} else if (v.is_number_integer()) {
|
||||
e.factionFilter = static_cast<uint8_t>(
|
||||
v.get<int>());
|
||||
}
|
||||
} else if (je.contains("factionFilterName") &&
|
||||
je["factionFilterName"].is_string()) {
|
||||
int parsed = parseFactionFilterToken(
|
||||
je["factionFilterName"].get<std::string>());
|
||||
if (parsed >= 0)
|
||||
e.factionFilter = static_cast<uint8_t>(parsed);
|
||||
}
|
||||
e.tier = static_cast<uint8_t>(je.value("tier", 1u));
|
||||
e.honorRequiredWeekly = je.value("honorRequiredWeekly", 0u);
|
||||
e.honorRequiredAchieve = je.value("honorRequiredAchieve",
|
||||
0u);
|
||||
e.titlePrefix = je.value("titlePrefix", std::string{});
|
||||
e.gearItemId = je.value("gearItemId", 0u);
|
||||
e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu);
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweePvPRanksLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprg-json: failed to save %s.wprg\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wprg (%zu ranks)\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);
|
||||
|
|
@ -287,6 +428,12 @@ bool handlePvPRanksCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wprg") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wprg-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wprg-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