@using Shogi.Contracts.Types; @using System.Text.Json; @inject PromotePrompt PromotePrompt; @inject AccountState AccountState;
@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;
} }
9 8 7 6 5 4 3 2 1
A B C D E F G H I

Do you wish to promote?

@if (Session != null) { }
@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; } 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 { Console.WriteLine(JsonSerializer.Serialize(new { this.Session.Player1, this.Session.Player2, Perspective, this.Session.SessionName })); 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.Name : this.Session.Player2?.Name ?? "Empty Seat"; opponentName = Perspective == WhichPlayer.Player1 ? this.Session.Player2?.Name ?? "Empty Seat" : this.Session.Player1.Name; } } private Action OnClickTileInternal(Piece? piece, string position) => () => OnClickTile?.Invoke(piece, position); private Action OnClickHandInternal(Piece piece) => () => OnClickHand?.Invoke(piece); private void OnClickJoinGameInternal() => OnClickJoinGame?.Invoke(); }