Support custom fully-open sequences for gates.
This commit is contained in:
@@ -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<IActorPreview> 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<Gate>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user