From 7c5a6176b27b6b0c0c3ef8a4aedbdec871391a80 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 18 Apr 2025 16:09:32 +0200 Subject: Add type on messages between peers --- pkg/ui/views/game_moves.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 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 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)) } } -- cgit v1.2.3-18-g5258