feat(editor): add WSPR JSON round-trip (--export/--import-wspr-json)

Closes the editing loop on the spell-reagent catalog: dump a
.wspr to JSON, hand-edit reagentKind / spellId / per-slot
itemId+count pairs (e.g. swap a Mage Portal's reagent from Rune
of Portals to a server-custom item, change a Warlock summon to
need 2 Soul Shards instead of 1, add Tier-3 Catalyst entries
for upgraded spell variants), re-import to a byte-identical
binary.

Reagent slot arrays (8 itemIds, 8 counts) are exported as JSON
arrays — easier to read and edit than 16 individual numbered
fields. Importer pads arrays shorter than 8 with zeros and
silently truncates longer arrays, so hand-edited sidecars don't
need to spell out every empty slot.

The exporter emits both reagentKind (int 0..4) and the human-
readable reagentKindName ("standard" / "soul-shard" /
"focused-item" / "catalyst" / "tradeable"); the importer accepts
either form.

Verified byte-identical round-trip on all three presets
(mage / warlock / rez). CLI flag count 979 -> 981.
This commit is contained in:
Kelsi 2026-05-09 22:40:12 -07:00
parent d97f4bf5db
commit 8e85278d89
3 changed files with 171 additions and 0 deletions

View file

@ -246,6 +246,7 @@ const char* const kArgRequired[] = {
"--export-wctr-json", "--import-wctr-json",
"--gen-spr", "--gen-spr-warlock", "--gen-spr-rez",
"--info-wspr", "--validate-wspr",
"--export-wspr-json", "--import-wspr-json",
"--gen-weather-temperate", "--gen-weather-arctic",
"--gen-weather-desert", "--gen-weather-stormy",
"--gen-zone-atmosphere",

View file

@ -1875,6 +1875,10 @@ void printUsage(const char* argv0) {
std::printf(" Print WSPR entries (id / spellId / kind / used slot count / item x count list / name)\n");
std::printf(" --validate-wspr <wspr-base> [--json]\n");
std::printf(" Static checks: id+name+spellId required, reagentKind 0..4, no duplicate ids; warns on slot id/count mismatch, SoulShard kind with non-canonical reagent, FocusedItem kind with no slots, duplicate spellId\n");
std::printf(" --export-wspr-json <wspr-base> [out.json]\n");
std::printf(" Export binary .wspr to a human-editable JSON sidecar (defaults to <base>.wspr.json). Reagent slot arrays exported as JSON arrays\n");
std::printf(" --import-wspr-json <json-path> [out-base]\n");
std::printf(" Import a .wspr.json sidecar back into binary .wspr (accepts reagentKind int OR reagentKindName string; reagent arrays pad with zeros if shorter than 8)\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");

View file

@ -5,6 +5,7 @@
#include "pipeline/wowee_spell_reagents.hpp"
#include <nlohmann/json.hpp>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstring>
@ -135,6 +136,165 @@ 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 = stripWsprExt(base);
if (!wowee::pipeline::WoweeSpellReagentLoader::exists(base)) {
std::fprintf(stderr,
"export-wspr-json: WSPR not found: %s.wspr\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeSpellReagentLoader::load(base);
if (outPath.empty()) outPath = base + ".wspr.json";
nlohmann::json j;
j["catalog"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
nlohmann::json items = nlohmann::json::array();
nlohmann::json counts = nlohmann::json::array();
for (int s = 0; s < wowee::pipeline::WoweeSpellReagent::kMaxReagentSlots; ++s) {
items.push_back(e.reagentItemId[s]);
counts.push_back(e.reagentCount[s]);
}
nlohmann::json je;
je["reagentSetId"] = e.reagentSetId;
je["name"] = e.name;
je["description"] = e.description;
je["spellId"] = e.spellId;
je["reagentItemId"] = items;
je["reagentCount"] = counts;
je["reagentKind"] = e.reagentKind;
je["reagentKindName"] =
wowee::pipeline::WoweeSpellReagent::reagentKindName(e.reagentKind);
je["iconColorRGBA"] = e.iconColorRGBA;
arr.push_back(je);
}
j["entries"] = arr;
std::ofstream os(outPath);
if (!os) {
std::fprintf(stderr,
"export-wspr-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(" sets : %zu\n", c.entries.size());
return 0;
}
uint8_t parseReagentKindToken(const nlohmann::json& jv,
uint8_t fallback) {
if (jv.is_number_integer() || jv.is_number_unsigned()) {
int v = jv.get<int>();
if (v < 0 || v > wowee::pipeline::WoweeSpellReagent::Tradeable)
return fallback;
return static_cast<uint8_t>(v);
}
if (jv.is_string()) {
std::string s = jv.get<std::string>();
for (auto& ch : s) ch = static_cast<char>(std::tolower(ch));
if (s == "standard") return wowee::pipeline::WoweeSpellReagent::Standard;
if (s == "soul-shard" ||
s == "soulshard") return wowee::pipeline::WoweeSpellReagent::SoulShard;
if (s == "focused-item" ||
s == "focuseditem") return wowee::pipeline::WoweeSpellReagent::FocusedItem;
if (s == "catalyst") return wowee::pipeline::WoweeSpellReagent::Catalyst;
if (s == "tradeable") return wowee::pipeline::WoweeSpellReagent::Tradeable;
}
return fallback;
}
// Read the reagentItemId / reagentCount fixed-length array
// fields from the JSON sidecar. Pads with zeros if the
// JSON array is shorter than kMaxReagentSlots, truncates
// silently if longer (extra entries dropped).
void readReagentSlotArray(const nlohmann::json& arr,
uint32_t out[wowee::pipeline::WoweeSpellReagent::kMaxReagentSlots]) {
for (int s = 0; s < wowee::pipeline::WoweeSpellReagent::kMaxReagentSlots; ++s)
out[s] = 0;
if (!arr.is_array()) return;
int n = std::min<int>(arr.size(),
wowee::pipeline::WoweeSpellReagent::kMaxReagentSlots);
for (int s = 0; s < n; ++s)
out[s] = arr[s].get<uint32_t>();
}
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-wspr-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-wspr-json: parse error in %s: %s\n",
jsonPath.c_str(), ex.what());
return 1;
}
wowee::pipeline::WoweeSpellReagent c;
if (j.contains("catalog") && j["catalog"].is_string())
c.name = j["catalog"].get<std::string>();
if (j.contains("entries") && j["entries"].is_array()) {
for (const auto& je : j["entries"]) {
wowee::pipeline::WoweeSpellReagent::Entry e;
if (je.contains("reagentSetId")) e.reagentSetId = je["reagentSetId"].get<uint32_t>();
if (je.contains("name")) e.name = je["name"].get<std::string>();
if (je.contains("description")) e.description = je["description"].get<std::string>();
if (je.contains("spellId")) e.spellId = je["spellId"].get<uint32_t>();
if (je.contains("reagentItemId"))
readReagentSlotArray(je["reagentItemId"], e.reagentItemId);
if (je.contains("reagentCount"))
readReagentSlotArray(je["reagentCount"], e.reagentCount);
uint8_t kind = wowee::pipeline::WoweeSpellReagent::Standard;
if (je.contains("reagentKind"))
kind = parseReagentKindToken(je["reagentKind"], kind);
else if (je.contains("reagentKindName"))
kind = parseReagentKindToken(je["reagentKindName"], kind);
e.reagentKind = kind;
if (je.contains("iconColorRGBA"))
e.iconColorRGBA = je["iconColorRGBA"].get<uint32_t>();
c.entries.push_back(e);
}
}
if (outBase.empty()) {
outBase = jsonPath;
const std::string suffix1 = ".wspr.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 = stripWsprExt(outBase);
if (!wowee::pipeline::WoweeSpellReagentLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wspr-json: failed to save %s.wspr\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wspr\n", outBase.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" sets : %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);
@ -275,6 +435,12 @@ bool handleSpellReagentsCatalog(int& i, int argc, char** argv,
if (std::strcmp(argv[i], "--validate-wspr") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wspr-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wspr-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}