Skip to content

Commit

Permalink
Get rid of the extra stop condition for replay. The if statement guar…
Browse files Browse the repository at this point in the history
…d in `goToPly` is enough to avoid issues.
  • Loading branch information
johndoknjas committed Dec 12, 2024
1 parent 0addc7e commit 9630ee8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions ui/common/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,14 @@ export function* showMovesDecreasingDelay(): Generator<number, void, void> {
for (let d = 350; ; ) yield Math.max(100, (d *= 14 / 15));
} // todo - make this inline in func below?

export function replayMovesRepeater(f: () => void, e: Event, additionalStopCond?: () => boolean): void {
export function replayMovesRepeater(f: () => void, e: Event): void {
const delay = showMovesDecreasingDelay();
const repeat = () => {
f();
timeout = setTimeout(repeat, delay.next().value!);
if (additionalStopCond?.()) clearTimeout(timeout);
};
let timeout = setTimeout(repeat, delay.next().value!);
f();
if (additionalStopCond?.()) clearTimeout(timeout);
const eventName = e.type === 'touchstart' ? 'touchend' : 'mouseup';
document.addEventListener(eventName, () => clearTimeout(timeout), { once: true });
}
4 changes: 2 additions & 2 deletions ui/round/src/view/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ const goToPly = (e: Event, ctrl: RoundController) => () => {
if (!isNaN(ply)) ctrl.userJump(ply);
ctrl.redraw();
};
// todo - get rid of stopCondition thing if not needed?
const goThroughMoves = (ctrl: RoundController, e: Event) => replayMovesRepeater(goToPly(e, ctrl), e, () => isNaN(targetPly(e)));

const goThroughMoves = (ctrl: RoundController, e: Event) => replayMovesRepeater(goToPly(e, ctrl), e);

function renderButtons(ctrl: RoundController) {
const firstPly = util.firstPly(ctrl.data),
Expand Down

0 comments on commit 9630ee8

Please sign in to comment.