@using Shogi.Contracts.Types; @using System.Text.Json;
@if (IsSpectating) { }
@for (var rank = 1; rank < 10; rank++) { foreach (var file in Files) { var position = $"{file}{rank}"; var piece = Session?.BoardState.Board[position]; var isSelected = piece != null && SelectedPosition == position;
@if (piece != null) { }
} }
9 8 7 6 5 4 3 2 1
A B C D E F G H I
@if (Session != null && UseSideboard == true) { }
@code { static readonly string[] Files = new[] { "A", "B", "C", "D", "E", "F", "G", "H", "I" }; /// /// When true, an icon is displayed indicating that the user is spectating. /// [Parameter] public bool IsSpectating { get; set; } = false; [Parameter] public WhichPlayer Perspective { get; set; } [Parameter] public Session? Session { get; set; } [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 bool IsMyTurn { get; set; } [Parameter] public bool UseSideboard { get; set; } = true; private IReadOnlyCollection opponentHand; private IReadOnlyCollection userHand; private string? userName; private string? opponentName; public GameBoardPresentation() { opponentHand = Array.Empty(); userHand = Array.Empty(); userName = string.Empty; opponentName = string.Empty; } protected override void OnParametersSet() { base.OnParametersSet(); if (Session == null) { opponentHand = Array.Empty(); userHand = Array.Empty(); userName = string.Empty; opponentName = string.Empty; } else { opponentHand = Perspective == WhichPlayer.Player1 ? this.Session.BoardState.Player2Hand : this.Session.BoardState.Player1Hand; userHand = Perspective == WhichPlayer.Player1 ? this.Session.BoardState.Player1Hand : this.Session.BoardState.Player2Hand; userName = Perspective == WhichPlayer.Player1 ? this.Session.Player1 : this.Session.Player2 ?? "Empty Seat"; opponentName = Perspective == WhichPlayer.Player1 ? this.Session.Player2 ?? "Empty Seat" : this.Session.Player1; } } private Action OnClickTileInternal(Piece? piece, string position) => () => OnClickTile?.Invoke(piece, position); private Action OnClickHandInternal(Piece piece) => () => OnClickHand?.Invoke(piece); private void OnClickJoinGameInternal() => OnClickJoinGame?.Invoke(); }