Add position to websocket message.
This commit is contained in:
parent
ff2ec599fe
commit
9fbffc61f9
@ -10,6 +10,7 @@ type WebsocketMessage struct {
|
||||
Move *types.Move `json:"move,omitempty"`
|
||||
Color *types.ChessColor `json:"color,omitempty"`
|
||||
Reason *string `json:"reason,omitempty"`
|
||||
Position *string `json:"position,omitempty"`
|
||||
}
|
||||
|
||||
type MessageType string
|
||||
|
@ -157,12 +157,12 @@ func (game Game) notifyPlayersAboutGameStart() error {
|
||||
}
|
||||
|
||||
func (game Game) broadcastMove(move types.Move) error {
|
||||
err := game.GetPlayer1().SendMove(move)
|
||||
err := game.GetPlayer1().SendMoveAndPosition(move, game.board.PGN())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = game.GetPlayer2().SendMove(move)
|
||||
err = game.GetPlayer2().SendMoveAndPosition(move, game.board.PGN())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (b *Board) pgn() string {
|
||||
func (b *Board) PGN() string {
|
||||
var pgn string
|
||||
var shortName string
|
||||
|
||||
|
@ -10,7 +10,7 @@ func Test_PGN_StartingPosition(t *testing.T) {
|
||||
board := newBoard()
|
||||
board.Init()
|
||||
|
||||
pgn := board.pgn()
|
||||
pgn := board.PGN()
|
||||
|
||||
assert.Equal(t,
|
||||
"RNBQKBNR/PPPPPPPP/--------/--------/--------/--------/pppppppp/rnbqkbnr",
|
||||
|
@ -36,10 +36,11 @@ func (p *Player) SetConnection(ctx context.Context, conn *websocket.Conn) {
|
||||
p.wsConnEstablished <- true
|
||||
}
|
||||
|
||||
func (p *Player) SendMove(move types.Move) error {
|
||||
func (p *Player) SendMoveAndPosition(move types.Move, boardPosition string) error {
|
||||
messageToSend, err := json.Marshal(api.WebsocketMessage{
|
||||
Type: api.MoveMessage,
|
||||
Move: &move,
|
||||
Position: &boardPosition,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println("Error while marshalling: ", err)
|
||||
|
Loading…
Reference in New Issue
Block a user