mirror of
https://github.com/SoPat712/maisie-heardle.git
synced 2025-08-21 18:28:45 -04:00
progress bar fixed... again
This commit is contained in:
@@ -190,19 +190,20 @@
|
|||||||
timeLeft = `${h}:${m}:${s}`;
|
timeLeft = `${h}:${m}:${s}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
$: suggestions = userInput
|
// ─── CLAMPED FILL PERCENT & NEXT SEGMENT ─────────────────────────────────────
|
||||||
? tracks.filter((t) => t.title.toLowerCase().includes(userInput.toLowerCase())).slice(0, 5)
|
let fillPercent = 0;
|
||||||
: [];
|
$: {
|
||||||
// switch fill% between snippet & full track
|
const raw = gameOver
|
||||||
$: fillPercent = gameOver
|
|
||||||
? (currentPosition / fullDuration) * 100
|
? (currentPosition / fullDuration) * 100
|
||||||
: (currentPosition / TOTAL_MS) * 100;
|
: (currentPosition / TOTAL_MS) * 100;
|
||||||
|
fillPercent = raw > 100 ? 100 : raw;
|
||||||
|
}
|
||||||
$: nextIncrementSec =
|
$: nextIncrementSec =
|
||||||
attemptCount < SEGMENT_INCREMENTS.length - 1 ? SEGMENT_INCREMENTS[attemptCount + 1] : 0;
|
attemptCount < SEGMENT_INCREMENTS.length - 1 ? SEGMENT_INCREMENTS[attemptCount + 1] : 0;
|
||||||
|
|
||||||
function formatTime(ms: number) {
|
function formatTime(ms: number) {
|
||||||
const s = Math.floor(ms / 1000);
|
const s = Math.floor(ms / 1000);
|
||||||
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`;
|
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '00')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function startPolling() {
|
function startPolling() {
|
||||||
@@ -227,11 +228,9 @@
|
|||||||
window
|
window
|
||||||
.matchMedia('(prefers-color-scheme: dark)')
|
.matchMedia('(prefers-color-scheme: dark)')
|
||||||
.addEventListener('change', (e) => (darkMode = e.matches));
|
.addEventListener('change', (e) => (darkMode = e.matches));
|
||||||
|
|
||||||
// countdown
|
// countdown
|
||||||
updateTime();
|
updateTime();
|
||||||
countdownInterval = setInterval(updateTime, 1000);
|
countdownInterval = setInterval(updateTime, 1000);
|
||||||
|
|
||||||
// SoundCloud widget
|
// SoundCloud widget
|
||||||
widget = SC.Widget(iframeElement);
|
widget = SC.Widget(iframeElement);
|
||||||
widget.bind(SC.Widget.Events.READY, () => {
|
widget.bind(SC.Widget.Events.READY, () => {
|
||||||
@@ -242,14 +241,29 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
widget.bind(SC.Widget.Events.PLAY, () => {
|
widget.bind(SC.Widget.Events.PLAY, () => {
|
||||||
|
// startPolling();
|
||||||
|
// if (!gameOver) {
|
||||||
|
// snippetTimeout = setTimeout(() => widget.pause(), segmentDurations[attemptCount]);
|
||||||
|
// }
|
||||||
startPolling();
|
startPolling();
|
||||||
if (!gameOver) {
|
if (!gameOver) {
|
||||||
snippetTimeout = setTimeout(() => widget.pause(), segmentDurations[attemptCount]);
|
snippetTimeout = setTimeout(() => {
|
||||||
|
widget.pause();
|
||||||
|
// snap exactly to the end of this snippet
|
||||||
|
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, stopAllTimers);
|
widget.bind(SC.Widget.Events.FINISH, () => {
|
||||||
|
// ensure we hit the very end
|
||||||
|
currentPosition = gameOver ? fullDuration : segmentDurations[attemptCount];
|
||||||
|
stopAllTimers();
|
||||||
|
});
|
||||||
widget.bind(SC.Widget.Events.PLAY_PROGRESS, (e: { currentPosition: number }) => {
|
widget.bind(SC.Widget.Events.PLAY_PROGRESS, (e: { currentPosition: number }) => {
|
||||||
|
// only update while actually playing
|
||||||
|
if (!isPlaying) return;
|
||||||
|
|
||||||
const limit = gameOver ? fullDuration : segmentDurations[attemptCount];
|
const limit = gameOver ? fullDuration : segmentDurations[attemptCount];
|
||||||
if (e.currentPosition >= limit) {
|
if (e.currentPosition >= limit) {
|
||||||
currentPosition = limit;
|
currentPosition = limit;
|
||||||
@@ -263,7 +277,9 @@
|
|||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
stopAllTimers();
|
stopAllTimers();
|
||||||
clearInterval(countdownInterval);
|
clearInterval(countdownInterval);
|
||||||
widget?.unbind && Object.values(SC.Widget.Events).forEach((ev) => widget.unbind(ev));
|
if (widget?.unbind) {
|
||||||
|
Object.values(SC.Widget.Events).forEach((ev) => widget.unbind(ev));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function playSegment() {
|
function playSegment() {
|
||||||
@@ -374,8 +390,7 @@
|
|||||||
<hr class="my-4" style="border-color:{COLORS.text}" />
|
<hr class="my-4" style="border-color:{COLORS.text}" />
|
||||||
<p class="text-xs" style="color:{COLORS.accent}">
|
<p class="text-xs" style="color:{COLORS.accent}">
|
||||||
Prepared with SoundCloud, Svelte, Tailwind CSS, Inter font, svelte-hero-icons
|
Prepared with SoundCloud, Svelte, Tailwind CSS, Inter font, svelte-hero-icons
|
||||||
<br />
|
<br /><br />
|
||||||
<br />
|
|
||||||
Game version: 1.2.0
|
Game version: 1.2.0
|
||||||
</p>
|
</p>
|
||||||
<p class="text-sm italic">New track in <strong>{timeLeft}</strong></p>
|
<p class="text-sm italic">New track in <strong>{timeLeft}</strong></p>
|
||||||
@@ -479,7 +494,7 @@
|
|||||||
title="preview player"
|
title="preview player"
|
||||||
></iframe>
|
></iframe>
|
||||||
|
|
||||||
<!-- Bottom‐pinned controls -->
|
<!-- Bottom‑pinned controls -->
|
||||||
<div class="mt-auto px-4 pb-4">
|
<div class="mt-auto px-4 pb-4">
|
||||||
<!-- Progress bar -->
|
<!-- Progress bar -->
|
||||||
<div
|
<div
|
||||||
@@ -559,7 +574,11 @@
|
|||||||
class="rounded px-4 py-2 font-semibold"
|
class="rounded px-4 py-2 font-semibold"
|
||||||
style="background:{COLORS.primary};color:{COLORS.background}"
|
style="background:{COLORS.primary};color:{COLORS.background}"
|
||||||
>
|
>
|
||||||
{#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}
|
||||||
|
Reference in New Issue
Block a user