feat: add time controls, correspondence games, and tournament mode
**Zeitmodi (Blitz/Rapid):** - 5, 10, 30 Min Zeitkontrolle bei Spielerstellung - Server-seitige Uhren: Zeit wird bei jedem Zug abgezogen - Timeout-Erkennung via claimTimeout Socket-Event - Schachuhr-Anzeige in GamePage (rot bei < 30s) - Turnierspiele erhalten automatisch Zeitkontrolle **Tagespartien (Correspondence):** - Neue DB-Tabelle correspondence_game - REST API: erstellen, beitreten, Zug machen, aufgeben - Seite /correspondence: Liste aktiver Tagespartien - Seite /correspondence/[code]: Spielen mit interaktivem Brett - Einladungslink teilen, Gegner tritt via Link bei **Turniermodus (Round-Robin):** - Neue DB-Tabellen: tournament, tournament_player, tournament_round - Round-Robin Paarungen mit Circle-Methode - Turnier erstellen: /tournament/create - Turnierliste: /tournament - Turnierseite /tournament/[code]: Standings, Runden, Spiele - Automatische Aktivisierung der nächsten Runde - Turnierspiele werden als normale activeGames erstellt - Ergebnisse aktualisieren Punkte automatisch Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
36
client/src/lib/tournament.ts
Normal file
36
client/src/lib/tournament.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { API_URL } from "@/config";
|
||||
import type { Tournament } from "@michess/types";
|
||||
|
||||
export const fetchTournaments = async (): Promise<Tournament[]> => {
|
||||
const res = await fetch(`${API_URL}/v1/tournaments`, { cache: "no-store" });
|
||||
if (!res.ok) return [];
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const fetchTournament = async (code: string): Promise<Tournament | null> => {
|
||||
const res = await fetch(`${API_URL}/v1/tournaments/${code}`, { cache: "no-store" });
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const createTournament = async (name: string, timeControl?: number, maxPlayers?: number): Promise<Tournament | null> => {
|
||||
const res = await fetch(`${API_URL}/v1/tournaments`, {
|
||||
method: "POST", credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name, timeControl, maxPlayers })
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const joinTournament = async (code: string): Promise<Tournament | null> => {
|
||||
const res = await fetch(`${API_URL}/v1/tournaments/${code}/join`, { method: "POST", credentials: "include" });
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const startTournament = async (code: string): Promise<Tournament | null> => {
|
||||
const res = await fetch(`${API_URL}/v1/tournaments/${code}/start`, { method: "POST", credentials: "include" });
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
};
|
||||
Reference in New Issue
Block a user