From 6b05136ef10b758ece59033421e747ea985b5c46 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sat, 9 May 2026 19:38:06 -0700 Subject: [PATCH] feat(editor): add WPCN JSON round-trip (export/import sidecar) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes the JSON round-trip gap on the player condition catalog format shipped this batch. --export-wpcn-json emits all 11 scalar fields plus dual int + name forms for conditionKind / comparisonOp / chainOp so hand-edits can use either representation. --import-wpcn-json accepts either form, falling back to the int when both are present. Verified byte-identical round-trip on all three preset emitters (starter / quest-gates / composite — including chained conditions referencing other entries by chainNextId). 747 documented CLI flags. --- tools/editor/cli_arg_required.cpp | 1 + tools/editor/cli_help.cpp | 4 + .../editor/cli_player_conditions_catalog.cpp | 181 ++++++++++++++++++ 3 files changed, 186 insertions(+) diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index a0fac6b3..8f0eb2d0 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -146,6 +146,7 @@ const char* const kArgRequired[] = { "--export-wwui-json", "--import-wwui-json", "--gen-pcn", "--gen-pcn-quest-gates", "--gen-pcn-composite", "--info-wpcn", "--validate-wpcn", + "--export-wpcn-json", "--import-wpcn-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 82ee1e3a..6d2842d7 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1407,6 +1407,10 @@ void printUsage(const char* argv0) { std::printf(" Print WPCN entries (id / kind / op / target IDs / int values / chainOp / chainNextId / name)\n"); std::printf(" --validate-wpcn [--json]\n"); std::printf(" Static checks: id>0+unique, name not empty, kind 0..15, op 0..7, chainOp 0..3, chain self-loop, dangling chainNextId warning\n"); + std::printf(" --export-wpcn-json [out.json]\n"); + std::printf(" Export binary .wpcn to a human-editable JSON sidecar (defaults to .wpcn.json)\n"); + std::printf(" --import-wpcn-json [out-base]\n"); + std::printf(" Import a .wpcn.json sidecar back into binary .wpcn (accepts conditionKind/comparisonOp/chainOp 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_player_conditions_catalog.cpp b/tools/editor/cli_player_conditions_catalog.cpp index cdfa683f..aa48bc01 100644 --- a/tools/editor/cli_player_conditions_catalog.cpp +++ b/tools/editor/cli_player_conditions_catalog.cpp @@ -129,6 +129,181 @@ 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 11 scalar fields + // plus dual int + name forms for conditionKind / + // comparisonOp / chainOp so hand-edits can use either. + std::string base = argv[++i]; + std::string outPath; + if (parseOptArg(i, argc, argv)) outPath = argv[++i]; + base = stripWpcnExt(base); + if (outPath.empty()) outPath = base + ".wpcn.json"; + if (!wowee::pipeline::WoweePlayerConditionLoader::exists(base)) { + std::fprintf(stderr, + "export-wpcn-json: WPCN not found: %s.wpcn\n", base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweePlayerConditionLoader::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}, + {"name", e.name}, + {"description", e.description}, + {"conditionKind", e.conditionKind}, + {"conditionKindName", wowee::pipeline::WoweePlayerCondition::conditionKindName(e.conditionKind)}, + {"comparisonOp", e.comparisonOp}, + {"comparisonOpName", wowee::pipeline::WoweePlayerCondition::comparisonOpName(e.comparisonOp)}, + {"chainOp", e.chainOp}, + {"chainOpName", wowee::pipeline::WoweePlayerCondition::chainOpName(e.chainOp)}, + {"targetIdA", e.targetIdA}, + {"targetIdB", e.targetIdB}, + {"intValueA", e.intValueA}, + {"intValueB", e.intValueB}, + {"chainNextId", e.chainNextId}, + {"failMessage", e.failMessage}, + }); + } + j["entries"] = arr; + std::ofstream out(outPath); + if (!out) { + std::fprintf(stderr, + "export-wpcn-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.wpcn\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 = ".wpcn.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 = stripWpcnExt(outBase); + std::ifstream in(jsonPath); + if (!in) { + std::fprintf(stderr, + "import-wpcn-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-wpcn-json: bad JSON in %s: %s\n", + jsonPath.c_str(), e.what()); + return 1; + } + auto kindFromName = [](const std::string& s) -> uint8_t { + if (s == "always") return wowee::pipeline::WoweePlayerCondition::Always; + if (s == "race") return wowee::pipeline::WoweePlayerCondition::Race; + if (s == "class") return wowee::pipeline::WoweePlayerCondition::Class; + if (s == "level") return wowee::pipeline::WoweePlayerCondition::Level; + if (s == "zone") return wowee::pipeline::WoweePlayerCondition::Zone; + if (s == "map") return wowee::pipeline::WoweePlayerCondition::Map; + if (s == "reputation") return wowee::pipeline::WoweePlayerCondition::Reputation; + if (s == "achievement") return wowee::pipeline::WoweePlayerCondition::AchievementWon; + if (s == "quest-complete") return wowee::pipeline::WoweePlayerCondition::QuestComplete; + if (s == "quest-active") return wowee::pipeline::WoweePlayerCondition::QuestActive; + if (s == "spell-known") return wowee::pipeline::WoweePlayerCondition::SpellKnown; + if (s == "item-equipped") return wowee::pipeline::WoweePlayerCondition::ItemEquipped; + if (s == "faction") return wowee::pipeline::WoweePlayerCondition::Faction; + if (s == "in-combat") return wowee::pipeline::WoweePlayerCondition::InCombat; + if (s == "mounted") return wowee::pipeline::WoweePlayerCondition::Mounted; + if (s == "resting") return wowee::pipeline::WoweePlayerCondition::Resting; + return wowee::pipeline::WoweePlayerCondition::Always; + }; + auto opFromName = [](const std::string& s) -> uint8_t { + if (s == "==") return wowee::pipeline::WoweePlayerCondition::Equal; + if (s == "!=") return wowee::pipeline::WoweePlayerCondition::NotEqual; + if (s == ">") return wowee::pipeline::WoweePlayerCondition::GreaterThan; + if (s == ">=") return wowee::pipeline::WoweePlayerCondition::GreaterOrEqual; + if (s == "<") return wowee::pipeline::WoweePlayerCondition::LessThan; + if (s == "<=") return wowee::pipeline::WoweePlayerCondition::LessOrEqual; + if (s == "in-set") return wowee::pipeline::WoweePlayerCondition::InSet; + if (s == "not-in-set") return wowee::pipeline::WoweePlayerCondition::NotInSet; + return wowee::pipeline::WoweePlayerCondition::Equal; + }; + auto chainFromName = [](const std::string& s) -> uint8_t { + if (s == "none") return wowee::pipeline::WoweePlayerCondition::ChainNone; + if (s == "and") return wowee::pipeline::WoweePlayerCondition::ChainAnd; + if (s == "or") return wowee::pipeline::WoweePlayerCondition::ChainOr; + if (s == "not") return wowee::pipeline::WoweePlayerCondition::ChainNot; + return wowee::pipeline::WoweePlayerCondition::ChainNone; + }; + wowee::pipeline::WoweePlayerCondition c; + c.name = j.value("name", std::string{}); + if (j.contains("entries") && j["entries"].is_array()) { + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweePlayerCondition::Entry e; + e.conditionId = je.value("conditionId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + if (je.contains("conditionKind") && + je["conditionKind"].is_number_integer()) { + e.conditionKind = static_cast( + je["conditionKind"].get()); + } else if (je.contains("conditionKindName") && + je["conditionKindName"].is_string()) { + e.conditionKind = kindFromName( + je["conditionKindName"].get()); + } + if (je.contains("comparisonOp") && + je["comparisonOp"].is_number_integer()) { + e.comparisonOp = static_cast( + je["comparisonOp"].get()); + } else if (je.contains("comparisonOpName") && + je["comparisonOpName"].is_string()) { + e.comparisonOp = opFromName( + je["comparisonOpName"].get()); + } + if (je.contains("chainOp") && + je["chainOp"].is_number_integer()) { + e.chainOp = static_cast( + je["chainOp"].get()); + } else if (je.contains("chainOpName") && + je["chainOpName"].is_string()) { + e.chainOp = chainFromName( + je["chainOpName"].get()); + } + e.targetIdA = je.value("targetIdA", 0u); + e.targetIdB = je.value("targetIdB", 0u); + e.intValueA = je.value("intValueA", 0); + e.intValueB = je.value("intValueB", 0); + e.chainNextId = je.value("chainNextId", 0u); + e.failMessage = je.value("failMessage", std::string{}); + c.entries.push_back(e); + } + } + if (!wowee::pipeline::WoweePlayerConditionLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wpcn-json: failed to save %s.wpcn\n", outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wpcn\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); @@ -257,6 +432,12 @@ bool handlePlayerConditionsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wpcn") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wpcn-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wpcn-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }