diff --git a/App.tsx b/App.tsx index 50c2bdd..4f8c606 100644 --- a/App.tsx +++ b/App.tsx @@ -182,6 +182,7 @@ function App() { onStart={startGame} onEndGame={role === 'HOST' ? endGame : undefined} currentPlayerId={currentPlayerId} + hostParticipates={gameConfig.hostParticipates} /> {auth.isAuthenticated && pendingQuizToSave && ( void; onEndGame?: () => void; currentPlayerId?: string | null; + hostParticipates?: boolean; } -export const Lobby: React.FC = ({ quizTitle, players, gamePin, role, onStart, onEndGame, currentPlayerId }) => { +export const Lobby: React.FC = ({ quizTitle, players, gamePin, role, onStart, onEndGame, currentPlayerId, hostParticipates = false }) => { const isHost = role === 'HOST'; + const hostPlayer = players.find(p => p.id === 'host'); const realPlayers = players.filter(p => p.id !== 'host'); const currentPlayer = currentPlayerId ? players.find(p => p.id === currentPlayerId) : null; @@ -48,7 +50,7 @@ export const Lobby: React.FC = ({ quizTitle, players, gamePin, role, <>
- {realPlayers.length === 0 && ( + {realPlayers.length === 0 && !hostParticipates && (
@@ -56,6 +58,19 @@ export const Lobby: React.FC = ({ quizTitle, players, gamePin, role,
Waiting for players to join...
)} + {hostParticipates && hostPlayer && ( + + + {hostPlayer.name} + HOST + + )} {realPlayers.map((player) => ( { }); const newScore = Math.max(0, currentPlayer.score + breakdown.total); - setPlayers(prev => prev.map(p => { + const updatedPlayers = playersRef.current.map(p => { if (p.id !== playerId) return p; return { ...p, score: newScore, previousScore: p.score, streak: newStreak, lastAnswerCorrect: isCorrect, selectedShape, pointsBreakdown: breakdown }; - })); + }); + setPlayers(updatedPlayers); conn.send({ type: 'RESULT', payload: { isCorrect, scoreAdded: breakdown.total, newScore, breakdown } }); + + const allAnswered = updatedPlayers.every(p => p.lastAnswerCorrect !== null); + if (allAnswered && gameStateRef.current === 'QUESTION') { + endQuestion(); + } } }; @@ -1369,10 +1375,16 @@ export const useGame = () => { setCurrentPlayerScore(newScore); setCurrentStreak(newStreak); - setPlayers(prev => prev.map(p => { + const updatedPlayers = playersRef.current.map(p => { if (p.id !== 'host') return p; return { ...p, score: newScore, previousScore: p.score, streak: newStreak, lastAnswerCorrect: isCorrect, selectedShape: option.shape, pointsBreakdown: breakdown }; - })); + }); + setPlayers(updatedPlayers); + + const allAnswered = updatedPlayers.every(p => p.lastAnswerCorrect !== null); + if (allAnswered && gameStateRef.current === 'QUESTION') { + endQuestion(); + } } else { const option = arg as AnswerOption; setSelectedOption(option);