From ac623d784a825fc10c86e08d2a872d87922d9414 Mon Sep 17 00:00:00 2001 From: tomas Date: Fri, 19 Aug 2022 22:15:00 +0200 Subject: [PATCH] Remove Do() and replace with foreach() --- OpenRA.Game/Exts.cs | 6 ------ OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs | 3 ++- .../Traits/Buildings/RepairableBuilding.cs | 8 ++++---- OpenRA.Mods.Common/Traits/Player/TechTree.cs | 18 ++++++++++-------- .../Widgets/Logic/MapChooserLogic.cs | 4 +++- .../Widgets/Logic/ReplayBrowserLogic.cs | 4 +++- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 3d4af5be77..f199e57dcc 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -38,12 +38,6 @@ namespace OpenRA catch { return def; } } - public static void Do(this IEnumerable e, Action fn) - { - foreach (var ee in e) - fn(ee); - } - public static Lazy Lazy(Func p) { return new Lazy(p); } public static IEnumerable GetNamespaces(this Assembly a) diff --git a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs index bf97badc38..d670794705 100644 --- a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs @@ -85,7 +85,8 @@ namespace OpenRA.Mods.Cnc.Graphics if (!cache.Any() || length != cachedLength || pos != cachedPos) cache = GenerateRenderables(wr); - cache.Do(c => c.Render(wr)); + foreach (var renderable in cache) + renderable.Render(wr); } public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; } diff --git a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs index cc06b1ba16..b02cc5f608 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs @@ -172,13 +172,13 @@ namespace OpenRA.Mods.Common.Traits if (health.DamageState == DamageState.Undamaged) { - Repairers.Do(r => + foreach (var repairer in Repairers) { - if (r == self.Owner) + if (repairer == self.Owner) return; - r.PlayerActor.TraitOrDefault()?.GiveExperience(Info.PlayerExperience); - }); + repairer.PlayerActor.TraitOrDefault()?.GiveExperience(Info.PlayerExperience); + } Repairers.Clear(); RepairActive = false; diff --git a/OpenRA.Mods.Common/Traits/Player/TechTree.cs b/OpenRA.Mods.Common/Traits/Player/TechTree.cs index d0d8c24de4..1f58c3335e 100644 --- a/OpenRA.Mods.Common/Traits/Player/TechTree.cs +++ b/OpenRA.Mods.Common/Traits/Player/TechTree.cs @@ -95,14 +95,16 @@ namespace OpenRA.Mods.Common.Traits } // Add buildables that have a build limit set and are not already in the list - player.World.ActorsWithTrait() - .Where(a => - a.Actor.Owner == player && - a.Actor.IsInWorld && - !a.Actor.IsDead && - !ret.ContainsKey(a.Actor.Info.Name) && - a.Actor.Info.TraitInfo().BuildLimit > 0) - .Do(b => ret[b.Actor.Info.Name].Add(b.Actor)); + var buildables = player.World.ActorsWithTrait() + .Where(a => + a.Actor.Owner == player && + a.Actor.IsInWorld && + !a.Actor.IsDead && + !ret.ContainsKey(a.Actor.Info.Name) && + a.Actor.Info.TraitInfo().BuildLimit > 0); + + foreach (var buildable in buildables) + ret[buildable.Actor.Info.Name].Add(buildable.Actor); return ret; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index a1f51c852b..82232df8fb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -343,7 +343,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic text: "Delete all maps on this page?", onConfirm: () => { - maps.Do(m => DeleteMap(m)); + foreach (var map in maps) + DeleteMap(map); + after?.Invoke(Game.ModData.MapCache.ChooseInitialMap(null, Game.CosmeticRandom)); }, confirmText: "Delete", diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 3ce823fa0f..5032a98ad4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -463,7 +463,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic text: $"Delete {list.Count} replays?", onConfirm: () => { - list.ForEach(DeleteReplay); + foreach (var replayMetadata in list) + DeleteReplay(replayMetadata); + if (selectedReplay == null) SelectFirstVisibleReplay(); },