diff --git a/OpenRa.Game/Graphics/CursorSequence.cs b/OpenRa.Game/Graphics/CursorSequence.cs index 76b2e23e49..e8990785a4 100644 --- a/OpenRa.Game/Graphics/CursorSequence.cs +++ b/OpenRa.Game/Graphics/CursorSequence.cs @@ -16,7 +16,7 @@ namespace OpenRa.Game.Graphics public CursorSequence(string cursorSrc, XmlElement e) { - sprites = CursorSheetBuilder.LoadAllSprites(cursorSrc, ".shp"); + sprites = CursorSheetBuilder.LoadAllSprites(cursorSrc); start = int.Parse(e.GetAttribute("start")); diff --git a/OpenRa.Game/Graphics/CursorSheetBuilder.cs b/OpenRa.Game/Graphics/CursorSheetBuilder.cs index f26c078902..513391d135 100644 --- a/OpenRa.Game/Graphics/CursorSheetBuilder.cs +++ b/OpenRa.Game/Graphics/CursorSheetBuilder.cs @@ -1,31 +1,21 @@ using System.Collections.Generic; using OpenRa.FileFormats; +using System.Linq; +using IjwFramework.Collections; namespace OpenRa.Game.Graphics { static class CursorSheetBuilder { - static Dictionary cursors = - new Dictionary(); + static Cache cursors = new Cache(LoadCursors); + static readonly string[] exts = { ".shp" }; - public static Sprite LoadSprite(string filename, params string[] exts) + static Sprite[] LoadCursors(string filename) { - return LoadAllSprites(filename, exts)[0]; + var shp = new Dune2ShpReader(FileSystem.OpenWithExts(filename, exts)); + return shp.Select(a => SheetBuilder.Add(a.Image, a.Size)).ToArray(); } - public static Sprite[] LoadAllSprites(string filename, params string[] exts) - { - Sprite[] value; - if (!cursors.TryGetValue(filename, out value)) - { - Dune2ShpReader shp = new Dune2ShpReader(FileSystem.OpenWithExts(filename, exts)); - value = new Sprite[shp.ImageCount]; - for (int i = 0; i < shp.ImageCount; i++) - value[i] = SheetBuilder.Add(shp[i].Image, shp[i].Size); - cursors.Add(filename, value); - } - - return value; - } + public static Sprite[] LoadAllSprites(string filename) { return cursors[filename]; } } } diff --git a/OpenRa.Game/Graphics/SpriteSheetBuilder.cs b/OpenRa.Game/Graphics/SpriteSheetBuilder.cs index 14d27b9a71..77e9e11eff 100644 --- a/OpenRa.Game/Graphics/SpriteSheetBuilder.cs +++ b/OpenRa.Game/Graphics/SpriteSheetBuilder.cs @@ -21,9 +21,6 @@ namespace OpenRa.Game.Graphics return shp.Select(a => SheetBuilder.Add(a.Image, shp.Size)).ToArray(); } - public static Sprite[] LoadAllSprites( string filename ) - { - return sprites[filename]; - } + public static Sprite[] LoadAllSprites(string filename) { return sprites[filename]; } } }