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

This commit is contained in:
reaperrr
2018-05-17 09:54:00 +02:00
committed by Matthias Mailänder
parent 9d24c40f92
commit d060f885e8
4 changed files with 24 additions and 10 deletions

View File

@@ -21,21 +21,24 @@ namespace OpenRA.Mods.Cnc.Traits
class AttackPopupTurretedInfo : AttackTurretedInfo, Requires<BuildingInfo>, Requires<WithEmbeddedTurretSpriteBodyInfo> class AttackPopupTurretedInfo : AttackTurretedInfo, Requires<BuildingInfo>, Requires<WithEmbeddedTurretSpriteBodyInfo>
{ {
[Desc("How many game ticks should pass before closing the actor's turret.")] [Desc("How many game ticks should pass before closing the actor's turret.")]
public int CloseDelay = 125; public readonly int CloseDelay = 125;
public int DefaultFacing = 0; public readonly int DefaultFacing = 0;
[Desc("The percentage of damage that is received while this actor is closed.")] [Desc("The percentage of damage that is received while this actor is closed.")]
public int ClosedDamageMultiplier = 50; public readonly int ClosedDamageMultiplier = 50;
[Desc("Sequence to play when opening.")] [Desc("Sequence to play when opening.")]
[SequenceReference] public string OpeningSequence = "opening"; [SequenceReference] public readonly string OpeningSequence = "opening";
[Desc("Sequence to play when closing.")] [Desc("Sequence to play when closing.")]
[SequenceReference] public string ClosingSequence = "closing"; [SequenceReference] public readonly string ClosingSequence = "closing";
[Desc("Idle sequence to play when closed.")] [Desc("Idle sequence to play when closed.")]
[SequenceReference] public string ClosedIdleSequence = "closed-idle"; [SequenceReference] public readonly string ClosedIdleSequence = "closed-idle";
[Desc("Which sprite body to play the animation on.")]
public readonly string Body = "body";
public override object Create(ActorInitializer init) { return new AttackPopupTurreted(init, this); } public override object Create(ActorInitializer init) { return new AttackPopupTurreted(init, this); }
} }
@@ -57,7 +60,7 @@ namespace OpenRA.Mods.Cnc.Traits
{ {
this.info = info; this.info = info;
turret = turrets.FirstOrDefault(); turret = turrets.FirstOrDefault();
wsb = init.Self.Trait<WithSpriteBody>(); wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
skippedMakeAnimation = init.Contains<SkipMakeAnimsInit>(); skippedMakeAnimation = init.Contains<SkipMakeAnimsInit>();
} }

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render; using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Traits; using OpenRA.Traits;
@@ -22,6 +23,9 @@ namespace OpenRA.Mods.Cnc.Traits.Render
[SequenceReference] public readonly string IdleSequence = "idle"; [SequenceReference] public readonly string IdleSequence = "idle";
[Desc("Which sprite body to play the animation on.")]
public readonly string Body = "body";
public object Create(ActorInitializer init) { return new WithDeliveryAnimation(init.Self, this); } public object Create(ActorInitializer init) { return new WithDeliveryAnimation(init.Self, this); }
} }
@@ -32,7 +36,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
public WithDeliveryAnimation(Actor self, WithDeliveryAnimationInfo info) public WithDeliveryAnimation(Actor self, WithDeliveryAnimationInfo info)
{ {
wsb = self.Trait<WithSpriteBody>(); wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
this.info = info; this.info = info;
} }

View File

@@ -24,6 +24,9 @@ namespace OpenRA.Mods.Cnc.Traits.Render
[SequenceReference] public readonly string CloseSequence = "close"; [SequenceReference] public readonly string CloseSequence = "close";
[SequenceReference] public readonly string UnloadSequence = "unload"; [SequenceReference] public readonly string UnloadSequence = "unload";
[Desc("Which sprite body to play the animation on.")]
public readonly string Body = "body";
public object Create(ActorInitializer init) { return new WithLandingCraftAnimation(init, this); } public object Create(ActorInitializer init) { return new WithLandingCraftAnimation(init, this); }
} }
@@ -42,7 +45,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
self = init.Self; self = init.Self;
cargo = self.Trait<Cargo>(); cargo = self.Trait<Cargo>();
move = self.Trait<IMove>(); move = self.Trait<IMove>();
wsb = init.Self.Trait<WithSpriteBody>(); wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
} }
public bool ShouldBeOpen() public bool ShouldBeOpen()

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.Mods.Common.Traits.Render; using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Traits; using OpenRA.Traits;
@@ -20,6 +21,9 @@ namespace OpenRA.Mods.Cnc.Traits.Render
[Desc("Sequence to use for charge animation.")] [Desc("Sequence to use for charge animation.")]
[SequenceReference] public readonly string ChargeSequence = "active"; [SequenceReference] public readonly string ChargeSequence = "active";
[Desc("Which sprite body to play the animation on.")]
public readonly string Body = "body";
public object Create(ActorInitializer init) { return new WithTeslaChargeAnimation(init, this); } public object Create(ActorInitializer init) { return new WithTeslaChargeAnimation(init, this); }
} }
@@ -31,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
public WithTeslaChargeAnimation(ActorInitializer init, WithTeslaChargeAnimationInfo info) public WithTeslaChargeAnimation(ActorInitializer init, WithTeslaChargeAnimationInfo info)
{ {
this.info = info; this.info = info;
wsb = init.Self.Trait<WithSpriteBody>(); wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
} }
void INotifyTeslaCharging.Charging(Actor self, Target target) void INotifyTeslaCharging.Charging(Actor self, Target target)