Refactor int -> TerrainType. This had a bigger footprint than i initially intended.
This commit is contained in:
@@ -21,12 +21,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
|
||||
using System;
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
public class TerrainColorSet
|
||||
{
|
||||
public readonly Dictionary<int, Color> colors = new Dictionary<int, Color>();
|
||||
public readonly Dictionary<TerrainType, Color> colors = new Dictionary<TerrainType, Color>();
|
||||
|
||||
string NextLine( StreamReader reader )
|
||||
{
|
||||
@@ -51,17 +51,17 @@ namespace OpenRA.FileFormats
|
||||
string line = NextLine( file );
|
||||
if( line == null )
|
||||
break;
|
||||
|
||||
string[] entries = line.Split(',');
|
||||
int key = int.Parse(entries[0]);
|
||||
Color val = Color.FromArgb(int.Parse(entries[1]),int.Parse(entries[2]),int.Parse(entries[3]));
|
||||
string[] kv = line.Split('=');
|
||||
TerrainType key = (TerrainType)Enum.Parse(typeof(TerrainType),kv[0]);
|
||||
string[] entries = kv[1].Split(',');
|
||||
Color val = Color.FromArgb(int.Parse(entries[0]),int.Parse(entries[1]),int.Parse(entries[2]));
|
||||
colors.Add(key,val);
|
||||
}
|
||||
|
||||
file.Close();
|
||||
}
|
||||
|
||||
public Color ColorForTerrainType(int type)
|
||||
public Color ColorForTerrainType(TerrainType type)
|
||||
{
|
||||
return colors[type];
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace OpenRA.FileFormats
|
||||
return missingTile;
|
||||
}
|
||||
|
||||
public int GetTerrainType(TileReference r)
|
||||
public TerrainType GetTerrainType(TileReference r)
|
||||
{
|
||||
if (r.tile == 0xff || r.tile == 0xffff)
|
||||
r.image = 0;
|
||||
|
||||
@@ -20,9 +20,24 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using System;
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
public enum TerrainType : byte
|
||||
{
|
||||
Clear = 0,
|
||||
Water = 1,
|
||||
Road = 2,
|
||||
Rock = 3,
|
||||
Tree = 4,
|
||||
River = 5,
|
||||
Rough = 6,
|
||||
Wall = 7,
|
||||
Beach = 8,
|
||||
Ore = 9,
|
||||
Special = 10,
|
||||
}
|
||||
|
||||
public class TileTemplate
|
||||
{
|
||||
public int Index; // not valid for `interior` stuff. only used for bridges.
|
||||
@@ -30,9 +45,9 @@ namespace OpenRA.FileFormats
|
||||
public int2 Size;
|
||||
public string Bridge;
|
||||
public float HP;
|
||||
public Dictionary<int, int> TerrainType = new Dictionary<int, int>();
|
||||
public Dictionary<int, TerrainType> TerrainType = new Dictionary<int, TerrainType>();
|
||||
}
|
||||
|
||||
|
||||
public class Walkability
|
||||
{
|
||||
Dictionary<string, TileTemplate> walkability
|
||||
@@ -53,11 +68,12 @@ namespace OpenRA.FileFormats
|
||||
.Where(p => p.Key.StartsWith("tiletype"))
|
||||
.ToDictionary(
|
||||
p => int.Parse(p.Key.Substring(8)),
|
||||
p => int.Parse(p.Value)),
|
||||
p => (TerrainType)Enum.Parse(typeof(TerrainType),p.Value)),
|
||||
Name = section.GetValue("Name", null).ToLowerInvariant(),
|
||||
Bridge = section.GetValue("bridge", null),
|
||||
HP = float.Parse(section.GetValue("hp", "0"))
|
||||
};
|
||||
|
||||
tile.Index = -1;
|
||||
int.TryParse(section.Name.Substring(3), out tile.Index);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user