From 3ad0d21e072c7461ea78a9a85111e6e19d3b0632 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 17 Apr 2025 17:46:05 +0200 Subject: Handle abandon game --- pkg/ui/views/game_moves.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'pkg/ui/views/game_moves.go') diff --git a/pkg/ui/views/game_moves.go b/pkg/ui/views/game_moves.go index 2fa7c9e..4ce3796 100644 --- a/pkg/ui/views/game_moves.go +++ b/pkg/ui/views/game_moves.go @@ -25,12 +25,15 @@ func (i item) FilterValue() string { return i.title } func (m *GameModel) getMoves() tea.Cmd { m.network.Server.OnReceiveFn = func(msg network.Message) { - moveStr := string(msg.Payload) - m.incomingMoves <- moveStr + payload := string(msg.Payload) + m.incomingMoves <- payload } return func() tea.Msg { move := <-m.incomingMoves + if move == "🏳️" { + return EndGameMsg{abandoned: true} + } return ChessMoveMsg(move) } } @@ -75,7 +78,7 @@ func (m GameModel) handleChessMoveMsg(msg ChessMoveMsg) (GameModel, tea.Cmd) { } if m.chessGame.Outcome() != chess.NoOutcome { - cmds = append(cmds, m.endGame()) + cmds = append(cmds, m.endGame(m.chessGame.Outcome().String())) } return m, tea.Batch(cmds...) -- cgit v1.2.3-18-g5258