Working on "Join Game" feature.
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
@using Shogi.Contracts.Api;
|
||||
@using Shogi.Contracts.Types;
|
||||
@using System.Text.RegularExpressions;
|
||||
@using System.Net;
|
||||
@inject PromotePrompt PromotePrompt;
|
||||
@inject IShogiApi ShogiApi;
|
||||
|
||||
<GameBoardPresentation OnClickHand="OnClickHand" OnClickTile="OnClickTile" Session="Session" Perspective="Perspective" />
|
||||
<GameBoardPresentation Session="Session"
|
||||
Perspective="Perspective"
|
||||
OnClickHand="OnClickHand"
|
||||
OnClickTile="OnClickTile"
|
||||
OnClickJoinGame="OnClickJoinGame" />
|
||||
|
||||
@code {
|
||||
[Parameter] public WhichPlayer Perspective { get; set; }
|
||||
[Parameter] public Session Session { get; set; }
|
||||
[Parameter, EditorRequired]
|
||||
public WhichPlayer Perspective { get; set; }
|
||||
[Parameter, EditorRequired]
|
||||
public Session Session { get; set; }
|
||||
[Parameter] public Func<Task>? OnRefetchSession { get; set; }
|
||||
private bool IsMyTurn => Session?.BoardState.WhoseTurn == Perspective;
|
||||
private string? selectedBoardPosition;
|
||||
private WhichPiece? selectedPieceFromHand;
|
||||
@@ -26,7 +34,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
async void OnClickTile(Piece? piece, string position)
|
||||
async Task OnClickTile(Piece? piece, string position)
|
||||
{
|
||||
if (!IsMyTurn) return;
|
||||
|
||||
@@ -64,8 +72,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
void OnClickHand(Piece piece)
|
||||
async Task OnClickHand(Piece piece)
|
||||
{
|
||||
selectedPieceFromHand = piece.WhichPiece;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
async Task OnClickJoinGame()
|
||||
{
|
||||
if (Session != null && OnRefetchSession != null)
|
||||
{
|
||||
var status = await ShogiApi.PatchJoinGame(Session.SessionName);
|
||||
if (status == HttpStatusCode.OK)
|
||||
{
|
||||
await OnRefetchSession.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user