Kelsidavis-WoWee/tools/editor/cli_bags_catalog.cpp

264 lines
9.5 KiB
C++
Raw Normal View History

feat(pipeline): add WBNK (Wowee Bag / Bank Slot) catalog 61st open format — replaces ItemBag.dbc plus the bank-storage and special-purpose container tables. Defines every slot the player has access to: equipped bags, bank bags, keyring, soul shard bag, quiver, reagent bag, hunter pet stable. 8 bag kinds (Inventory / Bank / Keyring / Quiver / SoulShard / Stable / Reagent / Wallet) cover the canonical container surface. Each entry has a fixed capacity (or 0 = variable, size set by equipped bag), a display order in the inventory UI, an unlock state with optional gold cost (bank bags ramp through 10s / 1g / 10g / 25g / 50g / 100g matching canonical WoW prices), and an accepts-bag-subclass mask gating which container kinds may be equipped (generic / herb / enchanting / engineer / gem / mining / leather / inscription / quiver / ammo pouch). Cross-references with prior formats — fixedBagItemId points at WIT.itemId for the bag item that always occupies a fixed slot (0 = player-equipable variable slot). CLI: --gen-bnk (5 inventory slots — 16-slot fixed main backpack + 4 player-equippable bag slots accepting generic containers + herb + enchanting bags), --gen-bnk-bank (8 bank bag slots with the canonical WoW unlock cost ramp), --gen-bnk-special (4 special-purpose: 32-slot Keyring fixed, warlock SoulShardBag, hunter ArrowQuiver, hunter HuntersStable for 5 pets), --info-wbnk, --validate-wbnk with --json variants. Validator catches id+name required, kind 0..7, locked-with-zero-cost (slot can never be unlocked), fixed-slot-with-non-zero-mask (equippable bag would be ignored), variable slot with empty mask (no bag can fit), and ambiguous (bagKind, displayOrder) tuples (UI sort would flicker). Format graph: 60 → 61 binary formats. CLI flag count: 833 → 840.
2026-05-09 20:46:06 -07:00
#include "cli_bags_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_bags.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <set>
#include <string>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWbnkExt(std::string base) {
stripExt(base, ".wbnk");
return base;
}
bool saveOrError(const wowee::pipeline::WoweeBagSlot& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeBagSlotLoader::save(c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wbnk\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(const wowee::pipeline::WoweeBagSlot& c,
const std::string& base) {
std::printf("Wrote %s.wbnk\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" slots : %zu\n", c.entries.size());
}
int handleGenStarter(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "StarterBags";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWbnkExt(base);
auto c = wowee::pipeline::WoweeBagSlotLoader::makeStarter(name);
if (!saveOrError(c, base, "gen-bnk")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenBank(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "BankBags";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWbnkExt(base);
auto c = wowee::pipeline::WoweeBagSlotLoader::makeBank(name);
if (!saveOrError(c, base, "gen-bnk-bank")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenSpecial(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "SpecialBags";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWbnkExt(base);
auto c = wowee::pipeline::WoweeBagSlotLoader::makeSpecial(name);
if (!saveOrError(c, base, "gen-bnk-special")) return 1;
printGenSummary(c, base);
return 0;
}
int handleInfo(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWbnkExt(base);
if (!wowee::pipeline::WoweeBagSlotLoader::exists(base)) {
std::fprintf(stderr, "WBNK not found: %s.wbnk\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeBagSlotLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wbnk"] = base + ".wbnk";
j["name"] = c.name;
j["count"] = c.entries.size();
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
arr.push_back({
{"bagSlotId", e.bagSlotId},
{"name", e.name},
{"description", e.description},
{"bagKind", e.bagKind},
{"bagKindName", wowee::pipeline::WoweeBagSlot::bagKindName(e.bagKind)},
{"containerSize", e.containerSize},
{"displayOrder", e.displayOrder},
{"isUnlocked", e.isUnlocked},
{"fixedBagItemId", e.fixedBagItemId},
{"unlockCostCopper", e.unlockCostCopper},
{"acceptsBagSubclassMask", e.acceptsBagSubclassMask},
});
}
j["entries"] = arr;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WBNK: %s.wbnk\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" slots : %zu\n", c.entries.size());
if (c.entries.empty()) return 0;
std::printf(" id kind size order unlock cost(c) accepts-mask fixedBag name\n");
for (const auto& e : c.entries) {
std::printf(" %4u %-10s %3u %3u %u %7u 0x%08x %5u %s\n",
e.bagSlotId,
wowee::pipeline::WoweeBagSlot::bagKindName(e.bagKind),
e.containerSize, e.displayOrder, e.isUnlocked,
e.unlockCostCopper, e.acceptsBagSubclassMask,
e.fixedBagItemId, e.name.c_str());
}
return 0;
}
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWbnkExt(base);
if (!wowee::pipeline::WoweeBagSlotLoader::exists(base)) {
std::fprintf(stderr,
"validate-wbnk: WBNK not found: %s.wbnk\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeBagSlotLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.entries.empty()) {
warnings.push_back("catalog has zero entries");
}
std::vector<uint32_t> idsSeen;
// displayOrder values within the same bagKind should be
// unique — duplicates would cause UI shuffle ambiguity.
std::set<std::string> orderSeen;
for (size_t k = 0; k < c.entries.size(); ++k) {
const auto& e = c.entries[k];
std::string ctx = "entry " + std::to_string(k) +
" (id=" + std::to_string(e.bagSlotId);
if (!e.name.empty()) ctx += " " + e.name;
ctx += ")";
if (e.bagSlotId == 0)
errors.push_back(ctx + ": bagSlotId is 0");
if (e.name.empty())
errors.push_back(ctx + ": name is empty");
if (e.bagKind > wowee::pipeline::WoweeBagSlot::Wallet) {
errors.push_back(ctx + ": bagKind " +
std::to_string(e.bagKind) + " not in 0..7");
}
// A slot that's not unlocked but has unlockCostCopper=0
// can never be unlocked through normal gameplay — flag.
if (e.isUnlocked == 0 && e.unlockCostCopper == 0) {
warnings.push_back(ctx +
": isUnlocked=0 with unlockCostCopper=0 "
"(slot can never be unlocked in-game)");
}
// A fixed-bag slot (containerSize > 0, fixedBagItemId
// = 0) with a non-zero acceptsBagSubclassMask is
// contradictory — fixed slots don't accept equippable
// bags. The starter MainBackpack illustrates this:
// size=16, mask=0.
if (e.containerSize > 0 && e.fixedBagItemId == 0 &&
e.acceptsBagSubclassMask != 0) {
warnings.push_back(ctx +
": fixed-size slot (containerSize=" +
std::to_string(e.containerSize) +
") with non-zero acceptsBagSubclassMask "
"(equippable bag would be ignored)");
}
// A variable slot (containerSize=0) with mask=0 can
// never accept any bag.
if (e.containerSize == 0 && e.acceptsBagSubclassMask == 0 &&
e.bagKind != wowee::pipeline::WoweeBagSlot::Stable) {
errors.push_back(ctx +
": variable slot (containerSize=0) with "
"acceptsBagSubclassMask=0 — no bag can fit here");
}
// (bagKind, displayOrder) tuple uniqueness — within
// the same kind the UI sorts by displayOrder, so
// duplicates would cause ambiguous ordering.
std::string tuple =
std::to_string(e.bagKind) + "/" +
std::to_string(e.displayOrder);
if (orderSeen.count(tuple)) {
warnings.push_back(ctx +
": duplicate (bagKind=" +
wowee::pipeline::WoweeBagSlot::bagKindName(e.bagKind) +
", displayOrder=" +
std::to_string(e.displayOrder) +
") — UI sort order is ambiguous");
}
orderSeen.insert(tuple);
for (uint32_t prev : idsSeen) {
if (prev == e.bagSlotId) {
errors.push_back(ctx + ": duplicate bagSlotId");
break;
}
}
idsSeen.push_back(e.bagSlotId);
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wbnk"] = base + ".wbnk";
j["ok"] = ok;
j["errors"] = errors;
j["warnings"] = warnings;
std::printf("%s\n", j.dump(2).c_str());
return ok ? 0 : 1;
}
std::printf("validate-wbnk: %s.wbnk\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu slots, all bagSlotIds unique, no order ambiguity\n",
c.entries.size());
return 0;
}
if (!warnings.empty()) {
std::printf(" warnings (%zu):\n", warnings.size());
for (const auto& w : warnings)
std::printf(" - %s\n", w.c_str());
}
if (!errors.empty()) {
std::printf(" ERRORS (%zu):\n", errors.size());
for (const auto& e : errors)
std::printf(" - %s\n", e.c_str());
}
return ok ? 0 : 1;
}
} // namespace
bool handleBagsCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-bnk") == 0 && i + 1 < argc) {
outRc = handleGenStarter(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-bnk-bank") == 0 && i + 1 < argc) {
outRc = handleGenBank(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-bnk-special") == 0 && i + 1 < argc) {
outRc = handleGenSpecial(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wbnk") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wbnk") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee