From f44ad461fecb6f5022e262b53377402eb393d614 Mon Sep 17 00:00:00 2001 From: Ben Stein Date: Tue, 14 Nov 2023 13:06:22 -0500 Subject: [PATCH] Removed automatic redirect from the game page to the external game page for external games (to permit access to scoreboard etc. Fixes GBAPI#300. --- ...ontinue-to-gameboard-button.component.html | 5 ++ .../continue-to-gameboard-button.component.ts | 75 +++++++++++++++++++ .../gameboard-ui/src/app/game/game.module.ts | 2 + .../pages/game-page/game-page.component.ts | 8 -- .../player-session.component.html | 4 +- .../src/app/services/router.service.ts | 8 ++ 6 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.html create mode 100644 projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.ts diff --git a/projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.html b/projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.html new file mode 100644 index 00000000..63037168 --- /dev/null +++ b/projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.html @@ -0,0 +1,5 @@ + + + {{buttonText}} + + diff --git a/projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.ts b/projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.ts new file mode 100644 index 00000000..c2bbdad4 --- /dev/null +++ b/projects/gameboard-ui/src/app/game/components/continue-to-gameboard-button/continue-to-gameboard-button.component.ts @@ -0,0 +1,75 @@ +import { Component, Input, OnChanges, SimpleChanges } from '@angular/core'; +import { GameEngineMode, GameStartPhase } from '@/api/game-models'; +import { Player } from '@/api/player-models'; +import { RouterService } from '@/services/router.service'; +import { firstValueFrom } from 'rxjs'; +import { GameService } from '@/api/game.service'; + +export interface ContinueToGameboardButtonContext { + gameId: string; + gameMode: GameEngineMode; + player: Player; +} + +@Component({ + selector: 'app-continue-to-gameboard-button', + templateUrl: './continue-to-gameboard-button.component.html', +}) +export class ContinueToGameboardButtonComponent implements OnChanges { + @Input() context?: ContinueToGameboardButtonContext; + + protected buttonText = ""; + protected buttonUrl: string | null = null; + protected isEnabled = false; + + constructor( + private gameService: GameService, + private routerService: RouterService) { } + + async ngOnChanges(changes: SimpleChanges): Promise { + // then we need to manually check if they've already started and redirect if so + // const gameStartPhase = await firstValueFrom(this.apiGame.getStartPhase(ctx.game.id, ctx.player.teamId)); + // this.logService.logInfo(`Game ${ctx.game.id} (player ${ctx.player.id}) is at start phase "${gameStartPhase}".`); + + // if (gameStartPhase == GameStartPhase.Started || gameStartPhase == GameStartPhase.Starting) { + // this.redirectToExternalGameLoadingPage(ctx); + // } + + if (changes.context && !!this.context) { + switch (this.context.gameMode) { + case "vm": + this.buttonText = "Continue to Gameboard"; + this.buttonUrl = this.routerService.getGameboardPageUrlTree(this.context.player.id).toString(); + this.isEnabled = true; + break; + case "external": + this.updateFromExternalGame(this.context); + break; + case "unity": + this.buttonText = "Continue to Cubespace"; + this.buttonUrl = this.routerService.getUnityBoardUrlTree({ + gameId: this.context.gameId, + playerId: this.context.player.id, + teamId: this.context.player.teamId, + sessionEnd: this.context.player.sessionEnd.valueOf() + }).toString(); + this.isEnabled = true; + } + } else { + this.buttonText = ""; + this.buttonUrl = null; + } + } + + private async updateFromExternalGame(context: ContinueToGameboardButtonContext) { + this.buttonText = "Continue to Cubespace"; + this.buttonUrl = this + .routerService + .getGameStartPageUrlTree({ gameId: context.gameId, playerId: context.player.id }) + .toString(); + + // this is only enabled if the game is started or starting + const gameStartPhase = await firstValueFrom(this.gameService.getStartPhase(context.gameId, context.player.teamId)); + this.isEnabled = gameStartPhase == GameStartPhase.Started || gameStartPhase == GameStartPhase.Starting; + } +} diff --git a/projects/gameboard-ui/src/app/game/game.module.ts b/projects/gameboard-ui/src/app/game/game.module.ts index 096dd355..0ee293ad 100644 --- a/projects/gameboard-ui/src/app/game/game.module.ts +++ b/projects/gameboard-ui/src/app/game/game.module.ts @@ -37,6 +37,7 @@ import { TeamChallengeScoresToChallengeResultTypeCountPipe } from './pipes/team- import { UserIsPlayingGuard } from '@/guards/user-is-playing.guard'; import { UnityBoardComponent } from '../unity/unity-board/unity-board.component'; import { ScoreboardTeamDetailModalComponent } from './components/scoreboard-team-detail-modal/scoreboard-team-detail-modal.component'; +import { ContinueToGameboardButtonComponent } from './components/continue-to-gameboard-button/continue-to-gameboard-button.component'; const MODULE_DECLARATIONS = [ CertificateComponent, @@ -71,6 +72,7 @@ const MODULE_DECLARATIONS = [ ScoreboardComponent, TeamChallengeScoresToChallengeResultTypeCountPipe, ScoreboardTeamDetailModalComponent, + ContinueToGameboardButtonComponent, ], imports: [ CommonModule, diff --git a/projects/gameboard-ui/src/app/game/pages/game-page/game-page.component.ts b/projects/gameboard-ui/src/app/game/pages/game-page/game-page.component.ts index 3ed848bd..de3797af 100644 --- a/projects/gameboard-ui/src/app/game/pages/game-page/game-page.component.ts +++ b/projects/gameboard-ui/src/app/game/pages/game-page/game-page.component.ts @@ -239,14 +239,6 @@ export class GamePageComponent implements OnDestroy { } }) ); - - // then we need to manually check if they've already started and redirect if so - const gameStartPhase = await firstValueFrom(this.apiGame.getStartPhase(ctx.game.id, ctx.player.teamId)); - this.logService.logInfo(`Game ${ctx.game.id} (player ${ctx.player.id}) is at start phase "${gameStartPhase}".`); - - if (gameStartPhase == GameStartPhase.Started || gameStartPhase == GameStartPhase.Starting) { - this.redirectToExternalGameLoadingPage(ctx); - } } } diff --git a/projects/gameboard-ui/src/app/game/player-session/player-session.component.html b/projects/gameboard-ui/src/app/game/player-session/player-session.component.html index 648db251..63c3e553 100644 --- a/projects/gameboard-ui/src/app/game/player-session/player-session.component.html +++ b/projects/gameboard-ui/src/app/game/player-session/player-session.component.html @@ -73,8 +73,8 @@

Session Forecast

diff --git a/projects/gameboard-ui/src/app/services/router.service.ts b/projects/gameboard-ui/src/app/services/router.service.ts index 9f23221a..0a32b0b0 100644 --- a/projects/gameboard-ui/src/app/services/router.service.ts +++ b/projects/gameboard-ui/src/app/services/router.service.ts @@ -130,6 +130,10 @@ export class RouterService implements OnDestroy { this.router.navigateByUrl(`/game/external/${gameId}/${teamId}`); } + public getGameboardPageUrlTree(playerId: string): UrlTree { + return this.router.createUrlTree(["game", "board", playerId]); + } + public getGamePageUrlTree(gameId: string): UrlTree { return this.router.parseUrl(`/game/${gameId}`); } @@ -146,6 +150,10 @@ export class RouterService implements OnDestroy { this.router.navigateByUrl(this.getGameStartPageUrlTree(ctx)); } + public getUnityBoardUrlTree(ctx: { gameId: string, playerId: string, teamId: string; sessionEnd: number }) { + return this.router.createUrlTree(["game", "unity-board", ctx.gameId, ctx.playerId, ctx.teamId, ctx.sessionEnd]); + } + public reloadOnNextNavigateEnd() { this.router.events.pipe( filter(e => e instanceof NavigationEnd)