mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
feat(editor): add WSPN JSON round-trip authoring workflow
Closes the WSPN open-format loop with --export-wspn-json / --import-wspn-json, mirroring the WOL/WOW/WOMX/WSND JSON pairs from earlier batches. All 5 binary formats added in recent batches now have full JSON round-trip authoring. Each entry round-trips all 12 fields: kind (int + kindName string), entryId, position[3], rotation[3], scale, flags (int + flagsList string array), respawnSec, factionId, questIdRequired, wanderRadius, label. Vector fields are emitted as 3-element arrays for natural JSON layout. Both kind and flags are emitted in dual form (int + named) so a hand-author can write the named string forms and skip the integer boilerplate. Missing optional fields fall back to WoweeSpawns::Entry defaults. Verified byte-identical round-trip on the village preset (12 entries: 6 creature + 2 object + 4 doodad). The position vec3 round-trips through floats with no precision loss for the typical small-coordinate test cases. Adds 2 flags (475 kArgRequired entries total).
This commit is contained in:
parent
88d1e6229f
commit
23f262c655
3 changed files with 163 additions and 0 deletions
|
|
@ -31,6 +31,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wsnd-json", "--import-wsnd-json",
|
||||
"--gen-spawns", "--gen-spawns-camp", "--gen-spawns-village",
|
||||
"--info-wspn", "--validate-wspn",
|
||||
"--export-wspn-json", "--import-wspn-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -861,6 +861,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WSPN spawn entries (kind / entryId / position / respawn / wander radius / label)\n");
|
||||
std::printf(" --validate-wspn <wspn-base> [--json]\n");
|
||||
std::printf(" Static checks: kind 0..2, finite position/scale/wander, doodads have respawn=0, no orphan entryId=0\n");
|
||||
std::printf(" --export-wspn-json <wspn-base> [out.json]\n");
|
||||
std::printf(" Export binary .wspn to a human-editable JSON sidecar (defaults to <base>.wspn.json)\n");
|
||||
std::printf(" --import-wspn-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wspn.json sidecar back into binary .wspn (accepts either kind int OR kindName string)\n");
|
||||
std::printf(" --gen-weather-temperate <wow-base> [zoneName]\n");
|
||||
std::printf(" Emit .wow weather schedule: clear-dominant + occasional rain + fog (forest / grassland)\n");
|
||||
std::printf(" --gen-weather-arctic <wow-base> [zoneName]\n");
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -138,6 +139,157 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int handleExportJson(int& i, int argc, char** argv) {
|
||||
// Export a .wspn to a human-editable JSON sidecar.
|
||||
// Mirrors the WOL/WOW/WOMX/WSND JSON pairs — gives a
|
||||
// quick-author surface for hand-editing spawn entries
|
||||
// without writing a binary patcher. Vector fields are
|
||||
// emitted as 3-element arrays; kind and flags both have
|
||||
// dual int + string-array forms so the importer accepts
|
||||
// either.
|
||||
std::string base = argv[++i];
|
||||
std::string outPath;
|
||||
if (parseOptArg(i, argc, argv)) outPath = argv[++i];
|
||||
base = stripWspnExt(base);
|
||||
if (outPath.empty()) outPath = base + ".wspn.json";
|
||||
if (!wowee::pipeline::WoweeSpawnsLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wspn-json: WSPN not found: %s.wspn\n", base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeSpawnsLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
nlohmann::json je;
|
||||
je["kind"] = e.kind;
|
||||
je["kindName"] = wowee::pipeline::WoweeSpawns::kindName(e.kind);
|
||||
je["entryId"] = e.entryId;
|
||||
je["position"] = {e.position.x, e.position.y, e.position.z};
|
||||
je["rotation"] = {e.rotation.x, e.rotation.y, e.rotation.z};
|
||||
je["scale"] = e.scale;
|
||||
je["flags"] = e.flags;
|
||||
nlohmann::json fa = nlohmann::json::array();
|
||||
if (e.flags & wowee::pipeline::WoweeSpawns::Disabled)
|
||||
fa.push_back("disabled");
|
||||
if (e.flags & wowee::pipeline::WoweeSpawns::EventOnly)
|
||||
fa.push_back("event-only");
|
||||
if (e.flags & wowee::pipeline::WoweeSpawns::QuestPhased)
|
||||
fa.push_back("quest-phased");
|
||||
je["flagsList"] = fa;
|
||||
je["respawnSec"] = e.respawnSec;
|
||||
je["factionId"] = e.factionId;
|
||||
je["questIdRequired"] = e.questIdRequired;
|
||||
je["wanderRadius"] = e.wanderRadius;
|
||||
je["label"] = e.label;
|
||||
arr.push_back(je);
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream out(outPath);
|
||||
if (!out) {
|
||||
std::fprintf(stderr,
|
||||
"export-wspn-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.wspn\n", base.c_str());
|
||||
std::printf(" entries : %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 = ".wspn.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 = stripWspnExt(outBase);
|
||||
std::ifstream in(jsonPath);
|
||||
if (!in) {
|
||||
std::fprintf(stderr,
|
||||
"import-wspn-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-wspn-json: bad JSON in %s: %s\n",
|
||||
jsonPath.c_str(), e.what());
|
||||
return 1;
|
||||
}
|
||||
auto kindFromName = [](const std::string& s) -> uint8_t {
|
||||
if (s == "creature") return wowee::pipeline::WoweeSpawns::Creature;
|
||||
if (s == "object") return wowee::pipeline::WoweeSpawns::GameObject;
|
||||
if (s == "doodad") return wowee::pipeline::WoweeSpawns::Doodad;
|
||||
return wowee::pipeline::WoweeSpawns::Creature;
|
||||
};
|
||||
auto flagFromName = [](const std::string& s) -> uint32_t {
|
||||
if (s == "disabled") return wowee::pipeline::WoweeSpawns::Disabled;
|
||||
if (s == "event-only") return wowee::pipeline::WoweeSpawns::EventOnly;
|
||||
if (s == "quest-phased") return wowee::pipeline::WoweeSpawns::QuestPhased;
|
||||
return 0;
|
||||
};
|
||||
auto readVec3 = [](const nlohmann::json& jv, glm::vec3& v) {
|
||||
if (jv.is_array() && jv.size() >= 3) {
|
||||
v.x = jv[0].get<float>();
|
||||
v.y = jv[1].get<float>();
|
||||
v.z = jv[2].get<float>();
|
||||
}
|
||||
};
|
||||
wowee::pipeline::WoweeSpawns c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (j.contains("entries") && j["entries"].is_array()) {
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeSpawns::Entry e;
|
||||
if (je.contains("kind") && je["kind"].is_number_integer()) {
|
||||
e.kind = static_cast<uint8_t>(je["kind"].get<int>());
|
||||
} else if (je.contains("kindName") && je["kindName"].is_string()) {
|
||||
e.kind = kindFromName(je["kindName"].get<std::string>());
|
||||
}
|
||||
e.entryId = je.value("entryId", 0u);
|
||||
if (je.contains("position")) readVec3(je["position"], e.position);
|
||||
if (je.contains("rotation")) readVec3(je["rotation"], e.rotation);
|
||||
e.scale = je.value("scale", 1.0f);
|
||||
if (je.contains("flags") && je["flags"].is_number_integer()) {
|
||||
e.flags = je["flags"].get<uint32_t>();
|
||||
} else if (je.contains("flagsList") && je["flagsList"].is_array()) {
|
||||
for (const auto& f : je["flagsList"]) {
|
||||
if (f.is_string()) e.flags |= flagFromName(f.get<std::string>());
|
||||
}
|
||||
}
|
||||
e.respawnSec = je.value("respawnSec", 0u);
|
||||
e.factionId = je.value("factionId", 0u);
|
||||
e.questIdRequired = je.value("questIdRequired", 0u);
|
||||
e.wanderRadius = je.value("wanderRadius", 0.0f);
|
||||
e.label = je.value("label", std::string{});
|
||||
c.entries.push_back(std::move(e));
|
||||
}
|
||||
}
|
||||
if (!wowee::pipeline::WoweeSpawnsLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wspn-json: failed to save %s.wspn\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wspn\n", outBase.c_str());
|
||||
std::printf(" source : %s\n", jsonPath.c_str());
|
||||
std::printf(" entries : %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);
|
||||
|
|
@ -246,6 +398,12 @@ bool handleSpawnsCatalog(int& i, int argc, char** argv, int& outRc) {
|
|||
if (std::strcmp(argv[i], "--validate-wspn") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wspn-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wspn-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue