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