diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 48af636a..04946a51 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -343,6 +343,7 @@ const char* const kArgRequired[] = { "--export-wmnl-json", "--import-wmnl-json", "--gen-pcr", "--gen-pcr-stable", "--gen-pcr-warlock", "--info-wpcr", "--validate-wpcr", + "--export-wpcr-json", "--import-wpcr-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 47bde5f4..099b2c33 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2317,6 +2317,10 @@ void printUsage(const char* argv0) { std::printf(" Print WPCR entries (id / spellId / classFilter / actionKind / happiness / pet-required / stable-NPC required / cost copper / reagent / cast ms / name)\n"); std::printf(" --validate-wpcr [--json]\n"); std::printf(" Static checks: id+name+classFilter required, actionKind 0..10, no duplicate actionIds, per-kind constraints (Tame and Summon REQUIRE no active pet, requiresPet must be 0); warns on happinessRestore outside +/-25, Stable kind without requiresStableNPC, Tame kind without cooldown (canonically 15 sec)\n"); + std::printf(" --export-wpcr-json [out.json]\n"); + std::printf(" Export binary .wpcr to a human-editable JSON sidecar (defaults to .wpcr.json; emits actionKind as both int AND name string; requiresPet/requiresStableNPC as bool)\n"); + std::printf(" --import-wpcr-json [out-base]\n"); + std::printf(" Import a .wpcr.json sidecar back into binary .wpcr (actionKind int OR \"revive\"/\"mend\"/\"feed\"/\"dismiss\"/\"tame\"/\"beastlore\"/\"stable\"/\"untrain\"/\"rename\"/\"abandon\"/\"summon\"; bool fields accept bool OR int)\n"); std::printf(" --catalog-pluck [--json]\n"); std::printf(" Extract one entry by id from any registered catalog format. Auto-detects magic, dispatches to the per-format --info-* handler internally, then prints just the matching entry. Primary-key field is auto-detected (first *Id field, or first numeric)\n"); std::printf(" --catalog-find [--magic ] [--json]\n"); diff --git a/tools/editor/cli_pet_care_catalog.cpp b/tools/editor/cli_pet_care_catalog.cpp index 65d8c047..e1167eed 100644 --- a/tools/editor/cli_pet_care_catalog.cpp +++ b/tools/editor/cli_pet_care_catalog.cpp @@ -148,6 +148,176 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int parseActionKindToken(const std::string& s) { + using P = wowee::pipeline::WoweePetCare; + if (s == "revive") return P::Revive; + if (s == "mend") return P::Mend; + if (s == "feed") return P::Feed; + if (s == "dismiss") return P::Dismiss; + if (s == "tame") return P::Tame; + if (s == "beastlore") return P::BeastLore; + if (s == "stable") return P::Stable; + if (s == "untrain") return P::Untrain; + if (s == "rename") return P::Rename; + if (s == "abandon") return P::Abandon; + if (s == "summon") return P::Summon; + return -1; +} + +int handleExportJson(int& i, int argc, char** argv) { + std::string base = argv[++i]; + std::string out; + if (parseOptArg(i, argc, argv)) out = argv[++i]; + base = stripWpcrExt(base); + if (out.empty()) out = base + ".wpcr.json"; + if (!wowee::pipeline::WoweePetCareLoader::exists(base)) { + std::fprintf(stderr, + "export-wpcr-json: WPCR not found: %s.wpcr\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweePetCareLoader::load(base); + nlohmann::json j; + j["magic"] = "WPCR"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"actionId", e.actionId}, + {"name", e.name}, + {"description", e.description}, + {"spellId", e.spellId}, + {"classFilter", e.classFilter}, + {"actionKind", e.actionKind}, + {"actionKindName", actionKindName(e.actionKind)}, + {"happinessRestore", e.happinessRestore}, + {"requiresPet", e.requiresPet != 0}, + {"requiresStableNPC", e.requiresStableNPC != 0}, + {"costCopper", e.costCopper}, + {"reagentItemId", e.reagentItemId}, + {"castTimeMs", e.castTimeMs}, + {"cooldownSec", e.cooldownSec}, + {"iconColorRGBA", e.iconColorRGBA}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wpcr-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu actions)\n", + out.c_str(), c.entries.size()); + return 0; +} + +int handleImportJson(int& i, int argc, char** argv) { + std::string in = argv[++i]; + std::string outBase; + if (parseOptArg(i, argc, argv)) outBase = argv[++i]; + if (outBase.empty()) { + outBase = in; + if (outBase.size() >= 10 && + outBase.substr(outBase.size() - 10) == ".wpcr.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wpcr"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wpcr-json: cannot open %s\n", in.c_str()); + return 1; + } + nlohmann::json j; + try { + is >> j; + } catch (const std::exception& ex) { + std::fprintf(stderr, + "import-wpcr-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweePetCare c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wpcr-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweePetCare::Entry e; + e.actionId = je.value("actionId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.spellId = je.value("spellId", 0u); + e.classFilter = je.value("classFilter", 0u); + if (je.contains("actionKind")) { + const auto& v = je["actionKind"]; + if (v.is_string()) { + int parsed = parseActionKindToken( + v.get()); + if (parsed < 0) { + std::fprintf(stderr, + "import-wpcr-json: unknown " + "actionKind token '%s' on entry " + "id=%u\n", + v.get().c_str(), + e.actionId); + return 1; + } + e.actionKind = static_cast(parsed); + } else if (v.is_number_integer()) { + e.actionKind = static_cast(v.get()); + } + } else if (je.contains("actionKindName") && + je["actionKindName"].is_string()) { + int parsed = parseActionKindToken( + je["actionKindName"].get()); + if (parsed >= 0) + e.actionKind = static_cast(parsed); + } + e.happinessRestore = static_cast( + je.value("happinessRestore", 0)); + if (je.contains("requiresPet")) { + const auto& v = je["requiresPet"]; + if (v.is_boolean()) + e.requiresPet = v.get() ? 1 : 0; + else if (v.is_number_integer()) + e.requiresPet = static_cast( + v.get() != 0 ? 1 : 0); + } + if (je.contains("requiresStableNPC")) { + const auto& v = je["requiresStableNPC"]; + if (v.is_boolean()) + e.requiresStableNPC = v.get() ? 1 : 0; + else if (v.is_number_integer()) + e.requiresStableNPC = static_cast( + v.get() != 0 ? 1 : 0); + } + e.costCopper = je.value("costCopper", 0u); + e.reagentItemId = je.value("reagentItemId", 0u); + e.castTimeMs = je.value("castTimeMs", 0u); + e.cooldownSec = je.value("cooldownSec", 0u); + e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweePetCareLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wpcr-json: failed to save %s.wpcr\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wpcr (%zu actions)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -281,6 +451,12 @@ bool handlePetCareCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wpcr") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wpcr-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wpcr-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }