Add spectator mode for late-joining players

- Server: Late joiners are added as spectators instead of players
- Server: Send forced-spectator event only to joining spectator (not broadcast)
- Server: Track spectators separately and move them to players after game ends
- Client: Handle forced-spectator event to show all player boards
- Client: Spectators see all boards equally without main/spectator highlighting
- Client: Mobile view shows scrollable vertical list of all boards for spectators
- Fix: All cleared lines are sent as garbage to each opponent (not randomized)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-20 18:26:48 +00:00
parent 75cd5b0e44
commit a0ab4ff5cd
7 changed files with 281 additions and 21 deletions
+6 -1
View File
@@ -323,12 +323,17 @@ class TetrisRenderer {
}
setActivePlayer(playerId) {
// Remove main class from all boards
// Remove main/spectator classes from all boards
this.boards.forEach((boardData, id) => {
boardData.element.classList.remove('active', 'main');
boardData.element.classList.remove('spectator', 'top-left', 'top-right', 'bottom-left', 'bottom-right');
});
// If playerId is null (spectator mode), show all boards equally without highlighting
if (playerId === null) {
return;
}
// Add main class to current player
const mainBoard = this.boards.get(playerId);
if (mainBoard) {