Replace some Where-FirstOrDefault chains with a single call to FirstOrDefault
This commit is contained in:
@@ -700,7 +700,7 @@ namespace OpenRA.Editor
|
|||||||
{
|
{
|
||||||
int imageLength = 0;
|
int imageLength = 0;
|
||||||
int type = surface1.Map.MapResources.Value[x, y].Type;
|
int type = surface1.Map.MapResources.Value[x, y].Type;
|
||||||
var template = surface1.ResourceTemplates.Where(a => a.Value.Info.ResourceType == type).FirstOrDefault().Value;
|
var template = surface1.ResourceTemplates.FirstOrDefault(a => a.Value.Info.ResourceType == type).Value;
|
||||||
if (type == 1)
|
if (type == 1)
|
||||||
imageLength = 12;
|
imageLength = 12;
|
||||||
else if (type == 2)
|
else if (type == 2)
|
||||||
|
|||||||
@@ -491,7 +491,7 @@ namespace OpenRA.Mods.RA.AI
|
|||||||
// Use of this function requires that one squad of this type. Hence it is a piece of shit
|
// Use of this function requires that one squad of this type. Hence it is a piece of shit
|
||||||
Squad GetSquadOfType(SquadType type)
|
Squad GetSquadOfType(SquadType type)
|
||||||
{
|
{
|
||||||
return squads.Where(s => s.type == type).FirstOrDefault();
|
return squads.FirstOrDefault(s => s.type == type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Squad RegisterNewSquad(SquadType type, Actor target)
|
Squad RegisterNewSquad(SquadType type, Actor target)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Orders
|
|||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var underCursor = world.ScreenMap.ActorsAt(mi)
|
var underCursor = world.ScreenMap.ActorsAt(mi)
|
||||||
.Where(a => a.Owner == world.LocalPlayer && a.HasTrait<T>()).FirstOrDefault();
|
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.HasTrait<T>());
|
||||||
|
|
||||||
if (underCursor != null)
|
if (underCursor != null)
|
||||||
yield return new Order(order, underCursor, false);
|
yield return new Order(order, underCursor, false);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Orders
|
|||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button == MouseButton.Left)
|
||||||
{
|
{
|
||||||
var underCursor = world.ScreenMap.ActorsAt(mi)
|
var underCursor = world.ScreenMap.ActorsAt(mi)
|
||||||
.Where(a => !world.FogObscures(a) && a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) && a.HasTrait<RepairableBuilding>()).FirstOrDefault();
|
.FirstOrDefault(a => !world.FogObscures(a) && a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) && a.HasTrait<RepairableBuilding>());
|
||||||
|
|
||||||
if (underCursor == null)
|
if (underCursor == null)
|
||||||
yield break;
|
yield break;
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
{
|
{
|
||||||
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
|
var options = new Dictionary<string, IEnumerable<DropDownOption>>();
|
||||||
|
|
||||||
var botController = orderManager.LobbyInfo.Clients.Where(c => c.IsAdmin).FirstOrDefault();
|
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||||
if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots))
|
if (orderManager.LobbyInfo.Slots.Values.Any(s => s.AllowBots))
|
||||||
{
|
{
|
||||||
var botOptions = new List<DropDownOption>(){ new DropDownOption()
|
var botOptions = new List<DropDownOption>(){ new DropDownOption()
|
||||||
@@ -467,7 +467,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
{
|
{
|
||||||
var slot = orderManager.LobbyInfo.FirstEmptySlot();
|
var slot = orderManager.LobbyInfo.FirstEmptySlot();
|
||||||
var bot = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
|
var bot = Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name).FirstOrDefault();
|
||||||
var botController = orderManager.LobbyInfo.Clients.Where(c => c.IsAdmin).FirstOrDefault();
|
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||||
if (slot != null && bot != null)
|
if (slot != null && bot != null)
|
||||||
orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot)));
|
orderManager.IssueOrder(Order.Command("slot_bot {0} {1} {2}".F(slot, botController.Index, bot)));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
|
foreach (var b in Rules.Info["player"].Traits.WithInterface<IBotInfo>().Select(t => t.Name))
|
||||||
{
|
{
|
||||||
var bot = b;
|
var bot = b;
|
||||||
var botController = orderManager.LobbyInfo.Clients.Where(c => c.IsAdmin).FirstOrDefault();
|
var botController = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.IsAdmin);
|
||||||
bots.Add(new SlotDropDownOption(bot,
|
bots.Add(new SlotDropDownOption(bot,
|
||||||
"slot_bot {0} {1} {2}".F(slot.PlayerReference, botController.Index, bot),
|
"slot_bot {0} {1} {2}".F(slot.PlayerReference, botController.Index, bot),
|
||||||
() => client != null && client.Bot == bot));
|
() => client != null && client.Bot == bot));
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
if (current == null)
|
if (current == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var actor = queue.Trait.AllItems().Where(a => a.Name == current.Item).FirstOrDefault();
|
var actor = queue.Trait.AllItems().FirstOrDefault(a => a.Name == current.Item);
|
||||||
if (actor == null)
|
if (actor == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -138,8 +138,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
var actor = world.Selection.Actors
|
var actor = world.Selection.Actors
|
||||||
.Where(a => a.Owner == world.LocalPlayer && !a.Destroyed)
|
.Where(a => a.Owner == world.LocalPlayer && !a.Destroyed)
|
||||||
.Select(a => Pair.New(a, a.TraitOrDefault<AutoTarget>()))
|
.Select(a => Pair.New(a, a.TraitOrDefault<AutoTarget>()))
|
||||||
.Where(a => a.Second != null)
|
.FirstOrDefault(a => a.Second != null);
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
if (actor.First == null)
|
if (actor.First == null)
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user