Added WithMoveAnimation trait
RenderUnitFlying -> WithUnitBody + WithMoveAnimation upgrade rule Make TD Orca use WithMoveAnimation Remove RenderUnitFlying
This commit is contained in:
@@ -388,6 +388,7 @@
|
||||
<Compile Include="Traits\Render\WithBuildingExplosion.cs" />
|
||||
<Compile Include="Traits\Render\WithActiveAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithAttackAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithMoveAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
|
||||
<Compile Include="Traits\Render\WithChargeOverlay.cs" />
|
||||
|
||||
54
OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs
Normal file
54
OpenRA.Mods.Common/Traits/Render/WithMoveAnimation.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
#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.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class WithMoveAnimationInfo : ITraitInfo, Requires<WithFacingSpriteBodyInfo>, Requires<IMoveInfo>
|
||||
{
|
||||
[Desc("Displayed while moving.")]
|
||||
public readonly string MoveSequence = "move";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithMoveAnimation(init, this); }
|
||||
}
|
||||
|
||||
public class WithMoveAnimation : ITick
|
||||
{
|
||||
readonly WithMoveAnimationInfo info;
|
||||
readonly IMove movement;
|
||||
readonly WithFacingSpriteBody wfsb;
|
||||
|
||||
WPos cachedPosition;
|
||||
|
||||
public WithMoveAnimation(ActorInitializer init, WithMoveAnimationInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
movement = init.Self.Trait<IMove>();
|
||||
wfsb = init.Self.Trait<WithFacingSpriteBody>();
|
||||
|
||||
cachedPosition = init.Self.CenterPosition;
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var oldCachedPosition = cachedPosition;
|
||||
cachedPosition = self.CenterPosition;
|
||||
|
||||
// Flying units set IsMoving whenever they are airborne, which isn't enough for our purposes
|
||||
var isMoving = movement.IsMoving && !self.IsDead && (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0;
|
||||
if (isMoving ^ (wfsb.DefaultAnimation.CurrentSequence.Name != info.MoveSequence))
|
||||
return;
|
||||
|
||||
wfsb.DefaultAnimation.ReplaceAnim(isMoving ? info.MoveSequence : wfsb.Info.Sequence);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1066,6 +1066,23 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
if (rrur != null)
|
||||
rrur.Key = "-WithFacingSpriteBody";
|
||||
}
|
||||
|
||||
// For RenderUnitFlying
|
||||
var ruf = node.Value.Nodes.Where(x => x.Key == "RenderUnitFlying");
|
||||
if (ruf.Any())
|
||||
{
|
||||
ruf.Do(x => x.Key = "RenderSprites");
|
||||
node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", ""));
|
||||
node.Value.Nodes.Add(new MiniYamlNode("WithFacingSpriteBody", ""));
|
||||
node.Value.Nodes.Add(new MiniYamlNode("WithMoveAnimation", "", new List<MiniYamlNode>
|
||||
{
|
||||
new MiniYamlNode("MoveSequence", "move")
|
||||
}));
|
||||
|
||||
var rruf = node.Value.Nodes.FirstOrDefault(n => n.Key == "-RenderUnitFlying");
|
||||
if (rruf != null)
|
||||
rruf.Key = "-WithFacingSpriteBody";
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
|
||||
Reference in New Issue
Block a user