1
0
mirror of https://github.com/maaslalani/gambit.git synced 2024-12-26 20:54:07 +02:00

refactor: turn (bool) -> whiteToMove

This commit is contained in:
Maas Lalani 2022-02-14 21:35:07 -05:00
parent 55180c8580
commit 5ea9a96daa
No known key found for this signature in database
GPG Key ID: 5A6ED5CBF1A0A000

View File

@ -6,7 +6,6 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/maaslalani/gambit/game"
"github.com/maaslalani/gambit/style"
)
// NoteMsg is a message that is sent to the client when a message is added to
@ -21,7 +20,7 @@ type SharedGame struct {
note string
turn bool
observer bool
roomTurn *bool
whiteToMove *bool
sync chan tea.Msg
}
@ -34,7 +33,7 @@ func NewSharedGame(p *Player, sync chan tea.Msg, roomTurn *bool, turn, observer
game: g,
turn: turn,
observer: observer,
roomTurn: roomTurn,
whiteToMove: roomTurn,
sync: sync,
}
return r
@ -71,7 +70,7 @@ func (r *SharedGame) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
r.note = string(msg)
return r, nil
case tea.MouseMsg:
if !r.observer && r.turn == *r.roomTurn {
if !r.observer && r.turn == *r.whiteToMove {
if msg.Type != tea.MouseLeft {
return r, nil
}
@ -91,14 +90,14 @@ func (r *SharedGame) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd)
r.game = g.(*game.Game)
default:
if !r.observer && r.turn == *r.roomTurn {
if !r.observer && r.turn == *r.whiteToMove {
g, cmd := r.game.Update(msg)
cmds = append(cmds, cmd)
r.game = g.(*game.Game)
}
}
default:
if !r.observer && r.turn == *r.roomTurn {
if !r.observer && r.turn == *r.whiteToMove {
g, cmd := r.game.Update(msg)
cmds = append(cmds, cmd)
r.game = g.(*game.Game)
@ -115,25 +114,5 @@ func (r *SharedGame) View() string {
s.WriteString("\n")
s.WriteString(r.note)
}
s.WriteString("\n")
s.WriteString(style.Faint(r.renderInfo()))
s.WriteString("\n")
return s.String()
}
// renderInfo returns information about the game.
func (r *SharedGame) renderInfo() string {
s := strings.Builder{}
turn := "Black"
if *r.roomTurn {
turn = "White"
}
fmt.Fprintf(&s, "ID: %s\n", r.player.room.id)
fmt.Fprintf(&s, "Turn: %s\n", turn)
fmt.Fprintf(&s, "User: %s\n", r.player)
os := r.player.room.ObserversCount()
if os > 0 {
fmt.Fprintf(&s, "Observers: %d", os)
}
return s.String()
}