From deda60127ff4a585e4fb19d9f524de5f4a4047cf Mon Sep 17 00:00:00 2001 From: jbock Date: Wed, 25 Sep 2024 10:25:39 +0200 Subject: [PATCH] use timesetting from server --- src/main/client/src/feature/game/Game.jsx | 8 +- .../client/src/feature/game/GamePanel.jsx | 6 +- src/main/client/src/feature/lobby/Lobby.jsx | 96 ++++++++++--------- src/main/client/src/store.js | 1 - 4 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/main/client/src/feature/game/Game.jsx b/src/main/client/src/feature/game/Game.jsx index 26d238a..64e5554 100644 --- a/src/main/client/src/feature/game/Game.jsx +++ b/src/main/client/src/feature/game/Game.jsx @@ -84,7 +84,7 @@ function Board({gameState, setGameState}) { let [cursor_x, setCursor_x] = useState(-1) let [cursor_y, setCursor_y] = useState(-1) let timeout = useTimeoutStore(state => state.timeout) - let fulltime = useTimeoutStore(state => state.fulltime) + let timesetting = gameState.timesetting let setTimeout = useTimeoutStore(state => state.setTimeout) let timeoutRef = useRef() timeoutRef.current = timeout @@ -119,7 +119,7 @@ function Board({gameState, setGameState}) { if (intervalIdRef.current) { clearInterval(intervalIdRef.current) } - setTimeout(fulltime) + setTimeout(timesetting) intervalIdRef.current = setInterval(() => { let t = timeoutRef.current - 1 setTimeout(t) @@ -131,7 +131,7 @@ function Board({gameState, setGameState}) { } }, 1000) - }, [setTimeout, fulltime, setGameState]) + }, [setTimeout, timesetting, setGameState]) useEffect(() => { resetCountdown() @@ -372,7 +372,7 @@ function Board({gameState, setGameState}) { if (board[cursor_y][cursor_x].isForbidden(currentColor(gameState))) { return } - if (cursor_x == forbidden_x && cursor_y == forbidden_y) { + if (cursor_x === forbidden_x && cursor_y === forbidden_y) { return } if (!showMoveNumbers && !counting && !end) { diff --git a/src/main/client/src/feature/game/GamePanel.jsx b/src/main/client/src/feature/game/GamePanel.jsx index c045d0e..302bdca 100644 --- a/src/main/client/src/feature/game/GamePanel.jsx +++ b/src/main/client/src/feature/game/GamePanel.jsx @@ -87,7 +87,7 @@ function WhoIsWho({gameState}) { let {black, white, counting} = gameState let end = gameHasEnded(gameState) let timeout = useTimeoutStore(state => state.timeout) - let fulltime = useTimeoutStore(state => state.fulltime) + let timesetting = gameState.timesetting let color = currentColor(gameState) let navigate = useNavigate() let onExit = useCallback(() => { @@ -107,9 +107,9 @@ function WhoIsWho({gameState}) { -
{!counting && !end && color === WHITE ? timeout : fulltime}
+
{!counting && !end && color === WHITE ? timeout : timesetting}
-
{!counting && !end && color === BLACK ? timeout : fulltime}
+
{!counting && !end && color === BLACK ? timeout : timesetting}
diff --git a/src/main/client/src/feature/lobby/Lobby.jsx b/src/main/client/src/feature/lobby/Lobby.jsx index d61bebb..0f1cae0 100644 --- a/src/main/client/src/feature/lobby/Lobby.jsx +++ b/src/main/client/src/feature/lobby/Lobby.jsx @@ -133,7 +133,7 @@ export function Lobby() { function NewGameDialog({onNewGame, onStartEdit, setNewGameOpen, newGameRef}) { let dimRef = useRef(9) - let timeRef = useRef(0) + let timeRef = useRef(10) let [edit, setEdit] = useState(false) return (
{ @@ -145,56 +145,60 @@ function NewGameDialog({onNewGame, onStartEdit, setNewGameOpen, newGameRef}) { onNewGame(game) } }}> -
-
-
- +
+
+ +
+
+ Board Dimension: +
+
+
+ dimRef.current = 9} /> + +
+
+ dimRef.current = 13} /> + +
+
+ dimRef.current = 19} /> +
-
-
- -
-
- dimRef.current = 9} /> - -
-
- dimRef.current = 13} /> - -
-
- dimRef.current = 19} /> - -
-
- -
-
- timeRef.current = 0} /> - -
-
- timeRef.current = 10} /> - -
-
- timeRef.current = 30} /> - -
+
+
+ Time Setting: +
+
+
+ timeRef.current = 0} /> + +
+
+ timeRef.current = 10} /> +
-
- setEdit(!edit)} /> - -
- +
+ timeRef.current = 30} /> + +
+
+
+
+ setEdit(!edit)} /> +
+
+
- ) } diff --git a/src/main/client/src/store.js b/src/main/client/src/store.js index 9720d93..e579a20 100644 --- a/src/main/client/src/store.js +++ b/src/main/client/src/store.js @@ -48,7 +48,6 @@ export const useMuteStore = create( export const useTimeoutStore = create(set => ( { - fulltime: 10, timeout: 10, setTimeout: timeout => set(produce(draft => { draft.timeout = timeout