Skip to content

Commit

Permalink
Fix WithTurretAimAnimation disabled handling
Browse files Browse the repository at this point in the history
The old sequence was not recovering when this trait lost its required
condition while the aim anim was running.

Now it doesn't unconditionally return, but instead checks what the
current sequence is and resets to base turret sequence if AimAnim is
disabled.
  • Loading branch information
reaperrr authored and abcdefg30 committed Mar 9, 2018
1 parent 1d8b190 commit fd83cbf
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions OpenRA.Mods.Common/Traits/Render/WithTurretAimAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
{
var turretAttackAnim = ai.TraitInfos<WithTurretAttackAnimationInfo>().Any(t => t.Turret == Turret);
if (turretAttackAnim)
throw new YamlException("WithTurretAimAnimation is currently not compatible with WithTurretAttackAnimation.");
throw new YamlException("WithTurretAimAnimation is currently not compatible with WithTurretAttackAnimation. Don't use them on the same turret.");

base.RulesetLoaded(rules, ai);
}
Expand All @@ -45,6 +45,7 @@ public class WithTurretAimAnimation : ConditionalTrait<WithTurretAimAnimationInf
readonly AttackBase attack;
readonly Armament armament;
readonly WithSpriteTurret wst;
string sequence;

public WithTurretAimAnimation(ActorInitializer init, WithTurretAimAnimationInfo info)
: base(info)
Expand All @@ -54,20 +55,22 @@ public WithTurretAimAnimation(ActorInitializer init, WithTurretAimAnimationInfo
.Single(a => a.Info.Name == info.Armament);
wst = init.Self.TraitsImplementing<WithSpriteTurret>()
.Single(st => st.Info.Turret == info.Turret);

sequence = wst.Info.Sequence;
}

void ITick.Tick(Actor self)
{
if (IsTraitDisabled)
if (IsTraitDisabled && sequence == wst.Info.Sequence)
return;

var sequence = wst.Info.Sequence;
if (!string.IsNullOrEmpty(Info.Sequence) && attack.IsAiming)
sequence = wst.Info.Sequence;
if (!IsTraitDisabled && !string.IsNullOrEmpty(Info.Sequence) && attack.IsAiming)
sequence = Info.Sequence;

var prefix = (armament.IsReloading && !string.IsNullOrEmpty(Info.ReloadPrefix)) ? Info.ReloadPrefix : "";

if (!string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence))
if (!IsTraitDisabled && !string.IsNullOrEmpty(prefix) && sequence != (prefix + sequence))
sequence = prefix + sequence;

wst.DefaultAnimation.ReplaceAnim(sequence);
Expand Down

0 comments on commit fd83cbf

Please sign in to comment.