Added WithMoveAnimation trait

RenderUnitFlying -> WithUnitBody + WithMoveAnimation upgrade rule

Make TD Orca use WithMoveAnimation
Remove RenderUnitFlying
This commit is contained in:
reaperrr
2015-05-12 03:52:41 +02:00
parent 4d79cce491
commit 733b7fc0b0
5 changed files with 35 additions and 15 deletions

View File

@@ -72,7 +72,6 @@
<Compile Include="Traits\SupportPowers\IonCannonPower.cs" /> <Compile Include="Traits\SupportPowers\IonCannonPower.cs" />
<Compile Include="Widgets\Logic\CncMainMenuLogic.cs" /> <Compile Include="Widgets\Logic\CncMainMenuLogic.cs" />
<Compile Include="Widgets\Logic\ProductionTabsLogic.cs" /> <Compile Include="Widgets\Logic\ProductionTabsLogic.cs" />
<Compile Include="Traits\RenderUnitFlying.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj"> <ProjectReference Include="..\OpenRA.Game\OpenRA.Game.csproj">

View File

@@ -388,6 +388,7 @@
<Compile Include="Traits\Render\WithBuildingExplosion.cs" /> <Compile Include="Traits\Render\WithBuildingExplosion.cs" />
<Compile Include="Traits\Render\WithActiveAnimation.cs" /> <Compile Include="Traits\Render\WithActiveAnimation.cs" />
<Compile Include="Traits\Render\WithAttackAnimation.cs" /> <Compile Include="Traits\Render\WithAttackAnimation.cs" />
<Compile Include="Traits\Render\WithMoveAnimation.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" /> <Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithMakeAnimation.cs" /> <Compile Include="Traits\Render\WithMakeAnimation.cs" />
<Compile Include="Traits\Render\WithChargeOverlay.cs" /> <Compile Include="Traits\Render\WithChargeOverlay.cs" />

View File

@@ -8,47 +8,47 @@
*/ */
#endregion #endregion
using OpenRA.Mods.Common.Traits; using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits namespace OpenRA.Mods.Common.Traits
{ {
class RenderUnitFlyingInfo : RenderUnitInfo, Requires<IMoveInfo> public class WithMoveAnimationInfo : ITraitInfo, Requires<WithFacingSpriteBodyInfo>, Requires<IMoveInfo>
{ {
[Desc("Displayed while moving.")]
public readonly string MoveSequence = "move"; public readonly string MoveSequence = "move";
public override object Create(ActorInitializer init) { return new RenderUnitFlying(init, this); } public object Create(ActorInitializer init) { return new WithMoveAnimation(init, this); }
} }
class RenderUnitFlying : RenderUnit, ITick public class WithMoveAnimation : ITick
{ {
readonly RenderUnitFlyingInfo info; readonly WithMoveAnimationInfo info;
readonly IMove movement; readonly IMove movement;
readonly WithFacingSpriteBody wfsb;
WPos cachedPosition; WPos cachedPosition;
public RenderUnitFlying(ActorInitializer init, RenderUnitFlyingInfo info) public WithMoveAnimation(ActorInitializer init, WithMoveAnimationInfo info)
: base(init, info)
{ {
this.info = info; this.info = info;
movement = init.Self.Trait<IMove>(); movement = init.Self.Trait<IMove>();
wfsb = init.Self.Trait<WithFacingSpriteBody>();
cachedPosition = init.Self.CenterPosition; cachedPosition = init.Self.CenterPosition;
} }
public override void Tick(Actor self) public void Tick(Actor self)
{ {
base.Tick(self);
var oldCachedPosition = cachedPosition; var oldCachedPosition = cachedPosition;
cachedPosition = self.CenterPosition; cachedPosition = self.CenterPosition;
// Flying units set IsMoving whenever they are airborne, which isn't enough for our purposes // 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; var isMoving = movement.IsMoving && !self.IsDead && (oldCachedPosition - cachedPosition).HorizontalLengthSquared != 0;
if (isMoving ^ (DefaultAnimation.CurrentSequence.Name != info.MoveSequence)) if (isMoving ^ (wfsb.DefaultAnimation.CurrentSequence.Name != info.MoveSequence))
return; return;
DefaultAnimation.ReplaceAnim(isMoving ? info.MoveSequence : info.Sequence); wfsb.DefaultAnimation.ReplaceAnim(isMoving ? info.MoveSequence : wfsb.Info.Sequence);
} }
} }
} }

View File

@@ -1066,6 +1066,23 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (rrur != null) if (rrur != null)
rrur.Key = "-WithFacingSpriteBody"; 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); UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -129,13 +129,16 @@ ORCA:
SelfReloads: true SelfReloads: true
ReloadCount: 2 ReloadCount: 2
SelfReloadTicks: 100 SelfReloadTicks: 100
RenderUnitFlying: RenderSprites:
LeavesHusk: LeavesHusk:
HuskActor: ORCA.Husk HuskActor: ORCA.Husk
AutoTarget: AutoTarget:
Explodes: Explodes:
Weapon: HeliExplode Weapon: HeliExplode
EmptyWeapon: HeliExplode EmptyWeapon: HeliExplode
AutoSelectionSize:
WithMoveAnimation:
MoveSequence: move
C17: C17:
ParaDrop: ParaDrop: