Skip to content

✔ Load before #115

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

Closed
wants to merge 6 commits into from
Closed
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
46 changes: 44 additions & 2 deletions addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ func _init() -> void:

ModLoaderUtils.log_success("DONE: Loaded all meta data", LOG_NAME)

# Check for mods with load_before. If a mod is listed in load_before,
# add the current mod to the dependencies of the the mod specified
# in load_before.
for dir_name in mod_data:
var mod: ModData = mod_data[dir_name]
if not mod.is_loadable:
continue
_check_load_before(mod)

# Run dependency checks after loading mod_manifest. If a mod depends on another
# mod that hasn't been loaded, that dependent mod won't be loaded.
for dir_name in mod_data:
Expand All @@ -145,6 +154,13 @@ func _init() -> void:
continue
_check_dependencies(mod)

# Check for mods with load_before
for dir_name in mod_data:
var mod: ModData = mod_data[dir_name]
if not mod.is_loadable:
continue
_check_load_before(mod)

# Sort mod_load_order by the importance score of the mod
mod_load_order = _get_load_order(mod_data.values())

Expand Down Expand Up @@ -376,9 +392,18 @@ func _init_mod_data(mod_folder_path: String) -> void:
# Run dependency checks on a mod, checking any dependencies it lists in its
# mod_manifest (ie. its manifest.json file). If a mod depends on another mod that
# hasn't been loaded, the dependent mod won't be loaded.
func _check_dependencies(mod: ModData) -> void:
func _check_dependencies(mod: ModData, dependency_chain_start := '') -> void:
ModLoaderUtils.log_debug("Checking dependencies - mod_id: %s dependencies: %s" % [mod.dir_name, mod.manifest.dependencies], LOG_NAME)

# Check for circular dependency
if dependency_chain_start == mod.dir_path:
ModLoaderUtils.log_debug("Dependency check - circular dependency detected.", LOG_NAME)
return

# Set dependency_chain_start to the first mod id
if dependency_chain_start == '':
dependency_chain_start = mod.dir_path

# loop through each dependency
for dependency_id in mod.manifest.dependencies:
# check if dependency is missing
Expand All @@ -396,7 +421,7 @@ func _check_dependencies(mod: ModData) -> void:

# check if dependency has dependencies
if dependency.manifest.dependencies.size() > 0:
_check_dependencies(dependency)
_check_dependencies(dependency, dependency_chain_start)


# Handle missing dependencies: Sets `is_loadable` to false and logs an error
Expand All @@ -410,6 +435,23 @@ func _handle_missing_dependency(mod_dir_name: String, dependency_id: String) ->
mod_missing_dependencies[mod_dir_name].append(dependency_id)


# Run load before check on a mod, checking any load_before entries it lists in its
# mod_manifest (ie. its manifest.json file). Add the mod to the dependency of the
# mods inside the load_before array.
func _check_load_before(mod: ModData) -> void:
# Skip if no entries in load_before
if mod.manifest.load_before.size() == 0:
return

# Add the mod to the dependency arrays
for load_before_id in mod.manifest.load_before:
var load_before_mod_dependencies = mod_data[load_before_id].manifest.dependencies
load_before_mod_dependencies.append(mod.dir_name)
mod_data[load_before_id].manifest.dependencies = load_before_mod_dependencies

ModLoaderUtils.log_debug("Load before detected -> Added %s as dependency for %s" % [mod.dir_name, mod.manifest.load_before], LOG_NAME)


# Get the load order of mods, using a custom sorter
func _get_load_order(mod_data_array: Array) -> Array:

Expand Down
4 changes: 3 additions & 1 deletion addons/mod_loader/mod_manifest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var authors: PoolStringArray = []
var compatible_game_version: PoolStringArray = []
# only used for information
var incompatibilities: PoolStringArray = []
var load_before: PoolStringArray = []
var tags : PoolStringArray = []
var config_defaults := {}
var description_rich := ""
Expand Down Expand Up @@ -70,9 +71,10 @@ func _init(manifest: Dictionary) -> void:
website_url = manifest.website_url
dependencies = manifest.dependencies

var godot_details: Dictionary = manifest.extra.godot
var godot_details: Dictionary = manifest.extra.godot
authors = _get_array_from_dict(godot_details, "authors")
incompatibilities = _get_array_from_dict(godot_details, "incompatibilities")
load_before = _get_array_from_dict(godot_details, "load_before")
compatible_game_version = _get_array_from_dict(godot_details, "compatible_game_version")
description_rich = _get_string_from_dict(godot_details, "description_rich")
tags = _get_array_from_dict(godot_details, "tags")
Expand Down