@@ -79,6 +79,9 @@ export function Game() {
79
79
function Board ( { gameState, setGameState} ) {
80
80
let [ cursor_x , setCursor_x ] = useState ( - 1 )
81
81
let [ cursor_y , setCursor_y ] = useState ( - 1 )
82
+ let [ countdown , setCountdown ] = useState ( 9 )
83
+ let countdownRef = useRef ( )
84
+ countdownRef . current = countdown
82
85
let [ ctrlKeyDown , setCtrlKeyDown ] = useState ( false )
83
86
let zoom = useViewStateStore ( state => state . zoom )
84
87
let { gameId} = useParams ( )
@@ -100,6 +103,18 @@ function Board({gameState, setGameState}) {
100
103
let dragging = useLayoutStore ( state => state . dragging )
101
104
let muted = useMuteStore ( state => state . muted )
102
105
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 ] )
103
118
let playClickSound = useCallback ( ( ) => {
104
119
if ( muted ) {
105
120
return
@@ -164,8 +179,6 @@ function Board({gameState, setGameState}) {
164
179
return has
165
180
} , [ gameState , counting , board , isCursorInBounds ] )
166
181
167
- let showMoveNumbers = ctrlKeyDown && ( isKibitz ( gameState , auth ) || gameHasEnded ( gameState ) )
168
-
169
182
let context = useMemo ( ( ) => {
170
183
let dim = board . length
171
184
if ( ! dim ) {
@@ -224,6 +237,12 @@ function Board({gameState, setGameState}) {
224
237
}
225
238
} , [ board , canvasRef , zoom ] )
226
239
240
+ useEffect ( ( ) => {
241
+ if ( ! showMoveNumbers ) {
242
+ paintLastMove ( context , lastMove , countdown )
243
+ }
244
+ } , [ showMoveNumbers , context , lastMove , countdown ] )
245
+
227
246
let onMouseMove = useCallback ( ( e ) => {
228
247
if ( dragging ) {
229
248
return
@@ -312,7 +331,7 @@ function Board({gameState, setGameState}) {
312
331
if ( showMoveNumbers ) {
313
332
paintMoveNumbers ( context , board )
314
333
} else {
315
- paintLastMove ( context , lastMove )
334
+ paintLastMove ( context , lastMove , countdownRef . current )
316
335
}
317
336
if ( currentPlayer ( gameState ) !== auth . name ) {
318
337
return
0 commit comments