Skip to content

Commit 7a0262f

Browse files
committed
wip time
1 parent b0617d9 commit 7a0262f

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ export function Game() {
7979
function Board({gameState, setGameState}) {
8080
let [cursor_x, setCursor_x] = useState(-1)
8181
let [cursor_y, setCursor_y] = useState(-1)
82+
let [countdown, setCountdown] = useState(9)
83+
let countdownRef = useRef()
84+
countdownRef.current = countdown
8285
let [ctrlKeyDown, setCtrlKeyDown] = useState(false)
8386
let zoom = useViewStateStore(state => state.zoom)
8487
let {gameId} = useParams()
@@ -100,6 +103,18 @@ function Board({gameState, setGameState}) {
100103
let dragging = useLayoutStore(state => state.dragging)
101104
let muted = useMuteStore(state => state.muted)
102105
let howler = useRef()
106+
let showMoveNumbers = ctrlKeyDown && (isKibitz(gameState, auth) || gameHasEnded(gameState))
107+
108+
useEffect(() => {
109+
let intervalId = setInterval(() => {
110+
setCountdown(countdown => {
111+
if (countdown <= 1) {
112+
clearInterval(intervalId)
113+
}
114+
return countdown - 1
115+
})
116+
}, 1000)
117+
}, [setCountdown])
103118
let playClickSound = useCallback(() => {
104119
if (muted) {
105120
return
@@ -164,8 +179,6 @@ function Board({gameState, setGameState}) {
164179
return has
165180
}, [gameState, counting, board, isCursorInBounds])
166181

167-
let showMoveNumbers = ctrlKeyDown && (isKibitz(gameState, auth) || gameHasEnded(gameState))
168-
169182
let context = useMemo(() => {
170183
let dim = board.length
171184
if (!dim) {
@@ -224,6 +237,12 @@ function Board({gameState, setGameState}) {
224237
}
225238
}, [board, canvasRef, zoom])
226239

240+
useEffect(() => {
241+
if (!showMoveNumbers) {
242+
paintLastMove(context, lastMove, countdown)
243+
}
244+
}, [showMoveNumbers, context, lastMove, countdown])
245+
227246
let onMouseMove = useCallback((e) => {
228247
if (dragging) {
229248
return
@@ -312,7 +331,7 @@ function Board({gameState, setGameState}) {
312331
if (showMoveNumbers) {
313332
paintMoveNumbers(context, board)
314333
} else {
315-
paintLastMove(context, lastMove)
334+
paintLastMove(context, lastMove, countdownRef.current)
316335
}
317336
if (currentPlayer(gameState) !== auth.name) {
318337
return

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,26 @@ function paintMoveNumber({cursorXref, cursorYref, stoneRadius, canvasRef, grid},
174174
ctx.fillText(historyEntry.n + 1, x, y)
175175
}
176176

177-
export function paintLastMove({canvasRef, grid, stoneRadius}, lastMove) {
177+
export function paintLastMove(context, lastMove, countdown) {
178178
if (!lastMove) {
179179
return
180180
}
181+
let {canvasRef, grid, stoneRadius} = context
181182
let {x: grid_x, y: grid_y, color} = lastMove
182183
let style = color === BLACK ?
183184
"rgba(255,255,255)" :
184185
"rgba(0,0,0)"
186+
paintStone(context, grid_x, grid_y, color)
185187
let [x, y] = grid[grid_y][grid_x]
186188
let ctx = canvasRef.current.getContext("2d")
189+
if (countdown && countdown < 10 && countdown > 0) {
190+
ctx.font = "bold " + Math.trunc(stoneRadius * 1.125) + "px sans-serif"
191+
ctx.textBaseline = "middle"
192+
ctx.textAlign = "center"
193+
ctx.fillStyle = style
194+
ctx.fillText(countdown, x, y)
195+
return
196+
}
187197
let length = stoneRadius * 0.875
188198
ctx.fillStyle = style
189199
ctx.beginPath()

0 commit comments

Comments
 (0)