- @if (this.OnClickJoinGame != null && string.IsNullOrEmpty(Session.Player2) && !string.IsNullOrEmpty(Session.Player1))
+ @if (string.IsNullOrEmpty(Session.Player2) && !string.IsNullOrEmpty(Session.Player1))
{
@@ -121,9 +121,9 @@
[Parameter] public string? SelectedPosition { get; set; }
[Parameter] public WhichPiece? SelectedPieceFromHand { get; set; }
// TODO: Exchange these OnClick actions for events like "SelectionChangedEvent" and "MoveFromBoardEvent" and "MoveFromHandEvent".
- [Parameter] public Func
? OnClickTile { get; set; }
- [Parameter] public Func? OnClickHand { get; set; }
- [Parameter] public Func? OnClickJoinGame { get; set; }
+ [Parameter] public EventCallback OnClickTile { get; set; }
+ [Parameter] public EventCallback OnClickHand { get; set; }
+ [Parameter] public EventCallback OnClickJoinGame { get; set; }
[Parameter] public bool IsMyTurn { get; set; }
[Parameter] public bool UseSideboard { get; set; } = true;
@@ -167,7 +167,9 @@
}
}
- private Action OnClickTileInternal(Piece? piece, string position) => () => OnClickTile?.Invoke(piece, position);
- private Action OnClickHandInternal(Piece piece) => () => OnClickHand?.Invoke(piece);
- private void OnClickJoinGameInternal() => OnClickJoinGame?.Invoke();
+ private Func OnClickTileInternal(string position) => () => OnClickTile.InvokeAsync(position);
+
+ private Func OnClickHandInternal(Piece piece) => () => OnClickHand.InvokeAsync(piece);
+
+ private Task OnClickJoinGameInternal() => OnClickJoinGame.InvokeAsync();
}
diff --git a/Shogi.UI/Pages/Play/GameBoard/SeatedGameBoard.razor b/Shogi.UI/Pages/Play/GameBoard/SeatedGameBoard.razor
index 909dc79..1a2c285 100644
--- a/Shogi.UI/Pages/Play/GameBoard/SeatedGameBoard.razor
+++ b/Shogi.UI/Pages/Play/GameBoard/SeatedGameBoard.razor
@@ -50,7 +50,7 @@
}
}
- bool ShouldPromptForPromotion(string position)
+ bool IsWithinPromoteArea(string position)
{
if (Perspective == WhichPlayer.Player1 && Regex.IsMatch(position, ".[7-9]"))
{
@@ -63,11 +63,11 @@
return false;
}
- async Task OnClickTile(Piece? pieceAtPosition, string position)
+ async Task OnClickTile(string position)
{
- if (!IsMyTurn) return;
-
+ if (!IsMyTurn || showPromotePrompt) return;
+ var pieceAtPosition = Session.BoardState.Board[position];
if (selectedBoardPosition == position)
{
// Deselect the selected position.
@@ -105,12 +105,13 @@
if (selectedBoardPosition != null)
{
- Console.WriteLine("pieceAtPosition is null? {0}", pieceAtPosition == null);
-
if (pieceAtPosition == null || pieceAtPosition?.Owner != Perspective)
{
+ var pieceBeingMoved = Session.BoardState.Board[selectedBoardPosition];
+ var isPromotedAlready = pieceBeingMoved != null && pieceBeingMoved.IsPromoted;
+ Console.WriteLine("Is promoted? {0}", isPromotedAlready);
// Moving to an empty space or capturing an opponent's piece.
- if (ShouldPromptForPromotion(position) || ShouldPromptForPromotion(selectedBoardPosition))
+ if (!isPromotedAlready && (IsWithinPromoteArea(position) || IsWithinPromoteArea(selectedBoardPosition)))
{
Console.WriteLine("Prompt!");
moveTo = position;
@@ -118,11 +119,7 @@
}
else
{
-
- 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;
@@ -134,9 +131,9 @@
}
}
- async Task OnClickHand(Piece piece)
+ void OnClickHand(Piece piece)
{
- if (!IsMyTurn) return;
+ if (!IsMyTurn || showPromotePrompt) return;
// Prevent selecting from both the hand and the board.
selectedBoardPosition = null;
@@ -149,11 +146,13 @@
StateHasChanged();
}
- private Task OnClickPromotionChoice(bool shouldPromote)
+ private async Task OnClickPromotionChoice(bool shouldPromote)
{
- if (selectedBoardPosition == null && selectedPieceFromHand.HasValue && moveTo != null)
+ if (selectedBoardPosition != null && moveTo != null)
{
- return ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedPieceFromHand.Value, moveTo));
+ await ShogiApi.Move(Session.SessionId, new MovePieceCommand(selectedBoardPosition, moveTo, shouldPromote));
+ showPromotePrompt = false;
+ return;
}
throw new InvalidOperationException("Unexpected scenario during OnClickPromotionChoice.");
diff --git a/Shogi.UI/Pages/Play/GameBoard/TestCbParams.cs b/Shogi.UI/Pages/Play/GameBoard/TestCbParams.cs
new file mode 100644
index 0000000..df0d7dc
--- /dev/null
+++ b/Shogi.UI/Pages/Play/GameBoard/TestCbParams.cs
@@ -0,0 +1,7 @@
+namespace Shogi.UI.Pages.Play.GameBoard
+{
+ public class TestCbParams
+ {
+ public string Name { get; set; }
+ }
+}
diff --git a/Shogi.UI/Shogi.UI.csproj b/Shogi.UI/Shogi.UI.csproj
index a2cdee1..a44d5de 100644
--- a/Shogi.UI/Shogi.UI.csproj
+++ b/Shogi.UI/Shogi.UI.csproj
@@ -26,16 +26,16 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/Tests/AcceptanceTests/Shogi.AcceptanceTests.csproj b/Tests/AcceptanceTests/Shogi.AcceptanceTests.csproj
index 3d612b4..b84ee1c 100644
--- a/Tests/AcceptanceTests/Shogi.AcceptanceTests.csproj
+++ b/Tests/AcceptanceTests/Shogi.AcceptanceTests.csproj
@@ -25,20 +25,20 @@
-
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/Tests/UnitTests/UnitTests.csproj b/Tests/UnitTests/UnitTests.csproj
index 5572e69..69bf354 100644
--- a/Tests/UnitTests/UnitTests.csproj
+++ b/Tests/UnitTests/UnitTests.csproj
@@ -8,14 +8,14 @@
-
-
-
-
+
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all