shoehive
Version:
WebSocket-based multiplayer game framework for real-time, event-driven gameplay
92 lines (91 loc) • 2.98 kB
TypeScript
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, options, }: {
gameId: string;
options?: Record<string, unknown>;
}): 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, value, notify, }: {
key: string;
value: unknown;
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 }: {
attributes: Record<string, unknown>;
}): 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 }: {
key: string;
}): unknown;
/**
* Get all attributes from the lobby.
* @returns An object containing all lobby attributes
*/
getAttributes(): Record<string, unknown>;
/**
* 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 }: {
key: string;
}): boolean;
/**
* Get the number of tables in the lobby.
* @returns The number of tables in the lobby
*/
getTableCount(): number;
}