Compare commits

...

8 Commits

Author SHA1 Message Date
Paddy 8d6129590a Fixing user info reading at page load
Jenkins Production Deployment
2022-09-26 17:59:36 +02:00
Paddy 13aa2c29b0 Fix bug where summary page was displayed together with extra points page 2022-09-26 17:45:17 +02:00
Paddy 5f256e1983 Adding first unit test for score calculation
Jenkins Production Deployment
2022-09-16 16:43:37 +02:00
Paddy 4dbc6a2a4d Adding point for winning against the elders
Jenkins Production Deployment
2022-09-16 15:28:01 +02:00
Paddy e26cd21cc6 Adding "game summary" page to add game component
Jenkins Production Deployment
2022-09-16 13:59:22 +02:00
Paddy 139fb20814 Adding comments to solo functions, prevent continuing process without selected solo
Jenkins Production Deployment
2022-09-16 12:33:18 +02:00
Paddy 1027011447 Adding solo page to add game component
Jenkins Production Deployment
2022-09-16 12:22:32 +02:00
Paddy b09b683727 Smol refactor
Jenkins Production Deployment
2022-09-16 11:50:39 +02:00
6 changed files with 196 additions and 18 deletions
@@ -47,10 +47,23 @@
<button (click)="switchToNextPage()" [disabled]="!calculatePointSum()">Next</button>
</div>
<div id="which-solo" class="visible-{{this.currentPage === 4}}">
<p>Select the Solo that has been played:</p>
<div class="togglebtn active-{{isSoloActive(solo)}}" *ngFor="let solo of getAllPossibleSolos()" (click)="toggleSolo(solo)">{{solo.toString()}}</div>
<p id="solo-warn" *ngIf="noSoloSelectedYet()">Please select a solo to continue</p>
<button (click)="switchToNextPage()" [disabled]="noSoloSelectedYet()">Next</button>
</div>
<div id="extra-points" class="visible-{{this.currentPage === 5}}">
<p>Extra Points</p>
<div *ngFor="let player of actualPlayers">
<p>{{player.firstName}}</p>
<input type="number" [(ngModel)]="player.foxesCaught" (change)="this.calculateCurrentScores()"/>
</div>
<p id="foxes-warn" *ngIf="!checkTotalFoxPoints()">Please check the number of caught foxes!</p>
<button (click)="switchToNextPage()" [disabled]="!checkAllExtraPoints()">Next</button>
</div>
<div id="summary" class="visible-{{this.currentPage === 6}}">
<p>Game Summary</p>
<button (click)="saveGame()">Save Game</button>
</div>
</div>
<div id="scores">
@@ -30,7 +30,7 @@
color: $inactive;
}
#player-amount-warn, #announcement-warn, #team-warn, #score-warn {
#player-amount-warn, #announcement-warn, #team-warn, #score-warn, #solo-warn {
color: $warn;
}
@@ -1,6 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AddGameComponent } from './add-game.component';
import {Team} from '../../models/doppelkopf/enums/team';
describe('AddGameComponent', () => {
let component: AddGameComponent;
@@ -20,4 +21,49 @@ describe('AddGameComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should have the correct score for a normal game', () => {
// Set up testing data
component.actualPlayers = [
{
firebonkId: 1,
uuid: 'abc-def-ghi-j',
firstName: 'Patrick',
team: Team.RE,
gamePoints: 0,
finalCardScore: 123,
},
{
firebonkId: 1,
uuid: 'abc-def-ghi-k',
firstName: 'Julian',
team: Team.RE,
gamePoints: 17,
finalCardScore: 0,
},
{
firebonkId: 1,
uuid: 'abc-def-ghi-l',
firstName: 'Yanick',
team: Team.CONTRA,
gamePoints: 50,
finalCardScore: 0,
},
{
firebonkId: 1,
uuid: 'abc-def-ghi-m',
firstName: 'Janina',
team: Team.CONTRA,
gamePoints: 50,
finalCardScore: 0,
},
]
component.calculateCurrentScores();
expect(component.actualPlayers[0].gamePoints).toEqual(1);
expect(component.actualPlayers[1].gamePoints).toEqual(1);
expect(component.actualPlayers[2].gamePoints).toEqual(-1);
expect(component.actualPlayers[3].gamePoints).toEqual(-1);
})
});
@@ -1,6 +1,7 @@
import {Component, OnInit} from '@angular/core';
import {Player} from '../../models/doppelkopf/player';
import * as announcements from '../../models/doppelkopf/enums/announcement';
import * as solos from '../../models/doppelkopf/enums/solo';
import {Team} from '../../models/doppelkopf/enums/team';
@Component({
@@ -13,6 +14,7 @@ export class AddGameComponent implements OnInit {
actualPlayers: Player[] = [];
selectedAnnouncements: announcements.Announcement[] = [];
soloPlayed?: solos.Solo;
currentPage: number = 0;
@@ -81,6 +83,11 @@ export class AddGameComponent implements OnInit {
this.calculateCurrentScores();
}
if(this.currentPage === 3 && !this.checkIfSolo()) {
// If we don't play a solo, we can skip the solo page
this.currentPage++;
}
this.currentPage++;
}
@@ -398,6 +405,11 @@ export class AddGameComponent implements OnInit {
winningTeam = winningTeam === Team.RE ? Team.CONTRA : Team.RE;
}
if(winningTeam === Team.CONTRA) {
// Against the elders
gameScore++;
}
// Double Score in case of announcement
if (this.checkAnnouncementActive(announcements.Announcement.RE)) {
gameScore *= 2;
@@ -436,24 +448,24 @@ export class AddGameComponent implements OnInit {
// Announcements
if (winningTeam === Team.RE) {
if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_NINETY) && winningTeamScore > 150) {
gameScore += 1;
gameScore++;
}
if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_SIXTY) && winningTeamScore > 180) {
gameScore += 1;
gameScore++;
}
if (this.checkAnnouncementActive(announcements.Announcement.RE_NO_THIRTY) && winningTeamScore > 210) {
gameScore += 1;
gameScore++;
}
}
if (winningTeam === Team.CONTRA) {
if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_NINETY) && winningTeamScore > 150) {
gameScore += 1;
gameScore++;
}
if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_SIXTY) && winningTeamScore > 180) {
gameScore += 1;
gameScore++;
}
if (this.checkAnnouncementActive(announcements.Announcement.CONTRA_NO_THIRTY) && winningTeamScore > 210) {
gameScore += 1;
gameScore++;
}
}
@@ -632,4 +644,80 @@ export class AddGameComponent implements OnInit {
return numberOfElders === 1;
}
/**
* Checks if the given solo is currently active
* @param solo The solo to check active status for
*/
isSoloActive(solo: solos.Solo): boolean {
return this.soloPlayed === solo;
}
/**
* Returns all possible solo values
*/
getAllPossibleSolos(): solos.Solo[] {
return solos.getAllSoloValues();
}
/**
* Toggles the given solo as the active one
* @param solo The solo to set as the active one
*/
toggleSolo(solo: solos.Solo): void {
this.soloPlayed = solo;
}
/**
* Returns true if there is a solo selected, false otherwise
*/
noSoloSelectedYet(): boolean {
return this.soloPlayed === undefined;
}
/**
* ______ __ ____ _ __
* / ____/ __/ /__________ _ / __ \____ (_)___ / /______
* / __/ | |/_/ __/ ___/ __ `/ / /_/ / __ \/ / __ \/ __/ ___/
* / /____> </ /_/ / / /_/ / / ____/ /_/ / / / / / /_(__ )
* /_____/_/|_|\__/_/ \__,_/ /_/ \____/_/_/ /_/\__/____/
*/
/**
* Checks if the number of caught foxes checks out
*/
checkTotalFoxPoints(): boolean {
let totalFoxPoints: number = 0;
for (let player of this.actualPlayers) {
totalFoxPoints += player.foxesCaught ?? 0;
}
return totalFoxPoints <= 2;
}
/**
* Checks if all extra point types have valid entries
*/
checkAllExtraPoints(): boolean {
return this.checkTotalFoxPoints();
}
/**
* _____
* / ___/__ ______ ___ ____ ___ ____ ________ __
* \__ \/ / / / __ `__ \/ __ `__ \/ __ `/ ___/ / / /
* ___/ / /_/ / / / / / / / / / / / /_/ / / / /_/ /
* /____/\__,_/_/ /_/ /_/_/ /_/ /_/\__,_/_/ \__, /
* /____/
*/
/**
* Sends the game stats to the API to be saved
*/
saveGame(): void {
//TODO implement
// call api method, then return to gameNight page / close modal or sth like that
window.location.reload();
}
}
+22 -7
View File
@@ -1,9 +1,24 @@
export enum Solo {
QUEENS = 0,
JACKS = 1,
COLOR_CHECKS = 2,
COLOR_HEART = 3,
COLOR_SPADES = 4,
COLOR_CROSS = 5,
FLESHLESS = 6
QUEENS = 'Queens',
JACKS = 'Jacks',
COLOR_CHECKS = 'Checks',
COLOR_HEART = 'Heart',
COLOR_SPADES = 'Spades',
COLOR_CROSS = 'Cross',
FLESHLESS = 'Fleshless'
}
/**
* Returns all available solo values
*/
export function getAllSoloValues(): Solo[] {
return [
Solo.QUEENS,
Solo.JACKS,
Solo.COLOR_CHECKS,
Solo.COLOR_HEART,
Solo.COLOR_SPADES,
Solo.COLOR_CROSS,
Solo.FLESHLESS
];
}
+17 -1
View File
@@ -17,8 +17,20 @@ export class HomeComponent implements OnInit {
}
ngOnInit(): void {
// TODO: First try to read existing session data
if(!HomeComponent.sessionDataAvailable()) {
this.authenticateUser();
window.location.reload();
}
}
/**
* Checks if there is session data saved in the local storage
* @return If there is session data available
*/
private static sessionDataAvailable(): boolean {
let user = StorageService.getUserInfo();
return user !== undefined;
}
/**
@@ -35,6 +47,10 @@ export class HomeComponent implements OnInit {
sessionKey: ''
};
if(user.firebonkId === undefined || user.firstName === undefined || user.token === undefined) {
return;
}
let authenticatedUser = ApiService.performAuthentication(user);
StorageService.setUserInfo(authenticatedUser);
});