From 21186c10b6a37b72402229ca0ac03444eea27dd3 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Wed, 15 Jul 2015 07:02:02 +0200 Subject: [PATCH] RenderBuildingTurreted -> WithTurretedSpriteBody --- OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs | 28 +++++++++++++------ OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 2 +- ...gTurreted.cs => WithTurretedSpriteBody.cs} | 15 +++++----- .../UtilityCommands/UpgradeRules.cs | 27 ++++++++++++++++++ mods/cnc/rules/structures.yaml | 9 ++++-- mods/ra/maps/allies-05a/map.yaml | 4 ++- mods/ra/rules/structures.yaml | 12 ++++++-- mods/ts/rules/gdi-support.yaml | 1 + 8 files changed, 75 insertions(+), 23 deletions(-) rename OpenRA.Mods.Common/Traits/Render/{RenderBuildingTurreted.cs => WithTurretedSpriteBody.cs} (75%) diff --git a/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs b/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs index 15db5c91ef..9299513e60 100644 --- a/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs +++ b/OpenRA.Mods.Cnc/Traits/AttackPopupTurreted.cs @@ -15,15 +15,25 @@ using OpenRA.Traits; namespace OpenRA.Mods.Cnc.Traits { [Desc("Actor's turret rises from the ground before attacking.")] - class AttackPopupTurretedInfo : AttackTurretedInfo, Requires, Requires + class AttackPopupTurretedInfo : AttackTurretedInfo, Requires, Requires { [Desc("How many game ticks should pass before closing the actor's turret.")] public int CloseDelay = 125; + public int DefaultFacing = 0; [Desc("The percentage of damage that is received while this actor is closed.")] public int ClosedDamageMultiplier = 50; + [Desc("Sequence to play when opening.")] + [SequenceReference] public string OpeningSequence = "opening"; + + [Desc("Sequence to play when closing.")] + [SequenceReference] public string ClosingSequence = "closing"; + + [Desc("Idle sequence to play when closed.")] + [SequenceReference] public string ClosedIdleSequence = "closed-idle"; + public override object Create(ActorInitializer init) { return new AttackPopupTurreted(init, this); } } @@ -32,11 +42,11 @@ namespace OpenRA.Mods.Cnc.Traits enum PopupState { Open, Rotating, Transitioning, Closed } readonly AttackPopupTurretedInfo info; - RenderBuilding rb; + readonly WithSpriteBody wsb; + readonly Turreted turret; int idleTicks = 0; PopupState state = PopupState.Open; - Turreted turret; bool skippedMakeAnimation; public AttackPopupTurreted(ActorInitializer init, AttackPopupTurretedInfo info) @@ -44,7 +54,7 @@ namespace OpenRA.Mods.Cnc.Traits { this.info = info; turret = turrets.FirstOrDefault(); - rb = init.Self.Trait(); + wsb = init.Self.Trait(); skippedMakeAnimation = init.Contains(); } @@ -60,10 +70,10 @@ namespace OpenRA.Mods.Cnc.Traits if (state == PopupState.Closed) { state = PopupState.Transitioning; - rb.PlayCustomAnimThen(self, "opening", () => + wsb.PlayCustomAnimation(self, info.OpeningSequence, () => { state = PopupState.Open; - rb.PlayCustomAnimRepeating(self, "idle"); + wsb.PlayCustomAnimationRepeating(self, wsb.Info.Sequence); }); return false; } @@ -81,10 +91,10 @@ namespace OpenRA.Mods.Cnc.Traits else if (state == PopupState.Rotating && turret.TurretFacing == info.DefaultFacing) { state = PopupState.Transitioning; - rb.PlayCustomAnimThen(self, "closing", () => + wsb.PlayCustomAnimation(self, info.ClosingSequence, () => { state = PopupState.Closed; - rb.PlayCustomAnimRepeating(self, "closed-idle"); + wsb.PlayCustomAnimationRepeating(self, info.ClosedIdleSequence); turret.DesiredFacing = null; }); } @@ -95,7 +105,7 @@ namespace OpenRA.Mods.Cnc.Traits if (skippedMakeAnimation) { state = PopupState.Closed; - rb.PlayCustomAnimRepeating(self, "closed-idle"); + wsb.PlayCustomAnimationRepeating(self, info.ClosedIdleSequence); turret.DesiredFacing = null; } } diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index b18376aa1e..ec22d6a22d 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -406,8 +406,8 @@ - + diff --git a/OpenRA.Mods.Common/Traits/Render/RenderBuildingTurreted.cs b/OpenRA.Mods.Common/Traits/Render/WithTurretedSpriteBody.cs similarity index 75% rename from OpenRA.Mods.Common/Traits/Render/RenderBuildingTurreted.cs rename to OpenRA.Mods.Common/Traits/Render/WithTurretedSpriteBody.cs index 413ee3f180..36e7327f67 100644 --- a/OpenRA.Mods.Common/Traits/Render/RenderBuildingTurreted.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTurretedSpriteBody.cs @@ -17,24 +17,25 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - class RenderBuildingTurretedInfo : RenderBuildingInfo, Requires + [Desc("This actor has turret art with facings baked into the sprite.")] + public class WithTurretedSpriteBodyInfo : WithSpriteBodyInfo, Requires, Requires { - public override object Create(ActorInitializer init) { return new RenderBuildingTurreted(init, this); } + public override object Create(ActorInitializer init) { return new WithTurretedSpriteBody(init, this); } public override IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) { - var t = init.Actor.Traits.WithInterface() - .FirstOrDefault(); + var t = init.Actor.Traits.WithInterface().FirstOrDefault(); + var wsb = init.Actor.Traits.WithInterface().FirstOrDefault(); // Show the correct turret facing var anim = new Animation(init.World, image, () => t.InitialFacing); - anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence)); + anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence)); yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale); } } - class RenderBuildingTurreted : RenderBuilding + public class WithTurretedSpriteBody : WithSpriteBody { readonly Turreted turreted; @@ -45,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits return () => turreted.TurretFacing; } - public RenderBuildingTurreted(ActorInitializer init, RenderBuildingInfo info) + public WithTurretedSpriteBody(ActorInitializer init, WithSpriteBodyInfo info) : base(init, info, MakeTurretFacingFunc(init.Self)) { turreted = init.Self.TraitsImplementing().FirstOrDefault(); diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 979287a349..7078102a48 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -1875,6 +1875,33 @@ namespace OpenRA.Mods.Common.UtilityCommands if (rrb != null) rrb.Key = "-WithSiloAnimation"; } + + // Replaced RenderBuildingTurreted with RenderSprites + WithTurretedSpriteBody (+AutoSelectionSize) + if (depth == 0) + { + var childKeysExcludeFromRS = new[] { "Sequence", "PauseOnLowPower" }; + + var rb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("RenderBuildingTurreted")); + if (rb != null) + { + rb.Key = "WithTurretedSpriteBody"; + + var rsNodes = rb.Value.Nodes.Where(n => !childKeysExcludeFromRS.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", "")); + + rb.Value.Nodes.RemoveAll(n => rsNodes.Contains(n)); + } + + var rrb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("-RenderBuildingTurreted")); + if (rrb != null) + rrb.Key = "-WithTurretedSpriteBody"; + } } UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index b8ef1febf4..d0e53b1f1d 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -654,7 +654,8 @@ GUN: Turreted: ROT: 12 InitialFacing: 50 - RenderBuildingTurreted: + RenderSprites: + WithTurretedSpriteBody: Armament: Weapon: TurretGun LocalOffset: 512,0,112 @@ -667,6 +668,7 @@ GUN: Range: 3 Power: Amount: -20 + -WithMakeAnimation: SAM: Inherits: ^Defense @@ -695,7 +697,9 @@ SAM: Turreted: ROT: 10 InitialFacing: 0 - RenderBuildingTurreted: + RenderSprites: + WithTurretedSpriteBody: + AutoSelectionSize: Armament: Weapon: SAMMissile MuzzleSequence: muzzle @@ -705,6 +709,7 @@ SAM: -RenderDetectionCircle: Power: Amount: -20 + -WithMakeAnimation: OBLI: Inherits: ^Defense diff --git a/mods/ra/maps/allies-05a/map.yaml b/mods/ra/maps/allies-05a/map.yaml index de13891713..2510f069a5 100644 --- a/mods/ra/maps/allies-05a/map.yaml +++ b/mods/ra/maps/allies-05a/map.yaml @@ -1729,8 +1729,9 @@ Rules: Turreted: ROT: 15 InitialFacing: 224 - RenderBuildingTurreted: + RenderSprites: Image: AGUN + WithTurretedSpriteBody: Armament: Weapon: MissionColt LocalOffset: 432,150,-30, 432,-150,-30 @@ -1738,6 +1739,7 @@ Rules: AutoTarget: -RenderBuilding: -Selectable: + -WithMakeAnimation: E1.Autotarget: Inherits: E1 Buildable: diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 46bdc3802c..e377c63bb3 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -451,7 +451,8 @@ AGUN: Turreted: ROT: 15 InitialFacing: 224 - RenderBuildingTurreted: + RenderSprites: + WithTurretedSpriteBody: Armament: Weapon: ZSU-23 LocalOffset: 432,150,-30, 432,-150,-30 @@ -465,6 +466,7 @@ AGUN: Amount: -50 DetectCloaked: Range: 6 + -WithMakeAnimation: DOME: Inherits: ^Building @@ -610,7 +612,8 @@ GUN: Turreted: ROT: 12 InitialFacing: 50 - RenderBuildingTurreted: + RenderSprites: + WithTurretedSpriteBody: Armament: Weapon: TurretGun LocalOffset: 512,0,112 @@ -622,6 +625,7 @@ GUN: Amount: -40 DetectCloaked: Range: 7 + -WithMakeAnimation: FTUR: Inherits: ^Defense @@ -686,7 +690,8 @@ SAM: Turreted: ROT: 30 InitialFacing: 0 - RenderBuildingTurreted: + RenderSprites: + WithTurretedSpriteBody: Armament: Weapon: Nike MuzzleSequence: muzzle @@ -699,6 +704,7 @@ SAM: Amount: -40 DetectCloaked: Range: 5 + -WithMakeAnimation: ATEK: Inherits: ^Building diff --git a/mods/ts/rules/gdi-support.yaml b/mods/ts/rules/gdi-support.yaml index 46e34401e5..188e373f2f 100644 --- a/mods/ts/rules/gdi-support.yaml +++ b/mods/ts/rules/gdi-support.yaml @@ -123,6 +123,7 @@ GACTWR: ProvidesPrerequisite@buildingname: SelectionDecorations: VisualBounds: 48, 48, 0, -12 + -WithMakeAnimation: GAVULC: Inherits: ^BuildingPlug