de-static'd CursorSheetBuilder
This commit is contained in:
@@ -27,7 +27,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public CursorSequence(string cursorSrc, string palette, XmlElement e)
|
public CursorSequence(string cursorSrc, string palette, XmlElement e)
|
||||||
{
|
{
|
||||||
sprites = CursorSheetBuilder.LoadAllSprites(cursorSrc);
|
sprites = Game.modData.CursorSheetBuilder.LoadAllSprites(cursorSrc);
|
||||||
|
|
||||||
start = int.Parse(e.GetAttribute("start"));
|
start = int.Parse(e.GetAttribute("start"));
|
||||||
this.palette = palette;
|
this.palette = palette;
|
||||||
|
|||||||
@@ -14,25 +14,32 @@ using OpenRA.FileFormats;
|
|||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
static class CursorSheetBuilder
|
public class CursorSheetBuilder
|
||||||
{
|
{
|
||||||
static Cache<string, Sprite[]> cursors = new Cache<string, Sprite[]>(LoadCursors);
|
ModData modData;
|
||||||
static readonly string[] exts = { ".shp" };
|
Cache<string, Sprite[]> cursors;
|
||||||
|
readonly string[] exts = { ".shp" };
|
||||||
|
|
||||||
static Sprite[] LoadCursors(string filename)
|
public CursorSheetBuilder( ModData modData )
|
||||||
|
{
|
||||||
|
this.modData = modData;
|
||||||
|
this.cursors = new Cache<string, Sprite[]>( LoadCursors );
|
||||||
|
}
|
||||||
|
|
||||||
|
Sprite[] LoadCursors(string filename)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var shp = new Dune2ShpReader(FileSystem.OpenWithExts(filename, exts));
|
var shp = new Dune2ShpReader(FileSystem.OpenWithExts(filename, exts));
|
||||||
return shp.Select(a => SheetBuilder.SharedInstance.Add(a.Image, a.Size)).ToArray();
|
return shp.Select(a => modData.SheetBuilder.Add(a.Image, a.Size)).ToArray();
|
||||||
}
|
}
|
||||||
catch (IndexOutOfRangeException) // This will occur when loading a custom (RA-format) .shp
|
catch (IndexOutOfRangeException) // This will occur when loading a custom (RA-format) .shp
|
||||||
{
|
{
|
||||||
var shp = new ShpReader(FileSystem.OpenWithExts(filename, exts));
|
var shp = new ShpReader(FileSystem.OpenWithExts(filename, exts));
|
||||||
return shp.Select(a => SheetBuilder.SharedInstance.Add(a.Image, shp.Size)).ToArray();
|
return shp.Select(a => modData.SheetBuilder.Add(a.Image, shp.Size)).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Sprite[] LoadAllSprites(string filename) { return cursors[filename]; }
|
public Sprite[] LoadAllSprites(string filename) { return cursors[filename]; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -10,12 +11,15 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public readonly Manifest Manifest;
|
public readonly Manifest Manifest;
|
||||||
public readonly ObjectCreator ObjectCreator;
|
public readonly ObjectCreator ObjectCreator;
|
||||||
|
public readonly CursorSheetBuilder CursorSheetBuilder;
|
||||||
|
public SheetBuilder SheetBuilder { get { return SheetBuilder.SharedInstance; } }
|
||||||
|
|
||||||
public ModData( Manifest manifest )
|
public ModData( Manifest manifest )
|
||||||
{
|
{
|
||||||
Manifest = manifest;
|
Manifest = manifest;
|
||||||
ObjectCreator = new ObjectCreator( manifest );
|
ObjectCreator = new ObjectCreator( manifest );
|
||||||
FileSystem.LoadFromManifest( manifest );
|
FileSystem.LoadFromManifest( manifest );
|
||||||
|
CursorSheetBuilder = new CursorSheetBuilder( this );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user