mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 19:13:52 +00:00
feat(editor): WMOD JSON round-trip closure
Adds --export-wmod-json / --import-wmod-json. Variable-length dependency arrays serialize as JSON int arrays, enabling hand-edits of dependency graphs. All 3 presets (std-addons / ui-replacement chain Bartender4->ElvUI->SuperOrders / utility) byte-identical binary roundtrip OK. Cycle detection live-tested: hand-mutated ui.wmod.json to add Bartender4 -> SuperOrders dep, re-imported, validator emits "dependency cycle detected: 10 -> 12 -> 11 -> 10 — addon-loader would deadlock" with the full back-edge path extracted. CLI flag count 1326 -> 1328.
This commit is contained in:
parent
9df1fa39cd
commit
fa30db7ae1
3 changed files with 136 additions and 0 deletions
|
|
@ -293,6 +293,131 @@ 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 = stripWmodExt(base);
|
||||
if (out.empty()) out = base + ".wmod.json";
|
||||
if (!wowee::pipeline::WoweeAddonManifestLoader::exists(base)) {
|
||||
std::fprintf(stderr,
|
||||
"export-wmod-json: WMOD not found: %s.wmod\n",
|
||||
base.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto c = wowee::pipeline::WoweeAddonManifestLoader::load(base);
|
||||
nlohmann::json j;
|
||||
j["magic"] = "WMOD";
|
||||
j["version"] = 1;
|
||||
j["name"] = c.name;
|
||||
nlohmann::json arr = nlohmann::json::array();
|
||||
for (const auto& e : c.entries) {
|
||||
arr.push_back({
|
||||
{"addonId", e.addonId},
|
||||
{"name", e.name},
|
||||
{"description", e.description},
|
||||
{"version", e.version},
|
||||
{"author", e.author},
|
||||
{"minClientBuild", e.minClientBuild},
|
||||
{"requiresSavedVariables",
|
||||
e.requiresSavedVariables != 0},
|
||||
{"loadOnDemand", e.loadOnDemand != 0},
|
||||
{"dependencies", e.dependencies},
|
||||
{"optionalDependencies", e.optionalDependencies},
|
||||
});
|
||||
}
|
||||
j["entries"] = arr;
|
||||
std::ofstream os(out);
|
||||
if (!os) {
|
||||
std::fprintf(stderr,
|
||||
"export-wmod-json: failed to open %s for write\n",
|
||||
out.c_str());
|
||||
return 1;
|
||||
}
|
||||
os << j.dump(2) << "\n";
|
||||
std::printf("Wrote %s (%zu addons)\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) == ".wmod.json") {
|
||||
outBase.resize(outBase.size() - 10);
|
||||
} else {
|
||||
stripExt(outBase, ".json");
|
||||
stripExt(outBase, ".wmod");
|
||||
}
|
||||
}
|
||||
std::ifstream is(in);
|
||||
if (!is) {
|
||||
std::fprintf(stderr,
|
||||
"import-wmod-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-wmod-json: JSON parse error: %s\n", ex.what());
|
||||
return 1;
|
||||
}
|
||||
wowee::pipeline::WoweeAddonManifest c;
|
||||
c.name = j.value("name", std::string{});
|
||||
if (!j.contains("entries") || !j["entries"].is_array()) {
|
||||
std::fprintf(stderr,
|
||||
"import-wmod-json: missing or non-array 'entries'\n");
|
||||
return 1;
|
||||
}
|
||||
for (const auto& je : j["entries"]) {
|
||||
wowee::pipeline::WoweeAddonManifest::Entry e;
|
||||
e.addonId = je.value("addonId", 0u);
|
||||
e.name = je.value("name", std::string{});
|
||||
e.description = je.value("description", std::string{});
|
||||
e.version = je.value("version", std::string{});
|
||||
e.author = je.value("author", std::string{});
|
||||
e.minClientBuild = je.value("minClientBuild", 0u);
|
||||
e.requiresSavedVariables =
|
||||
je.value("requiresSavedVariables", false) ? 1 : 0;
|
||||
e.loadOnDemand = je.value("loadOnDemand", false) ? 1 : 0;
|
||||
if (je.contains("dependencies") &&
|
||||
je["dependencies"].is_array()) {
|
||||
for (const auto& d : je["dependencies"]) {
|
||||
if (d.is_number_unsigned() ||
|
||||
d.is_number_integer()) {
|
||||
e.dependencies.push_back(d.get<uint32_t>());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (je.contains("optionalDependencies") &&
|
||||
je["optionalDependencies"].is_array()) {
|
||||
for (const auto& d : je["optionalDependencies"]) {
|
||||
if (d.is_number_unsigned() ||
|
||||
d.is_number_integer()) {
|
||||
e.optionalDependencies.push_back(
|
||||
d.get<uint32_t>());
|
||||
}
|
||||
}
|
||||
}
|
||||
c.entries.push_back(e);
|
||||
}
|
||||
if (!wowee::pipeline::WoweeAddonManifestLoader::save(c, outBase)) {
|
||||
std::fprintf(stderr,
|
||||
"import-wmod-json: failed to save %s.wmod\n",
|
||||
outBase.c_str());
|
||||
return 1;
|
||||
}
|
||||
std::printf("Wrote %s.wmod (%zu addons)\n",
|
||||
outBase.c_str(), c.entries.size());
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool handleAddonManifestCatalog(int& i, int argc, char** argv,
|
||||
|
|
@ -313,6 +438,12 @@ bool handleAddonManifestCatalog(int& i, int argc, char** argv,
|
|||
if (std::strcmp(argv[i], "--validate-wmod") == 0 && i + 1 < argc) {
|
||||
outRc = handleValidate(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--export-wmod-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleExportJson(i, argc, argv); return true;
|
||||
}
|
||||
if (std::strcmp(argv[i], "--import-wmod-json") == 0 && i + 1 < argc) {
|
||||
outRc = handleImportJson(i, argc, argv); return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -385,6 +385,7 @@ const char* const kArgRequired[] = {
|
|||
"--export-wgch-json", "--import-wgch-json",
|
||||
"--gen-mod", "--gen-mod-ui", "--gen-mod-util",
|
||||
"--info-wmod", "--validate-wmod",
|
||||
"--export-wmod-json", "--import-wmod-json",
|
||||
"--gen-weather-temperate", "--gen-weather-arctic",
|
||||
"--gen-weather-desert", "--gen-weather-stormy",
|
||||
"--gen-zone-atmosphere",
|
||||
|
|
|
|||
|
|
@ -2513,6 +2513,10 @@ void printUsage(const char* argv0) {
|
|||
std::printf(" Print WMOD entries (id / version / requiresSavedVariables / loadOnDemand / dep counts / name)\n");
|
||||
std::printf(" --validate-wmod <wmod-base> [--json]\n");
|
||||
std::printf(" Static checks: id+name+version required, no duplicate addonIds, no duplicate addon names (load-order ambiguity), no self-dependency, no missing required-dep addonId, DFS cycle detection on required deps (deadlock at load); warns on optional self-dep and on minClientBuild < 4500 (likely typo)\n");
|
||||
std::printf(" --export-wmod-json <wmod-base> [out.json]\n");
|
||||
std::printf(" Export binary .wmod to a human-editable JSON sidecar (defaults to <base>.wmod.json; emits dependencies and optionalDependencies as JSON int arrays)\n");
|
||||
std::printf(" --import-wmod-json <json-path> [out-base]\n");
|
||||
std::printf(" Import a .wmod.json sidecar back into binary .wmod (dependency arrays accept JSON int arrays — round-trips chained dep graphs byte-identical)\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