using Robust.Shared.Serialization; using Robust.Shared.Utility; 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 Dictionary _characters; public PlayerPreferences(IEnumerable> characters, int selectedCharacterIndex, Color adminOOCColor) { _characters = new Dictionary(characters); SelectedCharacterIndex = selectedCharacterIndex; AdminOOCColor = adminOOCColor; } /// /// All player characters. /// public IReadOnlyDictionary Characters => _characters; public ICharacterProfile GetProfile(int index) { return _characters[index]; } /// /// Index of the currently selected character. /// public int SelectedCharacterIndex { get; } /// /// The currently selected character. /// public ICharacterProfile SelectedCharacter => Characters[SelectedCharacterIndex]; public Color AdminOOCColor { get; set; } public int IndexOfCharacter(ICharacterProfile profile) { return _characters.FirstOrNull(p => p.Value == profile)?.Key ?? -1; } public bool TryIndexOfCharacter(ICharacterProfile profile, out int index) { return (index = IndexOfCharacter(profile)) != -1; } } }