From 552bceb07cdf9348ae7d1da2d3222c46ce400503 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 8 May 2020 20:12:32 +0100 Subject: [PATCH] SpriteEffect facing -> WAngle. --- OpenRA.Mods.Common/Effects/SpriteEffect.cs | 16 ++++++++++------ OpenRA.Mods.Common/Projectiles/Bullet.cs | 4 ++-- OpenRA.Mods.Common/Projectiles/LaserZap.cs | 6 +++++- OpenRA.Mods.Common/Projectiles/Missile.cs | 5 +++-- .../Traits/SmokeTrailWhenDamaged.cs | 13 +++++-------- 5 files changed, 25 insertions(+), 19 deletions(-) diff --git a/OpenRA.Mods.Common/Effects/SpriteEffect.cs b/OpenRA.Mods.Common/Effects/SpriteEffect.cs index d8b215ed69..405c0a1ca3 100644 --- a/OpenRA.Mods.Common/Effects/SpriteEffect.cs +++ b/OpenRA.Mods.Common/Effects/SpriteEffect.cs @@ -31,14 +31,18 @@ namespace OpenRA.Mods.Common.Effects // Facing is last on these overloads partially for backwards compatibility with previous main ctor revision // and partially because most effects don't need it. The latter is also the reason for placement of 'delay'. public SpriteEffect(WPos pos, World world, string image, string sequence, string palette, - bool visibleThroughFog = false, int facing = 0, int delay = 0) - : this(() => pos, () => facing, world, image, sequence, palette, visibleThroughFog, delay) { } + bool visibleThroughFog = false, int delay = 0) + : this(() => pos, () => WAngle.Zero, world, image, sequence, palette, visibleThroughFog, delay) { } public SpriteEffect(Actor actor, World world, string image, string sequence, string palette, - bool visibleThroughFog = false, int facing = 0, int delay = 0) - : this(() => actor.CenterPosition, () => facing, world, image, sequence, palette, visibleThroughFog, delay) { } + bool visibleThroughFog = false, int delay = 0) + : this(() => actor.CenterPosition, () => WAngle.Zero, world, image, sequence, palette, visibleThroughFog, delay) { } - public SpriteEffect(Func posFunc, Func facingFunc, World world, string image, string sequence, string palette, + public SpriteEffect(WPos pos, WAngle facing, World world, string image, string sequence, string palette, + bool visibleThroughFog = false, int delay = 0) + : this(() => pos, () => facing, world, image, sequence, palette, visibleThroughFog, delay) { } + + public SpriteEffect(Func posFunc, Func facingFunc, World world, string image, string sequence, string palette, bool visibleThroughFog = false, int delay = 0) { this.world = world; @@ -48,7 +52,7 @@ namespace OpenRA.Mods.Common.Effects this.visibleThroughFog = visibleThroughFog; this.delay = delay; pos = posFunc(); - anim = new Animation(world, image, () => WAngle.FromFacing(facingFunc())); + anim = new Animation(world, image, facingFunc); } public void Tick(World world) diff --git a/OpenRA.Mods.Common/Projectiles/Bullet.cs b/OpenRA.Mods.Common/Projectiles/Bullet.cs index 10ad546c9b..6595587e90 100644 --- a/OpenRA.Mods.Common/Projectiles/Bullet.cs +++ b/OpenRA.Mods.Common/Projectiles/Bullet.cs @@ -212,8 +212,8 @@ namespace OpenRA.Mods.Common.Projectiles if (!string.IsNullOrEmpty(info.TrailImage) && --smokeTicks < 0) { var delayedPos = WPos.LerpQuadratic(source, target, angle, ticks - info.TrailDelay, length); - world.AddFrameEndTask(w => w.Add(new SpriteEffect(delayedPos, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom), - trailPalette, facing: GetEffectiveFacing().Facing))); + world.AddFrameEndTask(w => w.Add(new SpriteEffect(delayedPos, GetEffectiveFacing(), w, + info.TrailImage, info.TrailSequences.Random(world.SharedRandom), trailPalette))); smokeTicks = info.TrailInterval; } diff --git a/OpenRA.Mods.Common/Projectiles/LaserZap.cs b/OpenRA.Mods.Common/Projectiles/LaserZap.cs index 0087e69e78..3696a6efdd 100644 --- a/OpenRA.Mods.Common/Projectiles/LaserZap.cs +++ b/OpenRA.Mods.Common/Projectiles/LaserZap.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using OpenRA.GameRules; using OpenRA.Graphics; @@ -148,8 +149,11 @@ namespace OpenRA.Mods.Common.Projectiles source = args.CurrentSource(); if (hasLaunchEffect && ticks == 0) - world.AddFrameEndTask(w => w.Add(new SpriteEffect(args.CurrentSource, args.CurrentMuzzleFacing, world, + { + Func getMuzzleFacing = () => WAngle.FromFacing(args.CurrentMuzzleFacing()); + world.AddFrameEndTask(w => w.Add(new SpriteEffect(args.CurrentSource, getMuzzleFacing, world, info.LaunchEffectImage, info.LaunchEffectSequence, info.LaunchEffectPalette))); + } // Beam tracks target if (info.TrackTarget && args.GuidedTarget.IsValidFor(args.SourceActor)) diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index fbaf983d08..b88d16e77b 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; @@ -857,8 +858,8 @@ namespace OpenRA.Mods.Common.Projectiles // Create the sprite trail effect if (!string.IsNullOrEmpty(info.TrailImage) && --ticksToNextSmoke < 0 && (state != States.Freefall || info.TrailWhenDeactivated)) { - world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos - 3 * move / 2, w, info.TrailImage, info.TrailSequences.Random(world.SharedRandom), - trailPalette, facing: renderFacing.Facing))); + world.AddFrameEndTask(w => w.Add(new SpriteEffect(pos - 3 * move / 2, renderFacing, w, + info.TrailImage, info.TrailSequences.Random(world.SharedRandom), trailPalette))); ticksToNextSmoke = info.TrailInterval; } diff --git a/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs b/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs index 6613a237e8..b4508267ab 100644 --- a/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.Common/Traits/SmokeTrailWhenDamaged.cs @@ -9,7 +9,9 @@ */ #endregion +using System; using OpenRA.Mods.Common.Effects; +using OpenRA.Mods.Common.Traits.Render; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -37,19 +39,14 @@ namespace OpenRA.Mods.Common.Traits { readonly SmokeTrailWhenDamagedInfo info; readonly BodyOrientation body; - readonly int getFacing; + readonly Func getFacing; int ticks; public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info) { this.info = info; body = self.Trait(); - var facing = self.TraitOrDefault(); - - if (facing != null) - getFacing = facing.Facing; - else - getFacing = 0; + getFacing = RenderSprites.MakeFacingFunc(self); } void ITick.Tick(Actor self) @@ -61,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits { var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation)); var pos = position + body.LocalToWorld(offset); - self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, w, info.Sprite, info.Sequence, info.Palette, facing: getFacing))); + self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, getFacing(), w, info.Sprite, info.Sequence, info.Palette))); } ticks = info.Interval;