Refactoring
This commit is contained in:
@@ -32,14 +32,8 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
Idle,
|
Idle,
|
||||||
Attacking,
|
Attacking,
|
||||||
Moving,
|
Moving,
|
||||||
Waiting
|
|
||||||
};
|
|
||||||
|
|
||||||
enum IdleState
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Waiting,
|
Waiting,
|
||||||
Active
|
IdleAnimating
|
||||||
};
|
};
|
||||||
|
|
||||||
public bool Panicked = false;
|
public bool Panicked = false;
|
||||||
@@ -49,7 +43,6 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
RenderInfantryInfo Info;
|
RenderInfantryInfo Info;
|
||||||
string idleSequence;
|
string idleSequence;
|
||||||
int idleDelay;
|
int idleDelay;
|
||||||
IdleState idleState;
|
|
||||||
|
|
||||||
protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence)
|
protected virtual string NormalizeInfantrySequence(Actor self, string baseSequence)
|
||||||
{
|
{
|
||||||
@@ -62,6 +55,11 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
return baseSequence;
|
return baseSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual bool AllowIdleAnimation(Actor self)
|
||||||
|
{
|
||||||
|
return Info.IdleAnimations.Length > 0 && !Prone && !Panicked;
|
||||||
|
}
|
||||||
|
|
||||||
public AnimationState State { get; private set; }
|
public AnimationState State { get; private set; }
|
||||||
Mobile mobile;
|
Mobile mobile;
|
||||||
public RenderInfantry(Actor self, RenderInfantryInfo info)
|
public RenderInfantry(Actor self, RenderInfantryInfo info)
|
||||||
@@ -69,7 +67,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
||||||
State = AnimationState.Idle;
|
State = AnimationState.Waiting;
|
||||||
mobile = self.Trait<Mobile>();
|
mobile = self.Trait<Mobile>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,50 +94,35 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
State = AnimationState.Moving;
|
State = AnimationState.Moving;
|
||||||
anim.PlayRepeating(NormalizeInfantrySequence(self, "run"));
|
anim.PlayRepeating(NormalizeInfantrySequence(self, "run"));
|
||||||
}
|
}
|
||||||
|
|
||||||
wasProne = Prone;
|
wasProne = Prone;
|
||||||
|
|
||||||
if (!self.IsIdle)
|
|
||||||
{
|
|
||||||
idleState = IdleState.None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idleState == IdleState.Active)
|
|
||||||
return;
|
|
||||||
|
|
||||||
else if (idleDelay > 0 && --idleDelay == 0)
|
|
||||||
{
|
|
||||||
idleState = IdleState.Active;
|
|
||||||
|
|
||||||
if (anim.HasSequence(idleSequence))
|
|
||||||
{
|
|
||||||
anim.PlayThen(idleSequence,
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
idleState = IdleState.None;
|
|
||||||
anim.PlayRepeating(NormalizeInfantrySequence(self, "stand"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
idleState = IdleState.None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TickIdle(Actor self)
|
public void TickIdle(Actor self)
|
||||||
{
|
{
|
||||||
if (State != AnimationState.Idle)
|
if (State != AnimationState.Idle && State != AnimationState.IdleAnimating)
|
||||||
{
|
{
|
||||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
||||||
State = AnimationState.Idle;
|
State = AnimationState.Idle;
|
||||||
|
|
||||||
|
if (Info.IdleAnimations.Length > 0)
|
||||||
|
{
|
||||||
|
idleSequence = Info.IdleAnimations.Random(self.World.SharedRandom);
|
||||||
|
idleDelay = self.World.SharedRandom.Next(Info.MinIdleWaitTicks, Info.MaxIdleWaitTicks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (AllowIdleAnimation(self) && idleDelay > 0 && --idleDelay == 0)
|
||||||
|
{
|
||||||
|
if (anim.HasSequence(idleSequence))
|
||||||
|
{
|
||||||
|
State = AnimationState.IdleAnimating;
|
||||||
|
anim.PlayThen(idleSequence,
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
anim.PlayRepeating(NormalizeInfantrySequence(self, "stand"));
|
||||||
|
State = AnimationState.Waiting;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idleState != IdleState.None || Info.IdleAnimations.Length == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
idleState = IdleState.Waiting;
|
|
||||||
idleSequence = Info.IdleAnimations.Random(self.World.SharedRandom);
|
|
||||||
idleDelay = self.World.SharedRandom.Next(Info.MinIdleWaitTicks, Info.MaxIdleWaitTicks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
|
|||||||
Reference in New Issue
Block a user