From 31a192c6eb30b933fffccf6e994211ecabd0a609 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Fri, 18 Apr 2025 22:14:19 +0300 Subject: [PATCH] Code style fix, added return of ErrorCode.InvalidArgument to AddPlayerCharacter/RemovePlayerCharacter --- CustomizePlus/Api/CustomizePlusIpc.Profile.cs | 30 ++++++------------- CustomizePlus/Profiles/ProfileManager.cs | 12 +++++--- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs index 35d5acc..8fb49b8 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs @@ -107,28 +107,22 @@ public partial class CustomizePlusIpc private int AddPlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId) { if (uniqueId == Guid.Empty) - { return (int)ErrorCode.ProfileNotFound; - } - var profile = this._profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); + var profile = _profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); if (profile == null) - { return (int)ErrorCode.ProfileNotFound; - } if (!ByteString.FromString(name, out var byteString)) - { return (int)ErrorCode.InvalidCharacter; - } - var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId); + var playerIdentifier = _actorManager.CreatePlayer(byteString, worldId); if (playerIdentifier == ActorIdentifier.Invalid) - { return (int)ErrorCode.InvalidCharacter; - } - this._profileManager.AddCharacter(profile, playerIdentifier); + if(!_profileManager.AddCharacter(profile, playerIdentifier)) + return (int)ErrorCode.InvalidArgument; //Returned if character is already associated with provided profile + return (int)ErrorCode.Success; } @@ -139,28 +133,22 @@ public partial class CustomizePlusIpc private int RemovePlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId) { if (uniqueId == Guid.Empty) - { return (int)ErrorCode.ProfileNotFound; - } - var profile = this._profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); + var profile = _profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); if (profile == null) - { return (int)ErrorCode.ProfileNotFound; - } if (!ByteString.FromString(name, out var byteString)) - { return (int)ErrorCode.InvalidCharacter; - } var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId); if (playerIdentifier == ActorIdentifier.Invalid) - { return (int)ErrorCode.InvalidCharacter; - } - this._profileManager.DeleteCharacter(profile, playerIdentifier); + if(!_profileManager.DeleteCharacter(profile, playerIdentifier)) + return (int)ErrorCode.InvalidArgument; //Returned if character is not associated with provided profile + return (int)ErrorCode.Success; } diff --git a/CustomizePlus/Profiles/ProfileManager.cs b/CustomizePlus/Profiles/ProfileManager.cs index edd24ed..d5b2420 100644 --- a/CustomizePlus/Profiles/ProfileManager.cs +++ b/CustomizePlus/Profiles/ProfileManager.cs @@ -178,10 +178,10 @@ public partial class ProfileManager : IDisposable /// /// Add character to profile /// - public void AddCharacter(Profile profile, ActorIdentifier actorIdentifier) + public bool AddCharacter(Profile profile, ActorIdentifier actorIdentifier) { if (!actorIdentifier.IsValid || profile.Characters.Any(x => actorIdentifier.MatchesIgnoringOwnership(x)) || profile.IsTemporary) - return; + return false; profile.Characters.Add(actorIdentifier); @@ -189,15 +189,17 @@ public partial class ProfileManager : IDisposable _logger.Debug($"Add character for profile {profile.UniqueId}."); _event.Invoke(ProfileChanged.Type.AddedCharacter, profile, actorIdentifier); + + return true; } /// /// Delete character from profile /// - public void DeleteCharacter(Profile profile, ActorIdentifier actorIdentifier) + public bool DeleteCharacter(Profile profile, ActorIdentifier actorIdentifier) { if (!actorIdentifier.IsValid || !profile.Characters.Any(x => actorIdentifier.MatchesIgnoringOwnership(x)) || profile.IsTemporary) - return; + return false; profile.Characters.Remove(actorIdentifier); @@ -205,6 +207,8 @@ public partial class ProfileManager : IDisposable _logger.Debug($"Removed character from profile {profile.UniqueId}."); _event.Invoke(ProfileChanged.Type.RemovedCharacter, profile, actorIdentifier); + + return true; } ///