diff --git a/README.md b/README.md index 9315312..b7c526f 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,10 @@ Each mod contains a **config.toml** file located within the mod directory. ```toml enabled = true -include = ["."] +include = [ + ".", + { enabled = false, include = "optional", name = "Extra optional things" } +] dll = ["TemplateMod.dll"] name = "Template Mod" diff --git a/Source/DivaModLoader/ModLoader.cpp b/Source/DivaModLoader/ModLoader.cpp index b147f9f..b97b041 100644 --- a/Source/DivaModLoader/ModLoader.cpp +++ b/Source/DivaModLoader/ModLoader.cpp @@ -77,12 +77,39 @@ void ModLoader::initMod(const std::filesystem::path& path) if (toml::array* includeArr = config["include"].as_array()) { - for (auto& includeElem : *includeArr) - { - const std::string include = includeElem.value_or(""); + toml::array nodes; + for (size_t i = includeArr->size() - 1; i != -1; i--) + nodes.push_back(includeArr->at(i)); - if (!include.empty()) - modDirectoryPaths.push_back(modDirectoryPath + "\\" + include); + while (!nodes.empty()) + { + toml::array temp; + temp.push_back(nodes.back()); + nodes.pop_back(); + toml::node& elem = temp.back(); + + if (toml::value* include = elem.as_string()) + { + if (!(*include)->empty()) + modDirectoryPaths.push_back(modDirectoryPath + "\\" + **include); + } + else if (toml::table* includeTable = elem.as_table()) + { + const bool enabled = includeTable->at_path("enabled").value_or(true); + if (!enabled) + continue; + + if (toml::value* include = includeTable->at_path("include").as_string()) + { + if (!(*include)->empty()) + modDirectoryPaths.push_back(modDirectoryPath + "\\" + **include); + } + else if (toml::array* arr = includeTable->at_path("include").as_array()) + { + for (size_t i = arr->size() - 1; i != -1; i--) + nodes.push_back(arr->at(i)); + } + } } }