From 8620a9d76083399a309e359f41b78507fd451e21 Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Fri, 9 Feb 2024 01:20:34 +0000 Subject: [PATCH] save move times --- src/components/boards/BoardGame.tsx | 8 +++++--- src/components/panels/analysis/ReportModal.tsx | 4 ++-- src/utils/treeReducer.ts | 6 +++++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/components/boards/BoardGame.tsx b/src/components/boards/BoardGame.tsx index f1ad541d..b171fb19 100644 --- a/src/components/boards/BoardGame.tsx +++ b/src/components/boards/BoardGame.tsx @@ -390,6 +390,9 @@ function BoardGame() { moves, ]); + const [whiteTime, setWhiteTime] = useState(null); + const [blackTime, setBlackTime] = useState(null); + useEffect(() => { const unlisten = events.bestMovesPayload.listen(({ payload }) => { const ev = payload.bestLines; @@ -404,13 +407,14 @@ function BoardGame() { dispatch({ type: "APPEND_MOVE", payload: parseUci(ev[0].uciMoves[0]), + clock: (pos.turn === "white" ? whiteTime : blackTime)! / 1000, }); } }); return () => { unlisten.then((f) => f()); }; - }, [activeTab, dispatch, pos, root.fen, moves]); + }, [activeTab, dispatch, pos, root.fen, moves, whiteTime, blackTime]); const movable = useMemo(() => { if (players.white.type === "human" && players.black.type === "human") { @@ -426,8 +430,6 @@ function BoardGame() { }, [players]); const [sameTimeControl, setSameTimeControl] = useState(true); - const [whiteTime, setWhiteTime] = useState(null); - const [blackTime, setBlackTime] = useState(null); const [intervalId, setIntervalId] = useState form.setFieldValue("goMode", { - ...form.values.goMode, + ...(form.values.goMode as any), c: (v || 1) as number, }) } diff --git a/src/utils/treeReducer.ts b/src/utils/treeReducer.ts index a5cfd017..dbec2840 100644 --- a/src/utils/treeReducer.ts +++ b/src/utils/treeReducer.ts @@ -210,6 +210,7 @@ export type TreeAction = promotion?: string; } | string; + clock?: number; } | { type: "MAKE_MOVES"; payload: string[]; mainline?: boolean } | { type: "GO_TO_START" } @@ -261,7 +262,10 @@ const treeReducer = (state: TreeState, action: TreeAction) => { .with({ type: "MAKE_MOVE" }, ({ payload, changePosition, mainline }) => { makeMove({ state, move: payload, last: false, changePosition, mainline }); }) - .with({ type: "APPEND_MOVE" }, ({ payload }) => { + .with({ type: "APPEND_MOVE" }, ({ payload, clock }) => { + const node = getNodeAtPath(state.root, state.position); + if (!node) return; + node.clock = clock; makeMove({ state, move: payload, last: true }); }) .with({ type: "MAKE_MOVES" }, ({ payload, mainline }) => {