diff --git a/tools/editor/cli_arg_required.cpp b/tools/editor/cli_arg_required.cpp index e3a88a7a..bf629b9c 100644 --- a/tools/editor/cli_arg_required.cpp +++ b/tools/editor/cli_arg_required.cpp @@ -346,6 +346,7 @@ const char* const kArgRequired[] = { "--export-wpcr-json", "--import-wpcr-json", "--gen-mvc", "--gen-mvc-quest", "--gen-mvc-starter", "--info-wmvc", "--validate-wmvc", + "--export-wmvc-json", "--import-wmvc-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 65d569ac..aca5b120 100644 --- a/tools/editor/cli_help.cpp +++ b/tools/editor/cli_help.cpp @@ -2331,6 +2331,10 @@ void printUsage(const char* argv0) { std::printf(" Print WMVC entries (id / cinematicId / category / orderHint / line count / name) plus per-block credit lines\n"); std::printf(" --validate-wmvc [--json]\n"); std::printf(" Static checks: id+name+cinematicId required, category 0..6, lines[] non-empty, no duplicate rollIds, no two blocks at same (cinematicId, orderHint) slot (would render in non-deterministic order); warns on empty lines (blank renders) or lines > 80 chars (text-buffer wrap)\n"); + std::printf(" --export-wmvc-json [out.json]\n"); + std::printf(" Export binary .wmvc to a human-editable JSON sidecar (defaults to .wmvc.json; emits category as both int AND name string; lines[] as JSON string array)\n"); + std::printf(" --import-wmvc-json [out-base]\n"); + std::printf(" Import a .wmvc.json sidecar back into binary .wmvc (category int OR \"production\"/\"music\"/\"audio\"/\"engineering\"/\"art\"/\"voice\"/\"special\"; lines[] is a JSON array of strings — directly editable to add/remove credit lines without binary tooling)\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"); diff --git a/tools/editor/cli_movie_credits_catalog.cpp b/tools/editor/cli_movie_credits_catalog.cpp index 53ff6151..a6ac4df1 100644 --- a/tools/editor/cli_movie_credits_catalog.cpp +++ b/tools/editor/cli_movie_credits_catalog.cpp @@ -141,6 +141,151 @@ int handleInfo(int& i, int argc, char** argv) { return 0; } +int parseCategoryToken(const std::string& s) { + using M = wowee::pipeline::WoweeMovieCredits; + if (s == "production") return M::Production; + if (s == "music") return M::Music; + if (s == "audio") return M::Audio; + if (s == "engineering") return M::Engineering; + if (s == "art") return M::Art; + if (s == "voice") return M::Voice; + if (s == "special") return M::Special; + return -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 = stripWmvcExt(base); + if (out.empty()) out = base + ".wmvc.json"; + if (!wowee::pipeline::WoweeMovieCreditsLoader::exists(base)) { + std::fprintf(stderr, + "export-wmvc-json: WMVC not found: %s.wmvc\n", + base.c_str()); + return 1; + } + auto c = wowee::pipeline::WoweeMovieCreditsLoader::load(base); + nlohmann::json j; + j["magic"] = "WMVC"; + j["version"] = 1; + j["name"] = c.name; + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : c.entries) { + arr.push_back({ + {"rollId", e.rollId}, + {"name", e.name}, + {"description", e.description}, + {"cinematicId", e.cinematicId}, + {"category", e.category}, + {"categoryName", categoryName(e.category)}, + {"orderHint", e.orderHint}, + {"iconColorRGBA", e.iconColorRGBA}, + {"lines", e.lines}, + }); + } + j["entries"] = arr; + std::ofstream os(out); + if (!os) { + std::fprintf(stderr, + "export-wmvc-json: failed to open %s for write\n", + out.c_str()); + return 1; + } + os << j.dump(2) << "\n"; + std::printf("Wrote %s (%zu blocks)\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) == ".wmvc.json") { + outBase.resize(outBase.size() - 10); + } else { + stripExt(outBase, ".json"); + stripExt(outBase, ".wmvc"); + } + } + std::ifstream is(in); + if (!is) { + std::fprintf(stderr, + "import-wmvc-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-wmvc-json: JSON parse error: %s\n", ex.what()); + return 1; + } + wowee::pipeline::WoweeMovieCredits c; + c.name = j.value("name", std::string{}); + if (!j.contains("entries") || !j["entries"].is_array()) { + std::fprintf(stderr, + "import-wmvc-json: missing or non-array 'entries'\n"); + return 1; + } + for (const auto& je : j["entries"]) { + wowee::pipeline::WoweeMovieCredits::Entry e; + e.rollId = je.value("rollId", 0u); + e.name = je.value("name", std::string{}); + e.description = je.value("description", std::string{}); + e.cinematicId = je.value("cinematicId", 0u); + if (je.contains("category")) { + const auto& v = je["category"]; + if (v.is_string()) { + int parsed = parseCategoryToken( + v.get()); + if (parsed < 0) { + std::fprintf(stderr, + "import-wmvc-json: unknown " + "category token '%s' on entry " + "id=%u\n", + v.get().c_str(), + e.rollId); + return 1; + } + e.category = static_cast(parsed); + } else if (v.is_number_integer()) { + e.category = static_cast(v.get()); + } + } else if (je.contains("categoryName") && + je["categoryName"].is_string()) { + int parsed = parseCategoryToken( + je["categoryName"].get()); + if (parsed >= 0) + e.category = static_cast(parsed); + } + e.orderHint = static_cast( + je.value("orderHint", 0u)); + e.iconColorRGBA = je.value("iconColorRGBA", 0xFFFFFFFFu); + if (je.contains("lines") && je["lines"].is_array()) { + for (const auto& L : je["lines"]) { + if (L.is_string()) + e.lines.push_back(L.get()); + } + } + c.entries.push_back(e); + } + if (!wowee::pipeline::WoweeMovieCreditsLoader::save(c, outBase)) { + std::fprintf(stderr, + "import-wmvc-json: failed to save %s.wmvc\n", + outBase.c_str()); + return 1; + } + std::printf("Wrote %s.wmvc (%zu blocks)\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); @@ -279,6 +424,12 @@ bool handleMovieCreditsCatalog(int& i, int argc, char** argv, if (std::strcmp(argv[i], "--validate-wmvc") == 0 && i + 1 < argc) { outRc = handleValidate(i, argc, argv); return true; } + if (std::strcmp(argv[i], "--export-wmvc-json") == 0 && i + 1 < argc) { + outRc = handleExportJson(i, argc, argv); return true; + } + if (std::strcmp(argv[i], "--import-wmvc-json") == 0 && i + 1 < argc) { + outRc = handleImportJson(i, argc, argv); return true; + } return false; }