Skip to content

Commit d2f9a32

Browse files
authored
Add default enabled state to mod manifest (#104)
1 parent 234ed4a commit d2f9a32

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

librecomp/include/librecomp/mods.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ namespace recomp {
220220
std::vector<std::string> authors;
221221
std::vector<Dependency> dependencies;
222222
bool runtime_toggleable;
223+
bool enabled_by_default;
223224
};
224225

225226
struct ModManifest {
@@ -237,6 +238,7 @@ namespace recomp {
237238
Version minimum_recomp_version;
238239
Version version;
239240
bool runtime_toggleable;
241+
bool enabled_by_default = true;
240242

241243
std::vector<NativeLibraryManifest> native_libraries;
242244
std::unique_ptr<ModFileHandle> file_handle;
@@ -476,7 +478,8 @@ namespace recomp {
476478
.version = manifest.version,
477479
.authors = manifest.authors,
478480
.dependencies = manifest.dependencies,
479-
.runtime_toggleable = is_runtime_toggleable()
481+
.runtime_toggleable = is_runtime_toggleable(),
482+
.enabled_by_default = manifest.enabled_by_default
480483
};
481484
}
482485
private:

librecomp/src/mod_manifest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const std::string short_description_key = "short_description";
169169
const std::string version_key = "version";
170170
const std::string authors_key = "authors";
171171
const std::string minimum_recomp_version_key = "minimum_recomp_version";
172+
const std::string enabled_by_default_key = "enabled_by_default";
172173
const std::string dependencies_key = "dependencies";
173174
const std::string native_libraries_key = "native_libraries";
174175
const std::string config_schema_key = "config_schema";
@@ -573,6 +574,12 @@ recomp::mods::ModOpenError recomp::mods::parse_manifest(ModManifest& ret, const
573574
return current_error;
574575
}
575576

577+
// Enabled by default (optional)
578+
current_error = try_get<json::boolean_t>(ret.enabled_by_default, manifest_json, enabled_by_default_key, false, error_param);
579+
if (current_error != ModOpenError::Good) {
580+
return current_error;
581+
}
582+
576583
// Dependencies (optional)
577584
std::vector<std::string> dep_strings{};
578585
current_error = try_get_vec<json::string_t>(dep_strings, manifest_json, dependencies_key, false, error_param);

librecomp/src/mods.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,11 @@ void recomp::mods::ModContext::load_mods_config() {
862862

863863
// Enable mods that are specified in the configuration or mods that are considered new.
864864
for (size_t i = 0; i < opened_mods.size(); i++) {
865-
const std::string &mod_id = opened_mods[i].manifest.mod_id;
866-
if (!opened_mod_is_known[i] || (config_enabled_mods.find(mod_id) != config_enabled_mods.end())) {
865+
const ModHandle& mod = opened_mods[i];
866+
const std::string &mod_id = mod.manifest.mod_id;
867+
bool is_default_enabled = !opened_mod_is_known[i] && mod.manifest.enabled_by_default;
868+
bool is_manually_enabled = config_enabled_mods.contains(mod_id);
869+
if (is_default_enabled || is_manually_enabled) {
867870
enable_mod(mod_id, true, false);
868871
}
869872
}

0 commit comments

Comments
 (0)