Decompose RenderInfantry into WithInfantryBody and RenderSprites.
This commit is contained in:
49
OpenRA.Mods.RA/Traits/Render/WithDisguisingInfantryBody.cs
Normal file
49
OpenRA.Mods.RA/Traits/Render/WithDisguisingInfantryBody.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Traits
|
||||
{
|
||||
class WithDisguisingInfantryBodyInfo : WithInfantryBodyInfo, Requires<DisguiseInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new WithDisguisingInfantryBody(init, this); }
|
||||
}
|
||||
|
||||
class WithDisguisingInfantryBody : WithInfantryBody
|
||||
{
|
||||
readonly WithDisguisingInfantryBodyInfo info;
|
||||
readonly Disguise disguise;
|
||||
readonly RenderSprites rs;
|
||||
string intendedSprite;
|
||||
|
||||
public WithDisguisingInfantryBody(ActorInitializer init, WithDisguisingInfantryBodyInfo info)
|
||||
: base(init, info)
|
||||
{
|
||||
this.info = info;
|
||||
rs = init.Self.Trait<RenderSprites>();
|
||||
disguise = init.Self.Trait<Disguise>();
|
||||
intendedSprite = disguise.AsSprite;
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
if (disguise.AsSprite != intendedSprite)
|
||||
{
|
||||
intendedSprite = disguise.AsSprite;
|
||||
DefaultAnimation.ChangeImage(intendedSprite ?? rs.GetImage(self), info.StandSequences.Random(Game.CosmeticRandom));
|
||||
rs.UpdatePalette();
|
||||
}
|
||||
|
||||
base.Tick(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user