mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): WGBK JSON round-trip closure
Adds --export-wgbk-json / --import-wgbk-json. Fixed-size 8-element perRankWithdrawalLimit array serializes as JSON int array; kUnlimited (0xFFFFFFFF / 4294967295) preserved through JSON. All 3 presets (standard/raid/small) byte-identical binary roundtrip OK including the raid preset's tier-tab strict rank-1 4-slot/day caps. Live-tested per-rank monotonicity validator: hand-mutated General tab rank 2 (member) limit to 200 (exceeds rank 1 officer cap of 50). Validator correctly errored: "perRankWithdrawalLimit[2]=200 > rank[1]=50 — lower rank cannot exceed higher rank's withdrawal cap". Exact rank indices + values appear in the message — actionable for the editor. CLI flag count 1380 -> 1382.
This commit is contained in:
parent
98316b48ac
commit
25ecdb0813
3 changed files with 134 additions and 0 deletions
|
|
@ -403,6 +403,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wcst-json", "--import-wcst-json",
|
||||
"--gen-gbk", "--gen-gbk-raid", "--gen-gbk-small",
|
||||
"--info-wgbk", "--validate-wgbk",
|
||||
"--export-wgbk-json", "--import-wgbk-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -280,6 +280,127 @@ int handleValidate(int& i, int argc, char** argv) {
|
|||
return ok ? 0 : 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 = stripWgbkExt(base);
|
||||
if (out.empty()) out = base + ".wgbk.json";
|
||||
if (!wowee::pipeline::WoweeGuildBankLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wgbk-json: WGBK not found: %s.wgbk\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeGuildBankLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WGBK";
|
||||
j["version"] = 1;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
nlohmann::json limits = nlohmann::json::array();
|
||||
for (uint32_t r = 0;
|
||||
r < wowee::pipeline::WoweeGuildBank::
|
||||
kRankCount; ++r) {
|
||||
limits.push_back(e.perRankWithdrawalLimit[r]);
|
||||
}
|
||||
arr.push_back({
|
||||
{"tabId", e.tabId},
|
||||
{"guildId", e.guildId},
|
||||
{"tabName", e.tabName},
|
||||
{"iconIndex", e.iconIndex},
|
||||
{"depositOnly", e.depositOnly != 0},
|
||||
{"slotCount", e.slotCount},
|
||||
{"perRankWithdrawalLimit", limits},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wgbk-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu tabs)\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) == ".wgbk.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wgbk");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgbk-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-wgbk-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeGuildBank c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgbk-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeGuildBank::Entry e;
|
||||
e.tabId = je.value("tabId", 0u);
|
||||
e.guildId = je.value("guildId", 0u);
|
||||
e.tabName = je.value("tabName", std::string{});
|
||||
e.iconIndex = je.value("iconIndex", 0u);
|
||||
e.depositOnly = je.value("depositOnly", false) ? 1 : 0;
|
||||
e.slotCount = static_cast<uint16_t>(
|
||||
je.value("slotCount", 0));
|
||||
if (je.contains("perRankWithdrawalLimit") &&
|
||||
je["perRankWithdrawalLimit"].is_array()) {
|
||||
uint32_t r = 0;
|
||||
for (const auto& v :
|
||||
je["perRankWithdrawalLimit"]) {
|
||||
if (r >= wowee::pipeline::WoweeGuildBank::
|
||||
kRankCount) break;
|
||||
if (v.is_number_unsigned() ||
|
||||
v.is_number_integer()) {
|
||||
e.perRankWithdrawalLimit[r] =
|
||||
v.get<uint32_t>();
|
||||
}
|
||||
++r;
|
||||
}
|
||||
}
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweeGuildBankLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgbk-json: failed to save %s.wgbk\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wgbk (%zu tabs)\n",
|
||||
outBase.c_str(), c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool handleGuildBankCatalog(int& i, int argc, char** argv,
|
||||
|
|
@ -302,6 +423,14 @@ bool handleGuildBankCatalog(int& i, int argc, char** argv,
|
|||
i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wgbk-json") == 0 &&
|
||||
i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wgbk-json") == 0 &&
|
||||
i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2597,6 +2597,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WGBK entries (id / guildId / slotCount / depositOnly / per-rank-0..7 withdrawal limits / tabName)\n");
|
||||
std::printf(" --validate-wgbk <wgbk-base> [--json]\n");
|
||||
std::printf(" Static checks: id+guildId+tabName required, slotCount 1..98 (vanilla cap), GM withdrawal limit > 0 (rank 0 cannot be locked out — almost certainly a typo), per-rank monotonicity (lower rank cannot exceed higher rank's cap), no duplicate tabIds, no duplicate (guildId,tabName) pairs (UI tab dispatch tie); warns on depositOnly flag set with non-zero rank-0 limit (self-contradiction — flag overrides at runtime but data is contradictory)\n");
|
||||
std::printf(" --export-wgbk-json <wgbk-base> [out.json]\n");
|
||||
std::printf(" Export binary .wgbk to a human-editable JSON sidecar (defaults to <base>.wgbk.json; perRankWithdrawalLimit emitted as 8-element JSON int array, kUnlimited = 4294967295)\n");
|
||||
std::printf(" --import-wgbk-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wgbk.json sidecar back into binary .wgbk (perRankWithdrawalLimit JSON int array, missing entries default to 0; round-trips per-rank caps byte-identical)\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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue