RenderSprites.anims is finally private.

Followup to #3348.
This commit is contained in:
Paul Chote
2014-05-22 22:15:12 +12:00
parent 4aa7376994
commit 15f63fb5ea
18 changed files with 79 additions and 82 deletions

View File

@@ -30,40 +30,34 @@ namespace OpenRA.Traits
public class RenderSimple : RenderSprites, IAutoSelectionSize
{
RenderSimpleInfo Info;
public readonly Animation DefaultAnimation;
public RenderSimple(Actor self, Func<int> baseFacing)
: base(self)
{
Add("", new Animation(self.World, GetImage(self), baseFacing));
Info = self.Info.Traits.Get<RenderSimpleInfo>();
DefaultAnimation = new Animation(self.World, GetImage(self), baseFacing);
Add("", DefaultAnimation);
}
public RenderSimple(Actor self)
: this(self, MakeFacingFunc(self))
{
anim.PlayRepeating("idle");
self.Trait<IBodyOrientation>().SetAutodetectedFacings(anim.CurrentSequence.Facings);
DefaultAnimation.PlayRepeating("idle");
self.Trait<IBodyOrientation>().SetAutodetectedFacings(DefaultAnimation.CurrentSequence.Facings);
}
public int2 SelectionSize(Actor self)
{
return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc())
&& b.Animation.CurrentSequence != null)
.Select(a => (a.Animation.Image.size*Info.Scale).ToInt2())
.FirstOrDefault();
}
public int2 SelectionSize(Actor self) { return AutoSelectionSize(self); }
public string NormalizeSequence(Actor self, string baseSequence)
{
return NormalizeSequence(anim, self.GetDamageState(), baseSequence);
return NormalizeSequence(DefaultAnimation, self.GetDamageState(), baseSequence);
}
public void PlayCustomAnim(Actor self, string name)
{
if (anim.HasSequence(name))
anim.PlayThen(NormalizeSequence(self, name),
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
if (DefaultAnimation.HasSequence(name))
DefaultAnimation.PlayThen(NormalizeSequence(self, name),
() => DefaultAnimation.PlayRepeating(NormalizeSequence(self, "idle")));
}
}
}

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.FileFormats;
using OpenRA.Primitives;
@@ -33,7 +34,7 @@ namespace OpenRA.Traits
public class RenderSprites : IRender, ITick, INotifyOwnerChanged
{
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
public static Func<int> MakeFacingFunc(Actor self)
{
@@ -42,13 +43,6 @@ namespace OpenRA.Traits
return () => facing.Facing;
}
public Animation anim
{
get { return anims[""].Animation; }
protected set { anims[""] = new AnimationWithOffset(value,
anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].Paused, anims[""].ZOffset); }
}
RenderSpritesInfo Info;
string cachedImage = null;
bool initializePalette = true;
@@ -131,5 +125,14 @@ namespace OpenRA.Traits
return baseSequence;
}
// Required by RenderSimple
protected int2 AutoSelectionSize(Actor self)
{
return anims.Values.Where(b => (b.DisableFunc == null || !b.DisableFunc())
&& b.Animation.CurrentSequence != null)
.Select(a => (a.Animation.Image.size*Info.Scale).ToInt2())
.FirstOrDefault();
}
}
}