Fix various Mods.Common animation traits not supporting actors having multiple sprite bodies

This commit is contained in:
reaperrr
2018-05-17 09:19:13 +02:00
committed by Matthias Mailänder
parent 0d0d2e0ae3
commit 9d24c40f92
10 changed files with 45 additions and 13 deletions

View File

@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits.Render
{
armament = init.Self.TraitsImplementing<Armament>()
.Single(a => a.Info.Name == Info.Armament);
wsb = init.Self.TraitsImplementing<WithSpriteBody>().First(w => w.Info.Name == Info.Body);
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
}
void PlayAttackAnimation(Actor self)

View File

@@ -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<WithSpriteBody>();
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>();
}

View File

@@ -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<WithSpriteBody>();
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
attackCharges = self.Trait<AttackCharges>();
}

View File

@@ -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<Harvester>();
wsb = init.Self.Trait<WithSpriteBody>();
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
}
protected virtual string NormalizeHarvesterSequence(Actor self, string baseSequence)

View File

@@ -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<WithSpriteBody>();
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
ticks = info.Interval;
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Render
: base(info)
{
movement = init.Self.Trait<IMove>();
wsb = init.Self.TraitsImplementing<WithSpriteBody>().First(w => w.Info.Name == Info.Body);
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == Info.Body);
}
void ITick.Tick(Actor self)

View File

@@ -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<WithSpriteBody>();
spriteBody = self.TraitsImplementing<WithSpriteBody>().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));
}

View File

@@ -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<WithSpriteBody>();
spriteBody = self.TraitsImplementing<WithSpriteBody>().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);
}

View File

@@ -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<WithSpriteBody>();
spriteBody = self.TraitsImplementing<WithSpriteBody>().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);
}

View File

@@ -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<WithSpriteBody>();
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
}