UNPKG

shoehive

Version:

WebSocket-based multiplayer game framework for real-time, event-driven gameplay

79 lines (78 loc) 2.77 kB
import { EventBus } from "../events/EventBus"; import { GameManager } from "./GameManager"; import { Table } from "./Table"; import { TableFactory } from "./TableFactory"; /** * ✅ Attribute Support * * The Lobby class manages the lobby state and broadcasts updates to connected players. * It is responsible for tracking available games and tables, and notifying players * when these change. */ export declare class Lobby { private eventBus; private gameManager; private tableFactory; private attributes; constructor(eventBus: EventBus, gameManager: GameManager, tableFactory: TableFactory); /** * Sets up event listeners for lobby-related events. * This listens for table creation, table emptying, and player attribute changes * that would affect lobby display. */ private setupEventListeners; /** * Creates a new table for a game. * * @param gameId The ID of the game. * @param options Optional options for the table. * @returns The newly created table, or null if the game definition is not found. */ createTable(gameId: string, options?: Record<string, any>): Table | null; /** * Broadcasts a lobby update to all players. */ private broadcastLobbyUpdate; /** * Broadcasts a lobby update to all players. * This method can be called externally to force a lobby update. */ updateLobbyState(): void; /** * Set a single attribute on the lobby and emit an event for the change. * * @param key The attribute name * @param value The attribute value * @param notify Whether to emit an event (defaults to true) */ setAttribute(key: string, value: any, notify?: boolean): void; /** * Set multiple attributes at once and emit a single event. * This is more efficient than calling setAttribute multiple times. * * @param attributes Object containing attribute key-value pairs */ setAttributes(attributes: Record<string, any>): void; /** * Get a single attribute from the lobby. * @param key - The key of the attribute to get * @returns The value of the attribute, or undefined if it doesn't exist */ getAttribute(key: string): any; /** * Get all attributes from the lobby. * @returns An object containing all lobby attributes */ getAttributes(): Record<string, any>; /** * Check if the lobby has an attribute. * @param key - The key of the attribute to check * @returns True if the attribute exists, false otherwise */ hasAttribute(key: string): boolean; /** * Get the number of tables in the lobby. * @returns The number of tables in the lobby */ getTableCount(): number; }