mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 11:03:51 +00:00
feat(editor): add WHLD JSON round-trip (--export/--import-whld-json)
Closes the editing loop on the instance-lockout catalog: dump a
.whld to JSON, hand-edit raidLockoutKind / resetIntervalMs /
maxBossKillsPerLockout / raidGroupSize / bonusRolls (e.g. switch
ICC 25-Heroic from Weekly to SemiWeekly for a faster server,
raise Wintergrasp's reset from 2.5h to 3h, mark a custom
heroic+ tier with bonus rolls), re-import to a byte-identical
binary.
raidLockoutKind dual-encoded: int 0..3 OR human-readable name
("daily" / "weekly" / "semi-weekly" / "custom"). All other
fields are scalar uint32/uint8 so no dual encoding needed.
Verified byte-identical round-trip on all three presets
(raid / dungeon / event). The event preset's mixed kinds (2
Daily + 1 Custom 2.5h) round-trip exactly, confirming that the
Custom kind's arbitrary intervalMs preserves through the JSON
serialization. CLI flag count 1067 -> 1069.
This commit is contained in:
parent
321c2610d0
commit
3f65e63ca1
3 changed files with 151 additions and 0 deletions
|
|
@ -284,6 +284,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wbos-json", "--import-wbos-json",
|
||||
"--gen-hld", "--gen-hld-dungeon", "--gen-hld-event",
|
||||
"--info-whld", "--validate-whld",
|
||||
"--export-whld-json", "--import-whld-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -2051,6 +2051,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WHLD entries (id / map / diff / kind / interval (formatted) / boss kills / size / bonus rolls / name)\n");
|
||||
std::printf(" --validate-whld <whld-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name+kind+interval required, no duplicate ids; warns on non-standard group size, kind/interval mismatches (Daily not 24h, Weekly not 7d), 0 boss kill cap\n");
|
||||
std::printf(" --export-whld-json <whld-base> [out.json]\n");
|
||||
std::printf(" Export binary .whld to a human-editable JSON sidecar (defaults to <base>.whld.json)\n");
|
||||
std::printf(" --import-whld-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .whld.json sidecar back into binary .whld (accepts raidLockoutKind int OR raidLockoutKindName 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");
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include "pipeline/wowee_instance_lockouts.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
|
@ -140,6 +141,145 @@ 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 = stripWhldExt(base);
|
||||
if (!wowee::pipeline::WoweeInstanceLockoutLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-whld-json: WHLD not found: %s.whld\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeInstanceLockoutLoader::load(base);
|
||||
if (outPath.empty()) outPath = base + ".whld.json";
|
||||
nlohmann::json j;
|
||||
j["catalog"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
nlohmann::json je;
|
||||
je["lockoutId"] = e.lockoutId;
|
||||
je["name"] = e.name;
|
||||
je["description"] = e.description;
|
||||
je["mapId"] = e.mapId;
|
||||
je["difficultyId"] = e.difficultyId;
|
||||
je["resetIntervalMs"] = e.resetIntervalMs;
|
||||
je["maxBossKillsPerLockout"] = e.maxBossKillsPerLockout;
|
||||
je["bonusRolls"] = e.bonusRolls;
|
||||
je["raidLockoutKind"] = e.raidLockoutKind;
|
||||
je["raidLockoutKindName"] =
|
||||
wowee::pipeline::WoweeInstanceLockout::lockoutKindName(e.raidLockoutKind);
|
||||
je["raidGroupSize"] = e.raidGroupSize;
|
||||
je["iconColorRGBA"] = e.iconColorRGBA;
|
||||
arr.push_back(je);
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(outPath);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-whld-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(" lockouts : %zu\n", c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t parseLockoutKindToken(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::WoweeInstanceLockout::Custom)
|
||||
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 == "daily") return wowee::pipeline::WoweeInstanceLockout::Daily;
|
||||
if (s == "weekly") return wowee::pipeline::WoweeInstanceLockout::Weekly;
|
||||
if (s == "semi-weekly" ||
|
||||
s == "semiweekly") return wowee::pipeline::WoweeInstanceLockout::SemiWeekly;
|
||||
if (s == "custom") return wowee::pipeline::WoweeInstanceLockout::Custom;
|
||||
}
|
||||
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-whld-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-whld-json: parse error in %s: %s\n",
|
||||
jsonPath.c_str(), ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeInstanceLockout 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::WoweeInstanceLockout::Entry e;
|
||||
if (je.contains("lockoutId")) e.lockoutId = je["lockoutId"].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("mapId")) e.mapId = je["mapId"].get<uint32_t>();
|
||||
if (je.contains("difficultyId")) e.difficultyId = je["difficultyId"].get<uint32_t>();
|
||||
if (je.contains("resetIntervalMs")) e.resetIntervalMs = je["resetIntervalMs"].get<uint32_t>();
|
||||
if (je.contains("maxBossKillsPerLockout")) e.maxBossKillsPerLockout = je["maxBossKillsPerLockout"].get<uint8_t>();
|
||||
if (je.contains("bonusRolls")) e.bonusRolls = je["bonusRolls"].get<uint8_t>();
|
||||
uint8_t kind = wowee::pipeline::WoweeInstanceLockout::Weekly;
|
||||
if (je.contains("raidLockoutKind"))
|
||||
kind = parseLockoutKindToken(je["raidLockoutKind"], kind);
|
||||
else if (je.contains("raidLockoutKindName"))
|
||||
kind = parseLockoutKindToken(je["raidLockoutKindName"], kind);
|
||||
e.raidLockoutKind = kind;
|
||||
if (je.contains("raidGroupSize")) e.raidGroupSize = je["raidGroupSize"].get<uint8_t>();
|
||||
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 = ".whld.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 = stripWhldExt(outBase);
|
||||
if (!wowee::pipeline::WoweeInstanceLockoutLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-whld-json: failed to save %s.whld\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.whld\n", outBase.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" lockouts : %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);
|
||||
|
|
@ -258,6 +398,12 @@ bool handleInstanceLockoutsCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-whld") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-whld-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-whld-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