File size: 2,135 Bytes
a64b653 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import { supabase } from "@/integrations/supabase/client";
import { getRandomWord } from "@/lib/words-standard";
import { getRandomSportsWord } from "@/lib/words-sports";
import { getRandomFoodWord } from "@/lib/words-food";
import { getThemedWord } from "./themeService";
import { Language } from "@/i18n/translations";
const generateWordsForTheme = async (theme: string, wordCount: number = 10, language: Language = 'en'): Promise<string[]> => {
console.log('Generating words for theme:', theme, 'count:', wordCount, 'language:', language);
const words: string[] = [];
const usedWords: string[] = [];
for (let i = 0; i < wordCount; i++) {
let word;
switch (theme) {
case "sports":
word = getRandomSportsWord(language);
break;
case "food":
word = getRandomFoodWord(language);
break;
case "standard":
word = getRandomWord(language);
break;
default:
word = await getThemedWord(theme, usedWords, language);
}
words.push(word);
usedWords.push(word);
}
return words;
};
export const createGame = async (theme: string, language: Language = 'en'): Promise<string> => {
console.log('Creating new game with theme:', theme, 'language:', language);
const words = await generateWordsForTheme(theme, 25, language);
const { data: game, error } = await supabase
.from('games')
.insert({
theme,
words,
language // Added this line to include the language
})
.select()
.single();
if (error) {
console.error('Error creating game:', error);
throw error;
}
console.log('Game created successfully:', game);
return game.id;
};
export const createSession = async (gameId: string): Promise<string> => {
console.log('Creating new session for game:', gameId);
const { data: session, error } = await supabase
.from('sessions')
.insert({
game_id: gameId
})
.select()
.single();
if (error) {
console.error('Error creating session:', error);
throw error;
}
console.log('Session created successfully:', session);
return session.id;
}; |