UNPKG

shoehive

Version:

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

99 lines (98 loc) 4.14 kB
import { LOBBY_EVENTS, DefaultLobbyEventPayloadMap } from "./LobbyEvents"; import { PLAYER_EVENTS, DefaultPlayerEventPayloadMap } from "./PlayerEvents"; import { TABLE_EVENTS, DefaultTableEventPayloadMap } from "./TableEvents"; export { LOBBY_EVENTS, PLAYER_EVENTS, TABLE_EVENTS }; /** * Interface for custom event maps that consumers of the library can extend * * Example usage: * ``` * // Define your game event constants * const GAME_EVENTS = { * STARTED: "game:started", * ENDED: "game:ended", * PAUSED: "game:paused", * RESUMED: "game:resumed", * ROUND_STARTED: "game:round:started", * ROUND_ENDED: "game:round:ended", * TURN_STARTED: "game:turn:started", * TURN_ENDED: "game:turn:ended" * } as const; * * // Define your game-specific event constants * const POKER_EVENTS = { * HAND_DEALT: "poker:hand:dealt", * BETTING_ROUND_STARTED: "poker:betting:started", * PLAYER_CALLED: "poker:player:called", * PLAYER_RAISED: "poker:player:raised", * PLAYER_FOLDED: "poker:player:folded" * } as const; * * // Create types for your custom events * type GameEventType = typeof GAME_EVENTS[keyof typeof GAME_EVENTS]; * type PokerEventType = typeof POKER_EVENTS[keyof typeof POKER_EVENTS]; * * // Extend the event system * declare module "shoehive" { * interface CustomEventMap { * gameEvents: GameEventType; * pokerEvents: PokerEventType; * } * } * ``` */ export interface CustomEventMap { } export type PlayerEventType = typeof PLAYER_EVENTS[keyof typeof PLAYER_EVENTS]; export type TableEventType = typeof TABLE_EVENTS[keyof typeof TABLE_EVENTS]; export type LobbyEventType = typeof LOBBY_EVENTS[keyof typeof LOBBY_EVENTS]; export type BuiltInEventType = PlayerEventType | TableEventType | LobbyEventType; export type EventType = BuiltInEventType | (CustomEventMap extends Record<string, infer E> ? E : never); export type EventPayloadMap<TMap extends Record<string, any>> = { [K in keyof TMap]: any; }; /** * Combined default event payload map for all built-in events * * This is a combined type that includes all the payload types for all the built-in events. * * You can use this type to listen for changes in the state, or to trigger actions based on events. */ export type DefaultEventPayloadMap = DefaultPlayerEventPayloadMap & DefaultTableEventPayloadMap & DefaultLobbyEventPayloadMap; export declare const EVENTS: { readonly PLAYER: { readonly CONNECTED: "player:connected"; readonly DISCONNECTED: "player:disconnected"; readonly RECONNECTED: "player:reconnected"; readonly REMOVED: "player:removed"; readonly STATE_UPDATED: "player:state:updated"; readonly ATTRIBUTE_CHANGED: "player:attribute:changed"; readonly ATTRIBUTES_CHANGED: "player:attributes:changed"; readonly AUTHENTICATION_FAILED: "player:authentication:failed"; readonly AUTHENTICATION_SUCCEEDED: "player:authentication:succeeded"; }; readonly TABLE: { readonly CREATED: "table:created"; readonly EMPTY: "table:empty"; readonly STATE_UPDATED: "table:state:updated"; readonly ATTRIBUTE_CHANGED: "table:attribute:changed"; readonly ATTRIBUTES_CHANGED: "table:attributes:changed"; readonly PLAYER_JOINED: "table:player:joined"; readonly PLAYER_LEFT: "table:player:left"; readonly PLAYER_SAT: "table:player:sat"; readonly PLAYER_STOOD: "table:player:stood"; readonly DECK_CREATED: "table:deck:created"; readonly DECK_SHUFFLED: "table:deck:shuffled"; readonly DECK_CARD_DRAWN: "table:deck:card:drawn"; readonly CARD_DEALT: "table:card:dealt"; readonly SEAT_HAND_ADDED: "table:seat:hand:added"; readonly SEAT_HAND_REMOVED: "table:seat:hand:removed"; readonly SEAT_HAND_CLEARED: "table:seat:hand:cleared"; readonly SEATS_HANDS_CLEARED: "table:seats:hands:cleared"; }; readonly LOBBY: { readonly UPDATED: "lobby:updated"; readonly ATTRIBUTE_CHANGED: "lobby:attribute:changed"; readonly ATTRIBUTES_CHANGED: "lobby:attributes:changed"; }; };