Play WithAcceptDeliveredCashAnimation only on the assigned WithSpriteBody

This commit is contained in:
reaperrr
2018-05-17 09:18:14 +02:00
committed by Matthias Mailänder
parent f85f2cd104
commit 0d0d2e0ae3

View File

@@ -20,19 +20,22 @@ namespace OpenRA.Mods.Common.Traits.Render
[Desc("Sequence name to use")] [Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "active"; [SequenceReference] public readonly string Sequence = "active";
[Desc("Which sprite body to play the animation on.")]
public readonly string Body = "body";
public object Create(ActorInitializer init) { return new WithAcceptDeliveredCashAnimation(init.Self, this); } public object Create(ActorInitializer init) { return new WithAcceptDeliveredCashAnimation(init.Self, this); }
} }
public class WithAcceptDeliveredCashAnimation : INotifyCashTransfer, INotifyBuildComplete, INotifySold public class WithAcceptDeliveredCashAnimation : INotifyCashTransfer, INotifyBuildComplete, INotifySold
{ {
readonly WithAcceptDeliveredCashAnimationInfo info; readonly WithAcceptDeliveredCashAnimationInfo info;
readonly WithSpriteBody[] wsbs; readonly WithSpriteBody wsb;
bool buildComplete; bool buildComplete;
public WithAcceptDeliveredCashAnimation(Actor self, WithAcceptDeliveredCashAnimationInfo info) public WithAcceptDeliveredCashAnimation(Actor self, WithAcceptDeliveredCashAnimationInfo info)
{ {
this.info = info; this.info = info;
wsbs = self.TraitsImplementing<WithSpriteBody>().ToArray(); wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
} }
void INotifyBuildComplete.BuildingComplete(Actor self) void INotifyBuildComplete.BuildingComplete(Actor self)
@@ -53,12 +56,9 @@ namespace OpenRA.Mods.Common.Traits.Render
if (!buildComplete || playing) if (!buildComplete || playing)
return; return;
foreach (var wsb in wsbs)
{
playing = true; playing = true;
wsb.PlayCustomAnimation(self, info.Sequence, () => playing = false); wsb.PlayCustomAnimation(self, info.Sequence, () => playing = false);
} }
}
void INotifyCashTransfer.OnDeliveringCash(Actor self, Actor acceptor) { } void INotifyCashTransfer.OnDeliveringCash(Actor self, Actor acceptor) { }
} }