import {Component, OnInit} from '@angular/core'; import {Player} from '../../models/doppelkopf/player'; @Component({ selector: 'app-add-game', templateUrl: './add-game.component.html', styleUrls: ['./add-game.component.scss'] }) export class AddGameComponent implements OnInit { potentialPlayers: Player[] = []; actualPlayers: Player[] = []; currentPage: number = 0; constructor() { this.potentialPlayers.push({ firebonkId: 1, uuid: 'abc-def-ghi-j', firstName: 'Patrick' }); this.potentialPlayers.push({ firebonkId: 2, uuid: 'abc-def-ghi-k', firstName: 'Julian' }); this.potentialPlayers.push({ firebonkId: 3, uuid: 'abc-def-ghi-l', firstName: 'Yannick' }); this.potentialPlayers.push({ firebonkId: 4, uuid: 'abc-def-ghi-m', firstName: 'Janina' }); this.potentialPlayers.push({ firebonkId: 5, uuid: 'abc-def-ghi-n', firstName: 'Moritz' }); this.actualPlayers.push(...this.potentialPlayers.slice(0,4)); } ngOnInit(): void { } /** * Toggles if the given player is should be an active player for the current game * @param player The player to toggle the activity for */ togglePlayer(player: Player): void { let index = this.actualPlayers.indexOf(player); if(index !== -1){ this.actualPlayers.splice(index, 1); } else { this.actualPlayers.push(player); } } /** * Checks, if the given player is currently marked as active for this game * @param player The player to check the activity status for * @returns boolean If the player is active */ isPlayerActive(player: Player): boolean { return this.actualPlayers.indexOf(player) !== -1; } /** * Returns, if the amount of currently active players is greater or less than 4 */ not4Players() { return this.actualPlayers.length !== 4; } /** * Switches the entry mask UI to the next page */ switchToNextPage(): void { this.currentPage++; } }