protected async Task Edit()
        {
            var parameters = new ModalParameters();

            if (GameInformation.PlayersNotes.FirstOrDefault(e => e.NotedPlayerName == GamePlayer.Username) != null)
            {
                parameters.Add(nameof(EditNotes.CurrentNote),
                               GameInformation.PlayersNotes.First(e => e.NotedPlayerName == GamePlayer.Username).Description);
            }
            parameters.Add(nameof(EditNotes.NotedPlayerName), GamePlayer.Username);

            var formModal = ModalService.Show <EditNotes>("Edit Notes", parameters);
            var result    = await formModal.Result;

            if (result.Cancelled)
            {
                return;
            }

            GameInformation.PlayersNotes = (await PlayerNoteService.GetList()).PlayerNotes;
            StateHasChanged();
        }
Beispiel #2
0
        protected override async Task OnInitializedAsync()
        {
            AuthState = await AuthenticationStateProvider.GetAuthenticationStateAsync();

            _hubConnection = new HubConnectionBuilder()
                             .WithUrl(NavigationManager.ToAbsoluteUri("/gameHub"))
                             .Build();

            _hubConnection.On("ReceiveMessage", (object message) =>
            {
                var newMessage = JsonConvert.DeserializeObject <GetMessageResult>(message.ToString());
                ChatMessages.Add(newMessage);
                StateHasChanged();
            });

            _hubConnection.On("ReceiveStartingHand", (object hand) =>
            {
                var newHand = JsonConvert.DeserializeObject <List <Card> >(hand.ToString());
                GameInformation.Hand.AddRange(newHand);
                StateHasChanged();
            });

            _hubConnection.On("ReceiveTurnPlayer", (string currentPlayer) =>
            {
                GameInformation.CurrentPlayer = currentPlayer;
                StateHasChanged();
            });

            _hubConnection.On("ReceiveFlop", (object flopjson) =>
            {
                var flop = JsonConvert.DeserializeObject <List <Card> >(flopjson.ToString());
                GameInformation.TableCards.AddRange(flop);
                StateHasChanged();
            });

            _hubConnection.On("ReceiveTurnOrRiver", (object card) =>
            {
                var turnOrRiverCard = JsonConvert.DeserializeObject <List <Card> >(card.ToString());
                GameInformation.TableCards.AddRange(turnOrRiverCard);
                StateHasChanged();
            });


            _hubConnection.On("ReceiveWinner", (string winner) =>
            {
                GameInformation.Winner = winner;
                StateHasChanged();
            });


            _hubConnection.On("ReceiveStateRefresh", (object playerState) =>
            {
                var playerStateModel = JsonConvert.DeserializeObject <PlayerStateModel>(playerState.ToString());

                GameInformation.Players        = playerStateModel.Players;
                GameInformation.TableCards     = playerStateModel.CommunityCards ?? new List <Card>();
                GameInformation.Hand           = playerStateModel.HandCards ?? new List <Card>();
                GameInformation.GameInProgress = playerStateModel.GameInProgress;
                GameInformation.RaiseAmount    = playerStateModel.RaiseAmount;
                GameInformation.Pots           = playerStateModel.Pots ?? new List <Pot>();
                if (GameInformation.GameInProgress == false)
                {
                    foreach (var gameInformationPlayer in GameInformation.Players)
                    {
                        gameInformationPlayer.IsPlaying = false;
                    }
                }

                GameInformation.Winner = null;

                StateHasChanged();
            });

            _hubConnection.On("ReceiveKick", async() =>
            {
                await LocalStorageService.RemoveItemAsync("currentTable");
                NavigationManager.NavigateTo("/");
            });

            await _hubConnection.StartAsync();

            await _hubConnection.SendAsync("AddToUsers", await LocalStorageService.GetItemAsync <int>("currentTable"));

            GameInformation.PlayersNotes = (await PlayerNoteService.GetList()).PlayerNotes;

            await base.OnInitializedAsync();
        }