mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-11 03:23:51 +00:00
feat(editor): WGCH JSON round-trip closure
Adds --export-wgch-json / --import-wgch-json with the established
readEnumField template factoring int+name dual encoding for both
channelKind ("global"/"realmzone"/"faction"/"custom") and accessKind
("publicjoin"/"inviteonly"/"autojoinonzone"/"moderated").
All 3 presets (std-channels / roleplay / admin) byte-identical
binary roundtrip OK including the zoneDefaultMapId=1519 Stormwind
auto-join binding on TradeStormwind. Validators pass on round-
tripped binaries.
CLI flag count 1317 -> 1319.
This commit is contained in:
parent
c7d85fc598
commit
09ad03ca34
3 changed files with 181 additions and 0 deletions
|
|
@ -382,6 +382,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wlan-json", "--import-wlan-json",
|
||||
"--gen-gch", "--gen-gch-rp", "--gen-gch-admin",
|
||||
"--info-wgch", "--validate-wgch",
|
||||
"--export-wgch-json", "--import-wgch-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -46,6 +46,62 @@ const char* accessKindName(uint8_t k) {
|
|||
}
|
||||
}
|
||||
|
||||
int parseChannelKindToken(const std::string& s) {
|
||||
using G = wowee::pipeline::WoweeGlobalChannels;
|
||||
if (s == "global") return G::Global;
|
||||
if (s == "realmzone") return G::RealmZone;
|
||||
if (s == "faction") return G::Faction;
|
||||
if (s == "custom") return G::Custom;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int parseAccessKindToken(const std::string& s) {
|
||||
using G = wowee::pipeline::WoweeGlobalChannels;
|
||||
if (s == "publicjoin") return G::PublicJoin;
|
||||
if (s == "inviteonly") return G::InviteOnly;
|
||||
if (s == "autojoinonzone") return G::AutoJoinOnZone;
|
||||
if (s == "moderated") return G::Moderated;
|
||||
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-wgch-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;
|
||||
}
|
||||
|
||||
bool saveOrError(const wowee::pipeline::WoweeGlobalChannels& c,
|
||||
const std::string& base, const char* cmd) {
|
||||
if (!wowee::pipeline::WoweeGlobalChannelsLoader::save(c, base)) {
|
||||
|
|
@ -255,6 +311,120 @@ int handleValidate(int& i, int argc, char** argv) {
|
|||
return ok ? 0 : 1;
|
||||
}
|
||||
|
||||
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 = stripWgchExt(base);
|
||||
if (out.empty()) out = base + ".wgch.json";
|
||||
if (!wowee::pipeline::WoweeGlobalChannelsLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wgch-json: WGCH not found: %s.wgch\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeGlobalChannelsLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WGCH";
|
||||
j["version"] = 1;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"channelId", e.channelId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"channelKind", e.channelKind},
|
||||
{"channelKindName", channelKindName(e.channelKind)},
|
||||
{"accessKind", e.accessKind},
|
||||
{"accessKindName", accessKindName(e.accessKind)},
|
||||
{"passwordRequired", e.passwordRequired != 0},
|
||||
{"levelMin", e.levelMin},
|
||||
{"maxMembers", e.maxMembers},
|
||||
{"topicSetByMods", e.topicSetByMods != 0},
|
||||
{"zoneDefaultMapId", e.zoneDefaultMapId},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wgch-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu channels)\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) == ".wgch.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wgch");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgch-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-wgch-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeGlobalChannels c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgch-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeGlobalChannels::Entry e;
|
||||
e.channelId = je.value("channelId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
if (!readEnumField(je, "channelKind", "channelKindName",
|
||||
parseChannelKindToken, "channelKind",
|
||||
e.channelId, e.channelKind)) return 1;
|
||||
if (!readEnumField(je, "accessKind", "accessKindName",
|
||||
parseAccessKindToken, "accessKind",
|
||||
e.channelId, e.accessKind)) return 1;
|
||||
e.passwordRequired = je.value("passwordRequired", false) ? 1 : 0;
|
||||
e.levelMin = static_cast<uint8_t>(je.value("levelMin", 0));
|
||||
e.maxMembers = static_cast<uint16_t>(je.value("maxMembers", 0));
|
||||
e.topicSetByMods = je.value("topicSetByMods", true) ? 1 : 0;
|
||||
e.zoneDefaultMapId = je.value("zoneDefaultMapId", 0u);
|
||||
e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu);
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweeGlobalChannelsLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wgch-json: failed to save %s.wgch\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wgch (%zu channels)\n",
|
||||
outBase.c_str(), c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool handleGlobalChannelsCatalog(int& i, int argc, char** argv,
|
||||
|
|
@ -275,6 +445,12 @@ bool handleGlobalChannelsCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wgch") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wgch-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wgch-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2499,6 +2499,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WGCH entries (id / channelKind / accessKind / passwordRequired / levelMin / maxMembers / zoneDefaultMapId / name)\n");
|
||||
std::printf(" --validate-wgch <wgch-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name required, channelKind 0..3, accessKind 0..3, no duplicate channelIds, no duplicate channel names (chat /join routing collision), AutoJoinOnZone REQUIRES zoneDefaultMapId; warns on dead zoneDefaultMapId set with non-AutoJoin kind\n");
|
||||
std::printf(" --export-wgch-json <wgch-base> [out.json]\n");
|
||||
std::printf(" Export binary .wgch to a human-editable JSON sidecar (defaults to <base>.wgch.json; emits both channelKind and accessKind as int + name string)\n");
|
||||
std::printf(" --import-wgch-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wgch.json sidecar back into binary .wgch (channelKind int OR \"global\"/\"realmzone\"/\"faction\"/\"custom\"; accessKind int OR \"publicjoin\"/\"inviteonly\"/\"autojoinonzone\"/\"moderated\")\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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue