@@ -196,34 +196,32 @@ static func get_all_as_array() -> Array:
196196# Example: If "Mod-TestMod" is set in disabled_mods via the editor, the mod will appear disabled in the user profile.
197197# If the user then enables the mod in the profile the entry in disabled_mods will be removed.
198198static func _update_disabled_mods () -> void :
199- var user_profile_disabled_mods := []
200199 var current_user_profile : ModUserProfile
201200
201+ current_user_profile = get_current ()
202+
202203 # Check if a current user profile is set
203- if not ModLoaderStore . current_user_profile :
204+ if not current_user_profile :
204205 ModLoaderLog .info ("There is no current user profile. The \" default\" profile will be created." , LOG_NAME )
205206 return
206207
207- current_user_profile = get_current ()
208-
209208 # Iterate through the mod list in the current user profile to find disabled mods
210209 for mod_id in current_user_profile .mod_list :
211- if not current_user_profile .mod_list [mod_id ].is_active :
212- user_profile_disabled_mods .push_back (mod_id )
213-
214- # Append the disabled mods to the global list of disabled mods
215- ModLoaderStore .ml_options .disabled_mods .append_array (user_profile_disabled_mods )
210+ var mod_list_entry : Dictionary = current_user_profile .mod_list [mod_id ]
211+ ModLoaderStore .mod_data [mod_id ].is_active = mod_list_entry .is_active
216212
217213 ModLoaderLog .debug (
218- "Updated the global list of disabled mods \" %s \" , based on the current user profile \" %s \" "
219- % [ ModLoaderStore . ml_options . disabled_mods , current_user_profile .name ] ,
214+ "Updated the active state of all mods, based on the current user profile \" %s \" "
215+ % current_user_profile .name ,
220216 LOG_NAME )
221217
222218
223219# This function updates the mod lists of all user profiles with newly loaded mods that are not already present.
224220# It does so by comparing the current set of loaded mods with the mod list of each user profile, and adding any missing mods.
225221# Additionally, it checks for and deletes any mods from each profile's mod list that are no longer installed on the system.
226222static func _update_mod_lists () -> bool :
223+ # Generate a list of currently present mods by combining the mods
224+ # in mod_data and ml_options.disabled_mods from ModLoaderStore.
227225 var current_mod_list := _generate_mod_list ()
228226
229227 # Iterate over all user profiles
@@ -246,18 +244,17 @@ static func _update_mod_lists() -> bool:
246244 return is_save_success
247245
248246
249- # Updates the mod list by checking the validity of each mod entry and making necessary modifications.
247+ # This function takes a mod_list dictionary and optional mod_data dictionary as input and returns
248+ # an updated mod_list dictionary. It iterates over each mod ID in the mod list, checks if the mod
249+ # is still installed and if the current_config is present. If the mod is not installed or the current
250+ # config is missing, the mod is removed or its current_config is reset to the default configuration.
250251static func _update_mod_list (mod_list : Dictionary , mod_data := ModLoaderStore .mod_data ) -> Dictionary :
251252 var updated_mod_list := mod_list .duplicate (true )
252253
253254 # Iterate over each mod ID in the mod list
254255 for mod_id in updated_mod_list :
255256 var mod_list_entry : Dictionary = updated_mod_list [mod_id ]
256257
257- # If mod data is accessible and the mod is loaded
258- if not mod_data .empty () and mod_data .has (mod_id ):
259- mod_list_entry = _generate_mod_list_entry (mod_id , true )
260-
261258 # If mod data is accessible and the mod is not loaded
262259 if not mod_data .empty () and not mod_data .has (mod_id ):
263260 # Check if the mod_dir for the mod-id exists
@@ -327,7 +324,10 @@ static func _set_mod_state(mod_id: String, profile_name: String, activate: bool)
327324 return false
328325
329326 # Handle mod state
327+ # Set state for user profile
330328 ModLoaderStore .user_profiles [profile_name ].mod_list [mod_id ].is_active = activate
329+ # Set state in the ModData
330+ ModLoaderStore .mod_data [mod_id ].is_active = activate
331331
332332 # Save profiles to the user profiles JSON file
333333 var is_save_success := _save ()
0 commit comments