Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: Allow both workshop and local mods to be loaded #369

Merged
merged 2 commits into from
Mar 22, 2024
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
2 changes: 1 addition & 1 deletion addons/mod_loader/api/deprecated.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static func deprecated_message(msg: String, since_version: String = "") -> void:
#
# Returns: void
static func _deprecated_log(msg: String) -> void:
if ModLoaderStore.ml_options.ignore_deprecated_errors or OS.has_feature("standalone"):
if ModLoaderStore and ModLoaderStore.ml_options.ignore_deprecated_errors or OS.has_feature("standalone"):
ModLoaderLog.warning(msg, LOG_NAME)
else:
ModLoaderLog.fatal(msg, LOG_NAME)
14 changes: 7 additions & 7 deletions addons/mod_loader/mod_loader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func _exit_tree() -> void:


func _load_mods() -> void:
ModLoaderStore.previous_mod_dirs = _ModLoaderPath.get_dir_paths_in_dir(_ModLoaderPath.get_unpacked_mods_dir_path())
# Loop over "res://mods" and add any mod zips to the unpacked virtual
# directory (UNPACKED_DIR)
var zip_data := _load_mod_zips()
Expand Down Expand Up @@ -225,18 +226,17 @@ func _check_autoload_positions() -> void:
var _pos_ml_core := _ModLoaderGodot.check_autoload_position("ModLoader", 1, true)


# Loop over "res://mods" and add any mod zips to the unpacked virtual directory
# (UNPACKED_DIR)
# Add any mod zips to the unpacked virtual directory
func _load_mod_zips() -> Dictionary:
var zip_data := {}

if not ModLoaderStore.ml_options.steam_workshop_enabled:
if ModLoaderStore.ml_options.load_from_local:
var mods_folder_path := _ModLoaderPath.get_path_to_mods()

# If we're not using Steam workshop, just loop over the mod ZIPs.
# Loop over the mod zips in the "mods" directory
var loaded_zip_data := _ModLoaderFile.load_zips_in_folder(mods_folder_path)
zip_data.merge(loaded_zip_data)
else:

if ModLoaderStore.ml_options.load_from_steam_workshop or ModLoaderStore.ml_options.steam_workshop_enabled:
# If we're using Steam workshop, loop over the workshop item directories
var loaded_workshop_zip_data := _ModLoaderSteam.load_steam_workshop_zips()
zip_data.merge(loaded_workshop_zip_data)
Expand All @@ -254,7 +254,7 @@ func _setup_mods() -> int:
if dir == null:
ModLoaderLog.error("Can't open unpacked mods folder %s." % unpacked_mods_path, LOG_NAME)
return -1
if not dir.list_dir_begin() == OK:# TODOGODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547
if not dir.list_dir_begin() == OK:
ModLoaderLog.error("Can't read unpacked mods folder %s." % unpacked_mods_path, LOG_NAME)
return -1

Expand Down
11 changes: 11 additions & 0 deletions addons/mod_loader/mod_loader_store.gd
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ var ml_options := {

# If true, ModLoader will load mod ZIPs from the Steam workshop directory,
# instead of the default location (res://mods)
# INFO: Redundant since the introduction of mod source options, kept for backwards compatibility.
steam_workshop_enabled = false,

# Overrides for the path mods/configs/workshop folders are loaded from.
Expand All @@ -130,6 +131,12 @@ var ml_options := {

# Array of mods that should be ignored when logging messages (contains mod IDs as strings)
ignored_mod_names_in_log = [],

# Mod Sources
# Indicates whether to load mods from the Steam Workshop directory, or the overridden workshop path.
load_from_steam_workshop = false,
# Indicates whether to load mods from the "mods" folder located at the game's install directory, or the overridden mods path.
load_from_local = true,
}


Expand Down Expand Up @@ -169,6 +176,8 @@ func _update_ml_options_from_options_resource() -> void:
# Update from the options in the resource
for key in ml_options:
ml_options[key] = current_options[key]
if key == "steam_workshop_enabled" and current_options[key] == true:
ModLoaderDeprecated.deprecated_message("The Steam Workshop Enabled option has been deprecated. Please use the mod source options instead.", "6.3.0")

# Get options overrides by feature tags
# An override is saved as Dictionary[String: ModLoaderOptionsProfile]
Expand Down Expand Up @@ -199,6 +208,8 @@ func _update_ml_options_from_options_resource() -> void:
# Update from the options in the resource
for key in ml_options:
ml_options[key] = override_options[key]
if key == "steam_workshop_enabled" and override_options[key] == true:
ModLoaderDeprecated.deprecated_message("The Steam Workshop Enabled option has been deprecated. Please use the mod source options instead.", "6.3.0")


# Update ModLoader's options, via CLI args
Expand Down
5 changes: 5 additions & 0 deletions addons/mod_loader/resources/options_profile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ extends Resource
@export_dir var override_path_to_workshop = ""
@export var ignore_deprecated_errors: bool = false
@export var ignored_mod_names_in_log: Array[String] = []
@export_group("Mod Source")
## Indicates whether to load mods from the Steam Workshop directory, or the overridden workshop path.
@export var load_from_steam_workshop: bool = false
## Indicates whether to load mods from the "mods" folder located at the game's install directory, or the overridden mods path.
@export var load_from_local: bool = true