From 4aa7376994e4323e2ef5c4c0b5ed2d6370ff1e86 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 22 May 2014 22:05:11 +1200 Subject: [PATCH] Add wrappers for RenderSprites anims dictionary. --- OpenRA.Game/Traits/Render/RenderSimple.cs | 2 +- OpenRA.Game/Traits/Render/RenderSprites.cs | 10 ++++++++++ OpenRA.Mods.Cnc/RenderGunboat.cs | 8 ++++---- OpenRA.Mods.Cnc/WithFire.cs | 2 +- OpenRA.Mods.Cnc/WithRoof.cs | 2 +- .../Render/WithBuildingPlacedOverlayInfo.cs | 2 +- OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs | 2 +- OpenRA.Mods.D2k/Render/WithDeliveryOverlay.cs | 2 +- OpenRA.Mods.D2k/Render/WithDockingOverlay.cs | 2 +- OpenRA.Mods.D2k/Render/WithProductionOverlay.cs | 2 +- OpenRA.Mods.RA/Burns.cs | 2 +- OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs | 4 ++-- OpenRA.Mods.RA/Render/WithCrateBody.cs | 2 +- OpenRA.Mods.RA/Render/WithHarvestAnimation.cs | 2 +- OpenRA.Mods.RA/Render/WithIdleOverlay.cs | 2 +- OpenRA.Mods.RA/Render/WithRepairOverlay.cs | 2 +- OpenRA.Mods.RA/Render/WithResources.cs | 4 ++-- OpenRA.Mods.RA/Render/WithRotor.cs | 2 +- OpenRA.Mods.RA/Render/WithSmoke.cs | 2 +- OpenRA.Mods.RA/Render/WithTurret.cs | 4 ++-- OpenRA.Mods.RA/ThrowsParticle.cs | 2 +- 21 files changed, 36 insertions(+), 26 deletions(-) diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 03f38ac302..81761d9c66 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -35,7 +35,7 @@ namespace OpenRA.Traits public RenderSimple(Actor self, Func 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(); } diff --git a/OpenRA.Game/Traits/Render/RenderSprites.cs b/OpenRA.Game/Traits/Render/RenderSprites.cs index ff5a2fa182..50fd4479e5 100755 --- a/OpenRA.Game/Traits/Render/RenderSprites.cs +++ b/OpenRA.Game/Traits/Render/RenderSprites.cs @@ -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[] diff --git a/OpenRA.Mods.Cnc/RenderGunboat.cs b/OpenRA.Mods.Cnc/RenderGunboat.cs index be6b082ced..3a75281cc1 100644 --- a/OpenRA.Mods.Cnc/RenderGunboat.cs +++ b/OpenRA.Mods.Cnc/RenderGunboat.cs @@ -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().SetAutodetectedFacings(2); } diff --git a/OpenRA.Mods.Cnc/WithFire.cs b/OpenRA.Mods.Cnc/WithFire.cs index ec5bc55c16..7ad29e7f27 100644 --- a/OpenRA.Mods.Cnc/WithFire.cs +++ b/OpenRA.Mods.Cnc/WithFire.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc var rs = self.Trait(); 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)); } } } diff --git a/OpenRA.Mods.Cnc/WithRoof.cs b/OpenRA.Mods.Cnc/WithRoof.cs index 0cfb42c047..cf3497c2ef 100644 --- a/OpenRA.Mods.Cnc/WithRoof.cs +++ b/OpenRA.Mods.Cnc/WithRoof.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc var rs = self.Trait(); var roof = new Animation(self.World, rs.GetImage(self), () => self.Trait().Facing); roof.Play("roof"); - rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024)); + rs.Add("roof", new AnimationWithOffset(roof, null, null, 1024)); } } } diff --git a/OpenRA.Mods.D2k/Render/WithBuildingPlacedOverlayInfo.cs b/OpenRA.Mods.D2k/Render/WithBuildingPlacedOverlayInfo.cs index ff26b3e5a8..68d02cd8c5 100644 --- a/OpenRA.Mods.D2k/Render/WithBuildingPlacedOverlayInfo.cs +++ b/OpenRA.Mods.D2k/Render/WithBuildingPlacedOverlayInfo.cs @@ -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)); diff --git a/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs b/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs index 089290adab..6deb6ace9b 100644 --- a/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs +++ b/OpenRA.Mods.D2k/Render/WithCrumbleOverlay.cs @@ -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)); } } diff --git a/OpenRA.Mods.D2k/Render/WithDeliveryOverlay.cs b/OpenRA.Mods.D2k/Render/WithDeliveryOverlay.cs index 6048990a0a..247196be86 100644 --- a/OpenRA.Mods.D2k/Render/WithDeliveryOverlay.cs +++ b/OpenRA.Mods.D2k/Render/WithDeliveryOverlay.cs @@ -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)); diff --git a/OpenRA.Mods.D2k/Render/WithDockingOverlay.cs b/OpenRA.Mods.D2k/Render/WithDockingOverlay.cs index cbe0182420..9651f6d02f 100644 --- a/OpenRA.Mods.D2k/Render/WithDockingOverlay.cs +++ b/OpenRA.Mods.D2k/Render/WithDockingOverlay.cs @@ -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)); diff --git a/OpenRA.Mods.D2k/Render/WithProductionOverlay.cs b/OpenRA.Mods.D2k/Render/WithProductionOverlay.cs index c9847baec6..081a407538 100644 --- a/OpenRA.Mods.D2k/Render/WithProductionOverlay.cs +++ b/OpenRA.Mods.D2k/Render/WithProductionOverlay.cs @@ -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)); diff --git a/OpenRA.Mods.RA/Burns.cs b/OpenRA.Mods.RA/Burns.cs index e6347ab581..967dc0bc26 100644 --- a/OpenRA.Mods.RA/Burns.cs +++ b/OpenRA.Mods.RA/Burns.cs @@ -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().anims.Add("fire", anim); + self.Trait().Add("fire", anim); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index 42b54fe82b..a3b25941b0 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -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) { } } } diff --git a/OpenRA.Mods.RA/Render/WithCrateBody.cs b/OpenRA.Mods.RA/Render/WithCrateBody.cs index 10703fb2d4..d16004de80 100755 --- a/OpenRA.Mods.RA/Render/WithCrateBody.cs +++ b/OpenRA.Mods.RA/Render/WithCrateBody.cs @@ -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() diff --git a/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs b/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs index ca6edd92cc..a42797a2dd 100644 --- a/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs +++ b/OpenRA.Mods.RA/Render/WithHarvestAnimation.cs @@ -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, diff --git a/OpenRA.Mods.RA/Render/WithIdleOverlay.cs b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs index 47a3313028..0c2ad17ac5 100644 --- a/OpenRA.Mods.RA/Render/WithIdleOverlay.cs +++ b/OpenRA.Mods.RA/Render/WithIdleOverlay.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Render buildComplete = !self.HasTrait(); // 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, diff --git a/OpenRA.Mods.RA/Render/WithRepairOverlay.cs b/OpenRA.Mods.RA/Render/WithRepairOverlay.cs index 094c35b7ad..f44c23bc4d 100644 --- a/OpenRA.Mods.RA/Render/WithRepairOverlay.cs +++ b/OpenRA.Mods.RA/Render/WithRepairOverlay.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Render buildComplete = !self.HasTrait(); // 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, diff --git a/OpenRA.Mods.RA/Render/WithResources.cs b/OpenRA.Mods.RA/Render/WithResources.cs index bc202da05c..9c3feeff3c 100755 --- a/OpenRA.Mods.RA/Render/WithResources.cs +++ b/OpenRA.Mods.RA/Render/WithResources.cs @@ -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(); } - 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) { } } } diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index 764df91589..5b0e14c732 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -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))); } diff --git a/OpenRA.Mods.RA/Render/WithSmoke.cs b/OpenRA.Mods.RA/Render/WithSmoke.cs index 0b82ed3da3..4c75da50ce 100644 --- a/OpenRA.Mods.RA/Render/WithSmoke.cs +++ b/OpenRA.Mods.RA/Render/WithSmoke.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Render var rs = self.Trait(); 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) diff --git a/OpenRA.Mods.RA/Render/WithTurret.cs b/OpenRA.Mods.RA/Render/WithTurret.cs index 7ca2be9efa..b3474ef3e8 100755 --- a/OpenRA.Mods.RA/Render/WithTurret.cs +++ b/OpenRA.Mods.RA/Render/WithTurret.cs @@ -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) diff --git a/OpenRA.Mods.RA/ThrowsParticle.cs b/OpenRA.Mods.RA/ThrowsParticle.cs index b472b4daa0..dd0d065dc8 100644 --- a/OpenRA.Mods.RA/ThrowsParticle.cs +++ b/OpenRA.Mods.RA/ThrowsParticle.cs @@ -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)