mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): add WIFS JSON round-trip (--export/--import-wifs-json)
Closes the editing loop on the item-flag bit catalog: dump a
.wifs to JSON, hand-edit bitMask hex / flagKind / isPositive
(e.g. add a server-custom Heroic25man flag at bit 0x10000000,
re-tag NoLoot from Drop kind to Quality kind, mark BindToAccount
as positive for an account-wide-loot server), re-import to a
byte-identical binary.
Two dual-encoded fields:
- flagKind: int 0..6 OR "quality" / "drop" / "trade" /
"magic" / "account" / "server" / "misc"
- isPositive: bool OR int (machine-generated sidecars work
too)
Hex bitMasks export as raw uint32 — pasting "0x40000000" hex
values into JSON works directly.
Verified byte-identical round-trip on all three presets
(std / bind / srv). CLI flag count 1023 -> 1025.
This commit is contained in:
parent
0ceb70f3e7
commit
fd0e2cc50b
3 changed files with 150 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#include "pipeline/wowee_item_flags.hpp"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
|
@ -119,6 +120,144 @@ 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 = stripWifsExt(base);
|
||||
if (!wowee::pipeline::WoweeItemFlagsLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wifs-json: WIFS not found: %s.wifs\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeItemFlagsLoader::load(base);
|
||||
if (outPath.empty()) outPath = base + ".wifs.json";
|
||||
nlohmann::json j;
|
||||
j["catalog"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
nlohmann::json je;
|
||||
je["flagId"] = e.flagId;
|
||||
je["name"] = e.name;
|
||||
je["description"] = e.description;
|
||||
je["bitMask"] = e.bitMask;
|
||||
je["flagKind"] = e.flagKind;
|
||||
je["flagKindName"] =
|
||||
wowee::pipeline::WoweeItemFlags::flagKindName(e.flagKind);
|
||||
je["isPositive"] = e.isPositive != 0;
|
||||
je["iconColorRGBA"] = e.iconColorRGBA;
|
||||
arr.push_back(je);
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(outPath);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wifs-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(" flags : %zu\n", c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t parseFlagKindToken(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::WoweeItemFlags::Misc)
|
||||
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 == "quality") return wowee::pipeline::WoweeItemFlags::Quality;
|
||||
if (s == "drop") return wowee::pipeline::WoweeItemFlags::Drop;
|
||||
if (s == "trade") return wowee::pipeline::WoweeItemFlags::Trade;
|
||||
if (s == "magic") return wowee::pipeline::WoweeItemFlags::Magic;
|
||||
if (s == "account") return wowee::pipeline::WoweeItemFlags::Account;
|
||||
if (s == "server") return wowee::pipeline::WoweeItemFlags::Server;
|
||||
if (s == "misc") return wowee::pipeline::WoweeItemFlags::Misc;
|
||||
}
|
||||
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-wifs-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-wifs-json: parse error in %s: %s\n",
|
||||
jsonPath.c_str(), ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeItemFlags 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::WoweeItemFlags::Entry e;
|
||||
if (je.contains("flagId")) e.flagId = je["flagId"].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("bitMask")) e.bitMask = je["bitMask"].get<uint32_t>();
|
||||
uint8_t kind = wowee::pipeline::WoweeItemFlags::Misc;
|
||||
if (je.contains("flagKind"))
|
||||
kind = parseFlagKindToken(je["flagKind"], kind);
|
||||
else if (je.contains("flagKindName"))
|
||||
kind = parseFlagKindToken(je["flagKindName"], kind);
|
||||
e.flagKind = kind;
|
||||
if (je.contains("isPositive")) {
|
||||
if (je["isPositive"].is_boolean())
|
||||
e.isPositive = je["isPositive"].get<bool>() ? 1 : 0;
|
||||
else
|
||||
e.isPositive = je["isPositive"].get<uint8_t>() ? 1 : 0;
|
||||
}
|
||||
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 = ".wifs.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 = stripWifsExt(outBase);
|
||||
if (!wowee::pipeline::WoweeItemFlagsLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wifs-json: failed to save %s.wifs\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wifs\n", outBase.c_str());
|
||||
std::printf(" catalog : %s\n", c.name.c_str());
|
||||
std::printf(" flags : %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);
|
||||
|
|
@ -235,6 +374,12 @@ bool handleItemFlagsCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wifs") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wifs-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wifs-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