feat(editor): add WCDF JSON round-trip (--export/--import-wcdf-json)

Closes the editing loop on the creature-difficulty routing
catalog: dump a .wcdf to JSON, hand-edit baseCreatureId / 4
variant ids / spawnGroupKind (e.g. swap a Lich King variant from
heroic25Id 39168 to a custom encore template, change a 5-man
boss from Boss to MiniBoss kind, route a new world boss through
the WorldBoss kind), re-import to a byte-identical binary.

The exporter emits both spawnGroupKind (int 0..5) and the human-
readable spawnGroupKindName ("boss" / "mini-boss" / "rare-elite"
/ "trash" / "add" / "world-boss"); the importer accepts either
form.

Verified byte-identical round-trip on all three presets
(starter / wotlk / fiveman). CLI flag count 941 -> 943.
This commit is contained in:
Kelsi 2026-05-09 22:11:16 -07:00
parent fa8719009b
commit 75c254925f
3 changed files with 154 additions and 0 deletions

View file

@ -5,6 +5,7 @@
#include "pipeline/wowee_creature_difficulties.hpp"
#include <nlohmann/json.hpp>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstring>
@ -125,6 +126,148 @@ 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 = stripWcdfExt(base);
if (!wowee::pipeline::WoweeCreatureDifficultyLoader::exists(base)) {
std::fprintf(stderr,
"export-wcdf-json: WCDF not found: %s.wcdf\n",
base.c_str());
return 1;
}
auto c = wowee::pipeline::WoweeCreatureDifficultyLoader::load(base);
if (outPath.empty()) outPath = base + ".wcdf.json";
nlohmann::json j;
j["catalog"] = c.name;
nlohmann::json arr = nlohmann::json::array();
for (const auto& e : c.entries) {
nlohmann::json je;
je["difficultyId"] = e.difficultyId;
je["name"] = e.name;
je["description"] = e.description;
je["baseCreatureId"] = e.baseCreatureId;
je["normal10Id"] = e.normal10Id;
je["normal25Id"] = e.normal25Id;
je["heroic10Id"] = e.heroic10Id;
je["heroic25Id"] = e.heroic25Id;
je["spawnGroupKind"] = e.spawnGroupKind;
je["spawnGroupKindName"] =
wowee::pipeline::WoweeCreatureDifficulty::spawnGroupKindName(e.spawnGroupKind);
je["iconColorRGBA"] = e.iconColorRGBA;
arr.push_back(je);
}
j["entries"] = arr;
std::ofstream os(outPath);
if (!os) {
std::fprintf(stderr,
"export-wcdf-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(" routes : %zu\n", c.entries.size());
return 0;
}
uint8_t parseSpawnGroupKindToken(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::WoweeCreatureDifficulty::WorldBoss)
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 == "boss") return wowee::pipeline::WoweeCreatureDifficulty::Boss;
if (s == "mini-boss" ||
s == "miniboss") return wowee::pipeline::WoweeCreatureDifficulty::MiniBoss;
if (s == "rare-elite" ||
s == "rareelite") return wowee::pipeline::WoweeCreatureDifficulty::RareElite;
if (s == "trash") return wowee::pipeline::WoweeCreatureDifficulty::Trash;
if (s == "add") return wowee::pipeline::WoweeCreatureDifficulty::Add;
if (s == "world-boss" ||
s == "worldboss") return wowee::pipeline::WoweeCreatureDifficulty::WorldBoss;
}
return fallback;
}
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-wcdf-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-wcdf-json: parse error in %s: %s\n",
jsonPath.c_str(), ex.what());
return 1;
}
wowee::pipeline::WoweeCreatureDifficulty 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::WoweeCreatureDifficulty::Entry e;
if (je.contains("difficultyId")) e.difficultyId = je["difficultyId"].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("baseCreatureId")) e.baseCreatureId = je["baseCreatureId"].get<uint32_t>();
if (je.contains("normal10Id")) e.normal10Id = je["normal10Id"].get<uint32_t>();
if (je.contains("normal25Id")) e.normal25Id = je["normal25Id"].get<uint32_t>();
if (je.contains("heroic10Id")) e.heroic10Id = je["heroic10Id"].get<uint32_t>();
if (je.contains("heroic25Id")) e.heroic25Id = je["heroic25Id"].get<uint32_t>();
uint8_t kind = wowee::pipeline::WoweeCreatureDifficulty::Boss;
if (je.contains("spawnGroupKind"))
kind = parseSpawnGroupKindToken(je["spawnGroupKind"], kind);
else if (je.contains("spawnGroupKindName"))
kind = parseSpawnGroupKindToken(je["spawnGroupKindName"], kind);
e.spawnGroupKind = 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 = ".wcdf.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 = stripWcdfExt(outBase);
if (!wowee::pipeline::WoweeCreatureDifficultyLoader::save(c, outBase)) {
std::fprintf(stderr,
"import-wcdf-json: failed to save %s.wcdf\n",
outBase.c_str());
return 1;
}
std::printf("Wrote %s.wcdf\n", outBase.c_str());
std::printf(" catalog : %s\n", c.name.c_str());
std::printf(" routes : %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);
@ -263,6 +406,12 @@ bool handleCreatureDifficultiesCatalog(int& i, int argc,
if (std::strcmp(argv[i], "--validate-wcdf") == 0 && i + 1 < argc) {
outRc = handleValidate(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--export-wcdf-json") == 0 && i + 1 < argc) {
outRc = handleExportJson(i, argc, argv); return true;
}
if (std::strcmp(argv[i], "--import-wcdf-json") == 0 && i + 1 < argc) {
outRc = handleImportJson(i, argc, argv); return true;
}
return false;
}