Skip to content

Commit

Permalink
upgrade deps, add new civs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosack committed Feb 10, 2018
1 parent 4196837 commit f952c11
Show file tree
Hide file tree
Showing 40 changed files with 1,855 additions and 1,173 deletions.
5 changes: 5 additions & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ function createWindow() {
}
}
]
}, {
label: 'Donate!',
click: () => {
opn('https://patreon.com/pydt');
}
}];

if (process.platform === 'darwin') {
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "playyourdamnturn",
"productName": "Play Your Damn Turn Client",
"version": "1.2.0",
"version": "1.2.1",
"description": "Desktop Client to assist with playing your damn turns.",
"author": "playyourdamnturn.com",
"main": "main.js",
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dist-linux": "bash -c \"npm run build-prod; electron-builder --linux --publish always\"",
"postinstall": "install-app-deps",
"lint": "tslint --type-check --project tsconfig.json --exclude ./ui/swagger/**/*.ts ./ui/**/*.ts",
"swagger-codegen": "bash -c \"mkdir -p .tmp && cp ../api/api/_gen/swagger/swagger.json .tmp/swagger.json && MSYS_NO_PATHCONV=1 docker run --rm -v ${PWD}:/local jimschubert/swagger-codegen-cli:2.2.3 generate -i /local/.tmp/swagger.json -l typescript-angular2 -o /local/ui/swagger/api -DmodelPropertyNaming=original\""
"swagger-codegen": "bash -c \"mkdir -p .tmp && cp ../api/api/_gen/swagger/swagger.json .tmp/swagger.json && MSYS_NO_PATHCONV=1 docker run --rm -v ${PWD}:/local jimschubert/swagger-codegen-cli:2.3.1 generate -i /local/.tmp/swagger.json -l typescript-angular --additional-properties ngVersion=4 -o /local/ui/swagger/api -DmodelPropertyNaming=original\""
},
"build": {
"appId": "play.your.damn.turn.client",
Expand All @@ -28,15 +28,15 @@
},
"repository": "https://github.com/pydt/client",
"devDependencies": {
"@angular/animations": "4.4.6",
"@angular/common": "4.4.6",
"@angular/compiler": "4.4.6",
"@angular/core": "4.4.6",
"@angular/forms": "4.4.6",
"@angular/http": "4.4.6",
"@angular/platform-browser": "4.4.6",
"@angular/platform-browser-dynamic": "4.4.6",
"@angular/router": "4.4.6",
"@angular/animations": "5.2.4",
"@angular/common": "5.2.4",
"@angular/compiler": "5.2.4",
"@angular/core": "5.2.4",
"@angular/forms": "5.2.4",
"@angular/http": "5.2.4",
"@angular/platform-browser": "5.2.4",
"@angular/platform-browser-dynamic": "5.2.4",
"@angular/router": "5.2.4",
"@types/chokidar": "^1.7.3",
"@types/countdown": "0.0.5",
"@types/lodash": "^4.14.85",
Expand All @@ -58,30 +58,30 @@
"electron-json-storage": "^3.1.0",
"es6-shim": "^0.35.3",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^0.11.2",
"file-loader": "^1.1.6",
"json-loader": "^0.5.7",
"lodash": "^4.17.4",
"mkdirp": "0.5.1",
"ngx-bootstrap": "^1.9.1",
"ngx-bootstrap": "^2.0.2",
"node-sass": "^4.7.1",
"pako": "^1.0.6",
"pydt-shared": "git+https://github.com/pydt/shared.git",
"raw-loader": "0.5.1",
"resolve-url-loader": "^2.2.0",
"rxjs": "^5.5.2",
"rxjs": "^5.5.6",
"sass-loader": "^6.0.6",
"shebang-loader": "0.0.1",
"style-loader": "^0.19.0",
"systemjs": "^0.20.19",
"ts-loader": "^2.3.4",
"tslint": "^5.7.0",
"style-loader": "^0.20.1",
"systemjs": "^0.21.0",
"ts-loader": "^3.5.0",
"tslint": "^5.9.1",
"tslint-loader": "^3.5.3",
"typescript": "^2.5.2",
"typings": "^2.1.1",
"url-loader": "^0.6.2",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4",
"zone.js": "^0.8.18"
"zone.js": "^0.8.20"
},
"dependencies": {
"ng2-validation": "^4.2.0"
Expand Down
12 changes: 2 additions & 10 deletions ui/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ModalDirective } from 'ngx-bootstrap/modal';
import { Router } from '@angular/router';
import { PydtSettings } from './shared/pydtSettings';
import * as app from 'electron';
import { NgZone } from '@angular/core';
import { AuthService } from './shared/authService';
import * as app from 'electron';

