Skip to content

Commit

Permalink
refactor: ♻️ added zip_path to user profiles
Browse files Browse the repository at this point in the history
This allows to verify if the mod is still installed by confirming the existence of the zip file. However, this check is only performed when the mod is not loaded and a path to the zip file exists. This ensures that mods are not deleted from the profile when running in the editor. It's important to note that this new check may cause mods to appear in user profiles even if they are currently not loaded. To determine if a mod is actually loaded, you should also check `ModLoaderStore.mod_data` or use `ModLoaderMod.is_mod_loaded()`.

closes GodotModding#288
  • Loading branch information
KANAjetzt committed Jun 24, 2023
1 parent 23dddf2 commit 95f2dfd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions addons/mod_loader/api/profile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@ static func _update_mod_list(mod_list: Dictionary, mod_data := ModLoaderStore.mo
# If the current config doesn't exist, reset it to the default configuration
mod_list_entry.current_config = ModLoaderConfig.DEFAULT_CONFIG_NAME

# If the mod is not loaded
if not mod_data.has(mod_id):
if (
# Check if the entry has a zip_path key
mod_list_entry.has("zip_path") and
# Check if the entry has a zip_path
not mod_list_entry.zip_path.empty() and
# Check if the zip file for the mod exists
not _ModLoaderFile.file_exists(mod_list_entry.zip_path)
):
# If the mod directory doesn't exist,
# the mod is no longer installed and can be removed from the mod list
ModLoaderLog.debug(
"Mod \"%s\" has been deleted from all user profiles as the corresponding zip file no longer exists at path \"%s\"."
% [mod_id, mod_list_entry.zip_path],
LOG_NAME,
true
)

updated_mod_list.erase(mod_id)
continue

updated_mod_list[mod_id] = mod_list_entry

return updated_mod_list
Expand All @@ -298,7 +320,13 @@ static func _generate_mod_list() -> Dictionary:
static func _generate_mod_list_entry(mod_id: String, is_active: bool) -> Dictionary:
var mod_list_entry := {}

# Set the mods active state
mod_list_entry.is_active = is_active

# Set the mods zip path if available
if ModLoaderStore.mod_data.has(mod_id):
mod_list_entry.zip_path = ModLoaderStore.mod_data[mod_id].zip_path

# Set the current_config if the mod has a config schema and is active
if is_active and not ModLoaderConfig.get_config_schema(mod_id).empty():
var current_config: ModConfig = ModLoaderStore.mod_data[mod_id].current_config
Expand Down

0 comments on commit 95f2dfd

Please sign in to comment.