Define a consistent interface for sprite loading. Fixes #4176.

This commit is contained in:
Paul Chote
2013-11-29 18:57:14 +13:00
parent 20a6c75ba4
commit f92ce8bf51
12 changed files with 323 additions and 183 deletions

View File

@@ -21,14 +21,13 @@ namespace OpenRA.FileFormats
Dictionary<ushort, List<byte[]>> templates;
public Size TileSize;
List<byte[]> LoadTemplate(string filename, string[] exts, Cache<string, R8Reader> r8cache, int[] frames)
List<byte[]> LoadTemplate(string filename, string[] exts, Cache<string, ISpriteFrame[]> 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);
data.Add(f >= 0 ? r8cache[filename][f].Data : null);
return data;
}
@@ -43,7 +42,7 @@ namespace OpenRA.FileFormats
this.TileSize = tileSize;
templates = new Dictionary<ushort, List<byte[]>>();
var r8cache = new Cache<string, R8Reader>(s => new R8Reader(FileSystem.OpenWithExts(s, ".R8")));
var r8cache = new Cache<string, ISpriteFrame[]>(s => new R8Reader(FileSystem.OpenWithExts(s, ".R8")).Frames.ToArray());
foreach (var t in TileSet.Templates)
templates.Add(t.Key, LoadTemplate(t.Value.Image, tileset.Extensions, r8cache, t.Value.Frames));
}