Refactor building power-down and Invulnerable effect. Introduces render bugs on state change (effects appearing/dissapearing a frame too late)

This commit is contained in:
Paul Chote
2010-01-08 01:26:30 +13:00
parent 42cfa7ec59
commit f3fd108a23
8 changed files with 87 additions and 45 deletions

View File

@@ -0,0 +1,36 @@
using System.Collections.Generic;
using OpenRa.Game.Graphics;
using OpenRa.Game.Traits;
namespace OpenRa.Game.Effects
{
class PowerDownIndicator : IEffect
{
Actor a;
Building b;
Animation anim = new Animation("powerdown");
public PowerDownIndicator(Actor a)
{
this.a = a;
this.b = a.traits.Get<Building>();
anim.PlayRepeating("disabled");
}
public void Tick()
{
if (!b.Disabled || a.IsDead)
Game.world.AddFrameEndTask(w => w.Remove(this));
}
public IEnumerable<Renderable> Render()
{
foreach (var r in a.Render())
yield return r.WithPalette(PaletteType.Disabled);
if (b.ManuallyDisabled)
yield return new Renderable(anim.Image,
a.CenterLocation - .5f * anim.Image.size, PaletteType.Chrome);
}
}
}