Skip to content

Commit 8963712

Browse files
authored
Merge pull request #326 from Qubus0/production_and_development_environment_options
2 parents 352da65 + 8cb4a34 commit 8963712

File tree

6 files changed

+90
-13
lines changed

6 files changed

+90
-13
lines changed

addons/mod_loader/api/log.gd

Lines changed: 8 additions & 2 deletions
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:
@@ -394,7 +398,9 @@ static func _is_mod_name_ignored(mod_name: String) -> bool:
394398

395399

396400
static func _get_verbosity() -> int:
397-
return ModLoaderStore.ml_options.log_level
401+
if not ModLoaderStore:
402+
return VERBOSITY_LEVEL.DEBUG
403+
return ModLoaderStore.ml_options.log_level
398404

399405

400406
static func _store_log(log_entry: ModLoaderLogEntry) -> void:

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: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,56 @@ 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
157-
# Update from the options in the resource
158-
for key in ml_options:
159-
ml_options[key] = current_options[key]
160-
else:
153+
if not _ModLoaderFile.file_exists(ml_options_path):
161154
ModLoaderLog.fatal(str("A critical file is missing: ", ml_options_path), LOG_NAME)
162155

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+
# Get options overrides by feature tags
174+
# An override is saved as Dictionary[String: ModLoaderOptionsProfile]
175+
for feature_tag in options_resource.feature_override_options.keys():
176+
if not feature_tag is String:
177+
ModLoaderLog.error(str(
178+
"Options override keys are required to be of type String. Failing key: \"%s.\" " % feature_tag,
179+
"Please edit your options at %s. " % ml_options_path,
180+
"Consult the documentation for all available feature tags: ",
181+
"https://docs.godotengine.org/en/3.5/tutorials/export/feature_tags.html"
182+
), LOG_NAME)
183+
continue
184+
185+
if not OS.has_feature(feature_tag):
186+
ModLoaderLog.info("Options override feature tag \"%s\". does not apply, skipping." % feature_tag, LOG_NAME)
187+
continue
188+
189+
ModLoaderLog.info("Applying options override with feature tag \"%s\"." % feature_tag, LOG_NAME)
190+
var override_options = options_resource.feature_override_options[feature_tag]
191+
if not override_options is ModLoaderOptionsProfile:
192+
ModLoaderLog.error(str(
193+
"Options override is not a valid Resource of type ModLoaderOptionsProfile. ",
194+
"Options override key with invalid resource: \"%s\". " % feature_tag,
195+
"Please edit your options at %s. " % ml_options_path
196+
), LOG_NAME)
197+
continue
198+
199+
# Update from the options in the resource
200+
for key in ml_options:
201+
ml_options[key] = override_options[key]
202+
163203

164204
# Update ModLoader's options, via CLI args
165205
func _update_ml_options_from_cli_args() -> void:
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 (Resource) 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 (Dictionary) var feature_override_options: Dictionary = {
12+
"editor": preload("res://addons/mod_loader/options/profiles/editor.tres")
13+
}
14+

0 commit comments

Comments
 (0)