fix: Resolve React hooks violation, implement player waiting screen, and auto-start game upon deck submission.
This commit is contained in:
@@ -3,6 +3,8 @@ interface Player {
|
||||
name: string;
|
||||
isHost: boolean;
|
||||
role: 'player' | 'spectator';
|
||||
ready?: boolean;
|
||||
deck?: any[];
|
||||
}
|
||||
|
||||
interface ChatMessage {
|
||||
@@ -17,7 +19,7 @@ interface Room {
|
||||
hostId: string;
|
||||
players: Player[];
|
||||
packs: any[]; // Store generated packs (JSON)
|
||||
status: 'waiting' | 'drafting' | 'deck_building' | 'finished';
|
||||
status: 'waiting' | 'drafting' | 'deck_building' | 'playing' | 'finished';
|
||||
messages: ChatMessage[];
|
||||
maxPlayers: number;
|
||||
}
|
||||
@@ -30,7 +32,7 @@ export class RoomManager {
|
||||
const room: Room = {
|
||||
id: roomId,
|
||||
hostId,
|
||||
players: [{ id: hostId, name: hostName, isHost: true, role: 'player' }],
|
||||
players: [{ id: hostId, name: hostName, isHost: true, role: 'player', ready: false }],
|
||||
packs,
|
||||
status: 'waiting',
|
||||
messages: [],
|
||||
@@ -40,6 +42,18 @@ export class RoomManager {
|
||||
return room;
|
||||
}
|
||||
|
||||
setPlayerReady(roomId: string, playerId: string, deck: any[]): Room | null {
|
||||
const room = this.rooms.get(roomId);
|
||||
if (!room) return null;
|
||||
|
||||
const player = room.players.find(p => p.id === playerId);
|
||||
if (player) {
|
||||
player.ready = true;
|
||||
player.deck = deck;
|
||||
}
|
||||
return room;
|
||||
}
|
||||
|
||||
joinRoom(roomId: string, playerId: string, playerName: string): Room | null {
|
||||
const room = this.rooms.get(roomId);
|
||||
if (!room) return null;
|
||||
|
||||
Reference in New Issue
Block a user