Yep
This commit is contained in:
@@ -2,16 +2,31 @@
|
||||
@using Shogi.Contracts.Types;
|
||||
@using System.Text.RegularExpressions;
|
||||
@using System.Net;
|
||||
@inject PromotePrompt PromotePrompt;
|
||||
@inject ShogiApi ShogiApi;
|
||||
|
||||
<GameBoardPresentation Session="Session"
|
||||
Perspective="Perspective"
|
||||
OnClickHand="OnClickHand"
|
||||
OnClickTile="OnClickTile"
|
||||
SelectedPosition="@selectedBoardPosition"
|
||||
SelectedPieceFromHand="@selectedPieceFromHand"
|
||||
IsMyTurn="IsMyTurn" />
|
||||
<div style="position: relative;">
|
||||
<GameBoardPresentation Session="Session"
|
||||
Perspective="Perspective"
|
||||
OnClickHand="OnClickHand"
|
||||
OnClickTile="OnClickTile"
|
||||
SelectedPosition="@selectedBoardPosition"
|
||||
SelectedPieceFromHand="@selectedPieceFromHand"
|
||||
IsMyTurn="IsMyTurn" />
|
||||
|
||||
@if (showPromotePrompt)
|
||||
{
|
||||
<!-- Promote prompt -->
|
||||
<!-- TODO: Add a background div which prevents mouse inputs to the board while this decision is being made. -->
|
||||
<section class="promote-prompt">
|
||||
<p>Do you wish to promote?</p>
|
||||
<div>
|
||||
<button type="button" @onclick="() => OnClickPromotionChoice(true)">Yes</button>
|
||||
<button type="button" @onclick="() => OnClickPromotionChoice(false)">No</button>
|
||||
<button type="button" @onclick="() => showPromotePrompt = false">Cancel</button>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
@@ -21,6 +36,8 @@
|
||||
private bool IsMyTurn => Session?.BoardState.WhoseTurn == Perspective;
|
||||
private string? selectedBoardPosition;
|
||||
private WhichPiece? selectedPieceFromHand;
|
||||
private bool showPromotePrompt;
|
||||
private string? moveTo;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
@@ -75,7 +92,7 @@
|
||||
{
|
||||
// Placing a piece from the hand to an empty space.
|
||||
var success = await ShogiApi.Move(
|
||||
Session.SessionId.ToString(),
|
||||
Session.SessionId,
|
||||
new MovePieceCommand(selectedPieceFromHand.Value, position));
|
||||
if (!success)
|
||||
{
|
||||
@@ -88,18 +105,24 @@
|
||||
|
||||
if (selectedBoardPosition != null)
|
||||
{
|
||||
Console.WriteLine("pieceAtPosition is null? {0}", pieceAtPosition == null);
|
||||
|
||||
if (pieceAtPosition == null || pieceAtPosition?.Owner != Perspective)
|
||||
{
|
||||
// Moving to an empty space or capturing an opponent's piece.
|
||||
if (ShouldPromptForPromotion(position) || ShouldPromptForPromotion(selectedBoardPosition))
|
||||
{
|
||||
PromotePrompt.Show(
|
||||
Session.SessionId.ToString(),
|
||||
new MovePieceCommand(selectedBoardPosition, position, false));
|
||||
Console.WriteLine("Prompt!");
|
||||
moveTo = position;
|
||||
showPromotePrompt = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var success = await ShogiApi.Move(Session.SessionId.ToString(), new MovePieceCommand(selectedBoardPosition, position, false));
|
||||
|
||||
Console.WriteLine("OnClick to move to {0}", position);
|
||||
var success = await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, position, false));
|
||||
|
||||
Console.WriteLine("Success? {0}", success);
|
||||
if (!success)
|
||||
{
|
||||
selectedBoardPosition = null;
|
||||
@@ -125,4 +148,14 @@
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private Task OnClickPromotionChoice(bool shouldPromote)
|
||||
{
|
||||
if (selectedBoardPosition == null && selectedPieceFromHand.HasValue && moveTo != null)
|
||||
{
|
||||
return ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedPieceFromHand.Value, moveTo));
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("Unexpected scenario during OnClickPromotionChoice.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user