Huge refactor of web-socket-handler

This commit is contained in:
sepia 2025-07-21 22:19:59 -05:00
parent f68a8d152f
commit 10a4bd64d2
11 changed files with 333 additions and 510 deletions

View file

@ -1,17 +1,10 @@
import { GameInstance } from '../game/game-instance';
import { GomokuGame } from '../game/game-instance';
export function renderGameBoardHtml(
game: GameInstance,
playerId: string,
game: GomokuGame,
isPlayerToPlay: boolean,
): string {
let boardHtml = '<div id="game-board" class="game-board-grid">';
const currentPlayerColor =
Object.entries(game.players).find(([_, id]) => id === playerId)?.[0] ||
null;
const isPlayersTurn =
game.status === 'playing' && game.currentPlayerColor === currentPlayerColor;
for (let row = 0; row < game.board.length; row++) {
for (let col = 0; col < game.board[row].length; col++) {
const stone = game.board[row][col];
@ -28,7 +21,7 @@ export function renderGameBoardHtml(
const left = col * 30;
// HTMX attributes for making a move
const wsAttrs = isPlayersTurn && !stone ? `ws-send="click"` : '';
const wsAttrs = isPlayerToPlay && !stone ? `ws-send="click"` : '';
boardHtml += `
<div
@ -46,7 +39,3 @@ export function renderGameBoardHtml(
boardHtml += `</div>`;
return boardHtml;
}
export function renderTitleBoxHtml(gameId: string, playerId: string): string {
return `<div id="title-box">You are: ${playerId}<br/>Game ID: ${gameId}</div>`;
}