Add chess premoves and time control metadata
All checks were successful
CI / Deploy / test (push) Successful in 1m15s
CI / Deploy / deploy (push) Successful in 1m11s

- pass chess room time control to the client
- add premove handling and richer chess board UI
- update join result typing for room options
This commit is contained in:
syntaxbullet
2026-04-10 10:19:33 +02:00
parent 31580df919
commit f796cac6be
5 changed files with 743 additions and 348 deletions

View File

@@ -244,7 +244,12 @@ export class GameServer {
this.replacedConnections.delete(discordId);
// Build room options for the client
const roomOptions = room?.betAmount ? { betAmount: room.betAmount } : undefined;
const roomOptions = room
? {
...(room.betAmount > 0 ? { betAmount: room.betAmount } : {}),
...(typeof room.options?.timeControl === "string" ? { timeControl: room.options.timeControl } : {}),
}
: undefined;
// Respond with JOIN_RESULT
ws.send(JSON.stringify({

View File

@@ -58,7 +58,7 @@ export type GameWsServerMessage =
| { type: "GAME_STARTED"; roomId: string; state: unknown }
| { type: "GAME_ENDED"; roomId: string; winner: string | null; reason: string; payout?: { amount: number; refunded?: boolean } }
| { type: "ROOM_CREATED"; roomId: string; gameSlug: string }
| { type: "JOIN_RESULT"; roomId: string; joinedAs: "player" | "spectator"; roomStatus: "waiting" | "playing" | "finished"; players: PlayerInfo[]; spectators: PlayerInfo[]; state?: unknown; roomOptions?: { betAmount?: number } }
| { type: "JOIN_RESULT"; roomId: string; joinedAs: "player" | "spectator"; roomStatus: "waiting" | "playing" | "finished"; players: PlayerInfo[]; spectators: PlayerInfo[]; state?: unknown; roomOptions?: { betAmount?: number; timeControl?: string } }
| { type: "ROUND_SETTLED"; roomId: string; payouts: Record<string, { net: number }> }
| { type: "SESSION_REPLACED"; roomId: string }
| { type: "ERROR"; message: string };

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@ export interface GameUIProps {
onAction: (action: unknown) => void;
players: { discordId: string; username: string }[];
roundResult?: { payouts: Record<string, { net: number }> } | null;
roomOptions?: { betAmount?: number };
roomOptions?: { betAmount?: number; timeControl?: string };
}
export interface GameUIPlugin {

View File

@@ -21,7 +21,7 @@ interface GameRoomState {
roundResult: RoundResult | null;
error: string | null;
sessionReplaced: boolean;
roomOptions: { betAmount?: number };
roomOptions: { betAmount?: number; timeControl?: string };
}
export function useGameRoom(roomId: string, userId: string, role?: string, preferAs: "player" | "spectator" = "player") {