diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 5f9e154c..3ef1283e 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -397,6 +397,7 @@ const char* const kArgRequired[] = { "--export-wtsc-json", "--import-wtsc-json", "--gen-prt-alliance", "--gen-prt-horde", "--gen-prt-teleports", "--info-wprt", "--validate-wprt", + "--export-wprt-json", "--import-wprt-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 f77a6f2e..9f635863 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2569,6 +2569,10 @@ void printUsage(const char* argv0) { std::printf(" Print WPRT entries (id / spellId / portalKind / factionAccess / levelRequirement / reagentItemId / destination)\n"); std::printf(" --validate-wprt [--json]\n"); std::printf(" Static checks: id+spellId+destination required, factionAccess 0..3, portalKind 0..1, no duplicate portalIds, no duplicate spellIds (would conflict on cast); warns on levelRequirement < 20 (vanilla mage cannot unlock), Portal kind without Rune of Portals (17032), Teleport kind without Rune of Teleportation (17031), and duplicate destination names (likely Teleport+Portal pair OR copy-paste bug)\n"); + std::printf(" --export-wprt-json [out.json]\n"); + std::printf(" Export binary .wprt to a human-editable JSON sidecar (defaults to .wprt.json; emits factionAccess and portalKind as int + name string; floats preserved bit-for-bit)\n"); + std::printf(" --import-wprt-json [out-base]\n"); + std::printf(" Import a .wprt.json sidecar back into binary .wprt (factionAccess int OR \"both\"/\"alliance\"/\"horde\"/\"neutral\"; portalKind int OR \"teleport\"/\"portal\")\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_mage_portals_catalog.cpp b/tools/editor/cli_mage_portals_catalog.cpp index a32c2837..288aec6c 100644 --- a/tools/editor/cli_mage_portals_catalog.cpp +++ b/tools/editor/cli_mage_portals_catalog.cpp @@ -154,6 +154,60 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int parseFactionAccessToken(const std::string& s) { + using P = wowee::pipeline::WoweeMagePortals; + if (s == "both") return P::Both; + if (s == "alliance") return P::Alliance; + if (s == "horde") return P::Horde; + if (s == "neutral") return P::Neutral; + return -1; +} + +int parsePortalKindToken(const std::string& s) { + using P = wowee::pipeline::WoweeMagePortals; + if (s == "teleport") return P::Teleport; + if (s == "portal") return P::Portal; + return -1; +} + +template +bool readEnumField(const nlohmann::json& je, + const char* intKey, + const char* nameKey, + ParseFn parseFn, + const char* label, + uint32_t entryId, + uint8_t& outValue) { + if (je.contains(intKey)) { + const auto& v = je[intKey]; + if (v.is_string()) { + int parsed = parseFn(v.get()); + if (parsed < 0) { + std::fprintf(stderr, + "import-wprt-json: unknown %s token " + "'%s' on entry id=%u\n", + label, v.get().c_str(), + entryId); + return false; + } + outValue = static_cast(parsed); + return true; + } + if (v.is_number_integer()) { + outValue = static_cast(v.get()); + return true; + } + } + if (je.contains(nameKey) && je[nameKey].is_string()) { + int parsed = parseFn(je[nameKey].get()); + if (parsed >= 0) { + outValue = static_cast(parsed); + return true; + } + } + return true; +} + int handleValidate(int& i, int argc, char** argv) { std::string base = argv[++i]; bool jsonOut = consumeJsonFlag(i, argc, argv); @@ -302,6 +356,132 @@ 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 = stripWprtExt(base); + if (out.empty()) out = base + ".wprt.json"; + if (!wowee::pipeline::WoweeMagePortalsLoader::exists(base)) { + std::fprintf(stderr, + "export-wprt-json: WPRT not found: %s.wprt\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMagePortalsLoader::load(base); + nlohmann::json j; + j["magic"] = "WPRT"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"portalId", e.portalId}, + {"spellId", e.spellId}, + {"destinationName", e.destinationName}, + {"destX", e.destX}, + {"destY", e.destY}, + {"destZ", e.destZ}, + {"destOrientation", e.destOrientation}, + {"destMapId", e.destMapId}, + {"factionAccess", e.factionAccess}, + {"factionAccessName", + factionAccessName(e.factionAccess)}, + {"portalKind", e.portalKind}, + {"portalKindName", + portalKindName(e.portalKind)}, + {"levelRequirement", e.levelRequirement}, + {"reagentCount", e.reagentCount}, + {"reagentItemId", e.reagentItemId}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wprt-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu portals)\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) == ".wprt.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wprt"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wprt-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-wprt-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeMagePortals c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wprt-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeMagePortals::Entry e; + e.portalId = je.value("portalId", 0u); + e.spellId = je.value("spellId", 0u); + e.destinationName = je.value("destinationName", + std::string{}); + e.destX = je.value("destX", 0.f); + e.destY = je.value("destY", 0.f); + e.destZ = je.value("destZ", 0.f); + e.destOrientation = je.value("destOrientation", 0.f); + e.destMapId = je.value("destMapId", 0u); + if (!readEnumField(je, "factionAccess", + "factionAccessName", + parseFactionAccessToken, + "factionAccess", e.portalId, + e.factionAccess)) return 1; + if (!readEnumField(je, "portalKind", "portalKindName", + parsePortalKindToken, + "portalKind", e.portalId, + e.portalKind)) return 1; + e.levelRequirement = static_cast( + je.value("levelRequirement", 0)); + e.reagentCount = static_cast( + je.value("reagentCount", 0)); + e.reagentItemId = je.value("reagentItemId", 0u); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeMagePortalsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wprt-json: failed to save %s.wprt\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wprt (%zu portals)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + } // namespace bool handleMagePortalsCatalog(int& i, int argc, char** argv, @@ -325,6 +505,14 @@ bool handleMagePortalsCatalog(int& i, int argc, char** argv, i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wprt-json") == 0 && + i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wprt-json") == 0 && + i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }