mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 19:43:52 +00:00
286 lines
10 KiB
C++
286 lines
10 KiB
C++
|
|
#include "cli_spell_variants_catalog.hpp"
|
||
|
|
#include "cli_arg_parse.hpp"
|
||
|
|
#include "cli_box_emitter.hpp"
|
||
|
|
|
||
|
|
#include "pipeline/wowee_spell_variants.hpp"
|
||
|
|
#include <nlohmann/json.hpp>
|
||
|
|
|
||
|
|
#include <cstdint>
|
||
|
|
#include <cstdio>
|
||
|
|
#include <cstring>
|
||
|
|
#include <fstream>
|
||
|
|
#include <map>
|
||
|
|
#include <set>
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
namespace wowee {
|
||
|
|
namespace editor {
|
||
|
|
namespace cli {
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
|
||
|
|
std::string stripWspvExt(std::string base) {
|
||
|
|
stripExt(base, ".wspv");
|
||
|
|
return base;
|
||
|
|
}
|
||
|
|
|
||
|
|
const char* conditionKindName(uint8_t k) {
|
||
|
|
using V = wowee::pipeline::WoweeSpellVariants;
|
||
|
|
switch (k) {
|
||
|
|
case V::Stance: return "stance";
|
||
|
|
case V::Form: return "form";
|
||
|
|
case V::Talent: return "talent";
|
||
|
|
case V::Race: return "race";
|
||
|
|
case V::EquippedWeapon: return "equippedweapon";
|
||
|
|
case V::AuraActive: return "auraactive";
|
||
|
|
default: return "unknown";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
bool saveOrError(const wowee::pipeline::WoweeSpellVariants& c,
|
||
|
|
const std::string& base, const char* cmd) {
|
||
|
|
if (!wowee::pipeline::WoweeSpellVariantsLoader::save(c, base)) {
|
||
|
|
std::fprintf(stderr, "%s: failed to save %s.wspv\n",
|
||
|
|
cmd, base.c_str());
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
void printGenSummary(const wowee::pipeline::WoweeSpellVariants& c,
|
||
|
|
const std::string& base) {
|
||
|
|
std::printf("Wrote %s.wspv\n", base.c_str());
|
||
|
|
std::printf(" catalog : %s\n", c.name.c_str());
|
||
|
|
std::printf(" variants : %zu\n", c.entries.size());
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenWarrior(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "WarriorStanceVariants";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWspvExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeSpellVariantsLoader::makeWarriorStance(name);
|
||
|
|
if (!saveOrError(c, base, "gen-spv")) return 1;
|
||
|
|
printGenSummary(c, base);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenTalent(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "TalentModifiedVariants";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWspvExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeSpellVariantsLoader::makeTalentMod(name);
|
||
|
|
if (!saveOrError(c, base, "gen-spv-talent")) return 1;
|
||
|
|
printGenSummary(c, base);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenRacial(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "RacialVariants";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWspvExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeSpellVariantsLoader::makeRacial(name);
|
||
|
|
if (!saveOrError(c, base, "gen-spv-racial")) 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 = stripWspvExt(base);
|
||
|
|
if (!wowee::pipeline::WoweeSpellVariantsLoader::exists(base)) {
|
||
|
|
std::fprintf(stderr, "WSPV not found: %s.wspv\n", base.c_str());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
auto c = wowee::pipeline::WoweeSpellVariantsLoader::load(base);
|
||
|
|
if (jsonOut) {
|
||
|
|
nlohmann::json j;
|
||
|
|
j["wspv"] = base + ".wspv";
|
||
|
|
j["name"] = c.name;
|
||
|
|
j["count"] = c.entries.size();
|
||
|
|
nlohmann::json arr = nlohmann::json::array();
|
||
|
|
for (const auto& e : c.entries) {
|
||
|
|
arr.push_back({
|
||
|
|
{"variantId", e.variantId},
|
||
|
|
{"name", e.name},
|
||
|
|
{"description", e.description},
|
||
|
|
{"baseSpellId", e.baseSpellId},
|
||
|
|
{"variantSpellId", e.variantSpellId},
|
||
|
|
{"conditionKind", e.conditionKind},
|
||
|
|
{"conditionKindName",
|
||
|
|
conditionKindName(e.conditionKind)},
|
||
|
|
{"priority", e.priority},
|
||
|
|
{"conditionValue", e.conditionValue},
|
||
|
|
{"iconColorRGBA", e.iconColorRGBA},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
j["entries"] = arr;
|
||
|
|
std::printf("%s\n", j.dump(2).c_str());
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
std::printf("WSPV: %s.wspv\n", base.c_str());
|
||
|
|
std::printf(" catalog : %s\n", c.name.c_str());
|
||
|
|
std::printf(" variants : %zu\n", c.entries.size());
|
||
|
|
if (c.entries.empty()) return 0;
|
||
|
|
std::printf(" id baseSp varSp condition condVal prio name\n");
|
||
|
|
for (const auto& e : c.entries) {
|
||
|
|
std::printf(" %4u %5u %5u %-13s %5u %3u %s\n",
|
||
|
|
e.variantId, e.baseSpellId,
|
||
|
|
e.variantSpellId,
|
||
|
|
conditionKindName(e.conditionKind),
|
||
|
|
e.conditionValue, e.priority,
|
||
|
|
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 = stripWspvExt(base);
|
||
|
|
if (!wowee::pipeline::WoweeSpellVariantsLoader::exists(base)) {
|
||
|
|
std::fprintf(stderr,
|
||
|
|
"validate-wspv: WSPV not found: %s.wspv\n",
|
||
|
|
base.c_str());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
auto c = wowee::pipeline::WoweeSpellVariantsLoader::load(base);
|
||
|
|
std::vector<std::string> errors;
|
||
|
|
std::vector<std::string> warnings;
|
||
|
|
if (c.entries.empty()) {
|
||
|
|
warnings.push_back("catalog has zero entries");
|
||
|
|
}
|
||
|
|
std::set<uint32_t> idsSeen;
|
||
|
|
// Per-(baseSpell, conditionKind, conditionValue,
|
||
|
|
// priority) tuple uniqueness — two variants with all
|
||
|
|
// four matching would tie at runtime and resolve
|
||
|
|
// non-deterministically.
|
||
|
|
std::set<uint64_t> tupleSeen;
|
||
|
|
auto tupleKey = [](uint32_t base, uint8_t kind,
|
||
|
|
uint32_t value, uint8_t prio) {
|
||
|
|
// Pack into 64 bits: base (32) | value (16
|
||
|
|
// truncated) | kind (8) | prio (8). Tight packing
|
||
|
|
// so we don't need a multi-key set.
|
||
|
|
uint64_t k = static_cast<uint64_t>(base) << 32;
|
||
|
|
k |= (static_cast<uint64_t>(value & 0xFFFF) << 16);
|
||
|
|
k |= (static_cast<uint64_t>(kind) << 8);
|
||
|
|
k |= prio;
|
||
|
|
return k;
|
||
|
|
};
|
||
|
|
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.variantId);
|
||
|
|
if (!e.name.empty()) ctx += " " + e.name;
|
||
|
|
ctx += ")";
|
||
|
|
if (e.variantId == 0)
|
||
|
|
errors.push_back(ctx + ": variantId is 0");
|
||
|
|
if (e.name.empty())
|
||
|
|
errors.push_back(ctx + ": name is empty");
|
||
|
|
if (e.baseSpellId == 0) {
|
||
|
|
errors.push_back(ctx +
|
||
|
|
": baseSpellId is 0 — variant has no "
|
||
|
|
"base spell to substitute for");
|
||
|
|
}
|
||
|
|
if (e.variantSpellId == 0) {
|
||
|
|
errors.push_back(ctx +
|
||
|
|
": variantSpellId is 0 — variant has no "
|
||
|
|
"spell to substitute INTO");
|
||
|
|
}
|
||
|
|
if (e.conditionKind > 5) {
|
||
|
|
errors.push_back(ctx + ": conditionKind " +
|
||
|
|
std::to_string(e.conditionKind) +
|
||
|
|
" out of range (must be 0..5)");
|
||
|
|
}
|
||
|
|
if (e.conditionValue == 0) {
|
||
|
|
warnings.push_back(ctx +
|
||
|
|
": conditionValue is 0 — condition would "
|
||
|
|
"match the always-zero default; verify "
|
||
|
|
"if intentional (the gate becomes a "
|
||
|
|
"no-op)");
|
||
|
|
}
|
||
|
|
// Tuple uniqueness check.
|
||
|
|
uint64_t key = tupleKey(e.baseSpellId,
|
||
|
|
e.conditionKind,
|
||
|
|
e.conditionValue,
|
||
|
|
e.priority);
|
||
|
|
if (!tupleSeen.insert(key).second) {
|
||
|
|
errors.push_back(ctx +
|
||
|
|
": (baseSpell=" +
|
||
|
|
std::to_string(e.baseSpellId) +
|
||
|
|
", conditionKind=" +
|
||
|
|
std::string(conditionKindName(e.conditionKind)) +
|
||
|
|
", conditionValue=" +
|
||
|
|
std::to_string(e.conditionValue) +
|
||
|
|
", priority=" +
|
||
|
|
std::to_string(e.priority) +
|
||
|
|
") tuple already bound by another variant "
|
||
|
|
"— spell-cast pipeline lookup would be "
|
||
|
|
"non-deterministic");
|
||
|
|
}
|
||
|
|
if (!idsSeen.insert(e.variantId).second) {
|
||
|
|
errors.push_back(ctx + ": duplicate variantId");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
bool ok = errors.empty();
|
||
|
|
if (jsonOut) {
|
||
|
|
nlohmann::json j;
|
||
|
|
j["wspv"] = base + ".wspv";
|
||
|
|
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-wspv: %s.wspv\n", base.c_str());
|
||
|
|
if (ok && warnings.empty()) {
|
||
|
|
std::printf(" OK — %zu variants, all variantIds + "
|
||
|
|
"(base,kind,val,prio) tuples unique\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 handleSpellVariantsCatalog(int& i, int argc, char** argv,
|
||
|
|
int& outRc) {
|
||
|
|
if (std::strcmp(argv[i], "--gen-spv") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleGenWarrior(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--gen-spv-talent") == 0 &&
|
||
|
|
i + 1 < argc) {
|
||
|
|
outRc = handleGenTalent(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--gen-spv-racial") == 0 &&
|
||
|
|
i + 1 < argc) {
|
||
|
|
outRc = handleGenRacial(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--info-wspv") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleInfo(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--validate-wspv") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleValidate(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace cli
|
||
|
|
} // namespace editor
|
||
|
|
} // namespace wowee
|