Replace INotifyBuildComplete in render traits with conditions.

This commit is contained in:
Paul Chote
2018-10-05 20:16:36 +00:00
committed by abcdefg30
parent 26b0a06a17
commit 14607f55c5
28 changed files with 152 additions and 407 deletions

View File

@@ -28,23 +28,21 @@ namespace OpenRA.Mods.Common.Traits.Render
public override object Create(ActorInitializer init) { return new WithIdleAnimation(init.Self, this); }
}
public class WithIdleAnimation : ConditionalTrait<WithIdleAnimationInfo>, ITick, INotifyBuildComplete, INotifySold
public class WithIdleAnimation : ConditionalTrait<WithIdleAnimationInfo>, ITick
{
readonly WithSpriteBody wsb;
bool buildComplete;
int ticks;
public WithIdleAnimation(Actor self, WithIdleAnimationInfo info)
: base(info)
{
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
ticks = info.Interval;
}
void ITick.Tick(Actor self)
{
if (!buildComplete || IsTraitDisabled)
if (IsTraitDisabled)
return;
if (--ticks <= 0)
@@ -54,16 +52,9 @@ namespace OpenRA.Mods.Common.Traits.Render
}
}
void INotifyBuildComplete.BuildingComplete(Actor self)
protected override void TraitDisabled(Actor self)
{
buildComplete = true;
wsb.CancelCustomAnimation(self);
}
void INotifySold.Selling(Actor self)
{
buildComplete = false;
}
void INotifySold.Sold(Actor self) { }
}
}