Refactor player setup.

Tweak how players in a world are created. Change the collection to be an array to more strongly imply it will not change during a game.
This commit is contained in:
RoosterDragon
2015-11-27 15:00:29 +00:00
parent 3e8df55bcb
commit 23a38a08f7
3 changed files with 26 additions and 12 deletions

View File

@@ -38,9 +38,14 @@ namespace OpenRA
public readonly MersenneTwister SharedRandom;
public readonly List<Player> Players = new List<Player>();
public Player[] Players = new Player[0];
public void SetPlayers(IEnumerable<Player> players, Player localPlayer)
{
Players = players.ToArray();
SetLocalPlayer(localPlayer);
}
public void AddPlayer(Player p) { Players.Add(p); }
public Player LocalPlayer { get; private set; }
public event Action GameOver = () => { };
@@ -82,12 +87,18 @@ namespace OpenRA
get { return LobbyInfo.GlobalSettings.AllowCheats || LobbyInfo.IsSinglePlayer; }
}
public void SetLocalPlayer(string pr)
void SetLocalPlayer(Player localPlayer)
{
if (localPlayer == null)
return;
if (!Players.Contains(localPlayer))
throw new ArgumentException("The local player must be one of the players in the world.", "localPlayer");
if (IsReplay)
return;
LocalPlayer = Players.FirstOrDefault(p => p.InternalName == pr);
LocalPlayer = localPlayer;
RenderPlayer = LocalPlayer;
}