From 8c2f25e2499bfa118d9a937540ed270aa6158ac2 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 28 Apr 2018 18:49:46 +0100 Subject: [PATCH] Remove explicit line numbers from update rule reports. Additions/removals by other rules in the set will almost certainly invalidate these. Reporting the block and file is the best we can reasonably do. --- .../UpdateRules/Rules/DefineSoundDefaults.cs | 35 ++++++++----------- .../Rules/DefineSquadExcludeHarvester.cs | 23 ++++-------- .../UpdateRules/Rules/IgnoreAbstractActors.cs | 3 +- .../Rules/RemoveWithReloadingSpriteTurret.cs | 17 +++++++-- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/DefineSoundDefaults.cs b/OpenRA.Mods.Common/UpdateRules/Rules/DefineSoundDefaults.cs index 32dd629b37..ec05c25257 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/DefineSoundDefaults.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/DefineSoundDefaults.cs @@ -27,37 +27,32 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules } } - Tuple>[] fields = + Tuple>[] fields = { - Tuple.Create("ParaDrop", "ChuteSound", "chute1.aud", new List()), - Tuple.Create("EjectOnDeath", "ChuteSound", "chute1.aud", new List()), - Tuple.Create("ProductionParadrop", "ChuteSound", "chute1.aud", new List()), - Tuple.Create("Building", "BuildSounds", "placbldg.aud, build5.aud", new List()), - Tuple.Create("Building", "UndeploySounds", "cashturn.aud", new List()) + Tuple.Create("ParaDrop", "ChuteSound", "chute1.aud", new List()), + Tuple.Create("EjectOnDeath", "ChuteSound", "chute1.aud", new List()), + Tuple.Create("ProductionParadrop", "ChuteSound", "chute1.aud", new List()), + Tuple.Create("Building", "BuildSounds", "placbldg.aud, build5.aud", new List()), + Tuple.Create("Building", "UndeploySounds", "cashturn.aud", new List()) }; - public override IEnumerable BeforeUpdate(ModData modData) - { - // Reset state for each mod/map - foreach (var field in fields) - field.Item4.Clear(); - - yield break; - } - - string BuildMessage(Tuple> field) + string BuildMessage(Tuple> field) { return "The default value for {0}.{1} has been removed.\n".F(field.Item1, field.Item2) - + "You may wish to explicitly define `{0}: {1}` at the following\n".F(field.Item2, field.Item3) - + "locations if the sound has not already been inherited from a parent definition.\n" - + UpdateUtils.FormatMessageList(field.Item4.Select(n => n.Location.ToString())); + + "You may wish to explicitly define `{0}: {1}` on the `{2}` trait \n".F(field.Item2, field.Item3, field.Item1) + + "definitions on the following actors (if they have not already been inherited from a parent).\n" + + UpdateUtils.FormatMessageList(field.Item4); } public override IEnumerable AfterUpdate(ModData modData) { foreach (var field in fields) + { if (field.Item4.Any()) yield return BuildMessage(field); + + field.Item4.Clear(); + } } public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) @@ -68,7 +63,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules { var node = traitNode.LastChildMatching(field.Item2); if (node == null) - field.Item4.Add(traitNode); + field.Item4.Add("{0} ({1})".F(actorNode.Key, traitNode.Location.Filename)); } } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/DefineSquadExcludeHarvester.cs b/OpenRA.Mods.Common/UpdateRules/Rules/DefineSquadExcludeHarvester.cs index 714c45fedb..9d228ad889 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/DefineSquadExcludeHarvester.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/DefineSquadExcludeHarvester.cs @@ -26,34 +26,23 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules } } - readonly List locations = new List(); - - public override IEnumerable BeforeUpdate(ModData modData) - { - // Reset state for each mod/map - locations.Clear(); - yield break; - } + readonly List locations = new List(); public override IEnumerable AfterUpdate(ModData modData) { if (locations.Any()) yield return "The automatic exclusion of harvesters from AI squads has been removed.\n" + "You may wish to add your harvester-type actors to `ExcludeFromSquads` under `UnitCommonNames`\n" - + "at the following locations.\n" - + UpdateUtils.FormatMessageList(locations.Select(l => l.ToString())); + + "on the following definitions:\n" + + UpdateUtils.FormatMessageList(locations); + + locations.Clear(); } public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) { foreach (var hackyAINode in actorNode.ChildrenMatching("HackyAI")) - { - var commonNamesNode = hackyAINode.LastChildMatching("UnitsCommonNames"); - if (commonNamesNode != null) - locations.Add(commonNamesNode.Location); - else - locations.Add(hackyAINode.Location); - } + locations.Add("{0} ({1})".F(hackyAINode.Key, hackyAINode.Location.Filename)); yield break; } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/IgnoreAbstractActors.cs b/OpenRA.Mods.Common/UpdateRules/Rules/IgnoreAbstractActors.cs index 162bedce29..d29cff932e 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/IgnoreAbstractActors.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/IgnoreAbstractActors.cs @@ -53,8 +53,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules yield return "Actor ids starting with '^' are now reserved for abstract\n" + "inheritance templates, and will not be parsed by the game.\n" + "Check the following definitions and rename them if they are not used for inheritance:\n" + - UpdateUtils.FormatMessageList(actors.Select(n => n.Key + ":\n" + - UpdateUtils.FormatMessageList(n.Value.Select(v => v.Location.ToString())))); + UpdateUtils.FormatMessageList(actors.Select(n => n.Key + " (" + n.Value.Select(v => v.Location.Filename).JoinWith(", ") + ")")); } } } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/RemoveWithReloadingSpriteTurret.cs b/OpenRA.Mods.Common/UpdateRules/Rules/RemoveWithReloadingSpriteTurret.cs index 9a22e68570..7ece90624d 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/RemoveWithReloadingSpriteTurret.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/RemoveWithReloadingSpriteTurret.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using System.Linq; namespace OpenRA.Mods.Common.UpdateRules.Rules { @@ -25,13 +26,25 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules } } + readonly List locations = new List(); + + public override IEnumerable AfterUpdate(ModData modData) + { + if (locations.Any()) + yield return "WithReloadingSpriteTurret has been replaced by WithSpriteTurret\n" + + "You should use AmmoPool.AmmoConditions to switch turret type when reloading\n" + + "to restore the previous behaviour on the following actors:" + + UpdateUtils.FormatMessageList(locations); + + locations.Clear(); + } + public override IEnumerable UpdateActorNode(ModData modData, MiniYamlNode actorNode) { foreach (var turret in actorNode.ChildrenMatching("WithReloadingSpriteTurret")) { turret.RenameKeyPreservingSuffix("WithSpriteTurret"); - yield return turret.Location.ToString() + ": WithReloadingSpriteTurret has been replaced by WithSpriteTurret.\n" + - "You should use AmmoPool.AmmoConditions to switch turret type when reloading to restore the previous behaviour."; + locations.Add("{0} ({1})".F(actorNode.Key, turret.Location.Filename)); } yield break;