TileSet cleanups.

This commit is contained in:
Paul Chote
2014-10-23 20:13:34 +13:00
parent 7d11649fab
commit ab2bc789ce
3 changed files with 16 additions and 22 deletions

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Graphics
{ {
var mapX = x + b.Left; var mapX = x + b.Left;
var mapY = y + b.Top; var mapY = y + b.Top;
var type = tileset.GetTerrainInfo(mapTiles[mapX, mapY]); var type = tileset[tileset.GetTerrainIndex(mapTiles[mapX, mapY])];
colors[y * stride + x] = type.Color.ToArgb(); colors[y * stride + x] = type.Color.ToArgb();
} }
} }

View File

@@ -44,6 +44,8 @@ namespace OpenRA
public class TileTemplate public class TileTemplate
{ {
static readonly string[] Fields = { "Id", "Image", "Frames", "Size", "PickAny", "Category" };
public readonly ushort Id; public readonly ushort Id;
public readonly string Image; public readonly string Image;
public readonly int[] Frames; public readonly int[] Frames;
@@ -113,8 +115,6 @@ namespace OpenRA
return tile; return tile;
} }
static readonly string[] Fields = { "Id", "Image", "Frames", "Size", "PickAny" };
public TerrainTileInfo this[int index] { get { return tileInfo[index]; } } public TerrainTileInfo this[int index] { get { return tileInfo[index]; } }
public bool Contains(int index) public bool Contains(int index)
@@ -148,6 +148,8 @@ namespace OpenRA
public class TileSet public class TileSet
{ {
static readonly string[] Fields = { "Name", "Id", "SheetSize", "Palette", "PlayerPalette", "Extensions", "WaterPaletteRotationBase", "EditorTemplateOrder" };
public readonly string Name; public readonly string Name;
public readonly string Id; public readonly string Id;
public readonly int SheetSize = 512; public readonly int SheetSize = 512;
@@ -162,8 +164,6 @@ namespace OpenRA
readonly Dictionary<string, byte> terrainIndexByType = new Dictionary<string, byte>(); readonly Dictionary<string, byte> terrainIndexByType = new Dictionary<string, byte>();
readonly byte defaultWalkableTerrainIndex; readonly byte defaultWalkableTerrainIndex;
static readonly string[] Fields = { "Name", "Id", "SheetSize", "Palette", "Extensions" };
public TileSet(ModData modData, string filepath) public TileSet(ModData modData, string filepath)
{ {
var yaml = MiniYaml.DictFromFile(filepath); var yaml = MiniYaml.DictFromFile(filepath);
@@ -176,8 +176,10 @@ namespace OpenRA
.Select(y => new TerrainTypeInfo(y)) .Select(y => new TerrainTypeInfo(y))
.OrderBy(tt => tt.Type) .OrderBy(tt => tt.Type)
.ToArray(); .ToArray();
if (TerrainInfo.Length >= byte.MaxValue) if (TerrainInfo.Length >= byte.MaxValue)
throw new InvalidDataException("Too many terrain types."); throw new InvalidDataException("Too many terrain types.");
for (byte i = 0; i < TerrainInfo.Length; i++) for (byte i = 0; i < TerrainInfo.Length; i++)
{ {
var tt = TerrainInfo[i].Type; var tt = TerrainInfo[i].Type;
@@ -197,22 +199,24 @@ namespace OpenRA
public TileSet(string name, string id, string palette, string[] extensions, TerrainTypeInfo[] terrainInfo) public TileSet(string name, string id, string palette, string[] extensions, TerrainTypeInfo[] terrainInfo)
{ {
this.Name = name; Name = name;
this.Id = id; Id = id;
this.Palette = palette; Palette = palette;
this.Extensions = extensions; Extensions = extensions;
this.TerrainInfo = terrainInfo; TerrainInfo = terrainInfo;
if (TerrainInfo.Length >= byte.MaxValue) if (TerrainInfo.Length >= byte.MaxValue)
throw new InvalidDataException("Too many terrain types."); throw new InvalidDataException("Too many terrain types.");
for (byte i = 0; i < terrainInfo.Length; i++) for (byte i = 0; i < terrainInfo.Length; i++)
{ {
var tt = terrainInfo[i].Type; var tt = terrainInfo[i].Type;
if (terrainIndexByType.ContainsKey(tt)) if (terrainIndexByType.ContainsKey(tt))
throw new InvalidDataException("Duplicate terrain type '{0}'.".F(tt)); throw new InvalidDataException("Duplicate terrain type '{0}'.".F(tt));
terrainIndexByType.Add(tt, i); terrainIndexByType.Add(tt, i);
} }
defaultWalkableTerrainIndex = GetTerrainIndex("Clear"); defaultWalkableTerrainIndex = GetTerrainIndex("Clear");
} }
@@ -221,11 +225,6 @@ namespace OpenRA
get { return TerrainInfo[index]; } get { return TerrainInfo[index]; }
} }
public int TerrainsCount
{
get { return TerrainInfo.Length; }
}
public bool TryGetTerrainIndex(string type, out byte index) public bool TryGetTerrainIndex(string type, out byte index)
{ {
return terrainIndexByType.TryGetValue(type, out index); return terrainIndexByType.TryGetValue(type, out index);
@@ -283,10 +282,5 @@ namespace OpenRA
Templates.Select(t => new MiniYamlNode("Template@{0}".F(t.Value.Id), t.Value.Save(this))).ToList())); Templates.Select(t => new MiniYamlNode("Template@{0}".F(t.Value.Id), t.Value.Save(this))).ToList()));
root.WriteToFile(filepath); root.WriteToFile(filepath);
} }
public TerrainTypeInfo GetTerrainInfo(TerrainTile r)
{
return this[GetTerrainIndex(r)];
}
} }
} }

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Move
TerrainInfo[] LoadTilesetSpeeds(TileSet tileSet) TerrainInfo[] LoadTilesetSpeeds(TileSet tileSet)
{ {
var info = new TerrainInfo[tileSet.TerrainsCount]; var info = new TerrainInfo[tileSet.TerrainInfo.Length];
for (var i = 0; i < info.Length; i++) for (var i = 0; i < info.Length; i++)
info[i] = TerrainInfo.Impassable; info[i] = TerrainInfo.Impassable;