diff --git a/OpenRA.FileFormats/Map/TileSet.cs b/OpenRA.FileFormats/Map/TileSet.cs index 946e8495e2..3a25ec431e 100644 --- a/OpenRA.FileFormats/Map/TileSet.cs +++ b/OpenRA.FileFormats/Map/TileSet.cs @@ -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 Terrain = new Dictionary(); public readonly Dictionary Tiles = new Dictionary(); public readonly Dictionary Templates = new Dictionary(); - 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 r) { diff --git a/OpenRA.FileFormats/Session.cs b/OpenRA.FileFormats/Session.cs index 5bd59eceeb..3536732637 100644 --- a/OpenRA.FileFormats/Session.cs +++ b/OpenRA.FileFormats/Session.cs @@ -61,7 +61,7 @@ namespace OpenRA.FileFormats public readonly string[] Folders, Packages, Rules, Sequences, Chrome, Assemblies, ChromeLayout, - Weapons, Voices, Music, Terrain; + Weapons, Voices, Music, TileSets; public readonly string ShellmapUid; @@ -81,8 +81,8 @@ namespace OpenRA.FileFormats Weapons = YamlList(yaml, "Weapons"); Voices = YamlList(yaml, "Voices"); Music = YamlList(yaml, "Music"); - Terrain = YamlList(yaml, "Terrain"); - + TileSets = YamlList(yaml, "TileSets"); + ShellmapUid = yaml["ShellmapUid"].Value; } diff --git a/OpenRA.Game/Chrome.cs b/OpenRA.Game/Chrome.cs index 1ad6d8ad92..6ebdc111fd 100644 --- a/OpenRA.Game/Chrome.cs +++ b/OpenRA.Game/Chrome.cs @@ -144,8 +144,7 @@ namespace OpenRA new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); y += 20; - var theaterInfo = Rules.Info["world"].Traits.WithInterface().FirstOrDefault(t => t.Theater == currentMap.Tileset); - DrawCentered("Theater: {0}".F(theaterInfo.Name), + DrawCentered("Theater: {0}".F(Rules.TileSets[currentMap.Tileset].Name), new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); y += 20; DrawCentered("Spawnpoints: {0}".F(currentMap.PlayerCount), diff --git a/OpenRA.Game/GameRules/Rules.cs b/OpenRA.Game/GameRules/Rules.cs index 6ceb192b9e..8a79214a18 100755 --- a/OpenRA.Game/GameRules/Rules.cs +++ b/OpenRA.Game/GameRules/Rules.cs @@ -34,7 +34,8 @@ namespace OpenRA public static Dictionary Weapons; public static Dictionary Voices; public static Dictionary Music; - + public static Dictionary TileSets; + public static void LoadRules(Manifest m, Map map) { Log.Write("debug", "Using rules files: "); @@ -47,6 +48,14 @@ namespace OpenRA Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value)); Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value)); Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(k.Value)); + + TileSets = new Dictionary(); + foreach (var file in m.TileSets) + { + var t = new TileSet(file); + TileSets.Add(t.Id,t); + } + TechTree = new TechTree(); } diff --git a/OpenRA.Game/Graphics/SpriteSheetBuilder.cs b/OpenRA.Game/Graphics/SpriteSheetBuilder.cs index 9cc53b8b24..8746e01348 100644 --- a/OpenRA.Game/Graphics/SpriteSheetBuilder.cs +++ b/OpenRA.Game/Graphics/SpriteSheetBuilder.cs @@ -26,15 +26,10 @@ namespace OpenRA.Graphics { static class SpriteSheetBuilder { - static TheaterInfo GetTheater(Map map) - { // todo: move this somewhere else - return Rules.Info["world"].Traits.WithInterface().FirstOrDefault(t => t.Theater == map.Theater); - } - - public static void Initialize( Map map ) + public static void Initialize( TileSet tileset ) { /* .tem: hack to allow incomplete theaters (interior) to work, falling back to temperate for the missing art */ - exts = new[] { "." + GetTheater(map).Suffix, ".shp", ".tem" }; + exts = new[] { "." + tileset.TileSuffix, ".shp", ".tem" }; sprites = new Cache( LoadSprites ); } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 841980b6f7..5d207956df 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -218,7 +218,6 @@ - diff --git a/OpenRA.Game/Traits/World/Theater.cs b/OpenRA.Game/Traits/World/Theater.cs deleted file mode 100644 index 2fc31dbb36..0000000000 --- a/OpenRA.Game/Traits/World/Theater.cs +++ /dev/null @@ -1,32 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. - * This file is part of OpenRA. - * - * OpenRA is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * OpenRA is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with OpenRA. If not, see . - */ -#endregion - -namespace OpenRA.Traits -{ - public class TheaterInfo : TraitInfo - { - public readonly string Name = null; - public readonly string Theater = null; - public readonly string Suffix = null; - public readonly string Tileset = null; - } - - public class Theater {} -} diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index a0a5c44311..4509af5281 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -75,14 +75,13 @@ namespace OpenRA Timer.Time( "----World.ctor" ); Map = map; + Rules.LoadRules(manifest,Map); Timer.Time( "load rules: {0}" ); - - var theaterInfo = Rules.Info["world"].Traits.WithInterface() - .FirstOrDefault(t => t.Theater == Map.Theater); - TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Suffix); - - SpriteSheetBuilder.Initialize( Map ); + + TileSet = Rules.TileSets[Map.Tileset]; + SpriteSheetBuilder.Initialize( TileSet ); + TileSet.LoadTiles(); Timer.Time( "Tileset: {0}" ); WorldRenderer = new WorldRenderer(this, Game.renderer); @@ -124,7 +123,7 @@ namespace OpenRA Timer.Time( "----end World.ctor" ); } - + public Actor CreateActor( string name, int2 location, Player owner ) { var a = new Actor( this, name, location, owner ); diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index d93d3b2590..3960e2bb52 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -49,4 +49,9 @@ Weapons: Voices: mods/cnc/voices.yaml: +TileSets: + mods/cnc/tileset-des.yaml: Desert + mods/cnc/tileset-win.yaml: Winter + mods/cnc/tileset-tem.yaml: Temperate + ShellmapUid:a0e5a8a3cb4e7fb82a08e8d768c32d480f0ec152 diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 4c379bf8f1..970b4c6207 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -50,21 +50,6 @@ World: AircraftInfluence: HazardLayer: # BridgeLoadHook: - Theater@DESERT: - Name:Desert - Theater:DESERT - Suffix:des - Tileset:mods/cnc/tileset-des.yaml - Theater@WINTER: - Name:Winter - Theater:WINTER - Suffix:win - Tileset:mods/cnc/tileset-win.yaml - Theater@TEMPERAT: - Name:Temperate - Theater:TEMPERAT - Suffix:tem - Tileset:mods/cnc/tileset-tem.yaml PaletteFromFile@terrain_desert: Name: terrain Theater: desert diff --git a/mods/cnc/tileset-des.yaml b/mods/cnc/tileset-des.yaml index 23e30fccb1..cc8c715f63 100644 --- a/mods/cnc/tileset-des.yaml +++ b/mods/cnc/tileset-des.yaml @@ -1,3 +1,8 @@ +General: + Name: Desert + Id: DESERT + TileSuffix: des + Terrain: TerrainType@Clear: Type: Clear diff --git a/mods/cnc/tileset-tem.yaml b/mods/cnc/tileset-tem.yaml index 65dfc849d9..04d75fdf42 100644 --- a/mods/cnc/tileset-tem.yaml +++ b/mods/cnc/tileset-tem.yaml @@ -1,3 +1,8 @@ +General: + Name: Temperate + Id: TEMPERAT + TileSuffix: tem + Terrain: TerrainType@Clear: Type: Clear diff --git a/mods/cnc/tileset-win.yaml b/mods/cnc/tileset-win.yaml index 4df9bb9d05..543ec5cde5 100644 --- a/mods/cnc/tileset-win.yaml +++ b/mods/cnc/tileset-win.yaml @@ -1,3 +1,8 @@ +General: + Name: Winter + Id: WINTER + TileSuffix: win + Terrain: TerrainType@Clear: Type: Clear