diff --git a/Plugin/GeodesicGrid/Cell.cs b/Plugin/GeodesicGrid/Cell.cs index 18951d8..df1b486 100644 --- a/Plugin/GeodesicGrid/Cell.cs +++ b/Plugin/GeodesicGrid/Cell.cs @@ -828,57 +828,5 @@ public override bool Equals(object obj) public static bool operator !=(Cell a, Cell b) { return !(a == b); } #endregion - - #region Specialized collections - - public class Set : IEnumerable - { - private readonly BitArray set; - - public Set(int level) - { - this.set = new BitArray((int)Cell.CountAtLevel(level)); - } - - public Set(int level, byte[] array) - { - this.set = new BitArray(array); - this.set.Length = (int)Cell.CountAtLevel(level); - } - - public bool this[Cell cell] - { - get - { - if (cell.Index >= set.Count) { throw new ArgumentException(); } - return set[(int)cell.Index]; - } - set - { - if (cell.Index >= set.Count) { throw new ArgumentException(); } - set[(int)cell.Index] = value; - } - } - - public IEnumerator GetEnumerator() - { - for (var i = 0; i < set.Count; i++) - { - if (set[i]) - { - yield return new Cell((uint)i); - } - } - } - - IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } - - public byte[] ToByteArray() - { - return set.ToByteArray(); - } - } - - #endregion } } \ No newline at end of file diff --git a/Plugin/GeodesicGrid/Set.cs b/Plugin/GeodesicGrid/Set.cs new file mode 100644 index 0000000..605f395 --- /dev/null +++ b/Plugin/GeodesicGrid/Set.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Kethane.GeodesicGrid +{ + public class Set : IEnumerable + { + private readonly BitArray set; + + public Set(int level) + { + this.set = new BitArray((int)Cell.CountAtLevel(level)); + } + + public Set(int level, byte[] array) + { + this.set = new BitArray(array); + this.set.Length = (int)Cell.CountAtLevel(level); + } + + public bool this[Cell cell] + { + get + { + if (cell.Index >= set.Count) { throw new ArgumentException(); } + return set[(int)cell.Index]; + } + set + { + if (cell.Index >= set.Count) { throw new ArgumentException(); } + set[(int)cell.Index] = value; + } + } + + public IEnumerator GetEnumerator() + { + for (var i = 0; i < set.Count; i++) + { + if (set[i]) + { + yield return new Cell((uint)i); + } + } + } + + IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } + + public byte[] ToByteArray() + { + return set.ToByteArray(); + } + } +} diff --git a/Plugin/Kethane.csproj b/Plugin/Kethane.csproj index d8975e1..05d99e9 100644 --- a/Plugin/Kethane.csproj +++ b/Plugin/Kethane.csproj @@ -50,6 +50,7 @@ + diff --git a/Plugin/KethaneData.cs b/Plugin/KethaneData.cs index 17d1e9e..9cf4bf9 100644 --- a/Plugin/KethaneData.cs +++ b/Plugin/KethaneData.cs @@ -29,7 +29,7 @@ public static KethaneData Current } public Dictionary> PlanetDeposits = new Dictionary>(); - public Dictionary> Scans = new Dictionary>(); + public Dictionary> Scans = new Dictionary>(); private Dictionary generatorNodes = new Dictionary(); private Dictionary generators = new Dictionary(); @@ -82,7 +82,7 @@ public override void OnLoad(ConfigNode config) var resourceNode = resourceNodes.SingleOrDefault(n => n.GetValue("Resource") == resourceName) ?? new ConfigNode(); PlanetDeposits[resourceName] = new Dictionary(); - Scans[resourceName] = new Dictionary(); + Scans[resourceName] = new Dictionary(); generatorNodes[resourceName] = resourceNode.GetNode("Generator") ?? resource.Generator; var generator = createGenerator(generatorNodes[resourceName].CreateCopy()); @@ -100,14 +100,14 @@ public override void OnLoad(ConfigNode config) var bodyNode = bodyNodes.SingleOrDefault(n => n.GetValue("Name") == body.name) ?? new ConfigNode(); PlanetDeposits[resourceName][body.name] = generator.Load(body, bodyNode.GetNode("GeneratorData")); - Scans[resourceName][body.name] = new Cell.Set(MapOverlay.GridLevel); + Scans[resourceName][body.name] = new Set(MapOverlay.GridLevel); var scanMask = bodyNode.GetValue("ScanMask"); if (scanMask != null) { try { - Scans[resourceName][body.name] = new Cell.Set(MapOverlay.GridLevel, Misc.FromBase64String(scanMask)); + Scans[resourceName][body.name] = new Set(MapOverlay.GridLevel, Misc.FromBase64String(scanMask)); } catch (FormatException e) { @@ -127,7 +127,7 @@ public override void OnLoad(ConfigNode config) foreach (var body in FlightGlobals.Bodies) { var old = Scans[resource.Resource][body.name]; - var set = new Cell.Set(MapOverlay.GridLevel); + var set = new Set(MapOverlay.GridLevel); foreach (var cell in Cell.AtLevel(MapOverlay.GridLevel)) {