Port cursors to yaml.
This commit is contained in:
@@ -20,37 +20,28 @@ namespace OpenRA.Graphics
|
||||
public static class CursorProvider
|
||||
{
|
||||
static Dictionary<string, CursorSequence> cursors;
|
||||
|
||||
public static void Initialize(string[] sequenceFiles)
|
||||
{
|
||||
// TODO: Convert cursor definitions to yaml and parse cursor palette info
|
||||
Game.modData.Palette.AddPalette("cursor", new Palette( FileSystem.Open( "cursor.pal" ), false ));
|
||||
|
||||
cursors = new Dictionary<string, CursorSequence>();
|
||||
|
||||
foreach (var f in sequenceFiles)
|
||||
LoadSequenceSource(f);
|
||||
|
||||
}
|
||||
|
||||
static void LoadSequenceSource(string filename)
|
||||
{
|
||||
XmlDocument document = new XmlDocument();
|
||||
document.Load(FileSystem.Open(filename));
|
||||
|
||||
foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor"))
|
||||
LoadSequencesForCursor(eCursor);
|
||||
public static void Initialize(string[] sequenceFiles)
|
||||
{
|
||||
cursors = new Dictionary<string, CursorSequence>();
|
||||
var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.Merge));
|
||||
|
||||
foreach (var s in sequences.NodesDict["Palettes"].Nodes)
|
||||
Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), false));
|
||||
|
||||
foreach (var s in sequences.NodesDict["Cursors"].Nodes)
|
||||
LoadSequencesForCursor(s.Key, s.Value);
|
||||
}
|
||||
|
||||
static void LoadSequencesForCursor(XmlElement eCursor)
|
||||
static void LoadSequencesForCursor(string cursorSrc, MiniYaml cursor)
|
||||
{
|
||||
Game.modData.LoadScreen.Display();
|
||||
string cursorSrc = eCursor.GetAttribute("src");
|
||||
string palette = eCursor.GetAttribute("palette");
|
||||
|
||||
foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence"))
|
||||
cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, palette, eSequence));
|
||||
|
||||
foreach (var sequence in cursor.Nodes)
|
||||
{
|
||||
Console.WriteLine(sequence.Key);
|
||||
cursors.Add(sequence.Key, new CursorSequence(cursorSrc, cursor.Value, sequence.Value));
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasCursorSequence(string cursor)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Xml;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Graphics
|
||||
{
|
||||
@@ -25,24 +26,27 @@ namespace OpenRA.Graphics
|
||||
|
||||
Sprite[] sprites;
|
||||
|
||||
public CursorSequence(string cursorSrc, string palette, XmlElement e)
|
||||
public CursorSequence(string cursorSrc, string palette, MiniYaml info)
|
||||
{
|
||||
sprites = Game.modData.CursorSheetBuilder.LoadAllSprites(cursorSrc);
|
||||
var d = info.NodesDict;
|
||||
|
||||
start = int.Parse(e.GetAttribute("start"));
|
||||
start = int.Parse(d["start"].Value);
|
||||
this.palette = palette;
|
||||
|
||||
if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*")
|
||||
if ((d.ContainsKey("length") && d["length"].Value == "*") || (d.ContainsKey("end") && d["end"].Value == "*"))
|
||||
length = sprites.Length - start;
|
||||
else if (e.HasAttribute("length"))
|
||||
length = int.Parse(e.GetAttribute("length"));
|
||||
else if (e.HasAttribute("end"))
|
||||
length = int.Parse(e.GetAttribute("end")) - start;
|
||||
else if (d.ContainsKey("length"))
|
||||
length = int.Parse(d["length"].Value);
|
||||
else if (d.ContainsKey("end"))
|
||||
length = int.Parse(d["end"].Value) - start;
|
||||
else
|
||||
length = 1;
|
||||
|
||||
int.TryParse( e.GetAttribute("x"), out Hotspot.X );
|
||||
int.TryParse( e.GetAttribute("y"), out Hotspot.Y );
|
||||
|
||||
if (d.ContainsKey("x"))
|
||||
int.TryParse(d["x"].Value, out Hotspot.X );
|
||||
if (d.ContainsKey("y"))
|
||||
int.TryParse(d["y"].Value, out Hotspot.Y );
|
||||
}
|
||||
|
||||
public Sprite GetSprite(int frame)
|
||||
|
||||
Reference in New Issue
Block a user