@@ -95,6 +95,45 @@ static func create_profile(profile_name: String) -> bool:
9595 return is_save_success
9696
9797
98+ # Renames an existing user profile.
99+ #
100+ # Parameters:
101+ # - old_profile_name (String): The current name for the user profile (must be unique).
102+ # - new_profile_name (String): The new name for the user profile (must be unique).
103+ #
104+ # Returns: bool
105+ static func rename_profile (old_profile_name : String , new_profile_name : String ) -> bool :
106+ # Verify that the old profile name is already in use
107+ if not ModLoaderStore .user_profiles .has (old_profile_name ):
108+ ModLoaderLog .error ("User profile with the name of \" %s \" does not exist." % old_profile_name , LOG_NAME )
109+ return false
110+
111+ # Verify that the new profile_name is not already in use
112+ if ModLoaderStore .user_profiles .has (new_profile_name ):
113+ ModLoaderLog .error ("User profile with the name of \" %s \" already exists." % new_profile_name , LOG_NAME )
114+ return false
115+
116+ # Rename user profile
117+ var profile_renamed := ModLoaderStore .user_profiles [old_profile_name ].duplicate () as ModUserProfile
118+ profile_renamed .name = new_profile_name
119+
120+ # Remove old profile entry, replace it with new name entry in the ModLoaderStore
121+ ModLoaderStore .user_profiles .erase (old_profile_name )
122+ ModLoaderStore .user_profiles [new_profile_name ] = profile_renamed
123+
124+ # Set it as the current profile if it was the current profile
125+ if ModLoaderStore .current_user_profile .name == old_profile_name :
126+ set_profile (profile_renamed )
127+
128+ # Store the new profile in the json file
129+ var is_save_success := _save ()
130+
131+ if is_save_success :
132+ ModLoaderLog .debug ("Renamed user profile from \" %s \" to \" %s \" " % [old_profile_name , new_profile_name ], LOG_NAME )
133+
134+ return is_save_success
135+
136+
98137# Sets the current user profile to the given user profile.
99138#
100139# Parameters:
0 commit comments