diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index dee43875..abf3d5cf 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -236,6 +236,7 @@ const char* const kArgRequired[] = { "--export-wmat-json", "--import-wmat-json", "--gen-psp", "--gen-psp-horde", "--gen-psp-dk", "--info-wpsp", "--validate-wpsp", + "--export-wpsp-json", "--import-wpsp-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 2ce0d2e8..2581769f 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -1829,6 +1829,10 @@ void printUsage(const char* argv0) { std::printf(" Print WPSP entries (id / raceMask / classMask / map / zone / startingLevel / spawn coords / name)\n"); std::printf(" --validate-wpsp [--json]\n"); std::printf(" Static checks: id+name+race+class+startingLevel required, no duplicate ids; warns on (0,0,0) spawn, item id/count mismatch, lvl>80, DK not at 55\n"); + std::printf(" --export-wpsp-json [out.json]\n"); + std::printf(" Export binary .wpsp to a human-editable JSON sidecar (defaults to .wpsp.json)\n"); + std::printf(" --import-wpsp-json [out-base]\n"); + std::printf(" Import a .wpsp.json sidecar back into binary .wpsp (all per-entry fields preserved verbatim including spawn/bind coords and item/spell ids)\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_spawn_profiles_catalog.cpp b/tools/editor/cli_player_spawn_profiles_catalog.cpp index fbf42a09..6c9f422f 100644 --- a/tools/editor/cli_player_spawn_profiles_catalog.cpp +++ b/tools/editor/cli_player_spawn_profiles_catalog.cpp @@ -140,6 +140,150 @@ 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 = stripWpspExt(base); + if (!wowee::pipeline::WoweePlayerSpawnProfileLoader::exists(base)) { + std::fprintf(stderr, + "export-wpsp-json: WPSP not found: %s.wpsp\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweePlayerSpawnProfileLoader::load(base); + if (outPath.empty()) outPath = base + ".wpsp.json"; + nlohmann::json j; + j["catalog"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + nlohmann::json je; + je["profileId"] = e.profileId; + je["name"] = e.name; + je["description"] = e.description; + je["raceMask"] = e.raceMask; + je["classMask"] = e.classMask; + je["mapId"] = e.mapId; + je["zoneId"] = e.zoneId; + je["spawnX"] = e.spawnX; + je["spawnY"] = e.spawnY; + je["spawnZ"] = e.spawnZ; + je["spawnFacing"] = e.spawnFacing; + je["bindMapId"] = e.bindMapId; + je["bindZoneId"] = e.bindZoneId; + je["startingItem1Id"] = e.startingItem1Id; + je["startingItem1Count"] = e.startingItem1Count; + je["startingItem2Id"] = e.startingItem2Id; + je["startingItem2Count"] = e.startingItem2Count; + je["startingItem3Id"] = e.startingItem3Id; + je["startingItem3Count"] = e.startingItem3Count; + je["startingItem4Id"] = e.startingItem4Id; + je["startingItem4Count"] = e.startingItem4Count; + je["startingSpell1Id"] = e.startingSpell1Id; + je["startingSpell2Id"] = e.startingSpell2Id; + je["startingSpell3Id"] = e.startingSpell3Id; + je["startingSpell4Id"] = e.startingSpell4Id; + je["startingLevel"] = e.startingLevel; + je["iconColorRGBA"] = e.iconColorRGBA; + arr.push_back(je); + } + j["entries"] = arr; + std::ofstream os(outPath); + if (!os) { + std::fprintf(stderr, + "export-wpsp-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(" profiles : %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]; + std::ifstream is(jsonPath); + if (!is) { + std::fprintf(stderr, + "import-wpsp-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-wpsp-json: parse error in %s: %s\n", + jsonPath.c_str(), ex.what()); + return 1; + } + wowee::pipeline::WoweePlayerSpawnProfile 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::WoweePlayerSpawnProfile::Entry e; + if (je.contains("profileId")) e.profileId = je["profileId"].get(); + if (je.contains("name")) e.name = je["name"].get(); + if (je.contains("description")) e.description = je["description"].get(); + if (je.contains("raceMask")) e.raceMask = je["raceMask"].get(); + if (je.contains("classMask")) e.classMask = je["classMask"].get(); + if (je.contains("mapId")) e.mapId = je["mapId"].get(); + if (je.contains("zoneId")) e.zoneId = je["zoneId"].get(); + if (je.contains("spawnX")) e.spawnX = je["spawnX"].get(); + if (je.contains("spawnY")) e.spawnY = je["spawnY"].get(); + if (je.contains("spawnZ")) e.spawnZ = je["spawnZ"].get(); + if (je.contains("spawnFacing")) e.spawnFacing = je["spawnFacing"].get(); + if (je.contains("bindMapId")) e.bindMapId = je["bindMapId"].get(); + if (je.contains("bindZoneId")) e.bindZoneId = je["bindZoneId"].get(); + if (je.contains("startingItem1Id")) e.startingItem1Id = je["startingItem1Id"].get(); + if (je.contains("startingItem1Count")) e.startingItem1Count = je["startingItem1Count"].get(); + if (je.contains("startingItem2Id")) e.startingItem2Id = je["startingItem2Id"].get(); + if (je.contains("startingItem2Count")) e.startingItem2Count = je["startingItem2Count"].get(); + if (je.contains("startingItem3Id")) e.startingItem3Id = je["startingItem3Id"].get(); + if (je.contains("startingItem3Count")) e.startingItem3Count = je["startingItem3Count"].get(); + if (je.contains("startingItem4Id")) e.startingItem4Id = je["startingItem4Id"].get(); + if (je.contains("startingItem4Count")) e.startingItem4Count = je["startingItem4Count"].get(); + if (je.contains("startingSpell1Id")) e.startingSpell1Id = je["startingSpell1Id"].get(); + if (je.contains("startingSpell2Id")) e.startingSpell2Id = je["startingSpell2Id"].get(); + if (je.contains("startingSpell3Id")) e.startingSpell3Id = je["startingSpell3Id"].get(); + if (je.contains("startingSpell4Id")) e.startingSpell4Id = je["startingSpell4Id"].get(); + if (je.contains("startingLevel")) e.startingLevel = je["startingLevel"].get(); + if (je.contains("iconColorRGBA")) e.iconColorRGBA = je["iconColorRGBA"].get(); + c.entries.push_back(e); + } + } + if (outBase.empty()) { + outBase = jsonPath; + const std::string suffix1 = ".wpsp.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 = stripWpspExt(outBase); + if (!wowee::pipeline::WoweePlayerSpawnProfileLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wpsp-json: failed to save %s.wpsp\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wpsp\n", outBase.c_str()); + std::printf(" catalog : %s\n", c.name.c_str()); + std::printf(" profiles : %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); @@ -270,6 +414,12 @@ bool handlePlayerSpawnProfilesCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wpsp") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wpsp-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wpsp-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }