Cleaner TileSet init

This commit is contained in:
Paul Chote
2010-06-26 13:33:46 +12:00
parent 08ee425415
commit d275c72cb8
13 changed files with 65 additions and 71 deletions

View File

@@ -61,14 +61,20 @@ namespace OpenRA.FileFormats
public class TileSet
{
public readonly string Name;
public readonly string Id;
public readonly string TileSuffix;
public readonly Dictionary<string, TerrainTypeInfo> Terrain = new Dictionary<string, TerrainTypeInfo>();
public readonly Dictionary<ushort, Terrain> Tiles = new Dictionary<ushort, Terrain>();
public readonly Dictionary<ushort, TileTemplate> Templates = new Dictionary<ushort, TileTemplate>();
public TileSet( string tilesetFile, string suffix )
public TileSet( string filepath )
{
var yaml = MiniYaml.FromFile(tilesetFile);
var yaml = MiniYaml.FromFile(filepath);
// General info
FieldLoader.Load(this, yaml["General"]);
// TerrainTypes
foreach (var tt in yaml["Terrain"].Nodes)
{
@@ -84,13 +90,27 @@ namespace OpenRA.FileFormats
Templates.Add(t.Id, t);
// Artwork
using( Stream s = FileSystem.Open( t.Image + "." + suffix ) )
using( Stream s = FileSystem.Open( t.Image + "." + TileSuffix ) )
{
if( !Tiles.ContainsKey( t.Id ) )
Tiles.Add( t.Id, new Terrain( s ) );
}
}
}
public void LoadTiles()
{
// Templates
foreach (var t in Templates)
{
// Artwork
using( Stream s = FileSystem.Open( t.Value.Image + "." + TileSuffix ) )
{
if( !Tiles.ContainsKey( t.Key ) )
Tiles.Add( t.Key, new Terrain( s ) );
}
}
}
public byte[] GetBytes(TileReference<ushort,byte> r)
{