diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index dba55e7f..28a38254 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -190,6 +190,7 @@ const char* const kArgRequired[] = { "--export-wbnk-json", "--import-wbnk-json", "--gen-rune", "--gen-rune-blood", "--gen-rune-frost", "--info-wrun", "--validate-wrun", + "--export-wrun-json", "--import-wrun-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 3bab3b1c..3cf7a50f 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1611,6 +1611,10 @@ void printUsage(const char* argv0) { std::printf(" Print WRUN entries (id / spell / B/F/U costs / death-convertible / RP cost+arrow / branch / name)\n"); std::printf(" --validate-wrun [--json]\n"); std::printf(" Static checks: id+name+spellId required, branch 0..3, no rune cost > 2 (DK has only 2 of each), runicPower > 100 cap, no-cost warning\n"); + std::printf(" --export-wrun-json [out.json]\n"); + std::printf(" Export binary .wrun to a human-editable JSON sidecar (defaults to .wrun.json)\n"); + std::printf(" --import-wrun-json [out-base]\n"); + std::printf(" Import a .wrun.json sidecar back into binary .wrun (accepts spellTreeBranch int OR name 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_runes_catalog.cpp b/tools/editor/cli_runes_catalog.cpp index eda984d0..5936efe6 100644 --- a/tools/editor/cli_runes_catalog.cpp +++ b/tools/editor/cli_runes_catalog.cpp @@ -129,6 +129,131 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int handleExportJson(int& i, int argc, char** argv) { + // Mirrors the JSON pairs added for every other novel + // open format. Each rune cost emits all 9 scalar fields + // plus a dual int + name form for spellTreeBranch so + // hand-edits can use either representation. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWrunExt(base); + if (outPath.empty()) outPath = base + ".wrun.json"; + if (!wowee::pipeline::WoweeRuneCostLoader::exists(base)) { + std::fprintf(stderr, + "export-wrun-json: WRUN not found: %s.wrun\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeRuneCostLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"runeCostId", e.runeCostId}, + {"spellId", e.spellId}, + {"name", e.name}, + {"description", e.description}, + {"bloodCost", e.bloodCost}, + {"frostCost", e.frostCost}, + {"unholyCost", e.unholyCost}, + {"anyDeathConvertCost", e.anyDeathConvertCost}, + {"runicPowerCost", e.runicPowerCost}, + {"spellTreeBranch", e.spellTreeBranch}, + {"spellTreeBranchName", wowee::pipeline::WoweeRuneCost::spellTreeBranchName(e.spellTreeBranch)}, + }); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wrun-json: cannot write %s\n", outPath.c_str()); + return 1; + } + out << j.dump(2) << "\n"; + out.close(); + std::printf("Wrote %s\n", outPath.c_str()); + std::printf(" source : %s.wrun\n", base.c_str()); + std::printf(" costs : %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]; + if (outBase.empty()) { + outBase = jsonPath; + std::string suffix = ".wrun.json"; + if (outBase.size() > suffix.size() && + outBase.substr(outBase.size() - suffix.size()) == suffix) { + outBase = outBase.substr(0, outBase.size() - suffix.size()); + } else if (outBase.size() > 5 && + outBase.substr(outBase.size() - 5) == ".json") { + outBase = outBase.substr(0, outBase.size() - 5); + } + } + outBase = stripWrunExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wrun-json: cannot read %s\n", jsonPath.c_str()); + return 1; + } + nlohmann::json j; + try { in >> j; } + catch (const std::exception& e) { + std::fprintf(stderr, + "import-wrun-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto branchFromName = [](const std::string& s) -> uint8_t { + if (s == "blood") return wowee::pipeline::WoweeRuneCost::BloodTree; + if (s == "frost") return wowee::pipeline::WoweeRuneCost::FrostTree; + if (s == "unholy") return wowee::pipeline::WoweeRuneCost::UnholyTree; + if (s == "generic") return wowee::pipeline::WoweeRuneCost::Generic; + return wowee::pipeline::WoweeRuneCost::Generic; + }; + wowee::pipeline::WoweeRuneCost c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeRuneCost::Entry e; + e.runeCostId = je.value("runeCostId", 0u); + e.spellId = je.value("spellId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.bloodCost = static_cast(je.value("bloodCost", 0)); + e.frostCost = static_cast(je.value("frostCost", 0)); + e.unholyCost = static_cast(je.value("unholyCost", 0)); + e.anyDeathConvertCost = static_cast( + je.value("anyDeathConvertCost", 0)); + e.runicPowerCost = static_cast( + je.value("runicPowerCost", 0)); + if (je.contains("spellTreeBranch") && + je["spellTreeBranch"].is_number_integer()) { + e.spellTreeBranch = static_cast( + je["spellTreeBranch"].get()); + } else if (je.contains("spellTreeBranchName") && + je["spellTreeBranchName"].is_string()) { + e.spellTreeBranch = branchFromName( + je["spellTreeBranchName"].get()); + } + c.entries.push_back(e); + } + } + if (!wowee::pipeline::WoweeRuneCostLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wrun-json: failed to save %s.wrun\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wrun\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" costs : %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); @@ -256,6 +381,12 @@ bool handleRunesCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wrun") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wrun-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wrun-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }