Skip to content

feat: ✨ added load_before #185

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

Merged
merged 4 commits into from
Mar 25, 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
4 changes: 4 additions & 0 deletions addons/mod_loader/classes/mod_manifest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var compatible_game_version: PoolStringArray = []
var compatible_mod_loader_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 @@ -77,6 +78,7 @@ func _init(manifest: Dictionary) -> void:
var godot_details: Dictionary = manifest.extra.godot
authors = ModLoaderUtils.get_array_from_dict(godot_details, "authors")
incompatibilities = ModLoaderUtils.get_array_from_dict(godot_details, "incompatibilities")
load_before = ModLoaderUtils.get_array_from_dict(godot_details, "load_before")
compatible_game_version = ModLoaderUtils.get_array_from_dict(godot_details, "compatible_game_version")
compatible_mod_loader_version = _handle_compatible_mod_loader_version(godot_details)
description_rich = ModLoaderUtils.get_string_from_dict(godot_details, "description_rich")
Expand Down Expand Up @@ -113,6 +115,7 @@ func get_as_dict() -> Dictionary:
"compatible_game_version": compatible_game_version,
"compatible_mod_loader_version": compatible_mod_loader_version,
"incompatibilities": incompatibilities,
"load_before": load_before,
"tags": tags,
"config_defaults": config_defaults,
"description_rich": description_rich,
Expand All @@ -135,6 +138,7 @@ func to_json() -> String:
"compatible_game_version": compatible_game_version,
"compatible_mod_loader_version": compatible_mod_loader_version,
"incompatibilities": incompatibilities,
"load_before": load_before,
"tags": tags,
"config_defaults": config_defaults,
"description_rich": description_rich,
Expand Down
43 changes: 43 additions & 0 deletions addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ 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 Down Expand Up @@ -474,6 +485,38 @@ 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

ModLoaderUtils.log_debug("Load before - In mod %s detected." % mod.dir_name, LOG_NAME)

# For each mod id in load_before
for load_before_id in mod.manifest.load_before:

# Check if the load_before mod exists
if not mod_data.has(load_before_id):
ModLoaderUtils.log_debug("Load before - Skipping %s because it's missing" % load_before_id, LOG_NAME)
continue

var load_before_mod_dependencies := mod_data[load_before_id].manifest.dependencies as PoolStringArray

# Check if it's already a dependency
if mod.dir_name in load_before_mod_dependencies:
ModLoaderUtils.log_debug("Load before - Skipping because it's already a dependency for %s" % load_before_id, LOG_NAME)
continue

# Add the mod to the dependency array
load_before_mod_dependencies.append(mod.dir_name)
mod_data[load_before_id].manifest.dependencies = load_before_mod_dependencies

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


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

Expand Down