vod jam and earl vod.atverkackt.de
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

Pause timer when watching a video

+25 -1
+25 -1
src/routes/+page.svelte
··· 33 33 } 34 34 } 35 35 36 + function pauseTimer() { 37 + if (timerStartedAt !== null && timerEndedAt === null) { 38 + savedElapsed += Date.now() - timerStartedAt; 39 + timerStartedAt = null; 40 + timerPausedForVideo = true; 41 + } 42 + } 43 + 44 + function resumeTimer() { 45 + if (timerPausedForVideo && timerEndedAt === null) { 46 + timerStartedAt = Date.now(); 47 + timerPausedForVideo = false; 48 + } 49 + } 50 + 36 51 function saveState() { 37 52 try { 38 53 const elapsed = timerStartedAt 39 - ? (timerEndedAt ?? Date.now()) - timerStartedAt 54 + ? (timerEndedAt ?? Date.now()) - timerStartedAt + savedElapsed 40 55 : savedElapsed; 41 56 const state: SavedState = { 42 57 collectedIds: [...collectedIds], ··· 70 85 let timerEndedAt: number | null = $state(restored?.timerEnded ? 0 : null); 71 86 let lastPlayerPosition: { x: number; y: number } | null = $state(restored?.playerPosition ?? null); 72 87 let initialPlayerPosition: { x: number; y: number } | null = restored?.playerPosition ?? null; 88 + let timerPausedForVideo = false; 73 89 74 90 let elapsedMs = $derived( 75 91 timerStartedAt && timerEndedAt ··· 191 207 collectPresent(selectedPresent); 192 208 } 193 209 if (gameState !== 'all-collected') { 210 + pauseTimer(); 194 211 gameState = 'watching-video'; 195 212 pauseAll(); 196 213 } ··· 204 221 } 205 222 206 223 function handleCloseVideo() { 224 + resumeTimer(); 207 225 gameState = 'viewing-present'; 208 226 playCorrectTrack(); 209 227 } 210 228 211 229 function handleBackToGame() { 230 + resumeTimer(); 212 231 selectedPresent = null; 213 232 gameState = 'playing'; 214 233 window.history.pushState(null, '', window.location.pathname); ··· 226 245 } 227 246 228 247 function handleCollectionWatch(present: WorldPresent) { 248 + pauseTimer(); 229 249 selectedPresent = present; 230 250 gameState = 'watching-video'; 231 251 pauseAll(); ··· 241 261 } 242 262 243 263 function handleStateChange(state: GameState) { 264 + const wasWatching = gameState === 'watching-video'; 244 265 gameState = state; 245 266 if (state === 'watching-video') { 267 + pauseTimer(); 246 268 pauseAll(); 247 269 } else { 270 + if (wasWatching) resumeTimer(); 248 271 playCorrectTrack(); 249 272 } 250 273 } ··· 256 279 const rkey = hash.slice(7); 257 280 focusVideoId = rkey; 258 281 } else { 282 + if (gameState === 'watching-video') resumeTimer(); 259 283 selectedPresent = null; 260 284 if (gameState !== 'intro') { 261 285 gameState = 'playing';