Remove unnecessary properties from Sequence.
This commit is contained in:
@@ -40,7 +40,7 @@ namespace OpenRA.Graphics
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
return backwards
|
return backwards
|
||||||
? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1, facingFunc())
|
? CurrentSequence.GetSprite(CurrentSequence.Start + CurrentSequence.Length - frame - 1, facingFunc())
|
||||||
: CurrentSequence.GetSprite(frame, facingFunc());
|
: CurrentSequence.GetSprite(frame, facingFunc());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Xml;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
@@ -19,16 +18,14 @@ namespace OpenRA.Graphics
|
|||||||
public class Sequence
|
public class Sequence
|
||||||
{
|
{
|
||||||
readonly Sprite[] sprites;
|
readonly Sprite[] sprites;
|
||||||
readonly int start, length, stride, facings, tick;
|
|
||||||
readonly bool reverseFacings, transpose;
|
readonly bool reverseFacings, transpose;
|
||||||
|
|
||||||
public readonly string Name;
|
public readonly string Name;
|
||||||
public int Start { get { return start; } }
|
public readonly int Start;
|
||||||
public int End { get { return start + length; } }
|
public readonly int Length;
|
||||||
public int Length { get { return length; } }
|
public readonly int Stride;
|
||||||
public int Stride { get { return stride; } }
|
public readonly int Facings;
|
||||||
public int Facings { get { return facings; } }
|
public readonly int Tick;
|
||||||
public int Tick { get { return tick; } }
|
|
||||||
public readonly int ZOffset;
|
public readonly int ZOffset;
|
||||||
|
|
||||||
public Sequence(string unit, string name, MiniYaml info)
|
public Sequence(string unit, string name, MiniYaml info)
|
||||||
@@ -38,7 +35,7 @@ namespace OpenRA.Graphics
|
|||||||
var d = info.NodesDict;
|
var d = info.NodesDict;
|
||||||
var offset = float2.Zero;
|
var offset = float2.Zero;
|
||||||
|
|
||||||
start = int.Parse(d["Start"].Value);
|
Start = int.Parse(d["Start"].Value);
|
||||||
|
|
||||||
if (d.ContainsKey("Offset"))
|
if (d.ContainsKey("Offset"))
|
||||||
offset = FieldLoader.GetValue<float2>("Offset", d["Offset"].Value);
|
offset = FieldLoader.GetValue<float2>("Offset", d["Offset"].Value);
|
||||||
@@ -49,30 +46,30 @@ namespace OpenRA.Graphics
|
|||||||
s => new Sprite(s.sheet, s.bounds, s.offset + offset, s.channel)).ToArray();
|
s => new Sprite(s.sheet, s.bounds, s.offset + offset, s.channel)).ToArray();
|
||||||
|
|
||||||
if (!d.ContainsKey("Length"))
|
if (!d.ContainsKey("Length"))
|
||||||
length = 1;
|
Length = 1;
|
||||||
else if (d["Length"].Value == "*")
|
else if (d["Length"].Value == "*")
|
||||||
length = sprites.Length - Start;
|
Length = sprites.Length - Start;
|
||||||
else
|
else
|
||||||
length = int.Parse(d["Length"].Value);
|
Length = int.Parse(d["Length"].Value);
|
||||||
|
|
||||||
if (d.ContainsKey("Stride"))
|
if (d.ContainsKey("Stride"))
|
||||||
stride = int.Parse(d["Stride"].Value);
|
Stride = int.Parse(d["Stride"].Value);
|
||||||
else
|
else
|
||||||
stride = length;
|
Stride = Length;
|
||||||
|
|
||||||
if (d.ContainsKey("Facings"))
|
if (d.ContainsKey("Facings"))
|
||||||
{
|
{
|
||||||
var f = int.Parse(d["Facings"].Value);
|
var f = int.Parse(d["Facings"].Value);
|
||||||
facings = Math.Abs(f);
|
Facings = Math.Abs(f);
|
||||||
reverseFacings = f < 0;
|
reverseFacings = f < 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
facings = 1;
|
Facings = 1;
|
||||||
|
|
||||||
if (d.ContainsKey("Tick"))
|
if (d.ContainsKey("Tick"))
|
||||||
tick = int.Parse(d["Tick"].Value);
|
Tick = int.Parse(d["Tick"].Value);
|
||||||
else
|
else
|
||||||
tick = 40;
|
Tick = 40;
|
||||||
|
|
||||||
if (d.ContainsKey("Transpose"))
|
if (d.ContainsKey("Transpose"))
|
||||||
transpose = bool.Parse(d["Transpose"].Value);
|
transpose = bool.Parse(d["Transpose"].Value);
|
||||||
@@ -80,15 +77,15 @@ namespace OpenRA.Graphics
|
|||||||
if (d.ContainsKey("ZOffset"))
|
if (d.ContainsKey("ZOffset"))
|
||||||
ZOffset = int.Parse(d["ZOffset"].Value);
|
ZOffset = int.Parse(d["ZOffset"].Value);
|
||||||
|
|
||||||
if (length > stride)
|
if (Length > Stride)
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
"{0}: Sequence {1}.{2}: Length must be <= stride"
|
"{0}: Sequence {1}.{2}: Length must be <= stride"
|
||||||
.F(info.Nodes[0].Location, unit, name));
|
.F(info.Nodes[0].Location, unit, name));
|
||||||
|
|
||||||
if (start < 0 || start + facings * stride > sprites.Length)
|
if (Start < 0 || Start + Facings * Stride > sprites.Length)
|
||||||
throw new InvalidOperationException(
|
throw new InvalidOperationException(
|
||||||
"{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist"
|
"{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist"
|
||||||
.F(unit, name, start, start + facings * stride - 1, srcOverride ?? unit, sprites.Length - 1,
|
.F(unit, name, Start, Start + Facings * Stride - 1, srcOverride ?? unit, sprites.Length - 1,
|
||||||
info.Nodes[0].Location));
|
info.Nodes[0].Location));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,15 +96,15 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public Sprite GetSprite(int frame, int facing)
|
public Sprite GetSprite(int frame, int facing)
|
||||||
{
|
{
|
||||||
var f = Traits.Util.QuantizeFacing(facing, facings);
|
var f = Traits.Util.QuantizeFacing(facing, Facings);
|
||||||
|
|
||||||
if (reverseFacings)
|
if (reverseFacings)
|
||||||
f = (facings - f) % facings;
|
f = (Facings - f) % Facings;
|
||||||
|
|
||||||
int i = transpose ? (frame % length) * facings + f :
|
int i = transpose ? (frame % Length) * Facings + f :
|
||||||
(f * stride) + (frame % length);
|
(f * Stride) + (frame % Length);
|
||||||
|
|
||||||
return sprites[start + i];
|
return sprites[Start + i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user