From 7d7e1d73dc81c9fad9ca35910803eaed7a4c0708 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 23:05:23 -0700 Subject: [PATCH] feat(editor): add WSCS JSON round-trip (--export/--import-wscs-json) Closes the editing loop on the skill-cost catalog: dump a .wscs to JSON, hand-edit costKind / skill ranges / requiredLevel / copperCost (e.g. retune Apprentice profession from 1s to 5s for a faster server, raise Cold Weather Flying from lvl 77 to 75, add a custom WeaponSkill tier above Master), re-import to a byte-identical binary. The exporter emits both costKind (int 0..4) and the human- readable costKindName ("profession" / "weapon" / "riding" / "class-skill" / "misc"); the importer accepts either form. Verified byte-identical round-trip on all three presets (prof / weapon / riding). CLI flag count 1015 -> 1017. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + tools/editor/cli_skill_costs_catalog.cpp | 147 +++++++++++++++++++++++ 3 files changed, 152 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 18c8b126..c0af76b5 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -262,6 +262,7 @@ const char* const kArgRequired[] = { "--export-wiqr-json", "--import-wiqr-json", "--gen-scs", "--gen-scs-weapon", "--gen-scs-riding", "--info-wscs", "--validate-wscs", + "--export-wscs-json", "--import-wscs-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 f30b8495..e60cd0c0 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1947,6 +1947,10 @@ void printUsage(const char* argv0) { std::printf(" Print WSCS entries (id / rank / kind / minSkill / maxSkill / required level / gold cost / name)\n"); std::printf(" --validate-wscs [--json]\n"); std::printf(" Static checks: id+name required, costKind 0..4, no duplicate ids, min80, RidingSkill below lvl 20, Profession with cost=0\n"); + std::printf(" --export-wscs-json [out.json]\n"); + std::printf(" Export binary .wscs to a human-editable JSON sidecar (defaults to .wscs.json)\n"); + std::printf(" --import-wscs-json [out-base]\n"); + std::printf(" Import a .wscs.json sidecar back into binary .wscs (accepts costKind int OR costKindName 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_skill_costs_catalog.cpp b/tools/editor/cli_skill_costs_catalog.cpp index 4f633c2d..73e23f79 100644 --- a/tools/editor/cli_skill_costs_catalog.cpp +++ b/tools/editor/cli_skill_costs_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_skill_costs.hpp" #include +#include #include #include #include @@ -138,6 +139,146 @@ 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 = stripWscsExt(base); + if (!wowee::pipeline::WoweeSkillCostLoader::exists(base)) { + std::fprintf(stderr, + "export-wscs-json: WSCS not found: %s.wscs\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeSkillCostLoader::load(base); + if (outPath.empty()) outPath = base + ".wscs.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["costId"] = e.costId; + je["name"] = e.name; + je["description"] = e.description; + je["skillRankIndex"] = e.skillRankIndex; + je["minSkillToLearn"] = e.minSkillToLearn; + je["maxSkillUnlocked"] = e.maxSkillUnlocked; + je["requiredLevel"] = e.requiredLevel; + je["costKind"] = e.costKind; + je["costKindName"] = + wowee::pipeline::WoweeSkillCost::costKindName(e.costKind); + 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-wscs-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(" tiers : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseCostKindToken(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::WoweeSkillCost::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 == "profession") return wowee::pipeline::WoweeSkillCost::Profession; + if (s == "weapon" || + s == "weaponskill") return wowee::pipeline::WoweeSkillCost::WeaponSkill; + if (s == "riding" || + s == "ridingskill") return wowee::pipeline::WoweeSkillCost::RidingSkill; + if (s == "class-skill" || + s == "classskill") return wowee::pipeline::WoweeSkillCost::ClassSkill; + if (s == "misc") return wowee::pipeline::WoweeSkillCost::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-wscs-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-wscs-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeSkillCost 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::WoweeSkillCost::Entry e; + if (je.contains("costId")) e.costId = je["costId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("skillRankIndex")) e.skillRankIndex = je["skillRankIndex"].get(); + if (je.contains("minSkillToLearn")) e.minSkillToLearn = je["minSkillToLearn"].get(); + if (je.contains("maxSkillUnlocked")) e.maxSkillUnlocked = je["maxSkillUnlocked"].get(); + if (je.contains("requiredLevel")) e.requiredLevel = je["requiredLevel"].get(); + uint8_t kind = wowee::pipeline::WoweeSkillCost::Profession; + if (je.contains("costKind")) + kind = parseCostKindToken(je["costKind"], kind); + else if (je.contains("costKindName")) + kind = parseCostKindToken(je["costKindName"], kind); + e.costKind = kind; + 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 = ".wscs.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 = stripWscsExt(outBase); + if (!wowee::pipeline::WoweeSkillCostLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wscs-json: failed to save %s.wscs\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wscs\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" tiers : %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); @@ -257,6 +398,12 @@ bool handleSkillCostsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wscs") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wscs-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wscs-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }