From ab2bc789ced57efaa6f6ed372b8351c4c778a5a4 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 23 Oct 2014 20:13:34 +1300 Subject: [PATCH] TileSet cleanups. --- OpenRA.Game/Graphics/Minimap.cs | 2 +- OpenRA.Game/Map/TileSet.cs | 34 ++++++++++++++------------------- OpenRA.Mods.RA/Move/Mobile.cs | 2 +- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 92ad74f796..62e02c285c 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -44,7 +44,7 @@ namespace OpenRA.Graphics { var mapX = x + b.Left; 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(); } } diff --git a/OpenRA.Game/Map/TileSet.cs b/OpenRA.Game/Map/TileSet.cs index 523186df4b..08bed3d29a 100644 --- a/OpenRA.Game/Map/TileSet.cs +++ b/OpenRA.Game/Map/TileSet.cs @@ -44,6 +44,8 @@ namespace OpenRA public class TileTemplate { + static readonly string[] Fields = { "Id", "Image", "Frames", "Size", "PickAny", "Category" }; + public readonly ushort Id; public readonly string Image; public readonly int[] Frames; @@ -113,8 +115,6 @@ namespace OpenRA return tile; } - static readonly string[] Fields = { "Id", "Image", "Frames", "Size", "PickAny" }; - public TerrainTileInfo this[int index] { get { return tileInfo[index]; } } public bool Contains(int index) @@ -148,6 +148,8 @@ namespace OpenRA public class TileSet { + static readonly string[] Fields = { "Name", "Id", "SheetSize", "Palette", "PlayerPalette", "Extensions", "WaterPaletteRotationBase", "EditorTemplateOrder" }; + public readonly string Name; public readonly string Id; public readonly int SheetSize = 512; @@ -162,8 +164,6 @@ namespace OpenRA readonly Dictionary terrainIndexByType = new Dictionary(); readonly byte defaultWalkableTerrainIndex; - static readonly string[] Fields = { "Name", "Id", "SheetSize", "Palette", "Extensions" }; - public TileSet(ModData modData, string filepath) { var yaml = MiniYaml.DictFromFile(filepath); @@ -176,8 +176,10 @@ namespace OpenRA .Select(y => new TerrainTypeInfo(y)) .OrderBy(tt => tt.Type) .ToArray(); + if (TerrainInfo.Length >= byte.MaxValue) throw new InvalidDataException("Too many terrain types."); + for (byte i = 0; i < TerrainInfo.Length; i++) { var tt = TerrainInfo[i].Type; @@ -197,22 +199,24 @@ namespace OpenRA public TileSet(string name, string id, string palette, string[] extensions, TerrainTypeInfo[] terrainInfo) { - this.Name = name; - this.Id = id; - this.Palette = palette; - this.Extensions = extensions; - this.TerrainInfo = terrainInfo; + Name = name; + Id = id; + Palette = palette; + Extensions = extensions; + TerrainInfo = terrainInfo; + if (TerrainInfo.Length >= byte.MaxValue) throw new InvalidDataException("Too many terrain types."); + for (byte i = 0; i < terrainInfo.Length; i++) { var tt = terrainInfo[i].Type; - if (terrainIndexByType.ContainsKey(tt)) throw new InvalidDataException("Duplicate terrain type '{0}'.".F(tt)); terrainIndexByType.Add(tt, i); } + defaultWalkableTerrainIndex = GetTerrainIndex("Clear"); } @@ -221,11 +225,6 @@ namespace OpenRA get { return TerrainInfo[index]; } } - public int TerrainsCount - { - get { return TerrainInfo.Length; } - } - public bool TryGetTerrainIndex(string type, out byte 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())); root.WriteToFile(filepath); } - - public TerrainTypeInfo GetTerrainInfo(TerrainTile r) - { - return this[GetTerrainIndex(r)]; - } } } diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index c9184e14f1..d07c0e0f22 100644 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Move 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++) info[i] = TerrainInfo.Impassable;