@Component({
selector: 'pydt-app',
Expand All @@ -20,15 +18,9 @@ export class AppComponent implements OnInit {
@ViewChild('manualUpdateModal') manualUpdateModal: ModalDirective;
@ViewChild('settingsModal') settingsModal: ModalDirective;

constructor(private auth: AuthService, private router: Router, private zone: NgZone) {}
constructor(private zone: NgZone) {}

ngOnInit() {
this.auth.getToken().then(token => {
if (!token) {
this.router.navigate(['/auth']);
}
});

app.ipcRenderer.on('show-about-modal', (e, data) => {
this.zone.run(() => {
this.hideAllModals();
Expand Down
23 changes: 14 additions & 9 deletions ui/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import { PlayTurnComponent } from './playTurn/playTurn.component';
import { PlayTurnState } from './playTurn/playTurnState.service';

import { BusyService, BusyComponent, ProfileCacheService } from 'pydt-shared';
import { DefaultApi, BASE_PATH } from './swagger/api';
import { ApiModule, DefaultService, Configuration } from './swagger/api';
import { PydtHttp } from './shared/pydtHttp';
import { AuthService } from './shared/authService';

@NgModule({
imports: [
ApiModule,
BrowserModule,
BrowserAnimationsModule,
CustomFormsModule,
Expand All @@ -45,24 +46,28 @@ import { AuthService } from './shared/authService';
],
providers: [
AuthService,
{
provide: Configuration,
useValue: new Configuration({
basePath: PYDT_CONFIG.API_URL
})
},
{
provide: ProfileCacheService,
useFactory: (api: DefaultApi) => {
useFactory: (api: DefaultService) => {
return new ProfileCacheService(api);
},
deps: [DefaultApi]
deps: [DefaultService]
},
PlayTurnState,
BusyService,
{ provide: BASE_PATH, useValue: PYDT_CONFIG.API_URL },
{
provide: Http,
useFactory: (backend: XHRBackend, options: RequestOptions, busy: BusyService, auth: AuthService) => {
return new PydtHttp(backend, options, busy, auth);
useFactory: (backend: XHRBackend, options: RequestOptions, busy: BusyService) => {
return new PydtHttp(backend, options, busy);
},
deps: [XHRBackend, RequestOptions, BusyService, AuthService]
},
DefaultApi
deps: [XHRBackend, RequestOptions, BusyService]
}
],
bootstrap: [AppComponent]
})
Expand Down
2 changes: 1 addition & 1 deletion ui/auth/auth.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AuthComponent {
constructor(private auth: AuthService, private router: Router) {}

onSubmit() {
this.auth.store(this.model.token)
this.auth.storeToken(this.model.token)
.then(() => {
this.router.navigate(['/']);
});
Expand Down
30 changes: 19 additions & 11 deletions ui/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Http } from '@angular/http';
import { ProfileCacheService } from 'pydt-shared';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { Game, SteamProfile, DefaultApi } from '../swagger/api';
import { Game, SteamProfile, DefaultService } from '../swagger/api';
import { Router } from '@angular/router';
import { AuthService } from '../shared/authService';
import * as _ from 'lodash';
import * as app from 'electron';
import * as awsIot from 'aws-iot-device-sdk';
Expand All @@ -26,20 +28,26 @@ export class HomeComponent implements OnInit, OnDestroy {
private iotDevice;

constructor(
private api: DefaultApi,
private api: DefaultService,
private http: Http,
private profileCache: ProfileCacheService
private router: Router,
private profileCache: ProfileCacheService,
private authService: AuthService
) {}

ngOnInit() {
this.api.userSteamProfile().subscribe(profile => {
this.profile = profile;
const timer = Observable.timer(10, POLL_INTERVAL);
this.configureIot();
async ngOnInit() {
if (!await this.authService.isAuthenticated()) {
this.router.navigate(['/auth']);
return;
}

this.timerSub = timer.subscribe(() => {
this.loadGames();
});
this.profile = await this.api.userSteamProfile().toPromise();

const timer = Observable.timer(10, POLL_INTERVAL);
this.configureIot();

this.timerSub = timer.subscribe(() => {
this.loadGames();
});
}

Expand Down
2 changes: 1 addition & 1 deletion ui/home/player.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template #tooltipTemplate><span [innerHtml]="getTooltip()"></span></template>
<ng-template #tooltipTemplate><span [innerHtml]="getTooltip()"></span></ng-template>
<div container="body" [tooltip]="tooltipTemplate" #tooltip="bs-tooltip">
<a href="javascript:void(0)" *ngIf="player" class="thumbnail" [class.currentTurn]="game.currentPlayerSteamId === player.steamId">
<img #profileImg [src]="getProfileImg()" style="height:32px;" on-mouseover="profileImg.src = 'https://playyourdamnturn.com/img/civs/' + (civDef?.getImageFileName() || 'RANDOM_RANDOM.png');" on-mouseleave="profileImg.src = getProfileImg();">
Expand Down
65 changes: 35 additions & 30 deletions ui/playTurn/playTurn.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Router } from '@angular/router';
import { PydtSettings } from '../shared/pydtSettings';
import { PlayTurnState } from './playTurnState.service';
import { Observable } from 'rxjs/Observable';
import { DefaultApi } from '../swagger/api';
import { DefaultService } from '../swagger/api';
import * as fs from 'fs';
import * as path from 'path';
import * as mkdirp from 'mkdirp';
Expand All @@ -27,7 +27,7 @@ export class PlayTurnComponent implements OnInit {

constructor(
public playTurnState: PlayTurnState,
private api: DefaultApi,
private api: DefaultService,
private router: Router,
private ngZone: NgZone
) {
Expand Down Expand Up @@ -80,6 +80,7 @@ export class PlayTurnComponent implements OnInit {
if (e.lengthComputable) {
this.curBytes = Math.round(e.loaded / 1024);
this.maxBytes = Math.round(e.total / 1024);
console.log(this.curBytes, this.maxBytes);
}
});
};
Expand All @@ -89,36 +90,40 @@ export class PlayTurnComponent implements OnInit {
};

xhr.onload = e => {
try {
let data = new Uint8Array(xhr.response);

this.ngZone.run(() => {
this.curBytes = this.maxBytes;
try {
data = pako.ungzip(new Uint8Array(xhr.response));
} catch (e) {
// Ignore - file probably wasn't gzipped...
}

fs.writeFile(this.saveFileToPlay, new Buffer(data), (err) => {
if (err) {
reject(err);
} else {
setTimeout(() => {
this.curBytes = this.maxBytes = null;
this.status = 'Downloaded file! Play Your Damn Turn!';

PydtSettings.getSettings().then(settings => {
if (settings.launchCiv) {
app.ipcRenderer.send('opn-url', 'steam://run/289070');
}
});

resolve();
}, 500);
let data = new Uint8Array(xhr.response);

try {
data = pako.ungzip(new Uint8Array(xhr.response));
} catch (e) {
// Ignore - file probably wasn't gzipped...
}
});
} catch (err) {
reject(err);
}

fs.writeFile(this.saveFileToPlay, new Buffer(data), (err) => {
if (err) {
reject(err);
} else {
setTimeout(() => {
this.curBytes = this.maxBytes = null;
this.status = 'Downloaded file! Play Your Damn Turn!';

PydtSettings.getSettings().then(settings => {
if (settings.launchCiv) {
app.ipcRenderer.send('opn-url', 'steam://run/289070');
}
});

resolve();
}, 500);
}
});
} catch (err) {
reject(err);
}
});
};
xhr.send();
});
Expand Down
19 changes: 15 additions & 4 deletions ui/shared/authService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { Injectable } from '@angular/core';
import { Configuration } from '../swagger/api';
import * as storage from 'electron-json-storage';

@Injectable()
export class AuthService {
store(token: string): Promise<void> {
constructor(private apiConfig: Configuration) {
}

async isAuthenticated() {
await this.setApiConfig();
return !!this.apiConfig.apiKeys.Authorization;
}

storeToken(token: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
const config = {
token: token
Expand All @@ -16,16 +25,18 @@ export class AuthService {

resolve();
});
}).then(() => {
return this.setApiConfig();
});
}

getToken(): Promise<string> {
private setApiConfig() {
return this.getConfig().then(config => {
return config.token;
this.apiConfig.apiKeys = { Authorization: config ? config.token : null };
});
}

getConfig(): Promise<any> {
private getConfig(): Promise<any> {
return new Promise((resolve, reject) => {
storage.get('configData', (err, config) => {
if (err) {
Expand Down
Loading

0 comments on commit f952c11

Please sign in to comment.