From d70a5aff6ade236c208961591fa9bd12bff7f102 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 5 May 2013 18:49:03 +1200 Subject: [PATCH] Tidy TileSet formatting (no code changes). --- OpenRA.FileFormats/Map/TileSet.cs | 59 +++++++++++++++++-------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/OpenRA.FileFormats/Map/TileSet.cs b/OpenRA.FileFormats/Map/TileSet.cs index e6d973b09d..621a47bd26 100644 --- a/OpenRA.FileFormats/Map/TileSet.cs +++ b/OpenRA.FileFormats/Map/TileSet.cs @@ -39,17 +39,17 @@ namespace OpenRA.FileFormats public bool PickAny; public string Category; - [FieldLoader.LoadUsing( "LoadTiles" )] + [FieldLoader.LoadUsing("LoadTiles")] public Dictionary Tiles = new Dictionary(); 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 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; }