reintroduce microsoft login. upgrade a bunch of stuff.
This commit is contained in:
71
Shogi.UI/Pages/Home/GameBoard/SeatedGameBoard.razor
Normal file
71
Shogi.UI/Pages/Home/GameBoard/SeatedGameBoard.razor
Normal file
@@ -0,0 +1,71 @@
|
||||
@using Shogi.Contracts.Api;
|
||||
@using Shogi.Contracts.Types;
|
||||
@using System.Text.RegularExpressions;
|
||||
@inject PromotePrompt PromotePrompt;
|
||||
@inject IShogiApi ShogiApi;
|
||||
|
||||
<GameBoardPresentation OnClickHand="OnClickHand" OnClickTile="OnClickTile" Session="Session" Perspective="Perspective" />
|
||||
|
||||
@code {
|
||||
[Parameter] public WhichPlayer Perspective { get; set; }
|
||||
[Parameter] public Session Session { get; set; }
|
||||
private bool IsMyTurn => Session?.BoardState.WhoseTurn == Perspective;
|
||||
private string? selectedBoardPosition;
|
||||
private WhichPiece? selectedPieceFromHand;
|
||||
|
||||
bool ShouldPromptForPromotion(string position)
|
||||
{
|
||||
if (Perspective == WhichPlayer.Player1 && Regex.IsMatch(position, ".[7-9]"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (Perspective == WhichPlayer.Player2 && Regex.IsMatch(position, ".[1-3]"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async void OnClickTile(Piece? piece, string position)
|
||||
{
|
||||
if (!IsMyTurn) return;
|
||||
|
||||
if (selectedBoardPosition == null || piece?.Owner == Perspective)
|
||||
{
|
||||
// Select a position.
|
||||
selectedBoardPosition = position;
|
||||
return;
|
||||
}
|
||||
if (selectedBoardPosition == position)
|
||||
{
|
||||
// Deselect the selected position.
|
||||
selectedBoardPosition = null;
|
||||
return;
|
||||
}
|
||||
if (piece == null)
|
||||
{
|
||||
if (ShouldPromptForPromotion(position) || ShouldPromptForPromotion(selectedBoardPosition))
|
||||
{
|
||||
PromotePrompt.Show(Session.SessionName, new MovePieceCommand
|
||||
{
|
||||
From = selectedBoardPosition,
|
||||
To = position
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
await ShogiApi.Move(Session.SessionName, new MovePieceCommand
|
||||
{
|
||||
From = selectedBoardPosition,
|
||||
IsPromotion = false,
|
||||
To = position
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnClickHand(Piece piece)
|
||||
{
|
||||
selectedPieceFromHand = piece.WhichPiece;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user