Adding advanced announcement selection logic
All checks were successful
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2022-09-14 19:00:23 +02:00
parent cd5154a07a
commit e41a07411e
Signed by: Paddy
GPG Key ID: 37ABC11275CAABCE

View File

@ -1,6 +1,6 @@
import {Component, OnInit} from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {Player} from '../../models/doppelkopf/player'; import {Player} from '../../models/doppelkopf/player';
import * as Announcement from '../../models/doppelkopf/enums/announcement'; import * as announcements from '../../models/doppelkopf/enums/announcement';
import {Team} from '../../models/doppelkopf/enums/team'; import {Team} from '../../models/doppelkopf/enums/team';
@Component({ @Component({
@ -12,7 +12,7 @@ export class AddGameComponent implements OnInit {
potentialPlayers: Player[] = []; potentialPlayers: Player[] = [];
actualPlayers: Player[] = []; actualPlayers: Player[] = [];
selectedAnnouncements: Announcement.Announcement[] = []; selectedAnnouncements: announcements.Announcement[] = [];
currentPage: number = 0; currentPage: number = 0;
@ -127,15 +127,116 @@ export class AddGameComponent implements OnInit {
*/ */
/** /**
* Toggles the activity status for the given announcement * Toggles the activity status for the given announcement and also activates / deactivates other announcements
* to conform to the rules.
* @param announcement The announcement to toggle activity for * @param announcement The announcement to toggle activity for
*/ */
toggleAnnouncement(announcement: Announcement.Announcement): void { toggleAnnouncement(announcement: announcements.Announcement): void {
let index = this.selectedAnnouncements.indexOf(announcement); let index = this.selectedAnnouncements.indexOf(announcement);
if (index !== -1) { if (index !== -1) {
this.selectedAnnouncements.splice(index, 1); this.selectedAnnouncements.splice(index, 1);
this.deactivateLowerAnnouncements(announcement);
} else { } else {
this.selectedAnnouncements.push(announcement); this.selectedAnnouncements.push(announcement);
this.activateHigherAnnouncements(announcement);
}
}
/**
* Deactivates all lower announcements. E.g.: When RE is deactivated, RE_NO_NINETY and all lower also get deactivated
* @param announcement The announcement that has been deactivated
*/
deactivateLowerAnnouncements(announcement: announcements.Announcement) {
// First for RE
switch(announcement) {
case announcements.Announcement.RE:
this.deactivateAnnouncement(announcements.Announcement.RE_NO_NINETY);
this.deactivateAnnouncement(announcements.Announcement.RE_NO_SIXTY);
this.deactivateAnnouncement(announcements.Announcement.RE_NO_THIRTY);
break;
case announcements.Announcement.RE_NO_NINETY:
this.deactivateAnnouncement(announcements.Announcement.RE_NO_SIXTY);
this.deactivateAnnouncement(announcements.Announcement.RE_NO_THIRTY);
break;
case announcements.Announcement.RE_NO_SIXTY:
this.deactivateAnnouncement(announcements.Announcement.RE_NO_THIRTY);
break;
}
// Now for CONTRA
switch(announcement) {
case announcements.Announcement.CONTRA:
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_NINETY);
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_SIXTY);
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_THIRTY);
break;
case announcements.Announcement.CONTRA_NO_NINETY:
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_SIXTY);
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_THIRTY);
break;
case announcements.Announcement.CONTRA_NO_SIXTY:
this.deactivateAnnouncement(announcements.Announcement.CONTRA_NO_THIRTY);
break;
}
}
/**
* Deactivates the given announcement if it is active
* @param announcement The announcement to deactivate
*/
deactivateAnnouncement(announcement: announcements.Announcement) {
let index = this.selectedAnnouncements.indexOf(announcement);
if (index !== -1) {
this.selectedAnnouncements.splice(index, 1);
}
}
/**
* Activates all higher announcements. E.g.: When RE_NO_NINETY is activated, RE also gets activated
* @param announcement The announcement that has been activated
*/
activateHigherAnnouncements(announcement: announcements.Announcement) {
// First for RE
switch(announcement) {
case announcements.Announcement.RE_NO_THIRTY:
this.activateAnnouncement(announcements.Announcement.RE_NO_SIXTY);
this.activateAnnouncement(announcements.Announcement.RE_NO_NINETY);
this.activateAnnouncement(announcements.Announcement.RE);
break;
case announcements.Announcement.RE_NO_SIXTY:
this.activateAnnouncement(announcements.Announcement.RE_NO_NINETY);
this.activateAnnouncement(announcements.Announcement.RE);
break;
case announcements.Announcement.RE_NO_NINETY:
this.activateAnnouncement(announcements.Announcement.RE);
break;
}
// Now for CONTRA
switch(announcement) {
case announcements.Announcement.CONTRA_NO_THIRTY:
this.activateAnnouncement(announcements.Announcement.CONTRA_NO_SIXTY);
this.activateAnnouncement(announcements.Announcement.CONTRA_NO_NINETY);
this.activateAnnouncement(announcements.Announcement.CONTRA);
break;
case announcements.Announcement.CONTRA_NO_SIXTY:
this.activateAnnouncement(announcements.Announcement.CONTRA_NO_NINETY);
this.activateAnnouncement(announcements.Announcement.CONTRA);
break;
case announcements.Announcement.CONTRA_NO_NINETY:
this.activateAnnouncement(announcements.Announcement.CONTRA);
break;
}
}
/**
* Activates the given announcement if it is inactive
* @param announcement The announcement to activate
*/
activateAnnouncement(announcement: announcements.Announcement) {
let index = this.selectedAnnouncements.indexOf(announcement);
if (index === -1) {
this.selectedAnnouncements.push(announcement);
} }
} }
@ -143,26 +244,26 @@ export class AddGameComponent implements OnInit {
* Checks if the given announcement is already marked as selected * Checks if the given announcement is already marked as selected
* @param announcement The announcement to check the status for * @param announcement The announcement to check the status for
*/ */
isAnnouncementActive(announcement: Announcement.Announcement): boolean { isAnnouncementActive(announcement: announcements.Announcement): boolean {
return this.selectedAnnouncements.indexOf(announcement) !== -1; return this.selectedAnnouncements.indexOf(announcement) !== -1;
} }
/** /**
* Returns a list of all possible announcements * Returns a list of all possible announcements
*/ */
getAllPossibleAnnouncements(): Announcement.Announcement[] { getAllPossibleAnnouncements(): announcements.Announcement[] {
return Announcement.getAllAnnouncementValues(); return announcements.getAllAnnouncementValues();
} }
/** /**
* Checks, if the currently selected announcements are a valid set of announcements * Checks, if the currently selected announcements are a valid set of announcements
*/ */
checkAnnouncementsValid(): boolean { checkAnnouncementsValid(): boolean {
return Announcement.checkValidity(this.selectedAnnouncements); return announcements.checkValidity(this.selectedAnnouncements);
} }
getHighestAnnouncements(): string { getHighestAnnouncements(): string {
return Announcement.returnTwoHighestAnnouncements(this.selectedAnnouncements); return announcements.returnTwoHighestAnnouncements(this.selectedAnnouncements);
} }
/** /**