diff --git a/OpenRA.Mods.TS/Traits/Render/WithVoxelWalkerBody.cs b/OpenRA.Mods.TS/Traits/Render/WithVoxelWalkerBody.cs index 45e6bacf21..959039e2d9 100644 --- a/OpenRA.Mods.TS/Traits/Render/WithVoxelWalkerBody.cs +++ b/OpenRA.Mods.TS/Traits/Render/WithVoxelWalkerBody.cs @@ -10,21 +10,37 @@ #endregion using System; +using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; +using OpenRA.Mods.Common; +using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits.Render; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.TS.Traits.Render { - public class WithVoxelWalkerBodyInfo : ITraitInfo, Requires, Requires, Requires + public class WithVoxelWalkerBodyInfo : ITraitInfo, IRenderActorPreviewVoxelsInfo, Requires, Requires, Requires { public readonly int TickRate = 5; public object Create(ActorInitializer init) { return new WithVoxelWalkerBody(init.Self, this); } + + public IEnumerable RenderPreviewVoxels( + ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, Func orientation, int facings, PaletteReference p) + { + var voxel = VoxelProvider.GetVoxel(image, "idle"); + var body = init.Actor.TraitInfo(); + var frame = init.Contains() ? init.Get() : 0; + + yield return new VoxelAnimation(voxel, () => WVec.Zero, + () => new[] { body.QuantizeOrientation(orientation(), facings) }, + () => false, () => frame); + } } - public class WithVoxelWalkerBody : IAutoSelectionSize, ITick + public class WithVoxelWalkerBody : IAutoSelectionSize, ITick, IActorPreviewInitModifier { WithVoxelWalkerBodyInfo info; IMove movement; @@ -69,5 +85,18 @@ namespace OpenRA.Mods.TS.Traits.Render if (++frame == frames) frame = 0; } + + void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits) + { + inits.Add(new BodyAnimationFrameInit(frame)); + } + } + + public class BodyAnimationFrameInit : IActorInit + { + [FieldFromYamlKey] readonly uint value = 0; + public BodyAnimationFrameInit() { } + public BodyAnimationFrameInit(uint init) { value = init; } + public uint Value(World world) { return value; } } }