diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-18 16:09:32 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-18 16:09:32 +0200 |
commit | 7c5a6176b27b6b0c0c3ef8a4aedbdec871391a80 (patch) | |
tree | 5ebfc9b402b8aa941ab9617b5f3842071edafedf /pkg/ui/views/game_moves.go | |
parent | 0b4fb251efdfd2fba7cd6154f5f59bd61ede15f1 (diff) |
Add type on messages between peers
Diffstat (limited to 'pkg/ui/views/game_moves.go')
-rw-r--r-- | pkg/ui/views/game_moves.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/pkg/ui/views/game_moves.go b/pkg/ui/views/game_moves.go index daf24e6..ea1fa02 100644 --- a/pkg/ui/views/game_moves.go +++ b/pkg/ui/views/game_moves.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/boozec/rahanna/pkg/p2p" + "github.com/boozec/rahanna/pkg/ui/multiplayer" "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" "github.com/notnil/chess" @@ -25,16 +26,19 @@ func (i item) FilterValue() string { return i.title } func (m *GameModel) getMoves() tea.Cmd { m.network.AddReceiveFunction(func(msg p2p.Message) { - payload := string(msg.Payload) - m.incomingMoves <- payload + gm := multiplayer.GameMove{ + Type: msg.Type, + Payload: msg.Payload, + } + m.incomingMoves <- gm }) return func() tea.Msg { move := <-m.incomingMoves - if move == "🏳️" { + if multiplayer.MoveType(string(move.Type)) == multiplayer.AbandonGameMessage { return EndGameMsg{abandoned: true} } - return ChessMoveMsg(move) + return ChessMoveMsg(string(move.Payload)) } } |