Split *AimAnimation from WithTurretAttackAnimation

These two didn't interact and actually even conflicted when used at the same time, so splitting them is the sensible thing to do.
This commit is contained in:
reaperrr
2017-09-16 20:30:22 +02:00
committed by abcdefg30
parent bd097730cf
commit a1ad76ba74
4 changed files with 126 additions and 29 deletions

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
public class WithTurretAttackAnimationInfo : ITraitInfo, Requires<WithSpriteTurretInfo>, Requires<ArmamentInfo>, Requires<AttackBaseInfo>
public class WithTurretAttackAnimationInfo : ITraitInfo, Requires<WithSpriteTurretInfo>, Requires<ArmamentInfo>
{
[Desc("Armament name")]
public readonly string Armament = "primary";
@@ -23,13 +23,7 @@ namespace OpenRA.Mods.Common.Traits.Render
public readonly string Turret = "primary";
[Desc("Displayed while attacking.")]
[SequenceReference] public readonly string AttackSequence = null;
[Desc("Displayed while targeting.")]
[SequenceReference] public readonly string AimSequence = null;
[Desc("Shown while reloading.")]
[SequenceReference(null, true)] public readonly string ReloadPrefix = null;
[SequenceReference] public readonly string Sequence = null;
[Desc("Delay in ticks before animation starts, either relative to attack preparation or attack.")]
public readonly int Delay = 0;
@@ -43,8 +37,6 @@ namespace OpenRA.Mods.Common.Traits.Render
public class WithTurretAttackAnimation : ITick, INotifyAttack
{
readonly WithTurretAttackAnimationInfo info;
readonly AttackBase attack;
readonly Armament armament;
readonly WithSpriteTurret wst;
int tick;
@@ -52,21 +44,21 @@ namespace OpenRA.Mods.Common.Traits.Render
public WithTurretAttackAnimation(ActorInitializer init, WithTurretAttackAnimationInfo info)
{
this.info = info;
attack = init.Self.Trait<AttackBase>();
armament = init.Self.TraitsImplementing<Armament>()
.Single(a => a.Info.Name == info.Armament);
wst = init.Self.TraitsImplementing<WithSpriteTurret>()
.Single(st => st.Info.Turret == info.Turret);
}
void PlayAttackAnimation(Actor self)
{
if (!string.IsNullOrEmpty(info.AttackSequence))
wst.PlayCustomAnimation(self, info.AttackSequence);
if (!string.IsNullOrEmpty(info.Sequence))
wst.PlayCustomAnimation(self, info.Sequence);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
{
if (a.Info.Name != info.Armament)
return;
if (info.DelayRelativeTo == AttackDelayType.Attack)
{
if (info.Delay > 0)
@@ -78,6 +70,9 @@ namespace OpenRA.Mods.Common.Traits.Render
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
{
if (a.Info.Name != info.Armament)
return;
if (info.DelayRelativeTo == AttackDelayType.Preparation)
{
if (info.Delay > 0)
@@ -91,20 +86,6 @@ namespace OpenRA.Mods.Common.Traits.Render
{
if (info.Delay > 0 && --tick == 0)
PlayAttackAnimation(self);
if (string.IsNullOrEmpty(info.AimSequence) && string.IsNullOrEmpty(info.ReloadPrefix))
return;
var sequence = wst.Info.Sequence;
if (!string.IsNullOrEmpty(info.AimSequence) && attack.IsAiming)
sequence = info.AimSequence;
var prefix = (armament.IsReloading && !string.IsNullOrEmpty(info.ReloadPrefix)) ? info.ReloadPrefix : "";
if (!string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence))
sequence = prefix + sequence;
wst.DefaultAnimation.ReplaceAnim(sequence);
}
}
}