mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 02:53:51 +00:00
feat(editor): add WCEQ JSON round-trip (export/import sidecar)
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
Some checks are pending
Build / Build (arm64) (push) Waiting to run
Build / Build (x86-64) (push) Waiting to run
Build / Build (macOS arm64) (push) Waiting to run
Build / Build (windows-arm64) (push) Waiting to run
Build / Build (windows-x86-64) (push) Waiting to run
Security / CodeQL (C/C++) (push) Waiting to run
Security / Semgrep (push) Waiting to run
Security / Sanitizer Build (ASan/UBSan) (push) Waiting to run
Closes the JSON round-trip gap on the creature equipment catalog format shipped last batch (50th open format). All fields are scalar — no enum widening — so the JSON mapping is a direct dump. Slot fields default to the canonical attachment-table values (mainhand=16, offhand=17, ranged=18) when omitted from a sidecar, so hand-edits don't need to spell out the slot numbers for typical loadouts. Verified byte-identical round-trip on all three preset emitters (starter / bosses / ranged). 762 documented CLI flags.
This commit is contained in:
parent
71d504822b
commit
f8058e3261
3 changed files with 129 additions and 0 deletions
|
|
@ -153,6 +153,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wtsk-json", "--import-wtsk-json",
|
||||
"--gen-ceq", "--gen-ceq-bosses", "--gen-ceq-ranged",
|
||||
"--info-wceq", "--validate-wceq",
|
||||
"--export-wceq-json", "--import-wceq-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -123,6 +123,124 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int handleExportJson(int& i, int argc, char** argv) {
|
||||
// Mirrors the JSON pairs added for every other novel
|
||||
// open format. Each loadout emits all 11 scalar fields —
|
||||
// no enum widening needed (all fields are raw numerics
|
||||
// or item ID cross-refs to other catalogs).
|
||||
std::string base = argv[++i];
|
||||
std::string outPath;
|
||||
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
|
||||
base = stripWceqExt(base);
|
||||
if (outPath.empty()) outPath = base + ".wceq.json";
|
||||
if (!wowee::pipeline::WoweeCreatureEquipmentLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wceq-json: WCEQ not found: %s.wceq\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeCreatureEquipmentLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"equipmentId", e.equipmentId},
|
||||
{"creatureId", e.creatureId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"mainHandItemId", e.mainHandItemId},
|
||||
{"offHandItemId", e.offHandItemId},
|
||||
{"rangedItemId", e.rangedItemId},
|
||||
{"mainHandSlot", e.mainHandSlot},
|
||||
{"offHandSlot", e.offHandSlot},
|
||||
{"rangedSlot", e.rangedSlot},
|
||||
{"equipFlags", e.equipFlags},
|
||||
{"mainHandVisualId", e.mainHandVisualId},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream out(outPath);
|
||||
if (!out) {
|
||||
std::fprintf(stderr,
|
||||
"export-wceq-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.wceq\n", base.c_str());
|
||||
std::printf(" loadouts : %zu\n", c.entries.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 = ".wceq.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 = stripWceqExt(outBase);
|
||||
std::ifstream in(jsonPath);
|
||||
if (!in) {
|
||||
std::fprintf(stderr,
|
||||
"import-wceq-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-wceq-json: bad JSON in %s: %s\n",
|
||||
jsonPath.c_str(), e.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeCreatureEquipment c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (j.contains("entries") && j["entries"].is_array()) {
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeCreatureEquipment::Entry e;
|
||||
e.equipmentId = je.value("equipmentId", 0u);
|
||||
e.creatureId = je.value("creatureId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
e.mainHandItemId = je.value("mainHandItemId", 0u);
|
||||
e.offHandItemId = je.value("offHandItemId", 0u);
|
||||
e.rangedItemId = je.value("rangedItemId", 0u);
|
||||
// Slot defaults match the canonical attachment table
|
||||
// (mainhand=16, offhand=17, ranged=18) so a sidecar
|
||||
// that omits these fields still produces sensible
|
||||
// binaries.
|
||||
e.mainHandSlot = static_cast<uint8_t>(je.value("mainHandSlot",
|
||||
wowee::pipeline::WoweeCreatureEquipment::kSlotMainHand));
|
||||
e.offHandSlot = static_cast<uint8_t>(je.value("offHandSlot",
|
||||
wowee::pipeline::WoweeCreatureEquipment::kSlotOffHand));
|
||||
e.rangedSlot = static_cast<uint8_t>(je.value("rangedSlot",
|
||||
wowee::pipeline::WoweeCreatureEquipment::kSlotRanged));
|
||||
e.equipFlags = static_cast<uint8_t>(je.value("equipFlags", 0));
|
||||
e.mainHandVisualId = je.value("mainHandVisualId", 0u);
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
}
|
||||
if (!wowee::pipeline::WoweeCreatureEquipmentLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wceq-json: failed to save %s.wceq\n", outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wceq\n", outBase.c_str());
|
||||
std::printf(" source : %s\n", jsonPath.c_str());
|
||||
std::printf(" loadouts : %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);
|
||||
|
|
@ -252,6 +370,12 @@ bool handleCreatureEquipmentCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wceq") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wceq-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wceq-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1437,6 +1437,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WCEQ entries (id / creatureId / mainhand+offhand+ranged item IDs / equipFlags / visualKitId / name)\n");
|
||||
std::printf(" --validate-wceq <wceq-base> [--json]\n");
|
||||
std::printf(" Static checks: id+creatureId>0+unique, dual-wield/shield/2H polearm flag coherence, mutually-exclusive flag combos\n");
|
||||
std::printf(" --export-wceq-json <wceq-base> [out.json]\n");
|
||||
std::printf(" Export binary .wceq to a human-editable JSON sidecar (defaults to <base>.wceq.json)\n");
|
||||
std::printf(" --import-wceq-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wceq.json sidecar back into binary .wceq (slot fields default to canonical 16/17/18 if omitted)\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