From ac6b2a8f62689d10a2032faa39bd767d9f179ec7 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 2 Jul 2016 22:39:34 +0100 Subject: [PATCH] Support custom fully-open sequences for gates. --- .../Traits/Render/WithGateSpriteBody.cs | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs index 46ef57395e..921bcd1c46 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs @@ -26,6 +26,9 @@ namespace OpenRA.Mods.Common.Traits.Render [Desc("Wall type for connections")] public readonly string Type = "wall"; + [Desc("Override sequence to use when fully open.")] + public readonly string OpenSequence = null; + public override object Create(ActorInitializer init) { return new WithGateSpriteBody(init, this); } public override IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) @@ -42,10 +45,11 @@ namespace OpenRA.Mods.Common.Traits.Render } } - class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, INotifyBuildComplete, IWallConnector + class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, INotifyBuildComplete, IWallConnector, ITick { readonly WithGateSpriteBodyInfo gateInfo; readonly Gate gate; + bool renderOpen; public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info) : base(init, info, () => 0) @@ -54,6 +58,26 @@ namespace OpenRA.Mods.Common.Traits.Render gate = init.Self.Trait(); } + void UpdateState(Actor self) + { + if (renderOpen) + DefaultAnimation.PlayRepeating(NormalizeSequence(self, gateInfo.OpenSequence)); + else + DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame); + } + + void ITick.Tick(Actor self) + { + if (gateInfo.OpenSequence == null) + return; + + if (gate.Position == gate.OpenPosition ^ renderOpen) + { + renderOpen = gate.Position == gate.OpenPosition; + UpdateState(self); + } + } + int GetGateFrame() { return int2.Lerp(0, DefaultAnimation.CurrentSequence.Length - 1, gate.Position, gate.OpenPosition); @@ -61,12 +85,12 @@ namespace OpenRA.Mods.Common.Traits.Render public override void DamageStateChanged(Actor self, AttackInfo e) { - DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame); + UpdateState(self); } public override void BuildingComplete(Actor self) { - DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame); + UpdateState(self); UpdateNeighbours(self); }