Switch from sending moves to sending state
This commit is contained in:
parent
6e66d892b5
commit
a6d8f47e8a
@ -161,20 +161,20 @@ func (game Game) notifyPlayersAboutGameStart() error {
|
||||
}
|
||||
|
||||
game.GetPlayer1().writeMessage(colorDeterminedPlayer1)
|
||||
game.GetPlayer1().SendBoardState(game.board.PGN(), types.White)
|
||||
game.GetPlayer1().SendBoardState(types.Move{}, game.board.PGN(), types.White)
|
||||
|
||||
game.GetPlayer2().writeMessage(colorDeterminedPlayer2)
|
||||
game.GetPlayer2().SendBoardState(game.board.PGN(), types.Black)
|
||||
game.GetPlayer2().SendBoardState(types.Move{}, game.board.PGN(), types.White)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (game Game) broadcastMove(move types.Move) error {
|
||||
err := game.GetPlayer1().SendMoveAndPosition(move, game.board.PGN())
|
||||
err := game.GetPlayer1().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.color)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = game.GetPlayer2().SendMoveAndPosition(move, game.board.PGN())
|
||||
err = game.GetPlayer2().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.color)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func (p *Player) SetWebsocketConnectionAndSendBoardState(
|
||||
turnColor types.ChessColor,
|
||||
) {
|
||||
p.SetWebsocketConnection(ctx, ws)
|
||||
p.SendBoardState(boardPosition, turnColor)
|
||||
p.SendBoardState(types.Move{}, boardPosition, turnColor)
|
||||
}
|
||||
|
||||
func (p *Player) SetDisconnectCallback(cb func(*Player)) {
|
||||
@ -62,13 +62,14 @@ func (p *Player) IsInGame() bool {
|
||||
return p.hasWebsocketConnection()
|
||||
}
|
||||
|
||||
func (p *Player) SendBoardState(boardPosition string, turnColor types.ChessColor) error {
|
||||
func (p *Player) SendBoardState(move types.Move, boardPosition string, turnColor types.ChessColor) error {
|
||||
var pColor = p.color
|
||||
if p.color == "" { // we default to white if we do not know the color yet
|
||||
pColor = types.White
|
||||
}
|
||||
|
||||
messageToSend, err := json.Marshal(api.WebsocketMessage{
|
||||
Move: &move,
|
||||
Type: api.BoardStateMessage,
|
||||
TurnColor: &turnColor,
|
||||
PlayerColor: &pColor,
|
||||
|
Loading…
Reference in New Issue
Block a user