Skip to content

Commit 197252b

Browse files
committed
✔ added checks for override.cfg setup (GodotModding#110)
* ✔ added checks for override.cfg setup * 🧹 removed logging when no autoloads are set up If there is no autoloads there will be no mod_loader.gd
1 parent 01a2fbe commit 197252b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

addons/mod_loader/mod_loader.gd

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,25 +183,32 @@ func _init() -> void:
183183
# Ensure ModLoader is the first autoload
184184
func _check_first_autoload() -> void:
185185
var autoload_array = ModLoaderUtils.get_autoload_array()
186-
var is_mod_loader_first = autoload_array.find("ModLoader") == 0
186+
var mod_loader_index = autoload_array.find("ModLoader")
187+
var is_mod_loader_first = mod_loader_index == 0
187188

188-
var base_msg = "ModLoader needs to be the first autoload to work correctly, "
189-
var help_msg = ""
189+
var override_cfg_path = ModLoaderUtils.get_override_path()
190+
var is_override_cfg_setup = ModLoaderUtils.file_exists(override_cfg_path)
190191

191192
# Log the autoloads order. Might seem superflous but could help when providing support
192193
ModLoaderUtils.log_debug_json_print("Autoload order", autoload_array, LOG_NAME)
193194

195+
# If the override file exists we assume the ModLoader was setup with the --setup-create-override-cfg cli arg
196+
# In that case the ModLoader will be the last entry in the autoload array
197+
if is_override_cfg_setup:
198+
ModLoaderUtils.log_info("override.cfg setup detected, ModLoader will be the last autoload loaded.", LOG_NAME)
199+
return
200+
201+
var base_msg = "ModLoader needs to be the first autoload to work correctly, "
202+
var help_msg = ""
203+
194204
if OS.has_feature("editor"):
195-
help_msg = "To configure your autoloads, to go Project > Project Settings > Autoload, and add ModLoader as the first item. For more info, see the 'Godot Project Setup' page on the ModLoader GitHub wiki."
205+
help_msg = "To configure your autoloads, go to Project > Project Settings > Autoload, and add ModLoader as the first item. For more info, see the 'Godot Project Setup' page on the ModLoader GitHub wiki."
196206
else:
197207
help_msg = "If you're seeing this error, something must have gone wrong in the setup process."
198208

199209
if not is_mod_loader_first:
200210
ModLoaderUtils.log_fatal(str(base_msg, 'but the first autoload is currently: "%s". ' % autoload_array[0], help_msg), LOG_NAME)
201211

202-
if autoload_array.size() == 0:
203-
ModLoaderUtils.log_fatal(str(base_msg, "but no autoloads are currently set up. ", help_msg), LOG_NAME)
204-
205212

206213
# Loop over "res://mods" and add any mod zips to the unpacked virtual directory
207214
# (UNPACKED_DIR)

addons/mod_loader/mod_loader_setup.gd

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ var is_setup_create_override_cfg : bool = modloaderutils.is_running_with_command
4141
func _init() -> void:
4242
modloaderutils.log_debug("ModLoader setup initialized", LOG_NAME)
4343

44+
var mod_loader_index: int = modloaderutils.get_autoload_index("ModLoader")
45+
4446
# Avoid doubling the setup work
4547
# Checks if the ModLoader Node is in the root of the scene tree
4648
# and if the IS_LOADER_SETUP_APPLIED project setting is there
47-
if modloaderutils.get_autoload_index("ModLoader") == 0:
49+
if mod_loader_index == 0:
50+
modded_start()
51+
return
52+
53+
# Check if --setup-create-override-cfg is passed,
54+
# in that case the ModLoader just has to be somewhere in the autoloads.
55+
if is_setup_create_override_cfg and mod_loader_index != -1:
4856
modded_start()
4957
return
5058

0 commit comments

Comments
 (0)