v0.8.2
Class: Lobby
â 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.
Table of contents
Constructors
Methods
- createTable
- getAttribute
- getAttributes
- getTableCount
- hasAttribute
- setAttribute
- setAttributes
- updateLobbyState
Constructors
constructor
⢠new Lobby(eventBus
, gameManager
, tableFactory
): Lobby
Parameters
Name | Type |
---|---|
eventBus | EventBus |
gameManager | GameManager |
tableFactory | TableFactory |
Returns
Methods
createTable
⸠createTable(gameId
, options?
): null
| Table
Creates a new table for a game.
Parameters
Name | Type | Description |
---|---|---|
gameId | string | The ID of the game. |
options? | Record <string , any > | Optional options for the table. |
Returns
null
| Table
The newly created table, or null if the game definition is not found.
getAttribute
⸠getAttribute(key
): any
Get a single attribute from the lobby.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key of the attribute to get |
Returns
any
The value of the attribute, or undefined if it doesnât exist
getAttributes
⸠getAttributes(): Record
<string
, any
>
Get all attributes from the lobby.
Returns
Record
<string
, any
>
An object containing all lobby attributes
getTableCount
⸠getTableCount(): number
Get the number of tables in the lobby.
Returns
number
The number of tables in the lobby
hasAttribute
⸠hasAttribute(key
): boolean
Check if the lobby has an attribute.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key of the attribute to check |
Returns
boolean
True if the attribute exists, false otherwise
setAttribute
⸠setAttribute(key
, value
, notify?
): void
Set a single attribute on the lobby and emit an event for the change.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
key | string | undefined | The attribute name |
value | any | undefined | The attribute value |
notify | boolean | true | Whether to emit an event (defaults to true) |
Returns
void
setAttributes
⸠setAttributes(attributes
): void
Set multiple attributes at once and emit a single event. This is more efficient than calling setAttribute multiple times.
Parameters
Name | Type | Description |
---|---|---|
attributes | Record <string , any > | Object containing attribute key-value pairs |
Returns
void
updateLobbyState
⸠updateLobbyState(): void
Broadcasts a lobby update to all players. This method can be called externally to force a lobby update.
Returns
void