From 7a88eb4f54767d3cc225d0914ce4260250b0ba9b Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 2 Sep 2022 00:33:31 +0300 Subject: [PATCH] add spectatorIds to game --- src/game/gamestore/GameStore.ts | 2 ++ src/game/gamestore/GameStoreImpl.ts | 10 ++++++++++ src/models/Game.ts | 1 + 3 files changed, 13 insertions(+) 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 {