diff options
-rw-r--r-- | pkg/ui/views/game.go | 8 | ||||
-rw-r--r-- | pkg/ui/views/game_api.go | 6 | ||||
-rw-r--r-- | pkg/ui/views/game_keymap.go | 3 | ||||
-rw-r--r-- | pkg/ui/views/game_moves.go | 2 |
4 files changed, 9 insertions, 10 deletions
diff --git a/pkg/ui/views/game.go b/pkg/ui/views/game.go index 8f63419..64e463b 100644 --- a/pkg/ui/views/game.go +++ b/pkg/ui/views/game.go @@ -106,11 +106,7 @@ func (m GameModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, cmd, m.updateMovesListCmd()) case EndGameMsg: if msg.abandoned { - if m.network.Me() == m.playerPeer(1) || m.network.Me() == m.playerPeer(3) { - m.game.Outcome = string(chess.WhiteWon) - } else { - m.game.Outcome = string(chess.BlackWon) - } + _ = m.getGame()() m, cmd = m.handleDatabaseGameMsg(*m.game) cmds = append(cmds, cmd) } @@ -143,7 +139,7 @@ func (m GameModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, m.getMoves(), m.updateMovesListCmd()) if m.chessGame.Outcome() != chess.NoOutcome { - cmds = append(cmds, m.endGame(m.chessGame.Outcome().String())) + cmds = append(cmds, m.endGame(m.chessGame.Outcome().String(), false)) } } } diff --git a/pkg/ui/views/game_api.go b/pkg/ui/views/game_api.go index 2f32f70..f39a771 100644 --- a/pkg/ui/views/game_api.go +++ b/pkg/ui/views/game_api.go @@ -88,7 +88,7 @@ type EndGameMsg struct { type RestoreGameMsg struct{} -func (m *GameModel) endGame(outcome string) tea.Cmd { +func (m *GameModel) endGame(outcome string, abandon bool) tea.Cmd { return func() tea.Msg { var game database.Game @@ -115,6 +115,10 @@ func (m *GameModel) endGame(outcome string) tea.Cmd { return err } + if abandon { + m.network.SendAll([]byte("abandon"), []byte("🏳️")) + } + return game } } diff --git a/pkg/ui/views/game_keymap.go b/pkg/ui/views/game_keymap.go index faf794a..677def4 100644 --- a/pkg/ui/views/game_keymap.go +++ b/pkg/ui/views/game_keymap.go @@ -44,8 +44,7 @@ func (m GameModel) handleKeyMsg(msg tea.KeyMsg) (GameModel, tea.Cmd) { outcome = string(chess.WhiteWon) } - m.network.SendAll([]byte("abandon"), []byte("🏳️")) - return m, m.endGame(outcome) + return m, m.endGame(outcome, true) } case key.Matches(msg, m.keys.Quit): return m, SwitchModelCmd(NewPlayModel(m.width, m.height)) diff --git a/pkg/ui/views/game_moves.go b/pkg/ui/views/game_moves.go index ed11d30..70b2dc7 100644 --- a/pkg/ui/views/game_moves.go +++ b/pkg/ui/views/game_moves.go @@ -84,7 +84,7 @@ func (m GameModel) handleChessMoveMsg(msg ChessMoveMsg) (GameModel, tea.Cmd) { cmds := []tea.Cmd{m.getMoves(), m.updateMovesListCmd()} if m.chessGame.Outcome() != chess.NoOutcome { - cmds = append(cmds, m.endGame(m.chessGame.Outcome().String())) + cmds = append(cmds, m.endGame(m.chessGame.Outcome().String(), false)) } return m, tea.Batch(cmds...) |