diff --git a/OpenRa.Game/ConstructionYard.cs b/OpenRa.Game/ConstructionYard.cs index 92f81337d2..34b6c6e862 100644 --- a/OpenRa.Game/ConstructionYard.cs +++ b/OpenRa.Game/ConstructionYard.cs @@ -7,10 +7,12 @@ namespace OpenRa.Game { class ConstructionYard : Actor { - static Range normalSequence = UnitSheetBuilder.GetUnit("fact"); - static Range makeSequence = UnitSheetBuilder.GetUnit("factmake"); + const string name = "fact"; - Range sequence = makeSequence; + static Sequence idle = SequenceProvider.GetSequence(name, "idle"); + static Sequence make = SequenceProvider.GetSequence(name, "make"); + + Sequence current = make; int frame = -1; public ConstructionYard(float2 location, int palette) @@ -23,16 +25,14 @@ namespace OpenRa.Game { get { - if ((sequence.Start == makeSequence.Start) && ++frame >= sequence.End - sequence.Start) + if ((current == make) && ++frame >= current.Length) { frame = 0; - sequence = normalSequence; + current = idle; } - return new Sprite[] { UnitSheetBuilder.sprites[sequence.Start + frame] }; + return new Sprite[] { current.GetSprite(frame) }; } } - - public override void Tick(World world, double t) { } } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index f79e7c6839..28941c5508 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -41,12 +41,14 @@ + + diff --git a/OpenRa.Game/Refinery.cs b/OpenRa.Game/Refinery.cs index d8529f6442..faee099aae 100644 --- a/OpenRa.Game/Refinery.cs +++ b/OpenRa.Game/Refinery.cs @@ -9,7 +9,8 @@ namespace OpenRa.Game { class Refinery : Actor { - static Range sequence = UnitSheetBuilder.GetUnit("proc"); + const string name = "proc"; + static Sequence idle = SequenceProvider.GetSequence(name, "idle"); public Refinery(float2 location, int palette) { @@ -17,14 +18,9 @@ namespace OpenRa.Game this.palette = palette; } - int GetFrame() { return 1; } - public override Sprite[] CurrentImages { - get - { - return new Sprite[] { UnitSheetBuilder.sprites[sequence.Start + GetFrame()] }; - } + get { return new Sprite[] { idle.GetSprite(0) }; } } } } diff --git a/OpenRa.Game/Sequence.cs b/OpenRa.Game/Sequence.cs new file mode 100644 index 0000000000..75be84ce9e --- /dev/null +++ b/OpenRa.Game/Sequence.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Text; +using BluntDirectX.Direct3D; +using System.Xml; + +namespace OpenRa.Game +{ + class Sequence + { + readonly int start, length; + + public int Start { get { return start; } } + public int End { get { return start + length; } } + public int Length { get { return length; } } + + public Sequence(string unit, XmlElement e) + { + string srcOverride = e.GetAttribute("src"); + + Range src = UnitSheetBuilder.GetUnit( + string.IsNullOrEmpty(srcOverride) ? unit : srcOverride); + + start = src.Start + int.Parse(e.GetAttribute("start")); + + if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*") + length = src.End - 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 + length = 1; + } + + public Sprite GetSprite(int frame) + { + return UnitSheetBuilder.sprites[frame + start]; + } + } +} diff --git a/OpenRa.Game/SequenceProvider.cs b/OpenRa.Game/SequenceProvider.cs new file mode 100644 index 0000000000..492731f9f0 --- /dev/null +++ b/OpenRa.Game/SequenceProvider.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; + +namespace OpenRa.Game +{ + static class SequenceProvider + { + static Dictionary> units = + new Dictionary>(); + + static SequenceProvider() + { + XmlDocument document = new XmlDocument(); + document.Load("../../../sequences.xml"); + + foreach (XmlElement eUnit in document.SelectNodes("/sequences/unit")) + LoadSequencesForUnit(eUnit); + } + + static void LoadSequencesForUnit(XmlElement eUnit) + { + string unitName = eUnit.GetAttribute("name"); + Dictionary sequences = new Dictionary(); + + foreach (XmlElement eSequence in eUnit.SelectNodes("./sequence")) + sequences.Add(eSequence.GetAttribute("name"), new Sequence(unitName, eSequence)); + + units.Add(unitName, sequences); + } + + public static Sequence GetSequence(string unitName, string sequenceName) + { + return units[unitName][sequenceName]; + } + } +} diff --git a/sequences.xml b/sequences.xml new file mode 100644 index 0000000000..b9cda217a8 --- /dev/null +++ b/sequences.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + +