mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
feat(editor): add WLAN JSON round-trip (--export/--import-wlan-json)
Dual encoding for both WLAN enums via the readEnumField template: languageCode (int 0..10 OR token "enUS" / "enGB" / "deDE" / "esES" / "frFR" / "itIT" / "koKR" / "ptBR" / "ruRU" / "zhCN" / "zhTW") and namespace (int 0..7 OR token "ui" / "quest" / "item" / "spell" / "creature" / "tooltip" / "gossip" / "system"). UTF-8 round-trip preserved through JSON: nlohmann::json escapes multibyte sequences as \uXXXX surrogate pairs on export and decodes them back to bytes on import, producing byte-identical binary output. The Korean "취소" and Chinese "取消" UI translations from the preset round-trip cleanly through the binary -> JSON -> binary cycle. All 3 presets (ui-basics / quest-sample / tooltip-set) byte-identical roundtrip OK including the multibyte strings. CLI flag count 1288 -> 1290.
This commit is contained in:
parent
73323f0b9d
commit
cef571bb45
3 changed files with 190 additions and 0 deletions
|
|
@ -379,6 +379,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wprg-json", "--import-wprg-json",
|
||||
"--gen-lan", "--gen-lan-quest", "--gen-lan-tooltip",
|
||||
"--info-wlan", "--validate-wlan",
|
||||
"--export-wlan-json", "--import-wlan-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -2485,6 +2485,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WLAN entries (id / language / namespace / original key / localized text)\n");
|
||||
std::printf(" --validate-wlan <wlan-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name+originalKey required, languageCode 0..10 OR 255 Unknown, namespace 0..7, no duplicate stringIds, no two entries with same (originalKey, languageCode, namespace) triple (locale lookup tie); warns on empty localizedText (override would render blank, possibly worse than fallback)\n");
|
||||
std::printf(" --export-wlan-json <wlan-base> [out.json]\n");
|
||||
std::printf(" Export binary .wlan to a human-editable JSON sidecar (defaults to <base>.wlan.json; emits both languageCode and namespace as int + name string; UTF-8 multibyte strings preserved)\n");
|
||||
std::printf(" --import-wlan-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wlan.json sidecar back into binary .wlan (languageCode int OR \"enUS\"/\"enGB\"/\"deDE\"/\"esES\"/\"frFR\"/\"itIT\"/\"koKR\"/\"ptBR\"/\"ruRU\"/\"zhCN\"/\"zhTW\"; namespace int OR \"ui\"/\"quest\"/\"item\"/\"spell\"/\"creature\"/\"tooltip\"/\"gossip\"/\"system\")\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");
|
||||
|
|
|
|||
|
|
@ -158,6 +158,185 @@ int handleInfo(int& i, int argc, char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parseLanguageCodeToken(const std::string& s) {
|
||||
using L = wowee::pipeline::WoweeLocalization;
|
||||
if (s == "enUS") return L::enUS;
|
||||
if (s == "enGB") return L::enGB;
|
||||
if (s == "deDE") return L::deDE;
|
||||
if (s == "esES") return L::esES;
|
||||
if (s == "frFR") return L::frFR;
|
||||
if (s == "itIT") return L::itIT;
|
||||
if (s == "koKR") return L::koKR;
|
||||
if (s == "ptBR") return L::ptBR;
|
||||
if (s == "ruRU") return L::ruRU;
|
||||
if (s == "zhCN") return L::zhCN;
|
||||
if (s == "zhTW") return L::zhTW;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int parseNamespaceToken(const std::string& s) {
|
||||
using L = wowee::pipeline::WoweeLocalization;
|
||||
if (s == "ui") return L::UI;
|
||||
if (s == "quest") return L::Quest;
|
||||
if (s == "item") return L::Item;
|
||||
if (s == "spell") return L::Spell;
|
||||
if (s == "creature") return L::Creature;
|
||||
if (s == "tooltip") return L::Tooltip;
|
||||
if (s == "gossip") return L::Gossip;
|
||||
if (s == "system") return L::System;
|
||||
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-wlan-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 = stripWlanExt(base);
|
||||
if (out.empty()) out = base + ".wlan.json";
|
||||
if (!wowee::pipeline::WoweeLocalizationLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wlan-json: WLAN not found: %s.wlan\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeLocalizationLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WLAN";
|
||||
j["version"] = 1;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"stringId", e.stringId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"languageCode", e.languageCode},
|
||||
{"languageCodeName",
|
||||
languageCodeName(e.languageCode)},
|
||||
{"namespace", e.namespace_},
|
||||
{"namespaceName", namespaceName(e.namespace_)},
|
||||
{"originalKey", e.originalKey},
|
||||
{"localizedText", e.localizedText},
|
||||
{"iconColorRGBA", e.iconColorRGBA},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wlan-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu strings)\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) == ".wlan.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wlan");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wlan-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-wlan-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeLocalization c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wlan-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeLocalization::Entry e;
|
||||
e.stringId = je.value("stringId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
if (!readEnumField(je, "languageCode",
|
||||
"languageCodeName",
|
||||
parseLanguageCodeToken,
|
||||
"languageCode",
|
||||
e.stringId,
|
||||
e.languageCode)) return 1;
|
||||
if (!readEnumField(je, "namespace", "namespaceName",
|
||||
parseNamespaceToken, "namespace",
|
||||
e.stringId, e.namespace_)) return 1;
|
||||
e.originalKey = je.value("originalKey", std::string{});
|
||||
e.localizedText = je.value("localizedText", std::string{});
|
||||
e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu);
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweeLocalizationLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wlan-json: failed to save %s.wlan\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wlan (%zu strings)\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);
|
||||
|
|
@ -289,6 +468,12 @@ bool handleLocalizationCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wlan") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wlan-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wlan-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