Added WithLandingCraftAnimation and removed RenderLandingCraft

This commit is contained in:
reaperrr
2015-06-23 20:07:15 +02:00
parent 1abe7ab2dc
commit de72db83db
5 changed files with 60 additions and 23 deletions

View File

@@ -104,7 +104,7 @@
<Compile Include="Traits\PaletteEffects\ChronoshiftPaletteEffect.cs" />
<Compile Include="Traits\PortableChrono.cs" />
<Compile Include="Traits\Render\RenderJammerCircle.cs" />
<Compile Include="Traits\Render\RenderLandingCraft.cs" />
<Compile Include="Traits\Render\WithLandingCraftAnimation.cs" />
<Compile Include="Traits\Render\RenderShroudCircle.cs" />
<Compile Include="Traits\SupportPowers\ChronoshiftPower.cs" />
<Compile Include="Traits\SupportPowers\GpsPower.cs" />

View File

@@ -14,30 +14,31 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Traits
{
public class RenderLandingCraftInfo : RenderUnitInfo, Requires<IMoveInfo>, Requires<CargoInfo>
public class WithLandingCraftAnimationInfo : ITraitInfo, Requires<IMoveInfo>, Requires<WithSpriteBodyInfo>, Requires<CargoInfo>
{
public readonly string[] OpenTerrainTypes = { "Clear" };
[SequenceReference] public readonly string OpenAnim = "open";
[SequenceReference] public readonly string UnloadAnim = "unload";
[SequenceReference] public readonly string OpenSequence = "open";
[SequenceReference] public readonly string UnloadSequence = "unload";
public override object Create(ActorInitializer init) { return new RenderLandingCraft(init, this); }
public object Create(ActorInitializer init) { return new WithLandingCraftAnimation(init, this); }
}
public class RenderLandingCraft : RenderUnit
public class WithLandingCraftAnimation : ITick
{
readonly RenderLandingCraftInfo info;
readonly WithLandingCraftAnimationInfo info;
readonly Actor self;
readonly Cargo cargo;
readonly IMove move;
readonly WithSpriteBody wsb;
bool open;
public RenderLandingCraft(ActorInitializer init, RenderLandingCraftInfo info)
: base(init, info)
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()
@@ -51,34 +52,32 @@ namespace OpenRA.Mods.RA.Traits
void Open()
{
if (open || !DefaultAnimation.HasSequence(info.OpenAnim))
if (open || !wsb.DefaultAnimation.HasSequence(info.OpenSequence))
return;
open = true;
PlayCustomAnimation(self, info.OpenAnim, () =>
wsb.PlayCustomAnimation(self, info.OpenSequence, () =>
{
if (DefaultAnimation.HasSequence(info.UnloadAnim))
PlayCustomAnimationRepeating(self, info.UnloadAnim);
if (wsb.DefaultAnimation.HasSequence(info.UnloadSequence))
wsb.PlayCustomAnimationRepeating(self, info.UnloadSequence);
});
}
void Close()
{
if (!open || !DefaultAnimation.HasSequence(info.OpenAnim))
if (!open || !wsb.DefaultAnimation.HasSequence(info.OpenSequence))
return;
open = false;
PlayCustomAnimationBackwards(self, info.OpenAnim, null);
wsb.PlayCustomAnimationBackwards(self, info.OpenSequence, null);
}
public override void Tick(Actor self)
public void Tick(Actor self)
{
if (ShouldBeOpen())
Open();
else
Close();
base.Tick(self);
}
}
}