|
- 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<Island> GetIslands()
- {
- if (IslandExtensions._islands == null)
- {
- List<Island> list = new List<Island>();
- 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<Island> IslandsWithElementType(int req)
- {
- if (req >= 0 && req < IslandExtensions._islandsPerType.Count)
- {
- return IslandExtensions._islandsPerType[req];
- }
- return new List<Island>();
- }
-
- private static readonly HashSet<Island> AvailableIslands = new HashSet<Island>
- {
- Island.GoneGreenlands,
- Island.BountyBreeze,
- Island.DesertShore,
- Island.JungleSlush,
- Island.RoughRocks,
- Island.LagoonAtoll,
- Island.SwampySlopes,
- Island.VolcanoVitus,
- Island.ShiveringSnows,
- Island.FreakyFloors
- };
-
- private static readonly List<List<Island>> _islandsPerType = new List<List<Island>>
- {
- new List<Island>(),
- new List<Island>
- {
- Island.BountyBreeze,
- Island.GoneGreenlands,
- Island.JungleSlush,
- Island.LagoonAtoll,
- Island.RoughRocks,
- Island.SwampySlopes,
- Island.VolcanoVitus,
- Island.ShiveringSnows,
- Island.FreakyFloors
- },
- new List<Island>
- {
- Island.BountyBreeze,
- Island.GoneGreenlands
- },
- new List<Island>
- {
- Island.BountyBreeze,
- Island.GoneGreenlands,
- Island.JungleSlush,
- Island.LagoonAtoll,
- Island.SwampySlopes,
- Island.VolcanoVitus,
- Island.FreakyFloors
- },
- new List<Island>
- {
- Island.DesertShore,
- Island.FreakyFloors
- },
- new List<Island>
- {
- Island.JungleSlush
- },
- new List<Island>
- {
- Island.RoughRocks
- },
- new List<Island>
- {
- Island.SwampySlopes,
- Island.FreakyFloors
- },
- new List<Island>
- {
- Island.VolcanoVitus
- },
- new List<Island>
- {
- Island.ShiveringSnows,
- Island.FreakyFloors
- }
- };
-
- private static IList<Island> _islands = null;
-
- private static string[] _sceneNames = new string[10];
-
- private static ILocalizedString[] _displayNames = new ILocalizedString[10];
- }
- }
|