Kelsidavis-WoWee/tools/editor/cli_gems_catalog.cpp

456 lines
18 KiB
C++
Raw Normal View History

feat(pipeline): add WGEM (Wowee Gem / Enchantment) format Novel open replacement for Blizzard's ItemEnchantment.dbc + GemProperties.dbc + SpellItemEnchantment.dbc. The 35th open format added to the editor. Defines two related kinds of item enhancement in one catalog: • Gems — socketable jewelry pieces with color (red / blue / yellow / meta) that fit into gear sockets, granting stats or triggering passive spells when socketed • Enchantments — persistent buffs applied to weapon / armor pieces, either by an enchanter spell or by an item proc (Mongoose, Crusader, Berserking) Cross-references with previously-added formats: WGEM.gem.itemIdToInsert -> WIT.entry.itemId WGEM.gem.spellId -> WSPL.entry.spellId WGEM.enchantment.spellId -> WSPL.entry.spellId Format: • magic "WGEM", version 1, little-endian • gems[]: gemId / itemIdToInsert / name / color / statType + statValue / requiredItemQuality / spellId • enchantments[]: enchantId / name / description / iconPath / enchantSlot / statType + statValue / spellId / durationSeconds / chargeCount Enums: • Color (8): Meta / Red / Yellow / Blue / Purple / Green / Orange / Prismatic • EnchantSlot (5): Permanent / Temporary / SocketColor / Ring / Cloak API: WoweeGemLoader::save / load / exists + WoweeGem::findGem / findEnchant. Three preset emitters showcase common shapes: • makeStarter — 3 gems (one per primary color) + 2 enchantments (proc + stat) • makeGemSet — 6-gem full color palette covering primary + secondary combinations • makeEnchants — 5 enchant variants spanning slots (Mongoose / Deadly Poison / stats ring / cloak / Berserking) CLI added (5 flags, 642 documented total now): --gen-gems / --gen-gems-set / --gen-gems-enchants --info-wgem / --validate-wgem Validator catches: ids=0 + duplicates, empty name, color / slot out of range, stat-only entries with statValue=0 (gem provides nothing), chargeCount > 0 on non-Temporary enchant slots (charges silently ignored at runtime). The validator caught a real preset issue on first run — the proc enchants (Mongoose / Deadly Poison / Berserking) had spellId=0 and statValue=0, providing nothing. Fixed by adding placeholder spellIds in the 28000-29000 range, with a comment noting they resolve to real WSPL proc spells when the spell catalog is extended.
2026-05-09 18:01:48 -07:00
#include "cli_gems_catalog.hpp"
#include "cli_arg_parse.hpp"
#include "cli_box_emitter.hpp"
#include "pipeline/wowee_gems.hpp"
#include <nlohmann/json.hpp>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
namespace wowee {
namespace editor {
namespace cli {
namespace {
std::string stripWgemExt(std::string base) {
stripExt(base, ".wgem");
return base;
}
bool saveOrError(const wowee::pipeline::WoweeGem& c,
const std::string& base, const char* cmd) {
if (!wowee::pipeline::WoweeGemLoader::save(c, base)) {
std::fprintf(stderr, "%s: failed to save %s.wgem\n",
cmd, base.c_str());
return false;
}
return true;
}
void printGenSummary(const wowee::pipeline::WoweeGem& c,
const std::string& base) {
std::printf("Wrote %s.wgem\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" gems : %zu\n", c.gems.size());
std::printf(" enchantments : %zu\n", c.enchantments.size());
}
int handleGenStarter(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "StarterGems";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWgemExt(base);
auto c = wowee::pipeline::WoweeGemLoader::makeStarter(name);
if (!saveOrError(c, base, "gen-gems")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenGemSet(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "FullGemSet";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWgemExt(base);
auto c = wowee::pipeline::WoweeGemLoader::makeGemSet(name);
if (!saveOrError(c, base, "gen-gems-set")) return 1;
printGenSummary(c, base);
return 0;
}
int handleGenEnchants(int& i, int argc, char** argv) {
std::string base = argv[++i];
std::string name = "EnchantSet";
if (parseOptArg(i, argc, argv)) name = argv[++i];
base = stripWgemExt(base);
auto c = wowee::pipeline::WoweeGemLoader::makeEnchants(name);
if (!saveOrError(c, base, "gen-gems-enchants")) 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 = stripWgemExt(base);
if (!wowee::pipeline::WoweeGemLoader::exists(base)) {
std::fprintf(stderr, "WGEM not found: %s.wgem\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeGemLoader::load(base);
if (jsonOut) {
nlohmann::json j;
j["wgem"] = base + ".wgem";
j["name"] = c.name;
j["gemCount"] = c.gems.size();
j["enchantCount"] = c.enchantments.size();
nlohmann::json ga = nlohmann::json::array();
for (const auto& g : c.gems) {
ga.push_back({
{"gemId", g.gemId},
{"itemIdToInsert", g.itemIdToInsert},
{"name", g.name},
{"color", g.color},
{"colorName", wowee::pipeline::WoweeGem::colorName(g.color)},
{"statType", g.statType},
{"statValue", g.statValue},
{"requiredItemQuality", g.requiredItemQuality},
{"spellId", g.spellId},
});
}
j["gems"] = ga;
nlohmann::json ea = nlohmann::json::array();
for (const auto& e : c.enchantments) {
ea.push_back({
{"enchantId", e.enchantId},
{"name", e.name},
{"description", e.description},
{"iconPath", e.iconPath},
{"enchantSlot", e.enchantSlot},
{"enchantSlotName", wowee::pipeline::WoweeGem::enchantSlotName(e.enchantSlot)},
{"statType", e.statType},
{"statValue", e.statValue},
{"spellId", e.spellId},
{"durationSeconds", e.durationSeconds},
{"chargeCount", e.chargeCount},
});
}
j["enchantments"] = ea;
std::printf("%s\n", j.dump(2).c_str());
return 0;
}
std::printf("WGEM: %s.wgem\n", base.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" gems : %zu\n", c.gems.size());
std::printf(" enchantments : %zu\n", c.enchantments.size());
if (!c.gems.empty()) {
std::printf("\n Gems:\n");
std::printf(" id color stat/value itemId name\n");
for (const auto& g : c.gems) {
std::printf(" %4u %-10s %3u/%-5d %5u %s\n",
g.gemId,
wowee::pipeline::WoweeGem::colorName(g.color),
g.statType, g.statValue,
g.itemIdToInsert, g.name.c_str());
}
}
if (!c.enchantments.empty()) {
std::printf("\n Enchantments:\n");
std::printf(" id slot stat/value dur(s) chg name\n");
for (const auto& e : c.enchantments) {
std::printf(" %4u %-10s %3u/%-5d %5u %3u %s\n",
e.enchantId,
wowee::pipeline::WoweeGem::enchantSlotName(e.enchantSlot),
e.statType, e.statValue,
e.durationSeconds, e.chargeCount,
e.name.c_str());
}
}
return 0;
}
int handleExportJson(int& i, int argc, char** argv) {
// Mirrors the JSON pairs added for every other novel
// open format. Two top-level arrays (gems / enchantments)
// mirror the binary layout. color and enchantSlot emit
// dual int + name forms.
std::string base = argv[++i];
std::string outPath;
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
base = stripWgemExt(base);
if (outPath.empty()) outPath = base + ".wgem.json";
if (!wowee::pipeline::WoweeGemLoader::exists(base)) {
std::fprintf(stderr,
"export-wgem-json: WGEM not found: %s.wgem\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeGemLoader::load(base);
nlohmann::json j;
j["name"] = c.name;
nlohmann::json ga = nlohmann::json::array();
for (const auto& g : c.gems) {
ga.push_back({
{"gemId", g.gemId},
{"itemIdToInsert", g.itemIdToInsert},
{"name", g.name},
{"color", g.color},
{"colorName", wowee::pipeline::WoweeGem::colorName(g.color)},
{"statType", g.statType},
{"statValue", g.statValue},
{"requiredItemQuality", g.requiredItemQuality},
{"spellId", g.spellId},
});
}
j["gems"] = ga;
nlohmann::json ea = nlohmann::json::array();
for (const auto& e : c.enchantments) {
ea.push_back({
{"enchantId", e.enchantId},
{"name", e.name},
{"description", e.description},
{"iconPath", e.iconPath},
{"enchantSlot", e.enchantSlot},
{"enchantSlotName", wowee::pipeline::WoweeGem::enchantSlotName(e.enchantSlot)},
{"statType", e.statType},
{"statValue", e.statValue},
{"spellId", e.spellId},
{"durationSeconds", e.durationSeconds},
{"chargeCount", e.chargeCount},
});
}
j["enchantments"] = ea;
std::ofstream out(outPath);
if (!out) {
std::fprintf(stderr,
"export-wgem-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.wgem\n", base.c_str());
std::printf(" gems / ench : %zu / %zu\n",
c.gems.size(), c.enchantments.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 = ".wgem.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 = stripWgemExt(outBase);
std::ifstream in(jsonPath);
if (!in) {
std::fprintf(stderr,
"import-wgem-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-wgem-json: bad JSON in %s: %s\n",
jsonPath.c_str(), e.what());
return 1;
}
auto colorFromName = [](const std::string& s) -> uint8_t {
if (s == "meta") return wowee::pipeline::WoweeGem::Meta;
if (s == "red") return wowee::pipeline::WoweeGem::Red;
if (s == "yellow") return wowee::pipeline::WoweeGem::Yellow;
if (s == "blue") return wowee::pipeline::WoweeGem::Blue;
if (s == "purple") return wowee::pipeline::WoweeGem::Purple;
if (s == "green") return wowee::pipeline::WoweeGem::Green;
if (s == "orange") return wowee::pipeline::WoweeGem::Orange;
if (s == "prismatic") return wowee::pipeline::WoweeGem::Prismatic;
return wowee::pipeline::WoweeGem::Red;
};
auto slotFromName = [](const std::string& s) -> uint8_t {
if (s == "permanent") return wowee::pipeline::WoweeGem::Permanent;
if (s == "temporary") return wowee::pipeline::WoweeGem::Temporary;
if (s == "socket") return wowee::pipeline::WoweeGem::SocketColor;
if (s == "ring") return wowee::pipeline::WoweeGem::Ring;
if (s == "cloak") return wowee::pipeline::WoweeGem::Cloak;
return wowee::pipeline::WoweeGem::Permanent;
};
wowee::pipeline::WoweeGem c;
c.name = j.value("name", std::string{});
if (j.contains("gems") && j["gems"].is_array()) {
for (const auto& jg : j["gems"]) {
wowee::pipeline::WoweeGem::GemEntry g;
g.gemId = jg.value("gemId", 0u);
g.itemIdToInsert = jg.value("itemIdToInsert", 0u);
g.name = jg.value("name", std::string{});
if (jg.contains("color") && jg["color"].is_number_integer()) {
g.color = static_cast<uint8_t>(jg["color"].get<int>());
} else if (jg.contains("colorName") && jg["colorName"].is_string()) {
g.color = colorFromName(jg["colorName"].get<std::string>());
}
g.statType = static_cast<uint8_t>(jg.value("statType", 0));
g.statValue = static_cast<int16_t>(jg.value("statValue", 0));
g.requiredItemQuality = static_cast<uint8_t>(
jg.value("requiredItemQuality", 0));
g.spellId = jg.value("spellId", 0u);
c.gems.push_back(g);
}
}
if (j.contains("enchantments") && j["enchantments"].is_array()) {
for (const auto& je : j["enchantments"]) {
wowee::pipeline::WoweeGem::EnchantEntry e;
e.enchantId = je.value("enchantId", 0u);
e.name = je.value("name", std::string{});
e.description = je.value("description", std::string{});
e.iconPath = je.value("iconPath", std::string{});
if (je.contains("enchantSlot") && je["enchantSlot"].is_number_integer()) {
e.enchantSlot = static_cast<uint8_t>(je["enchantSlot"].get<int>());
} else if (je.contains("enchantSlotName") &&
je["enchantSlotName"].is_string()) {
e.enchantSlot = slotFromName(je["enchantSlotName"].get<std::string>());
}
e.statType = static_cast<uint8_t>(je.value("statType", 0));
e.statValue = static_cast<int16_t>(je.value("statValue", 0));
e.spellId = je.value("spellId", 0u);
e.durationSeconds = je.value("durationSeconds", 0u);
e.chargeCount = static_cast<uint16_t>(je.value("chargeCount", 0));
c.enchantments.push_back(e);
}
}
if (!wowee::pipeline::WoweeGemLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wgem-json: failed to save %s.wgem\n", outBase.c_str());
return 1;
}
std::printf("Wrote %s.wgem\n", outBase.c_str());
std::printf(" source : %s\n", jsonPath.c_str());
std::printf(" gems / ench : %zu / %zu\n",
c.gems.size(), c.enchantments.size());
return 0;
}
feat(pipeline): add WGEM (Wowee Gem / Enchantment) format Novel open replacement for Blizzard's ItemEnchantment.dbc + GemProperties.dbc + SpellItemEnchantment.dbc. The 35th open format added to the editor. Defines two related kinds of item enhancement in one catalog: • Gems — socketable jewelry pieces with color (red / blue / yellow / meta) that fit into gear sockets, granting stats or triggering passive spells when socketed • Enchantments — persistent buffs applied to weapon / armor pieces, either by an enchanter spell or by an item proc (Mongoose, Crusader, Berserking) Cross-references with previously-added formats: WGEM.gem.itemIdToInsert -> WIT.entry.itemId WGEM.gem.spellId -> WSPL.entry.spellId WGEM.enchantment.spellId -> WSPL.entry.spellId Format: • magic "WGEM", version 1, little-endian • gems[]: gemId / itemIdToInsert / name / color / statType + statValue / requiredItemQuality / spellId • enchantments[]: enchantId / name / description / iconPath / enchantSlot / statType + statValue / spellId / durationSeconds / chargeCount Enums: • Color (8): Meta / Red / Yellow / Blue / Purple / Green / Orange / Prismatic • EnchantSlot (5): Permanent / Temporary / SocketColor / Ring / Cloak API: WoweeGemLoader::save / load / exists + WoweeGem::findGem / findEnchant. Three preset emitters showcase common shapes: • makeStarter — 3 gems (one per primary color) + 2 enchantments (proc + stat) • makeGemSet — 6-gem full color palette covering primary + secondary combinations • makeEnchants — 5 enchant variants spanning slots (Mongoose / Deadly Poison / stats ring / cloak / Berserking) CLI added (5 flags, 642 documented total now): --gen-gems / --gen-gems-set / --gen-gems-enchants --info-wgem / --validate-wgem Validator catches: ids=0 + duplicates, empty name, color / slot out of range, stat-only entries with statValue=0 (gem provides nothing), chargeCount > 0 on non-Temporary enchant slots (charges silently ignored at runtime). The validator caught a real preset issue on first run — the proc enchants (Mongoose / Deadly Poison / Berserking) had spellId=0 and statValue=0, providing nothing. Fixed by adding placeholder spellIds in the 28000-29000 range, with a comment noting they resolve to real WSPL proc spells when the spell catalog is extended.
2026-05-09 18:01:48 -07:00
int handleValidate(int& i, int argc, char** argv) {
std::string base = argv[++i];
bool jsonOut = consumeJsonFlag(i, argc, argv);
base = stripWgemExt(base);
if (!wowee::pipeline::WoweeGemLoader::exists(base)) {
std::fprintf(stderr,
"validate-wgem: WGEM not found: %s.wgem\n", base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeGemLoader::load(base);
std::vector<std::string> errors;
std::vector<std::string> warnings;
if (c.gems.empty() && c.enchantments.empty()) {
warnings.push_back("catalog has zero gems and zero enchantments");
}
std::vector<uint32_t> gemIdsSeen;
for (size_t k = 0; k < c.gems.size(); ++k) {
const auto& g = c.gems[k];
std::string ctx = "gem " + std::to_string(k) +
" (id=" + std::to_string(g.gemId);
if (!g.name.empty()) ctx += " " + g.name;
ctx += ")";
if (g.gemId == 0) errors.push_back(ctx + ": gemId is 0");
if (g.name.empty()) errors.push_back(ctx + ": name is empty");
if (g.color > wowee::pipeline::WoweeGem::Prismatic) {
errors.push_back(ctx + ": color " +
std::to_string(g.color) + " not in 0..7");
}
// Stat-only gems (spellId=0) need statValue != 0.
if (g.spellId == 0 && g.statValue == 0) {
warnings.push_back(ctx +
": no spell + statValue=0 (gem provides nothing)");
}
for (uint32_t prev : gemIdsSeen) {
if (prev == g.gemId) {
errors.push_back(ctx + ": duplicate gemId");
break;
}
}
gemIdsSeen.push_back(g.gemId);
}
std::vector<uint32_t> enchIdsSeen;
for (size_t k = 0; k < c.enchantments.size(); ++k) {
const auto& e = c.enchantments[k];
std::string ctx = "enchant " + std::to_string(k) +
" (id=" + std::to_string(e.enchantId);
if (!e.name.empty()) ctx += " " + e.name;
ctx += ")";
if (e.enchantId == 0) errors.push_back(ctx + ": enchantId is 0");
if (e.name.empty()) errors.push_back(ctx + ": name is empty");
if (e.enchantSlot > wowee::pipeline::WoweeGem::Cloak) {
errors.push_back(ctx + ": enchantSlot " +
std::to_string(e.enchantSlot) + " not in 0..4");
}
if (e.spellId == 0 && e.statValue == 0) {
warnings.push_back(ctx +
": no spell + statValue=0 (enchant provides nothing)");
}
// Charges only meaningful for Temporary enchants.
if (e.chargeCount > 0 &&
e.enchantSlot != wowee::pipeline::WoweeGem::Temporary) {
warnings.push_back(ctx +
": chargeCount > 0 on non-Temporary slot (charges ignored)");
}
for (uint32_t prev : enchIdsSeen) {
if (prev == e.enchantId) {
errors.push_back(ctx + ": duplicate enchantId");
break;
}
}
enchIdsSeen.push_back(e.enchantId);
}
bool ok = errors.empty();
if (jsonOut) {
nlohmann::json j;
j["wgem"] = base + ".wgem";
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-wgem: %s.wgem\n", base.c_str());
if (ok && warnings.empty()) {
std::printf(" OK — %zu gems, %zu enchantments, all IDs unique\n",
c.gems.size(), c.enchantments.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 handleGemsCatalog(int& i, int argc, char** argv, int& outRc) {
if (std::strcmp(argv[i], "--gen-gems") == 0 && i + 1 < argc) {
outRc = handleGenStarter(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-gems-set") == 0 && i + 1 < argc) {
outRc = handleGenGemSet(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--gen-gems-enchants") == 0 && i + 1 < argc) {
outRc = handleGenEnchants(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--info-wgem") == 0 && i + 1 < argc) {
outRc = handleInfo(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--validate-wgem") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wgem-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wgem-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
feat(pipeline): add WGEM (Wowee Gem / Enchantment) format Novel open replacement for Blizzard's ItemEnchantment.dbc + GemProperties.dbc + SpellItemEnchantment.dbc. The 35th open format added to the editor. Defines two related kinds of item enhancement in one catalog: • Gems — socketable jewelry pieces with color (red / blue / yellow / meta) that fit into gear sockets, granting stats or triggering passive spells when socketed • Enchantments — persistent buffs applied to weapon / armor pieces, either by an enchanter spell or by an item proc (Mongoose, Crusader, Berserking) Cross-references with previously-added formats: WGEM.gem.itemIdToInsert -> WIT.entry.itemId WGEM.gem.spellId -> WSPL.entry.spellId WGEM.enchantment.spellId -> WSPL.entry.spellId Format: • magic "WGEM", version 1, little-endian • gems[]: gemId / itemIdToInsert / name / color / statType + statValue / requiredItemQuality / spellId • enchantments[]: enchantId / name / description / iconPath / enchantSlot / statType + statValue / spellId / durationSeconds / chargeCount Enums: • Color (8): Meta / Red / Yellow / Blue / Purple / Green / Orange / Prismatic • EnchantSlot (5): Permanent / Temporary / SocketColor / Ring / Cloak API: WoweeGemLoader::save / load / exists + WoweeGem::findGem / findEnchant. Three preset emitters showcase common shapes: • makeStarter — 3 gems (one per primary color) + 2 enchantments (proc + stat) • makeGemSet — 6-gem full color palette covering primary + secondary combinations • makeEnchants — 5 enchant variants spanning slots (Mongoose / Deadly Poison / stats ring / cloak / Berserking) CLI added (5 flags, 642 documented total now): --gen-gems / --gen-gems-set / --gen-gems-enchants --info-wgem / --validate-wgem Validator catches: ids=0 + duplicates, empty name, color / slot out of range, stat-only entries with statValue=0 (gem provides nothing), chargeCount > 0 on non-Temporary enchant slots (charges silently ignored at runtime). The validator caught a real preset issue on first run — the proc enchants (Mongoose / Deadly Poison / Berserking) had spellId=0 and statValue=0, providing nothing. Fixed by adding placeholder spellIds in the 28000-29000 range, with a comment noting they resolve to real WSPL proc spells when the spell catalog is extended.
2026-05-09 18:01:48 -07:00
return false;
}
} // namespace cli
} // namespace editor
} // namespace wowee