Fix renderHost crash (roundActive used before declaration) + reset state on lobby join

This commit is contained in:
danny 2026-06-14 14:54:40 +02:00
parent f805552ff1
commit ad5b69514c

View file

@ -701,7 +701,7 @@ const App = (() => {
const d=await api('host_open',{code,pass});
role='host'; room=d.state.code; hostPass=pass;
selectedImposters=new Set(d.state.liarKeys||[]);
questionsLoaded=false;
questionsLoaded=false; lastJSON=''; lastChatLen=0; lastRoundNum=-1;
sessionStorage.setItem('bsb_session',JSON.stringify({role:'host',room:d.state.code,pass}));
show('lobby',false); show('playerView',false); show('hostView',true);
$('hRoom').textContent=room;
@ -715,6 +715,7 @@ const App = (() => {
try{
const d=await api('player_join',{code,name:nm});
role='player'; room=d.state.code; pkey=d.pkey; name=nm;
lastJSON=''; lastChatLen=0; lastRoundNum=-1; localVotes=new Set();
sessionStorage.setItem('bsb_session',JSON.stringify({role:'player',room:d.state.code,pkey:d.pkey,name:nm}));
show('lobby',false); show('hostView',false); show('playerView',true);
$('pRoom').textContent=room; $('pName').textContent=nm;
@ -1206,6 +1207,8 @@ const App = (() => {
const revealedKeys=state.revealedKeys||[];
const anyRevealed=state.revealed||ri>=9999||revealedKeys.length>0;
const revealCount=ri>=9999?players.length:revealedKeys.length;
// Must be defined before use in renderImposterList
const roundActive=!!(state.normalQuestion);
$('hRound').textContent=state.roundNum||1;
$('hRoundState').textContent=anyRevealed?(revealCount>=players.length&&players.length>0?'aufgedeckt':`${revealCount}/${players.length} aufgedeckt`):'verdeckt';
renderHostPlayers(players);
@ -1222,8 +1225,7 @@ const App = (() => {
questionsLoaded=true;
}
// Question locking: disable textareas when a round is active
const roundActive=!!(state.normalQuestion);
// Question locking: disable textareas when a round is active (roundActive already defined above)
$('hNormalQ').disabled=roundActive;
$('hImposterQ').disabled=roundActive;
$('hNormalQ').style.opacity=roundActive?'0.5':'1';