Skip to content

Commit

Permalink
Removed automatic redirect from the game page to the external game pa…
Browse files Browse the repository at this point in the history
…ge for external games (to permit access to scoreboard etc. Fixes GBAPI#300.
  • Loading branch information
sei-bstein committed Nov 14, 2023
1 parent 022fab6 commit f44ad46
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ng-container *ngIf="buttonText && buttonUrl">
<a class="btn btn-primary btn-lg" [class.disabled]="!isEnabled" [routerLink]="buttonUrl">
{{buttonText}}
</a>
</ng-container>
Original file line number Diff line number Diff line change
@@ -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<void> {
// 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;
}
}
2 changes: 2 additions & 0 deletions projects/gameboard-ui/src/app/game/game.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -71,6 +72,7 @@ const MODULE_DECLARATIONS = [
ScoreboardComponent,
TeamChallengeScoresToChallengeResultTypeCountPipe,
ScoreboardTeamDetailModalComponent,
ContinueToGameboardButtonComponent,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ <h3>Session Forecast</h3>
</ng-container>

<div *ngIf="!ctx.player.session?.isBefore" class="text-center my-4">
<a *ngIf="ctx.game.mode != 'unity'; else toCubespace" class="btn btn-primary btn-lg"
[routerLink]="['../board', ctx.player.id]">Continue to Gameboard</a>
<app-continue-to-gameboard-button
[context]="{ player: ctx.player, gameId: ctx.game.id, gameMode: ctx.game.mode}"></app-continue-to-gameboard-button>
</div>

<div class="col d-flex justify-content-center" *ngIf="ctx.game.mapUrl">
Expand Down
8 changes: 8 additions & 0 deletions projects/gameboard-ui/src/app/services/router.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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)
Expand Down

0 comments on commit f44ad46

Please sign in to comment.