init release
This commit is contained in:
62
src/app/training/training.component.ts
Normal file
62
src/app/training/training.component.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
// src/app/training.component.ts
|
||||
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { Deck, DeckImage } from '../deck.service';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
@Component({
|
||||
selector: 'app-training',
|
||||
templateUrl: './training.component.html',
|
||||
standalone: true,
|
||||
imports: [CommonModule]
|
||||
})
|
||||
export class TrainingComponent {
|
||||
@Input() deck!: Deck;
|
||||
@Output() close = new EventEmitter<void>();
|
||||
|
||||
currentIndex: number = 0;
|
||||
knownCount: number = 0;
|
||||
unknownCount: number = 0;
|
||||
showTextFlag: boolean = false;
|
||||
|
||||
get currentImage(): DeckImage | null {
|
||||
if (this.currentIndex < this.deck.images.length) {
|
||||
return this.deck.images[this.currentIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
get progress(): string {
|
||||
return `Fortschritt: ${this.currentIndex} / ${this.deck.images.length}`;
|
||||
}
|
||||
|
||||
showText(): void {
|
||||
this.showTextFlag = true;
|
||||
}
|
||||
|
||||
markKnown(): void {
|
||||
this.knownCount++;
|
||||
this.nextImage();
|
||||
}
|
||||
|
||||
markUnknown(): void {
|
||||
this.unknownCount++;
|
||||
this.nextImage();
|
||||
}
|
||||
|
||||
nextImage(): void {
|
||||
this.currentIndex++;
|
||||
this.showTextFlag = false;
|
||||
if (this.currentIndex >= this.deck.images.length) {
|
||||
this.endTraining();
|
||||
}
|
||||
}
|
||||
|
||||
endTraining(): void {
|
||||
alert(`Training beendet!\nGewusst: ${this.knownCount}\nNicht gewusst: ${this.unknownCount}`);
|
||||
this.close.emit();
|
||||
}
|
||||
|
||||
closeTraining(): void {
|
||||
this.close.emit();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user