Introduce ISpriteSequence interface.
This commit is contained in:
@@ -16,7 +16,7 @@ namespace OpenRA.Graphics
|
|||||||
public class Animation
|
public class Animation
|
||||||
{
|
{
|
||||||
readonly int defaultTick = 40; // 25 fps == 40 ms
|
readonly int defaultTick = 40; // 25 fps == 40 ms
|
||||||
public Sequence CurrentSequence { get; private set; }
|
public ISpriteSequence CurrentSequence { get; private set; }
|
||||||
public bool IsDecoration = false;
|
public bool IsDecoration = false;
|
||||||
public Func<bool> Paused;
|
public Func<bool> Paused;
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sequence GetSequence(string sequenceName)
|
public ISpriteSequence GetSequence(string sequenceName)
|
||||||
{
|
{
|
||||||
return sequenceProvider.GetSequence(name, sequenceName);
|
return sequenceProvider.GetSequence(name, sequenceName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,21 +13,39 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
public class Sequence
|
public interface ISpriteSequence
|
||||||
|
{
|
||||||
|
string Name { get; }
|
||||||
|
int Start { get; }
|
||||||
|
int Length { get; }
|
||||||
|
int Stride { get; }
|
||||||
|
int Facings { get; }
|
||||||
|
int Tick { get; }
|
||||||
|
int ZOffset { get; }
|
||||||
|
int ShadowStart { get; }
|
||||||
|
int ShadowZOffset { get; }
|
||||||
|
int[] Frames { get; }
|
||||||
|
|
||||||
|
Sprite GetSprite(int frame);
|
||||||
|
Sprite GetSprite(int frame, int facing);
|
||||||
|
Sprite GetShadow(int frame, int facing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Sequence : ISpriteSequence
|
||||||
{
|
{
|
||||||
readonly Sprite[] sprites;
|
readonly Sprite[] sprites;
|
||||||
readonly bool reverseFacings, transpose;
|
readonly bool reverseFacings, transpose;
|
||||||
|
|
||||||
public readonly string Name;
|
public string Name { get; private set; }
|
||||||
public readonly int Start;
|
public int Start { get; private set; }
|
||||||
public readonly int Length;
|
public int Length { get; private set; }
|
||||||
public readonly int Stride;
|
public int Stride { get; private set; }
|
||||||
public readonly int Facings;
|
public int Facings { get; private set; }
|
||||||
public readonly int Tick;
|
public int Tick { get; private set; }
|
||||||
public readonly int ZOffset;
|
public int ZOffset { get; private set; }
|
||||||
public readonly int ShadowStart;
|
public int ShadowStart { get; private set; }
|
||||||
public readonly int ShadowZOffset;
|
public int ShadowZOffset { get; private set; }
|
||||||
public readonly int[] Frames;
|
public int[] Frames { get; private set; }
|
||||||
|
|
||||||
public Sequence(SpriteCache cache, string unit, string name, MiniYaml info)
|
public Sequence(SpriteCache cache, string unit, string name, MiniYaml info)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
using Sequences = IReadOnlyDictionary<string, Lazy<IReadOnlyDictionary<string, Sequence>>>;
|
using Sequences = IReadOnlyDictionary<string, Lazy<IReadOnlyDictionary<string, ISpriteSequence>>>;
|
||||||
using UnitSequences = Lazy<IReadOnlyDictionary<string, Sequence>>;
|
using UnitSequences = Lazy<IReadOnlyDictionary<string, ISpriteSequence>>;
|
||||||
|
|
||||||
public class SequenceProvider
|
public class SequenceProvider
|
||||||
{
|
{
|
||||||
@@ -29,13 +29,13 @@ namespace OpenRA.Graphics
|
|||||||
this.SpriteCache = cache.SpriteCache;
|
this.SpriteCache = cache.SpriteCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sequence GetSequence(string unitName, string sequenceName)
|
public ISpriteSequence GetSequence(string unitName, string sequenceName)
|
||||||
{
|
{
|
||||||
UnitSequences unitSeq;
|
UnitSequences unitSeq;
|
||||||
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
||||||
|
|
||||||
Sequence seq;
|
ISpriteSequence seq;
|
||||||
if (!unitSeq.Value.TryGetValue(sequenceName, out seq))
|
if (!unitSeq.Value.TryGetValue(sequenceName, out seq))
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName));
|
throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName));
|
||||||
|
|
||||||
@@ -125,9 +125,9 @@ namespace OpenRA.Graphics
|
|||||||
return new ReadOnlyDictionary<string, UnitSequences>(items);
|
return new ReadOnlyDictionary<string, UnitSequences>(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
IReadOnlyDictionary<string, Sequence> CreateUnitSequences(MiniYamlNode node)
|
IReadOnlyDictionary<string, ISpriteSequence> CreateUnitSequences(MiniYamlNode node)
|
||||||
{
|
{
|
||||||
var unitSequences = new Dictionary<string, Sequence>();
|
var unitSequences = new Dictionary<string, ISpriteSequence>();
|
||||||
|
|
||||||
foreach (var kvp in node.Value.ToDictionary())
|
foreach (var kvp in node.Value.ToDictionary())
|
||||||
{
|
{
|
||||||
@@ -144,7 +144,7 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ReadOnlyDictionary<string, Sequence>(unitSequences);
|
return new ReadOnlyDictionary<string, ISpriteSequence>(unitSequences);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.Graphics
|
|||||||
yield return z;
|
yield return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<IFinalizedRenderable> DrawZapWandering(WorldRenderer wr, float2 from, float2 to, Sequence s, string pal)
|
static IEnumerable<IFinalizedRenderable> DrawZapWandering(WorldRenderer wr, float2 from, float2 to, ISpriteSequence s, string pal)
|
||||||
{
|
{
|
||||||
var z = float2.Zero; /* hack */
|
var z = float2.Zero; /* hack */
|
||||||
var dist = to - from;
|
var dist = to - from;
|
||||||
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Graphics
|
|||||||
return renderables;
|
return renderables;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<IFinalizedRenderable> DrawZap(WorldRenderer wr, float2 from, float2 to, Sequence s, out float2 p, string palette)
|
static IEnumerable<IFinalizedRenderable> DrawZap(WorldRenderer wr, float2 from, float2 to, ISpriteSequence s, out float2 p, string palette)
|
||||||
{
|
{
|
||||||
var dist = to - from;
|
var dist = to - from;
|
||||||
var q = new float2(-dist.Y, dist.X);
|
var q = new float2(-dist.Y, dist.X);
|
||||||
|
|||||||
Reference in New Issue
Block a user