Skip to content

Commit 6c91c47

Browse files
authored
fix: 🐛 mod_data init and uninstall detection (#307)
Refactored `_update_mod_list()` by adding the missing `.keys()` call, removing the outdated check for uninstalled mods, and implemented an if statement in `_setup_mods()` within *mod_loader.gd* to prevent initializing `mod_data` twice, which resolves the issue of the missing `zip_data`. closes #306
1 parent 279a012 commit 6c91c47

File tree

3 files changed

+26
-35
lines changed

3 files changed

+26
-35
lines changed

addons/mod_loader/api/profile.gd

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -253,45 +253,36 @@ static func _update_mod_list(mod_list: Dictionary, mod_data := ModLoaderStore.mo
253253
var updated_mod_list := mod_list.duplicate(true)
254254

255255
# Iterate over each mod ID in the mod list
256-
for mod_id in updated_mod_list:
256+
for mod_id in updated_mod_list.keys():
257257
var mod_list_entry: Dictionary = updated_mod_list[mod_id]
258258

259-
# If mod data is accessible and the mod is not loaded
260-
if not mod_data.empty() and not mod_data.has(mod_id):
261-
# Check if the mod_dir for the mod-id exists
262-
if not _ModLoaderFile.dir_exists(_ModLoaderPath.get_unpacked_mods_dir_path() + mod_id):
263-
# If the mod directory doesn't exist,
264-
# the mod is no longer installed and can be removed from the mod list
265-
updated_mod_list.erase(mod_id)
266-
continue
267-
268259
# Check if the current config doesn't exist
269260
# This can happen if the config file was manually deleted
270261
if mod_list_entry.has("current_config") and _ModLoaderPath.get_path_to_mod_config_file(mod_id, mod_list_entry.current_config).empty():
271262
# If the current config doesn't exist, reset it to the default configuration
272263
mod_list_entry.current_config = ModLoaderConfig.DEFAULT_CONFIG_NAME
273264

274-
# If the mod is not loaded
275-
if not mod_data.has(mod_id):
276-
if (
277-
# Check if the entry has a zip_path key
278-
mod_list_entry.has("zip_path") and
279-
# Check if the entry has a zip_path
280-
not mod_list_entry.zip_path.empty() and
281-
# Check if the zip file for the mod exists
282-
not _ModLoaderFile.file_exists(mod_list_entry.zip_path)
283-
):
284-
# If the mod directory doesn't exist,
285-
# the mod is no longer installed and can be removed from the mod list
286-
ModLoaderLog.debug(
287-
"Mod \"%s\" has been deleted from all user profiles as the corresponding zip file no longer exists at path \"%s\"."
288-
% [mod_id, mod_list_entry.zip_path],
289-
LOG_NAME,
290-
true
291-
)
292-
293-
updated_mod_list.erase(mod_id)
294-
continue
265+
if (
266+
# If the mod is not loaded
267+
not mod_data.has(mod_id) and
268+
# Check if the entry has a zip_path key
269+
mod_list_entry.has("zip_path") and
270+
# Check if the entry has a zip_path
271+
not mod_list_entry.zip_path.empty() and
272+
# Check if the zip file for the mod doesn't exist
273+
not _ModLoaderFile.file_exists(mod_list_entry.zip_path)
274+
):
275+
# If the mod directory doesn't exist,
276+
# the mod is no longer installed and can be removed from the mod list
277+
ModLoaderLog.debug(
278+
"Mod \"%s\" has been deleted from all user profiles as the corresponding zip file no longer exists at path \"%s\"."
279+
% [mod_id, mod_list_entry.zip_path],
280+
LOG_NAME,
281+
true
282+
)
283+
284+
updated_mod_list.erase(mod_id)
285+
continue
295286

296287
updated_mod_list[mod_id] = mod_list_entry
297288

addons/mod_loader/internal/file.gd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ static func load_zips_in_folder(folder_path: String) -> Dictionary:
5858
ModLoaderLog.error("Can't read mod folder %s (Error: %s)" % [folder_path, mod_dir_listdir_error], LOG_NAME)
5959
return {}
6060

61-
62-
6361
# Get all zip folders inside the game mod folder
6462
while true:
6563
# Get the next file in the directory

addons/mod_loader/mod_loader.gd

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ func _setup_mods() -> int:
282282
ModLoaderLog.info("Skipped setting up mod: \"%s\"" % mod_dir_name, LOG_NAME)
283283
continue
284284

285-
# Init the mod data for each mod
286-
_init_mod_data(mod_dir_name)
285+
# Initialize the mod data for each mod if there is no existing mod data for that mod.
286+
if not ModLoaderStore.mod_data.has(mod_dir_name):
287+
_init_mod_data(mod_dir_name)
288+
287289
unpacked_mods_count += 1
288290

289291
dir.list_dir_end()

0 commit comments

Comments
 (0)