Specify valid filetypes in tilesets

This commit is contained in:
Paul Chote
2010-06-30 20:08:31 +12:00
parent 9ca9d9a47e
commit 202d1a38d5
9 changed files with 14 additions and 25 deletions

View File

@@ -103,6 +103,7 @@ namespace OpenRA.Editor
{ {
Rules.LoadRules(manifest, map); Rules.LoadRules(manifest, map);
tileset = Rules.TileSets[map.Theater]; tileset = Rules.TileSets[map.Theater];
tileset.LoadTiles();
var palette = new Palette(FileSystem.Open(map.Theater.ToLowerInvariant() + ".pal"), true); var palette = new Palette(FileSystem.Open(map.Theater.ToLowerInvariant() + ".pal"), true);
surface1.Bind(map, tileset, palette); surface1.Bind(map, tileset, palette);
@@ -178,7 +179,7 @@ namespace OpenRA.Editor
{ {
try try
{ {
var template = RenderResourceType(a, tileset.TileSuffix, palette); var template = RenderResourceType(a, tileset.Extensions, palette);
var ibox = new PictureBox var ibox = new PictureBox
{ {
Image = template.Bitmap, Image = template.Bitmap,
@@ -251,7 +252,7 @@ namespace OpenRA.Editor
image = ri.OverrideImage[i]; image = ri.OverrideImage[i];
image = image ?? ri.Image ?? info.Name; image = image ?? ri.Image ?? info.Name;
using (var s = FileSystem.OpenWithExts(image, "." + tileset.TileSuffix, ".shp")) using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
{ {
var shp = new ShpReader(s); var shp = new ShpReader(s);
var frame = shp[0]; var frame = shp[0];
@@ -275,10 +276,10 @@ namespace OpenRA.Editor
} }
} }
static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string ext, Palette p) static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[] exts, Palette p)
{ {
var image = info.SpriteNames[0]; var image = info.SpriteNames[0];
using (var s = FileSystem.OpenWithExts(image, "." + ext, ".shp")) using (var s = FileSystem.OpenWithExts(image, exts))
{ {
var shp = new ShpReader(s); var shp = new ShpReader(s);
var frame = shp[shp.ImageCount - 1]; var frame = shp[shp.ImageCount - 1];

View File

@@ -61,7 +61,7 @@ namespace OpenRA.FileFormats
{ {
public readonly string Name; public readonly string Name;
public readonly string Id; public readonly string Id;
public readonly string TileSuffix; public readonly string[] Extensions;
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>();
@@ -83,32 +83,20 @@ namespace OpenRA.FileFormats
// Templates // Templates
foreach (var tt in yaml["Templates"].Nodes) foreach (var tt in yaml["Templates"].Nodes)
{ {
// Info
var t = new TileTemplate(tt.Value.Nodes); var t = new TileTemplate(tt.Value.Nodes);
Templates.Add(t.Id, t); Templates.Add(t.Id, t);
// Artwork
using( Stream s = FileSystem.Open( t.Image + "." + TileSuffix ) )
{
if( !Tiles.ContainsKey( t.Id ) )
Tiles.Add( t.Id, new Terrain( s ) );
}
} }
} }
public void LoadTiles() public void LoadTiles()
{ {
// Templates
foreach (var t in Templates) foreach (var t in Templates)
{ using( Stream s = FileSystem.OpenWithExts(t.Value.Image, Extensions) )
// Artwork
using( Stream s = FileSystem.Open( t.Value.Image + "." + TileSuffix ) )
{ {
if( !Tiles.ContainsKey( t.Key ) ) if( !Tiles.ContainsKey( t.Key ) )
Tiles.Add( t.Key, new Terrain( s ) ); Tiles.Add( t.Key, new Terrain( s ) );
} }
} }
}
public byte[] GetBytes(TileReference<ushort,byte> r) public byte[] GetBytes(TileReference<ushort,byte> r)
{ {

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Graphics
public static void Initialize( TileSet tileset ) public static void Initialize( TileSet tileset )
{ {
/* .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[] { "." + tileset.TileSuffix, ".shp", ".tem" }; exts = tileset.Extensions;
sprites = new Cache<string, Sprite[]>( LoadSprites ); sprites = new Cache<string, Sprite[]>( LoadSprites );
} }

View File

@@ -1,7 +1,7 @@
General: General:
Name: Desert Name: Desert
Id: DESERT Id: DESERT
TileSuffix: des Extensions: .des, .shp, .tem
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:

View File

@@ -1,7 +1,7 @@
General: General:
Name: Temperate Name: Temperate
Id: TEMPERAT Id: TEMPERAT
TileSuffix: tem Extensions: .tem, .shp
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:

View File

@@ -1,7 +1,7 @@
General: General:
Name: Winter Name: Winter
Id: WINTER Id: WINTER
TileSuffix: win Extensions: .win, .shp, .tem
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:

View File

@@ -1,7 +1,7 @@
General: General:
Name: Interior Name: Interior
Id: INTERIOR Id: INTERIOR
TileSuffix: int Extensions: .int, .shp, .tem
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:

View File

@@ -1,7 +1,7 @@
General: General:
Name: Snow Name: Snow
Id: SNOW Id: SNOW
TileSuffix: sno Extensions: .sno, .shp, .tem
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear:

View File

@@ -1,7 +1,7 @@
General: General:
Name: Temperate Name: Temperate
Id: TEMPERAT Id: TEMPERAT
TileSuffix: tem Extensions: .tem, .shp
Terrain: Terrain:
TerrainType@Clear: TerrainType@Clear: