#include "cli_bags_catalog.hpp" #include "cli_arg_parse.hpp" #include "cli_box_emitter.hpp" #include "pipeline/wowee_bags.hpp" #include #include #include #include #include #include #include #include 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 errors; std::vector warnings; if (c.entries.empty()) { warnings.push_back("catalog has zero entries"); } std::vector idsSeen; // displayOrder values within the same bagKind should be // unique — duplicates would cause UI shuffle ambiguity. std::set 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