From 3228cb25f7e7659348c1a56dc18cc788b2837a51 Mon Sep 17 00:00:00 2001 From: KANAjetzt <41547570+KANAjetzt@users.noreply.github.com> Date: Thu, 22 Jun 2023 10:45:21 +0200 Subject: [PATCH] fix: :bug: `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 --- addons/mod_loader/api/profile.gd | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/addons/mod_loader/api/profile.gd b/addons/mod_loader/api/profile.gd index da715d76..b15b022c 100644 --- a/addons/mod_loader/api/profile.gd +++ b/addons/mod_loader/api/profile.gd @@ -80,12 +80,12 @@ static func create_profile(profile_name: String) -> bool: if not new_profile: return false - # Set it as the current profile - ModLoaderStore.current_user_profile = new_profile - # Store the new profile in the ModLoaderStore ModLoaderStore.user_profiles[profile_name] = new_profile + # Set it as the current profile + ModLoaderStore.current_user_profile = ModLoaderStore.user_profiles[profile_name] + # Store the new profile in the json file var is_save_success := _save() @@ -108,7 +108,7 @@ static func set_profile(user_profile: ModUserProfile) -> bool: return false # Update the current_user_profile in the ModLoaderStore - ModLoaderStore.current_user_profile = user_profile + ModLoaderStore.current_user_profile = ModLoaderStore.user_profiles[user_profile.name] # Save changes in the json file var is_save_success := _save() @@ -390,12 +390,6 @@ static func _load() -> bool: ModLoaderLog.error("No profile file found at \"%s\"" % FILE_PATH_USER_PROFILES, LOG_NAME) return false - # Set the current user profile to the one specified in the data - var current_user_profile: ModUserProfile = ModUserProfile.new() - current_user_profile.name = data.current_profile - current_user_profile.mod_list = data.profiles[data.current_profile].mod_list - ModLoaderStore.current_user_profile = current_user_profile - # Loop through each profile in the data and add them to ModLoaderStore for profile_name in data.profiles.keys(): # Get the profile data from the JSON object @@ -405,6 +399,9 @@ static func _load() -> bool: var new_profile := _create_new_profile(profile_name, profile_data.mod_list) ModLoaderStore.user_profiles[profile_name] = new_profile + # Set the current user profile to the one specified in the data + ModLoaderStore.current_user_profile = ModLoaderStore.user_profiles[data.current_profile] + return true