mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WGFS JSON round-trip (--export/--import-wgfs-json)
Closes the editing loop on the glyph-slot catalog: dump a .wgfs
to JSON, hand-edit slotKind / displayOrder / minLevelToUnlock /
requiredClassMask (e.g. add a fourth Major slot, lower a Minor
slot's unlock from 75 to 70, restrict a Prime slot to Mages
only), re-import to a byte-identical binary.
The exporter emits both slotKind (int 0..2) and the human-
readable slotKindName ("major", "minor", "prime"); the importer
accepts either form.
Verified byte-identical round-trip on all three presets
(starter / wotlk / cata). CLI flag count 934 -> 936.
This commit is contained in:
parent
48c770f5ea
commit
ea173d6ff8
3 changed files with 147 additions and 0 deletions
|
|
@ -227,6 +227,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wspc-json", "--import-wspc-json",
|
||||
"--gen-gfs", "--gen-gfs-wotlk", "--gen-gfs-cata",
|
||||
"--info-wgfs", "--validate-wgfs",
|
||||
"--export-wgfs-json", "--import-wgfs-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "pipeline/wowee_glyph_slots.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
|
@ -122,6 +123,141 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int handleExportJson(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string outPath;
|
||||
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
|
||||
base = stripWgfsExt(base);
|
||||
if (!wowee::pipeline::WoweeGlyphSlotLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wgfs-json: WGFS not found: %s.wgfs\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeGlyphSlotLoader::load(base);
|
||||
if (outPath.empty()) outPath = base + ".wgfs.json";
|
||||
nlohmann::json j;
|
||||
j["catalog"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
nlohmann::json je;
|
||||
je["slotId"] = e.slotId;
|
||||
je["name"] = e.name;
|
||||
je["description"] = e.description;
|
||||
je["slotKind"] = e.slotKind;
|
||||
je["slotKindName"] =
|
||||
wowee::pipeline::WoweeGlyphSlot::slotKindName(e.slotKind);
|
||||
je["displayOrder"] = e.displayOrder;
|
||||
je["minLevelToUnlock"] = e.minLevelToUnlock;
|
||||
je["requiredClassMask"] = e.requiredClassMask;
|
||||
je["iconColorRGBA"] = e.iconColorRGBA;
|
||||
arr.push_back(je);
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(outPath);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wgfs-json: failed to open %s for write\n",
|
||||
outPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s\n", outPath.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" slots : %zu\n", c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t parseSlotKindToken(const nlohmann::json& jv,
|
||||
uint8_t fallback) {
|
||||
if (jv.is_number_integer() || jv.is_number_unsigned()) {
|
||||
int v = jv.get<int>();
|
||||
if (v < 0 || v > wowee::pipeline::WoweeGlyphSlot::Prime)
|
||||
return fallback;
|
||||
return static_cast<uint8_t>(v);
|
||||
}
|
||||
if (jv.is_string()) {
|
||||
std::string s = jv.get<std::string>();
|
||||
for (auto& ch : s) ch = static_cast<char>(std::tolower(ch));
|
||||
if (s == "major") return wowee::pipeline::WoweeGlyphSlot::Major;
|
||||
if (s == "minor") return wowee::pipeline::WoweeGlyphSlot::Minor;
|
||||
if (s == "prime") return wowee::pipeline::WoweeGlyphSlot::Prime;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
int handleImportJson(int& i, int argc, char** argv) {
|
||||
std::string jsonPath = argv[++i];
|
||||
std::string outBase;
|
||||
if (parseOptArg(i, argc, argv)) outBase = argv[++i];
|
||||
std::ifstream is(jsonPath);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgfs-json: failed to open %s\n", jsonPath.c_str());
|
||||
return 1;
|
||||
}
|
||||
nlohmann::json j;
|
||||
try {
|
||||
is >> j;
|
||||
} catch (const std::exception& ex) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgfs-json: parse error in %s: %s\n",
|
||||
jsonPath.c_str(), ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeGlyphSlot c;
|
||||
if (j.contains("catalog") && j["catalog"].is_string())
|
||||
c.name = j["catalog"].get<std::string>();
|
||||
if (j.contains("entries") && j["entries"].is_array()) {
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeGlyphSlot::Entry e;
|
||||
if (je.contains("slotId")) e.slotId = je["slotId"].get<uint32_t>();
|
||||
if (je.contains("name")) e.name = je["name"].get<std::string>();
|
||||
if (je.contains("description")) e.description = je["description"].get<std::string>();
|
||||
uint8_t kind = wowee::pipeline::WoweeGlyphSlot::Major;
|
||||
if (je.contains("slotKind"))
|
||||
kind = parseSlotKindToken(je["slotKind"], kind);
|
||||
else if (je.contains("slotKindName"))
|
||||
kind = parseSlotKindToken(je["slotKindName"], kind);
|
||||
e.slotKind = kind;
|
||||
if (je.contains("displayOrder"))
|
||||
e.displayOrder = je["displayOrder"].get<uint8_t>();
|
||||
if (je.contains("minLevelToUnlock"))
|
||||
e.minLevelToUnlock = je["minLevelToUnlock"].get<uint8_t>();
|
||||
if (je.contains("requiredClassMask"))
|
||||
e.requiredClassMask = je["requiredClassMask"].get<uint32_t>();
|
||||
if (je.contains("iconColorRGBA"))
|
||||
e.iconColorRGBA = je["iconColorRGBA"].get<uint32_t>();
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
}
|
||||
if (outBase.empty()) {
|
||||
outBase = jsonPath;
|
||||
const std::string suffix1 = ".wgfs.json";
|
||||
const std::string suffix2 = ".json";
|
||||
if (outBase.size() >= suffix1.size() &&
|
||||
outBase.compare(outBase.size() - suffix1.size(),
|
||||
suffix1.size(), suffix1) == 0) {
|
||||
outBase.resize(outBase.size() - suffix1.size());
|
||||
} else if (outBase.size() >= suffix2.size() &&
|
||||
outBase.compare(outBase.size() - suffix2.size(),
|
||||
suffix2.size(), suffix2) == 0) {
|
||||
outBase.resize(outBase.size() - suffix2.size());
|
||||
}
|
||||
}
|
||||
outBase = stripWgfsExt(outBase);
|
||||
if (!wowee::pipeline::WoweeGlyphSlotLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgfs-json: failed to save %s.wgfs\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wgfs\n", outBase.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" slots : %zu\n", c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleValidate(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
|
|
@ -246,6 +382,12 @@ bool handleGlyphSlotsCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wgfs") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wgfs-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wgfs-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1785,6 +1785,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WGFS entries (id / kind / displayOrder / minLevelToUnlock / classMask / name)\n");
|
||||
std::printf(" --validate-wgfs <wgfs-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name+classMask required, slotKind 0..2, no duplicate ids; warns on lvl>80, displayOrder>4, and (kind+order) collisions for overlapping classMask\n");
|
||||
std::printf(" --export-wgfs-json <wgfs-base> [out.json]\n");
|
||||
std::printf(" Export binary .wgfs to a human-editable JSON sidecar (defaults to <base>.wgfs.json)\n");
|
||||
std::printf(" --import-wgfs-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wgfs.json sidecar back into binary .wgfs (accepts slotKind int OR slotKindName string)\n");
|
||||
std::printf(" --gen-weather-temperate <wow-base> [zoneName]\n");
|
||||
std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n");
|
||||
std::printf(" --gen-weather-arctic <wow-base> [zoneName]\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue