From e4738ce7229bd00f4ec5f09cff4a3d793e3de135 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 28 May 2018 21:43:53 +0200 Subject: [PATCH] Update rule for AimAnimation splits and ReloadPrefix removal --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 2 +- .../UpdateRules/Rules/SplitAimAnimations.cs | 185 ++++++++++++++++++ .../Rules/SplitTurretAimAnimation.cs | 91 --------- OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 2 +- 4 files changed, 187 insertions(+), 93 deletions(-) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/SplitAimAnimations.cs delete mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/SplitTurretAimAnimation.cs diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 172a2d3ffc..6140867220 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -872,7 +872,7 @@ - + diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/SplitAimAnimations.cs b/OpenRA.Mods.Common/UpdateRules/Rules/SplitAimAnimations.cs new file mode 100644 index 0000000000..42b78467d2 --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/SplitAimAnimations.cs @@ -0,0 +1,185 @@ +#region Copyright & License Information +/* + * Copyright 2007-2018 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class SplitAimAnimations : UpdateRule + { + public override string Name { get { return "Introduce WithAimAnimation and WithTurretAimAnimation traits"; } } + public override string Description + { + get + { + return "WithAttackAnimation.AimSequence, WithTurretAttackAnimation.AimSequence\n" + + "as well as WithSpriteTurret.AimSequence have been split to new With*AimAnimation traits.\n" + + "Furthermore, ReloadPrefixes have been removed in favor of condition-based solutions."; + } + } + + readonly List> aimAnimLocations = new List>(); + readonly List> reloadPrefixLocations = new List>(); + + public override IEnumerable AfterUpdate(ModData modData) + { + var message1 = "AimSequences have been split to With*AimAnimation.\n" + + "The following actors have been updated and might need manual adjustments:\n" + + UpdateUtils.FormatMessageList(aimAnimLocations.Select(n => n.Item1 + " (" + n.Item2 + ")")); + + if (aimAnimLocations.Any()) + yield return message1; + + aimAnimLocations.Clear(); + + var message2 = "ReloadPrefixes have been removed.\n" + + "Instead, grant a condition on reloading via Armament.ReloadingCondition to enable\n" + + "an alternate sprite body (with reloading sequences) on the following actors:\n" + + UpdateUtils.FormatMessageList(reloadPrefixLocations.Select(n => n.Item1 + " (" + n.Item2 + ")")); + + if (reloadPrefixLocations.Any()) + yield return message2; + + reloadPrefixLocations.Clear(); + } + + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) + { + var turretAttack = actorNode.LastChildMatching("WithTurretAttackAnimation"); + if (turretAttack != null) + { + var attackSequence = turretAttack.LastChildMatching("AttackSequence"); + var aimSequence = turretAttack.LastChildMatching("AimSequence"); + var reloadPrefix = turretAttack.LastChildMatching("ReloadPrefix"); + + if (aimSequence != null) + aimAnimLocations.Add(Tuple.Create(actorNode.Key, actorNode.Location.Filename)); + + if (reloadPrefix != null) + reloadPrefixLocations.Add(Tuple.Create(actorNode.Key, actorNode.Location.Filename)); + + // If only AttackSequence is not null, just rename AttackSequence to Sequence. + // If only the prefix isn't null (extremely unlikely, but you never know), just rename the trait. + // If AttackSequence is null but AimSequence isn't, rename the trait and property. + // If both aren't null, split/copy everything relevant to the new WithTurretAimAnimation. + // If both are null (extremely unlikely), do nothing. + if (attackSequence != null && aimSequence == null) + attackSequence.RenameKeyPreservingSuffix("Sequence"); + else if (attackSequence == null && aimSequence == null && reloadPrefix != null) + { + turretAttack.RemoveNode(reloadPrefix); + turretAttack.RenameKeyPreservingSuffix("WithTurretAimAnimation"); + } + else if (attackSequence == null && aimSequence != null) + { + turretAttack.RenameKeyPreservingSuffix("WithTurretAimAnimation"); + aimSequence.RenameKeyPreservingSuffix("Sequence"); + if (reloadPrefix != null) + turretAttack.RemoveNode(reloadPrefix); + } + else if (attackSequence != null && aimSequence != null) + { + var turretAim = new MiniYamlNode("WithTurretAimAnimation", ""); + aimSequence.RenameKeyPreservingSuffix("Sequence"); + turretAim.AddNode(aimSequence); + turretAttack.RemoveNode(aimSequence); + + var turret = turretAttack.LastChildMatching("Turret"); + var armament = turretAttack.LastChildMatching("Armament"); + if (reloadPrefix != null) + turretAttack.RemoveNode(reloadPrefix); + + if (turret != null) + turretAim.AddNode(turret); + if (armament != null) + turretAim.AddNode(armament); + + attackSequence.RenameKeyPreservingSuffix("Sequence"); + actorNode.AddNode(turretAim); + } + } + + var spriteTurret = actorNode.LastChildMatching("WithSpriteTurret"); + if (spriteTurret != null) + { + var aimSequence = spriteTurret.LastChildMatching("AimSequence"); + if (aimSequence != null) + { + aimAnimLocations.Add(Tuple.Create(actorNode.Key, actorNode.Location.Filename)); + + var aimAnim = new MiniYamlNode("WithTurretAimAnimation", ""); + aimSequence.RenameKeyPreservingSuffix("Sequence"); + aimAnim.AddNode(aimSequence); + spriteTurret.RemoveNode(aimSequence); + actorNode.AddNode(aimAnim); + } + } + + var attackAnim = actorNode.LastChildMatching("WithAttackAnimation"); + if (attackAnim != null) + { + var attackSequence = attackAnim.LastChildMatching("AttackSequence"); + var aimSequence = attackAnim.LastChildMatching("AimSequence"); + var reloadPrefix = attackAnim.LastChildMatching("ReloadPrefix"); + + if (aimSequence != null) + aimAnimLocations.Add(Tuple.Create(actorNode.Key, actorNode.Location.Filename)); + + if (reloadPrefix != null) + reloadPrefixLocations.Add(Tuple.Create(actorNode.Key, actorNode.Location.Filename)); + + // If only AttackSequence is not null, just rename AttackSequence to Sequence. + // If only the prefix isn't null (extremely unlikely, but you never know), just rename the trait. + // If AttackSequence is null but AimSequence isn't, rename the trait and property. + // If both sequences aren't null, split/copy everything relevant to the new WithAimAnimation. + // If both sequences and the prefix are null (extremely unlikely), do nothing. + if (attackSequence != null && aimSequence == null && reloadPrefix == null) + attackSequence.RenameKeyPreservingSuffix("Sequence"); + else if (attackSequence == null && aimSequence == null && reloadPrefix != null) + { + attackAnim.RemoveNode(reloadPrefix); + attackAnim.RenameKeyPreservingSuffix("WithAimAnimation"); + } + else if (attackSequence == null && aimSequence != null) + { + attackAnim.RenameKeyPreservingSuffix("WithAimAnimation"); + aimSequence.RenameKeyPreservingSuffix("Sequence"); + if (reloadPrefix != null) + attackAnim.RemoveNode(reloadPrefix); + } + else if (attackSequence != null && aimSequence != null) + { + var aimAnim = new MiniYamlNode("WithAimAnimation", ""); + aimSequence.RenameKeyPreservingSuffix("Sequence"); + aimAnim.AddNode(aimSequence); + attackAnim.RemoveNode(aimSequence); + + var body = attackAnim.LastChildMatching("Body"); + var armament = attackAnim.LastChildMatching("Armament"); + if (reloadPrefix != null) + attackAnim.RemoveNode(reloadPrefix); + + if (body != null) + aimAnim.AddNode(body); + if (armament != null) + aimAnim.AddNode(armament); + + attackSequence.RenameKeyPreservingSuffix("Sequence"); + actorNode.AddNode(aimAnim); + } + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/SplitTurretAimAnimation.cs b/OpenRA.Mods.Common/UpdateRules/Rules/SplitTurretAimAnimation.cs deleted file mode 100644 index 323efed737..0000000000 --- a/OpenRA.Mods.Common/UpdateRules/Rules/SplitTurretAimAnimation.cs +++ /dev/null @@ -1,91 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2018 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, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -using System.Collections.Generic; -using System.Linq; - -namespace OpenRA.Mods.Common.UpdateRules.Rules -{ - public class SplitTurretAimAnimation : UpdateRule - { - public override string Name { get { return "Introduce WithTurretAimAnimation trait"; } } - public override string Description - { - get - { - return "WithSpriteTurret.AimSequence and WithTurretAttackAnimation.AimSequence\n" + - "have been split into a new WithTurretAimAnimation trait."; - } - } - - public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) - { - var turretAttack = actorNode.LastChildMatching("WithTurretAttackAnimation"); - if (turretAttack != null) - { - var attackSequence = turretAttack.LastChildMatching("AttackSequence"); - var aimSequence = turretAttack.LastChildMatching("AimSequence"); - - // If only AimSequence is null, just rename AttackSequence to Sequence (ReloadPrefix is very unlikely to be defined in that case). - // If only AttackSequence is null, just rename the trait and property (the delay properties will likely be undefined). - // If both aren't null, split/copy everything relevant to the new WithTurretAimAnimation. - // If both are null (extremely unlikely), do nothing. - if (attackSequence == null && aimSequence != null) - { - turretAttack.RenameKeyPreservingSuffix("WithTurretAimAnimation"); - aimSequence.RenameKeyPreservingSuffix("Sequence"); - } - else if (attackSequence != null && aimSequence == null) - attackSequence.RenameKeyPreservingSuffix("Sequence"); - else if (attackSequence != null && aimSequence != null) - { - var turretAim = new MiniYamlNode("WithTurretAimAnimation", ""); - aimSequence.RenameKeyPreservingSuffix("Sequence"); - turretAim.AddNode(aimSequence); - turretAttack.RemoveNode(aimSequence); - - var reloadPrefix = turretAttack.LastChildMatching("ReloadPrefix"); - var turret = turretAttack.LastChildMatching("Turret"); - var armament = turretAttack.LastChildMatching("Armament"); - if (reloadPrefix != null) - { - turretAim.AddNode(reloadPrefix); - turretAttack.RemoveNode(reloadPrefix); - } - - if (turret != null) - turretAim.AddNode(turret); - if (armament != null) - turretAim.AddNode(armament); - - attackSequence.RenameKeyPreservingSuffix("Sequence"); - actorNode.AddNode(turretAim); - } - } - - var spriteTurret = actorNode.LastChildMatching("WithSpriteTurret"); - if (spriteTurret != null) - { - var aimSequence = spriteTurret.LastChildMatching("AimSequence"); - if (aimSequence != null) - { - var aimAnim = new MiniYamlNode("WithTurretAimAnimation", ""); - aimSequence.RenameKeyPreservingSuffix("Sequence"); - aimAnim.AddNode(aimSequence); - spriteTurret.RemoveNode(aimSequence); - actorNode.AddNode(aimAnim); - } - } - - yield break; - } - } -} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 5abb168ac4..b33804af68 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.UpdateRules new RemoveTerrainTypeIsWaterFlag(), new DefineSquadExcludeHarvester(), new RemoveWeaponScanRadius(), - new SplitTurretAimAnimation(), + new SplitAimAnimations(), new DefineSoundDefaults(), new RenameWormSpawner(), new RemoveWithReloadingSpriteTurret(),