diff --git a/SlipItIn/SlipItIn.csproj b/SlipItIn/SlipItIn.csproj index 31c1665..153e893 100644 --- a/SlipItIn/SlipItIn.csproj +++ b/SlipItIn/SlipItIn.csproj @@ -104,4 +104,36 @@ Platforms\Android\AndroidManifest.Release.xml + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + + + 1 + + diff --git a/SlipItIn/ViewModels/GameBoardViewModel.cs b/SlipItIn/ViewModels/GameBoardViewModel.cs index 53e526d..4a333ba 100644 --- a/SlipItIn/ViewModels/GameBoardViewModel.cs +++ b/SlipItIn/ViewModels/GameBoardViewModel.cs @@ -23,31 +23,31 @@ public partial class GameBoardViewModel : BaseViewModel, private DateTime _lastStateUtc = DateTime.UtcNow; [ObservableProperty] - private int gameId; + private partial int GameId { get; set; } [ObservableProperty] - private int currentRound; + private partial int CurrentRound { get; set; } [ObservableProperty] - private int roundTimeRemaining; + private partial int RoundTimeRemaining { get; set; } [ObservableProperty] - private bool isChallengeVisible; + private partial bool IsConnected { get; set; } [ObservableProperty] - private SlipChallengeDto? pendingChallenge; + private partial bool IsSyncing { get; set; } [ObservableProperty] - private bool isConnected; + public partial bool IsChallengeVisible { get; set; } [ObservableProperty] - private bool isSyncing; + public partial SlipChallengeDto? PendingChallenge { get; set; } [ObservableProperty] - private string syncStatusText = "Bereit"; + public partial string SyncStatusText { get; set; } = "Bereit"; [ObservableProperty] - private int pendingSyncActions; + public partial int PendingSyncActions { get; set; } public ObservableCollection MyCards { get; } = []; public ObservableCollection OtherPlayers { get; } = []; @@ -233,12 +233,12 @@ public partial class GameBoardViewModel : BaseViewModel, public void Receive(SyncStateChangedMessage message) { - MainThread.BeginInvokeOnMainThread(() => + MainThread.BeginInvokeOnMainThread((Action)(() => { IsSyncing = message.Value.IsSyncing; SyncStatusText = message.Value.StatusText; PendingSyncActions = message.Value.PendingActions; - }); + })); } public void Receive(ConnectionStateChangedMessage message) diff --git a/SlipItIn/ViewModels/LobbyViewModel.cs b/SlipItIn/ViewModels/LobbyViewModel.cs index 12b26a0..911aada 100644 --- a/SlipItIn/ViewModels/LobbyViewModel.cs +++ b/SlipItIn/ViewModels/LobbyViewModel.cs @@ -22,25 +22,25 @@ public partial class LobbyViewModel : BaseViewModel, private readonly IApiService _apiService; [ObservableProperty] - private string lobbyCode = string.Empty; + public partial string LobbyCode { get; set; } = string.Empty; [ObservableProperty] - private int gameId; + public partial int GameId { get; set; } [ObservableProperty] - private bool isHost; + public partial bool IsHost { get; set; } [ObservableProperty] - private bool isConnected; + public partial bool IsConnected { get; set; } [ObservableProperty] - private bool isSyncing; + public partial bool IsSyncing { get; set; } [ObservableProperty] - private string syncStatusText = "Bereit"; + public partial string SyncStatusText { get; set; } = "Bereit"; [ObservableProperty] - private int pendingSyncActions; + public partial int PendingSyncActions { get; set; } public ObservableCollection Players { get; } = []; @@ -106,6 +106,9 @@ public partial class LobbyViewModel : BaseViewModel, if (GameId <= 0) throw new InvalidOperationException("Keine aktive Lobby gefunden."); + if (!CanStartGame) + throw new InvalidOperationException("Alle Spieler müssen bereit sein, bevor das Spiel gestartet werden kann."); + await _signalR.StartGameAsync(GameId); }); } @@ -133,6 +136,11 @@ public partial class LobbyViewModel : BaseViewModel, Players.Clear(); foreach (var player in message.Value.Players) Players.Add(player); + + var currentUsername = _authSession.CurrentUser?.Username; + IsCurrentPlayerReady = message.Value.Players.Any(p => + p.IsReady && string.Equals(p.Username, currentUsername, StringComparison.OrdinalIgnoreCase)); + CanStartGame = message.Value.Players.Count >= 2 && message.Value.Players.All(p => p.IsReady); }); } diff --git a/SlipItIn/ViewModels/LoginViewModel.cs b/SlipItIn/ViewModels/LoginViewModel.cs index 728afda..35d029e 100644 --- a/SlipItIn/ViewModels/LoginViewModel.cs +++ b/SlipItIn/ViewModels/LoginViewModel.cs @@ -14,10 +14,10 @@ public partial class LoginViewModel : BaseViewModel private readonly IGameStateService _gameStateService; [ObservableProperty] - private string email = string.Empty; + public partial string Email { get; set; } = string.Empty; [ObservableProperty] - private string password = string.Empty; + public partial string Password { get; set; } = string.Empty; public LoginViewModel(IApiService apiService, IAuthSessionService authSession, ISignalRService signalR, IGameStateService gameStateService) { diff --git a/SlipItIn/ViewModels/RegisterViewModel.cs b/SlipItIn/ViewModels/RegisterViewModel.cs index c859099..c0dacf5 100644 --- a/SlipItIn/ViewModels/RegisterViewModel.cs +++ b/SlipItIn/ViewModels/RegisterViewModel.cs @@ -13,13 +13,13 @@ public partial class RegisterViewModel : BaseViewModel private readonly ISignalRService _signalR; [ObservableProperty] - private string username = string.Empty; + public partial string Username { get; set; } = string.Empty; [ObservableProperty] - private string email = string.Empty; + public partial string Email { get; set; } = string.Empty; [ObservableProperty] - private string password = string.Empty; + public partial string Password { get; set; } = string.Empty; public RegisterViewModel(IApiService apiService, IAuthSessionService authSession, ISignalRService signalR) {