diff --git a/internal/client/application.go b/internal/client/application.go index a1fc7ef..3a8e3eb 100644 --- a/internal/client/application.go +++ b/internal/client/application.go @@ -7,7 +7,6 @@ import ( "fmt" "log/slog" "net" - "sync/atomic" "time" "github.com/gobwas/ws" @@ -61,10 +60,9 @@ type Application struct { stocks [4]int prices [4]int - gameStarted atomic.Bool - server network.Connection - errCh chan string - l *slog.Logger + server network.Connection + errCh chan string + l *slog.Logger } func NewApplication(l *slog.Logger) *Application { @@ -109,11 +107,6 @@ func (a *Application) initUI() { } // Successful login. a.lobby.Reset() - if a.gameStarted.Load() { - a.pages.SwitchToPage(gamePageName) - } else { - a.pages.SwitchToPage(lobbyPageName) - } }, func() { a.Stop() diff --git a/internal/client/event_handlers.go b/internal/client/event_handlers.go index 5dfe027..60ab65b 100644 --- a/internal/client/event_handlers.go +++ b/internal/client/event_handlers.go @@ -30,8 +30,7 @@ func (a *Application) handleStateUpdate(state *message.GameState) { // Readiness update. if !state.Started { - if a.gameStarted.Load() { - a.gameStarted.Store(false) + if page, _ := a.pages.GetFrontPage(); page == titlePageName || page == gamePageName { a.pages.SwitchToPage(lobbyPageName) } @@ -41,9 +40,8 @@ func (a *Application) handleStateUpdate(state *message.GameState) { return } - // Switch to main page if game started. - if !a.gameStarted.Load() { - a.gameStarted.Store(true) + // Switch to game page if game started. + if page, _ := a.pages.GetFrontPage(); page == titlePageName || page == lobbyPageName { a.pages.SwitchToPage(gamePageName) } @@ -53,7 +51,7 @@ func (a *Application) handleStateUpdate(state *message.GameState) { // Update local game data. if len(a.hand) == 0 || len(a.hand) != len(state.Player.Hand) { - // This is a little trick to only update the card list if the hand size did not change. + // This is a little trick to only update the actions display if the hand changed. // It prevents the list from scrolling to the top on each update made by other players. a.actions.Update(state.Player.Hand) }