From 31b9b55ebd6a42a9a6d54e57fe1495fabdda6d02 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 10 May 2026 00:22:14 -0700 Subject: [PATCH] feat(editor): add WGRP JSON round-trip (--export/--import-wgrp-json) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JSON sidecar with sizeCategory derived string ("5man" / "10man" / "25man" / "40man" / "custom") added on export for human readability. sizeCategory is purely informational — the round-trip is driven by maxPartySize itself; the import handler ignores sizeCategory so users can edit maxPartySize freely without keeping the two in sync. requireSpec accepts both bool and int on import for JSON-edit ergonomics. All 3 presets (5-man/raid10/raid25) byte-identical roundtrip OK. CLI flag count 1095 -> 1097. --- tools/editor/cli_arg_required.cpp | 1 + .../editor/cli_group_compositions_catalog.cpp | 144 ++++++++++++++++++ tools/editor/cli_help.cpp | 4 + 3 files changed, 149 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index f0b83521..a30a6f69 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -296,6 +296,7 @@ const char* const kArgRequired[] = { "--export-wact-json", "--import-wact-json", "--gen-grp", "--gen-grp-raid10", "--gen-grp-raid25", "--info-wgrp", "--validate-wgrp", + "--export-wgrp-json", "--import-wgrp-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_group_compositions_catalog.cpp b/tools/editor/cli_group_compositions_catalog.cpp index 3b65c78e..ecc0fef0 100644 --- a/tools/editor/cli_group_compositions_catalog.cpp +++ b/tools/editor/cli_group_compositions_catalog.cpp @@ -125,6 +125,144 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +// "5man"/"10man"/"25man"/"40man" form derived from +// maxPartySize for human-readable JSON. Round-trip is +// driven by maxPartySize itself; sizeCategory is purely +// informational on export and ignored on import. +const char* sizeCategoryName(uint8_t maxParty) { + switch (maxParty) { + case 5: return "5man"; + case 10: return "10man"; + case 25: return "25man"; + case 40: return "40man"; + default: return "custom"; + } +} + +int handleExportJson(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string out; + if (parseOptArg(i, argc, argv)) out = argv[++i]; + base = stripWgrpExt(base); + if (out.empty()) out = base + ".wgrp.json"; + if (!wowee::pipeline::WoweeGroupCompositionLoader::exists(base)) { + std::fprintf(stderr, + "export-wgrp-json: WGRP not found: %s.wgrp\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeGroupCompositionLoader::load(base); + nlohmann::json j; + j["magic"] = "WGRP"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"compId", e.compId}, + {"name", e.name}, + {"description", e.description}, + {"mapId", e.mapId}, + {"difficultyId", e.difficultyId}, + {"requiredTanks", e.requiredTanks}, + {"requiredHealers", e.requiredHealers}, + {"requiredDamageDealers", e.requiredDamageDealers}, + {"minPartySize", e.minPartySize}, + {"maxPartySize", e.maxPartySize}, + {"sizeCategory", sizeCategoryName(e.maxPartySize)}, + {"requireSpec", e.requireSpec != 0}, + {"iconColorRGBA", e.iconColorRGBA}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wgrp-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu compositions)\n", + out.c_str(), c.entries.size()); + return 0; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string in = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + if (outBase.empty()) { + outBase = in; + if (outBase.size() >= 10 && + outBase.substr(outBase.size() - 10) == ".wgrp.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wgrp"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wgrp-json: cannot open %s\n", in.c_str()); + return 1; + } + nlohmann::json j; + try { + is >> j; + } catch (const std::exception& ex) { + std::fprintf(stderr, + "import-wgrp-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeGroupComposition c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wgrp-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeGroupComposition::Entry e; + e.compId = je.value("compId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.mapId = je.value("mapId", 0u); + e.difficultyId = je.value("difficultyId", 0u); + e.requiredTanks = static_cast( + je.value("requiredTanks", 0u)); + e.requiredHealers = static_cast( + je.value("requiredHealers", 0u)); + e.requiredDamageDealers = static_cast( + je.value("requiredDamageDealers", 0u)); + e.minPartySize = static_cast( + je.value("minPartySize", 5u)); + e.maxPartySize = static_cast( + je.value("maxPartySize", 5u)); + // requireSpec accepts bool OR int. + if (je.contains("requireSpec")) { + const auto& rs = je["requireSpec"]; + if (rs.is_boolean()) + e.requireSpec = rs.get() ? 1 : 0; + else if (rs.is_number_integer()) + e.requireSpec = static_cast( + rs.get() != 0 ? 1 : 0); + } + e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeGroupCompositionLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wgrp-json: failed to save %s.wgrp\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wgrp (%zu compositions)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -250,6 +388,12 @@ bool handleGroupCompositionsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wgrp") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wgrp-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wgrp-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 637ca3e3..64100633 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2107,6 +2107,10 @@ void printUsage(const char* argv0) { std::printf(" Print WGRP entries (id / map / diff / required tanks/heals/dps / min/max party / spec gate / name)\n"); std::printf(" --validate-wgrp \n"); std::printf(" Static checks: id+name+mapId required, min<=max, role sum<=maxParty (else unfulfillable), no duplicate ids; warns on non-standard size, role sum [out.json]\n"); + std::printf(" Export binary .wgrp to a human-editable JSON sidecar (defaults to .wgrp.json; sizeCategory string is informational, ignored on import)\n"); + std::printf(" --import-wgrp-json [out-base]\n"); + std::printf(" Import a .wgrp.json sidecar back into binary .wgrp (requireSpec 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");