diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index d8f15f07..1a11de78 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -409,6 +409,7 @@ const char* const kArgRequired[] = { "--export-wqgr-json", "--import-wqgr-json", "--gen-cra-alchemy", "--gen-cra-engineering", "--gen-cra-blacksmithing", "--info-wcra", "--validate-wcra", + "--export-wcra-json", "--import-wcra-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_crafting_recipes_catalog.cpp b/tools/editor/cli_crafting_recipes_catalog.cpp index 3a5ad5e1..c625fbd9 100644 --- a/tools/editor/cli_crafting_recipes_catalog.cpp +++ b/tools/editor/cli_crafting_recipes_catalog.cpp @@ -301,6 +301,134 @@ int handleValidate(int& i, int argc, char** argv) { return ok ? 0 : 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 = stripWcraExt(base); + if (out.empty()) out = base + ".wcra.json"; + if (!wowee::pipeline::WoweeCraftingRecipesLoader::exists(base)) { + std::fprintf(stderr, + "export-wcra-json: WCRA not found: %s.wcra\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeCraftingRecipesLoader::load(base); + nlohmann::json j; + j["magic"] = "WCRA"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json reagents = nlohmann::json::array(); + for (const auto& r : e.reagents) { + reagents.push_back({ + {"itemId", r.itemId}, + {"count", r.count}, + }); + } + arr.push_back({ + {"recipeId", e.recipeId}, + {"spellId", e.spellId}, + {"name", e.name}, + {"tradeSkillId", e.tradeSkillId}, + {"tradeSkillName", + tradeSkillName(e.tradeSkillId)}, + {"requiredSkillLevel", e.requiredSkillLevel}, + {"producedItemId", e.producedItemId}, + {"producedCount", e.producedCount}, + {"categoryId", e.categoryId}, + {"learnedFromItemId", e.learnedFromItemId}, + {"reagents", reagents}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wcra-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu recipes)\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) == ".wcra.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wcra"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wcra-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-wcra-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeCraftingRecipes c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wcra-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeCraftingRecipes::Entry e; + e.recipeId = je.value("recipeId", 0u); + e.spellId = je.value("spellId", 0u); + e.name = je.value("name", std::string{}); + e.tradeSkillId = static_cast( + je.value("tradeSkillId", 0)); + e.requiredSkillLevel = static_cast( + je.value("requiredSkillLevel", 0)); + e.producedItemId = je.value("producedItemId", 0u); + e.producedCount = static_cast( + je.value("producedCount", 1)); + e.categoryId = static_cast( + je.value("categoryId", 0)); + e.learnedFromItemId = je.value("learnedFromItemId", 0u); + if (je.contains("reagents") && + je["reagents"].is_array()) { + for (const auto& r : je["reagents"]) { + wowee::pipeline::WoweeCraftingRecipes:: + Reagent reagent; + reagent.itemId = r.value("itemId", 0u); + reagent.count = r.value("count", 0u); + e.reagents.push_back(reagent); + } + } + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeCraftingRecipesLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wcra-json: failed to save %s.wcra\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wcra (%zu recipes)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + } // namespace bool handleCraftingRecipesCatalog(int& i, int argc, char** argv, @@ -324,6 +452,14 @@ bool handleCraftingRecipesCatalog(int& i, int argc, char** argv, i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wcra-json") == 0 && + i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wcra-json") == 0 && + i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; } diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index f2db9489..8d7bbffc 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2625,6 +2625,10 @@ void printUsage(const char* argv0) { std::printf(" Print WCRA entries (recipeId / spellId / tradeSkillName / requiredSkillLevel / producedItemId / producedCount / reagent count / name)\n"); std::printf(" --validate-wcra [--json]\n"); std::printf(" Static checks: id+name+spellId+tradeSkillId+producedItemId+producedCount required, no duplicate recipeIds, no duplicate spellIds (cast-handler conflict), no zero-itemId/zero-count reagents, no duplicate reagent itemIds within a single recipe (should be merged), no self-reagent (recipe consuming its own output is a perpetual-motion bug); warns on requiredSkillLevel > 450 (above WotLK cap), empty reagent list (free-to-craft is unusual)\n"); + std::printf(" --export-wcra-json [out.json]\n"); + std::printf(" Export binary .wcra to a human-editable JSON sidecar (defaults to .wcra.json; tradeSkillName is informational; reagents emitted as JSON object array of {itemId,count})\n"); + std::printf(" --import-wcra-json [out-base]\n"); + std::printf(" Import a .wcra.json sidecar back into binary .wcra (tradeSkillId int authoritative, tradeSkillName ignored; reagents accept JSON object array — round-trips per-recipe variable-length reagent lists byte-identical)\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");