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);
tileset = Rules.TileSets[map.Theater];
tileset.LoadTiles();
var palette = new Palette(FileSystem.Open(map.Theater.ToLowerInvariant() + ".pal"), true);
surface1.Bind(map, tileset, palette);
@@ -178,7 +179,7 @@ namespace OpenRA.Editor
{
try
{
var template = RenderResourceType(a, tileset.TileSuffix, palette);
var template = RenderResourceType(a, tileset.Extensions, palette);
var ibox = new PictureBox
{
Image = template.Bitmap,
@@ -251,7 +252,7 @@ namespace OpenRA.Editor
image = ri.OverrideImage[i];
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 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];
using (var s = FileSystem.OpenWithExts(image, "." + ext, ".shp"))
using (var s = FileSystem.OpenWithExts(image, exts))
{
var shp = new ShpReader(s);
var frame = shp[shp.ImageCount - 1];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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