mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 11:33:52 +00:00
feat(editor): WPRT JSON round-trip closure
Adds --export-wprt-json / --import-wprt-json with the established
readEnumField template factoring int+name dual encoding for both
factionAccess ("both"/"alliance"/"horde"/"neutral") and portalKind
("teleport"/"portal"). Float fields (destX/Y/Z, destOrientation)
preserved bit-for-bit through JSON.
All 3 presets (alliance/horde/teleports) byte-identical binary
roundtrip OK including the Teleport: Orgrimmar Horde-faction
entry that crosses the otherwise-Alliance teleports preset.
Live-tested reagent-mismatch warning: hand-mutated Stormwind
Portal entry (Portal kind) to use Rune of Teleportation (17031
— Teleport reagent), validator correctly emitted: "Portal kind
with reagentItemId=17031 — vanilla group portals require Rune
of Portals (itemId 17032). Verify intentional".
CLI flag count 1362 -> 1364.
This commit is contained in:
parent
be3a253dcc
commit
f41f913a2a
3 changed files with 193 additions and 0 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 <wprt-base> [--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 <wprt-base> [out.json]\n");
|
||||
std::printf(" Export binary .wprt to a human-editable JSON sidecar (defaults to <base>.wprt.json; emits factionAccess and portalKind as int + name string; floats preserved bit-for-bit)\n");
|
||||
std::printf(" --import-wprt-json <json-path> [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 <wXXX-file> <id> [--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 <directory> <id> [--magic <WXXX>] [--json]\n");
|
||||
|
|
|
|||
|
|
@ -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 <typename ParseFn>
|
||||
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<std::string>());
|
||||
if (parsed < 0) {
|
||||
std::fprintf(stderr,
|
||||
"import-wprt-json: unknown %s token "
|
||||
"'%s' on entry id=%u\n",
|
||||
label, v.get<std::string>().c_str(),
|
||||
entryId);
|
||||
return false;
|
||||
}
|
||||
outValue = static_cast<uint8_t>(parsed);
|
||||
return true;
|
||||
}
|
||||
if (v.is_number_integer()) {
|
||||
outValue = static_cast<uint8_t>(v.get<int>());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (je.contains(nameKey) && je[nameKey].is_string()) {
|
||||
int parsed = parseFn(je[nameKey].get<std::string>());
|
||||
if (parsed >= 0) {
|
||||
outValue = static_cast<uint8_t>(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<uint8_t>(
|
||||
je.value("levelRequirement", 0));
|
||||
e.reagentCount = static_cast<uint8_t>(
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue