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

feat: ✨ added load_before #185

Merged
merged 4 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 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,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
KANAjetzt marked this conversation as resolved.
Show resolved Hide resolved
load_before_mod_dependencies.append(mod.dir_name)
mod_data[load_before_id].manifest.dependencies = load_before_mod_dependencies
Qubus0 marked this conversation as resolved.
Show resolved Hide resolved

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