mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
234 lines
7.9 KiB
C++
234 lines
7.9 KiB
C++
|
|
#include "cli_glyphs_catalog.hpp"
|
||
|
|
#include "cli_arg_parse.hpp"
|
||
|
|
#include "cli_box_emitter.hpp"
|
||
|
|
|
||
|
|
#include "pipeline/wowee_glyphs.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 stripWglyExt(std::string base) {
|
||
|
|
stripExt(base, ".wgly");
|
||
|
|
return base;
|
||
|
|
}
|
||
|
|
|
||
|
|
bool saveOrError(const wowee::pipeline::WoweeGlyph& c,
|
||
|
|
const std::string& base, const char* cmd) {
|
||
|
|
if (!wowee::pipeline::WoweeGlyphLoader::save(c, base)) {
|
||
|
|
std::fprintf(stderr, "%s: failed to save %s.wgly\n",
|
||
|
|
cmd, base.c_str());
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
void printGenSummary(const wowee::pipeline::WoweeGlyph& c,
|
||
|
|
const std::string& base) {
|
||
|
|
std::printf("Wrote %s.wgly\n", base.c_str());
|
||
|
|
std::printf(" catalog : %s\n", c.name.c_str());
|
||
|
|
std::printf(" glyphs : %zu\n", c.entries.size());
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenStarter(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "StarterGlyphs";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWglyExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeGlyphLoader::makeStarter(name);
|
||
|
|
if (!saveOrError(c, base, "gen-glyphs")) return 1;
|
||
|
|
printGenSummary(c, base);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenWarrior(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "WarriorGlyphs";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWglyExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeGlyphLoader::makeWarrior(name);
|
||
|
|
if (!saveOrError(c, base, "gen-glyphs-warrior")) return 1;
|
||
|
|
printGenSummary(c, base);
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int handleGenUniversal(int& i, int argc, char** argv) {
|
||
|
|
std::string base = argv[++i];
|
||
|
|
std::string name = "UniversalGlyphs";
|
||
|
|
if (parseOptArg(i, argc, argv)) name = argv[++i];
|
||
|
|
base = stripWglyExt(base);
|
||
|
|
auto c = wowee::pipeline::WoweeGlyphLoader::makeUniversal(name);
|
||
|
|
if (!saveOrError(c, base, "gen-glyphs-universal")) 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 = stripWglyExt(base);
|
||
|
|
if (!wowee::pipeline::WoweeGlyphLoader::exists(base)) {
|
||
|
|
std::fprintf(stderr, "WGLY not found: %s.wgly\n", base.c_str());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
auto c = wowee::pipeline::WoweeGlyphLoader::load(base);
|
||
|
|
if (jsonOut) {
|
||
|
|
nlohmann::json j;
|
||
|
|
j["wgly"] = base + ".wgly";
|
||
|
|
j["name"] = c.name;
|
||
|
|
j["count"] = c.entries.size();
|
||
|
|
nlohmann::json arr = nlohmann::json::array();
|
||
|
|
for (const auto& e : c.entries) {
|
||
|
|
arr.push_back({
|
||
|
|
{"glyphId", e.glyphId},
|
||
|
|
{"name", e.name},
|
||
|
|
{"description", e.description},
|
||
|
|
{"iconPath", e.iconPath},
|
||
|
|
{"glyphType", e.glyphType},
|
||
|
|
{"glyphTypeName", wowee::pipeline::WoweeGlyph::glyphTypeName(e.glyphType)},
|
||
|
|
{"spellId", e.spellId},
|
||
|
|
{"itemId", e.itemId},
|
||
|
|
{"classMask", e.classMask},
|
||
|
|
{"requiredLevel", e.requiredLevel},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
j["entries"] = arr;
|
||
|
|
std::printf("%s\n", j.dump(2).c_str());
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
std::printf("WGLY: %s.wgly\n", base.c_str());
|
||
|
|
std::printf(" catalog : %s\n", c.name.c_str());
|
||
|
|
std::printf(" glyphs : %zu\n", c.entries.size());
|
||
|
|
if (c.entries.empty()) return 0;
|
||
|
|
std::printf(" id type spell item classMask lvl name\n");
|
||
|
|
for (const auto& e : c.entries) {
|
||
|
|
std::printf(" %4u %-5s %5u %5u 0x%08x %3u %s\n",
|
||
|
|
e.glyphId,
|
||
|
|
wowee::pipeline::WoweeGlyph::glyphTypeName(e.glyphType),
|
||
|
|
e.spellId, e.itemId, e.classMask,
|
||
|
|
e.requiredLevel, 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 = stripWglyExt(base);
|
||
|
|
if (!wowee::pipeline::WoweeGlyphLoader::exists(base)) {
|
||
|
|
std::fprintf(stderr,
|
||
|
|
"validate-wgly: WGLY not found: %s.wgly\n", base.c_str());
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
auto c = wowee::pipeline::WoweeGlyphLoader::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;
|
||
|
|
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.glyphId);
|
||
|
|
if (!e.name.empty()) ctx += " " + e.name;
|
||
|
|
ctx += ")";
|
||
|
|
if (e.glyphId == 0)
|
||
|
|
errors.push_back(ctx + ": glyphId is 0");
|
||
|
|
if (e.name.empty())
|
||
|
|
errors.push_back(ctx + ": name is empty");
|
||
|
|
if (e.spellId == 0)
|
||
|
|
errors.push_back(ctx + ": spellId is 0 "
|
||
|
|
"(glyph applies no aura)");
|
||
|
|
if (e.glyphType > wowee::pipeline::WoweeGlyph::Prime) {
|
||
|
|
errors.push_back(ctx + ": glyphType " +
|
||
|
|
std::to_string(e.glyphType) + " not in 0..2");
|
||
|
|
}
|
||
|
|
if (e.classMask == 0) {
|
||
|
|
errors.push_back(ctx +
|
||
|
|
": classMask=0 (no class can use this glyph)");
|
||
|
|
}
|
||
|
|
if (e.itemId == 0) {
|
||
|
|
warnings.push_back(ctx + ": itemId=0 "
|
||
|
|
"(no inscribed item — glyph can't be taught)");
|
||
|
|
}
|
||
|
|
// WotLK glyphs unlock at character level 25 (minor),
|
||
|
|
// 50 (major), 70 (major), 80 (prime). Anything below
|
||
|
|
// 15 is suspicious.
|
||
|
|
if (e.requiredLevel != 0 && e.requiredLevel < 15) {
|
||
|
|
warnings.push_back(ctx + ": requiredLevel=" +
|
||
|
|
std::to_string(e.requiredLevel) +
|
||
|
|
" below WotLK glyph threshold (25)");
|
||
|
|
}
|
||
|
|
for (uint32_t prev : idsSeen) {
|
||
|
|
if (prev == e.glyphId) {
|
||
|
|
errors.push_back(ctx + ": duplicate glyphId");
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
idsSeen.push_back(e.glyphId);
|
||
|
|
}
|
||
|
|
bool ok = errors.empty();
|
||
|
|
if (jsonOut) {
|
||
|
|
nlohmann::json j;
|
||
|
|
j["wgly"] = base + ".wgly";
|
||
|
|
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-wgly: %s.wgly\n", base.c_str());
|
||
|
|
if (ok && warnings.empty()) {
|
||
|
|
std::printf(" OK — %zu glyphs, all glyphIds 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 handleGlyphsCatalog(int& i, int argc, char** argv, int& outRc) {
|
||
|
|
if (std::strcmp(argv[i], "--gen-glyphs") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleGenStarter(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--gen-glyphs-warrior") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleGenWarrior(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--gen-glyphs-universal") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleGenUniversal(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--info-wgly") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleInfo(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
if (std::strcmp(argv[i], "--validate-wgly") == 0 && i + 1 < argc) {
|
||
|
|
outRc = handleValidate(i, argc, argv); return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace cli
|
||
|
|
} // namespace editor
|
||
|
|
} // namespace wowee
|