Add dynamic position support to SpriteEffect
This was the last missing 'puzzle piece' to replace some remaining spcial-case effects.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Graphics;
|
||||
@@ -20,18 +21,29 @@ namespace OpenRA.Mods.Common.Effects
|
||||
readonly World world;
|
||||
readonly string palette;
|
||||
readonly Animation anim;
|
||||
readonly WPos pos;
|
||||
readonly Func<WPos> posFunc;
|
||||
readonly bool visibleThroughFog;
|
||||
readonly bool scaleSizeWithZoom;
|
||||
WPos pos;
|
||||
|
||||
// Facing is last on these overloads partially for backwards compatibility with previous main ctor revision
|
||||
// and partially because most effects don't need it.
|
||||
public SpriteEffect(WPos pos, World world, string image, string sequence, string palette, bool visibleThroughFog = false, bool scaleSizeWithZoom = false, int facing = 0)
|
||||
: this(() => pos, () => facing, world, image, sequence, palette, visibleThroughFog, scaleSizeWithZoom) { }
|
||||
|
||||
public SpriteEffect(Actor actor, World world, string image, string sequence, string palette, bool visibleThroughFog = false, bool scaleSizeWithZoom = false, int facing = 0)
|
||||
: this(() => actor.CenterPosition, () => facing, world, image, sequence, palette, visibleThroughFog, scaleSizeWithZoom) { }
|
||||
|
||||
public SpriteEffect(Func<WPos> posFunc, Func<int> facingFunc, World world, string image, string sequence, string palette,
|
||||
bool visibleThroughFog = false, bool scaleSizeWithZoom = false)
|
||||
{
|
||||
this.world = world;
|
||||
this.pos = pos;
|
||||
this.posFunc = posFunc;
|
||||
this.palette = palette;
|
||||
this.scaleSizeWithZoom = scaleSizeWithZoom;
|
||||
this.visibleThroughFog = visibleThroughFog;
|
||||
anim = new Animation(world, image, () => facing);
|
||||
pos = posFunc();
|
||||
anim = new Animation(world, image, facingFunc);
|
||||
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => { w.Remove(this); w.ScreenMap.Remove(this); }));
|
||||
world.ScreenMap.Add(this, pos, anim.Image);
|
||||
}
|
||||
@@ -39,6 +51,8 @@ namespace OpenRA.Mods.Common.Effects
|
||||
public void Tick(World world)
|
||||
{
|
||||
anim.Tick();
|
||||
|
||||
pos = posFunc();
|
||||
world.ScreenMap.Update(this, pos, anim.Image);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user