From 608ca31f6d0820a12e4a7ec9a77fe4952476ca57 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 15 Aug 2013 19:17:00 +1200 Subject: [PATCH] Support .r8 tileset artwork. --- .../Graphics/TileSetRenderer.cs | 21 ++++++++++++++++--- OpenRA.FileFormats/Map/TileSet.cs | 3 ++- OpenRA.Game/Graphics/Theater.cs | 17 +++++++++++++-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/OpenRA.FileFormats/Graphics/TileSetRenderer.cs b/OpenRA.FileFormats/Graphics/TileSetRenderer.cs index 24d47b2558..2850c991f2 100644 --- a/OpenRA.FileFormats/Graphics/TileSetRenderer.cs +++ b/OpenRA.FileFormats/Graphics/TileSetRenderer.cs @@ -23,16 +23,31 @@ namespace OpenRA.FileFormats Dictionary> templates; public Size TileSize; + List LoadTemplate(string filename, string[] exts, Cache r8Cache, int[] frames) + { + if (exts.Contains(".r8") && FileSystem.Exists(filename+".r8")) + { + var data = new List(); + + 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>(); - + var r8Cache = new Cache(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) diff --git a/OpenRA.FileFormats/Map/TileSet.cs b/OpenRA.FileFormats/Map/TileSet.cs index 29639db9b8..fcb95ea9b2 100644 --- a/OpenRA.FileFormats/Map/TileSet.cs +++ b/OpenRA.FileFormats/Map/TileSet.cs @@ -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() { diff --git a/OpenRA.Game/Graphics/Theater.cs b/OpenRA.Game/Graphics/Theater.cs index e509a02b24..1ff13f4dcf 100644 --- a/OpenRA.Game/Graphics/Theater.cs +++ b/OpenRA.Game/Graphics/Theater.cs @@ -25,8 +25,20 @@ namespace OpenRA.Graphics Dictionary templates; Sprite missingTile; - Sprite[] LoadTemplate(string filename, string[] exts) + Sprite[] LoadTemplate(string filename, string[] exts, Cache 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(s => new R8Reader(FileSystem.OpenWithExts(s, ".r8"))); templates = new Dictionary(); 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));