Fix guessing phase
This commit is contained in:
@ -107,19 +107,31 @@ const getTimeRemaining = (roomId) => {
|
||||
|
||||
const advancePhase = (roomId) => {
|
||||
const gameState = gameStates[roomId];
|
||||
if (!gameState) return false;
|
||||
|
||||
if (gameState.phase === 'composing') {
|
||||
if (!gameState) {
|
||||
console.error(`Cannot advance phase: no game state for room ${roomId}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const currentPhase = gameState.phase;
|
||||
console.log(`Advancing phase for room ${roomId} from ${currentPhase}`);
|
||||
|
||||
if (currentPhase === 'composing') {
|
||||
gameState.phase = 'guessing';
|
||||
gameState.roundStartTime = Date.now();
|
||||
return true;
|
||||
} else if (gameState.phase === 'guessing') {
|
||||
console.log(`Room ${roomId} advanced to guessing phase`);
|
||||
return { phase: 'guessing' };
|
||||
}
|
||||
else if (currentPhase === 'guessing') {
|
||||
gameState.phase = 'results';
|
||||
return true;
|
||||
} else if (gameState.phase === 'results') {
|
||||
console.log(`Room ${roomId} advanced to results phase`);
|
||||
return { phase: 'results' };
|
||||
}
|
||||
else if (currentPhase === 'results') {
|
||||
console.log(`Room ${roomId} starting new round from results phase`);
|
||||
return startNewRound(roomId);
|
||||
}
|
||||
|
||||
|
||||
console.warn(`Cannot advance from unknown phase "${currentPhase}" in room ${roomId}`);
|
||||
return false;
|
||||
};
|
||||
|
||||
@ -172,6 +184,12 @@ const cleanupGameState = (roomId) => {
|
||||
delete gameStates[roomId];
|
||||
};
|
||||
|
||||
const getCurrentComposer = (roomId) => gameStates[roomId]?.currentComposer || null;
|
||||
|
||||
const getGameState = (roomId) => {
|
||||
return gameStates[roomId] || null;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
initializeGameState,
|
||||
startNewRound,
|
||||
@ -185,5 +203,7 @@ module.exports = {
|
||||
getUserRole,
|
||||
getSongOptions,
|
||||
getSelectedSong,
|
||||
cleanupGameState
|
||||
cleanupGameState,
|
||||
getCurrentComposer,
|
||||
getGameState
|
||||
};
|
||||
|
Reference in New Issue
Block a user