when going to roundend. the function for roundend should be called. why is this not…
- User
when going to round_end. the function for round_end should be called. why is this not happening. the state is set t round_end but the function isnt called
import { Game, GameState } from '../types'; import { startGame } from './game'; import { startNewRound } from './rounds'; import { getGame } from './utils'; import { db } from '../config'; import { calculateRoundScores } from './scoring/calculateRoundScores';
const validTransitions: Record<GameState, GameState[]> = { lobby: ['round_start'], round_start: ['song_submission'], song_submission: ['music_playback'], music_playback: ['ranking'], ranking: ['scoreboard'], scoreboard: ['round_end'], round_end: ['round_start', 'game_end'], game_end: ['lobby'], };
const stateTransitions: Record<GameState, (gameId: string, gameData: Game, gameRef: FirebaseFirestore.DocumentReference, transaction: FirebaseFirestore.Transaction) => Promise> = { lobby: async () => 'lobby', round_start: async (gameId, gameData, gameRef, transaction) => { if (gameData.currentRound === 0) { await startGame({ gameId, gameData, transaction }); } await startNewRound({ gameId, gameData, transaction }); return 'song_submission'; }, song_submission: async () => 'song_submission', music_playback: async () => 'music_playback', ranking: async () => 'ranking', scoreboard: async (gameId, gameData, gameRef, transaction) => { await calculateRoundScores({ gameId, currentRound: gameData.currentRound }); return 'round_end'; }, round_end: async (gameId, gameData, gameRef, transaction) => { console.log("Round end", gameData.currentRound, gameData.totalRounds); if (gameData.currentRound >= gameData.totalRounds - 1) { console.log("Game ending"); return 'game_end'; } else { console.log("Starting new round"); transaction.update(gameRef, { currentRound: gameData.currentRound + 1 }); await startNewRound({ gameId, gameData: { ...gameData, currentRound: gameData.currentRound + 1 }, transaction }); return 'round_start'; } }, game_end: async () => 'game_end', };
export async function progressGame(data: { gameId: string, gameData?: Game, gameRef?: FirebaseFirestore.DocumentReference }): Promise { try { const { gameId } = data; console.log('Progressing game:', { gameId }); let { gameData, gameRef } = data;
code - Assistant