Split and refactor aim animation from WithAttackAnimation
Splitting it from the attack animation, triggering start and end of the aiming animation via interface, as well as removing ReloadPrefix (in favor of switching sprite bodies via condition when reloading) allows us to drop updating via ITick, which in turn will make it much easier to ultimately make this trait compatible with other animation traits, once the priority system lands.
This commit is contained in:
@@ -20,13 +20,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
public readonly string Armament = "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;
|
||||
@@ -51,37 +45,28 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
public class WithAttackAnimation : ConditionalTrait<WithAttackAnimationInfo>, ITick, INotifyAttack
|
||||
{
|
||||
readonly AttackBase attack;
|
||||
readonly Armament armament;
|
||||
readonly WithSpriteBody wsb;
|
||||
readonly bool noAimOrReloadAnim;
|
||||
|
||||
int tick;
|
||||
bool attackAnimPlaying;
|
||||
|
||||
public WithAttackAnimation(ActorInitializer init, WithAttackAnimationInfo info)
|
||||
: base(info)
|
||||
{
|
||||
attack = init.Self.Trait<AttackBase>();
|
||||
armament = init.Self.TraitsImplementing<Armament>()
|
||||
.Single(a => a.Info.Name == Info.Armament);
|
||||
wsb = init.Self.TraitsImplementing<WithSpriteBody>().First(w => w.Info.Name == Info.Body);
|
||||
|
||||
noAimOrReloadAnim = string.IsNullOrEmpty(Info.AimSequence) && string.IsNullOrEmpty(Info.ReloadPrefix);
|
||||
}
|
||||
|
||||
void PlayAttackAnimation(Actor self)
|
||||
{
|
||||
if (!IsTraitDisabled && !wsb.IsTraitDisabled && !string.IsNullOrEmpty(Info.AttackSequence))
|
||||
{
|
||||
attackAnimPlaying = true;
|
||||
wsb.PlayCustomAnimation(self, Info.AttackSequence, () => attackAnimPlaying = false);
|
||||
}
|
||||
if (!IsTraitDisabled && !wsb.IsTraitDisabled && !string.IsNullOrEmpty(Info.Sequence))
|
||||
wsb.PlayCustomAnimation(self, Info.Sequence);
|
||||
}
|
||||
|
||||
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||
{
|
||||
if (Info.DelayRelativeTo == AttackDelayType.Attack)
|
||||
if (a == armament && Info.DelayRelativeTo == AttackDelayType.Attack)
|
||||
{
|
||||
if (Info.Delay > 0)
|
||||
tick = Info.Delay;
|
||||
@@ -92,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
|
||||
void INotifyAttack.PreparingAttack(Actor self, Target target, Armament a, Barrel barrel)
|
||||
{
|
||||
if (Info.DelayRelativeTo == AttackDelayType.Preparation)
|
||||
if (a == armament && Info.DelayRelativeTo == AttackDelayType.Preparation)
|
||||
{
|
||||
if (Info.Delay > 0)
|
||||
tick = Info.Delay;
|
||||
@@ -105,20 +90,6 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
if (Info.Delay > 0 && --tick == 0)
|
||||
PlayAttackAnimation(self);
|
||||
|
||||
if (IsTraitDisabled || noAimOrReloadAnim || attackAnimPlaying || wsb.IsTraitDisabled)
|
||||
return;
|
||||
|
||||
var sequence = wsb.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;
|
||||
|
||||
wsb.DefaultAnimation.ReplaceAnim(sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user