From be65d37760e56867fc5ac68510ffdc0f6e00bbb5 Mon Sep 17 00:00:00 2001 From: Wiseguy <68165316+Mr-Wiseguy@users.noreply.github.com> Date: Fri, 31 Jan 2025 02:36:33 -0500 Subject: [PATCH] Added config option parsing for mod toml and populate them in the mod manifest (#129) --- RecompModTool/main.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/RecompModTool/main.cpp b/RecompModTool/main.cpp index 10a102b..85d6d48 100644 --- a/RecompModTool/main.cpp +++ b/RecompModTool/main.cpp @@ -32,6 +32,7 @@ struct ModManifest { std::string game_id; std::string minimum_recomp_version; std::unordered_map> native_libraries; + std::vector config_options; std::vector dependencies; std::vector full_dependency_strings; }; @@ -218,6 +219,11 @@ static std::vector get_toml_path_array(const toml::array& return ret; } +bool validate_config_option(const toml::table& option) { + // TODO config option validation. + return true; +} + ModManifest parse_mod_config_manifest(const std::filesystem::path& basedir, const toml::table& manifest_table) { ModManifest ret; @@ -317,6 +323,23 @@ ModManifest parse_mod_config_manifest(const std::filesystem::path& basedir, cons }); } + // Config schema (optional) + const toml::array& config_options_array = read_toml_array(manifest_table, "config_options", false); + if (!config_options_array.empty()) { + ret.config_options.reserve(config_options_array.size()); + config_options_array.for_each([&ret](const auto& el) { + if constexpr (toml::is_table) { + if (!validate_config_option(el)) { + throw toml::parse_error("Invalid config option", el.source()); + } + ret.config_options.emplace_back(el); + } + else { + throw toml::parse_error("Invalid type for config option", el.source()); + } + }); + } + return ret; } @@ -484,6 +507,14 @@ void write_manifest(const std::filesystem::path& path, const ModManifest& manife output_data.emplace("dependencies", string_vector_to_toml(manifest.full_dependency_strings)); } + if (!manifest.config_options.empty()) { + toml::array options_array{}; + for (const auto& option : manifest.config_options) { + options_array.emplace_back(option); + } + output_data.emplace("config_schema", toml::table{{"options", std::move(options_array)}}); + } + toml::json_formatter formatter{output_data, toml::format_flags::indentation | toml::format_flags::indentation}; std::ofstream output_file(path);