From ba13c1d9827e68ec9099a7bb61a9ecba8ae8773a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 25 Aug 2013 14:30:00 +0200 Subject: [PATCH] StyleCop clean Map/*.cs files --- OpenRA.Editor/BrushTool.cs | 6 ++--- OpenRA.Editor/Form1.cs | 10 +++---- OpenRA.Editor/LegacyMapImporter.cs | 8 +++--- OpenRA.Editor/ResourceTool.cs | 4 +-- OpenRA.Editor/Surface.cs | 10 +++---- .../Graphics/TileSetRenderer.cs | 10 +++---- OpenRA.FileFormats/Map/PlayerReference.cs | 12 ++++----- OpenRA.FileFormats/Map/SmudgeReference.cs | 2 +- OpenRA.FileFormats/Map/TileReference.cs | 10 +++---- OpenRA.FileFormats/Map/TileSet.cs | 26 ++++++++----------- OpenRA.Game/Graphics/Minimap.cs | 4 +-- OpenRA.Game/Graphics/Theater.cs | 6 ++--- OpenRA.Game/Map.cs | 12 ++++----- OpenRA.Game/Traits/World/ResourceLayer.cs | 2 +- OpenRA.Mods.RA/BridgeLayer.cs | 10 +++---- OpenRA.Mods.RA/World/SmudgeLayer.cs | 8 +++--- 16 files changed, 68 insertions(+), 72 deletions(-) mode change 100755 => 100644 OpenRA.Editor/Form1.cs mode change 100755 => 100644 OpenRA.Editor/Surface.cs mode change 100755 => 100644 OpenRA.Mods.RA/World/SmudgeLayer.cs diff --git a/OpenRA.Editor/BrushTool.cs b/OpenRA.Editor/BrushTool.cs index c679c9e5b5..bee1330293 100644 --- a/OpenRA.Editor/BrushTool.cs +++ b/OpenRA.Editor/BrushTool.cs @@ -46,8 +46,8 @@ namespace OpenRA.Editor surface.Map.MapTiles.Value[u + pos.X, v + pos.Y] = new TileReference { - type = brushTemplate.N, - index = template.PickAny ? (byte)((u + pos.X) % 4 + ((v + pos.Y) % 4) * 4) : (byte)z, + Type = brushTemplate.N, + Index = template.PickAny ? (byte)((u + pos.X) % 4 + ((v + pos.Y) % 4) * 4) : (byte)z, }; var ch = new int2((pos.X + u) / Surface.ChunkSize, (pos.Y + v) / Surface.ChunkSize); @@ -96,7 +96,7 @@ namespace OpenRA.Editor for (var x = a.X; x <= b.X; x++) { - s.Map.MapTiles.Value[x, p.Y] = new TileReference { type = brushTemplate.N, index = (byte)0 }; + s.Map.MapTiles.Value[x, p.Y] = new TileReference { Type = brushTemplate.N, Index = (byte)0 }; if (s.Map.MapTiles.Value[x, p.Y - 1].Equals(replace)) maybeEnqueue(x, p.Y - 1); if (s.Map.MapTiles.Value[x, p.Y + 1].Equals(replace)) diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs old mode 100755 new mode 100644 index 14645aff0b..c5ac3fc376 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -519,8 +519,8 @@ namespace OpenRA.Editor for (var i = surface1.Map.Bounds.Left; i < surface1.Map.Bounds.Right; i++) { var tr = surface1.Map.MapTiles.Value[i, j]; - if (tr.type == 0xff || tr.type == 0xffff || tr.type == 1 || tr.type == 2) - tr.index = (byte)r.Next(0, surface1.TileSetRenderer.Data(tr.type).Count); + if (tr.Type == 0xff || tr.Type == 0xffff || tr.Type == 1 || tr.Type == 2) + tr.Index = (byte)r.Next(0, surface1.TileSetRenderer.Data(tr.Type).Count); surface1.Map.MapTiles.Value[i, j] = tr; } @@ -674,7 +674,7 @@ namespace OpenRA.Editor for (int i = 0; i < surface1.Map.MapSize.X; i++) for (int j = 0; j < surface1.Map.MapSize.Y; j++) { - if (surface1.Map.MapResources.Value[i, j].type != 0) + if (surface1.Map.MapResources.Value[i, j].Type != 0) totalResource += GetResourceValue(i, j); } @@ -689,7 +689,7 @@ namespace OpenRA.Editor { if (!surface1.Map.IsInMap(new CPos(x + u, y + v))) continue; - if (surface1.Map.MapResources.Value[x + u, y + v].type == resourceType) + if (surface1.Map.MapResources.Value[x + u, y + v].Type == resourceType) ++sum; } @@ -699,7 +699,7 @@ namespace OpenRA.Editor int GetResourceValue(int x, int y) { int imageLength = 0; - int type = surface1.Map.MapResources.Value[x, y].type; + int type = surface1.Map.MapResources.Value[x, y].Type; var template = surface1.ResourceTemplates.Where(a => a.Value.Info.ResourceType == type).FirstOrDefault().Value; if (type == 1) imageLength = 12; diff --git a/OpenRA.Editor/LegacyMapImporter.cs b/OpenRA.Editor/LegacyMapImporter.cs index b64290e9a9..929d7e524a 100644 --- a/OpenRA.Editor/LegacyMapImporter.cs +++ b/OpenRA.Editor/LegacyMapImporter.cs @@ -254,11 +254,11 @@ namespace OpenRA.Editor for (int j = 0; j < mapSize; j++) for (int i = 0; i < mapSize; i++) - map.MapTiles.Value[i, j].type = ReadWord(ms); + map.MapTiles.Value[i, j].Type = ReadWord(ms); for (int j = 0; j < mapSize; j++) for (int i = 0; i < mapSize; i++) - map.MapTiles.Value[i, j].index = ReadByte(ms); + map.MapTiles.Value[i, j].Index = ReadByte(ms); } void UnpackRAOverlayData(MemoryStream ms) @@ -311,8 +311,8 @@ namespace OpenRA.Editor for (int j = 0; j < mapSize; j++) for (int i = 0; i < mapSize; i++) { - map.MapTiles.Value[i, j].type = ReadByte(ms); - map.MapTiles.Value[i, j].index = ReadByte(ms); + map.MapTiles.Value[i, j].Type = ReadByte(ms); + map.MapTiles.Value[i, j].Index = ReadByte(ms); } } diff --git a/OpenRA.Editor/ResourceTool.cs b/OpenRA.Editor/ResourceTool.cs index a2ded666c3..2b601c8245 100644 --- a/OpenRA.Editor/ResourceTool.cs +++ b/OpenRA.Editor/ResourceTool.cs @@ -26,8 +26,8 @@ namespace OpenRA.Editor surface.Map.MapResources.Value[surface.GetBrushLocation().X, surface.GetBrushLocation().Y] = new TileReference { - type = (byte)resourceTemplate.Info.ResourceType, - index = (byte)random.Next(resourceTemplate.Info.SpriteNames.Length) + Type = (byte)resourceTemplate.Info.ResourceType, + Index = (byte)random.Next(resourceTemplate.Info.SpriteNames.Length) }; var ch = new int2(surface.GetBrushLocation().X / Surface.ChunkSize, diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs old mode 100755 new mode 100644 index 4794c78651..710e49d604 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -206,7 +206,7 @@ namespace OpenRA.Editor var key = Map.Actors.Value.FirstOrDefault(a => a.Value.Location() == brushLocation); if (key.Key != null) Map.Actors.Value.Remove(key.Key); - if (Map.MapResources.Value[brushLocation.X, brushLocation.Y].type != 0) + if (Map.MapResources.Value[brushLocation.X, brushLocation.Y].Type != 0) { Map.MapResources.Value[brushLocation.X, brushLocation.Y] = new TileReference(); var ch = new int2(brushLocation.X / ChunkSize, brushLocation.Y / ChunkSize); @@ -272,16 +272,16 @@ namespace OpenRA.Editor for (var j = 0; j < ChunkSize; j++) { var tr = Map.MapTiles.Value[u * ChunkSize + i, v * ChunkSize + j]; - var tile = TileSetRenderer.Data(tr.type); - var index = (tr.index < tile.Count) ? tr.index : (byte)0; + var tile = TileSetRenderer.Data(tr.Type); + var index = (tr.Index < tile.Count) ? tr.Index : (byte)0; var rawImage = tile[index]; for (var x = 0; x < TileSetRenderer.TileSize.Width; x++) for (var y = 0; y < TileSetRenderer.TileSize.Height; y++) p[(j * TileSetRenderer.TileSize.Width + y) * stride + i * TileSetRenderer.TileSize.Width + x] = Palette.GetColor(rawImage[x + TileSetRenderer.TileSize.Width * y]).ToArgb(); - if (Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].type != 0) + if (Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].Type != 0) { - var resourceImage = ResourceTemplates[Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].type].Bitmap; + var resourceImage = ResourceTemplates[Map.MapResources.Value[u * ChunkSize + i, v * ChunkSize + j].Type].Bitmap; var srcdata = resourceImage.LockBits(resourceImage.Bounds(), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); diff --git a/OpenRA.FileFormats/Graphics/TileSetRenderer.cs b/OpenRA.FileFormats/Graphics/TileSetRenderer.cs index b83bb7e1c2..98b25d7df1 100644 --- a/OpenRA.FileFormats/Graphics/TileSetRenderer.cs +++ b/OpenRA.FileFormats/Graphics/TileSetRenderer.cs @@ -23,14 +23,14 @@ namespace OpenRA.FileFormats Dictionary> templates; public Size TileSize; - List LoadTemplate(string filename, string[] exts, Cache r8Cache, int[] frames) + List LoadTemplate(string filename, string[] exts, Cache r8cache, int[] frames) { - if (exts.Contains(".R8") && FileSystem.Exists(filename+".R8")) + if (exts.Contains(".R8") && FileSystem.Exists(filename + ".R8")) { var data = new List(); foreach (var f in frames) - data.Add(f >= 0 ? r8Cache[filename][f].Image : null); + data.Add(f >= 0 ? r8cache[filename][f].Image : null); return data; } @@ -45,9 +45,9 @@ namespace OpenRA.FileFormats this.TileSize = tileSize; templates = new Dictionary>(); - var r8Cache = new Cache(s => new R8Reader(FileSystem.OpenWithExts(s, ".R8"))); + var r8cache = new Cache(s => new R8Reader(FileSystem.OpenWithExts(s, ".R8"))); foreach (var t in TileSet.Templates) - templates.Add(t.Key, LoadTemplate(t.Value.Image, tileset.Extensions, r8Cache, t.Value.Frames)); + templates.Add(t.Key, LoadTemplate(t.Value.Image, tileset.Extensions, r8cache, t.Value.Frames)); } public Bitmap RenderTemplate(ushort id, Palette p) diff --git a/OpenRA.FileFormats/Map/PlayerReference.cs b/OpenRA.FileFormats/Map/PlayerReference.cs index 93a72589ab..91109c1407 100644 --- a/OpenRA.FileFormats/Map/PlayerReference.cs +++ b/OpenRA.FileFormats/Map/PlayerReference.cs @@ -8,8 +8,8 @@ */ #endregion -using System.Drawing; using System; +using System.Drawing; namespace OpenRA.FileFormats { @@ -30,8 +30,8 @@ namespace OpenRA.FileFormats // ColorRamp naming retained for backward compatibility public bool LockColor = false; - public HSLColor ColorRamp = new HSLColor(0,0,238); - public HSLColor Color { get { return ColorRamp; } set { ColorRamp = value; }} + public HSLColor ColorRamp = new HSLColor(0, 0, 238); + public HSLColor Color { get { return ColorRamp; } set { ColorRamp = value; } } public bool LockSpawn = false; public int Spawn = 0; @@ -39,10 +39,10 @@ namespace OpenRA.FileFormats public bool LockTeam = false; public int Team = 0; - public string[] Allies = {}; - public string[] Enemies = {}; + public string[] Allies = { }; + public string[] Enemies = { }; - public PlayerReference() {} + public PlayerReference() { } public PlayerReference(MiniYaml my) { FieldLoader.Load(this, my); } public override string ToString() { return Name; } diff --git a/OpenRA.FileFormats/Map/SmudgeReference.cs b/OpenRA.FileFormats/Map/SmudgeReference.cs index 8c5d4dddb2..d7cea78ebd 100644 --- a/OpenRA.FileFormats/Map/SmudgeReference.cs +++ b/OpenRA.FileFormats/Map/SmudgeReference.cs @@ -16,7 +16,7 @@ namespace OpenRA.FileFormats public readonly int2 Location; public readonly int Depth; - public SmudgeReference( string type, int2 location, int depth ) + public SmudgeReference(string type, int2 location, int depth) { Type = type; Location = location; diff --git a/OpenRA.FileFormats/Map/TileReference.cs b/OpenRA.FileFormats/Map/TileReference.cs index 5a2812904d..f1a6337d38 100644 --- a/OpenRA.FileFormats/Map/TileReference.cs +++ b/OpenRA.FileFormats/Map/TileReference.cs @@ -12,15 +12,15 @@ namespace OpenRA.FileFormats { public struct TileReference { - public T type; - public U index; + public T Type; + public U Index; public TileReference(T t, U i) { - type = t; - index = i; + Type = t; + Index = i; } - public override int GetHashCode() { return type.GetHashCode() ^ index.GetHashCode(); } + public override int GetHashCode() { return Type.GetHashCode() ^ Index.GetHashCode(); } } } diff --git a/OpenRA.FileFormats/Map/TileSet.cs b/OpenRA.FileFormats/Map/TileSet.cs index fcb95ea9b2..2750150dd2 100644 --- a/OpenRA.FileFormats/Map/TileSet.cs +++ b/OpenRA.FileFormats/Map/TileSet.cs @@ -25,7 +25,7 @@ namespace OpenRA.FileFormats public Color Color; public string CustomCursor; - public TerrainTypeInfo() {} + public TerrainTypeInfo() { } public TerrainTypeInfo(MiniYaml my) { FieldLoader.Load(this, my); } public MiniYaml Save() { return FieldSaver.Save(this); } @@ -43,7 +43,7 @@ namespace OpenRA.FileFormats [FieldLoader.LoadUsing("LoadTiles")] public Dictionary Tiles = new Dictionary(); - public TileTemplate() {} + public TileTemplate() { } public TileTemplate(MiniYaml my) { FieldLoader.Load(this, my); } static object LoadTiles(MiniYaml y) @@ -87,9 +87,9 @@ namespace OpenRA.FileFormats public Dictionary Templates = new Dictionary(); public string[] EditorTemplateOrder; - static readonly string[] fields = {"Name", "TileSize", "Id", "SheetSize", "Palette", "Extensions"}; + static readonly string[] Fields = { "Name", "TileSize", "Id", "SheetSize", "Palette", "Extensions" }; - public TileSet() {} + public TileSet() { } public TileSet(string filepath) { @@ -112,9 +112,9 @@ namespace OpenRA.FileFormats var root = new List(); var gen = new List(); - foreach (var field in fields) + foreach (var field in Fields) { - FieldInfo f = this.GetType().GetField(field); + var f = this.GetType().GetField(field); if (f.GetValue(this) == null) continue; @@ -123,23 +123,19 @@ namespace OpenRA.FileFormats root.Add(new MiniYamlNode("General", null, gen)); - root.Add(new MiniYamlNode( "Terrain", null, - Terrain.Select(t => new MiniYamlNode( - "TerrainType@{0}".F(t.Value.Type), - t.Value.Save())).ToList())); + root.Add(new MiniYamlNode("Terrain", null, + Terrain.Select(t => new MiniYamlNode("TerrainType@{0}".F(t.Value.Type), t.Value.Save())).ToList())); root.Add(new MiniYamlNode("Templates", null, - Templates.Select(t => new MiniYamlNode( - "Template@{0}".F(t.Value.Id), - t.Value.Save())).ToList())); + Templates.Select(t => new MiniYamlNode("Template@{0}".F(t.Value.Id), t.Value.Save())).ToList())); root.WriteToFile(filepath); } public string GetTerrainType(TileReference r) { - var tt = Templates[r.type].Tiles; + var tt = Templates[r.Type].Tiles; string ret; - if (!tt.TryGetValue(r.index, out ret)) + if (!tt.TryGetValue(r.Index, out ret)) return "Clear"; // Default walkable return ret; diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index e7731a287d..2de2a4e638 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -79,11 +79,11 @@ namespace OpenRA.Graphics { var mapX = x + map.Bounds.Left; var mapY = y + map.Bounds.Top; - if (map.MapResources.Value[mapX, mapY].type == 0) + if (map.MapResources.Value[mapX, mapY].Type == 0) continue; var res = Rules.Info["world"].Traits.WithInterface() - .Where(t => t.ResourceType == map.MapResources.Value[mapX, mapY].type) + .Where(t => t.ResourceType == map.MapResources.Value[mapX, mapY].Type) .Select(t => t.TerrainType).FirstOrDefault(); if (res == null) continue; diff --git a/OpenRA.Game/Graphics/Theater.cs b/OpenRA.Game/Graphics/Theater.cs index 6efe0095bd..034cefdb38 100644 --- a/OpenRA.Game/Graphics/Theater.cs +++ b/OpenRA.Game/Graphics/Theater.cs @@ -73,9 +73,9 @@ namespace OpenRA.Graphics public Sprite TileSprite(TileReference r) { Sprite[] template; - if (templates.TryGetValue(r.type, out template)) - if (template.Length > r.index && template[r.index] != null) - return template[r.index]; + if (templates.TryGetValue(r.Type, out template)) + if (template.Length > r.Index && template[r.Index] != null) + return template[r.Index]; return missingTile; } diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index cd7e369c89..ca92bbe7bf 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -111,7 +111,7 @@ namespace OpenRA public static Map FromTileset(string tileset) { var tile = OpenRA.Rules.TileSets[tileset].Templates.First(); - var tileRef = new TileReference { type = tile.Key, index = (byte)0 }; + var tileRef = new TileReference { Type = tile.Key, Index = (byte)0 }; Map map = new Map() { @@ -349,17 +349,17 @@ namespace OpenRA for (var i = 0; i < MapSize.X; i++) for (var j = 0; j < MapSize.Y; j++) { - writer.Write(MapTiles.Value[i, j].type); - var pickAny = OpenRA.Rules.TileSets[Tileset].Templates[MapTiles.Value[i, j].type].PickAny; - writer.Write(pickAny ? (byte)(i % 4 + (j % 4) * 4) : MapTiles.Value[i, j].index); + writer.Write(MapTiles.Value[i, j].Type); + var pickAny = OpenRA.Rules.TileSets[Tileset].Templates[MapTiles.Value[i, j].Type].PickAny; + writer.Write(pickAny ? (byte)(i % 4 + (j % 4) * 4) : MapTiles.Value[i, j].Index); } // Resource data for (var i = 0; i < MapSize.X; i++) for (var j = 0; j < MapSize.Y; j++) { - writer.Write(MapResources.Value[i, j].type); - writer.Write(MapResources.Value[i, j].index); + writer.Write(MapResources.Value[i, j].Type); + writer.Write(MapResources.Value[i, j].Index); } } diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index bf7dc4536a..8994a17a62 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -74,7 +74,7 @@ namespace OpenRA.Traits for (var y = map.Bounds.Top; y < map.Bounds.Bottom; y++) { var type = resourceTypes.FirstOrDefault( - r => r.info.ResourceType == w.Map.MapResources.Value[x, y].type); + r => r.info.ResourceType == w.Map.MapResources.Value[x, y].Type); if (type == null) continue; diff --git a/OpenRA.Mods.RA/BridgeLayer.cs b/OpenRA.Mods.RA/BridgeLayer.cs index c3a187b921..5ef0ca2bdc 100644 --- a/OpenRA.Mods.RA/BridgeLayer.cs +++ b/OpenRA.Mods.RA/BridgeLayer.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA // Loop through the map looking for templates to overlay for (int i = w.Map.Bounds.Left; i < w.Map.Bounds.Right; i++) for (int j = w.Map.Bounds.Top; j < w.Map.Bounds.Bottom; j++) - if (BridgeTypes.Keys.Contains(w.Map.MapTiles.Value[i, j].type)) + if (BridgeTypes.Keys.Contains(w.Map.MapTiles.Value[i, j].Type)) ConvertBridgeToActor(w, i, j); // Link adjacent (long)-bridges so that artwork is updated correctly @@ -66,8 +66,8 @@ namespace OpenRA.Mods.RA return; // Correlate the tile "image" aka subtile with its position to find the template origin - var tile = w.Map.MapTiles.Value[i, j].type; - var index = w.Map.MapTiles.Value[i, j].index; + var tile = w.Map.MapTiles.Value[i, j].Type; + var index = w.Map.MapTiles.Value[i, j].Index; var template = w.TileSet.Templates[tile]; var ni = i - index % template.Size.X; var nj = j - index / template.Size.X; @@ -90,8 +90,8 @@ namespace OpenRA.Mods.RA var y = nj + ind / template.Size.X; // This isn't the bridge you're looking for - if (!w.Map.IsInMap(x, y) || w.Map.MapTiles.Value[x, y].type != tile || - w.Map.MapTiles.Value[x, y].index != ind) + if (!w.Map.IsInMap(x, y) || w.Map.MapTiles.Value[x, y].Type != tile || + w.Map.MapTiles.Value[x, y].Index != ind) continue; subTiles.Add(new CPos(x, y), ind); diff --git a/OpenRA.Mods.RA/World/SmudgeLayer.cs b/OpenRA.Mods.RA/World/SmudgeLayer.cs old mode 100755 new mode 100644 index a760e9b31e..dda25e7a34 --- a/OpenRA.Mods.RA/World/SmudgeLayer.cs +++ b/OpenRA.Mods.RA/World/SmudgeLayer.cs @@ -69,9 +69,9 @@ namespace OpenRA.Mods.RA { // Existing smudge; make it deeper var tile = dirty.ContainsKey(loc) ? dirty[loc] : tiles[loc]; - var depth = Info.Depths[tile.type - 1]; - if (tile.index < depth - 1) - tile.index++; + var depth = Info.Depths[tile.Type - 1]; + if (tile.Index < depth - 1) + tile.Index++; dirty[loc] = tile; } @@ -106,7 +106,7 @@ namespace OpenRA.Mods.RA if (world.ShroudObscures(kv.Key)) continue; - smudgeSprites[kv.Value.type - 1][kv.Value.index].DrawAt(kv.Key.ToPPos().ToFloat2(), pal); + smudgeSprites[kv.Value.Type - 1][kv.Value.Index].DrawAt(kv.Key.ToPPos().ToFloat2(), pal); } } }