Skip to content

Commit

Permalink
save move times
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Feb 9, 2024
1 parent 9e99e5e commit 8620a9d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/components/boards/BoardGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ function BoardGame() {
moves,
]);

const [whiteTime, setWhiteTime] = useState<number | null>(null);
const [blackTime, setBlackTime] = useState<number | null>(null);

useEffect(() => {
const unlisten = events.bestMovesPayload.listen(({ payload }) => {
const ev = payload.bestLines;
Expand All @@ -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") {
Expand All @@ -426,8 +430,6 @@ function BoardGame() {
}, [players]);

const [sameTimeControl, setSameTimeControl] = useState(true);
const [whiteTime, setWhiteTime] = useState<number | null>(null);
const [blackTime, setBlackTime] = useState<number | null>(null);

const [intervalId, setIntervalId] = useState<ReturnType<
typeof setInterval
Expand Down
4 changes: 2 additions & 2 deletions src/components/panels/analysis/ReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ function ReportModal({
/>
<NumberInput
min={1}
value={form.values.goMode.c}
value={form.values.goMode.c as number}
onChange={(v) =>
form.setFieldValue("goMode", {
...form.values.goMode,
...(form.values.goMode as any),
c: (v || 1) as number,
})
}
Expand Down
6 changes: 5 additions & 1 deletion src/utils/treeReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export type TreeAction =
promotion?: string;
}
| string;
clock?: number;
}
| { type: "MAKE_MOVES"; payload: string[]; mainline?: boolean }
| { type: "GO_TO_START" }
Expand Down Expand Up @@ -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 }) => {
Expand Down

0 comments on commit 8620a9d

Please sign in to comment.