Tidy TileSet formatting (no code changes).

This commit is contained in:
Paul Chote
2013-05-05 18:49:03 +12:00
parent ccbfacec62
commit d70a5aff6a

View File

@@ -39,17 +39,17 @@ namespace OpenRA.FileFormats
public bool PickAny;
public string Category;
[FieldLoader.LoadUsing( "LoadTiles" )]
[FieldLoader.LoadUsing("LoadTiles")]
public Dictionary<byte, string> Tiles = new Dictionary<byte, string>();
public TileTemplate() {}
public TileTemplate(MiniYaml my) { FieldLoader.Load( this, my ); }
public TileTemplate(MiniYaml my) { FieldLoader.Load(this, my); }
static object LoadTiles( MiniYaml y )
static object LoadTiles(MiniYaml y)
{
return y.NodesDict["Tiles"].NodesDict.ToDictionary(
t => byte.Parse(t.Key),
t => t.Value.Value );
t => t.Value.Value);
}
static readonly string[] Fields = { "Id", "Image", "Size", "PickAny" };
@@ -60,12 +60,14 @@ namespace OpenRA.FileFormats
foreach (var field in Fields)
{
FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue;
root.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
if (f.GetValue(this) == null)
continue;
root.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
}
root.Add( new MiniYamlNode( "Tiles", null,
Tiles.Select( x => new MiniYamlNode( x.Key.ToString(), x.Value ) ).ToList() ) );
root.Add(new MiniYamlNode("Tiles", null,
Tiles.Select(x => new MiniYamlNode(x.Key.ToString(), x.Value)).ToList()));
return new MiniYaml(null, root);
}
@@ -90,9 +92,9 @@ namespace OpenRA.FileFormats
public TileSet() {}
public TileSet( string filepath )
public TileSet(string filepath)
{
var yaml = MiniYaml.DictFromFile( filepath );
var yaml = MiniYaml.DictFromFile(filepath);
// General info
FieldLoader.Load(this, yaml["General"]);
@@ -110,7 +112,7 @@ namespace OpenRA.FileFormats
{
foreach (var t in Templates)
if (t.Value.Data == null)
using( var s = FileSystem.OpenWithExts(t.Value.Image, Extensions) )
using (var s = FileSystem.OpenWithExts(t.Value.Image, Extensions))
t.Value.Data = new Terrain(s, TileSize);
}
@@ -122,33 +124,35 @@ namespace OpenRA.FileFormats
foreach (var field in fields)
{
FieldInfo f = this.GetType().GetField(field);
if (f.GetValue(this) == null) continue;
gen.Add( new MiniYamlNode( field, FieldSaver.FormatValue( this, f ) ) );
if (f.GetValue(this) == null)
continue;
gen.Add(new MiniYamlNode(field, FieldSaver.FormatValue(this, f)));
}
root.Add( new MiniYamlNode( "General", null, gen ) );
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() ) );
root.Add(new MiniYamlNode( "Terrain", null,
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() ) );
root.Add(new MiniYamlNode("Templates", null,
Templates.Select(t => new MiniYamlNode(
"Template@{0}".F(t.Value.Id),
t.Value.Save())).ToList()));
root.WriteToFile(filepath);
}
public byte[] GetBytes(TileReference<ushort,byte> r)
{
TileTemplate tile;
if( Templates.TryGetValue( r.type, out tile ) )
return tile.Data.TileBitmapBytes[ r.index ];
if (Templates.TryGetValue(r.type, out tile))
return tile.Data.TileBitmapBytes[r.index];
byte[] missingTile = new byte[ TileSize * TileSize ];
for( int i = 0 ; i < missingTile.Length ; i++ )
missingTile[ i ] = 0x36;
byte[] missingTile = new byte[TileSize*TileSize];
for (var i = 0; i < missingTile.Length; i++)
missingTile[i] = 0x36;
return missingTile;
}
@@ -159,6 +163,7 @@ namespace OpenRA.FileFormats
string ret;
if (!tt.TryGetValue(r.index, out ret))
return "Clear"; // Default walkable
return ret;
}