52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
namespace Gameboard.ShogiUI.Sockets.Models
|
|
{
|
|
/// <summary>
|
|
/// A representation of a Session without the board and game-rules.
|
|
/// </summary>
|
|
public class SessionMetadata
|
|
{
|
|
public string Name { get; }
|
|
public User Player1 { get; }
|
|
public User? Player2 { get; private set; }
|
|
public bool IsPrivate { get; }
|
|
|
|
public SessionMetadata(string name, bool isPrivate, User player1, User? player2 = null)
|
|
{
|
|
Name = name;
|
|
IsPrivate = isPrivate;
|
|
Player1 = player1;
|
|
Player2 = player2;
|
|
}
|
|
public SessionMetadata(Session sessionModel)
|
|
{
|
|
Name = sessionModel.Name;
|
|
IsPrivate = sessionModel.IsPrivate;
|
|
Player1 = sessionModel.Player1;
|
|
Player2 = sessionModel.Player2;
|
|
}
|
|
|
|
public void SetPlayer2(User user)
|
|
{
|
|
Player2 = user;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|