diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 54e096da..db36ce76 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -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", diff --git a/tools/editor/cli_glyph_slots_catalog.cpp b/tools/editor/cli_glyph_slots_catalog.cpp index eb824fff..3d1d257d 100644 --- a/tools/editor/cli_glyph_slots_catalog.cpp +++ b/tools/editor/cli_glyph_slots_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_glyph_slots.hpp" #include +#include #include #include #include @@ -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(); + if (v < 0 || v > wowee::pipeline::WoweeGlyphSlot::Prime) + return fallback; + return static_cast(v); + } + if (jv.is_string()) { + std::string s = jv.get(); + for (auto& ch : s) ch = static_cast(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(); + 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(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + 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(); + if (je.contains("minLevelToUnlock")) + e.minLevelToUnlock = je["minLevelToUnlock"].get(); + if (je.contains("requiredClassMask")) + e.requiredClassMask = je["requiredClassMask"].get(); + if (je.contains("iconColorRGBA")) + e.iconColorRGBA = je["iconColorRGBA"].get(); + 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; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index d9e11e54..8ad1d7fe 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -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 [--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 [out.json]\n"); + std::printf(" Export binary .wgfs to a human-editable JSON sidecar (defaults to .wgfs.json)\n"); + std::printf(" --import-wgfs-json [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 [zoneName]\n"); std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n"); std::printf(" --gen-weather-arctic [zoneName]\n");