git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1288 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
(no author)
2007-07-17 08:03:02 +00:00
parent 68a533d658
commit 742a91c3f2
6 changed files with 143 additions and 15 deletions

View File

@@ -7,10 +7,12 @@ namespace OpenRa.Game
{
class ConstructionYard : Actor
{
static Range<int> normalSequence = UnitSheetBuilder.GetUnit("fact");
static Range<int> makeSequence = UnitSheetBuilder.GetUnit("factmake");
const string name = "fact";
Range<int> 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) { }
}
}

View File

@@ -41,12 +41,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Actor.cs" />
<Compile Include="Sequence.cs" />
<Compile Include="ConstructionYard.cs" />
<Compile Include="float2.cs" />
<Compile Include="int2.cs" />
<Compile Include="ISelectable.cs" />
<Compile Include="MoveOrder.cs" />
<Compile Include="Region.cs" />
<Compile Include="SequenceProvider.cs" />
<Compile Include="SheetBuilder.cs" />
<Compile Include="HardwarePalette.cs" />
<Compile Include="MainWindow.cs">

View File

@@ -9,7 +9,8 @@ namespace OpenRa.Game
{
class Refinery : Actor
{
static Range<int> 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) }; }
}
}
}

41
OpenRa.Game/Sequence.cs Normal file
View File

@@ -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<int> 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];
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace OpenRa.Game
{
static class SequenceProvider
{
static Dictionary<string, Dictionary<string, Sequence>> units =
new Dictionary<string, Dictionary<string, Sequence>>();
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<string, Sequence> sequences = new Dictionary<string, Sequence>();
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];
}
}
}