Fix creating and deleting character slots crashing the client and server (#2172)

* Fix creating a character slot crashing the client

* a

* Fix deleting character profiles
This commit is contained in:
DrSmugleaf
2020-10-06 12:03:14 +02:00
committed by GitHub
parent f9bb3fed6f
commit f35625630b
5 changed files with 89 additions and 5 deletions

View File

@@ -41,11 +41,20 @@ namespace Content.Shared.Preferences
/// </summary>
public ICharacterProfile SelectedCharacter => Characters.ElementAtOrDefault(SelectedCharacterIndex);
public int FirstEmptySlot => IndexOfCharacter(null);
public int FirstEmptySlot()
{
var firstEmpty = IndexOfCharacter(null);
return firstEmpty == -1 ? _characters.Count : firstEmpty;
}
public int IndexOfCharacter(ICharacterProfile profile)
{
return _characters.FindIndex(x => x == profile);
}
public bool TryIndexOfCharacter(ICharacterProfile profile, out int index)
{
return (index = IndexOfCharacter(profile)) != -1;
}
}
}