Skip to content

Commit 65337cd

Browse files
committed
review mode: also show move numbers on empty fields
1 parent 429b05e commit 65337cd

File tree

5 files changed

+87
-66
lines changed

5 files changed

+87
-66
lines changed

src/main/client/src/component/SideBar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const SideBar = ({page, children}) => {
5353
return (
5454
<div
5555
style={{width: sidebarWidth + "px"}}
56-
className="absolute border-l border-gray-500 top-0 right-0 h-full bg-slate-800">
56+
className="fixed border-l border-gray-500 top-0 right-0 h-full bg-slate-800">
5757
<div
5858
onMouseDown={!dragging ? onMouseDown : undefined}
5959
style={{

src/main/client/src/feature/game/Game.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ function Board({gameState, setGameState}) {
367367
<div className="grid h-full">
368368
<canvas className={twJoin(
369369
"place-self-center",
370-
isCursorInBounds() && showMoveNumbers() && board[cursor_y][cursor_x].hasStone && "cursor-pointer",
370+
isCursorInBounds() && showMoveNumbers() && board[cursor_y][cursor_x].historyEntry.n !== -1 && "cursor-pointer",
371371
)}
372372
ref={canvasRef}
373373
onMouseLeave={() => {

src/main/client/src/feature/game/paint.js

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,10 @@ export function paintStones(context, board, showMoveNumbers) {
8383
let cursor_y = context.cursorYref.current
8484
for (let grid_y = 0; grid_y < board.length; grid_y++) {
8585
for (let grid_x = 0; grid_x < board.length; grid_x++) {
86-
let {hasStone, color} = board[grid_y][grid_x]
87-
if (!hasStone) {
88-
continue
89-
}
90-
if (showMoveNumbers && grid_x === cursor_x && grid_y === cursor_y) {
91-
paintShadow(context, grid_x, grid_y, color)
92-
} else {
86+
let {hasStone, color, historyEntry} = board[grid_y][grid_x]
87+
if (showMoveNumbers && historyEntry.n !== -1 && grid_x === cursor_x && grid_y === cursor_y) {
88+
paintShadow(context, grid_x, grid_y, historyEntry.color)
89+
} else if (hasStone) {
9390
paintStone(context, grid_x, grid_y, color)
9491
}
9592
}
@@ -99,11 +96,8 @@ export function paintStones(context, board, showMoveNumbers) {
9996
export function paintMoveNumbers(context, board) {
10097
for (let grid_y = 0; grid_y < board.length; grid_y++) {
10198
for (let grid_x = 0; grid_x < board.length; grid_x++) {
102-
let {hasStone, color, n} = board[grid_y][grid_x]
103-
if (!hasStone) {
104-
continue
105-
}
106-
paintMoveNumber(context, grid_x, grid_y, color, n + 1)
99+
let {color, historyEntry} = board[grid_y][grid_x]
100+
paintMoveNumber(context, grid_x, grid_y, color, historyEntry)
107101
}
108102
}
109103
}
@@ -113,20 +107,18 @@ export function paintStonesCounting(context, board, countingGroup, showMoveNumbe
113107
let cursor_y = context.cursorYref.current
114108
for (let grid_y = 0; grid_y < board.length; grid_y++) {
115109
for (let grid_x = 0; grid_x < board.length; grid_x++) {
116-
let {hasStone, color} = board[grid_y][grid_x]
117-
if (hasStone) {
118-
if (countingGroup && countingGroup(grid_x, grid_y)) {
119-
paintShadow(context, grid_x, grid_y, color)
120-
} else if (showMoveNumbers && grid_x === cursor_x && grid_y === cursor_y) {
121-
paintShadow(context, grid_x, grid_y, color)
122-
} else {
123-
paintStone(context, grid_x, grid_y, color)
124-
}
125-
}
126-
if (color & ANY_REMOVED) {
110+
let {hasStone, color, historyEntry} = board[grid_y][grid_x]
111+
let isHover = showMoveNumbers && historyEntry.n !== -1 && grid_x === cursor_x && grid_y === cursor_y
112+
if (countingGroup && countingGroup(grid_x, grid_y)) {
113+
paintShadow(context, grid_x, grid_y, color)
114+
} else if (isHover) {
115+
paintShadow(context, grid_x, grid_y, historyEntry.color)
116+
} else if (hasStone) {
117+
paintStone(context, grid_x, grid_y, color)
118+
} else if (color & ANY_REMOVED) {
127119
paintShadow(context, grid_x, grid_y, color)
128120
}
129-
if (color & TERRITORY) {
121+
if (color & TERRITORY && !isHover) {
130122
let style = (color & TERRITORY) === TERRITORY_B ?
131123
"rgba(0,0,0)" :
132124
"rgba(255,255,255)"
@@ -157,18 +149,31 @@ function paintStone({canvasRef, grid, stoneRadius}, grid_x, grid_y, color) {
157149
ctx.fill()
158150
}
159151

160-
function paintMoveNumber({stoneRadius, canvasRef, grid}, grid_x, grid_y, color, n) {
161-
let style = color === BLACK ?
162-
"rgba(255,255,255)" :
163-
"rgba(0,0,0)"
152+
function paintMoveNumber({cursorXref, cursorYref, stoneRadius, canvasRef, grid}, grid_x, grid_y, color, historyEntry) {
153+
if (historyEntry.n === -1) {
154+
return
155+
}
156+
let cursor_x = cursorXref.current
157+
let cursor_y = cursorYref.current
158+
let textColor
159+
if (cursor_x === grid_x && cursor_y === grid_y) {
160+
textColor = historyEntry.color === BLACK ?
161+
"rgba(255,255,255)" :
162+
"rgba(0,0,0)"
163+
} else {
164+
textColor = (color & (BLACK | TERRITORY_B)) ?
165+
"rgba(255,255,255)" :
166+
"rgba(0,0,0)"
167+
}
164168
let [x, y] = grid[grid_y][grid_x]
165-
let size = Math.trunc(stoneRadius * 0.75)
166169
let ctx = canvasRef.current.getContext("2d")
167-
ctx.font = size + "px sans-serif"
170+
ctx.font = (cursor_x === grid_x && cursor_y === grid_y) ?
171+
("bold " + Math.trunc(stoneRadius * 1.125) + "px sans-serif") :
172+
Math.trunc(stoneRadius * 0.75) + "px sans-serif"
168173
ctx.textBaseline = "middle"
169174
ctx.textAlign = "center"
170-
ctx.fillStyle = style
171-
ctx.fillText(n, x, y)
175+
ctx.fillStyle = textColor
176+
ctx.fillText(historyEntry.n + 1, x, y)
172177
}
173178

174179
export function paintLastMove({canvasRef, grid, stoneRadius}, lastMove) {

src/main/client/src/feature/game/state.js

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function initialState() {
3131
id: "",
3232
moves: [],
3333
baseBoard: [],
34-
countBoard: [],
34+
historyBoard: [],
3535
viewPos: Number.NaN,
3636
dim: 0,
3737
handicap: 0,
@@ -117,10 +117,10 @@ export function moveBack(baseState) {
117117
let moves = baseState.moves
118118
let move = moves[viewPos]
119119
let baseBoard = unApply(baseState.baseBoard, move)
120-
let countBoard = baseState.countBoard
120+
let historyBoard = baseState.historyBoard
121121
return produce(baseState, (draft) => {
122122
draft.baseBoard = baseBoard
123-
draft.board = cheapRehydrate(baseBoard, countBoard)
123+
draft.board = cheapRehydrate(baseBoard, historyBoard)
124124
draft.viewPos = viewPos
125125
if (viewPos) {
126126
let previous = moves[viewPos - 1]
@@ -139,10 +139,10 @@ export function moveForward(baseState) {
139139
let moves = baseState.moves
140140
let move = moves[viewPos]
141141
let [, updated] = updateBoard(baseState.baseBoard, move)
142-
let countBoard = baseState.countBoard
142+
let historyBoard = baseState.historyBoard
143143
return produce(baseState, (draft) => {
144144
draft.baseBoard = updated
145-
draft.board = cheapRehydrate(updated, countBoard)
145+
draft.board = cheapRehydrate(updated, historyBoard)
146146
draft.viewPos = viewPos + 1
147147
draft.lastMove = move.action === "pass" ? undefined : move
148148
})
@@ -152,21 +152,21 @@ function goToEnd(baseState) {
152152
let moves = baseState.moves
153153
let queueLength = baseState.queueLength
154154
let baseBoard = baseState.baseBoard
155-
let countBoard = baseState.countBoard
155+
let historyBoard = baseState.historyBoard
156156
for (let i = queueLength; i < moves.length; i++) {
157157
let move = moves[i]
158158
let previousMove = getMove(moves, i - 1)
159159
let [, updated] = updateBoardState(baseBoard, previousMove, move, true)
160160
baseBoard = updated
161161
}
162162
return produce(baseState, (draft) => {
163-
draft.board = rehydrate(baseBoard, countBoard)
163+
draft.board = rehydrate(baseBoard, historyBoard)
164164
})
165165
}
166166

167167
export function addMove(baseState, move) {
168168
let {action, n} = move
169-
let {moves, baseBoard, countBoard, counting, queueLength} = baseState
169+
let {moves, baseBoard, historyBoard, counting, queueLength} = baseState
170170
let previousMove = getMove(moves, n - 1)
171171
if (n < moves.length) {
172172
return baseState
@@ -191,9 +191,9 @@ export function addMove(baseState, move) {
191191
draft.moves.push(storedMove)
192192
draft.lastMove = action === "pass" ? undefined : storedMove
193193
draft.baseBoard = updated
194-
let updatedCountBoard = updateCountBoard(countBoard, move)
195-
draft.countBoard = updatedCountBoard
196-
draft.board = rehydrate(updated, updatedCountBoard)
194+
let updatedFinalBoard = counting ? historyBoard : updateHistoryBoard(historyBoard, move)
195+
draft.historyBoard = updatedFinalBoard
196+
draft.board = rehydrate(updated, updatedFinalBoard)
197197
draft.forbidden = forbidden
198198
if (action === "pass" && previousMove?.action === "pass") {
199199
draft.counting = true
@@ -203,10 +203,16 @@ export function addMove(baseState, move) {
203203

204204
export function createGameState(game, auth) {
205205
let baseBoard = Array(game.dim)
206-
let countBoard = Array(game.dim)
206+
let historyBoard = Array(game.dim)
207207
for (let y = 0; y < game.dim; y++) {
208208
baseBoard[y] = new Int32Array(game.dim)
209-
countBoard[y] = new Int32Array(game.dim)
209+
historyBoard[y] = []
210+
for (let x = 0; x < game.dim; x++) {
211+
historyBoard[y][x] = {
212+
n: -1,
213+
color: 0,
214+
}
215+
}
210216
}
211217
let moves = []
212218
let forbidden = [-1, -1]
@@ -223,15 +229,17 @@ export function createGameState(game, auth) {
223229
if (passes) {
224230
counting = true
225231
queueLength = move.n
226-
} else {
227-
passes = 1
228232
}
233+
passes = 1
229234
} else {
230235
passes = 0
231236
}
232237
let previousMove = getMove(moves, i - 1)
233238
let [storedMove, updated, newForbidden] = updateBoardState(baseBoard, previousMove, move, counting)
234-
countBoard[move.y][move.x] = move.n
239+
historyBoard[move.y][move.x] = {
240+
n: move.n,
241+
color: 0,
242+
}
235243
moves.push(storedMove)
236244
forbidden = newForbidden
237245
baseBoard = updated
@@ -244,9 +252,9 @@ export function createGameState(game, auth) {
244252
handicap: game.handicap,
245253
counting: counting,
246254
baseBoard: baseBoard,
247-
countBoard: countBoard,
255+
historyBoard: historyBoard,
248256
moves: moves,
249-
board: rehydrate(baseBoard, countBoard),
257+
board: rehydrate(baseBoard, historyBoard),
250258
forbidden: forbidden,
251259
viewPos: queueLength || moves.length,
252260
queueLength: queueLength || moves.length,
@@ -313,20 +321,20 @@ function unApply(board, move) {
313321
return result
314322
}
315323

316-
function cheapRehydrate(board, countBoard) {
317-
let dim = board.length
324+
function cheapRehydrate(baseBoard, historyBoard) {
325+
let dim = baseBoard.length
318326
let result = Array(dim)
319-
for (let i = 0; i < board.length; i++) {
327+
for (let i = 0; i < baseBoard.length; i++) {
320328
result[i] = Array(dim)
321329
}
322-
for (let y = 0; y < board.length; y++) {
323-
for (let x = 0; x < board[y].length; x++) {
330+
for (let y = 0; y < baseBoard.length; y++) {
331+
for (let x = 0; x < baseBoard[y].length; x++) {
324332
result[y][x] = {
325-
n: countBoard[y][x],
333+
historyEntry: historyBoard[y][x],
326334
x: x,
327335
y: y,
328-
color: board[y][x],
329-
hasStone: hasStone(board[y][x]),
336+
color: baseBoard[y][x],
337+
hasStone: hasStone(baseBoard[y][x]),
330338
isForbidden: () => false,
331339
liberties: 0,
332340
has: () => false,
@@ -347,9 +355,17 @@ function getMove(moves, i) {
347355
return moves[i]
348356
}
349357

350-
function updateCountBoard(countBoard, {x, y, n}) {
351-
let updated = countBoard.slice()
352-
updated[y] = countBoard[y].slice()
353-
updated[y][x] = n
358+
function updateHistoryBoard(historyBoard, move) {
359+
let {x, y, n, color, action} = move
360+
if (action) {
361+
return historyBoard
362+
}
363+
if (!color) {
364+
return historyBoard
365+
}
366+
let updated = historyBoard.slice()
367+
updated[y] = historyBoard[y].slice()
368+
let oldColor = updated[y][x].color
369+
updated[y][x] = {n, color: color || oldColor}
354370
return updated
355371
}

src/main/client/src/model/board.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function getGroupInfo(board, xx, yy) {
8383
}
8484
}
8585

86-
export function rehydrate(board, countBoard) {
86+
export function rehydrate(board, historyBoard) {
8787
let dim = board.length
8888
let result = Array(dim)
8989
for (let i = 0; i < board.length; i++) {
@@ -100,7 +100,7 @@ export function rehydrate(board, countBoard) {
100100
...groupInfo,
101101
x: xx,
102102
y: yy,
103-
n: countBoard[yy][xx],
103+
historyEntry: historyBoard[yy][xx],
104104
}
105105
})
106106
}

0 commit comments

Comments
 (0)