yep
This commit is contained in:
@@ -9,18 +9,26 @@
|
||||
Perspective="Perspective"
|
||||
OnClickHand="OnClickHand"
|
||||
OnClickTile="OnClickTile"
|
||||
OnClickJoinGame="OnClickJoinGame" />
|
||||
SelectedPosition="@selectedBoardPosition" />
|
||||
|
||||
@code {
|
||||
[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;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
base.OnParametersSet();
|
||||
if (Session == null)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(Session)} cannot be null.", nameof(Session));
|
||||
}
|
||||
}
|
||||
|
||||
bool ShouldPromptForPromotion(string position)
|
||||
{
|
||||
if (Perspective == WhichPlayer.Player1 && Regex.IsMatch(position, ".[7-9]"))
|
||||
@@ -36,12 +44,16 @@
|
||||
|
||||
async Task OnClickTile(Piece? piece, string position)
|
||||
{
|
||||
Console.WriteLine("Is my turn?");
|
||||
Console.WriteLine(true);
|
||||
if (!IsMyTurn) return;
|
||||
|
||||
if (selectedBoardPosition == null || piece?.Owner == Perspective)
|
||||
{
|
||||
// Select a position.
|
||||
Console.WriteLine("Position {0}", position);
|
||||
selectedBoardPosition = position;
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
if (selectedBoardPosition == position)
|
||||
@@ -77,16 +89,4 @@
|
||||
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