Convert WithRepairAnimation from disable to conditional.

This commit is contained in:
atlimit8
2017-03-16 17:29:45 -05:00
parent 5fd4b3a1bd
commit 700b117122

View File

@@ -14,32 +14,29 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render namespace OpenRA.Mods.Common.Traits.Render
{ {
[Desc("Replaces the building animation when it repairs a unit.")] [Desc("Replaces the building animation when it repairs a unit.")]
public class WithRepairAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo> public class WithRepairAnimationInfo : ConditionalTraitInfo, Requires<WithSpriteBodyInfo>
{ {
[Desc("Sequence name to use")] [Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "active"; [SequenceReference] public readonly string Sequence = "active";
public readonly bool PauseOnLowPower = false; public override object Create(ActorInitializer init) { return new WithRepairAnimation(init.Self, this); }
public object Create(ActorInitializer init) { return new WithRepairAnimation(init.Self, this); }
} }
public class WithRepairAnimation : INotifyRepair, INotifyBuildComplete, INotifySold public class WithRepairAnimation : ConditionalTrait<WithRepairAnimationInfo>, INotifyRepair, INotifyBuildComplete, INotifySold
{ {
readonly WithRepairAnimationInfo info;
readonly WithSpriteBody spriteBody; readonly WithSpriteBody spriteBody;
bool buildComplete; bool buildComplete;
public WithRepairAnimation(Actor self, WithRepairAnimationInfo info) public WithRepairAnimation(Actor self, WithRepairAnimationInfo info)
: base(info)
{ {
this.info = info;
spriteBody = self.TraitOrDefault<WithSpriteBody>(); spriteBody = self.TraitOrDefault<WithSpriteBody>();
} }
void INotifyRepair.Repairing(Actor self, Actor target) void INotifyRepair.Repairing(Actor self, Actor target)
{ {
if (buildComplete && spriteBody != null && !(info.PauseOnLowPower && self.IsDisabled())) if (buildComplete && spriteBody != null && !IsTraitDisabled)
spriteBody.PlayCustomAnimation(self, info.Sequence, () => spriteBody.CancelCustomAnimation(self)); spriteBody.PlayCustomAnimation(self, Info.Sequence, () => spriteBody.CancelCustomAnimation(self));
} }
void INotifyBuildComplete.BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)