Group pieces in the hand.
This commit is contained in:
@@ -11,13 +11,15 @@
|
||||
var position = $"{file}{rank}";
|
||||
var piece = Session?.BoardState.Board[position];
|
||||
var isSelected = piece != null && SelectedPosition == position;
|
||||
<div class="tile" @onclick="OnClickTileInternal(position)"
|
||||
<div class="tile"
|
||||
@onclick="OnClickTileInternal(position)"
|
||||
data-position="@(position)"
|
||||
data-selected="@(isSelected)"
|
||||
data-upsidedown="@(piece?.Owner != Perspective)"
|
||||
style="grid-area: @position">
|
||||
@if (piece != null)
|
||||
{
|
||||
<GamePiece Piece="piece" Perspective="Perspective" />
|
||||
<GamePiece Piece="piece.WhichPiece" IsPromoted="piece.IsPromoted" />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@@ -49,13 +51,27 @@
|
||||
<!-- Side board -->
|
||||
@if (Session != null && UseSideboard == true)
|
||||
{
|
||||
@* <aside class="side-board PrimaryTheme ThemeVariant--Contrast" style="grid-area: opponent-side-board"> *@
|
||||
@* @if (opponentHand.Any()) *@
|
||||
@* { *@
|
||||
@* @foreach (var piece in opponentHand) *@
|
||||
@* { *@
|
||||
@* <div class="tile" *@
|
||||
@* data-upsidedown="@(piece.Owner != Perspective)"> *@
|
||||
@* <GamePiece Piece="piece.WhichPiece" IsPromoted="false" /> *@
|
||||
@* </div> *@
|
||||
@* } *@
|
||||
@* } *@
|
||||
@* </aside> *@
|
||||
|
||||
<aside class="side-board PrimaryTheme ThemeVariant--Contrast" style="grid-area: opponent-side-board">
|
||||
@if (opponentHand.Any())
|
||||
@if (OpponentHandGrouped.Any())
|
||||
{
|
||||
@foreach (var piece in opponentHand)
|
||||
@foreach (var (whichPiece, count) in OpponentHandGrouped)
|
||||
{
|
||||
<div class="tile">
|
||||
<GamePiece Piece="piece" Perspective="Perspective" />
|
||||
<div class="tile"
|
||||
data-upsidedown>
|
||||
<GamePiece Piece="whichPiece" IsPromoted="false" Count="count"/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -90,7 +106,7 @@
|
||||
<div @onclick="OnClickHandInternal(piece)"
|
||||
class="tile"
|
||||
data-selected="@(piece.WhichPiece == SelectedPieceFromHand)">
|
||||
<GamePiece Piece="piece" Perspective="Perspective" />
|
||||
<GamePiece Piece="piece.WhichPiece" IsPromoted="false" />
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@@ -109,6 +125,7 @@
|
||||
</article>
|
||||
|
||||
@code {
|
||||
|
||||
static readonly string[] Files = new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I" };
|
||||
|
||||
/// <summary>
|
||||
@@ -164,11 +181,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Dictionary<WhichPiece, int> OpponentHandGrouped => opponentHand.GroupBy(piece => piece.WhichPiece).ToDictionary(grouping => grouping.Key, grouping => grouping.Count());
|
||||
private Dictionary<WhichPiece, int> PlayerHandGrouped => userHand.GroupBy(piece => piece.WhichPiece).ToDictionary(grouping => grouping.Key, grouping => grouping.Count());
|
||||
|
||||
private bool IsMyTurn => Session?.BoardState.WhoseTurn == Perspective;
|
||||
private bool IsPlayerInCheck => Session?.BoardState.PlayerInCheck == Perspective;
|
||||
private bool IsOpponentInCheck => Session?.BoardState.PlayerInCheck != null && Session.BoardState.PlayerInCheck != Perspective;
|
||||
private bool IsPlayerVictor => Session?.BoardState.Victor == Perspective;
|
||||
private bool IsOpponentVictor => Session?.BoardState.Victor != null && Session.BoardState.Victor != Perspective;
|
||||
|
||||
private Func<Task> OnClickTileInternal(string position) => () =>
|
||||
{
|
||||
if (IsMyTurn)
|
||||
@@ -177,6 +200,7 @@
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
};
|
||||
|
||||
private Func<Task> OnClickHandInternal(Piece piece) => () =>
|
||||
{
|
||||
if (IsMyTurn)
|
||||
|
||||
Reference in New Issue
Block a user