StyleCop clean Map/*.cs files
This commit is contained in:
@@ -46,8 +46,8 @@ namespace OpenRA.Editor
|
||||
surface.Map.MapTiles.Value[u + pos.X, v + pos.Y] =
|
||||
new TileReference<ushort, byte>
|
||||
{
|
||||
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<ushort, byte> { type = brushTemplate.N, index = (byte)0 };
|
||||
s.Map.MapTiles.Value[x, p.Y] = new TileReference<ushort, byte> { 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))
|
||||
|
||||
10
OpenRA.Editor/Form1.cs
Executable file → Normal file
10
OpenRA.Editor/Form1.cs
Executable file → Normal file
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace OpenRA.Editor
|
||||
surface.Map.MapResources.Value[surface.GetBrushLocation().X, surface.GetBrushLocation().Y]
|
||||
= new TileReference<byte, byte>
|
||||
{
|
||||
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,
|
||||
|
||||
10
OpenRA.Editor/Surface.cs
Executable file → Normal file
10
OpenRA.Editor/Surface.cs
Executable file → Normal file
@@ -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<byte, byte>();
|
||||
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);
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ namespace OpenRA.FileFormats
|
||||
Dictionary<ushort, List<byte[]>> templates;
|
||||
public Size TileSize;
|
||||
|
||||
List<byte[]> LoadTemplate(string filename, string[] exts, Cache<string, R8Reader> r8Cache, int[] frames)
|
||||
List<byte[]> LoadTemplate(string filename, string[] exts, Cache<string, R8Reader> r8cache, int[] frames)
|
||||
{
|
||||
if (exts.Contains(".R8") && FileSystem.Exists(filename + ".R8"))
|
||||
{
|
||||
var data = new List<byte[]>();
|
||||
|
||||
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<ushort, List<byte[]>>();
|
||||
var r8Cache = new Cache<string, R8Reader>(s => new R8Reader(FileSystem.OpenWithExts(s, ".R8")));
|
||||
var r8cache = new Cache<string, R8Reader>(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)
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
|
||||
@@ -12,15 +12,15 @@ namespace OpenRA.FileFormats
|
||||
{
|
||||
public struct TileReference<T, U>
|
||||
{
|
||||
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(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace OpenRA.FileFormats
|
||||
public Dictionary<ushort, TileTemplate> Templates = new Dictionary<ushort, TileTemplate>();
|
||||
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() { }
|
||||
|
||||
@@ -112,9 +112,9 @@ namespace OpenRA.FileFormats
|
||||
var root = new List<MiniYamlNode>();
|
||||
var gen = new List<MiniYamlNode>();
|
||||
|
||||
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;
|
||||
|
||||
@@ -124,22 +124,18 @@ 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()));
|
||||
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<ushort, byte> 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;
|
||||
|
||||
@@ -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<ResourceTypeInfo>()
|
||||
.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;
|
||||
|
||||
@@ -73,9 +73,9 @@ namespace OpenRA.Graphics
|
||||
public Sprite TileSprite(TileReference<ushort, byte> 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;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace OpenRA
|
||||
public static Map FromTileset(string tileset)
|
||||
{
|
||||
var tile = OpenRA.Rules.TileSets[tileset].Templates.First();
|
||||
var tileRef = new TileReference<ushort, byte> { type = tile.Key, index = (byte)0 };
|
||||
var tileRef = new TileReference<ushort, byte> { 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
8
OpenRA.Mods.RA/World/SmudgeLayer.cs
Executable file → Normal file
8
OpenRA.Mods.RA/World/SmudgeLayer.cs
Executable file → Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user