mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WLMA JSON round-trip (--export/--import-wlma-json)
Dual encoding for both modeKind fields (the primary
modeKind AND the timeoutFallbackKind disconnect-fallback)
via the readEnumField template — both accept int 0..5
OR token "freeforall"/"roundrobin"/"masterloot"/
"needbeforegreed"/"personal"/"disenchant".
masterLooterRequired accepts bool or int.
thresholdQuality serializes as both int (authoritative,
0..7) AND derived qualityName string ("Poor"/"Common"/
"Uncommon"/"Rare"/"Epic"/"Legendary"/"Artifact"/
"Heirloom") for human-readable JSON. The qualityName is
informational only — int form is authoritative on
import.
All 3 presets (standard/raid/afk) byte-identical
roundtrip OK. CLI flag count 1253 -> 1255.
This commit is contained in:
parent
6fa81cf185
commit
637a63e395
3 changed files with 186 additions and 0 deletions
|
|
@ -364,6 +364,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wmar-json", "--import-wmar-json",
|
||||
"--gen-lma", "--gen-lma-raid", "--gen-lma-afk",
|
||||
"--info-wlma", "--validate-wlma",
|
||||
"--export-wlma-json", "--import-wlma-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -2415,6 +2415,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WLMA entries (id / kind / threshold quality / master-looter required / idle skip seconds / fallback kind / name)\n");
|
||||
std::printf(" --validate-wlma <wlma-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name required, modeKind 0..5, thresholdQuality 0..7, no duplicate modeIds, MasterLoot kind REQUIRES masterLooterRequired=1 (else self-contradicting); warns on Personal kind with masterLooterRequired=1 (no-op flag), timeoutFallbackKind == modeKind (fallback to self is no-op)\n");
|
||||
std::printf(" --export-wlma-json <wlma-base> [out.json]\n");
|
||||
std::printf(" Export binary .wlma to a human-editable JSON sidecar (defaults to <base>.wlma.json; emits both modeKind and timeoutFallbackKind as int + name string; thresholdQuality also gets a derived qualityName string)\n");
|
||||
std::printf(" --import-wlma-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wlma.json sidecar back into binary .wlma (modeKind / timeoutFallbackKind int OR \"freeforall\"/\"roundrobin\"/\"masterloot\"/\"needbeforegreed\"/\"personal\"/\"disenchant\"; masterLooterRequired accepts bool OR int)\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");
|
||||
|
|
|
|||
|
|
@ -156,6 +156,181 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parseModeKindToken(const std::string& s) {
|
||||
using L = wowee::pipeline::WoweeLootModes;
|
||||
if (s == "freeforall") return L::FreeForAll;
|
||||
if (s == "roundrobin") return L::RoundRobin;
|
||||
if (s == "masterloot") return L::MasterLoot;
|
||||
if (s == "needbeforegreed") return L::NeedBeforeGreed;
|
||||
if (s == "personal") return L::Personal;
|
||||
if (s == "disenchant") return L::Disenchant;
|
||||
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-wlma-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 handleExportJson(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
std::string out;
|
||||
if (parseOptArg(i, argc, argv)) out = argv[++i];
|
||||
base = stripWlmaExt(base);
|
||||
if (out.empty()) out = base + ".wlma.json";
|
||||
if (!wowee::pipeline::WoweeLootModesLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wlma-json: WLMA not found: %s.wlma\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeLootModesLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WLMA";
|
||||
j["version"] = 1;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"modeId", e.modeId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"modeKind", e.modeKind},
|
||||
{"modeKindName", modeKindName(e.modeKind)},
|
||||
{"thresholdQuality", e.thresholdQuality},
|
||||
{"thresholdQualityName",
|
||||
qualityName(e.thresholdQuality)},
|
||||
{"masterLooterRequired",
|
||||
e.masterLooterRequired != 0},
|
||||
{"idleSkipSec", e.idleSkipSec},
|
||||
{"timeoutFallbackKind", e.timeoutFallbackKind},
|
||||
{"timeoutFallbackKindName",
|
||||
modeKindName(e.timeoutFallbackKind)},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wlma-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu modes)\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) == ".wlma.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wlma");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wlma-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-wlma-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeLootModes c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wlma-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeLootModes::Entry e;
|
||||
e.modeId = je.value("modeId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
if (!readEnumField(je, "modeKind", "modeKindName",
|
||||
parseModeKindToken, "modeKind",
|
||||
e.modeId, e.modeKind)) return 1;
|
||||
e.thresholdQuality = static_cast<uint8_t>(
|
||||
je.value("thresholdQuality", 2u));
|
||||
if (je.contains("masterLooterRequired")) {
|
||||
const auto& v = je["masterLooterRequired"];
|
||||
if (v.is_boolean())
|
||||
e.masterLooterRequired = v.get<bool>() ? 1 : 0;
|
||||
else if (v.is_number_integer())
|
||||
e.masterLooterRequired = static_cast<uint8_t>(
|
||||
v.get<int>() != 0 ? 1 : 0);
|
||||
}
|
||||
e.idleSkipSec = static_cast<uint8_t>(
|
||||
je.value("idleSkipSec", 0u));
|
||||
if (!readEnumField(je, "timeoutFallbackKind",
|
||||
"timeoutFallbackKindName",
|
||||
parseModeKindToken,
|
||||
"timeoutFallbackKind",
|
||||
e.modeId,
|
||||
e.timeoutFallbackKind)) return 1;
|
||||
e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu);
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweeLootModesLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wlma-json: failed to save %s.wlma\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wlma (%zu modes)\n",
|
||||
outBase.c_str(), c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handleValidate(int& i, int argc, char** argv) {
|
||||
std::string base = argv[++i];
|
||||
bool jsonOut = consumeJsonFlag(i, argc, argv);
|
||||
|
|
@ -293,6 +468,12 @@ bool handleLootModesCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wlma") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wlma-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wlma-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