Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✔ added checks for override.cfg setup #110

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,32 @@ func _init() -> void:
# Ensure ModLoader is the first autoload
func _check_first_autoload() -> void:
var autoload_array = ModLoaderUtils.get_autoload_array()
var is_mod_loader_first = autoload_array.find("ModLoader") == 0
var mod_loader_index = autoload_array.find("ModLoader")
var is_mod_loader_first = mod_loader_index == 0

var base_msg = "ModLoader needs to be the first autoload to work correctly, "
var help_msg = ""
var override_cfg_path = ModLoaderUtils.get_override_path()
var is_override_cfg_setup = ModLoaderUtils.file_exists(override_cfg_path)

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

# If the override file exists we assume the ModLoader was setup with the --setup-create-override-cfg cli arg
# In that case the ModLoader will be the last entry in the autoload array
if is_override_cfg_setup:
ModLoaderUtils.log_info("override.cfg setup detected, ModLoader will be the last autoload loaded.", LOG_NAME)
return

var base_msg = "ModLoader needs to be the first autoload to work correctly, "
KANAjetzt marked this conversation as resolved.
Show resolved Hide resolved
var help_msg = ""

if OS.has_feature("editor"):
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."
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."
else:
help_msg = "If you're seeing this error, something must have gone wrong in the setup process."

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

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


# Loop over "res://mods" and add any mod zips to the unpacked virtual directory
# (UNPACKED_DIR)
Expand Down
10 changes: 9 additions & 1 deletion addons/mod_loader/mod_loader_setup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ var is_setup_create_override_cfg : bool = modloaderutils.is_running_with_command
func _init() -> void:
modloaderutils.log_debug("ModLoader setup initialized", LOG_NAME)

var mod_loader_index: int = modloaderutils.get_autoload_index("ModLoader")

# Avoid doubling the setup work
# Checks if the ModLoader Node is in the root of the scene tree
# and if the IS_LOADER_SETUP_APPLIED project setting is there
if modloaderutils.get_autoload_index("ModLoader") == 0:
if mod_loader_index == 0:
modded_start()
return

# Check if --setup-create-override-cfg is passed,
# in that case the ModLoader just has to be somewhere in the autoloads.
if is_setup_create_override_cfg and mod_loader_index != -1:
modded_start()
return

Expand Down