Skip to content

Commit e01a5d5

Browse files
ML Options: Add the groundwork for loading custom options (#145)
* ML Settings: Add the groundwork for loading custom settings * ML Options: Rename from "ML Settings" * ML Options: Add missing log level (ERROR) * ML Options: Add "current" file, for instant editing * ML Options: Rename `options_example` to `options_profiles` * ML Options: Cleanup filenames and directories * ML Options: Update the options profile class name * ML Options: Add new custom classes to setup * ML Options: Amends from PR review (type safety etc)
1 parent 64371e5 commit e01a5d5

File tree

10 files changed

+124
-0
lines changed

10 files changed

+124
-0
lines changed

addons/mod_loader/mod_loader.gd

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,36 @@ var loaded_vanilla_parents_cache := {}
8787
# Helps to decide whether a script extension should go through the _handle_script_extensions process
8888
var is_initializing := true
8989

90+
# These variables handle various options, which can be changed via Godot's GUI
91+
# by adding a ModLoaderOptions resource to the resource file specified by
92+
# `ml_options_path`. See res://addons/mod_loader/options_examples for some
93+
# resource files you can add to the options_curent file.
94+
# See: res://addons/mod_loader/options/classes/options_profile.gd
95+
# See: res://addons/mod_loader/options/options_current_data.gd
96+
var ml_options_path := "res://addons/mod_loader/options/options_current.tres"
97+
var ml_options := {
98+
enable_mods = true,
99+
log_level = ModLoaderUtils.verbosity_level.DEBUG,
100+
path_to_mods = "res://mods",
101+
path_to_configs = "res://configs",
102+
use_steam_workshop_path = false,
103+
}
104+
90105

91106
# Main
92107
# =============================================================================
93108

94109
func _init() -> void:
110+
_update_ml_options()
111+
95112
# if mods are not enabled - don't load mods
96113
if REQUIRE_CMD_LINE and not ModLoaderUtils.is_running_with_command_line_arg("--enable-mods"):
97114
return
98115

116+
if not ml_options.enable_mods:
117+
ModLoaderUtils.log_info("Mods are currently disabled", LOG_NAME)
118+
return
119+
99120
# Rotate the log files once on startup. Can't be checked in utils, since it's static
100121
ModLoaderUtils.rotate_log_file()
101122

@@ -182,6 +203,20 @@ func _init() -> void:
182203
is_initializing = false
183204

184205

206+
# Update ModLoader's options, via the custom options resource
207+
func _update_ml_options() -> void:
208+
# Get user options for ModLoader
209+
if File.new().file_exists(ml_options_path):
210+
var options_resource := load(ml_options_path)
211+
if not options_resource.current_options == null:
212+
var current_options: Resource = options_resource.current_options
213+
# Update from the options in the resource
214+
for key in ml_options:
215+
ml_options[key] = current_options[key]
216+
else:
217+
ModLoaderUtils.log_fatal(str("A critical file is missing: ", ml_options_path), LOG_NAME)
218+
219+
185220
# Ensure ModLoader is the first autoload
186221
func _check_first_autoload() -> void:
187222
var autoload_array = ModLoaderUtils.get_autoload_array()

addons/mod_loader/mod_loader_setup.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ const new_global_classes := [
3030
"class": "ScriptExtensionData",
3131
"language": "GDScript",
3232
"path": "res://addons/mod_loader/classes/script_extension_data.gd"
33+
}, {
34+
"base": "Resource",
35+
"class": "ModLoaderCurrentOptions",
36+
"language": "GDScript",
37+
"path": "res://addons/mod_loader/options/classes/options_current.gd"
38+
}, {
39+
"base": "Resource",
40+
"class": "ModLoaderOptionsProfile",
41+
"language": "GDScript",
42+
"path": "res://addons/mod_loader/options/classes/options_profile.gd"
3343
}
3444
]
3545

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class_name ModLoaderCurrentOptions
2+
extends Resource
3+
4+
export (Resource) var current_options = null
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class_name ModLoaderOptionsProfile
2+
extends Resource
3+
4+
# export (String) var my_string := ""
5+
# export (Resource) var upgrade_to_process_icon = null
6+
# export (Array, Resource) var elites: = []
7+
8+
export (bool) var enable_mods = true
9+
export (ModLoaderUtils.verbosity_level) var log_level: = ModLoaderUtils.verbosity_level.DEBUG
10+
export (String, DIR) var path_to_mods = "res://mods"
11+
export (String, DIR) var path_to_configs = "res://configs"
12+
export (bool) var use_steam_workshop_path = false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_resource type="Resource" load_steps=3 format=2]
2+
3+
[ext_resource path="res://addons/mod_loader/options/classes/options_current.gd" type="Script" id=1]
4+
[ext_resource path="res://addons/mod_loader/options/profiles/current.tres" type="Resource" id=2]
5+
6+
[resource]
7+
script = ExtResource( 1 )
8+
current_options = ExtResource( 2 )
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_resource type="Resource" load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/mod_loader/options/classes/options_profile.gd" type="Script" id=1]
4+
5+
[resource]
6+
script = ExtResource( 1 )
7+
enable_mods = true
8+
log_level = 3
9+
path_to_mods = "res://mods"
10+
path_to_configs = "res://configs"
11+
use_steam_workshop_path = false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_resource type="Resource" load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/mod_loader/options/classes/options_profile.gd" type="Script" id=1]
4+
5+
[resource]
6+
script = ExtResource( 1 )
7+
enable_mods = true
8+
log_level = 3
9+
path_to_mods = "res://mods"
10+
path_to_configs = "res://configs"
11+
use_steam_workshop_path = false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_resource type="Resource" load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/mod_loader/options/classes/options_profile.gd" type="Script" id=1]
4+
5+
[resource]
6+
script = ExtResource( 1 )
7+
enable_mods = false
8+
log_level = 3
9+
path_to_mods = "res://mods"
10+
path_to_configs = "res://configs"
11+
use_steam_workshop_path = false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_resource type="Resource" load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/mod_loader/options/classes/options_profile.gd" type="Script" id=1]
4+
5+
[resource]
6+
script = ExtResource( 1 )
7+
enable_mods = true
8+
log_level = 2
9+
path_to_mods = "res://mods"
10+
path_to_configs = "res://configs"
11+
use_steam_workshop_path = false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_resource type="Resource" load_steps=2 format=2]
2+
3+
[ext_resource path="res://addons/mod_loader/options/classes/options_profile.gd" type="Script" id=1]
4+
5+
[resource]
6+
script = ExtResource( 1 )
7+
enable_mods = true
8+
log_level = 2
9+
path_to_mods = "res://mods"
10+
path_to_configs = "res://configs"
11+
use_steam_workshop_path = true

0 commit comments

Comments
 (0)