diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index f1549aaa4d..79cbc8933e 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -400,7 +400,6 @@ - diff --git a/OpenRA.Mods.Common/Traits/Render/RenderUnit.cs b/OpenRA.Mods.Common/Traits/Render/RenderUnit.cs deleted file mode 100644 index 832544bf63..0000000000 --- a/OpenRA.Mods.Common/Traits/Render/RenderUnit.cs +++ /dev/null @@ -1,50 +0,0 @@ -#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 System; -using OpenRA.Traits; - -namespace OpenRA.Mods.Common.Traits -{ - [Desc("Render trait for non-animated actors that have sprites facing into each direction.", - "Deprecated. This will soon be removed, use RenderSprites + WithFacingSpriteBody instead.")] - public class RenderUnitInfo : RenderSimpleInfo, Requires - { - public override object Create(ActorInitializer init) { return new RenderUnit(init, this); } - } - - public class RenderUnit : RenderSimple, ISpriteBody - { - readonly RenderUnitInfo info; - - public RenderUnit(ActorInitializer init, RenderUnitInfo info) - : base(init, info) - { - this.info = info; - } - - public void PlayCustomAnimation(Actor self, string newAnimation, Action after) - { - DefaultAnimation.PlayThen(newAnimation, () => { DefaultAnimation.Play(info.Sequence); if (after != null) after(); }); - } - - public void PlayCustomAnimationRepeating(Actor self, string name) - { - DefaultAnimation.PlayThen(name, - () => PlayCustomAnimationRepeating(self, name)); - } - - public void PlayCustomAnimationBackwards(Actor self, string name, Action after) - { - DefaultAnimation.PlayBackwardsThen(name, - () => { DefaultAnimation.PlayRepeating(info.Sequence); if (after != null) after(); }); - } - } -} diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 3e568972eb..ca3627dc08 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -1317,6 +1317,38 @@ namespace OpenRA.Mods.Common.UtilityCommands if (rrh != null) rrh.Key = "-WithHarvestAnimation"; } + + // Replace RenderUnit with RenderSprites + WithFacingSpriteBody + AutoSelectionSize. + // Normally this should have been removed by previous upgrade rules, but let's run this again + // to make sure to get rid of potential left-over cases like D2k sandworms and harvesters. + if (depth == 0) + { + var childKeys = new[] { "Sequence" }; + + var ru = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("RenderUnit")); + if (ru != null) + { + ru.Key = "WithFacingSpriteBody"; + + var rsNodes = ru.Value.Nodes.Where(n => !childKeys.Contains(n.Key)).ToList(); + + if (rsNodes.Any()) + node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", new MiniYaml("", rsNodes))); + else + node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", "")); + + node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", "")); + + ru.Value.Nodes.RemoveAll(n => rsNodes.Contains(n)); + + Console.WriteLine("RenderUnit has now been removed from code."); + Console.WriteLine("Use RenderSprites + WithFacingSpriteBody (+ AutoSelectionSize, if necessary) instead."); + } + + var rru = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("-RenderUnit")); + if (rru != null) + rru.Key = "-WithFacingSpriteBody"; + } } UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); diff --git a/OpenRA.Mods.D2k/Activities/SwallowActor.cs b/OpenRA.Mods.D2k/Activities/SwallowActor.cs index 0701fff2e6..c92cb98503 100644 --- a/OpenRA.Mods.D2k/Activities/SwallowActor.cs +++ b/OpenRA.Mods.D2k/Activities/SwallowActor.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.D2k.Activities readonly Target target; readonly Sandworm sandworm; readonly WeaponInfo weapon; - readonly RenderUnit renderUnit; + readonly WithSpriteBody withSpriteBody; readonly RadarPings radarPings; readonly AttackSwallow swallow; readonly IPositionable positionable; @@ -44,11 +44,11 @@ namespace OpenRA.Mods.D2k.Activities sandworm = self.Trait(); positionable = self.Trait(); swallow = self.Trait(); - renderUnit = self.Trait(); + withSpriteBody = self.Trait(); radarPings = self.World.WorldActor.TraitOrDefault(); countdown = swallow.Info.AttackTime; - renderUnit.DefaultAnimation.ReplaceAnim("burrowed"); + withSpriteBody.DefaultAnimation.ReplaceAnim(sandworm.Info.BurrowedSequence); stance = AttackState.Burrowed; location = target.Actor.Location; } @@ -104,7 +104,7 @@ namespace OpenRA.Mods.D2k.Activities // List because IEnumerable gets evaluated too late. void PlayAttack(Actor self, WPos attackPosition, List affectedPlayers) { - renderUnit.PlayCustomAnim(self, "mouth"); + withSpriteBody.PlayCustomAnimation(self, sandworm.Info.MouthSequence); Sound.Play(swallow.Info.WormAttackSound, self.CenterPosition); Game.RunAfterDelay(1000, () => @@ -142,7 +142,7 @@ namespace OpenRA.Mods.D2k.Activities self.World.AddFrameEndTask(w => self.Kill(self)); } else - renderUnit.DefaultAnimation.ReplaceAnim("idle"); + withSpriteBody.DefaultAnimation.ReplaceAnim(sandworm.Info.IdleSequence); return NextActivity; } @@ -156,7 +156,7 @@ namespace OpenRA.Mods.D2k.Activities if (!WormAttack(self)) { - renderUnit.DefaultAnimation.ReplaceAnim("idle"); + withSpriteBody.DefaultAnimation.ReplaceAnim(sandworm.Info.IdleSequence); return NextActivity; } diff --git a/OpenRA.Mods.D2k/Traits/Sandworm.cs b/OpenRA.Mods.D2k/Traits/Sandworm.cs index 3a88e181ee..8281a11d05 100644 --- a/OpenRA.Mods.D2k/Traits/Sandworm.cs +++ b/OpenRA.Mods.D2k/Traits/Sandworm.cs @@ -15,7 +15,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.D2k.Traits { - class SandwormInfo : WandersInfo, Requires, Requires, Requires + class SandwormInfo : WandersInfo, Requires, Requires, Requires { [Desc("Time between rescanning for targets (in ticks).")] public readonly int TargetRescanInterval = 32; @@ -30,7 +30,13 @@ namespace OpenRA.Mods.D2k.Traits public readonly int ChanceToDisappear = 80; [Desc("Name of the sequence that is used when the actor is idle or moving (not attacking).")] - public readonly string IdleSequence = "idle"; + [SequenceReference] public readonly string IdleSequence = "idle"; + + [Desc("Name of the sequence that is used when the actor is attacking.")] + [SequenceReference] public readonly string MouthSequence = "mouth"; + + [Desc("Name of the sequence that is used when the actor is burrowed.")] + [SequenceReference] public readonly string BurrowedSequence = "burrowed"; public override object Create(ActorInitializer init) { return new Sandworm(init.Self, this); } } @@ -41,7 +47,7 @@ namespace OpenRA.Mods.D2k.Traits readonly WormManager manager; readonly Lazy mobile; - readonly Lazy renderUnit; + readonly Lazy withSpriteBody; readonly Lazy attackTrait; public bool IsMovingTowardTarget { get; private set; } @@ -55,15 +61,15 @@ namespace OpenRA.Mods.D2k.Traits { Info = info; mobile = Exts.Lazy(self.Trait); - renderUnit = Exts.Lazy(self.Trait); + withSpriteBody = Exts.Lazy(self.Trait); attackTrait = Exts.Lazy(self.Trait); manager = self.World.WorldActor.Trait(); } public override void OnBecomingIdle(Actor self) { - if (renderUnit.Value.DefaultAnimation.CurrentSequence.Name != Info.IdleSequence) - renderUnit.Value.DefaultAnimation.PlayRepeating("idle"); + if (withSpriteBody.Value.DefaultAnimation.CurrentSequence.Name != Info.IdleSequence) + withSpriteBody.Value.DefaultAnimation.PlayRepeating(Info.IdleSequence); base.OnBecomingIdle(self); } diff --git a/mods/d2k/rules/arrakis.yaml b/mods/d2k/rules/arrakis.yaml index 785394ab28..9f1c0d82d8 100644 --- a/mods/d2k/rules/arrakis.yaml +++ b/mods/d2k/rules/arrakis.yaml @@ -33,7 +33,7 @@ sandworm: Spice: 100 TargetableUnit: TargetTypes: Ground - RenderUnit: + WithFacingSpriteBody: WithAttackOverlay: Sequence: sand BodyOrientation: @@ -51,6 +51,8 @@ sandworm: AnnounceOnSeen: Notification: WormSign PingRadar: True + RenderSprites: + AutoSelectionSize: sietch: Inherits: ^Building diff --git a/mods/d2k/rules/starport.yaml b/mods/d2k/rules/starport.yaml index 7e9bf3c026..9ae4bc671a 100644 --- a/mods/d2k/rules/starport.yaml +++ b/mods/d2k/rules/starport.yaml @@ -14,7 +14,7 @@ harvester.starport: Queue: Starport Valued: Cost: 1500 - RenderUnit: + RenderSprites: Image: harvester trike.starport: diff --git a/mods/d2k/rules/vehicles.yaml b/mods/d2k/rules/vehicles.yaml index 31773a4140..fccc46aed7 100644 --- a/mods/d2k/rules/vehicles.yaml +++ b/mods/d2k/rules/vehicles.yaml @@ -77,10 +77,6 @@ harvester: EmptyWeapon: UnitExplodeScale LeavesHusk: HuskActor: Harvester.Husk - RenderUnit: - -RenderSprites: - -WithFacingSpriteBody: - -AutoSelectionSize: WithHarvestOverlay: Palette: effect50alpha WithDockingAnimation: