Support .r8 tileset artwork.

This commit is contained in:
Paul Chote
2013-08-15 19:17:00 +12:00
parent b6a033eef5
commit 608ca31f6d
3 changed files with 35 additions and 6 deletions

View File

@@ -23,16 +23,31 @@ namespace OpenRA.FileFormats
Dictionary<ushort, List<byte[]>> templates;
public Size TileSize;
List<byte[]> LoadTemplate(string filename, string[] exts, Cache<string, R8Reader> r8Cache, int[] frames)
{
if (exts.Contains(".r8") && FileSystem.Exists(filename+".r8"))
{
var data = new List<byte[]>();
foreach (var f in frames)
data.Add(f >= 0 ? r8Cache[filename][f].Image : null);
return data;
}
using (var s = FileSystem.OpenWithExts(filename, exts))
return new Terrain(s).TileBitmapBytes;
}
public TileSetRenderer(TileSet tileset, Size tileSize)
{
this.TileSet = tileset;
this.TileSize = tileSize;
templates = new Dictionary<ushort, List<byte[]>>();
var r8Cache = new Cache<string, R8Reader>(s => new R8Reader(FileSystem.OpenWithExts(s, ".r8")));
foreach (var t in TileSet.Templates)
using (var s = FileSystem.OpenWithExts(t.Value.Image, tileset.Extensions))
templates.Add(t.Key, new Terrain(s).TileBitmapBytes);
templates.Add(t.Key, LoadTemplate(t.Value.Image, tileset.Extensions, r8Cache, t.Value.Frames));
}
public Bitmap RenderTemplate(ushort id, Palette p)

View File

@@ -35,6 +35,7 @@ namespace OpenRA.FileFormats
{
public ushort Id;
public string Image;
public int[] Frames;
public int2 Size;
public bool PickAny;
public string Category;
@@ -52,7 +53,7 @@ namespace OpenRA.FileFormats
t => t.Value.Value);
}
static readonly string[] Fields = { "Id", "Image", "Size", "PickAny" };
static readonly string[] Fields = { "Id", "Image", "Frames", "Size", "PickAny" };
public MiniYaml Save()
{

View File

@@ -25,8 +25,20 @@ namespace OpenRA.Graphics
Dictionary<ushort, Sprite[]> templates;
Sprite missingTile;
Sprite[] LoadTemplate(string filename, string[] exts)
Sprite[] LoadTemplate(string filename, string[] exts, Cache<string, R8Reader> r8Cache, int[] frames)
{
if (exts.Contains(".r8") && FileSystem.Exists(filename+".r8"))
{
return frames.Select(f =>
{
if (f < 0)
return null;
var image = r8Cache[filename][f];
return sheetBuilder.Add(image.Image, new Size(image.Size.Width, image.Size.Height));
}).ToArray();
}
using (var s = FileSystem.OpenWithExts(filename, exts))
{
var t = new Terrain(s);
@@ -48,10 +60,11 @@ namespace OpenRA.Graphics
return new Sheet(new Size(tileset.SheetSize, tileset.SheetSize));
};
var r8Cache = new Cache<string, R8Reader>(s => new R8Reader(FileSystem.OpenWithExts(s, ".r8")));
templates = new Dictionary<ushort, Sprite[]>();
sheetBuilder = new SheetBuilder(SheetType.Indexed, allocate);
foreach (var t in tileset.Templates)
templates.Add(t.Value.Id, LoadTemplate(t.Value.Image, tileset.Extensions));
templates.Add(t.Value.Id, LoadTemplate(t.Value.Image, tileset.Extensions, r8Cache, t.Value.Frames));
// 1x1px transparent tile
missingTile = sheetBuilder.Add(new byte[1], new Size(1, 1));