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

Utils for ModLoader autoload position #104

Merged
merged 7 commits into from
Feb 9, 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
25 changes: 7 additions & 18 deletions addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -168,35 +168,24 @@ func _init() -> void:

# Ensure ModLoader is the first autoload
func _check_first_autoload() -> void:
var autoloads := {}
var autoload_index = 0
var is_mod_loader_first = false

for prop in ProjectSettings.get_property_list():
var name: String = prop.name
if name.begins_with("autoload/"):
if autoload_index == 0:
if name == "autoload/ModLoader":
is_mod_loader_first = true
var value: String = ProjectSettings.get_setting(name)
autoloads[name] = value
autoload_index += 1

# Log the autoloads order. Might seem superflous but could help when providing support
ModLoaderUtils.log_debug_json_print("Autoload order", autoloads, LOG_NAME)
var autoload_array = ModLoaderUtils.get_autoload_array()
var is_mod_loader_first = autoload_array.find("ModLoader") == 0
KANAjetzt marked this conversation as resolved.
Show resolved Hide resolved

var base_msg = "ModLoader needs to be the first autoload to work correctly, "
var help_msg = ""

# 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 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."
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". ' % name, help_msg), LOG_NAME)
ModLoaderUtils.log_fatal(str(base_msg, 'but the first autoload is currently: "%s". ' % autoload_array[0], help_msg), LOG_NAME)
KANAjetzt marked this conversation as resolved.
Show resolved Hide resolved

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


Expand Down
21 changes: 21 additions & 0 deletions addons/mod_loader/mod_loader_utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,27 @@ static func is_valid_global_class_dict(global_class_dict: Dictionary) -> bool:
return true


# Get an array of all autoloads -> ["autoload/AutoloadName", ...]
static func get_autoload_array() -> Array:
var autoloads := []

# Get all autoload settings
for prop in ProjectSettings.get_property_list():
var name: String = prop.name
if name.begins_with("autoload/"):
autoloads.append(name.trim_prefix("autoload/"))

return autoloads


# Get the index of a specific autoload
static func get_autoload_index(autoload_name: String) -> int:
var autoloads := get_autoload_array()
var autoload_index := autoloads.find(autoload_name)

return autoload_index


# Get a flat array of all files in the target directory. This was needed in the
# original version of this script, before becoming deprecated. It may still be
# used if DEBUG_ENABLE_STORING_FILEPATHS is true.
Expand Down