This commit is contained in:
2023-01-28 13:21:47 -06:00
parent 11b387b928
commit 8a25c0ed35
26 changed files with 443 additions and 359 deletions

View File

@@ -1,9 +1,11 @@
@using Shogi.Contracts.Api
@using Shogi.Contracts.Socket;
@using Shogi.Contracts.Types;
@using System.Text.RegularExpressions;
@inject IShogiApi ShogiApi
@inject AccountState Account;
@inject PromotePrompt PromotePrompt;
@inject ShogiSocket ShogiSocket;
@if (session == null)
{
@@ -11,11 +13,11 @@
}
else if (isSpectating)
{
<SpectatorGameBoard Session="session" />
<SpectatorGameBoard Session="session" OnRefetchSession="RefetchSession" />
}
else
{
<SeatedGameBoard Perspective="perspective" Session="session" OnRefetchSession="RefetchSession" />
<SeatedGameBoard Perspective="perspective" Session="session" />
}
@@ -27,6 +29,13 @@ else
private WhichPlayer perspective;
private bool isSpectating;
protected override void OnInitialized()
{
base.OnInitialized();
ShogiSocket.OnPlayerMoved += OnPlayerMoved_RefetchSession;
ShogiSocket.OnSessionJoined +=
}
protected override async Task OnParametersSetAsync()
{
await RefetchSession();
@@ -34,7 +43,7 @@ else
async Task RefetchSession()
{
if (!string.IsNullOrWhiteSpace(SessionName))
if (!string.IsNullOrWhiteSpace(SessionName))
{
this.session = await ShogiApi.GetSession(SessionName);
if (this.session != null)
@@ -44,9 +53,18 @@ else
this.perspective = accountId == session.Player2 ? WhichPlayer.Player2 : WhichPlayer.Player1;
this.isSpectating = !(accountId == this.session.Player1 || accountId == this.session.Player2);
Console.WriteLine($"IsSpectating - {isSpectating}. AccountId - {accountId}. Player1 - {this.session.Player1}. Player2 - {this.session.Player2}");
}
StateHasChanged();
}
}
Task OnPlayerMoved_RefetchSession(PlayerHasMovedMessage args)
{
if (args.SessionName == SessionName)
{
return RefetchSession();
}
return Task.CompletedTask;
}
}