using System; using System.Collections.Generic; using CIG.Translation; namespace CIG3.ExtensionMethods { public static class IslandExtensions { public static bool IsAvailable(this Island island) { return IslandExtensions.AvailableIslands.Contains(island); } public static bool IsValid(this Island island) { return island > Island.None && island < Island.Count; } public static string GetSceneName(this Island island) { if (island.IsValid()) { string text = IslandExtensions._sceneNames[(int)island]; if (text == null) { text = (IslandExtensions._sceneNames[(int)island] = island.ToString()); } return text; } return null; } public static ILocalizedString GetDisplayName(this Island island) { if (island.IsValid()) { ILocalizedString localizedString = IslandExtensions._displayNames[(int)island]; if (localizedString == null) { localizedString = (IslandExtensions._displayNames[(int)island] = Localization.Key("island_name_" + island.ToString().ToLowerInvariant())); } return localizedString; } return null; } public static int GetIndex(this Island island) { if (island.IsValid()) { return (int)island; } return -1; } public static Island GetIsland(int index) { if (((Island)index).IsValid()) { return (Island)index; } return Island.None; } public static IList GetIslands() { if (IslandExtensions._islands == null) { List list = new List(); for (int i = 0; i < 10; i++) { list.Add((Island)i); } IslandExtensions._islands = list.AsReadOnly(); } return IslandExtensions._islands; } public static Island[] GetIslandsArray() { Island[] array = new Island[10]; IslandExtensions.GetIslands().CopyTo(array, 0); return array; } public static List IslandsWithElementType(int req) { if (req >= 0 && req < IslandExtensions._islandsPerType.Count) { return IslandExtensions._islandsPerType[req]; } return new List(); } private static readonly HashSet AvailableIslands = new HashSet { Island.GoneGreenlands, Island.BountyBreeze, Island.DesertShore, Island.JungleSlush, Island.RoughRocks, Island.LagoonAtoll, Island.SwampySlopes, Island.VolcanoVitus, Island.ShiveringSnows, Island.FreakyFloors }; private static readonly List> _islandsPerType = new List> { new List(), new List { Island.BountyBreeze, Island.GoneGreenlands, Island.JungleSlush, Island.LagoonAtoll, Island.RoughRocks, Island.SwampySlopes, Island.VolcanoVitus, Island.ShiveringSnows, Island.FreakyFloors }, new List { Island.BountyBreeze, Island.GoneGreenlands }, new List { Island.BountyBreeze, Island.GoneGreenlands, Island.JungleSlush, Island.LagoonAtoll, Island.SwampySlopes, Island.VolcanoVitus, Island.FreakyFloors }, new List { Island.DesertShore, Island.FreakyFloors }, new List { Island.JungleSlush }, new List { Island.RoughRocks }, new List { Island.SwampySlopes, Island.FreakyFloors }, new List { Island.VolcanoVitus }, new List { Island.ShiveringSnows, Island.FreakyFloors } }; private static IList _islands = null; private static string[] _sceneNames = new string[10]; private static ILocalizedString[] _displayNames = new ILocalizedString[10]; } }