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 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<string, TerrainTypeInfo> Terrain = new Dictionary<string, TerrainTypeInfo>();
public readonly Dictionary<ushort, Terrain> Tiles = new Dictionary<ushort, Terrain>(); public readonly Dictionary<ushort, Terrain> Tiles = new Dictionary<ushort, Terrain>();
public readonly Dictionary<ushort, TileTemplate> Templates = new Dictionary<ushort, TileTemplate>(); 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 // TerrainTypes
foreach (var tt in yaml["Terrain"].Nodes) foreach (var tt in yaml["Terrain"].Nodes)
{ {
@@ -84,13 +90,27 @@ namespace OpenRA.FileFormats
Templates.Add(t.Id, t); Templates.Add(t.Id, t);
// Artwork // Artwork
using( Stream s = FileSystem.Open( t.Image + "." + suffix ) ) using( Stream s = FileSystem.Open( t.Image + "." + TileSuffix ) )
{ {
if( !Tiles.ContainsKey( t.Id ) ) if( !Tiles.ContainsKey( t.Id ) )
Tiles.Add( t.Id, new Terrain( s ) ); 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) public byte[] GetBytes(TileReference<ushort,byte> r)
{ {

View File

@@ -61,7 +61,7 @@ namespace OpenRA.FileFormats
public readonly string[] public readonly string[]
Folders, Packages, Rules, Folders, Packages, Rules,
Sequences, Chrome, Assemblies, ChromeLayout, Sequences, Chrome, Assemblies, ChromeLayout,
Weapons, Voices, Music, Terrain; Weapons, Voices, Music, TileSets;
public readonly string ShellmapUid; public readonly string ShellmapUid;
@@ -81,8 +81,8 @@ namespace OpenRA.FileFormats
Weapons = YamlList(yaml, "Weapons"); Weapons = YamlList(yaml, "Weapons");
Voices = YamlList(yaml, "Voices"); Voices = YamlList(yaml, "Voices");
Music = YamlList(yaml, "Music"); Music = YamlList(yaml, "Music");
Terrain = YamlList(yaml, "Terrain"); TileSets = YamlList(yaml, "TileSets");
ShellmapUid = yaml["ShellmapUid"].Value; ShellmapUid = yaml["ShellmapUid"].Value;
} }

View File

@@ -144,8 +144,7 @@ namespace OpenRA
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
y += 20; y += 20;
var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == currentMap.Tileset); DrawCentered("Theater: {0}".F(Rules.TileSets[currentMap.Tileset].Name),
DrawCentered("Theater: {0}".F(theaterInfo.Name),
new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White); new int2(mapContainer.Left + mapContainer.Width / 2, y), Color.White);
y += 20; y += 20;
DrawCentered("Spawnpoints: {0}".F(currentMap.PlayerCount), DrawCentered("Spawnpoints: {0}".F(currentMap.PlayerCount),

View File

@@ -34,7 +34,8 @@ namespace OpenRA
public static Dictionary<string, WeaponInfo> Weapons; public static Dictionary<string, WeaponInfo> Weapons;
public static Dictionary<string, VoiceInfo> Voices; public static Dictionary<string, VoiceInfo> Voices;
public static Dictionary<string, MusicInfo> Music; public static Dictionary<string, MusicInfo> Music;
public static Dictionary<string, TileSet> TileSets;
public static void LoadRules(Manifest m, Map map) public static void LoadRules(Manifest m, Map map)
{ {
Log.Write("debug", "Using rules files: "); 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)); 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)); Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value));
Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(k.Value)); Music = LoadYamlRules(m.Music, map.Music, (k, _) => new MusicInfo(k.Value));
TileSets = new Dictionary<string, TileSet>();
foreach (var file in m.TileSets)
{
var t = new TileSet(file);
TileSets.Add(t.Id,t);
}
TechTree = new TechTree(); TechTree = new TechTree();
} }

View File

