@@ -196,34 +196,32 @@ static func get_all_as_array() -> Array:
196
196
# Example: If "Mod-TestMod" is set in disabled_mods via the editor, the mod will appear disabled in the user profile.
197
197
# If the user then enables the mod in the profile the entry in disabled_mods will be removed.
198
198
static func _update_disabled_mods () -> void :
199
- var user_profile_disabled_mods := []
200
199
var current_user_profile : ModUserProfile
201
200
201
+ current_user_profile = get_current ()
202
+
202
203
# Check if a current user profile is set
203
- if not ModLoaderStore . current_user_profile :
204
+ if not current_user_profile :
204
205
ModLoaderLog .info ("There is no current user profile. The \" default\" profile will be created." , LOG_NAME )
205
206
return
206
207
207
- current_user_profile = get_current ()
208
-
209
208
# Iterate through the mod list in the current user profile to find disabled mods
210
209
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
216
212
217
213
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 ,
220
216
LOG_NAME )
221
217
222
218
223
219
# This function updates the mod lists of all user profiles with newly loaded mods that are not already present.
224
220
# It does so by comparing the current set of loaded mods with the mod list of each user profile, and adding any missing mods.
225
221
# Additionally, it checks for and deletes any mods from each profile's mod list that are no longer installed on the system.
226
222
static 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.
227
225
var current_mod_list := _generate_mod_list ()
228
226
229
227
# Iterate over all user profiles
@@ -246,18 +244,17 @@ static func _update_mod_lists() -> bool:
246
244
return is_save_success
247
245
248
246
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.
250
251
static func _update_mod_list (mod_list : Dictionary , mod_data := ModLoaderStore .mod_data ) -> Dictionary :
251
252
var updated_mod_list := mod_list .duplicate (true )
252
253
253
254
# Iterate over each mod ID in the mod list
254
255
for mod_id in updated_mod_list :
255
256
var mod_list_entry : Dictionary = updated_mod_list [mod_id ]
256
257
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
-
261
258
# If mod data is accessible and the mod is not loaded
262
259
if not mod_data .empty () and not mod_data .has (mod_id ):
263
260
# 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)
327
324
return false
328
325
329
326
# Handle mod state
327
+ # Set state for user profile
330
328
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
331
331
332
332
# Save profiles to the user profiles JSON file
333
333
var is_save_success := _save ()
0 commit comments