+
+
+ @if (showPromotePrompt)
+ {
+
+
+
+ }
+
@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.");
+ }
}
diff --git a/Shogi.UI/Pages/Play/GameBoard/SeatedGameBoard.razor.css b/Shogi.UI/Pages/Play/GameBoard/SeatedGameBoard.razor.css
new file mode 100644
index 0000000..05a3c33
--- /dev/null
+++ b/Shogi.UI/Pages/Play/GameBoard/SeatedGameBoard.razor.css
@@ -0,0 +1,14 @@
+.promote-prompt {
+ position: absolute;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ border: 2px solid #444;
+ padding: 1rem;
+ box-shadow: 1px 1px 1px #444;
+ text-align: center;
+ z-index: 101;
+
+ background-color: #444;
+ border: 1px solid black;
+}
\ No newline at end of file
diff --git a/Shogi.UI/Pages/Play/PromotePrompt.cs b/Shogi.UI/Pages/Play/PromotePrompt.cs
deleted file mode 100644
index 3bba99c..0000000
--- a/Shogi.UI/Pages/Play/PromotePrompt.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using Shogi.Contracts.Api;
-using Shogi.UI.Shared;
-
-namespace Shogi.UI.Pages.Play;
-
-public class PromotePrompt
-{
- private readonly ShogiApi shogiApi;
- private string? sessionName;
- private MovePieceCommand? command;
-
- public PromotePrompt(ShogiApi shogiApi)
- {
- this.shogiApi = shogiApi;
- this.IsVisible = false;
- this.OnClickCancel = this.Hide;
- }
-
- public bool IsVisible { get; private set; }
- public Action OnClickCancel;
- public Func