This commit is contained in:
2026-10-17 20:16:24 +07:00
parent f5dc9c1e5b
commit 40456eebf1
16 changed files with 2122 additions and 54 deletions
+10 -2
View File
@@ -159,6 +159,7 @@ function initialTimer(): TimerState {
}
}
export class Controller {
onMusicEnded: ((report: Report) => void) | null = null
state: State = {
session: randomUUID(),
sequence: 0,
@@ -330,6 +331,11 @@ export class Controller {
tick() {
if (this.updateTimer()) this.broadcast()
}
synchronizeTimer(timer: Omit<TimerState, 'revision'>) {
this.state.timer = { ...timer, revision: this.state.timer.revision + 1 }
this.timerDeadline = timer.status === 'running' ? this.now() + timer.remainingMs : null
this.broadcast()
}
setResults(value: unknown) {
const key = this.state.catalog.key
if (value !== null && !key) throw new Error('Сначала выберите пакет игры')
@@ -578,8 +584,10 @@ export class Controller {
this.measured.delete(report.channel)
}
if (report.status === 'ended') {
if (report.channel === 'music') this.advance()
else c.desired = 'paused'
if (report.channel === 'music') {
this.onMusicEnded?.(report)
this.advance()
} else c.desired = 'paused'
}
this.broadcast()
}