diff --git a/src/game/gamestore/GameStore.ts b/src/game/gamestore/GameStore.ts index 8813b29..59c8ea3 100644 --- a/src/game/gamestore/GameStore.ts +++ b/src/game/gamestore/GameStore.ts @@ -12,4 +12,6 @@ export interface GameStore { setGameByUser(userId: string, game: Game): void; getGameByUser(userId: string): Game | undefined; removeGameByPlayer(userId: string): void; + + getSpeactatingGameIdsByUser(userId: string): string[] } \ No newline at end of file diff --git a/src/game/gamestore/GameStoreImpl.ts b/src/game/gamestore/GameStoreImpl.ts index e720cb4..218796b 100644 --- a/src/game/gamestore/GameStoreImpl.ts +++ b/src/game/gamestore/GameStoreImpl.ts @@ -35,4 +35,14 @@ export class GameStoreImpl implements GameStore { removeGameByPlayer(userId: string): void { this.removeGameIdByPlayer(userId); } + + getSpeactatingGameIdsByUser(userId: string): string[] { + const speactatingGameIds = []; + for (const gameId in this.gameStore.keys()) { + const game = this.gameStore.get(gameId) as Game; + const isSpectator = game.spectatorIds.find((value) => value === userId); + isSpectator && speactatingGameIds.push(game.id); + } + return speactatingGameIds; + } } \ No newline at end of file diff --git a/src/models/Game.ts b/src/models/Game.ts index ec37311..7a0d1db 100644 --- a/src/models/Game.ts +++ b/src/models/Game.ts @@ -5,6 +5,7 @@ export interface Game { id: string; mancalaGame: MancalaGame; gameUsersConnectionInfo: GameUsersConnectionInfo; + spectatorIds: string[]; } export interface GameUsersConnectionInfo {