Use Tuple syntax

This commit is contained in:
teinarss
2020-08-02 13:41:03 +02:00
committed by Paul Chote
parent 8a74f6ea18
commit 19b02875c7
90 changed files with 738 additions and 826 deletions

View File

@@ -78,12 +78,12 @@ namespace OpenRA.Mods.Common.Traits
var myTeam = self.World.LobbyInfo.ClientWithIndex(self.Owner.ClientIndex).Team;
var teams = self.World.Players.Where(p => !p.NonCombatant && p.Playable)
.Select(p => new Pair<Player, PlayerStatistics>(p, p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.Second != null ? p.Second.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.First.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.Second != null ? gg.Second.Experience : 0));
.Select(p => (Player: p, PlayerStatistics: p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.PlayerStatistics != null ? p.PlayerStatistics.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics != null ? gg.PlayerStatistics.Experience : 0));
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().First == self.Owner))
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().Player == self.Owner))
{
mo.MarkCompleted(self.Owner, objectiveID);
return;

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
public class GrantConditionOnPrerequisiteManager : ITechTreeElement
{
readonly Actor self;
readonly Dictionary<string, List<Pair<Actor, GrantConditionOnPrerequisite>>> upgradables = new Dictionary<string, List<Pair<Actor, GrantConditionOnPrerequisite>>>();
readonly Dictionary<string, List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)>> upgradables = new Dictionary<string, List<(Actor, GrantConditionOnPrerequisite)>>();
readonly TechTree techTree;
public GrantConditionOnPrerequisiteManager(ActorInitializer init)
@@ -44,11 +44,11 @@ namespace OpenRA.Mods.Common.Traits
var key = MakeKey(prerequisites);
if (!upgradables.ContainsKey(key))
{
upgradables.Add(key, new List<Pair<Actor, GrantConditionOnPrerequisite>>());
upgradables.Add(key, new List<(Actor, GrantConditionOnPrerequisite)>());
techTree.Add(key, prerequisites, 0, this);
}
upgradables[key].Add(Pair.New(actor, u));
upgradables[key].Add((actor, u));
// Notify the current state
u.PrerequisitesUpdated(actor, techTree.HasPrerequisites(prerequisites));
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
var key = MakeKey(prerequisites);
var list = upgradables[key];
list.RemoveAll(x => x.First == actor && x.Second == u);
list.RemoveAll(x => x.Actor == actor && x.GrantConditionOnPrerequisite == u);
if (!list.Any())
{
upgradables.Remove(key);
@@ -69,22 +69,22 @@ namespace OpenRA.Mods.Common.Traits
public void PrerequisitesAvailable(string key)
{
List<Pair<Actor, GrantConditionOnPrerequisite>> list;
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
if (!upgradables.TryGetValue(key, out list))
return;
foreach (var u in list)
u.Second.PrerequisitesUpdated(u.First, true);
u.GrantConditionOnPrerequisite.PrerequisitesUpdated(u.Actor, true);
}
public void PrerequisitesUnavailable(string key)
{
List<Pair<Actor, GrantConditionOnPrerequisite>> list;
List<(Actor Actor, GrantConditionOnPrerequisite GrantConditionOnPrerequisite)> list;
if (!upgradables.TryGetValue(key, out list))
return;
foreach (var u in list)
u.Second.PrerequisitesUpdated(u.First, false);
u.GrantConditionOnPrerequisite.PrerequisitesUpdated(u.Actor, false);
}
public void PrerequisitesItemHidden(string key) { }

View File

@@ -119,16 +119,16 @@ namespace OpenRA.Mods.Common.Traits
foreach (var t in BuildingUtils.GetLineBuildCells(w, targetLocation, actorInfo, buildingInfo, order.Player))
{
if (t.First == targetLocation)
if (t.Cell == targetLocation)
continue;
w.CreateActor(t.First == targetLocation ? actorInfo.Name : segmentType, new TypeDictionary
w.CreateActor(t.Cell == targetLocation ? actorInfo.Name : segmentType, new TypeDictionary
{
new LocationInit(t.First),
new LocationInit(t.Cell),
new OwnerInit(order.Player),
new FactionInit(faction),
new LineBuildDirectionInit(t.First.X == targetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X),
new LineBuildParentInit(new[] { t.Second, placed }),
new LineBuildDirectionInit(t.Cell.X == targetLocation.X ? LineBuildDirection.Y : LineBuildDirection.X),
new LineBuildParentInit(new[] { t.Actor, placed }),
new PlaceBuildingInit()
});
}

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public bool IsInitialized { get; private set; }
readonly World world;
CellLayer<Pair<int, int>> terrainColor;
CellLayer<(int, int)> terrainColor;
readonly Shroud shroud;
public event Action<MPos> CellTerrainColorChanged = null;
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World w, WorldRenderer wr)
{
terrainColor = new CellLayer<Pair<int, int>>(w.Map);
terrainColor = new CellLayer<(int, int)>(w.Map);
w.AddFrameEndTask(_ =>
{
@@ -82,22 +82,22 @@ namespace OpenRA.Mods.Common.Traits
});
}
public Pair<int, int> this[MPos uv]
public (int Left, int Right) this[MPos uv]
{
get { return terrainColor[uv]; }
}
public static Pair<int, int> GetColor(Map map, MPos uv)
public static (int Left, int Right) GetColor(Map map, MPos uv)
{
var custom = map.CustomTerrain[uv];
if (custom != byte.MaxValue)
{
var c = map.Rules.TileSet[custom].Color.ToArgb();
return Pair.New(c, c);
return (c, c);
}
var tc = map.GetTerrainColorPair(uv);
return Pair.New(tc.First.ToArgb(), tc.Second.ToArgb());
return (tc.Left.ToArgb(), tc.Right.ToArgb());
}
}
}

View File

@@ -119,12 +119,12 @@ namespace OpenRA.Mods.Common.Traits
var myTeam = self.World.LobbyInfo.ClientWithIndex(self.Owner.ClientIndex).Team;
var teams = self.World.Players.Where(p => !p.NonCombatant && p.Playable)
.Select(p => new Pair<Player, PlayerStatistics>(p, p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.Second != null ? p.Second.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.First.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.Second != null ? gg.Second.Experience : 0));
.Select(p => (Player: p, PlayerStatistics: p.PlayerActor.TraitOrDefault<PlayerStatistics>()))
.OrderByDescending(p => p.PlayerStatistics != null ? p.PlayerStatistics.Experience : 0)
.GroupBy(p => (self.World.LobbyInfo.ClientWithIndex(p.Player.ClientIndex) ?? new Session.Client()).Team)
.OrderByDescending(g => g.Sum(gg => gg.PlayerStatistics != null ? gg.PlayerStatistics.Experience : 0));
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().First == self.Owner))
if (teams.First().Key == myTeam && (myTeam != 0 || teams.First().First().Player == self.Owner))
{
mo.MarkCompleted(self.Owner, objectiveID);
return;