Skip to content

Commit 7955a26

Browse files
committed
fix: reduce probability of incorrect final time to be captured
When going on the switch menu, and coming back into the game, sometimes, a final time was detected.
1 parent 4e3fe94 commit 7955a26

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/domains/attempt/compositions/use-attempt-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ELAPSED_BEFORE_BEING_FINAL_MS = 1000;
2121
function useAttemptManagerFactory() {
2222
let state: State = "WAITING_ATTEMPT";
2323
let attempt = createAttemptHandler("Search for...", "?");
24-
const { isFinalTime } = useIsFinalTime(ELAPSED_BEFORE_BEING_FINAL_MS);
24+
const { deferFinalTime, isFinalTime } = useIsFinalTime(ELAPSED_BEFORE_BEING_FINAL_MS);
2525

2626
/**
2727
* Returns an AttemptEntity object only if there was a creation or an update of an AttemptEntity
@@ -35,6 +35,7 @@ function useAttemptManagerFactory() {
3535
const coins = Coins.get(image, putImageData);
3636

3737
if (!isDefined(time) || !isDefined(coins)) {
38+
deferFinalTime();
3839
return undefined;
3940
}
4041

src/domains/attempt/compositions/use-is-final-time.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function useIsFinalTimeFactory(beforeFinalMs: number) {
99
const now = Date.now();
1010

1111
if (isPause) {
12-
lastTimestamp = now;
12+
deferFinalTime(now);
1313
return false;
1414
}
1515

@@ -32,8 +32,13 @@ function useIsFinalTimeFactory(beforeFinalMs: number) {
3232
return false;
3333
};
3434

35+
const deferFinalTime = (time?: number): void => {
36+
lastTimestamp = time ?? Date.now();
37+
};
38+
3539
return {
3640
isFinalTime,
41+
deferFinalTime,
3742
};
3843
}
3944

0 commit comments

Comments
 (0)