diff --git a/tools/editor/cli_addon_manifest_catalog.cpp b/tools/editor/cli_addon_manifest_catalog.cpp index b8004529..30cdc50d 100644 --- a/tools/editor/cli_addon_manifest_catalog.cpp +++ b/tools/editor/cli_addon_manifest_catalog.cpp @@ -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()); + } + } + } + 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()); + } + } + } + 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; } diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index 9dccc928..e956a3e1 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -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", diff --git a/tools/editor/cli_help.cpp b/tools/editor/cli_help.cpp index 9cd1008a..25576a2d 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -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 [--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 [out.json]\n"); + std::printf(" Export binary .wmod to a human-editable JSON sidecar (defaults to .wmod.json; emits dependencies and optionalDependencies as JSON int arrays)\n"); + std::printf(" --import-wmod-json [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 [--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 [--magic ] [--json]\n");