feat(game): add configurable rounds per room
This commit is contained in:
@@ -11,18 +11,20 @@ type Handlers = {
|
||||
multi: UseMultiGame;
|
||||
playerName: string;
|
||||
joinCode: string;
|
||||
maxPlayers: number;
|
||||
totalRounds: number;
|
||||
setScreen: Dispatch<SetStateAction<Screen>>;
|
||||
setError: Dispatch<SetStateAction<string | null>>;
|
||||
setLoading: Dispatch<SetStateAction<boolean>>;
|
||||
};
|
||||
|
||||
export function useGameHandlers({
|
||||
solo, multi, playerName, joinCode, setScreen, setError, setLoading,
|
||||
solo, multi, playerName, joinCode, maxPlayers, totalRounds, setScreen, setError, setLoading,
|
||||
}: Handlers) {
|
||||
async function handleCreateRoom() {
|
||||
if (!playerName.trim()) { setError("Entre ton pseudo !"); return; }
|
||||
setLoading(true); setError(null);
|
||||
const { error: err } = await multi.createRoom(playerName.trim());
|
||||
const { error: err } = await multi.createRoom(playerName.trim(), maxPlayers, totalRounds);
|
||||
setLoading(false);
|
||||
if (err) { setError(err); return; }
|
||||
setScreen("lobby");
|
||||
|
||||
+2
-2
@@ -152,11 +152,11 @@ export function useMultiGame() {
|
||||
|
||||
// Room actions
|
||||
|
||||
async function createRoom(playerName: string): Promise<{ error?: string }> {
|
||||
async function createRoom(playerName: string, maxPlayers = 16, totalRounds = 3): Promise<{ error?: string }> {
|
||||
const res = await fetch("/api/rooms", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ playerName }),
|
||||
body: JSON.stringify({ playerName, maxPlayers, totalRounds }),
|
||||
});
|
||||
const data = await res.json() as { room?: Room; playerId?: string; error?: string };
|
||||
if (!res.ok) return { error: data.error ?? "Erreur" };
|
||||
|
||||
Reference in New Issue
Block a user