diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 0e9ae7a8..c7fe7869 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -220,6 +220,7 @@ const char* const kArgRequired[] = { "--export-wscd-json", "--import-wscd-json", "--gen-cef", "--gen-cef-ferocity", "--gen-cef-exotic", "--info-wcef", "--validate-wcef", + "--export-wcef-json", "--import-wcef-json", "--gen-weather-temperate", "--gen-weather-arctic", "--gen-weather-desert", "--gen-weather-stormy", "--gen-zone-atmosphere", diff --git a/tools/editor/cli_creature_families_catalog.cpp b/tools/editor/cli_creature_families_catalog.cpp index 50402667..423d2e6b 100644 --- a/tools/editor/cli_creature_families_catalog.cpp +++ b/tools/editor/cli_creature_families_catalog.cpp @@ -5,6 +5,7 @@ #include "pipeline/wowee_creature_families.hpp" #include +#include #include #include #include @@ -146,6 +147,205 @@ 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 = stripWcefExt(base); + if (!wowee::pipeline::WoweeCreatureFamilyLoader::exists(base)) { + std::fprintf(stderr, + "export-wcef-json: WCEF not found: %s.wcef\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeCreatureFamilyLoader::load(base); + if (outPath.empty()) outPath = base + ".wcef.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + std::string foodNames; + appendFoodNames(e.petFoodTypes, foodNames); + nlohmann::json je; + je["familyId"] = e.familyId; + je["name"] = e.name; + je["description"] = e.description; + je["familyKind"] = e.familyKind; + je["familyKindName"] = + wowee::pipeline::WoweeCreatureFamily::familyKindName(e.familyKind); + je["petTalentTree"] = e.petTalentTree; + je["petTalentTreeName"] = + wowee::pipeline::WoweeCreatureFamily::petTalentTreeName(e.petTalentTree); + je["minLevelForTame"] = e.minLevelForTame; + je["skillLine"] = e.skillLine; + je["petFoodTypes"] = e.petFoodTypes; + je["petFoodTypesLabels"] = foodNames; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wcef-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(" families : %zu\n", c.entries.size()); + return 0; +} + +uint8_t parseFamilyKindToken(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::WoweeCreatureFamily::Exotic) + 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 == "beast") return wowee::pipeline::WoweeCreatureFamily::Beast; + if (s == "demon") return wowee::pipeline::WoweeCreatureFamily::Demon; + if (s == "undead") return wowee::pipeline::WoweeCreatureFamily::Undead; + if (s == "elemental") return wowee::pipeline::WoweeCreatureFamily::Elemental; + if (s == "not-pet" || + s == "notpet") return wowee::pipeline::WoweeCreatureFamily::NotPet; + if (s == "exotic") return wowee::pipeline::WoweeCreatureFamily::Exotic; + } + return fallback; +} + +uint8_t parseTalentTreeToken(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::WoweeCreatureFamily::Cunning) + 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 == "none") return wowee::pipeline::WoweeCreatureFamily::TreeNone; + if (s == "ferocity") return wowee::pipeline::WoweeCreatureFamily::Ferocity; + if (s == "tenacity") return wowee::pipeline::WoweeCreatureFamily::Tenacity; + if (s == "cunning") return wowee::pipeline::WoweeCreatureFamily::Cunning; + } + return fallback; +} + +uint32_t parseFoodTypesField(const nlohmann::json& jv) { + using F = wowee::pipeline::WoweeCreatureFamily; + if (jv.is_number_integer() || jv.is_number_unsigned()) + return jv.get(); + if (jv.is_string()) { + std::string s = jv.get(); + uint32_t out = 0; + size_t pos = 0; + while (pos < s.size()) { + size_t end = s.find('|', pos); + if (end == std::string::npos) end = s.size(); + std::string tok = s.substr(pos, end - pos); + for (auto& ch : tok) ch = static_cast(std::tolower(ch)); + if (tok == "meat") out |= F::Meat; + else if (tok == "fish") out |= F::Fish; + else if (tok == "bread") out |= F::Bread; + else if (tok == "cheese") out |= F::Cheese; + else if (tok == "fruit") out |= F::Fruit; + else if (tok == "fungus") out |= F::Fungus; + else if (tok == "raw") out |= F::Raw; + pos = end + 1; + } + return out; + } + 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]; + std::ifstream is(jsonPath); + if (!is) { + std::fprintf(stderr, + "import-wcef-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-wcef-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweeCreatureFamily 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::WoweeCreatureFamily::Entry e; + if (je.contains("familyId")) e.familyId = je["familyId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + uint8_t kind = wowee::pipeline::WoweeCreatureFamily::Beast; + if (je.contains("familyKind")) + kind = parseFamilyKindToken(je["familyKind"], kind); + else if (je.contains("familyKindName")) + kind = parseFamilyKindToken(je["familyKindName"], kind); + e.familyKind = kind; + uint8_t tree = wowee::pipeline::WoweeCreatureFamily::TreeNone; + if (je.contains("petTalentTree")) + tree = parseTalentTreeToken(je["petTalentTree"], tree); + else if (je.contains("petTalentTreeName")) + tree = parseTalentTreeToken(je["petTalentTreeName"], tree); + e.petTalentTree = tree; + if (je.contains("minLevelForTame")) + e.minLevelForTame = je["minLevelForTame"].get(); + if (je.contains("skillLine")) + e.skillLine = je["skillLine"].get(); + if (je.contains("petFoodTypes")) + e.petFoodTypes = parseFoodTypesField(je["petFoodTypes"]); + else if (je.contains("petFoodTypesLabels")) + e.petFoodTypes = parseFoodTypesField(je["petFoodTypesLabels"]); + if (je.contains("iconColorRGBA")) + e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wcef.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 = stripWcefExt(outBase); + if (!wowee::pipeline::WoweeCreatureFamilyLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wcef-json: failed to save %s.wcef\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wcef\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" families : %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); @@ -278,6 +478,12 @@ bool handleCreatureFamiliesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wcef") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wcef-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wcef-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 e0363bf9..befc74a3 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1755,6 +1755,10 @@ void printUsage(const char* argv0) { std::printf(" Print WCEF entries (id / kind / talent tree / tame level / skill line / food types / name)\n"); std::printf(" --validate-wcef [--json]\n"); std::printf(" Static checks: id+name required, familyKind 0..5, talent tree 0..3, no duplicate ids; warns on NotPet+talent, Exotic+lvl>80, Beast/Exotic with no foods (would starve)\n"); + std::printf(" --export-wcef-json [out.json]\n"); + std::printf(" Export binary .wcef to a human-editable JSON sidecar (defaults to .wcef.json)\n"); + std::printf(" --import-wcef-json [out-base]\n"); + std::printf(" Import a .wcef.json sidecar back into binary .wcef (accepts familyKind/petTalentTree int OR name; petFoodTypes int OR pipe-separated label 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");