diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 529ba338..79e64798 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -287,6 +287,7 @@ const char* const kArgRequired[] = { "--export-whld-json", "--import-whld-json", "--gen-stc", "--gen-stc-cata", "--gen-stc-premium", "--info-wstc", "--validate-wstc", + "--export-wstc-json", "--import-wstc-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 842ed69a..43524ec1 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2065,6 +2065,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSTC entries (id / displayOrder / minLevelToUnlock / cost (formatted) / premium flag / name)\n"); std::printf(" --validate-wstc [--json]\n"); std::printf(" Static checks: id+name required, no duplicate ids; warns on lvl>80 (unreachable), Premium+nonzero cost (donor slots are free), duplicate displayOrder (UI collision)\n"); + std::printf(" --export-wstc-json [out.json]\n"); + std::printf(" Export binary .wstc to a human-editable JSON sidecar (defaults to .wstc.json)\n"); + std::printf(" --import-wstc-json [out-base]\n"); + std::printf(" Import a .wstc.json sidecar back into binary .wstc (isPremium 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_stable_slots_catalog.cpp b/tools/editor/cli_stable_slots_catalog.cpp index 05f71bfb..a9fa6927 100644 --- a/tools/editor/cli_stable_slots_catalog.cpp +++ b/tools/editor/cli_stable_slots_catalog.cpp @@ -130,6 +130,117 @@ 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 = stripWstcExt(base); + if (!wowee::pipeline::WoweeStableSlotLoader::exists(base)) { + std::fprintf(stderr, + "export-wstc-json: WSTC not found: %s.wstc\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeStableSlotLoader::load(base); + if (outPath.empty()) outPath = base + ".wstc.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["displayOrder"] = e.displayOrder; + je["minLevelToUnlock"] = e.minLevelToUnlock; + je["isPremium"] = e.isPremium != 0; + je["copperCost"] = e.copperCost; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wstc-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; +} + +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-wstc-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-wstc-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeStableSlot 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::WoweeStableSlot::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(); + if (je.contains("displayOrder")) e.displayOrder = je["displayOrder"].get(); + if (je.contains("minLevelToUnlock")) e.minLevelToUnlock = je["minLevelToUnlock"].get(); + if (je.contains("isPremium")) { + if (je["isPremium"].is_boolean()) + e.isPremium = je["isPremium"].get() ? 1 : 0; + else + e.isPremium = je["isPremium"].get() ? 1 : 0; + } + if (je.contains("copperCost")) e.copperCost = je["copperCost"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wstc.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 = stripWstcExt(outBase); + if (!wowee::pipeline::WoweeStableSlotLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wstc-json: failed to save %s.wstc\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wstc\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); @@ -241,6 +352,12 @@ bool handleStableSlotsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wstc") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wstc-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wstc-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }