From a7057393eb7d1312df63e6203385c9815c87170b Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 23:00:32 -0700 Subject: [PATCH] feat(editor): add WIQR JSON round-trip (--export/--import-wiqr-json) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes the editing loop on the item-quality catalog: dump a .wiqr to JSON, hand-edit color hex / vendor multiplier / level gates / disenchant flag / border texture path (e.g. retune Epic purple from #a335ee to #c33fff for a brighter look, raise Heirloom unlock from lvl 80 to 85, mark Legendary as disenchantable, swap a server-custom tier's border texture), re-import to a byte-identical binary. The colors export as raw RGBA uint32 — direct pasting of 0xAARRGGBB hex values without conversion. canBeDisenchanted round-trips as a JSON bool but accepts int as well so machine- generated sidecars work too. Verified byte-identical round-trip on all three presets (std / srv / raid). CLI flag count 1008 -> 1010. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + tools/editor/cli_item_qualities_catalog.cpp | 122 ++++++++++++++++++++ 3 files changed, 127 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 18c39c30..c1f8edea 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -259,6 +259,7 @@ const char* const kArgRequired[] = { "--export-waur-json", "--import-waur-json", "--gen-iqr", "--gen-iqr-server", "--gen-iqr-raid", "--info-wiqr", "--validate-wiqr", + "--export-wiqr-json", "--import-wiqr-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 a9efcdb7..8dea4b41 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1933,6 +1933,10 @@ void printUsage(const char* argv0) { std::printf(" Print WIQR entries (id / name / nameColor RGBA / vendor multiplier / minLevel / maxLevel / disenchant flag / border texture)\n"); std::printf(" --validate-wiqr [--json]\n"); std::printf(" Static checks: name required, no duplicate ids, vendor>=0, min<=max; warns on lvl>80 (unreachable), vendor>100x (sanity), alpha=0 nameColor (invisible)\n"); + std::printf(" --export-wiqr-json [out.json]\n"); + std::printf(" Export binary .wiqr to a human-editable JSON sidecar (defaults to .wiqr.json). Colors as RGBA uint32, easy to paste hex values\n"); + std::printf(" --import-wiqr-json [out-base]\n"); + std::printf(" Import a .wiqr.json sidecar back into binary .wiqr (canBeDisenchanted accepts bool OR int)\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_qualities_catalog.cpp b/tools/editor/cli_item_qualities_catalog.cpp index be2bc26c..667bd0b3 100644 --- a/tools/editor/cli_item_qualities_catalog.cpp +++ b/tools/editor/cli_item_qualities_catalog.cpp @@ -123,6 +123,122 @@ 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 = stripWiqrExt(base); + if (!wowee::pipeline::WoweeItemQualityLoader::exists(base)) { + std::fprintf(stderr, + "export-wiqr-json: WIQR not found: %s.wiqr\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeItemQualityLoader::load(base); + if (outPath.empty()) outPath = base + ".wiqr.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["qualityId"] = e.qualityId; + je["name"] = e.name; + je["description"] = e.description; + je["nameColorRGBA"] = e.nameColorRGBA; + je["borderColorRGBA"] = e.borderColorRGBA; + je["vendorPriceMultiplier"] = e.vendorPriceMultiplier; + je["minLevelToDrop"] = e.minLevelToDrop; + je["maxLevelToDrop"] = e.maxLevelToDrop; + je["canBeDisenchanted"] = e.canBeDisenchanted != 0; + je["inventoryBorderTexture"] = e.inventoryBorderTexture; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wiqr-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(" tiers : %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]; + std::ifstream is(jsonPath); + if (!is) { + std::fprintf(stderr, + "import-wiqr-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-wiqr-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeItemQuality c; + if (j.contains("catalog") && j["catalog"].is_string()) + c.name = j["catalog"].get(); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeItemQuality::Entry e; + if (je.contains("qualityId")) e.qualityId = je["qualityId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("nameColorRGBA")) e.nameColorRGBA = je["nameColorRGBA"].get(); + if (je.contains("borderColorRGBA")) e.borderColorRGBA = je["borderColorRGBA"].get(); + if (je.contains("vendorPriceMultiplier")) e.vendorPriceMultiplier = je["vendorPriceMultiplier"].get(); + if (je.contains("minLevelToDrop")) e.minLevelToDrop = je["minLevelToDrop"].get(); + if (je.contains("maxLevelToDrop")) e.maxLevelToDrop = je["maxLevelToDrop"].get(); + if (je.contains("canBeDisenchanted")) { + if (je["canBeDisenchanted"].is_boolean()) + e.canBeDisenchanted = je["canBeDisenchanted"].get() ? 1 : 0; + else + e.canBeDisenchanted = je["canBeDisenchanted"].get() ? 1 : 0; + } + if (je.contains("inventoryBorderTexture")) + e.inventoryBorderTexture = je["inventoryBorderTexture"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wiqr.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 = stripWiqrExt(outBase); + if (!wowee::pipeline::WoweeItemQualityLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wiqr-json: failed to save %s.wiqr\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wiqr\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" tiers : %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); @@ -234,6 +350,12 @@ bool handleItemQualitiesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wiqr") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wiqr-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wiqr-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }