diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 7dcc8f17..43c9ab02 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -109,6 +109,7 @@ const char* const kArgRequired[] = { "--export-wgld-json", "--import-wgld-json", "--gen-conditions", "--gen-conditions-gated", "--gen-conditions-event", "--info-wpcd", "--validate-wpcd", + "--export-wpcd-json", "--import-wpcd-json", "--gen-pets", "--gen-pets-hunter", "--gen-pets-warlock", "--info-wpet", "--validate-wpet", "--gen-weather-temperate", "--gen-weather-arctic", diff --git a/tools/editor/cli_conditions_catalog.cpp b/tools/editor/cli_conditions_catalog.cpp index 386ae51b..460c2afc 100644 --- a/tools/editor/cli_conditions_catalog.cpp +++ b/tools/editor/cli_conditions_catalog.cpp @@ -124,6 +124,148 @@ 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 condition emits all 9 scalar fields + // plus dual int + name forms for kind and aggregator. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWpcdExt(base); + if (outPath.empty()) outPath = base + ".wpcd.json"; + if (!wowee::pipeline::WoweeConditionLoader::exists(base)) { + std::fprintf(stderr, + "export-wpcd-json: WPCD not found: %s.wpcd\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeConditionLoader::load(base); + nlohmann::json j; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"conditionId", e.conditionId}, + {"groupId", e.groupId}, + {"name", e.name}, + {"description", e.description}, + {"kind", e.kind}, + {"kindName", wowee::pipeline::WoweeCondition::kindName(e.kind)}, + {"aggregator", e.aggregator}, + {"aggregatorName", wowee::pipeline::WoweeCondition::aggregatorName(e.aggregator)}, + {"negated", e.negated}, + {"targetId", e.targetId}, + {"minValue", e.minValue}, + {"maxValue", e.maxValue}, + }); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wpcd-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.wpcd\n", base.c_str()); + std::printf(" conditions : %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 = ".wpcd.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 = stripWpcdExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wpcd-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-wpcd-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto kindFromName = [](const std::string& s) -> uint8_t { + if (s == "true") return wowee::pipeline::WoweeCondition::AlwaysTrue; + if (s == "false") return wowee::pipeline::WoweeCondition::AlwaysFalse; + if (s == "quest-done") return wowee::pipeline::WoweeCondition::QuestCompleted; + if (s == "quest-active") return wowee::pipeline::WoweeCondition::QuestActive; + if (s == "has-item") return wowee::pipeline::WoweeCondition::HasItem; + if (s == "has-spell") return wowee::pipeline::WoweeCondition::HasSpell; + if (s == "min-level") return wowee::pipeline::WoweeCondition::MinLevel; + if (s == "max-level") return wowee::pipeline::WoweeCondition::MaxLevel; + if (s == "class") return wowee::pipeline::WoweeCondition::ClassMatch; + if (s == "race") return wowee::pipeline::WoweeCondition::RaceMatch; + if (s == "rep") return wowee::pipeline::WoweeCondition::FactionRep; + if (s == "achievement") return wowee::pipeline::WoweeCondition::HasAchievement; + if (s == "team-size") return wowee::pipeline::WoweeCondition::TeamSize; + if (s == "guild-level") return wowee::pipeline::WoweeCondition::GuildLevel; + if (s == "event") return wowee::pipeline::WoweeCondition::EventActive; + if (s == "area") return wowee::pipeline::WoweeCondition::AreaId; + if (s == "title") return wowee::pipeline::WoweeCondition::HasTitle; + return wowee::pipeline::WoweeCondition::AlwaysTrue; + }; + auto aggFromName = [](const std::string& s) -> uint8_t { + if (s == "and") return wowee::pipeline::WoweeCondition::And; + if (s == "or") return wowee::pipeline::WoweeCondition::Or; + return wowee::pipeline::WoweeCondition::And; + }; + wowee::pipeline::WoweeCondition c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeCondition::Entry e; + e.conditionId = je.value("conditionId", 0u); + e.groupId = je.value("groupId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + if (je.contains("kind") && je["kind"].is_number_integer()) { + e.kind = static_cast(je["kind"].get()); + } else if (je.contains("kindName") && je["kindName"].is_string()) { + e.kind = kindFromName(je["kindName"].get()); + } + if (je.contains("aggregator") && je["aggregator"].is_number_integer()) { + e.aggregator = static_cast(je["aggregator"].get()); + } else if (je.contains("aggregatorName") && + je["aggregatorName"].is_string()) { + e.aggregator = aggFromName(je["aggregatorName"].get()); + } + e.negated = static_cast(je.value("negated", 0)); + e.targetId = je.value("targetId", 0u); + e.minValue = je.value("minValue", 0); + e.maxValue = je.value("maxValue", 0); + c.entries.push_back(std::move(e)); + } + } + if (!wowee::pipeline::WoweeConditionLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wpcd-json: failed to save %s.wpcd\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wpcd\n", outBase.c_str()); + std::printf(" source : %s\n", jsonPath.c_str()); + std::printf(" conditions : %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); @@ -232,6 +374,12 @@ bool handleConditionsCatalog(int& i, int argc, char** argv, int& outRc) { if (std::strcmp(argv[i], "--validate-wpcd") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wpcd-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wpcd-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 dc63ea17..578d8191 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1231,6 +1231,10 @@ void printUsage(const char* argv0) { std::printf(" Print WPCD entries (id / group / kind / aggregator / negated / target / min..max value / name)\n"); std::printf(" --validate-wpcd [--json]\n"); std::printf(" Static checks: id>0+unique, kind in 0..16, aggregator 0..1, kinds that need targetId have non-zero target\n"); + std::printf(" --export-wpcd-json [out.json]\n"); + std::printf(" Export binary .wpcd to a human-editable JSON sidecar (defaults to .wpcd.json)\n"); + std::printf(" --import-wpcd-json [out-base]\n"); + std::printf(" Import a .wpcd.json sidecar back into binary .wpcd (accepts kind/aggregator int OR name forms)\n"); std::printf(" --gen-pets [name]\n"); std::printf(" Emit .wpet starter: 2 hunter families (Wolf + Cat) + 1 warlock minion (Imp) with WSPL ability refs\n"); std::printf(" --gen-pets-hunter [name]\n");