split unit smoke out into WithSmoke trait; remove duplication
This commit is contained in:
47
OpenRA.Mods.RA/Render/WithSmoke.cs
Normal file
47
OpenRA.Mods.RA/Render/WithSmoke.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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 OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithSmokeInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new WithSmoke(init.self); }
|
||||
}
|
||||
|
||||
public class WithSmoke : INotifyDamage
|
||||
{
|
||||
bool isSmoking;
|
||||
Animation anim;
|
||||
|
||||
public WithSmoke(Actor self)
|
||||
{
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
|
||||
anim = new Animation("smoke_m");
|
||||
rs.anims.Add("smoke", new RenderSimple.AnimationWithOffset(
|
||||
anim, null, () => !isSmoking));
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (isSmoking) return;
|
||||
if (e.DamageState < DamageState.Heavy) return;
|
||||
|
||||
isSmoking = true;
|
||||
anim.PlayThen( "idle",
|
||||
() => anim.PlayThen( "loop",
|
||||
() => anim.PlayBackwardsThen( "end",
|
||||
() => isSmoking = false ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user