Timer toggle: manual ON/OFF control, links to Open/Pause/Resume buttons, auto-syncs state

This commit is contained in:
2026-04-08 19:28:07 -05:00
parent 9d34d648d8
commit 1a2dc295e1

View File

@@ -330,13 +330,11 @@ function modTimerToggle(){
if(modTimerRunning){ if(modTimerRunning){
clearInterval(modTimerInterval);modTimerRunning=false; clearInterval(modTimerInterval);modTimerRunning=false;
document.getElementById('btn-timer-ss').textContent='START'; document.getElementById('btn-timer-ss').textContent='START';
document.getElementById('timer-tog').checked=false;
broadcastTimerToPlayers(modTimerRemaining,false); broadcastTimerToPlayers(modTimerRemaining,false);
} else { } else {
if(modTimerRemaining<=0)modTimerLoad(); if(modTimerRemaining<=0)modTimerLoad();
modTimerRunning=true; modTimerRunning=true;
document.getElementById('btn-timer-ss').textContent='PAUSE'; document.getElementById('btn-timer-ss').textContent='PAUSE';
document.getElementById('timer-tog').checked=true;
broadcastTimerToPlayers(modTimerRemaining,true); broadcastTimerToPlayers(modTimerRemaining,true);
modTimerInterval=setInterval(()=>{ modTimerInterval=setInterval(()=>{
modTimerRemaining--; modTimerRemaining--;
@@ -345,7 +343,6 @@ function modTimerToggle(){
if(modTimerRemaining<=0){ if(modTimerRemaining<=0){
clearInterval(modTimerInterval);modTimerRunning=false; clearInterval(modTimerInterval);modTimerRunning=false;
document.getElementById('btn-timer-ss').textContent='START'; document.getElementById('btn-timer-ss').textContent='START';
document.getElementById('timer-tog').checked=false;
ws_send({type:'close_round'}); ws_send({type:'close_round'});
toast('TIME UP — round closed','warn'); toast('TIME UP — round closed','warn');
if(typeof gsap!=='undefined'){ if(typeof gsap!=='undefined'){
@@ -354,6 +351,9 @@ function modTimerToggle(){
} }
},1000); },1000);
} }
// Update toggle state to match running state
const tog=document.getElementById('timer-tog');
if(tog)tog.checked=modTimerRunning;
} }
function toggleTimerFromSwitch(){ function toggleTimerFromSwitch(){
@@ -373,14 +373,12 @@ function modTimerLoad(){
modTimerRunning=false; modTimerRunning=false;
clearInterval(modTimerInterval); clearInterval(modTimerInterval);
document.getElementById('btn-timer-ss').textContent='START'; document.getElementById('btn-timer-ss').textContent='START';
// Keep toggle state as is - don't auto-uncheck
renderModTimerDisplay(); renderModTimerDisplay();
} }
function modTimerReset(){ function modTimerReset(){
clearInterval(modTimerInterval); clearInterval(modTimerInterval);
modTimerRunning=false; modTimerRunning=false;
// Keep toggle state as is - don't auto-uncheck
modTimerRemaining=Math.max(5,parseInt(document.getElementById('mod-timer-set').value)||30); modTimerRemaining=Math.max(5,parseInt(document.getElementById('mod-timer-set').value)||30);
renderModTimerDisplay(); renderModTimerDisplay();
broadcastTimerToPlayers(modTimerRemaining,false); broadcastTimerToPlayers(modTimerRemaining,false);
@@ -400,14 +398,61 @@ function broadcastTimerToPlayers(sec,running){
function toggleRound(){ function toggleRound(){
if(room.buzzerState.roundOpen){ if(room.buzzerState.roundOpen){
ws_send({type:'close_round'}); ws_send({type:'close_round'});
// If timer toggle is ON and timer running, pause it
if(document.getElementById('timer-tog')?.checked && modTimerRunning){
clearInterval(modTimerInterval);modTimerRunning=false;
document.getElementById('btn-timer-ss').textContent='START';
}
} else { } else {
ws_send({type:'open_round'}); ws_send({type:'open_round'});
// If timer toggle is ON and timer not running, start it
if(document.getElementById('timer-tog')?.checked && !modTimerRunning && modTimerRemaining===0){
modTimerLoad();
modTimerRunning=true;
document.getElementById('btn-timer-ss').textContent='PAUSE';
modTimerInterval=setInterval(()=>{
modTimerRemaining--;
renderModTimerDisplay();
broadcastTimerToPlayers(modTimerRemaining,true);
if(modTimerRemaining<=0){
clearInterval(modTimerInterval);modTimerRunning=false;
document.getElementById('btn-timer-ss').textContent='START';
ws_send({type:'close_round'});
toast('TIME UP — round closed','warn');
}
},1000);
}
} }
} }
function resumeRound(){ function resumeRound(){
ws_send({type:'resume_round'}); ws_send({type:'resume_round'});
// If timer toggle is ON and timer not running, resume it
if(document.getElementById('timer-tog')?.checked && !modTimerRunning){
modTimerLoad();
modTimerRunning=true;
document.getElementById('btn-timer-ss').textContent='PAUSE';
modTimerInterval=setInterval(()=>{
modTimerRemaining--;
renderModTimerDisplay();
broadcastTimerToPlayers(modTimerRemaining,true);
if(modTimerRemaining<=0){
clearInterval(modTimerInterval);modTimerRunning=false;
document.getElementById('btn-timer-ss').textContent='START';
ws_send({type:'close_round'});
toast('TIME UP — round closed','warn');
} }
},1000);
}
}
// Timer toggle handler
document.getElementById('timer-tog').addEventListener('change',function(e){
if(e.target.checked && modTimerRemaining===0){
// If timer is enabled but not started, load it from set value
modTimerLoad();
}
});
function renderRoundButtons(){ function renderRoundButtons(){
const btn=document.getElementById('mod-round-btn'); const btn=document.getElementById('mod-round-btn');