Add wrappers for RenderSprites anims dictionary.

This commit is contained in:
Paul Chote
2014-05-22 22:05:11 +12:00
parent 475aa93271
commit 4aa7376994
21 changed files with 36 additions and 26 deletions

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Traits
public RenderSimple(Actor self, Func<int> baseFacing)
: base(self)
{
anims.Add("", new Animation(self.World, GetImage(self), baseFacing));
Add("", new Animation(self.World, GetImage(self), baseFacing));
Info = self.Info.Traits.Get<RenderSimpleInfo>();
}

View File

@@ -105,6 +105,16 @@ namespace OpenRA.Traits
a.Animation.Tick();
}
public void Add(string key, AnimationWithOffset anim)
{
anims.Add(key, anim);
}
public void Remove(string key)
{
anims.Remove(key);
}
public static string NormalizeSequence(Animation anim, DamageState state, string baseSequence)
{
var states = new Pair<DamageState, string>[]

View File

@@ -37,19 +37,19 @@ namespace OpenRA.Mods.RA.Render
left = new Animation(self.World, name, () => turret.turretFacing);
left.Play("left");
anims.Add("left", new AnimationWithOffset(left, null, () => facing.Facing > 128, 0));
Add("left", new AnimationWithOffset(left, null, () => facing.Facing > 128, 0));
right = new Animation(self.World, name, () => turret.turretFacing);
right.Play("right");
anims.Add("right", new AnimationWithOffset(right, null, () => facing.Facing <= 128, 0));
Add("right", new AnimationWithOffset(right, null, () => facing.Facing <= 128, 0));
var leftWake = new Animation(self.World, name);
leftWake.Play("wake-left");
anims.Add("wake-left", new AnimationWithOffset(leftWake, null, () => facing.Facing > 128, -87));
Add("wake-left", new AnimationWithOffset(leftWake, null, () => facing.Facing > 128, -87));
var rightWake = new Animation(self.World, name);
rightWake.Play("wake-right");
anims.Add("wake-right", new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87));
Add("wake-right", new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87));
self.Trait<IBodyOrientation>().SetAutodetectedFacings(2);
}

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc
var rs = self.Trait<RenderSprites>();
var roof = new Animation(self.World, rs.GetImage(self));
roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop"));
rs.anims.Add("fire", new AnimationWithOffset(roof, null, null, 1024));
rs.Add("fire", new AnimationWithOffset(roof, null, null, 1024));
}
}
}

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc
var rs = self.Trait<RenderSprites>();
var roof = new Animation(self.World, rs.GetImage(self), () => self.Trait<IFacing>().Facing);
roof.Play("roof");
rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024));
rs.Add("roof", new AnimationWithOffset(roof, null, null, 1024));
}
}
}

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Render
overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence);
rs.anims.Add("crane_overlay_{0}".F(info.Sequence),
rs.Add("crane_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete));

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Render
{
var overlay = new Animation(init.world, rs.GetImage(init.self));
overlay.PlayThen(info.Sequence, () => buildComplete = false);
rs.anims.Add("make_overlay_{0}".F(info.Sequence),
rs.Add("make_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, null, () => !buildComplete));
}
}

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Render
overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence);
rs.anims.Add("delivery_overlay_{0}".F(info.Sequence),
rs.Add("delivery_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete));

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Render
overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence);
rs.anims.Add("docking_overlay_{0}".F(info.Sequence),
rs.Add("docking_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete));

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Render
overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(info.Sequence);
rs.anims.Add("production_overlay_{0}".F(info.Sequence),
rs.Add("production_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !IsProducing || !buildComplete));

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
var anim = new Animation(self.World, "fire", () => 0);
anim.IsDecoration = true;
anim.PlayRepeating(Info.Anim);
self.Trait<RenderSprites>().anims.Add("fire", anim);
self.Trait<RenderSprites>().Add("fire", anim);
}
public void Tick(Actor self)

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Render
// Additional 512 units move from center -> top of cell
var offset = FootprintUtils.CenterOffset(bi).Y + 512;
anims.Add("roof", new AnimationWithOffset(roof, null,
Add("roof", new AnimationWithOffset(roof, null,
() => !buildComplete, offset));
}
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA.Render
roof.PlayThen(NormalizeSequence(self, "build-top"), () => { isOpen = true; openExit = exit; });
}
public void Selling(Actor self) { anims.Remove("roof"); }
public void Selling(Actor self) { Remove("roof"); }
public void Sold(Actor self) { }
}
}

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Render
var images = info.XmasImages.Any() && DateTime.Today.Month == 12 ? info.XmasImages : info.Images;
anim = new Animation(self.World, images.Random(Game.CosmeticRandom));
anim.Play("idle");
rs.anims.Add("", anim);
rs.Add("", anim);
}
public void OnLanded()

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Render
anim = new Animation(self.World, rs.GetImage(self), RenderSimple.MakeFacingFunc(self));
anim.Play(info.Sequence);
rs.anims.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim,
rs.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !visible,
() => false,

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Render
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self));
overlay.PlayRepeating(info.Sequence);
rs.anims.Add("idle_overlay_{0}".F(info.Sequence),
rs.Add("idle_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete,

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Render
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(self.World, rs.GetImage(self));
overlay.Play(info.Sequence);
rs.anims.Add("repair_{0}".F(info.Sequence),
rs.Add("repair_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete,

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Render
? ((10 * anim.CurrentSequence.Length - 1) * playerResources.Ore) / (10 * playerResources.OreCapacity)
: 0);
rs.anims.Add("resources_{0}".F(info.Sequence), new AnimationWithOffset(
rs.Add("resources_{0}".F(info.Sequence), new AnimationWithOffset(
anim, null, () => !buildComplete, 1024));
}
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Render
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
}
public void Selling(Actor self) { rs.anims.Remove("resources_{0}".F(info.Sequence)); }
public void Selling(Actor self) { rs.Remove("resources_{0}".F(info.Sequence)); }
public void Sold(Actor self) { }
}
}

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Render
rotorAnim = new Animation(self.World, rs.GetImage(self));
rotorAnim.PlayRepeating(info.Sequence);
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
rs.Add(info.Id, new AnimationWithOffset(rotorAnim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
}

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Render
var rs = self.Trait<RenderSprites>();
anim = new Animation(self.World, "smoke_m");
rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking));
rs.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking));
}
public void Damaged(Actor self, AttackInfo e)

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Render
anim = new Animation(self.World, rs.GetImage(self), () => t.turretFacing);
anim.Play(info.Sequence);
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
rs.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
anim, () => TurretOffset(self), null, () => false, p => ZOffsetFromCenter(self, p, 1)));
// Restrict turret facings to match the sprite
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA.Render
return;
var sequence = ab.IsAttacking ? info.AimSequence : info.Sequence;
rs.anims["turret_{0}".F(info.Turret)].Animation.ReplaceAnim(sequence);
anim.ReplaceAnim(sequence);
}
static public int ZOffsetFromCenter(Actor self, WPos pos, int offset)

View File

@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA
var anim = new Animation(init.world, rs.GetImage(self), () => (int)facing);
anim.PlayRepeating(info.Anim);
rs.anims.Add(info.Anim, new AnimationWithOffset(anim, () => pos, null));
rs.Add(info.Anim, new AnimationWithOffset(anim, () => pos, null));
}
public void Tick(Actor self)