From e84d90fc3a473ae71bb9c9abc37a1883c2daac2d Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 28 Dec 2011 08:13:36 +1300 Subject: [PATCH] more general tidying --- OpenRA.Editor/LegacyMapImporter.cs | 29 ++++++++++++++--------------- OpenRA.FileFormats/ColorRamp.cs | 4 +--- OpenRA.Game/Map.cs | 12 +----------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/OpenRA.Editor/LegacyMapImporter.cs b/OpenRA.Editor/LegacyMapImporter.cs index 6c22f78ea7..1095a32b2d 100644 --- a/OpenRA.Editor/LegacyMapImporter.cs +++ b/OpenRA.Editor/LegacyMapImporter.cs @@ -189,27 +189,27 @@ namespace OpenRA.Editor static MemoryStream ReadPackedSection(IniSection mapPackSection) { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); for (int i = 1; ; i++) { - string line = mapPackSection.GetValue(i.ToString(), null); + var line = mapPackSection.GetValue(i.ToString(), null); if (line == null) break; sb.Append(line.Trim()); } - byte[] data = Convert.FromBase64String(sb.ToString()); - List chunks = new List(); - BinaryReader reader = new BinaryReader(new MemoryStream(data)); + var data = Convert.FromBase64String(sb.ToString()); + var chunks = new List(); + var reader = new BinaryReader(new MemoryStream(data)); try { while (true) { - uint length = reader.ReadUInt32() & 0xdfffffff; - byte[] dest = new byte[8192]; - byte[] src = reader.ReadBytes((int)length); + var length = reader.ReadUInt32() & 0xdfffffff; + var dest = new byte[8192]; + var src = reader.ReadBytes((int)length); /*int actualLength =*/ Format80.DecodeInto(src, dest); @@ -219,8 +219,8 @@ namespace OpenRA.Editor } catch (EndOfStreamException) { } - MemoryStream ms = new MemoryStream(); - foreach (byte[] chunk in chunks) + var ms = new MemoryStream(); + foreach (var chunk in chunks) ms.Write(chunk, 0, chunk.Length); ms.Position = 0; @@ -284,7 +284,7 @@ namespace OpenRA.Editor void ReadRATrees(IniFile file) { - IniSection terrain = file.GetSection("TERRAIN", true); + var terrain = file.GetSection("TERRAIN", true); if (terrain == null) return; @@ -316,14 +316,14 @@ namespace OpenRA.Editor void ReadCncOverlay(IniFile file) { - IniSection overlay = file.GetSection("OVERLAY", true); + var overlay = file.GetSection("OVERLAY", true); if (overlay == null) return; foreach (KeyValuePair kv in overlay) { var loc = int.Parse(kv.Key); - int2 cell = new int2(loc % MapSize, loc / MapSize); + var cell = new int2(loc % MapSize, loc / MapSize); var res = Pair.New((byte)0, (byte)0); if (overlayResourceMapping.ContainsKey(kv.Value.ToLower())) @@ -343,7 +343,7 @@ namespace OpenRA.Editor void ReadCncTrees(IniFile file) { - IniSection terrain = file.GetSection("TERRAIN", true); + var terrain = file.GetSection("TERRAIN", true); if (terrain == null) return; @@ -375,7 +375,6 @@ namespace OpenRA.Editor if (parts[0] == "") parts[0] = "Neutral"; - if (!Players.Contains(parts[0])) Players.Add(parts[0]); diff --git a/OpenRA.FileFormats/ColorRamp.cs b/OpenRA.FileFormats/ColorRamp.cs index 1c2cfd5a60..36929d7c6a 100644 --- a/OpenRA.FileFormats/ColorRamp.cs +++ b/OpenRA.FileFormats/ColorRamp.cs @@ -21,8 +21,6 @@ namespace OpenRA.FileFormats H = h; S = s; L = l; R = r; } - public static readonly ColorRamp Empty = new ColorRamp(0,0,0,0); - /* returns a color along the Lum ramp */ public Color GetColor( float t ) { @@ -35,7 +33,7 @@ namespace OpenRA.FileFormats } // hk is hue in the range [0,1] instead of [0,360] - public static Color ColorFromHSL(float hk, float s, float l) + static Color ColorFromHSL(float hk, float s, float l) { // Convert from HSL to RGB var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s); diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 99cf3ac8bb..2eebf00039 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -56,16 +56,9 @@ namespace OpenRA [FieldLoader.Ignore] public Dictionary Players = new Dictionary(); [FieldLoader.Ignore] public Lazy> Smudges; - // Rules overrides [FieldLoader.Ignore] public List Rules = new List(); - - // Sequences overrides [FieldLoader.Ignore] public List Sequences = new List(); - - // Weapon overrides [FieldLoader.Ignore] public List Weapons = new List(); - - // Voices overrides [FieldLoader.Ignore] public List Voices = new List(); // Binary map data @@ -76,10 +69,7 @@ namespace OpenRA [FieldLoader.Ignore] public Lazy[,]> MapResources; [FieldLoader.Ignore] public string [,] CustomTerrain; - public Map() - { - // Do nothing; not a valid map (editor hack) - } + public Map() {} /* doesn't really produce a valid map, but enough for loading a mod */ public static Map FromTileset(string tileset) {