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

@@ -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<TheaterInfo>().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),

View File

@@ -34,7 +34,8 @@ namespace OpenRA
public static Dictionary<string, WeaponInfo> Weapons;
public static Dictionary<string, VoiceInfo> Voices;
public static Dictionary<string, MusicInfo> Music;
public static Dictionary<string, TileSet> 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<string, TileSet>();
foreach (var file in m.TileSets)
{
var t = new TileSet(file);
TileSets.Add(t.Id,t);
}
TechTree = new TechTree();
}

View File

@@ -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<TheaterInfo>().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<string, Sprite[]>( LoadSprites );
}

View File

@@ -218,7 +218,6 @@
<Compile Include="Traits\Player\EvaAlerts.cs" />
<Compile Include="Traits\World\ScreenShaker.cs" />
<Compile Include="Traits\LineBuild.cs" />
<Compile Include="Traits\World\Theater.cs" />
<Compile Include="Widgets\WidgetLoader.cs" />
<Compile Include="Widgets\ButtonWidget.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" );
Map = map;
Rules.LoadRules(manifest,Map);
Timer.Time( "load rules: {0}" );
var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>()
.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 );