diff --git a/static/script.js b/static/script.js index 4c5399e..cf85cd6 100644 --- a/static/script.js +++ b/static/script.js @@ -3761,4 +3761,49 @@ function buildChannelValue(matchId) { if (hasMatch) return "match"; return ""; +} + +function setClockSeconds(newSeconds) { + const wasRunning = !!timerId; + + if (timerId) { + clearInterval(timerId); + timerId = null; + } + + pausedAccumulatedSeconds = Math.max(0, Number(newSeconds) || 0); + matchClockSeconds = pausedAccumulatedSeconds; + + if (wasRunning) { + periodStartedAt = Date.now(); + timerId = setInterval(() => { + updateTimerUI(); + saveMatchState(); + }, 1000); + } else { + periodStartedAt = null; + } + + updateTimerUI(); + saveMatchState(); + syncClockToVmix(matchClockSeconds, wasRunning); +} + +async function syncClockToVmix(seconds, shouldRun) { + const h = String(Math.floor(seconds / 3600)).padStart(2, "0"); + const m = String(Math.floor((seconds % 3600) / 60)).padStart(2, "0"); + const s = String(seconds % 60).padStart(2, "0"); + const value = `${h}:${m}:${s}`; + + const commands = [ + vmixCmd("Function=SetCountdown&Input=ВЕРХНИЙ СЧЕТ&SelectedName=Таймер.Text&Value=02:00:00"), + vmixCmd(`Function=ChangeCountdown&Input=ВЕРХНИЙ СЧЕТ&SelectedName=Таймер.Text&Value=${value}`), + vmixCmd( + shouldRun + ? "Function=StartCountdown&Input=ВЕРХНИЙ СЧЕТ&SelectedName=Таймер.Text" + : "Function=PauseCountdown&Input=ВЕРХНИЙ СЧЕТ&SelectedName=Таймер.Text" + ) + ]; + + await sendDirectVmixCommands(commands); } \ No newline at end of file diff --git a/templates/match_workspace.html b/templates/match_workspace.html index 555ce72..f930408 100644 --- a/templates/match_workspace.html +++ b/templates/match_workspace.html @@ -289,7 +289,7 @@ Матч не начат -