Added WithFacingSpriteBody trait.
Extracted AutoSelectionSize into its own trait. RenderUnit -> RenderSprites + WithFacingSpriteBody upgrade rule Remove RenderSimple dependencies of ThrowsParticle and WithHarvestAnimation.
This commit is contained in:
@@ -364,6 +364,7 @@
|
|||||||
<Compile Include="Traits\ProximityCaptor.cs" />
|
<Compile Include="Traits\ProximityCaptor.cs" />
|
||||||
<Compile Include="Traits\ProximityCapturable.cs" />
|
<Compile Include="Traits\ProximityCapturable.cs" />
|
||||||
<Compile Include="Traits\RadarColorFromTerrain.cs" />
|
<Compile Include="Traits\RadarColorFromTerrain.cs" />
|
||||||
|
<Compile Include="Traits\Render\AutoSelectionSize.cs" />
|
||||||
<Compile Include="Traits\Render\Hovers.cs" />
|
<Compile Include="Traits\Render\Hovers.cs" />
|
||||||
<Compile Include="Traits\Render\LeavesTrails.cs" />
|
<Compile Include="Traits\Render\LeavesTrails.cs" />
|
||||||
<Compile Include="Traits\Render\RenderBuilding.cs" />
|
<Compile Include="Traits\Render\RenderBuilding.cs" />
|
||||||
@@ -405,6 +406,7 @@
|
|||||||
<Compile Include="Traits\Render\WithSmoke.cs" />
|
<Compile Include="Traits\Render\WithSmoke.cs" />
|
||||||
<Compile Include="Traits\Render\WithSpriteBody.cs" />
|
<Compile Include="Traits\Render\WithSpriteBody.cs" />
|
||||||
<Compile Include="Traits\Render\WithTurret.cs" />
|
<Compile Include="Traits\Render\WithTurret.cs" />
|
||||||
|
<Compile Include="Traits\Render\WithFacingSpriteBody.cs" />
|
||||||
<Compile Include="Traits\Render\WithBuildingPlacedOverlay.cs" />
|
<Compile Include="Traits\Render\WithBuildingPlacedOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithProductionDoorOverlay.cs" />
|
<Compile Include="Traits\Render\WithProductionDoorOverlay.cs" />
|
||||||
<Compile Include="Traits\Render\WithProductionOverlay.cs" />
|
<Compile Include="Traits\Render\WithProductionOverlay.cs" />
|
||||||
|
|||||||
31
OpenRA.Mods.Common/Traits/Render/AutoSelectionSize.cs
Normal file
31
OpenRA.Mods.Common/Traits/Render/AutoSelectionSize.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#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;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
public class AutoSelectionSizeInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||||
|
{
|
||||||
|
public object Create(ActorInitializer init) { return new AutoSelectionSize(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AutoSelectionSize : IAutoSelectionSize
|
||||||
|
{
|
||||||
|
public AutoSelectionSize(AutoSelectionSizeInfo info) { }
|
||||||
|
|
||||||
|
public int2 SelectionSize(Actor self)
|
||||||
|
{
|
||||||
|
var rs = self.Trait<RenderSprites>();
|
||||||
|
return rs.AutoSelectionSize(self);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -236,8 +236,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return sequence;
|
return sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Required by RenderSimple
|
// Required by RenderSimple, WithSpriteBody and WithInfantryBody
|
||||||
protected int2 AutoSelectionSize(Actor self)
|
public int2 AutoSelectionSize(Actor self)
|
||||||
{
|
{
|
||||||
return anims.Where(b => b.IsVisible
|
return anims.Where(b => b.IsVisible
|
||||||
&& b.Animation.Animation.CurrentSequence != null)
|
&& b.Animation.Animation.CurrentSequence != null)
|
||||||
|
|||||||
46
OpenRA.Mods.Common/Traits/Render/WithFacingSpriteBody.cs
Normal file
46
OpenRA.Mods.Common/Traits/Render/WithFacingSpriteBody.cs
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
public class WithFacingSpriteBodyInfo : WithSpriteBodyInfo, Requires<IBodyOrientationInfo>, Requires<IFacingInfo>
|
||||||
|
{
|
||||||
|
public override object Create(ActorInitializer init) { return new WithFacingSpriteBody(init, this); }
|
||||||
|
|
||||||
|
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
|
{
|
||||||
|
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||||
|
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||||
|
|
||||||
|
var anim = new Animation(init.World, image, () => facing);
|
||||||
|
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||||
|
|
||||||
|
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race)
|
||||||
|
{
|
||||||
|
var rsi = ai.Traits.Get<RenderSpritesInfo>();
|
||||||
|
return sequenceProvider.GetSequence(rsi.GetImage(ai, sequenceProvider, race), Sequence).Facings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WithFacingSpriteBody : WithSpriteBody
|
||||||
|
{
|
||||||
|
public WithFacingSpriteBody(ActorInitializer init, WithFacingSpriteBodyInfo info)
|
||||||
|
: base(init, info, RenderSprites.MakeFacingFunc(init.Self)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var rs = self.Trait<RenderSprites>();
|
var rs = self.Trait<RenderSprites>();
|
||||||
var body = self.Trait<IBodyOrientation>();
|
var body = self.Trait<IBodyOrientation>();
|
||||||
|
|
||||||
anim = new Animation(self.World, rs.GetImage(self), RenderSimple.MakeFacingFunc(self));
|
anim = new Animation(self.World, rs.GetImage(self), RenderSprites.MakeFacingFunc(self));
|
||||||
anim.IsDecoration = true;
|
anim.IsDecoration = true;
|
||||||
anim.Play(info.Sequence);
|
anim.Play(info.Sequence);
|
||||||
rs.Add(new AnimationWithOffset(anim,
|
rs.Add(new AnimationWithOffset(anim,
|
||||||
|
|||||||
@@ -9,13 +9,16 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("Default trait for rendering sprite-based actors.")]
|
[Desc("Default trait for rendering sprite-based actors.")]
|
||||||
class WithSpriteBodyInfo : UpgradableTraitInfo, ITraitInfo, Requires<RenderSpritesInfo>
|
public class WithSpriteBodyInfo : UpgradableTraitInfo, ITraitInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo,
|
||||||
|
Requires<RenderSpritesInfo>
|
||||||
{
|
{
|
||||||
[Desc("Animation to play when the actor is created.")]
|
[Desc("Animation to play when the actor is created.")]
|
||||||
public readonly string StartSequence = null;
|
public readonly string StartSequence = null;
|
||||||
@@ -23,30 +26,54 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Animation to play when the actor is idle.")]
|
[Desc("Animation to play when the actor is idle.")]
|
||||||
public readonly string Sequence = "idle";
|
public readonly string Sequence = "idle";
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new WithSpriteBody(init, this); }
|
public virtual object Create(ActorInitializer init) { return new WithSpriteBody(init, this); }
|
||||||
}
|
|
||||||
|
|
||||||
class WithSpriteBody : UpgradableTrait<WithSpriteBodyInfo>, ISpriteBody
|
public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
|
||||||
readonly Animation body;
|
|
||||||
readonly WithSpriteBodyInfo info;
|
|
||||||
|
|
||||||
public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
|
|
||||||
: base(info)
|
|
||||||
{
|
{
|
||||||
this.info = info;
|
var anim = new Animation(init.World, image);
|
||||||
|
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||||
|
|
||||||
var rs = init.Self.Trait<RenderSprites>();
|
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
|
||||||
body = new Animation(init.Self.World, rs.GetImage(init.Self));
|
|
||||||
PlayCustomAnimation(init.Self, info.StartSequence, () => body.PlayRepeating(info.Sequence));
|
|
||||||
rs.Add(new AnimationWithOffset(body, null, () => IsTraitDisabled));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimation(Actor self, string newAnimation, Action after)
|
public virtual int QuantizedBodyFacings(ActorInfo ai, SequenceProvider sequenceProvider, string race)
|
||||||
{
|
{
|
||||||
body.PlayThen(newAnimation, () =>
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WithSpriteBody : UpgradableTrait<WithSpriteBodyInfo>, ISpriteBody
|
||||||
|
{
|
||||||
|
public readonly Animation DefaultAnimation;
|
||||||
|
|
||||||
|
public WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info)
|
||||||
|
: this(init, info, () => 0) { }
|
||||||
|
|
||||||
|
protected WithSpriteBody(ActorInitializer init, WithSpriteBodyInfo info, Func<int> baseFacing)
|
||||||
|
: base(info)
|
||||||
|
{
|
||||||
|
var rs = init.Self.Trait<RenderSprites>();
|
||||||
|
|
||||||
|
DefaultAnimation = new Animation(init.World, rs.GetImage(init.Self), baseFacing);
|
||||||
|
rs.Add(new AnimationWithOffset(DefaultAnimation, null, () => IsTraitDisabled));
|
||||||
|
|
||||||
|
if (Info.StartSequence != null)
|
||||||
|
PlayCustomAnimation(init.Self, Info.StartSequence,
|
||||||
|
() => DefaultAnimation.PlayRepeating(NormalizeSequence(init.Self, Info.Sequence)));
|
||||||
|
else
|
||||||
|
DefaultAnimation.PlayRepeating(NormalizeSequence(init.Self, Info.Sequence));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string NormalizeSequence(Actor self, string sequence)
|
||||||
|
{
|
||||||
|
return RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PlayCustomAnimation(Actor self, string name, Action after = null)
|
||||||
|
{
|
||||||
|
DefaultAnimation.PlayThen(NormalizeSequence(self, name), () =>
|
||||||
{
|
{
|
||||||
body.Play(info.Sequence);
|
DefaultAnimation.Play(NormalizeSequence(self, Info.Sequence));
|
||||||
if (after != null)
|
if (after != null)
|
||||||
after();
|
after();
|
||||||
});
|
});
|
||||||
@@ -54,14 +81,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void PlayCustomAnimationRepeating(Actor self, string name)
|
public void PlayCustomAnimationRepeating(Actor self, string name)
|
||||||
{
|
{
|
||||||
body.PlayThen(name, () => PlayCustomAnimationRepeating(self, name));
|
DefaultAnimation.PlayThen(name,
|
||||||
|
() => PlayCustomAnimationRepeating(self, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimationBackwards(Actor self, string name, Action after)
|
public void PlayCustomAnimationBackwards(Actor self, string name, Action after = null)
|
||||||
{
|
{
|
||||||
body.PlayBackwardsThen(name, () =>
|
DefaultAnimation.PlayBackwardsThen(NormalizeSequence(self, name), () =>
|
||||||
{
|
{
|
||||||
body.PlayRepeating(info.Sequence);
|
DefaultAnimation.PlayRepeating(NormalizeSequence(self, Info.Sequence));
|
||||||
if (after != null)
|
if (after != null)
|
||||||
after();
|
after();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<IBodyOrientationInfo>
|
class ThrowsParticleInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<IBodyOrientationInfo>
|
||||||
{
|
{
|
||||||
public readonly string Anim = null;
|
public readonly string Anim = null;
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
|
public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
|
||||||
{
|
{
|
||||||
var self = init.Self;
|
var self = init.Self;
|
||||||
var rs = self.Trait<RenderSimple>();
|
var rs = self.Trait<RenderSprites>();
|
||||||
var body = self.Trait<IBodyOrientation>();
|
var body = self.Trait<IBodyOrientation>();
|
||||||
|
|
||||||
// TODO: Carry orientation over from the parent instead of just facing
|
// TODO: Carry orientation over from the parent instead of just facing
|
||||||
|
|||||||
@@ -1016,6 +1016,37 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (engineVersion < 20150528)
|
||||||
|
{
|
||||||
|
// Note (stolen from WithInfantryBody upgrade rule):
|
||||||
|
// These rules are set up to do approximately the right thing for maps, but
|
||||||
|
// mods need additional manual tweaks. This is the best we can do without having
|
||||||
|
// much smarter rules parsing, because we currently can't reason about inherited traits.
|
||||||
|
if (depth == 0)
|
||||||
|
{
|
||||||
|
var childKeys = new[] { "Sequence" };
|
||||||
|
|
||||||
|
var ru = node.Value.Nodes.FirstOrDefault(n => n.Key == "RenderUnit");
|
||||||
|
if (ru != null)
|
||||||
|
{
|
||||||
|
ru.Key = "WithFacingSpriteBody";
|
||||||
|
node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", ""));
|
||||||
|
|
||||||
|
var rsNodes = ru.Value.Nodes.Where(n => !childKeys.Contains(n.Key)).ToList();
|
||||||
|
if (rsNodes.Any())
|
||||||
|
node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", new MiniYaml("", rsNodes)));
|
||||||
|
else
|
||||||
|
node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", ""));
|
||||||
|
|
||||||
|
ru.Value.Nodes.RemoveAll(n => rsNodes.Contains(n));
|
||||||
|
}
|
||||||
|
|
||||||
|
var rru = node.Value.Nodes.FirstOrDefault(n => n.Key == "-RenderUnit");
|
||||||
|
if (rru != null)
|
||||||
|
rru.Key = "-WithFacingSpriteBody";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user