checkpoint

This commit is contained in:
2021-11-10 18:46:29 -06:00
parent 2a3b7b32b4
commit 20f44c8b90
26 changed files with 519 additions and 407 deletions

View File

@@ -6,11 +6,11 @@
public class SessionMetadata
{
public string Name { get; }
public string Player1 { get; }
public string? Player2 { get; private set; }
public User Player1 { get; }
public User? Player2 { get; private set; }
public bool IsPrivate { get; }
public SessionMetadata(string name, bool isPrivate, string player1, string? player2 = null)
public SessionMetadata(string name, bool isPrivate, User player1, User? player2 = null)
{
Name = name;
IsPrivate = isPrivate;
@@ -25,11 +25,27 @@
Player2 = sessionModel.Player2;
}
public void SetPlayer2(string playerName)
public void SetPlayer2(User user)
{
Player2 = playerName;
Player2 = user;
}
public ServiceModels.Types.Game ToServiceModel() => new(Name, Player1, Player2);
public bool IsSeated(User user) => user.Id == Player1.Id || user.Id == Player2?.Id;
public ServiceModels.Types.Game ToServiceModel(User? user = null)
{
// TODO: Find a better way for the UI to know whether or not they are seated at a given game than client-side ID matching.
var player1 = Player1.DisplayName;
var player2 = Player2?.DisplayName;
if (user != null)
{
if (user.Id == Player1.Id) player1 = Player1.Id;
if (Player2 != null && user.Id == Player2.Id)
{
player2 = Player2.DisplayName;
}
}
return new(Name, player1, player2);
}
}
}