This commit is contained in:
Josh Patra
2025-04-20 15:14:58 -04:00
parent 11f92705d5
commit cb5e672c75

View File

@@ -209,13 +209,26 @@
function startPolling() { function startPolling() {
isPlaying = true; isPlaying = true;
// clear any previous timers
clearInterval(progressInterval); clearInterval(progressInterval);
clearTimeout(snippetTimeout);
// progress bar updater
progressInterval = setInterval(() => { progressInterval = setInterval(() => {
widget.getPosition((pos: number) => { widget.getPosition((pos: number) => {
const limit = gameOver ? fullDuration : segmentDurations[attemptCount]; const limit = gameOver ? fullDuration : segmentDurations[attemptCount];
currentPosition = Math.min(pos, limit); currentPosition = Math.min(pos, limit);
}); });
}, 100); }, 100);
// clamp at the end of this segment
if (!gameOver) {
snippetTimeout = setTimeout(() => {
widget.pause();
currentPosition = segmentDurations[attemptCount];
}, segmentDurations[attemptCount]);
}
} }
function stopAllTimers() { function stopAllTimers() {
@@ -260,17 +273,11 @@
widget.seekTo(0); widget.seekTo(0);
loading = false; loading = false;
widgetReady = true; widgetReady = true;
}, 2000); }, 750);
}); });
widget.bind(SC.Widget.Events.PLAY, () => { widget.bind(SC.Widget.Events.PLAY, () => {
startPolling(); startPolling();
if (!gameOver) {
snippetTimeout = setTimeout(() => {
widget.pause();
currentPosition = segmentDurations[attemptCount];
}, segmentDurations[attemptCount]);
}
}); });
widget.bind(SC.Widget.Events.PAUSE, stopAllTimers); widget.bind(SC.Widget.Events.PAUSE, stopAllTimers);
widget.bind(SC.Widget.Events.FINISH, () => { widget.bind(SC.Widget.Events.FINISH, () => {
@@ -609,7 +616,10 @@
{#if nextIncrementSec > 0}Skip (+{nextIncrementSec}s){:else}I don't know it{/if} {#if nextIncrementSec > 0}Skip (+{nextIncrementSec}s){:else}I don't know it{/if}
</button> </button>
<button <button
on:click={submitGuess} on:click={() => {
submitGuess();
togglePlayPause();
}}
class="rounded px-4 py-2 font-semibold" class="rounded px-4 py-2 font-semibold"
style="background:{COLORS.secondary};color:{COLORS.background}" style="background:{COLORS.secondary};color:{COLORS.background}"
disabled={!userInput} disabled={!userInput}