Skip to content

Commit 3228cb2

Browse files
authored
fix: 🐛 current_user_profile reference to user_profiles (#293)
Resolves a bug where the `current_user_profile` doesn't reference the Profile object in `user_profiles`. closes #290
1 parent 4a7b512 commit 3228cb2

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

addons/mod_loader/api/profile.gd

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ static func create_profile(profile_name: String) -> bool:
8080
if not new_profile:
8181
return false
8282

83-
# Set it as the current profile
84-
ModLoaderStore.current_user_profile = new_profile
85-
8683
# Store the new profile in the ModLoaderStore
8784
ModLoaderStore.user_profiles[profile_name] = new_profile
8885

86+
# Set it as the current profile
87+
ModLoaderStore.current_user_profile = ModLoaderStore.user_profiles[profile_name]
88+
8989
# Store the new profile in the json file
9090
var is_save_success := _save()
9191

@@ -108,7 +108,7 @@ static func set_profile(user_profile: ModUserProfile) -> bool:
108108
return false
109109

110110
# Update the current_user_profile in the ModLoaderStore
111-
ModLoaderStore.current_user_profile = user_profile
111+
ModLoaderStore.current_user_profile = ModLoaderStore.user_profiles[user_profile.name]
112112

113113
# Save changes in the json file
114114
var is_save_success := _save()
@@ -390,12 +390,6 @@ static func _load() -> bool:
390390
ModLoaderLog.error("No profile file found at \"%s\"" % FILE_PATH_USER_PROFILES, LOG_NAME)
391391
return false
392392

393-
# Set the current user profile to the one specified in the data
394-
var current_user_profile: ModUserProfile = ModUserProfile.new()
395-
current_user_profile.name = data.current_profile
396-
current_user_profile.mod_list = data.profiles[data.current_profile].mod_list
397-
ModLoaderStore.current_user_profile = current_user_profile
398-
399393
# Loop through each profile in the data and add them to ModLoaderStore
400394
for profile_name in data.profiles.keys():
401395
# Get the profile data from the JSON object
@@ -405,6 +399,9 @@ static func _load() -> bool:
405399
var new_profile := _create_new_profile(profile_name, profile_data.mod_list)
406400
ModLoaderStore.user_profiles[profile_name] = new_profile
407401

402+
# Set the current user profile to the one specified in the data
403+
ModLoaderStore.current_user_profile = ModLoaderStore.user_profiles[data.current_profile]
404+
408405
return true
409406

410407

0 commit comments

Comments
 (0)