diff --git a/OpenRa.Game/Graphics/Animation.cs b/OpenRa.Game/Graphics/Animation.cs index 34542f3f78..1b3c47dfb7 100644 --- a/OpenRa.Game/Graphics/Animation.cs +++ b/OpenRa.Game/Graphics/Animation.cs @@ -10,12 +10,20 @@ namespace OpenRa.Graphics bool backwards = false; bool tickAlways; + Func facingFunc; + public string Name { get { return name; } } public Animation( string name ) + : this( name, () => 0 ) + { + } + + public Animation( string name, Func facingFunc ) { this.name = name.ToLowerInvariant(); - tickFunc = () => { }; + this.tickFunc = () => { }; + this.facingFunc = facingFunc; } public Sprite Image @@ -23,8 +31,8 @@ namespace OpenRa.Graphics get { return backwards - ? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1) - : CurrentSequence.GetSprite(frame); + ? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1, facingFunc()) + : CurrentSequence.GetSprite(frame, facingFunc()); } } diff --git a/OpenRa.Game/Graphics/Sequence.cs b/OpenRa.Game/Graphics/Sequence.cs index aabfcc75a1..f59d643371 100644 --- a/OpenRa.Game/Graphics/Sequence.cs +++ b/OpenRa.Game/Graphics/Sequence.cs @@ -5,12 +5,13 @@ namespace OpenRa.Graphics public class Sequence { readonly Sprite[] sprites; - readonly int start, length; + readonly int start, length, facings; public readonly string Name; public int Start { get { return start; } } public int End { get { return start + length; } } public int Length { get { return length; } } + public int Facings { get { return facings; } } public Sequence(string unit, XmlElement e) { @@ -28,11 +29,22 @@ namespace OpenRa.Graphics length = int.Parse(e.GetAttribute("end")) - int.Parse(e.GetAttribute("start")); else length = 1; + + if( e.HasAttribute( "facings" ) ) + facings = int.Parse( e.GetAttribute( "facings" ) ); + else + facings = 1; } - public Sprite GetSprite(int frame) + public Sprite GetSprite( int frame ) { - return sprites[ ( frame % length ) + start ]; + return GetSprite( frame, 0 ); + } + + public Sprite GetSprite(int frame, int facing) + { + var f = Traits.Util.QuantizeFacing( facing, facings ); + return sprites[ (f * length) + ( frame % length ) + start ]; } } } diff --git a/OpenRa.Game/Traits/Activities/Harvest.cs b/OpenRa.Game/Traits/Activities/Harvest.cs index bf972b3d81..ccf59ba6b8 100644 --- a/OpenRa.Game/Traits/Activities/Harvest.cs +++ b/OpenRa.Game/Traits/Activities/Harvest.cs @@ -40,12 +40,10 @@ namespace OpenRa.Traits.Activities !self.World.Map.Harvest(self.Location, out isGem)) return false; - var harvestAnim = "harvest" + Util.QuantizeFacing(unit.Facing, 8); - - if (harvestAnim != renderUnit.anim.CurrentSequence.Name) + if (renderUnit.anim.CurrentSequence.Name != "harvest") { isHarvesting = true; - renderUnit.PlayCustomAnimation(self, harvestAnim, () => isHarvesting = false); + renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false); } harv.AcceptResource(isGem); return true; diff --git a/OpenRa.Game/Traits/Render/RenderUnit.cs b/OpenRa.Game/Traits/Render/RenderUnit.cs index ee9eb2f45a..3c203180f3 100644 --- a/OpenRa.Game/Traits/Render/RenderUnit.cs +++ b/OpenRa.Game/Traits/Render/RenderUnit.cs @@ -15,6 +15,7 @@ namespace OpenRa.Traits public RenderUnit(Actor self) : base(self) { + anim = new Animation( GetImage( self ), () => self.traits.Get().Facing ); PlayFacingAnim(self); anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) ); diff --git a/mods/ra/sequences.xml b/mods/ra/sequences.xml index 9942d501d4..55a4ae00e5 100644 --- a/mods/ra/sequences.xml +++ b/mods/ra/sequences.xml @@ -1,4 +1,4 @@ - + - - - - - - - - - + + @@ -1081,4 +1074,4 @@ - +