|
@@ -1,5 +1,7 @@
|
|
import { Component } from '@angular/core';
|
|
import { Component } from '@angular/core';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
|
|
+import { DetailsService } from 'src/services/details/details.service';
|
|
|
|
+import { LifeDetailsComponent } from './life-details/life-details.component';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'app-life',
|
|
selector: 'app-life',
|
|
@@ -7,7 +9,10 @@ import { DataService } from 'src/services/data/data.service';
|
|
styleUrls: ['./life.component.scss'],
|
|
styleUrls: ['./life.component.scss'],
|
|
})
|
|
})
|
|
export class LifeComponent {
|
|
export class LifeComponent {
|
|
- public constructor(public dataAccessor: DataService) {}
|
|
|
|
|
|
+ public constructor(
|
|
|
|
+ public dataAccessor: DataService,
|
|
|
|
+ public detailsAccessor: DetailsService
|
|
|
|
+ ) {}
|
|
|
|
|
|
public maxHitPoints: number = 0;
|
|
public maxHitPoints: number = 0;
|
|
public currentHitPoints: number = 0;
|
|
public currentHitPoints: number = 0;
|
|
@@ -18,61 +23,38 @@ export class LifeComponent {
|
|
public missingHitPointsPercentage: number = 0;
|
|
public missingHitPointsPercentage: number = 0;
|
|
|
|
|
|
ngOnInit(): void {
|
|
ngOnInit(): void {
|
|
- this.initMaxSubscription();
|
|
|
|
- this.initCurrentSubscription();
|
|
|
|
- this.initTemporarySubscription();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private initMaxSubscription(): void {
|
|
|
|
- this.dataAccessor.hitPointMaximum$.subscribe((newValue: any) => {
|
|
|
|
- this.maxHitPoints = newValue.value;
|
|
|
|
- this.calculatePercentages();
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private initCurrentSubscription(): void {
|
|
|
|
- this.dataAccessor.currentHitPoints$.subscribe((newValue: any) => {
|
|
|
|
- this.currentHitPoints = newValue.value;
|
|
|
|
- this.calculatePercentages();
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private initTemporarySubscription(): void {
|
|
|
|
- this.dataAccessor.temporaryHitPoints$.subscribe((newValue: any) => {
|
|
|
|
- this.temporaryHitPoints = newValue.value;
|
|
|
|
- this.calculatePercentages();
|
|
|
|
- });
|
|
|
|
|
|
+ const lifeData = this.dataAccessor.hitPoints;
|
|
|
|
+ this.maxHitPoints = lifeData.maxHitPoints;
|
|
|
|
+ this.currentHitPoints = lifeData.currentHitPoints;
|
|
|
|
+ this.temporaryHitPoints = lifeData.temporaryHitPoints;
|
|
|
|
+ this.calculatePercentages();
|
|
}
|
|
}
|
|
|
|
|
|
public addHitPoints(): void {
|
|
public addHitPoints(): void {
|
|
if (this.currentHitPoints < this.maxHitPoints) {
|
|
if (this.currentHitPoints < this.maxHitPoints) {
|
|
- this.dataAccessor.updateCharacterData({
|
|
|
|
- name: 'currentHitPoints',
|
|
|
|
- value: this.currentHitPoints + 1,
|
|
|
|
- });
|
|
|
|
|
|
+ this.currentHitPoints = this.currentHitPoints + 1;
|
|
|
|
+ this.updateDatabase();
|
|
|
|
+ this.calculatePercentages();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public removeHitPoints(): void {
|
|
public removeHitPoints(): void {
|
|
if (this.temporaryHitPoints > 0) {
|
|
if (this.temporaryHitPoints > 0) {
|
|
- this.dataAccessor.updateCharacterData({
|
|
|
|
- name: 'temporaryHitPoints',
|
|
|
|
- value: this.temporaryHitPoints - 1,
|
|
|
|
- });
|
|
|
|
|
|
+ this.temporaryHitPoints = this.temporaryHitPoints - 1;
|
|
|
|
+ this.updateDatabase();
|
|
|
|
+ this.calculatePercentages();
|
|
} else if (this.currentHitPoints > 0) {
|
|
} else if (this.currentHitPoints > 0) {
|
|
- this.dataAccessor.updateCharacterData({
|
|
|
|
- name: 'currentHitPoints',
|
|
|
|
- value: this.currentHitPoints - 1,
|
|
|
|
- });
|
|
|
|
|
|
+ this.currentHitPoints = this.currentHitPoints - 1;
|
|
|
|
+ this.updateDatabase();
|
|
|
|
+ this.calculatePercentages();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public addTemporaryHitPoints(): void {
|
|
public addTemporaryHitPoints(): void {
|
|
if (this.currentHitPoints > 0) {
|
|
if (this.currentHitPoints > 0) {
|
|
- this.dataAccessor.updateCharacterData({
|
|
|
|
- name: 'temporaryHitPoints',
|
|
|
|
- value: this.temporaryHitPoints + 1,
|
|
|
|
- });
|
|
|
|
|
|
+ this.temporaryHitPoints = this.temporaryHitPoints + 1;
|
|
|
|
+ this.updateDatabase();
|
|
|
|
+ this.calculatePercentages();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -87,5 +69,34 @@ export class LifeComponent {
|
|
this.maxHitPoints;
|
|
this.maxHitPoints;
|
|
}
|
|
}
|
|
|
|
|
|
- // TODO: Set life: Modalmit dem man die Were genau einstellen kann
|
|
|
|
|
|
+ public openDetailsPanel(): void {
|
|
|
|
+ this.detailsAccessor.openPanel(LifeDetailsComponent, {
|
|
|
|
+ lifeData: {
|
|
|
|
+ maxHitPoints: this.maxHitPoints,
|
|
|
|
+ currentHitPoints: this.currentHitPoints,
|
|
|
|
+ temporaryHitPoints: this.temporaryHitPoints,
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ // The result from the details panel with return values
|
|
|
|
+ const resultSubscription = this.detailsAccessor.result$.subscribe(
|
|
|
|
+ (result) => {
|
|
|
|
+ console.log(result);
|
|
|
|
+ this.maxHitPoints = result.data.maxHitPoints;
|
|
|
|
+ this.currentHitPoints = result.data.currentHitPoints;
|
|
|
|
+ this.temporaryHitPoints = result.data.temporaryHitPoints;
|
|
|
|
+
|
|
|
|
+ this.calculatePercentages();
|
|
|
|
+ this.updateDatabase();
|
|
|
|
+ resultSubscription.unsubscribe();
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public updateDatabase() {
|
|
|
|
+ this.dataAccessor.hitPoints = {
|
|
|
|
+ maxHitPoints: this.maxHitPoints,
|
|
|
|
+ currentHitPoints: this.currentHitPoints,
|
|
|
|
+ temporaryHitPoints: this.temporaryHitPoints,
|
|
|
|
+ };
|
|
|
|
+ }
|
|
}
|
|
}
|