Link timer toggle to Open/Pause/Resume buttons — timer auto-starts/pauses/resumes with round
This commit is contained in:
@@ -372,17 +372,55 @@ function broadcastTimerToPlayers(sec,running){
|
|||||||
// MOD ROUND CONTROL
|
// MOD ROUND CONTROL
|
||||||
// ══════════════════════════════════════════════════════
|
// ══════════════════════════════════════════════════════
|
||||||
function toggleRound(){
|
function toggleRound(){
|
||||||
// Toggle: Open if closed, Close if open
|
|
||||||
if(room.buzzerState.roundOpen){
|
if(room.buzzerState.roundOpen){
|
||||||
ws_send({type:'close_round'});
|
ws_send({type:'close_round'});
|
||||||
|
// Pause timer if toggle is ON
|
||||||
|
if(document.getElementById('timer-tog').checked){
|
||||||
|
modTimerToggle();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ws_send({type:'open_round'});
|
ws_send({type:'open_round'});
|
||||||
|
// Start timer if toggle is ON
|
||||||
|
if(document.getElementById('timer-tog').checked){
|
||||||
|
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';
|
||||||
|
document.getElementById('timer-tog').checked=false;
|
||||||
|
ws_send({type:'close_round'});
|
||||||
|
toast('TIME UP — round closed','warn');
|
||||||
|
}
|
||||||
|
},1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resumeRound(){
|
function resumeRound(){
|
||||||
// Open round WITHOUT clearing existing buzzes (for accidental close recovery)
|
|
||||||
ws_send({type:'resume_round'});
|
ws_send({type:'resume_round'});
|
||||||
|
// Resume timer if toggle is ON
|
||||||
|
if(document.getElementById('timer-tog').checked){
|
||||||
|
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';
|
||||||
|
document.getElementById('timer-tog').checked=false;
|
||||||
|
ws_send({type:'close_round'});
|
||||||
|
toast('TIME UP — round closed','warn');
|
||||||
|
}
|
||||||
|
},1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderRoundButtons(){
|
function renderRoundButtons(){
|
||||||
@@ -398,6 +436,10 @@ function renderRoundButtons(){
|
|||||||
btn.className='btn btn-g btn-full';
|
btn.className='btn btn-g btn-full';
|
||||||
resumeBtn.style.display='block';
|
resumeBtn.style.display='block';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync timer toggle state with modTimerRunning
|
||||||
|
const tog=document.getElementById('timer-tog');
|
||||||
|
if(tog){tog.checked=modTimerRunning;}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ══════════════════════════════════════════════════════
|
// ══════════════════════════════════════════════════════
|
||||||
|
|||||||
Reference in New Issue
Block a user