Skip to content

Commit 3df29d4

Browse files
committed
feat: add dictionary for overrides based on feature tags to options
1 parent 352da65 commit 3df29d4

File tree

6 files changed

+83
-11
lines changed

6 files changed

+83
-11
lines changed

addons/mod_loader/api/log.gd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ static func _log(message: String, mod_name: String, log_type: String = "info", o
345345
if only_once and _is_logged_before(log_entry):
346346
return
347347

348-
_store_log(log_entry)
348+
if ModLoaderStore:
349+
_store_log(log_entry)
349350

350351
# Check if the scene_tree is available
351352
if Engine.get_main_loop():
@@ -385,6 +386,9 @@ static func _log(message: String, mod_name: String, log_type: String = "info", o
385386

386387

387388
static func _is_mod_name_ignored(mod_name: String) -> bool:
389+
if not ModLoaderStore:
390+
return false
391+
388392
var ignored_mod_names := ModLoaderStore.ml_options.ignored_mod_names_in_log as Array
389393

390394
if not ignored_mod_names.size() == 0:

addons/mod_loader/mod_loader.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func _init_mod(mod: ModData) -> void:
341341
if method.name == "_init":
342342
if method.args.size() > 0:
343343
argument_found = true
344-
344+
345345
var mod_main_instance: Node
346346
if argument_found:
347347
mod_main_instance = mod_main_script.new(self)

addons/mod_loader/mod_loader_store.gd

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,52 @@ func _update_ml_options_from_options_resource() -> void:
150150
var ml_options_path := "res://addons/mod_loader/options/options.tres"
151151

152152
# Get user options for ModLoader
153-
if _ModLoaderFile.file_exists(ml_options_path):
154-
var options_resource := load(ml_options_path)
155-
if not options_resource.current_options == null:
156-
var current_options: Resource = options_resource.current_options
153+
if not _ModLoaderFile.file_exists(ml_options_path):
154+
ModLoaderLog.fatal(str("A critical file is missing: ", ml_options_path), LOG_NAME)
155+
156+
var options_resource: ModLoaderCurrentOptions = load(ml_options_path)
157+
if options_resource.current_options == null:
158+
ModLoaderLog.warning(str(
159+
"No current options are set. Falling back to defaults. ",
160+
"Edit your options at %s. " % ml_options_path
161+
), LOG_NAME)
162+
else:
163+
var current_options = options_resource.current_options
164+
if not current_options is ModLoaderOptionsProfile:
165+
ModLoaderLog.error(str(
166+
"Current options is not a valid Resource of type ModLoaderOptionsProfile. ",
167+
"Please edit your options at %s. " % ml_options_path
168+
), LOG_NAME)
169+
# Update from the options in the resource
170+
for key in ml_options:
171+
ml_options[key] = current_options[key]
172+
173+
174+
# Get options overrides by feature tags
175+
# An override is saved as Dictionary[String: ModLoaderOptionsProfile]
176+
for feature_tag in options_resource.feature_override_options.keys():
177+
if not feature_tag is String:
178+
ModLoaderLog.error(str(
179+
"Options override keys are required to be of type String. Failing key: \"%s.\" " % feature_tag,
180+
"Please edit your options at %s. " % ml_options_path,
181+
"Consult the documentation for all available feature tags: ",
182+
"https://docs.godotengine.org/en/3.5/tutorials/export/feature_tags.html"
183+
), LOG_NAME)
184+
continue
185+
if not OS.has_feature(feature_tag):
186+
var override_options = options_resource.feature_override_options[feature_tag]
187+
if not override_options is ModLoaderOptionsProfile:
188+
ModLoaderLog.error(str(
189+
"Options override is not a valid Resource of type ModLoaderOptionsProfile. ",
190+
"Options override key with invalid resource: \"%s\". " % feature_tag,
191+
"Please edit your options at %s. " % ml_options_path
192+
), LOG_NAME)
193+
continue
157194
# Update from the options in the resource
158195
for key in ml_options:
159-
ml_options[key] = current_options[key]
160-
else:
161-
ModLoaderLog.fatal(str("A critical file is missing: ", ml_options_path), LOG_NAME)
196+
ml_options[key] = override_options[key]
197+
198+
162199

163200

164201
# Update ModLoader's options, via CLI args
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
[gd_resource type="Resource" load_steps=3 format=2]
1+
[gd_resource type="Resource" load_steps=4 format=2]
22

33
[ext_resource path="res://addons/mod_loader/options/profiles/current.tres" type="Resource" id=1]
44
[ext_resource path="res://addons/mod_loader/resources/options_current.gd" type="Script" id=2]
5+
[ext_resource path="res://addons/mod_loader/options/profiles/editor.tres" type="Resource" id=3]
56

67
[resource]
78
script = ExtResource( 2 )
89
current_options = ExtResource( 1 )
10+
feature_override_options = {
11+
"editor": ExtResource( 3 )
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[gd_resource type="Resource" load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/mod_loader/resources/options_profile.gd" type="Script" id=1]
4+
5+
[resource]
6+
script = ExtResource( 1 )
7+
enable_mods = true
8+
locked_mods = [ ]
9+
log_level = 3
10+
disabled_mods = [ ]
11+
allow_modloader_autoloads_anywhere = false
12+
steam_workshop_enabled = false
13+
override_path_to_mods = ""
14+
override_path_to_configs = ""
15+
override_path_to_workshop = ""
16+
ignore_deprecated_errors = true
17+
ignored_mod_names_in_log = [ ]
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
class_name ModLoaderCurrentOptions
22
extends Resource
33

4-
export (Resource) var current_options = null
4+
# The default options set for the mod loader
5+
export var current_options: Resource = preload("res://addons/mod_loader/options/profiles/default.tres")
6+
7+
# Overrides for all available feature tags through OS.has_feature()
8+
# Format: Dictionary[String: ModLoaderOptionsProfile] where the string is a tag
9+
# Warning: Some tags can occur at the same time (Windows + editor for example) -
10+
# In a case where multiple apply, the last one in the dict will override all others
11+
export var feature_override_options: Dictionary = {
12+
"editor": preload("res://addons/mod_loader/options/profiles/editor.tres")
13+
}
14+

0 commit comments

Comments
 (0)