Skip to content

Commit

Permalink
download turns/endgame video
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosack committed Jun 16, 2023
1 parent 11273c8 commit 8088a88
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 12 deletions.
6 changes: 3 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@
"outputHashing": "all",
"optimization": true
},
"development": {
}
"development": {}
},
"defaultConfiguration": "development"
},
Expand Down Expand Up @@ -97,6 +96,7 @@
"scripts": [],
"styles": [
"src/styles/app.scss",
"node_modules/@videogular/ngx-videogular/fonts/videogular.css",
"node_modules/dragula/dist/dragula.css"
],
"assets": [
Expand Down Expand Up @@ -213,4 +213,4 @@
],
"analytics": false
}
}
}
39 changes: 32 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@angular/router": "^15.0.4",
"@angular/service-worker": "^15.0.4",
"@nguniversal/express-engine": "^15.0.0",
"@videogular/ngx-videogular": "^8.0.0",
"angulartics2": "^12.2.0",
"bootstrap-sass": "^3.4.3",
"core-js": "^3.27.0",
Expand All @@ -45,7 +46,7 @@
"ngx-clipboard": "^15.1.0",
"ngx-markdown": "^15.0.0",
"pako": "^2.1.0",
"pydt-shared": "^1.8.4",
"pydt-shared": "^1.8.5-beta4",
"remove-markdown": "^0.5.0",
"rollbar": "^2.26.0",
"rxjs": "^7.8.0",
Expand Down
8 changes: 8 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import {
BusyService,
MetadataCacheService,
} from "pydt-shared";
import { VgCoreModule } from "@videogular/ngx-videogular/core";
import { VgControlsModule } from "@videogular/ngx-videogular/controls";
import { VgOverlayPlayModule } from "@videogular/ngx-videogular/overlay-play";
import { VgBufferingModule } from "@videogular/ngx-videogular/buffering";
import { Ng2TableModule } from "../ng2-table/ng-table-module";
import * as envVars from "../envVars";
import { AppComponent } from "./app.component";
Expand Down Expand Up @@ -103,6 +107,10 @@ export const profileCacheFactory = (userService: UserService): ProfileCacheServi
Ng2TableModule,
routing,
Angulartics2Module.forRoot(),
VgCoreModule,
VgControlsModule,
VgOverlayPlayModule,
VgBufferingModule,
// https://github.com/angular/angular/issues/47455
ServiceWorkerModule.register("pydt-service-worker.js", { enabled: environment.production }),
],
Expand Down
9 changes: 9 additions & 0 deletions src/app/game/detail/stats/stats.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@
></ng-table>
</div>
</div>
<div *ngIf="game.gameVideoUrl" class="row">
<div class="col-md-12">
<vg-player>
<video [vgMedia]="media" #media id="replay" preload="auto" controls>
<source [src]="game.gameVideoUrl" type="video/webm">

Check failure on line 20 in src/app/game/detail/stats/stats.component.html

View workflow job for this annotation

GitHub Actions / deploy

Replace `··<source·[src]="game.gameVideoUrl"·type="video/webm"` with `<source·[src]="game.gameVideoUrl"·type="video/webm"·/`
</video>
</vg-player>

Check failure on line 22 in src/app/game/detail/stats/stats.component.html

View workflow job for this annotation

GitHub Actions / deploy

Insert `··`
</div>
</div>
39 changes: 38 additions & 1 deletion src/app/game/detail/turns/turns.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from "@angular/core";
import { Component, HostListener, Input, OnInit } from "@angular/core";
import * as moment from "moment";
import {
Game,
Expand All @@ -13,6 +13,7 @@ import {
import { Utility } from "../../../shared/utility";
import { Parser } from "json2csv";
import * as FileSaver from "file-saver";
import { AuthService } from "../../../shared";

export interface TableColumn {
title: string;
Expand Down Expand Up @@ -48,6 +49,7 @@ export class GameDetailTurnsComponent implements OnInit {
private profileCache: ProfileCacheService,
private gameService: GameService,
private metadataCache: MetadataCacheService,
private auth: AuthService,
) {}

get civGame(): CivGame {
Expand Down Expand Up @@ -112,7 +114,39 @@ export class GameDetailTurnsComponent implements OnInit {
FileSaver.saveAs(blob, `${this.game.displayName}.csv`);
}

@HostListener("window:DownloadTurn", ["$event.detail"])
public async downloadTurn(turn: number): Promise<void> {
const resp = await this.gameService.getTurnById(this.game.gameId, turn).toPromise();

window.location.href = resp.downloadUrl;
}

private createTableData(turns: GameTurn[], textOnly: boolean): unknown[] {
const canDownload = (turn: GameTurn) => {
if (!this.auth.getToken()) {
// Unauthenticated users can't download
return false;
}

// Only go back 20 turns since that's all PYDT keeps
if (turn.turn < (this.game.gameTurnRangeKey || 0) - 20) {
return false;
}

// Allow download if it's the end user's turn or if the game is finalized
return this.game.finalized || turn.playerSteamId === this.auth.getSteamProfile().steamid;
};

if (turns.some(x => canDownload(x)) && !this.tableColumns.some(x => x.name === "download")) {
this.tableColumns = [
...this.tableColumns,
{
title: "Download",
name: "download",
},
];
}

return turns.map(turn => {
let timeTaken = "";

Expand All @@ -130,6 +164,9 @@ export class GameDetailTurnsComponent implements OnInit {
endDate: turn.endDate ? moment(turn.endDate).format("LLL") : "In Progress...",
timeTaken: timeTaken.toString(),
skipped: turn.skipped ? "Skipped!" : "",
download: canDownload(turn)
? `<a href='#' *ngIf="false" onClick="window.dispatchEvent(new CustomEvent('DownloadTurn', { detail: ${turn.turn} }));return false;">Download</a>`
: "",
};
});
}
Expand Down

0 comments on commit 8088a88

Please sign in to comment.