Skip to content

Commit

Permalink
Fix viewer wrong side
Browse files Browse the repository at this point in the history
  • Loading branch information
qnkhuat committed Apr 4, 2021
1 parent 319b594 commit 6877302
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ func (cl *Client) renderBoard() {
for f = 0; f <= numcols; f++ {
if f == 0 && r != numrows { // draw rank square
var rank chess.Rank
if cl.Role == White {
// flip if it's black
if cl.Role == White || cl.Role == Viewer {
rank = chess.Rank(numrows - r - 1)
} else {
rank = chess.Rank(r)
Expand Down Expand Up @@ -626,7 +627,7 @@ func (cl *Client) HandleRead() {
}
func (cl *Client) posToSquare(row, col int) chess.Square {
// A1 is square 0
if cl.Role == White { // decending order if is white
if cl.Role == White || cl.Role == Viewer { // decending order if is white
row = numrows - row - 1
}
col = col - 1 // 1 column for the rank
Expand All @@ -636,7 +637,7 @@ func (cl *Client) posToSquare(row, col int) chess.Square {
func (cl *Client) squareToPos(sq chess.Square) (int, int) {
col := int(sq.File()) + 1
row := int(sq.Rank())
if cl.Role == White {
if cl.Role == White || cl.Role == Viewer {
row = numrows - row - 1
}
return row, col
Expand Down

0 comments on commit 6877302

Please sign in to comment.