Added WithLandingCraftAnimation and removed RenderLandingCraft
This commit is contained in:
83
OpenRA.Mods.RA/Traits/Render/WithLandingCraftAnimation.cs
Normal file
83
OpenRA.Mods.RA/Traits/Render/WithLandingCraftAnimation.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
public class WithLandingCraftAnimationInfo : ITraitInfo, Requires<IMoveInfo>, Requires<WithSpriteBodyInfo>, Requires<CargoInfo>
|
||||
{
|
||||
public readonly string[] OpenTerrainTypes = { "Clear" };
|
||||
[SequenceReference] public readonly string OpenSequence = "open";
|
||||
[SequenceReference] public readonly string UnloadSequence = "unload";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithLandingCraftAnimation(init, this); }
|
||||
}
|
||||
|
||||
public class WithLandingCraftAnimation : ITick
|
||||
{
|
||||
readonly WithLandingCraftAnimationInfo info;
|
||||
readonly Actor self;
|
||||
readonly Cargo cargo;
|
||||
readonly IMove move;
|
||||
readonly WithSpriteBody wsb;
|
||||
bool open;
|
||||
|
||||
public WithLandingCraftAnimation(ActorInitializer init, WithLandingCraftAnimationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
self = init.Self;
|
||||
cargo = self.Trait<Cargo>();
|
||||
move = self.Trait<IMove>();
|
||||
wsb = init.Self.Trait<WithSpriteBody>();
|
||||
}
|
||||
|
||||
public bool ShouldBeOpen()
|
||||
{
|
||||
if (self.CenterPosition.Z > 0 || move.IsMoving)
|
||||
return false;
|
||||
|
||||
return cargo.CurrentAdjacentCells.Any(c => self.World.Map.Contains(c)
|
||||
&& info.OpenTerrainTypes.Contains(self.World.Map.GetTerrainInfo(c).Type));
|
||||
}
|
||||
|
||||
void Open()
|
||||
{
|
||||
if (open || !wsb.DefaultAnimation.HasSequence(info.OpenSequence))
|
||||
return;
|
||||
|
||||
open = true;
|
||||
wsb.PlayCustomAnimation(self, info.OpenSequence, () =>
|
||||
{
|
||||
if (wsb.DefaultAnimation.HasSequence(info.UnloadSequence))
|
||||
wsb.PlayCustomAnimationRepeating(self, info.UnloadSequence);
|
||||
});
|
||||
}
|
||||
|
||||
void Close()
|
||||
{
|
||||
if (!open || !wsb.DefaultAnimation.HasSequence(info.OpenSequence))
|
||||
return;
|
||||
|
||||
open = false;
|
||||
wsb.PlayCustomAnimationBackwards(self, info.OpenSequence, null);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (ShouldBeOpen())
|
||||
Open();
|
||||
else
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user