diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index b0bbce82..2a5e6cd8 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -211,6 +211,7 @@ const char* const kArgRequired[] = { "--export-wsrg-json", "--import-wsrg-json", "--gen-sct", "--gen-sct-channel", "--gen-sct-ramp", "--info-wsct", "--validate-wsct", + "--export-wsct-json", "--import-wsct-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 197a01a4..f4b24066 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1711,6 +1711,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSCT entries (id / kind / baseMs / perLevelMs / minMs / maxMs / iconColor / name)\n"); std::printf(" --validate-wsct [--json]\n"); std::printf(" Static checks: id+name required, castKind 0..4, baseMs>=0, min<=max, no duplicate ids; warns on Instant+nonzero base, errors on Channel+0 base\n"); + std::printf(" --export-wsct-json [out.json]\n"); + std::printf(" Export binary .wsct to a human-editable JSON sidecar (defaults to .wsct.json)\n"); + std::printf(" --import-wsct-json [out-base]\n"); + std::printf(" Import a .wsct.json sidecar back into binary .wsct (accepts castKind int OR castKindName 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"); diff --git a/tools/editor/cli_spell_cast_times_catalog.cpp b/tools/editor/cli_spell_cast_times_catalog.cpp index 7c1c6638..3886ad16 100644 --- a/tools/editor/cli_spell_cast_times_catalog.cpp +++ b/tools/editor/cli_spell_cast_times_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_spell_cast_times.hpp" #include +#include #include #include #include @@ -122,6 +123,143 @@ 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 = stripWsctExt(base); + if (!wowee::pipeline::WoweeSpellCastTimeLoader::exists(base)) { + std::fprintf(stderr, + "export-wsct-json: WSCT not found: %s.wsct\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeSpellCastTimeLoader::load(base); + if (outPath.empty()) outPath = base + ".wsct.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["castTimeId"] = e.castTimeId; + je["name"] = e.name; + je["description"] = e.description; + je["castKind"] = e.castKind; + je["castKindName"] = + wowee::pipeline::WoweeSpellCastTime::castKindName(e.castKind); + je["baseCastMs"] = e.baseCastMs; + je["perLevelMs"] = e.perLevelMs; + je["minCastMs"] = e.minCastMs; + je["maxCastMs"] = e.maxCastMs; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wsct-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(" buckets : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseCastKindToken(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::WoweeSpellCastTime::ChargeCast) + 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 == "instant") return wowee::pipeline::WoweeSpellCastTime::Instant; + if (s == "cast") return wowee::pipeline::WoweeSpellCastTime::Cast; + if (s == "channel") return wowee::pipeline::WoweeSpellCastTime::Channel; + if (s == "delayed" || + s == "delayedcast") return wowee::pipeline::WoweeSpellCastTime::DelayedCast; + if (s == "charge" || + s == "chargecast") return wowee::pipeline::WoweeSpellCastTime::ChargeCast; + } + 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-wsct-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-wsct-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeSpellCastTime 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::WoweeSpellCastTime::Entry e; + if (je.contains("castTimeId")) e.castTimeId = je["castTimeId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + uint8_t kind = wowee::pipeline::WoweeSpellCastTime::Cast; + if (je.contains("castKind")) + kind = parseCastKindToken(je["castKind"], kind); + else if (je.contains("castKindName")) + kind = parseCastKindToken(je["castKindName"], kind); + e.castKind = kind; + if (je.contains("baseCastMs")) e.baseCastMs = je["baseCastMs"].get(); + if (je.contains("perLevelMs")) e.perLevelMs = je["perLevelMs"].get(); + if (je.contains("minCastMs")) e.minCastMs = je["minCastMs"].get(); + if (je.contains("maxCastMs")) e.maxCastMs = je["maxCastMs"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wsct.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 = stripWsctExt(outBase); + if (!wowee::pipeline::WoweeSpellCastTimeLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wsct-json: failed to save %s.wsct\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wsct\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" buckets : %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); @@ -237,6 +375,12 @@ bool handleSpellCastTimesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wsct") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wsct-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wsct-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }