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