diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index 5a2e5591c8..7f3475cd52 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -135,6 +135,16 @@ namespace OpenRA return Array.IndexOf(array, value); } + public static T FirstOrDefault(this T[] array, Predicate match) + { + return Array.Find(array, match); + } + + public static T FirstOrDefault(this List list, Predicate match) + { + return list.Find(match); + } + public static T Random(this IEnumerable ts, MersenneTwister r) { return Random(ts, r, true); diff --git a/OpenRA.Game/FileSystem/FileSystem.cs b/OpenRA.Game/FileSystem/FileSystem.cs index 110028d3df..f6518ee173 100644 --- a/OpenRA.Game/FileSystem/FileSystem.cs +++ b/OpenRA.Game/FileSystem/FileSystem.cs @@ -328,7 +328,7 @@ namespace OpenRA.FileSystem if (name == ".") continue; - resolved = Array.Find(Directory.GetFileSystemEntries(resolved), e => e.Equals(Path.Combine(resolved, name), StringComparison.InvariantCultureIgnoreCase)); + resolved = Directory.GetFileSystemEntries(resolved).FirstOrDefault(e => e.Equals(Path.Combine(resolved, name), StringComparison.InvariantCultureIgnoreCase)); if (resolved == null) return null; diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 837ddf5190..a2e365b1ad 100644 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Server; @@ -43,7 +42,7 @@ namespace OpenRA.Network static Player FindPlayerByClient(this World world, Session.Client c) { - return Array.Find(world.Players, p => p.ClientIndex == c.Index && p.PlayerReference.Playable); + return world.Players.FirstOrDefault(p => p.ClientIndex == c.Index && p.PlayerReference.Playable); } static bool OrderNotFromServerOrWorldIsReplay(int clientId, World world) => clientId != 0 || (world != null && world.IsReplay); @@ -185,12 +184,12 @@ namespace OpenRA.Network if (!string.IsNullOrEmpty(order.TargetString)) { var data = MiniYaml.FromString(order.TargetString); - var saveLastOrdersFrame = data.Find(n => n.Key == "SaveLastOrdersFrame"); + var saveLastOrdersFrame = data.FirstOrDefault(n => n.Key == "SaveLastOrdersFrame"); if (saveLastOrdersFrame != null) orderManager.GameSaveLastFrame = FieldLoader.GetValue("saveLastOrdersFrame", saveLastOrdersFrame.Value.Value); - var saveSyncFrame = data.Find(n => n.Key == "SaveSyncFrame"); + var saveSyncFrame = data.FirstOrDefault(n => n.Key == "SaveSyncFrame"); if (saveSyncFrame != null) orderManager.GameSaveLastSyncFrame = FieldLoader.GetValue("SaveSyncFrame", saveSyncFrame.Value.Value); @@ -375,7 +374,7 @@ namespace OpenRA.Network var strings = node.Key.Split('@'); if (strings[0] == "ConnectionQuality") { - var client = orderManager.LobbyInfo.Clients.Find(c => c.Index == Exts.ParseInt32Invariant(strings[1])); + var client = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.Index == Exts.ParseInt32Invariant(strings[1])); if (client != null) client.ConnectionQuality = FieldLoader.GetValue("ConnectionQuality", node.Value.Value); } diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 36602f14a7..20ba3c35fe 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -109,14 +109,14 @@ namespace OpenRA .Where(f => !requireSelectable || f.Selectable) .ToList(); - var selected = selectableFactions.Find(f => f.InternalName == factionName) + var selected = selectableFactions.FirstOrDefault(f => f.InternalName == factionName) ?? selectableFactions.Random(playerRandom); // Don't loop infinite for (var i = 0; i <= 10 && selected.RandomFactionMembers.Count > 0; i++) { var faction = selected.RandomFactionMembers.Random(playerRandom); - selected = selectableFactions.Find(f => f.InternalName == faction); + selected = selectableFactions.FirstOrDefault(f => f.InternalName == faction); if (selected == null) throw new YamlException($"Unknown faction: {faction}"); @@ -179,7 +179,7 @@ namespace OpenRA else { // Map player - ClientIndex = world.LobbyInfo.Clients.Find(c => c.IsAdmin)?.Index ?? 0; // Owned by the host (TODO: fix this) + ClientIndex = world.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin)?.Index ?? 0; // Owned by the host (TODO: fix this) Color = pr.Color; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index e43f22279b..3b53051c1a 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -211,7 +211,7 @@ namespace OpenRA.Scripting var bindings = Game.ModData.ObjectCreator.GetTypesImplementing(); foreach (var b in bindings) { - var ctor = Array.Find(b.GetConstructors(BindingFlags.Public | BindingFlags.Instance), c => + var ctor = b.GetConstructors(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(c => { var p = c.GetParameters(); return p.Length == 1 && p[0].ParameterType == typeof(ScriptContext); diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 0d15a2ff3b..2eadac0ea7 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -1160,7 +1160,7 @@ namespace OpenRA.Server } public bool HasClientWonOrLost(Session.Client client) => - worldPlayers.Find(p => p?.ClientIndex == client.Index)?.Outcome != WinState.Undefined; + worldPlayers.FirstOrDefault(p => p?.ClientIndex == client.Index)?.Outcome != WinState.Undefined; public void DropClient(Connection toDrop) { @@ -1169,7 +1169,7 @@ namespace OpenRA.Server orderBuffer?.RemovePlayer(toDrop.PlayerIndex); Conns.Remove(toDrop); - var dropClient = LobbyInfo.Clients.Find(c => c.Index == toDrop.PlayerIndex); + var dropClient = LobbyInfo.Clients.FirstOrDefault(c => c.Index == toDrop.PlayerIndex); if (dropClient == null) { toDrop.Dispose(); diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index c11e499627..1ff0c955f9 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -348,7 +348,7 @@ namespace OpenRA LoadSectionYaml(yamlSection.Value, settingsSection); } - var keysNode = yamlCache.Find(n => n.Key == "Keys"); + var keysNode = yamlCache.FirstOrDefault(n => n.Key == "Keys"); if (keysNode != null) foreach (var node in keysNode.Value.Nodes) if (node.Key != null) @@ -373,7 +373,7 @@ namespace OpenRA var yamlCacheBuilder = yamlCache.ConvertAll(n => new MiniYamlNodeBuilder(n)); foreach (var kv in Sections) { - var sectionYaml = yamlCacheBuilder.Find(x => x.Key == kv.Key); + var sectionYaml = yamlCacheBuilder.FirstOrDefault(x => x.Key == kv.Key); if (sectionYaml == null) { sectionYaml = new MiniYamlNodeBuilder(kv.Key, new MiniYamlBuilder("")); @@ -403,7 +403,7 @@ namespace OpenRA } } - var keysYaml = yamlCacheBuilder.Find(x => x.Key == "Keys"); + var keysYaml = yamlCacheBuilder.FirstOrDefault(x => x.Key == "Keys"); if (keysYaml == null) { keysYaml = new MiniYamlNodeBuilder("Keys", new MiniYamlBuilder("")); diff --git a/OpenRA.Mods.Cnc/Scripting/Properties/InfiltrateProperties.cs b/OpenRA.Mods.Cnc/Scripting/Properties/InfiltrateProperties.cs index 11ee26e5b8..e9d8a646b1 100644 --- a/OpenRA.Mods.Cnc/Scripting/Properties/InfiltrateProperties.cs +++ b/OpenRA.Mods.Cnc/Scripting/Properties/InfiltrateProperties.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using Eluant; using OpenRA.Mods.Cnc.Activities; @@ -33,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Scripting [Desc("Infiltrate the target actor.")] public void Infiltrate(Actor target) { - var infiltrates = Array.Find(infiltratesTraits, x => !x.IsTraitDisabled && x.Info.Types.Overlaps(target.GetEnabledTargetTypes())); + var infiltrates = infiltratesTraits.FirstOrDefault(x => !x.IsTraitDisabled && x.Info.Types.Overlaps(target.GetEnabledTargetTypes())); if (infiltrates == null) throw new LuaException($"{Self} tried to infiltrate invalid target {target}!"); diff --git a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs index 0cb1749955..553c005495 100644 --- a/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs +++ b/OpenRA.Mods.Cnc/Traits/SupportPowers/GrantPrerequisiteChargeDrainPower.cs @@ -161,7 +161,7 @@ namespace OpenRA.Mods.Cnc.Traits if (!available || order.ExtraData != 1) return; - var power = Instances.Find(i => !i.IsTraitPaused); + var power = Instances.FirstOrDefault(i => !i.IsTraitPaused); if (power == null) return; diff --git a/OpenRA.Mods.Common/Activities/LayMines.cs b/OpenRA.Mods.Common/Activities/LayMines.cs index 0fc25b4764..fb5740af16 100644 --- a/OpenRA.Mods.Common/Activities/LayMines.cs +++ b/OpenRA.Mods.Common/Activities/LayMines.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Activities; @@ -176,7 +175,7 @@ namespace OpenRA.Mods.Common.Activities { if (ammoPools != null) { - var pool = Array.Find(ammoPools, x => x.Info.Name == minelayer.Info.AmmoPoolName); + var pool = ammoPools.FirstOrDefault(x => x.Info.Name == minelayer.Info.AmmoPoolName); if (pool == null) return false; @@ -194,7 +193,7 @@ namespace OpenRA.Mods.Common.Activities { if (ammoPools != null) { - var pool = Array.Find(ammoPools, x => x.Info.Name == minelayer.Info.AmmoPoolName); + var pool = ammoPools.FirstOrDefault(x => x.Info.Name == minelayer.Info.AmmoPoolName); if (pool == null) return false; diff --git a/OpenRA.Mods.Common/Activities/Resupply.cs b/OpenRA.Mods.Common/Activities/Resupply.cs index 3b5478fb14..f8316f08ed 100644 --- a/OpenRA.Mods.Common/Activities/Resupply.cs +++ b/OpenRA.Mods.Common/Activities/Resupply.cs @@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Activities QueueChild(move.MoveWithinRange(host, closeEnough, targetLineColor: moveInfo.GetTargetLineColor())); var delta = (self.CenterPosition - host.CenterPosition).LengthSquared; - Array.Find(transportCallers, t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell); + transportCallers.FirstOrDefault(t => t.MinimumDistance.LengthSquared < delta)?.RequestTransport(self, targetCell); return false; } @@ -256,7 +256,7 @@ namespace OpenRA.Mods.Common.Activities void RepairTick(Actor self) { - var repairsUnits = Array.Find(allRepairsUnits, r => !r.IsTraitDisabled && !r.IsTraitPaused); + var repairsUnits = allRepairsUnits.FirstOrDefault(r => !r.IsTraitDisabled && !r.IsTraitPaused); if (repairsUnits == null) { if (!allRepairsUnits.Any(r => r.IsTraitPaused)) diff --git a/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs b/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs index 96870efd5a..3990bf8eed 100644 --- a/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/MSCabCompression.cs @@ -89,7 +89,7 @@ namespace OpenRA.Mods.Common.FileFormats public void ExtractFile(string filename, Stream output, Action onProgress = null) { - var file = Array.Find(files, f => f.FileName == filename); + var file = files.FirstOrDefault(f => f.FileName == filename); if (file == null) throw new FileNotFoundException(filename); diff --git a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs index 4967629398..cb954911e0 100644 --- a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs +++ b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs @@ -207,7 +207,7 @@ namespace OpenRA.Mods.Common.Lint continue; var childType = childNode.Key.Split('@')[0]; - var field = Array.Find(translationNodes, t => t.Name == childType); + var field = translationNodes.FirstOrDefault(t => t.Name == childType); if (field.Name == null) continue; diff --git a/OpenRA.Mods.Common/Scripting/Global/PlayerGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/PlayerGlobal.cs index 4ceca1a3f9..cd41a413a7 100644 --- a/OpenRA.Mods.Common/Scripting/Global/PlayerGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/PlayerGlobal.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using Eluant; using OpenRA.Scripting; @@ -25,7 +24,7 @@ namespace OpenRA.Mods.Common.Scripting [Desc("Returns the player with the specified internal name, or nil if a match is not found.")] public Player GetPlayer(string name) { - return Array.Find(Context.World.Players, p => p.InternalName == name); + return Context.World.Players.FirstOrDefault(p => p.InternalName == name); } [Desc("Returns a table of players filtered by the specified function.")] diff --git a/OpenRA.Mods.Common/Scripting/Properties/AmmoPoolProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/AmmoPoolProperties.cs index 9c63ddfbf0..3b7d3b73bf 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/AmmoPoolProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/AmmoPoolProperties.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using Eluant; using OpenRA.Mods.Common.Traits; @@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Scripting [Desc("Returns the count of the actor's specified ammopool.")] public int AmmoCount(string poolName = "primary") { - var pool = Array.Find(ammoPools, a => a.Info.Name == poolName); + var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName); if (pool == null) throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}."); @@ -44,7 +43,7 @@ namespace OpenRA.Mods.Common.Scripting [Desc("Returns the maximum count of ammo the actor can load.")] public int MaximumAmmoCount(string poolName = "primary") { - var pool = Array.Find(ammoPools, a => a.Info.Name == poolName); + var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName); if (pool == null) throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}."); @@ -55,7 +54,7 @@ namespace OpenRA.Mods.Common.Scripting "(Use a negative amount to remove ammo.)")] public void Reload(string poolName = "primary", int amount = 1) { - var pool = Array.Find(ammoPools, a => a.Info.Name == poolName); + var pool = ammoPools.FirstOrDefault(a => a.Info.Name == poolName); if (pool == null) throw new LuaException($"Invalid ammopool name {poolName} queried on actor {self}."); diff --git a/OpenRA.Mods.Common/Scripting/Properties/ConditionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/ConditionProperties.cs index a2da37bdd6..c16d46943e 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/ConditionProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/ConditionProperties.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using Eluant; using OpenRA.Mods.Common.Traits; @@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Scripting "If duration > 0 the condition will be automatically revoked after the defined number of ticks.")] public int GrantCondition(string condition, int duration = 0) { - var external = Array.Find(externalConditions, t => t.Info.Condition == condition && t.CanGrantCondition(this)); + var external = externalConditions.FirstOrDefault(t => t.Info.Condition == condition && t.CanGrantCondition(this)); if (external == null) throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait"); diff --git a/OpenRA.Mods.Common/Scripting/Properties/PlayerConditionProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/PlayerConditionProperties.cs index 280fe19588..328f2641dc 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/PlayerConditionProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/PlayerConditionProperties.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Linq; using Eluant; using OpenRA.Mods.Common.Traits; @@ -33,7 +32,7 @@ namespace OpenRA.Mods.Common.Scripting "If duration > 0 the condition will be automatically revoked after the defined number of ticks.")] public int GrantCondition(string condition, int duration = 0) { - var external = Array.Find(externalConditions, t => t.Info.Condition == condition && t.CanGrantCondition(this)); + var external = externalConditions.FirstOrDefault(t => t.Info.Condition == condition && t.CanGrantCondition(this)); if (external == null) throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait"); diff --git a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs index eeb645376c..8b62a6fb86 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/PlayerProperties.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Scripting { get { - var c = Player.World.LobbyInfo.Clients.Find(i => i.Index == Player.ClientIndex); + var c = Player.World.LobbyInfo.Clients.FirstOrDefault(i => i.Index == Player.ClientIndex); return c?.Team ?? 0; } } @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Scripting { get { - var c = Player.World.LobbyInfo.Clients.Find(i => i.Index == Player.ClientIndex); + var c = Player.World.LobbyInfo.Clients.FirstOrDefault(i => i.Index == Player.ClientIndex); return c?.Handicap ?? 0; } } diff --git a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs index b7185e63cf..3c2bbf87a8 100644 --- a/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs +++ b/OpenRA.Mods.Common/ServerTraits/LobbyCommands.cs @@ -278,7 +278,7 @@ namespace OpenRA.Mods.Common.Server { // Client 0 will always be the Host // In some cases client 0 doesn't exist, so we untick all players - var host = server.LobbyInfo.Clients.Find(c => c.Index == 0); + var host = server.LobbyInfo.Clients.FirstOrDefault(c => c.Index == 0); if (host != null) host.State = Session.ClientState.NotReady; else @@ -442,7 +442,7 @@ namespace OpenRA.Mods.Common.Server } else { - var occupantConn = server.Conns.Find(c => c.PlayerIndex == occupant.Index); + var occupantConn = server.Conns.FirstOrDefault(c => c.PlayerIndex == occupant.Index); if (occupantConn != null) { server.SendOrderTo(conn, "ServerError", SlotClosed); @@ -1143,7 +1143,7 @@ namespace OpenRA.Mods.Common.Server if (spawnPoint == 0) return true; - var existingClient = server.LobbyInfo.Clients.Find(cc => cc.SpawnPoint == spawnPoint); + var existingClient = server.LobbyInfo.Clients.FirstOrDefault(cc => cc.SpawnPoint == spawnPoint); if (client != existingClient && !client.IsAdmin) { server.SendLocalizedMessageTo(conn, AdminClearSpawn); diff --git a/OpenRA.Mods.Common/ServerTraits/SkirmishLogic.cs b/OpenRA.Mods.Common/ServerTraits/SkirmishLogic.cs index e3585733d3..537ef429bd 100644 --- a/OpenRA.Mods.Common/ServerTraits/SkirmishLogic.cs +++ b/OpenRA.Mods.Common/ServerTraits/SkirmishLogic.cs @@ -165,7 +165,7 @@ namespace OpenRA.Mods.Common.Server var slot = server.LobbyInfo.FirstEmptyBotSlot(); var bot = server.Map.PlayerActorInfo.TraitInfos().Select(t => t.Type).FirstOrDefault(); - var botController = server.LobbyInfo.Clients.Find(c => c.IsAdmin); + var botController = server.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); if (slot != null && bot != null) server.InterpretCommand($"slot_bot {slot} {botController.Index} {bot}", conn); } diff --git a/OpenRA.Mods.Common/Traits/AttackMove.cs b/OpenRA.Mods.Common/Traits/AttackMove.cs index 71b32cab3c..8088170e99 100644 --- a/OpenRA.Mods.Common/Traits/AttackMove.cs +++ b/OpenRA.Mods.Common/Traits/AttackMove.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; @@ -163,7 +162,7 @@ namespace OpenRA.Mods.Common.Traits if (world.Map.Contains(cell)) { var explored = subject.Actor.Owner.Shroud.IsExplored(cell); - var cannotMove = Array.Find(subjects, a => !a.Trait.Info.MoveIntoShroud).Trait; + var cannotMove = subjects.FirstOrDefault(a => !a.Trait.Info.MoveIntoShroud).Trait; var blocked = !explored && cannotMove != null; if (isAssaultMove) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs index 61c345aa31..56e35ba288 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SquadManagerBotModule.cs @@ -305,7 +305,7 @@ namespace OpenRA.Mods.Common.Traits // HACK: Use of this function requires that there is one squad of this type. Squad GetSquadOfType(SquadType type) { - return Squads.Find(s => s.Type == type); + return Squads.FirstOrDefault(s => s.Type == type); } Squad RegisterNewSquad(IBot bot, SquadType type, (Actor Actor, WVec Offset) target = default) diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs index 6cbdb63e09..7d4333c418 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; @@ -143,7 +142,7 @@ namespace OpenRA.Mods.Common.Traits return; var currentTransform = self.CurrentActivity as Transform; - var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused); + var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused); if (transform == null && currentTransform == null) return; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs index adc208f88b..19f0196833 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; @@ -95,7 +94,7 @@ namespace OpenRA.Mods.Common.Traits return; var currentTransform = self.CurrentActivity as Transform; - var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused); + var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused); if (transform == null && currentTransform == null) return; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs index dddff6fc8e..d04046245d 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; @@ -121,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits return; var currentTransform = self.CurrentActivity as Transform; - var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused); + var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused); if (transform == null && currentTransform == null) return; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs index bc82e4e9bb..568e394492 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; @@ -129,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits return; var currentTransform = self.CurrentActivity as Transform; - var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused); + var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused); if (transform == null && currentTransform == null) return; diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs index b6c85cbcf2..e569dce002 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Activities; @@ -123,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits return; var currentTransform = self.CurrentActivity as Transform; - var transform = Array.Find(transforms, t => !t.IsTraitDisabled && !t.IsTraitPaused); + var transform = transforms.FirstOrDefault(t => !t.IsTraitDisabled && !t.IsTraitPaused); if (transform == null && currentTransform == null) return; diff --git a/OpenRA.Mods.Common/Traits/Crates/GrantExternalConditionCrateAction.cs b/OpenRA.Mods.Common/Traits/Crates/GrantExternalConditionCrateAction.cs index 53f7c72bcf..7997e642e2 100644 --- a/OpenRA.Mods.Common/Traits/Crates/GrantExternalConditionCrateAction.cs +++ b/OpenRA.Mods.Common/Traits/Crates/GrantExternalConditionCrateAction.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits { if (external == null || !external.CanGrantCondition(self)) { - external = externals.Find(t => t.CanGrantCondition(self)); + external = externals.FirstOrDefault(t => t.CanGrantCondition(self)); if (external == null) break; } diff --git a/OpenRA.Mods.Common/Traits/Minelayer.cs b/OpenRA.Mods.Common/Traits/Minelayer.cs index 0f7d24b60d..36c65746d7 100644 --- a/OpenRA.Mods.Common/Traits/Minelayer.cs +++ b/OpenRA.Mods.Common/Traits/Minelayer.cs @@ -310,7 +310,7 @@ namespace OpenRA.Mods.Common.Traits protected override IEnumerable Render(WorldRenderer wr, World world) { yield break; } protected override IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { - var minelayer = minelayers.Find(m => m.IsInWorld && !m.IsDead); + var minelayer = minelayers.FirstOrDefault(m => m.IsInWorld && !m.IsDead); if (minelayer == null) yield break; diff --git a/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs index a79046b279..38f4f31b7f 100644 --- a/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ClassicParallelProductionQueue.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits if (allProductionPaused) return; - var item = Queue.Find(i => !i.Paused); + var item = Queue.FirstOrDefault(i => !i.Paused); if (item == null) return; diff --git a/OpenRA.Mods.Common/Traits/Player/GameSaveViewportManager.cs b/OpenRA.Mods.Common/Traits/Player/GameSaveViewportManager.cs index 880cb76b0b..16bacdbd46 100644 --- a/OpenRA.Mods.Common/Traits/Player/GameSaveViewportManager.cs +++ b/OpenRA.Mods.Common/Traits/Player/GameSaveViewportManager.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Traits; @@ -34,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits // TODO: This won't make sense for MP saves var localPlayer = worldRenderer.World.LocalPlayer; if ((localPlayer != null && localPlayer.PlayerActor != self) || - (localPlayer == null && self.Owner != Array.Find(self.World.Players, p => p.IsBot))) + (localPlayer == null && self.Owner != self.World.Players.FirstOrDefault(p => p.IsBot))) return null; var nodes = new List() diff --git a/OpenRA.Mods.Common/Traits/Player/ParallelProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ParallelProductionQueue.cs index d9e74d770f..6a1dfca704 100644 --- a/OpenRA.Mods.Common/Traits/Player/ParallelProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ParallelProductionQueue.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits { CancelUnbuildableItems(); - var item = Queue.Find(i => !i.Paused); + var item = Queue.FirstOrDefault(i => !i.Paused); if (item == null) return; diff --git a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs index fd6b6fb08c..949d1c8c67 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlaceBuilding.cs @@ -175,7 +175,7 @@ namespace OpenRA.Mods.Common.Traits .Where(p => p.AcceptsPlug(plugInfo.Type)) .ToList(); - var pluggable = pluggables.Find(p => a.Location + p.Info.Offset == targetLocation) + var pluggable = pluggables.FirstOrDefault(p => a.Location + p.Info.Offset == targetLocation) ?? pluggables.FirstOrDefault(); if (pluggable == null) diff --git a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs index 0de33915a9..4466b31e6e 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs @@ -515,7 +515,7 @@ namespace OpenRA.Mods.Common.Traits protected virtual void PauseProduction(string itemName, bool paused) { - Queue.Find(a => a.Item == itemName)?.Pause(paused); + Queue.FirstOrDefault(a => a.Item == itemName)?.Pause(paused); } protected virtual void CancelProduction(string itemName, uint numberToCancel) diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs index 81667a72b8..d68f8881dd 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SelectDirectionalTarget.cs @@ -151,7 +151,7 @@ namespace OpenRA.Mods.Common.Traits Arrow GetArrow(double degree) { - var arrow = Array.Find(directionArrows, d => d.EndAngle >= degree); + var arrow = directionArrows.FirstOrDefault(d => d.EndAngle >= degree); return arrow ?? directionArrows[0]; } diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs index f6996e7bba..15fd3c0fc1 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPowerManager.cs @@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Traits if (!Ready) return; - var power = Instances.Find(i => !i.IsTraitPaused); + var power = Instances.FirstOrDefault(i => !i.IsTraitPaused); if (power == null) return; diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs index ff83a0c110..e1acae47be 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs @@ -332,7 +332,7 @@ namespace OpenRA.Mods.Common.Traits public EditorActorPreview this[string id] { - get { return previews.Find(p => p.ID.Equals(id, StringComparison.OrdinalIgnoreCase)); } + get { return previews.FirstOrDefault(p => p.ID.Equals(id, StringComparison.OrdinalIgnoreCase)); } } } } diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs index d105535094..9b69258ce3 100644 --- a/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20231010/AbstractDocking.cs @@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules refineryNode.RemoveNode(dockOffsetNode); } - var buildingNode = actorNode.Value.Nodes.Find(n => buildings.Any(b => n.KeyMatches(b, includeRemovals: false))); + var buildingNode = actorNode.Value.Nodes.FirstOrDefault(n => buildings.Any(b => n.KeyMatches(b, includeRemovals: false))); if (buildingNode != null) { var dimensions = buildingNode.ChildrenMatching("Dimensions", includeRemovals: false).FirstOrDefault()?.NodeValue() ?? new CVec(1, 1); diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index 0a7283ded3..f667d8a5a7 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -9,7 +9,6 @@ */ #endregion -using System; using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.UpdateRules.Rules; @@ -99,7 +98,7 @@ namespace OpenRA.Mods.Common.UpdateRules if (namedType != null && namedType.IsSubclassOf(typeof(UpdateRule))) return new[] { (UpdateRule)objectCreator.CreateBasic(namedType) }; - return Array.Find(Paths, p => p.source == source)?.Rules(chain); + return Paths.FirstOrDefault(p => p.source == source)?.Rules(chain); } public static IEnumerable KnownPaths { get { return Paths.Select(p => p.source); } } diff --git a/OpenRA.Mods.Common/UtilityCommands/Utilities.cs b/OpenRA.Mods.Common/UtilityCommands/Utilities.cs index 95f36d1ebc..48e61433c3 100644 --- a/OpenRA.Mods.Common/UtilityCommands/Utilities.cs +++ b/OpenRA.Mods.Common/UtilityCommands/Utilities.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.UtilityCommands var fs = map ?? modData.DefaultFileSystem; var topLevelNodes = MiniYaml.Load(fs, manifestNodes, mapProperty); - return topLevelNodes.Find(n => n.Key == key); + return topLevelNodes.FirstOrDefault(n => n.Key == key); } } } diff --git a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs index 43724700ce..eeeb2a8069 100644 --- a/OpenRA.Mods.Common/Widgets/ButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ButtonWidget.cs @@ -247,8 +247,7 @@ namespace OpenRA.Mods.Common.Widgets var position = GetTextPosition(text, font, rb); - // PERF: Avoid LINQ by using Children.Find(...) != null instead of Children.Any(...) - var hover = Ui.MouseOverWidget == this || Children.Find(c => c == Ui.MouseOverWidget) != null; + var hover = Ui.MouseOverWidget == this || Children.FirstOrDefault(c => c == Ui.MouseOverWidget) != null; DrawBackground(rb, disabled, Depressed, hover, highlighted); if (Contrast) font.DrawTextWithContrast(text, position + stateOffset, diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index e0be9dc4e0..768b3cb983 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -146,8 +146,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (map.Package != null) { - selectedDirectory = writableDirectories.Find(k => k.Folder.Contains(map.Package.Name)); - selectedDirectory ??= writableDirectories.Find(k => Directory.GetDirectories(k.Folder.Name).Any(f => f.Contains(map.Package.Name))); + selectedDirectory = writableDirectories.FirstOrDefault(k => k.Folder.Contains(map.Package.Name)); + selectedDirectory ??= writableDirectories.FirstOrDefault(k => Directory.GetDirectories(k.Folder.Name).Any(f => f.Contains(map.Package.Name))); } // Prioritize MapClassification.User directories over system directories diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs index 64ce412f79..b09ce9ded8 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ClassicProductionLogic.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void SelectTab(bool reverse) { - palette.CurrentQueue = Array.Find(queues, q => q.Enabled); + palette.CurrentQueue = queues.FirstOrDefault(q => q.Enabled); // When a tab is selected, scroll to the top because the current row position may be invalid for the new tab palette.ScrollToTop(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs index 17519f3ac3..8131d86b87 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameInfoStatsLogic.cs @@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic } var localClient = orderManager.LocalClient; - var localPlayer = localClient == null ? null : Array.Find(world.Players, player => player.ClientIndex == localClient.Index); + var localPlayer = localClient == null ? null : world.Players.FirstOrDefault(player => player.ClientIndex == localClient.Index); bool LocalPlayerCanKick() => localClient != null && (Game.IsHost || ((!orderManager.LocalClient.IsObserver) && localPlayer.WinState == WinState.Undefined)); bool CanClientBeKicked(Session.Client client, Func isVoteKick) => diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs index 41cc86066b..9fcdbebcca 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/ModContentPromptLogic.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var downloadYaml = MiniYaml.Load(modFileSystem, content.Downloads, null); modFileSystem.UnmountAll(); - var download = downloadYaml.Find(n => n.Key == content.QuickDownload); + var download = downloadYaml.FirstOrDefault(n => n.Key == content.QuickDownload); if (download == null) throw new InvalidOperationException($"Mod QuickDownload `{content.QuickDownload}` definition not found."); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index b3582d65ac..ace279b627 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -274,7 +274,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var botTypes = map.PlayerActorInfo.TraitInfos().Select(t => t.Type); var options = new Dictionary>(); - var botController = orderManager.LobbyInfo.Clients.Find(c => c.IsAdmin); + var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots)) { var botOptions = new List() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 05ce5ada7f..a9e0da0f9b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic { foreach (var b in map.PlayerActorInfo.TraitInfos()) { - var botController = orderManager.LobbyInfo.Clients.Find(c => c.IsAdmin); + var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin); bots.Add(new SlotDropDownOption(b.Name, $"slot_bot {slot.PlayerReference} {botController.Index} {b.Type}", () => client != null && client.Bot == b.Type)); @@ -266,7 +266,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic static void ClearPlayerSpawnPoint(OrderManager orderManager, MapPreviewWidget mapPreview, MapPreview preview, MouseInput mi) { var selectedSpawn = DetermineSelectedSpawnPoint(mapPreview, preview, mi); - if (Game.IsHost || orderManager.LobbyInfo.Clients.Find(cc => cc.SpawnPoint == selectedSpawn) == orderManager.LocalClient) + if (Game.IsHost || orderManager.LobbyInfo.Clients.FirstOrDefault(cc => cc.SpawnPoint == selectedSpawn) == orderManager.LocalClient) orderManager.IssueOrder(Order.Command($"clear_spawn {selectedSpawn}")); } diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index 42bc19ef22..2b68c50ab7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -356,7 +356,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic gameModeDropdown.GetText = () => { - var item = categories.Find(m => m.Category == category); + var item = categories.FirstOrDefault(m => m.Category == category); if (item == default((string, int))) item.Category = TranslationProvider.GetString(NoMatches); diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index 3923e4542f..b6926cbdf3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -696,7 +696,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic void SelectFirstVisibleReplay() { - SelectReplay(replays.Find(r => replayState[r].Visible)); + SelectReplay(replays.FirstOrDefault(r => replayState[r].Visible)); } void SelectReplay(ReplayMetadata replay) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs index e1e691e0b3..f2bf3d3550 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[0]; + soundDevice = devices.FirstOrDefault(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/ResourcePreviewWidget.cs b/OpenRA.Mods.Common/Widgets/ResourcePreviewWidget.cs index 1f34d7f8f2..5a36e78c06 100644 --- a/OpenRA.Mods.Common/Widgets/ResourcePreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ResourcePreviewWidget.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Widgets { resourceType = value; if (resourceType != null) - resourceRenderer = Array.Find(resourceRenderers, r => r.ResourceTypes.Contains(resourceType)); + resourceRenderer = resourceRenderers.FirstOrDefault(r => r.ResourceTypes.Contains(resourceType)); else resourceRenderer = null; } diff --git a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs index 74e0eb4a4a..92faef6849 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollPanelWidget.cs @@ -283,7 +283,7 @@ namespace OpenRA.Mods.Common.Widgets public void ScrollToItem(string itemKey, bool smooth = false) { - var item = Children.Find(c => c is ScrollItemWidget si && si.ItemKey == itemKey); + var item = Children.FirstOrDefault(c => c is ScrollItemWidget si && si.ItemKey == itemKey); if (item != null) ScrollToItem(item, smooth); @@ -291,7 +291,7 @@ namespace OpenRA.Mods.Common.Widgets public void ScrollToSelectedItem() { - var item = Children.Find(c => c is ScrollItemWidget si && si.IsSelected()); + var item = Children.FirstOrDefault(c => c is ScrollItemWidget si && si.IsSelected()); if (item != null) ScrollToItem(item); @@ -468,7 +468,7 @@ namespace OpenRA.Mods.Common.Widgets if (collection != col) return; - var widget = Children.Find(w => widgetItemEquals(w, item)); + var widget = Children.FirstOrDefault(w => widgetItemEquals(w, item)); if (widget != null) RemoveChild(widget); }); diff --git a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs index 0eabbd17fa..f3c43a6abd 100644 --- a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs +++ b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs @@ -505,7 +505,7 @@ namespace OpenRA.Mods.D2k.UtilityCommands } // Get the first tileset template that contains the Frame ID of the original map's tile with the requested index - var template = tileSetsFromYaml.Find(x => ((DefaultTerrainTemplateInfo)x).Frames.Contains(tileIndex)); + var template = tileSetsFromYaml.FirstOrDefault(x => ((DefaultTerrainTemplateInfo)x).Frames.Contains(tileIndex)); // HACK: The arrakis.yaml tileset file seems to be missing some tiles, so just get a replacement for them // Also used for duplicate tiles that are taken from only tileset @@ -525,7 +525,7 @@ namespace OpenRA.Mods.D2k.UtilityCommands } var templateIndex = template.Id; - var frameIndex = Array.IndexOf(((DefaultTerrainTemplateInfo)template).Frames, tileIndex); + var frameIndex = ((DefaultTerrainTemplateInfo)template).Frames.IndexOf(tileIndex); return new TerrainTile(templateIndex, (byte)((frameIndex == -1) ? 0 : frameIndex)); } diff --git a/OpenRA.Platforms.Default/Sdl2Input.cs b/OpenRA.Platforms.Default/Sdl2Input.cs index 19cb6c53e0..0edbea1852 100644 --- a/OpenRA.Platforms.Default/Sdl2Input.cs +++ b/OpenRA.Platforms.Default/Sdl2Input.cs @@ -208,7 +208,7 @@ namespace OpenRA.Platforms.Default { var rawBytes = new byte[SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE]; unsafe { Marshal.Copy((IntPtr)e.text.text, rawBytes, 0, SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE); } - inputHandler.OnTextInput(Encoding.UTF8.GetString(rawBytes, 0, Array.IndexOf(rawBytes, (byte)0))); + inputHandler.OnTextInput(Encoding.UTF8.GetString(rawBytes, 0, rawBytes.IndexOf((byte)0))); break; }