From 104de8ffe68275d5b9f1ace775ae5e8038d1f79a Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 19:55:50 -0700 Subject: [PATCH] feat(editor): add WSET JSON round-trip (export/import sidecar) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes the JSON round-trip gap on the item set catalog format shipped this batch. --export-wset-json emits all 8 scalar fields plus two nested arrays — itemIds[] (only the populated slots) and bonuses[{threshold, spellId}] (only the populated bonus pairs). --import-wset-json derives pieceCount and bonusCount from the array sizes (the explicit count fields in the binary header are recomputed on import) and clears any trailing slots so a 5-piece PvP set imported from JSON correctly leaves slots 5-7 zero. requiredClassMask is dumped as a raw uint32 — users hand-edit using WCHC bit positions (Druid=0x800, Mage=0x100, Paladin=0x04 etc). Verified byte-identical round-trip on all three preset emitters (starter / tier / PvP — including the 5-piece PvP variant with 2/4-piece bonuses). 769 documented CLI flags. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + tools/editor/cli_item_sets_catalog.cpp | 136 +++++++++++++++++++++++++ 3 files changed, 141 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 931a6d14..787f5719 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -156,6 +156,7 @@ const char* const kArgRequired[] = { "--export-wceq-json", "--import-wceq-json", "--gen-itset", "--gen-itset-tier", "--gen-itset-pvp", "--info-wset", "--validate-wset", + "--export-wset-json", "--import-wset-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 21310426..bfb64e2d 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1451,6 +1451,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSET entries (id / pieces / bonuses / classMask / skill+rank gates / first item ID / name)\n"); std::printf(" --validate-wset [--json]\n"); std::printf(" Static checks: id+name+pieceCount required, piece/bonus arrays match counts, monotonic bonus thresholds within pieceCount\n"); + std::printf(" --export-wset-json [out.json]\n"); + std::printf(" Export binary .wset to a human-editable JSON sidecar with nested itemIds[] + bonuses[] arrays\n"); + std::printf(" --import-wset-json [out-base]\n"); + std::printf(" Import a .wset.json sidecar back into binary .wset (pieceCount/bonusCount derived from array sizes; missing slots cleared)\n"); std::printf(" --gen-weather-temperate [zoneName]\n"); std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n"); std::printf(" --gen-weather-arctic [zoneName]\n"); diff --git a/tools/editor/cli_item_sets_catalog.cpp b/tools/editor/cli_item_sets_catalog.cpp index 16fb96bc..96700033 100644 --- a/tools/editor/cli_item_sets_catalog.cpp +++ b/tools/editor/cli_item_sets_catalog.cpp @@ -137,6 +137,136 @@ 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 set emits all 8 scalar fields plus + // two nested arrays (itemIds[] and bonuses[{threshold, + // spellId}]) — only the populated slots are emitted to + // keep hand-edits compact. classMask is dumped as a raw + // integer; users can hand-edit using the bit positions + // documented in the WCHC catalog. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWsetExt(base); + if (outPath.empty()) outPath = base + ".wset.json"; + if (!wowee::pipeline::WoweeItemSetLoader::exists(base)) { + std::fprintf(stderr, + "export-wset-json: WSET not found: %s.wset\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeItemSetLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) appendEntryJson(arr, e); + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wset-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.wset\n", base.c_str()); + std::printf(" sets : %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 = ".wset.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 = stripWsetExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wset-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-wset-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + wowee::pipeline::WoweeItemSet c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeItemSet::Entry e; + e.setId = je.value("setId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.requiredClassMask = je.value("requiredClassMask", 0u); + e.requiredSkillId = static_cast( + je.value("requiredSkillId", 0)); + e.requiredSkillRank = static_cast( + je.value("requiredSkillRank", 0)); + // Items + bonuses are derived from array sizes — + // the explicit pieceCount / bonusCount fields in + // the binary header are redundant on import (the + // exporter emits them so info dumps stay + // self-consistent, but on import we recompute). + for (size_t k = 0; + k < wowee::pipeline::WoweeItemSet::kMaxPieces; ++k) { + e.itemIds[k] = 0; + } + for (size_t k = 0; + k < wowee::pipeline::WoweeItemSet::kMaxBonuses; ++k) { + e.bonusThresholds[k] = 0; + e.bonusSpellIds[k] = 0; + } + if (je.contains("itemIds") && je["itemIds"].is_array()) { + size_t slot = 0; + for (const auto& ji : je["itemIds"]) { + if (slot >= wowee::pipeline::WoweeItemSet::kMaxPieces) + break; + e.itemIds[slot++] = ji.get(); + } + e.pieceCount = static_cast(slot); + } + if (je.contains("bonuses") && je["bonuses"].is_array()) { + size_t slot = 0; + for (const auto& jb : je["bonuses"]) { + if (slot >= wowee::pipeline::WoweeItemSet::kMaxBonuses) + break; + e.bonusThresholds[slot] = static_cast( + jb.value("threshold", 0)); + e.bonusSpellIds[slot] = jb.value("spellId", 0u); + ++slot; + } + e.bonusCount = static_cast(slot); + } + c.entries.push_back(e); + } + } + if (!wowee::pipeline::WoweeItemSetLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wset-json: failed to save %s.wset\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wset\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" sets : %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); @@ -285,6 +415,12 @@ bool handleItemSetsCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wset") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wset-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wset-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }