more general tidying

This commit is contained in:
Chris Forbes
2011-12-28 08:13:36 +13:00
parent 418b8d40f9
commit e84d90fc3a
3 changed files with 16 additions and 29 deletions

View File

@@ -189,27 +189,27 @@ namespace OpenRA.Editor
static MemoryStream ReadPackedSection(IniSection mapPackSection) static MemoryStream ReadPackedSection(IniSection mapPackSection)
{ {
StringBuilder sb = new StringBuilder(); var sb = new StringBuilder();
for (int i = 1; ; i++) for (int i = 1; ; i++)
{ {
string line = mapPackSection.GetValue(i.ToString(), null); var line = mapPackSection.GetValue(i.ToString(), null);
if (line == null) if (line == null)
break; break;
sb.Append(line.Trim()); sb.Append(line.Trim());
} }
byte[] data = Convert.FromBase64String(sb.ToString()); var data = Convert.FromBase64String(sb.ToString());
List<byte[]> chunks = new List<byte[]>(); var chunks = new List<byte[]>();
BinaryReader reader = new BinaryReader(new MemoryStream(data)); var reader = new BinaryReader(new MemoryStream(data));
try try
{ {
while (true) while (true)
{ {
uint length = reader.ReadUInt32() & 0xdfffffff; var length = reader.ReadUInt32() & 0xdfffffff;
byte[] dest = new byte[8192]; var dest = new byte[8192];
byte[] src = reader.ReadBytes((int)length); var src = reader.ReadBytes((int)length);
/*int actualLength =*/ /*int actualLength =*/
Format80.DecodeInto(src, dest); Format80.DecodeInto(src, dest);
@@ -219,8 +219,8 @@ namespace OpenRA.Editor
} }
catch (EndOfStreamException) { } catch (EndOfStreamException) { }
MemoryStream ms = new MemoryStream(); var ms = new MemoryStream();
foreach (byte[] chunk in chunks) foreach (var chunk in chunks)
ms.Write(chunk, 0, chunk.Length); ms.Write(chunk, 0, chunk.Length);
ms.Position = 0; ms.Position = 0;
@@ -284,7 +284,7 @@ namespace OpenRA.Editor
void ReadRATrees(IniFile file) void ReadRATrees(IniFile file)
{ {
IniSection terrain = file.GetSection("TERRAIN", true); var terrain = file.GetSection("TERRAIN", true);
if (terrain == null) if (terrain == null)
return; return;
@@ -316,14 +316,14 @@ namespace OpenRA.Editor
void ReadCncOverlay(IniFile file) void ReadCncOverlay(IniFile file)
{ {
IniSection overlay = file.GetSection("OVERLAY", true); var overlay = file.GetSection("OVERLAY", true);
if (overlay == null) if (overlay == null)
return; return;
foreach (KeyValuePair<string, string> kv in overlay) foreach (KeyValuePair<string, string> kv in overlay)
{ {
var loc = int.Parse(kv.Key); 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); var res = Pair.New((byte)0, (byte)0);
if (overlayResourceMapping.ContainsKey(kv.Value.ToLower())) if (overlayResourceMapping.ContainsKey(kv.Value.ToLower()))
@@ -343,7 +343,7 @@ namespace OpenRA.Editor
void ReadCncTrees(IniFile file) void ReadCncTrees(IniFile file)
{ {
IniSection terrain = file.GetSection("TERRAIN", true); var terrain = file.GetSection("TERRAIN", true);
if (terrain == null) if (terrain == null)
return; return;
@@ -375,7 +375,6 @@ namespace OpenRA.Editor
if (parts[0] == "") if (parts[0] == "")
parts[0] = "Neutral"; parts[0] = "Neutral";
if (!Players.Contains(parts[0])) if (!Players.Contains(parts[0]))
Players.Add(parts[0]); Players.Add(parts[0]);

View File

@@ -21,8 +21,6 @@ namespace OpenRA.FileFormats
H = h; S = s; L = l; R = r; 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 */ /* returns a color along the Lum ramp */
public Color GetColor( float t ) public Color GetColor( float t )
{ {
@@ -35,7 +33,7 @@ namespace OpenRA.FileFormats
} }
// hk is hue in the range [0,1] instead of [0,360] // 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 // Convert from HSL to RGB
var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s); var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s);

View File

@@ -56,16 +56,9 @@ namespace OpenRA
[FieldLoader.Ignore] public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>(); [FieldLoader.Ignore] public Dictionary<string, PlayerReference> Players = new Dictionary<string, PlayerReference>();
[FieldLoader.Ignore] public Lazy<List<SmudgeReference>> Smudges; [FieldLoader.Ignore] public Lazy<List<SmudgeReference>> Smudges;
// Rules overrides
[FieldLoader.Ignore] public List<MiniYamlNode> Rules = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
// Sequences overrides
[FieldLoader.Ignore] public List<MiniYamlNode> Sequences = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Sequences = new List<MiniYamlNode>();
// Weapon overrides
[FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
// Voices overrides
[FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>(); [FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
// Binary map data // Binary map data
@@ -76,10 +69,7 @@ namespace OpenRA
[FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources; [FieldLoader.Ignore] public Lazy<TileReference<byte, byte>[,]> MapResources;
[FieldLoader.Ignore] public string [,] CustomTerrain; [FieldLoader.Ignore] public string [,] CustomTerrain;
public Map() public Map() {} /* doesn't really produce a valid map, but enough for loading a mod */
{
// Do nothing; not a valid map (editor hack)
}
public static Map FromTileset(string tileset) public static Map FromTileset(string tileset)
{ {