From 5b970c499b8e478fdb926e29338cc68df2c9eacd Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 6 Dec 2009 20:14:50 +1300 Subject: [PATCH] PlayFacing() ext --- OpenRa.Game/Traits/InfantrySquad.cs | 5 ++--- OpenRa.Game/Traits/RenderBuildingTurreted.cs | 3 +-- OpenRa.Game/Traits/RenderUnit.cs | 6 +----- OpenRa.Game/Traits/RenderUnitTurreted.cs | 6 +++--- OpenRa.Game/Traits/Util.cs | 7 +++++++ 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/OpenRa.Game/Traits/InfantrySquad.cs b/OpenRa.Game/Traits/InfantrySquad.cs index d159ceb1f8..dfbe60ea9f 100644 --- a/OpenRa.Game/Traits/InfantrySquad.cs +++ b/OpenRa.Game/Traits/InfantrySquad.cs @@ -55,7 +55,7 @@ namespace OpenRa.Game.Traits if (currentSequence == seq) return; if (isFacing) - anim.PlayFetchIndex(seq, () => Util.QuantizeFacing(facing, anim.CurrentSequence.Length)); + anim.PlayFacing(seq, () => facing ); else anim.PlayRepeatingPreservingPosition(seq); @@ -66,8 +66,7 @@ namespace OpenRa.Game.Traits { name = type; anim = new Animation(type); - anim.PlayFetchIndex("stand", - () => Util.QuantizeFacing(facing, anim.CurrentSequence.Length)); + anim.PlayFacing("stand", () => facing); location = initialLocation; speed = ((InfantryInfo)Rules.UnitInfo[name]).Speed / 2; } diff --git a/OpenRa.Game/Traits/RenderBuildingTurreted.cs b/OpenRa.Game/Traits/RenderBuildingTurreted.cs index 757e23346a..aa759a16db 100644 --- a/OpenRa.Game/Traits/RenderBuildingTurreted.cs +++ b/OpenRa.Game/Traits/RenderBuildingTurreted.cs @@ -11,8 +11,7 @@ namespace OpenRa.Game.Traits void PlayTurretAnim(Actor self, string a) { - anim.PlayFetchIndex(a, - () => self.traits.Get().turretFacing / 8); + anim.PlayFacing(a, () => self.traits.Get().turretFacing); } public override void Damaged(Actor self, DamageState ds) diff --git a/OpenRa.Game/Traits/RenderUnit.cs b/OpenRa.Game/Traits/RenderUnit.cs index 685074198c..260bda3aec 100644 --- a/OpenRa.Game/Traits/RenderUnit.cs +++ b/OpenRa.Game/Traits/RenderUnit.cs @@ -16,11 +16,7 @@ namespace OpenRa.Game.Traits void PlayFacingAnim(Actor self) { var unit = self.traits.Get(); - - anim.PlayFetchIndex("idle", - () => Util.QuantizeFacing( - unit.Facing, - anim.CurrentSequence.Length )); + anim.PlayFacing("idle", () => unit.Facing); } public void PlayCustomAnimation(Actor self, string newAnim, Action after) diff --git a/OpenRa.Game/Traits/RenderUnitTurreted.cs b/OpenRa.Game/Traits/RenderUnitTurreted.cs index 1c158df44c..ba3f01c5e9 100644 --- a/OpenRa.Game/Traits/RenderUnitTurreted.cs +++ b/OpenRa.Game/Traits/RenderUnitTurreted.cs @@ -20,12 +20,12 @@ namespace OpenRa.Game.Traits var attack = self.traits.WithInterface().First(); muzzleFlash = new Animation(self.Info.Name); muzzleFlash.PlayFetchIndex("muzzle", - () => (Util.QuantizeFacing(self.traits.Get().turretFacing,8)) * 6 + (int)(attack.primaryRecoil * 5.9f)); + () => (Util.QuantizeFacing(self.traits.Get().turretFacing,8)) * 6 + + (int)(attack.primaryRecoil * 5.9f)); /* hack: recoil can be 1.0f, but don't overflow into next anim */ } - turretAnim.PlayFetchIndex("turret", - () => self.traits.Get().turretFacing / 8); + turretAnim.PlayFacing("turret", () => self.traits.Get().turretFacing); } public override IEnumerable> Render(Actor self) diff --git a/OpenRa.Game/Traits/Util.cs b/OpenRa.Game/Traits/Util.cs index 67d7a34899..b1604e0b5c 100755 --- a/OpenRa.Game/Traits/Util.cs +++ b/OpenRa.Game/Traits/Util.cs @@ -42,6 +42,13 @@ namespace OpenRa.Game.Traits return highest * 8; } + public static void PlayFacing(this Animation anim, string sequenceName, Func facing) + { + anim.PlayFetchIndex(sequenceName, + () => Traits.Util.QuantizeFacing(facing(), + anim.CurrentSequence.Length)); + } + public static int GetNearestFacing( int facing, int desiredFacing ) { var turn = desiredFacing - facing;