From acca8371429f7c28f052b2d87ec2c5d04f6cd64d Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sat, 18 Mar 2023 13:25:59 +0000 Subject: [PATCH] Fix RCS1246 --- .editorconfig | 2 ++ OpenRA.Game/Game.cs | 2 +- OpenRA.Game/Map/Map.cs | 4 ++-- OpenRA.Game/Scripting/ScriptContext.cs | 6 +++--- OpenRA.Game/Server/OrderBuffer.cs | 4 ++-- OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs | 4 ++-- OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs | 6 +++--- OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs | 2 +- OpenRA.Mods.Common/Terrain/DefaultTileCache.cs | 2 +- .../Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs | 2 +- .../Traits/BotModules/SquadManagerBotModule.cs | 4 ++-- OpenRA.Mods.Common/Traits/Minelayer.cs | 2 +- OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs | 3 +-- OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs | 3 +-- .../Traits/SupportPowers/SupportPowerManager.cs | 2 +- .../Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs | 2 +- .../Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs | 2 +- .../Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs | 4 ++-- OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs | 2 +- .../Widgets/Logic/Settings/AudioSettingsLogic.cs | 2 +- OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs | 4 ++-- 21 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.editorconfig b/.editorconfig index 504b3085cf..83c30f627c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1170,3 +1170,5 @@ dotnet_diagnostic.RCS1236.severity = warning # Use 'for' statement instead of 'while' statement. dotnet_diagnostic.RCS1239.severity = warning +# Use element access. +dotnet_diagnostic.RCS1246.severity = warning diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 3379f41ba0..e735281ce8 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -423,7 +423,7 @@ namespace OpenRA // Sanitize input from platform-specific launchers // Process.Start requires paths to not be quoted, even if they contain spaces - if (launchPath != null && launchPath.First() == '"' && launchPath.Last() == '"') + if (launchPath != null && launchPath[0] == '"' && launchPath.Last() == '"') launchPath = launchPath[1..^1]; // Metadata registration requires an explicit launch path diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 05459f42a7..18c04510ac 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -1197,7 +1197,7 @@ namespace OpenRA // Project this guessed cell and take the first available cell // If it is projected outside the layer, then make another guess. var allProjected = ProjectedCellsCovering(uv); - var projected = allProjected.Length > 0 ? allProjected.First() + var projected = allProjected.Length > 0 ? allProjected[0] : new PPos(uv.U, uv.V.Clamp(Bounds.Top, Bounds.Bottom)); // Clamp the projected cell to the map area @@ -1266,7 +1266,7 @@ namespace OpenRA PPos edge; if (allProjected.Length > 0) { - var puv = allProjected.First(); + var puv = allProjected[0]; var horizontalBound = (puv.U - Bounds.Left < Bounds.Width / 2) ? Bounds.Left : Bounds.Right; var verticalBound = (puv.V - Bounds.Top < Bounds.Height / 2) ? Bounds.Top : Bounds.Bottom; diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index 7592972360..e43f22279b 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -102,7 +102,7 @@ namespace OpenRA.Scripting if (names.Length != 1) throw new InvalidOperationException($"[ScriptGlobal] attribute not found for global table '{type}'"); - Name = names.First().Name; + Name = names[0].Name; Bind(new[] { this }); } @@ -114,7 +114,7 @@ namespace OpenRA.Scripting { using (var luaObject = a.ToLuaValue(Context)) using (var filterResult = filter.Call(luaObject)) - using (var result = filterResult.First()) + using (var result = filterResult[0]) return result.ToBoolean(); }); } @@ -214,7 +214,7 @@ namespace OpenRA.Scripting var ctor = Array.Find(b.GetConstructors(BindingFlags.Public | BindingFlags.Instance), c => { var p = c.GetParameters(); - return p.Length == 1 && p.First().ParameterType == typeof(ScriptContext); + return p.Length == 1 && p[0].ParameterType == typeof(ScriptContext); }); if (ctor == null) diff --git a/OpenRA.Game/Server/OrderBuffer.cs b/OpenRA.Game/Server/OrderBuffer.cs index 6ede800a9c..6fdc8bbc84 100644 --- a/OpenRA.Game/Server/OrderBuffer.cs +++ b/OpenRA.Game/Server/OrderBuffer.cs @@ -68,7 +68,7 @@ namespace OpenRA.Server ticksPerInterval = Interval / timestep; this.players = players.ToList(); - baselinePlayer = this.players.First(); + baselinePlayer = this.players[0]; foreach (var player in this.players) { @@ -128,7 +128,7 @@ namespace OpenRA.Server players.Remove(player); if (player == baselinePlayer && players.Count > 0) { - var newBaseline = players.First(); + var newBaseline = players[0]; Interlocked.Exchange(ref baselinePlayer, newBaseline); } diff --git a/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs b/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs index 776fdfb49c..e8d7259531 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSVeinsRenderer.cs @@ -380,7 +380,7 @@ namespace OpenRA.Mods.Cnc.Traits if (resourceType != info.ResourceType) yield break; - var sprite = veinSequence.GetSprite(HeavyIndices.First()); + var sprite = veinSequence.GetSprite(HeavyIndices[0]); var palette = wr.Palette(info.Palette); yield return new UISpriteRenderable(sprite, WPos.Zero, origin, 0, palette, scale); @@ -391,7 +391,7 @@ namespace OpenRA.Mods.Cnc.Traits if (resourceType != info.ResourceType) yield break; - var frame = HeavyIndices.First(); + var frame = HeavyIndices[0]; var sprite = veinSequence.GetSprite(frame); var alpha = veinSequence.GetAlpha(frame); var palette = wr.Palette(info.Palette); diff --git a/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs b/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs index 008f15eaee..5991d246fc 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs @@ -138,7 +138,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands if (!string.IsNullOrEmpty(foundation)) { var dimensions = foundation.Split('x'); - if (dimensions.First() == "0" || dimensions.Last() == "0") + if (dimensions[0] == "0" || dimensions.Last() == "0") Console.WriteLine("\tImmobile:\n \t\tOccupiesSpace: False"); else { @@ -148,10 +148,10 @@ namespace OpenRA.Mods.Cnc.UtilityCommands if (!string.IsNullOrEmpty(adjacent)) Console.WriteLine("\t\tAdjacent: " + adjacent); - Console.WriteLine("\t\tDimensions: " + dimensions.First() + "," + dimensions.Last()); + Console.WriteLine("\t\tDimensions: " + dimensions[0] + "," + dimensions.Last()); Console.Write("\t\tFootprint:"); - int.TryParse(dimensions.First(), out var width); + int.TryParse(dimensions[0], out var width); int.TryParse(dimensions.Last(), out var height); for (var y = 0; y < height; y++) { diff --git a/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs b/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs index 5a33219181..4ae6686e2a 100644 --- a/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/UnitOrderGenerator.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Orders // HACK: This is required by the hacky player actions-per-minute calculation // TODO: Reimplement APM properly and then remove this - yield return new Order("CreateGroup", actorsInvolved.First().Owner.PlayerActor, false, actorsInvolved); + yield return new Order("CreateGroup", actorsInvolved[0].Owner.PlayerActor, false, actorsInvolved); foreach (var o in orders) yield return CheckSameOrder(o.Order, o.Trait.IssueOrder(o.Actor, o.Order, o.Target, mi.Modifiers.HasModifier(Modifiers.Shift))); diff --git a/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs b/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs index 68398577bb..fa024e2b06 100644 --- a/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs +++ b/OpenRA.Mods.Common/Terrain/DefaultTileCache.cs @@ -138,7 +138,7 @@ namespace OpenRA.Mods.Common.Terrain if (onMissingImage != null && variants.Count == 0) continue; - templates.Add(t.Value.Id, new TheaterTemplate(allSprites.ToArray(), variants.First().Length, templateInfo.Images.Length)); + templates.Add(t.Value.Id, new TheaterTemplate(allSprites.ToArray(), variants[0].Length, templateInfo.Images.Length)); } // 1x1px transparent tile diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs index be738f7d00..84970b7219 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/MinelayerBotModule.cs @@ -226,7 +226,7 @@ namespace OpenRA.Mods.Common.Traits var vec = new CVec(Info.MineFieldRadius, Info.MineFieldRadius); bot.QueueOrder(new Order("PlaceMinefield", null, Target.FromCell(world, minelayingPosition + vec), false, groupedActors: orderedActors.ToArray()) { ExtraLocation = minelayingPosition - vec }); - bot.QueueOrder(new Order("Move", null, Target.FromCell(world, orderedActors.First().Location), true, groupedActors: orderedActors.ToArray())); + bot.QueueOrder(new Order("Move", null, Target.FromCell(world, orderedActors[0].Location), true, groupedActors: orderedActors.ToArray())); } else { diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index 81a8d7f4a3..61c345aa31 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -428,7 +428,7 @@ namespace OpenRA.Mods.Common.Traits var allEnemyBaseBuilder = FindEnemies( World.Actors.Where(a => Info.ConstructionYardTypes.Contains(a.Info.Name)), - ownUnits.First()) + ownUnits[0]) .ToList(); if (allEnemyBaseBuilder.Count == 0 || ownUnits.Count < Info.SquadSize) @@ -443,7 +443,7 @@ namespace OpenRA.Mods.Common.Traits unit.Info.HasTraitInfo() && !Info.AirUnitsTypes.Contains(unit.Info.Name) && !Info.NavalUnitsTypes.Contains(unit.Info.Name)), - ownUnits.First()) + ownUnits[0]) .ToList(); if (AttackOrFleeFuzzy.Rush.CanAttack(ownUnits, enemies.ConvertAll(x => x.Actor))) diff --git a/OpenRA.Mods.Common/Traits/Minelayer.cs b/OpenRA.Mods.Common/Traits/Minelayer.cs index a29c5a8a25..0f7d24b60d 100644 --- a/OpenRA.Mods.Common/Traits/Minelayer.cs +++ b/OpenRA.Mods.Common/Traits/Minelayer.cs @@ -293,7 +293,7 @@ namespace OpenRA.Mods.Common.Traits if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action) { - minelayers.First().World.CancelInputMode(); + minelayers[0].World.CancelInputMode(); foreach (var minelayer in minelayers) yield return new Order("PlaceMinefield", minelayer, Target.FromCell(world, cell), queued) { ExtraLocation = minefieldStart }; } diff --git a/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs index e28bb15417..c5524487cc 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithBridgeSpriteBody.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Traits; @@ -48,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits.Render yield break; var anim = new Animation(init.World, image); - anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequences.First()), () => 0); + anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequences[0]), () => 0); yield return new SpriteActorPreview(anim, () => WVec.Zero, () => 0, p); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs index e492814b3d..7fe352db6f 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; -using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; using OpenRA.Traits; @@ -56,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits.Render yield break; var anim = new Animation(init.World, image, init.GetFacing()); - anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), StandSequences.First())); + anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), StandSequences[0])); if (IsPlayerPalette) p = init.WorldRenderer.Palette(Palette + init.Get().InternalName); diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index 140fc7adba..f6996e7bba 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -197,7 +197,7 @@ namespace OpenRA.Mods.Common.Traits if (!Active) return; - var power = Instances.First(); + var power = Instances[0]; if (Manager.DevMode.FastCharge && remainingSubTicks > 2500) remainingSubTicks = 2500; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs index 51ffab1fb4..57b5c3f68c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleBasesHotkeyLogic.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame .Skip(1) .FirstOrDefault(); - next ??= bases.First(); + next ??= bases[0]; selection.Combine(world, new Actor[] { next }, false, true); viewport.Center(selection.Actors); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs index 7658595a8d..c2ada7cf8d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleHarvestersHotkeyLogic.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame .Skip(1) .FirstOrDefault(); - next ??= harvesters.First(); + next ??= harvesters[0]; selection.Combine(world, new Actor[] { next }, false, true); viewport.Center(selection.Actors); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs index befd7c3ad7..86d3129351 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/CycleProductionActorsHotkeyLogic.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame var facilities = world.ActorsHavingTrait() .Where(a => a.Owner == player && a.OccupiesSpace != null && !a.Info.HasTraitInfo() && a.TraitsImplementing().Any(t => !t.IsTraitDisabled)) - .OrderBy(f => f.TraitsImplementing().First(t => !t.IsTraitDisabled).Info.Produces.First()) + .OrderBy(f => f.TraitsImplementing().First(t => !t.IsTraitDisabled).Info.Produces[0]) .ToList(); if (facilities.Count == 0) @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic.Ingame .Skip(1) .FirstOrDefault(); - next ??= facilities.First(); + next ??= facilities[0]; Game.Sound.PlayNotification(world.Map.Rules, null, "Sounds", clickSound, null); diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index 66ad33cf52..01c3d29698 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -178,7 +178,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic missionList.ScrollToSelectedItem(); } else - SelectMap(allPreviews.First()); + SelectMap(allPreviews[0]); } // Preload map preview to reduce jank diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs index fddafe4ace..e1e691e0b3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs @@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic videoVolumeSlider.OnChange += x => Game.Sound.VideoVolume = x; var devices = Game.Sound.AvailableDevices(); - soundDevice = Array.Find(devices, d => d.Device == ss.Device) ?? devices.First(); + soundDevice = Array.Find(devices, d => d.Device == ss.Device) ?? devices[0]; var audioDeviceDropdown = panel.Get("AUDIO_DEVICE"); audioDeviceDropdown.OnMouseDown = _ => ShowAudioDeviceDropdown(audioDeviceDropdown, devices, scrollPanel); diff --git a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs index e62ff665d7..30916eb91d 100644 --- a/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs @@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Widgets .ThenBy(q => q.RemainingTimeActual) .ToList(); - var current = queued.First(); + var current = queued[0]; var queue = current.Queue; var faction = queue.Actor.Owner.Faction.InternalName; @@ -195,7 +195,7 @@ namespace OpenRA.Mods.Common.Widgets var bold = Game.Renderer.Fonts["Small"]; foreach (var icon in productionIcons) { - var current = icon.Queued.First(); + var current = icon.Queued[0]; var text = GetOverlayForItem(current, world.Timestep); tiny.DrawTextWithContrast(text, icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),