diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 786d2df2..920e5bd6 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -412,6 +412,7 @@ const char* const kArgRequired[] = { "--export-wcra-json", "--import-wcra-json", "--gen-loc-poi", "--gen-loc-herb", "--gen-loc-rare", "--info-wloc", "--validate-wloc", + "--export-wloc-json", "--import-wloc-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 0f1ae6d7..568298ab 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2639,6 +2639,10 @@ void printUsage(const char* argv0) { std::printf(" Print WLOC entries (id / mapId / areaId / locKindName / factionAccessName / respawnSec / discoverableXp / requiredSkill / level / name)\n"); std::printf(" --validate-wloc [--json]\n"); std::printf(" Static checks: id+name required, locKind 0..6, factionAccess 0..3, no duplicate locationIds, spawnable kinds (Rare/Herb/Mineral/Fishing) MUST have respawnSec > 0 (else entity spawns once and never returns); warns on discoverableXp set with non-POI kind (XP would never award), requiredSkillId set with non-gather kind (skill check would never fire), and gather kind with skill > 0 but level = 0 (every player satisfies — verify intentional)\n"); + std::printf(" --export-wloc-json [out.json]\n"); + std::printf(" Export binary .wloc to a human-editable JSON sidecar (defaults to .wloc.json; emits both locKind and factionAccess as int + name string; floats preserved bit-for-bit)\n"); + std::printf(" --import-wloc-json [out-base]\n"); + std::printf(" Import a .wloc.json sidecar back into binary .wloc (locKind int OR \"poi\"/\"rarespawn\"/\"herbnode\"/\"mineralvein\"/\"fishingspot\"/\"areatrigger\"/\"portallanding\"; factionAccess int OR \"both\"/\"alliance\"/\"horde\"/\"neutral\")\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_world_locations_catalog.cpp b/tools/editor/cli_world_locations_catalog.cpp index a9aa8671..01a25cae 100644 --- a/tools/editor/cli_world_locations_catalog.cpp +++ b/tools/editor/cli_world_locations_catalog.cpp @@ -173,6 +173,65 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int parseLocKindToken(const std::string& s) { + using L = wowee::pipeline::WoweeWorldLocations; + if (s == "poi") return L::POI; + if (s == "rarespawn") return L::RareSpawn; + if (s == "herbnode") return L::HerbNode; + if (s == "mineralvein") return L::MineralVein; + if (s == "fishingspot") return L::FishingSpot; + if (s == "areatrigger") return L::AreaTrigger; + if (s == "portallanding") return L::PortalLanding; + return -1; +} + +int parseFactionAccessToken(const std::string& s) { + using L = wowee::pipeline::WoweeWorldLocations; + if (s == "both") return L::Both; + if (s == "alliance") return L::Alliance; + if (s == "horde") return L::Horde; + if (s == "neutral") return L::Neutral; + 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-wloc-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); @@ -295,6 +354,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 = stripWlocExt(base); + if (out.empty()) out = base + ".wloc.json"; + if (!wowee::pipeline::WoweeWorldLocationsLoader::exists(base)) { + std::fprintf(stderr, + "export-wloc-json: WLOC not found: %s.wloc\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeWorldLocationsLoader::load(base); + nlohmann::json j; + j["magic"] = "WLOC"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"locationId", e.locationId}, + {"name", e.name}, + {"mapId", e.mapId}, + {"areaId", e.areaId}, + {"x", e.x}, + {"y", e.y}, + {"z", e.z}, + {"locKind", e.locKind}, + {"locKindName", locKindName(e.locKind)}, + {"iconIndex", e.iconIndex}, + {"factionAccess", e.factionAccess}, + {"factionAccessName", + factionAccessName(e.factionAccess)}, + {"respawnSec", e.respawnSec}, + {"discoverableXp", e.discoverableXp}, + {"requiredSkillId", e.requiredSkillId}, + {"requiredSkillName", + skillIdName(e.requiredSkillId)}, + {"requiredSkillLevel", e.requiredSkillLevel}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wloc-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu locations)\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) == ".wloc.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wloc"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wloc-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-wloc-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeWorldLocations c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wloc-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeWorldLocations::Entry e; + e.locationId = je.value("locationId", 0u); + e.name = je.value("name", std::string{}); + e.mapId = je.value("mapId", 0u); + e.areaId = je.value("areaId", 0u); + e.x = je.value("x", 0.f); + e.y = je.value("y", 0.f); + e.z = je.value("z", 0.f); + if (!readEnumField(je, "locKind", "locKindName", + parseLocKindToken, "locKind", + e.locationId, e.locKind)) return 1; + e.iconIndex = static_cast( + je.value("iconIndex", 0)); + if (!readEnumField(je, "factionAccess", + "factionAccessName", + parseFactionAccessToken, + "factionAccess", e.locationId, + e.factionAccess)) return 1; + e.respawnSec = je.value("respawnSec", 0u); + e.discoverableXp = je.value("discoverableXp", 0u); + e.requiredSkillId = static_cast( + je.value("requiredSkillId", 0)); + e.requiredSkillLevel = static_cast( + je.value("requiredSkillLevel", 0)); + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeWorldLocationsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wloc-json: failed to save %s.wloc\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wloc (%zu locations)\n", + outBase.c_str(), c.entries.size()); + return 0; +} + } // namespace bool handleWorldLocationsCatalog(int& i, int argc, char** argv, @@ -318,6 +505,14 @@ bool handleWorldLocationsCatalog(int& i, int argc, char** argv, i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wloc-json") == 0 && + i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wloc-json") == 0 && + i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }