import { Html } from '@elysiajs/html'; import { PlayerConnection } from '../player-connection'; import { GameServer } from '../game-server'; export function broadcastButtons(server: GameServer) { server.connections.forEach((conn: PlayerConnection) => broadcastButtonsToPlayer(server, conn), ); } export function broadcastButtonsToPlayer( server: GameServer, conn: PlayerConnection, ) { const buttons: JSX.Element[] = []; let title: string | undefined; if (server.gomoku.status == 'playing' && server.getPlayerColor(conn)) { if (server.takebackRequesterId) { if (server.takebackRequesterId === conn.id) { title = 'You requested a takeback'; buttons.push( , ); } else { title = 'Your opponent requests a takeback'; buttons.push( , ); buttons.push( , ); } } else if (server.drawRequesterId) { if (server.drawRequesterId === conn.id) { title = 'You requested a draw'; buttons.push( , ); } else { title = 'Your opponent offers a draw'; buttons.push( , ); buttons.push( , ); } } else { buttons.push( , ); buttons.push( , ); buttons.push( , ); } } else if (server.gomoku.status === 'finished') { if (server.rematchRequesterId) { if (server.rematchRequesterId === conn.id) { title = 'You requested a rematch'; buttons.push( , ); } else { title = 'Your opponent requests a rematch'; buttons.push( , ); buttons.push( , ); } } else { buttons.push( , ); } } else if (server.gomoku.status === 'waiting') { buttons.push( , ); } conn.ws.send(
{title}
{buttons}
, ); console.log(`Sent buttons for game ${server.id} to player ${conn.id}`); }