using System; using System.Collections.Generic; using System.Linq; using Robust.Shared.Serialization; namespace Content.Shared.Preferences { /// /// Contains all player characters and the index of the currently selected character. /// Serialized both over the network and to disk. /// [Serializable] [NetSerializable] public sealed class PlayerPreferences { private List _characters; public PlayerPreferences(IEnumerable characters, int selectedCharacterIndex) { _characters = characters.ToList(); SelectedCharacterIndex = selectedCharacterIndex; } /// /// All player characters. /// public IEnumerable Characters => _characters.AsEnumerable(); /// /// Index of the currently selected character. /// public int SelectedCharacterIndex { get; } /// /// The currently selected character. /// public ICharacterProfile SelectedCharacter => Characters.ElementAtOrDefault(SelectedCharacterIndex); public int FirstEmptySlot => IndexOfCharacter(null); public int IndexOfCharacter(ICharacterProfile profile) { return _characters.FindIndex(x => x == profile); } } }