@@ -26,15 +26,10 @@ namespace OpenRA.Graphics
{ {
static class SpriteSheetBuilder static class SpriteSheetBuilder
{ {
static TheaterInfo GetTheater(Map map) public static void Initialize( TileSet tileset )
{ // todo: move this somewhere else
return Rules.Info["world"].Traits.WithInterface<TheaterInfo>().FirstOrDefault(t => t.Theater == map.Theater);
}
public static void Initialize( Map map )
{ {
/* .tem: hack to allow incomplete theaters (interior) to work, falling back to temperate for the missing art */ /* .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<string, Sprite[]>( LoadSprites ); sprites = new Cache<string, Sprite[]>( LoadSprites );
} }

View File

@@ -218,7 +218,6 @@
<Compile Include="Traits\Player\EvaAlerts.cs" /> <Compile Include="Traits\Player\EvaAlerts.cs" />
<Compile Include="Traits\World\ScreenShaker.cs" /> <Compile Include="Traits\World\ScreenShaker.cs" />
<Compile Include="Traits\LineBuild.cs" /> <Compile Include="Traits\LineBuild.cs" />
<Compile Include="Traits\World\Theater.cs" />
<Compile Include="Widgets\WidgetLoader.cs" /> <Compile Include="Widgets\WidgetLoader.cs" />
<Compile Include="Widgets\ButtonWidget.cs" /> <Compile Include="Widgets\ButtonWidget.cs" />
<Compile Include="Widgets\Widget.cs" /> <Compile Include="Widgets\Widget.cs" />

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#endregion
namespace OpenRA.Traits
{
public class TheaterInfo : TraitInfo<Theater>
{
public readonly string Name = null;
public readonly string Theater = null;
public readonly string Suffix = null;
public readonly string Tileset = null;
}
public class Theater {}
}

View File

@@ -75,14 +75,13 @@ namespace OpenRA
Timer.Time( "----World.ctor" ); Timer.Time( "----World.ctor" );
Map = map; Map = map;
Rules.LoadRules(manifest,Map); Rules.LoadRules(manifest,Map);
Timer.Time( "load rules: {0}" ); Timer.Time( "load rules: {0}" );
var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>() TileSet = Rules.TileSets[Map.Tileset];
.FirstOrDefault(t => t.Theater == Map.Theater); SpriteSheetBuilder.Initialize( TileSet );
TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Suffix); TileSet.LoadTiles();
SpriteSheetBuilder.Initialize( Map );
Timer.Time( "Tileset: {0}" ); Timer.Time( "Tileset: {0}" );
WorldRenderer = new WorldRenderer(this, Game.renderer); WorldRenderer = new WorldRenderer(this, Game.renderer);
@@ -124,7 +123,7 @@ namespace OpenRA
Timer.Time( "----end World.ctor" ); Timer.Time( "----end World.ctor" );
} }
public Actor CreateActor( string name, int2 location, Player owner ) public Actor CreateActor( string name, int2 location, Player owner )
{ {
var a = new Actor( this, name, location, owner ); var a = new Actor( this, name, location, owner );

View File

@@ -49,4 +49,9 @@ Weapons:
Voices: Voices:
mods/cnc/voices.yaml: 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 ShellmapUid:a0e5a8a3cb4e7fb82a08e8d768c32d480f0ec152

View File

@@ -50,21 +50,6 @@ World:
AircraftInfluence: AircraftInfluence:
HazardLayer: HazardLayer:
# BridgeLoadHook: # 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: PaletteFromFile@terrain_desert:
Name: terrain Name: terrain
Theater: desert Theater: desert

View File

@@ -1,3 +1,8 @@
General:
Name: Desert
Id: DESERT
TileSuffix: des
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:
Type: Clear Type: Clear

View File

@@ -1,3 +1,8 @@
General:
Name: Temperate
Id: TEMPERAT
TileSuffix: tem
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:
Type: Clear Type: Clear

View File

@@ -1,3 +1,8 @@
General:
Name: Winter
Id: WINTER
TileSuffix: win
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:
Type: Clear Type: Clear