diff --git a/OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs index 3438e47314..2f22d3e3a1 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithAttackAnimation.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits.Render { armament = init.Self.TraitsImplementing() .Single(a => a.Info.Name == Info.Armament); - wsb = init.Self.TraitsImplementing().First(w => w.Info.Name == Info.Body); + wsb = init.Self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); } void PlayAttackAnimation(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs index 8bcb8ab75e..f8593e488c 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBuildingPlacedAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -19,6 +20,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Sequence name to use"), SequenceReference] public readonly string Sequence = "build"; + [Desc("Which sprite body to play the animation on.")] + public readonly string Body = "body"; + public object Create(ActorInitializer init) { return new WithBuildingPlacedAnimation(init.Self, this); } } @@ -31,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits.Render public WithBuildingPlacedAnimation(Actor self, WithBuildingPlacedAnimationInfo info) { this.info = info; - wsb = self.Trait(); + wsb = self.TraitsImplementing().Single(w => w.Info.Name == info.Body); buildComplete = !self.Info.HasTraitInfo(); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithChargeAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithChargeAnimation.cs index 15a12246f3..1982c8ece8 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithChargeAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithChargeAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -20,6 +21,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Sequence to use for the charge levels.")] 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 WithChargeAnimation(init.Self, this); } } @@ -32,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits.Render public WithChargeAnimation(Actor self, WithChargeAnimationInfo info) { this.info = info; - wsb = self.Trait(); + wsb = self.TraitsImplementing().Single(w => w.Info.Name == info.Body); attackCharges = self.Trait(); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithHarvestAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithHarvestAnimation.cs index 0737c93248..2c9bf51c5d 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithHarvestAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithHarvestAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Activities; using OpenRA.Traits; @@ -22,6 +23,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Displayed while harvesting.")] [SequenceReference] public readonly string HarvestSequence = "harvest"; + [Desc("Which sprite body to play the animation on.")] + public readonly string Body = "body"; + public object Create(ActorInitializer init) { return new WithHarvestAnimation(init, this); } } @@ -38,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits.Render { Info = info; harv = init.Self.Trait(); - wsb = init.Self.Trait(); + wsb = init.Self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); } protected virtual string NormalizeHarvesterSequence(Actor self, string baseSequence) diff --git a/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs index 10c92a80dd..8bc391a03e 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithIdleAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -21,6 +22,9 @@ namespace OpenRA.Mods.Common.Traits.Render public readonly int Interval = 750; + [Desc("Which sprite body to play the animation on.")] + public readonly string Body = "body"; + public override object Create(ActorInitializer init) { return new WithIdleAnimation(init.Self, this); } } @@ -33,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits.Render public WithIdleAnimation(Actor self, WithIdleAnimationInfo info) : base(info) { - wsb = self.Trait(); + wsb = self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); buildComplete = !self.Info.HasTraitInfo(); // always render instantly for units ticks = info.Interval; } diff --git a/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs index eddf620981..194979d515 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Render : base(info) { movement = init.Self.Trait(); - wsb = init.Self.TraitsImplementing().First(w => w.Info.Name == Info.Body); + wsb = init.Self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); } void ITick.Tick(Actor self) diff --git a/OpenRA.Mods.Common/Traits/Render/WithNukeLaunchAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithNukeLaunchAnimation.cs index f286b44aa2..c098d98dda 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithNukeLaunchAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithNukeLaunchAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -19,6 +20,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Sequence name to use")] [SequenceReference] public readonly string Sequence = "active"; + [Desc("Which sprite body to play the animation on.")] + public readonly string Body = "body"; + public override object Create(ActorInitializer init) { return new WithNukeLaunchAnimation(init.Self, this); } } @@ -30,12 +34,12 @@ namespace OpenRA.Mods.Common.Traits.Render public WithNukeLaunchAnimation(Actor self, WithNukeLaunchAnimationInfo info) : base(info) { - spriteBody = self.TraitOrDefault(); + spriteBody = self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); } void INotifyNuke.Launching(Actor self) { - if (buildComplete && spriteBody != null && !IsTraitDisabled) + if (buildComplete && !IsTraitDisabled) spriteBody.PlayCustomAnimation(self, Info.Sequence, () => spriteBody.CancelCustomAnimation(self)); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithRearmAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithRearmAnimation.cs index 1229efc311..edf429eb81 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRearmAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRearmAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -19,6 +20,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Sequence name to use")] [SequenceReference] public readonly string Sequence = "active"; + [Desc("Which sprite body to play the animation on.")] + public readonly string Body = "body"; + public override object Create(ActorInitializer init) { return new WithRearmAnimation(init.Self, this); } } @@ -30,12 +34,12 @@ namespace OpenRA.Mods.Common.Traits.Render public WithRearmAnimation(Actor self, WithRearmAnimationInfo info) : base(info) { - spriteBody = self.TraitOrDefault(); + spriteBody = self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); } void INotifyRearm.Rearming(Actor self, Actor target) { - if (buildComplete && spriteBody != null && !IsTraitDisabled) + if (buildComplete && !IsTraitDisabled) spriteBody.PlayCustomAnimation(self, Info.Sequence); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs index fef78fe926..9665a94d0c 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithRepairAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -19,6 +20,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Sequence name to use")] [SequenceReference] public readonly string Sequence = "active"; + [Desc("Which sprite body to play the animation on.")] + public readonly string Body = "body"; + public override object Create(ActorInitializer init) { return new WithRepairAnimation(init.Self, this); } } @@ -30,14 +34,14 @@ namespace OpenRA.Mods.Common.Traits.Render public WithRepairAnimation(Actor self, WithRepairAnimationInfo info) : base(info) { - spriteBody = self.TraitOrDefault(); + spriteBody = self.TraitsImplementing().Single(w => w.Info.Name == Info.Body); } void INotifyRepair.BeforeRepair(Actor self, Actor target) { } void INotifyRepair.RepairTick(Actor self, Actor target) { - if (buildComplete && spriteBody != null && !IsTraitDisabled) + if (buildComplete && !IsTraitDisabled) spriteBody.PlayCustomAnimation(self, Info.Sequence); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithSiloAnimation.cs b/OpenRA.Mods.Common/Traits/Render/WithSiloAnimation.cs index 31bd85dcd9..5a3999cfc8 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSiloAnimation.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSiloAnimation.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Linq; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render @@ -22,6 +23,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Internal resource stages. Does not have to match number of sequence frames.")] public readonly int Stages = 10; + [Desc("Which sprite body to play the animation on.")] + public readonly string Body = "body"; + public object Create(ActorInitializer init) { return new WithSiloAnimation(init, this); } } @@ -34,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits.Render public WithSiloAnimation(ActorInitializer init, WithSiloAnimationInfo info) { this.info = info; - wsb = init.Self.Trait(); + wsb = init.Self.TraitsImplementing().Single(w => w.Info.Name == info.Body); playerResources = init.Self.Owner.PlayerActor.Trait(); }