diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index dfb939e1..82ebc24b 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -290,6 +290,7 @@ const char* const kArgRequired[] = { "--export-wstc-json", "--import-wstc-json", "--gen-stm", "--gen-stm-regen", "--gen-stm-armor", "--info-wstm", "--validate-wstm", + "--export-wstm-json", "--import-wstm-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 b8543713..b36b4f1d 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2079,6 +2079,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSTM entries (id / kind / minLvl / maxLvl / baseValue / perLevelDelta / multiplier / value@lvl80 sample / name)\n"); std::printf(" --validate-wstm [--json]\n"); std::printf(" Static checks: id+name required, curveKind 0..6, minLevel<=maxLevel, no duplicate ids; warns on maxLevel>80, multiplier=0 (always 0), multiplier<0 (inverts), perLevelDelta<0 (shrinks)\n"); + std::printf(" --export-wstm-json [out.json]\n"); + std::printf(" Export binary .wstm to a human-editable JSON sidecar (defaults to .wstm.json)\n"); + std::printf(" --import-wstm-json [out-base]\n"); + std::printf(" Import a .wstm.json sidecar back into binary .wstm (accepts curveKind int OR curveKindName 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_stat_curves_catalog.cpp b/tools/editor/cli_stat_curves_catalog.cpp index 31ead132..4b319cc8 100644 --- a/tools/editor/cli_stat_curves_catalog.cpp +++ b/tools/editor/cli_stat_curves_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_stat_curves.hpp" #include +#include #include #include #include @@ -125,6 +126,144 @@ 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 = stripWstmExt(base); + if (!wowee::pipeline::WoweeStatCurveLoader::exists(base)) { + std::fprintf(stderr, + "export-wstm-json: WSTM not found: %s.wstm\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeStatCurveLoader::load(base); + if (outPath.empty()) outPath = base + ".wstm.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["curveId"] = e.curveId; + je["name"] = e.name; + je["description"] = e.description; + je["curveKind"] = e.curveKind; + je["curveKindName"] = + wowee::pipeline::WoweeStatCurve::curveKindName(e.curveKind); + je["minLevel"] = e.minLevel; + je["maxLevel"] = e.maxLevel; + je["baseValue"] = e.baseValue; + je["perLevelDelta"] = e.perLevelDelta; + je["multiplier"] = e.multiplier; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wstm-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(" curves : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseCurveKindToken(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::WoweeStatCurve::Misc) + 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 == "crit") return wowee::pipeline::WoweeStatCurve::Crit; + if (s == "hit") return wowee::pipeline::WoweeStatCurve::Hit; + if (s == "power") return wowee::pipeline::WoweeStatCurve::Power; + if (s == "regen") return wowee::pipeline::WoweeStatCurve::Regen; + if (s == "resist") return wowee::pipeline::WoweeStatCurve::Resist; + if (s == "mitigation") return wowee::pipeline::WoweeStatCurve::Mitigation; + if (s == "misc") return wowee::pipeline::WoweeStatCurve::Misc; + } + 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-wstm-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-wstm-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeStatCurve 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::WoweeStatCurve::Entry e; + if (je.contains("curveId")) e.curveId = je["curveId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + uint8_t kind = wowee::pipeline::WoweeStatCurve::Misc; + if (je.contains("curveKind")) + kind = parseCurveKindToken(je["curveKind"], kind); + else if (je.contains("curveKindName")) + kind = parseCurveKindToken(je["curveKindName"], kind); + e.curveKind = kind; + if (je.contains("minLevel")) e.minLevel = je["minLevel"].get(); + if (je.contains("maxLevel")) e.maxLevel = je["maxLevel"].get(); + if (je.contains("baseValue")) e.baseValue = je["baseValue"].get(); + if (je.contains("perLevelDelta")) e.perLevelDelta = je["perLevelDelta"].get(); + if (je.contains("multiplier")) e.multiplier = je["multiplier"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wstm.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 = stripWstmExt(outBase); + if (!wowee::pipeline::WoweeStatCurveLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wstm-json: failed to save %s.wstm\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wstm\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" curves : %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); @@ -236,6 +375,12 @@ bool handleStatCurvesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wstm") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wstm-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wstm-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }