From b893b367fa688f5677ef98b1096e0e93cc1dfcb7 Mon Sep 17 00:00:00 2001 From: Manuel Rauber Date: Mon, 11 Mar 2024 16:02:31 +0100 Subject: [PATCH] feat: improve character editor --- .../button/button.component.css} | 0 .../button/button.component.html} | 11 +- .../buttons/button/button.component.ts | 17 ++ .../character-dashboard.component.html | 53 +----- .../character-dashboard.component.ts | 18 +- .../character-main-statistics.component.css | 0 .../character-main-statistics.component.html | 8 + .../character-main-statistics.component.ts | 19 ++ .../character-statistic.component.css | 0 .../character-statistic.component.html | 12 +- .../character-statistic.component.ts | 3 +- .../character-statistics.component.css | 3 + .../character-statistics.component.html | 29 +++ .../character-statistics.component.ts | 166 ++++++++++++++++++ .../character-value-statistics.component.css | 0 .../character-value-statistics.component.html | 88 ++++++++++ .../character-value-statistics.component.ts | 21 +++ .../create-character.component.html | 23 +-- .../create-character.component.ts | 69 ++++---- .../submit-button/submit-button.component.ts | 15 -- .../backup-restore.component.html | 6 +- .../backup-restore.component.ts | 4 +- .../components/tools/dice/dice.component.html | 2 +- .../components/tools/dice/dice.component.ts | 4 +- src/app/models/character/value-statistics.ts | 2 +- src/app/services/characters.service.ts | 41 ++++- ...required-points-to-distribute-validator.ts | 7 +- 27 files changed, 488 insertions(+), 133 deletions(-) rename src/app/components/{inputs/submit-button/submit-button.component.css => buttons/button/button.component.css} (100%) rename src/app/components/{inputs/submit-button/submit-button.component.html => buttons/button/button.component.html} (80%) create mode 100644 src/app/components/buttons/button/button.component.ts create mode 100644 src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.css create mode 100644 src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.html create mode 100644 src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.ts rename src/app/components/characters/{ => character-statistics}/character-statistic/character-statistic.component.css (100%) rename src/app/components/characters/{ => character-statistics}/character-statistic/character-statistic.component.html (89%) rename src/app/components/characters/{ => character-statistics}/character-statistic/character-statistic.component.ts (95%) create mode 100644 src/app/components/characters/character-statistics/character-statistics.component.css create mode 100644 src/app/components/characters/character-statistics/character-statistics.component.html create mode 100644 src/app/components/characters/character-statistics/character-statistics.component.ts create mode 100644 src/app/components/characters/character-statistics/character-value-statistics/character-value-statistics.component.css create mode 100644 src/app/components/characters/character-statistics/character-value-statistics/character-value-statistics.component.html create mode 100644 src/app/components/characters/character-statistics/character-value-statistics/character-value-statistics.component.ts delete mode 100644 src/app/components/inputs/submit-button/submit-button.component.ts diff --git a/src/app/components/inputs/submit-button/submit-button.component.css b/src/app/components/buttons/button/button.component.css similarity index 100% rename from src/app/components/inputs/submit-button/submit-button.component.css rename to src/app/components/buttons/button/button.component.css diff --git a/src/app/components/inputs/submit-button/submit-button.component.html b/src/app/components/buttons/button/button.component.html similarity index 80% rename from src/app/components/inputs/submit-button/submit-button.component.html rename to src/app/components/buttons/button/button.component.html index 6dcb578..833ff58 100644 --- a/src/app/components/inputs/submit-button/submit-button.component.html +++ b/src/app/components/buttons/button/button.component.html @@ -1,14 +1,15 @@ diff --git a/src/app/components/buttons/button/button.component.ts b/src/app/components/buttons/button/button.component.ts new file mode 100644 index 0000000..7193e04 --- /dev/null +++ b/src/app/components/buttons/button/button.component.ts @@ -0,0 +1,17 @@ +import { ChangeDetectionStrategy, Component, EventEmitter, input, Output } from '@angular/core'; +import { NgClass } from '@angular/common'; + +@Component({ + selector: 'pap-button', + standalone: true, + imports: [NgClass], + templateUrl: './button.component.html', + styleUrl: './button.component.css', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class ButtonComponent { + disabled = input(false); + danger = input(false); + type = input<'button' | 'submit'>('button'); + @Output() tap = new EventEmitter(); +} diff --git a/src/app/components/characters/character-dashboard/character-dashboard.component.html b/src/app/components/characters/character-dashboard/character-dashboard.component.html index 439a393..c207311 100644 --- a/src/app/components/characters/character-dashboard/character-dashboard.component.html +++ b/src/app/components/characters/character-dashboard/character-dashboard.component.html @@ -4,49 +4,12 @@
-
-
- - - - - - - - -
- -
- -
-
- - - - - -
-
- - - - - -
-
- - - -
-
-
-
-
+ diff --git a/src/app/components/characters/character-dashboard/character-dashboard.component.ts b/src/app/components/characters/character-dashboard/character-dashboard.component.ts index ae1415d..158ef16 100644 --- a/src/app/components/characters/character-dashboard/character-dashboard.component.ts +++ b/src/app/components/characters/character-dashboard/character-dashboard.component.ts @@ -4,16 +4,26 @@ import { CharactersStore } from '../../../stores/characters.store'; import { filter, map } from 'rxjs'; import { toSignal } from '@angular/core/rxjs-interop'; import { H1Component } from '../../headings/h1/h1.component'; -import { CharacterStatisticComponent } from '../character-statistic/character-statistic.component'; +import { CharacterStatisticComponent } from '../character-statistics/character-statistic/character-statistic.component'; import { ContentGroupComponent } from '../../content-group/content-group.component'; import { EditModeStore } from '../../../stores/edit-mode.store'; import { SecondaryH1Component } from '../../headings/secondary-h1/secondary-h1.component'; import { NonNullableFormBuilder, ReactiveFormsModule } from '@angular/forms'; +import { CharacterMainStatisticsComponent } from '../character-statistics/character-main-statistics/character-main-statistics.component'; +import { CharacterStatisticsComponent } from '../character-statistics/character-statistics.component'; @Component({ selector: 'pap-character-dashboard', standalone: true, - imports: [H1Component, CharacterStatisticComponent, ContentGroupComponent, SecondaryH1Component, ReactiveFormsModule], + imports: [ + H1Component, + CharacterStatisticComponent, + ContentGroupComponent, + SecondaryH1Component, + ReactiveFormsModule, + CharacterMainStatisticsComponent, + CharacterStatisticsComponent, + ], templateUrl: './character-dashboard.component.html', styleUrl: './character-dashboard.component.css', changeDetection: ChangeDetectionStrategy.OnPush, @@ -48,7 +58,7 @@ export default class CharacterDashboardComponent { life: [0], power: [0], energy: [0], - strike: [0], + precision: [0], perception: [0], magicDefense: [0], magicTolerance: [0], @@ -87,8 +97,6 @@ export default class CharacterDashboardComponent { // We might want to save the changes const statistics = this.formGroup.getRawValue(); - console.log('effect'); - void this.characterStore.updateStatistics({ ...character, main: statistics.main, value: statistics.value }); }); } diff --git a/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.css b/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.html b/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.html new file mode 100644 index 0000000..3f3a30c --- /dev/null +++ b/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.ts b/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.ts new file mode 100644 index 0000000..c38c09c --- /dev/null +++ b/src/app/components/characters/character-statistics/character-main-statistics/character-main-statistics.component.ts @@ -0,0 +1,19 @@ +import { ChangeDetectionStrategy, Component, input } from '@angular/core'; +import { CharacterStatisticComponent } from '../character-statistic/character-statistic.component'; +import { ContentGroupComponent } from '../../../content-group/content-group.component'; +import { FormGroup, ReactiveFormsModule } from '@angular/forms'; + +@Component({ + selector: 'pap-character-main-statistics', + standalone: true, + imports: [CharacterStatisticComponent, ContentGroupComponent, ReactiveFormsModule], + templateUrl: './character-main-statistics.component.html', + styleUrl: './character-main-statistics.component.css', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class CharacterMainStatisticsComponent { + formGroup = input.required(); + footer = input(''); + remainingPoints = input(0); + allowEdit = input(false); +} diff --git a/src/app/components/characters/character-statistic/character-statistic.component.css b/src/app/components/characters/character-statistics/character-statistic/character-statistic.component.css similarity index 100% rename from src/app/components/characters/character-statistic/character-statistic.component.css rename to src/app/components/characters/character-statistics/character-statistic/character-statistic.component.css diff --git a/src/app/components/characters/character-statistic/character-statistic.component.html b/src/app/components/characters/character-statistics/character-statistic/character-statistic.component.html similarity index 89% rename from src/app/components/characters/character-statistic/character-statistic.component.html rename to src/app/components/characters/character-statistics/character-statistic/character-statistic.component.html index 6f65bf7..ed0b083 100644 --- a/src/app/components/characters/character-statistic/character-statistic.component.html +++ b/src/app/components/characters/character-statistics/character-statistic/character-statistic.component.html @@ -2,12 +2,20 @@

{{ label() }}

@if (!allowEdit()) { -

{{ value() }}

+ @if (displayValue(); as displayValue) { +

{{ displayValue }}

+ } @else { +

{{ value() }}

+ } } @if (allowEdit()) {
-

{{ value() }}

+ @if (displayValue(); as displayValue) { +

{{ displayValue }} ({{ value() }})

+ } @else { +

{{ value() }}

+ }
@if (showTens()) {
- Importieren + Importieren
@@ -26,7 +26,7 @@

Lege Dir zuvor ein Backup an, damit Du im Notfall dieses Wiederherstellen kannst.

- Zurücksetzen + Zurücksetzen
diff --git a/src/app/components/settings/backup-restore/backup-restore.component.ts b/src/app/components/settings/backup-restore/backup-restore.component.ts index 4574fd5..102b2c2 100644 --- a/src/app/components/settings/backup-restore/backup-restore.component.ts +++ b/src/app/components/settings/backup-restore/backup-restore.component.ts @@ -1,6 +1,6 @@ import { ChangeDetectionStrategy, Component, ElementRef, inject, ViewChild } from '@angular/core'; import { H1Component } from '../../headings/h1/h1.component'; -import { SubmitButtonComponent } from '../../inputs/submit-button/submit-button.component'; +import { ButtonComponent } from '../../buttons/button/button.component'; import { DatabaseService } from '../../../services/database.service'; import { TauriService } from '../../../services/tauri.service'; import { DateTime } from 'luxon'; @@ -12,7 +12,7 @@ import { FileDirective } from '../../../directives/file.directive'; @Component({ selector: 'pap-backup-restore', standalone: true, - imports: [H1Component, SubmitButtonComponent, H2Component, H3Component, FormsModule, ReactiveFormsModule, FileDirective], + imports: [H1Component, ButtonComponent, H2Component, H3Component, FormsModule, ReactiveFormsModule, FileDirective], templateUrl: './backup-restore.component.html', styleUrl: './backup-restore.component.css', changeDetection: ChangeDetectionStrategy.OnPush, diff --git a/src/app/components/tools/dice/dice.component.html b/src/app/components/tools/dice/dice.component.html index 11fe2b7..0639459 100644 --- a/src/app/components/tools/dice/dice.component.html +++ b/src/app/components/tools/dice/dice.component.html @@ -12,7 +12,7 @@ required type="text" /> - Würfeln! + Würfeln!
Ergebnis: {{ result }}
diff --git a/src/app/components/tools/dice/dice.component.ts b/src/app/components/tools/dice/dice.component.ts index c4d76f8..cba0d87 100644 --- a/src/app/components/tools/dice/dice.component.ts +++ b/src/app/components/tools/dice/dice.component.ts @@ -1,13 +1,13 @@ import { AfterViewInit, Component } from '@angular/core'; import DiceBox from '@3d-dice/dice-box'; import { FormsModule } from '@angular/forms'; -import { SubmitButtonComponent } from '../../inputs/submit-button/submit-button.component'; +import { ButtonComponent } from '../../buttons/button/button.component'; import { H1Component } from '../../headings/h1/h1.component'; @Component({ selector: 'pap-dice', standalone: true, - imports: [FormsModule, SubmitButtonComponent, H1Component], + imports: [FormsModule, ButtonComponent, H1Component], templateUrl: './dice.component.html', styleUrl: './dice.component.css', }) diff --git a/src/app/models/character/value-statistics.ts b/src/app/models/character/value-statistics.ts index d2233fd..9ba54d9 100644 --- a/src/app/models/character/value-statistics.ts +++ b/src/app/models/character/value-statistics.ts @@ -32,7 +32,7 @@ export interface ValueStatistics { /** * Treffen. */ - strike: number; + precision: number; /** * Wahrnehmung. diff --git a/src/app/services/characters.service.ts b/src/app/services/characters.service.ts index d6549f4..3d271c2 100644 --- a/src/app/services/characters.service.ts +++ b/src/app/services/characters.service.ts @@ -4,6 +4,7 @@ import { MainStatistics } from '../models/character/main-statistics'; import { CharactersTable } from './tables/characters.table'; import { TransactionsService } from './transactions.service'; import { Statistics } from '../models/character/statistics'; +import { ValueStatistics } from '../models/character/value-statistics'; @Injectable({ providedIn: 'root', @@ -22,6 +23,24 @@ export class CharactersService { return statistics.agility + statistics.magic + statistics.spirit + statistics.intelligence + statistics.stamina + statistics.strength; } + sumValueStatistics(value: ValueStatistics): number { + return ( + value.reaction + + value.mana + + value.manaRegeneration + + value.life + + value.energy + + value.magicControl + + value.magicTolerance + + value.magicDefense + + value.perception + + value.precision + + value.power + + value.cover + + value.authority + ); + } + async add(character: Omit): Promise { const characterEntity = await this.charactersTable.add({ ...character, @@ -32,7 +51,7 @@ export class CharactersService { magicDefense: 0, magicTolerance: 0, magicControl: 0, - strike: 0, + precision: 0, perception: 0, mana: 0, manaRegeneration: 0, @@ -68,7 +87,7 @@ export class CharactersService { magicDefense: b.value.magicDefense - a.value.magicDefense, magicTolerance: b.value.magicTolerance - a.value.magicTolerance, magicControl: b.value.magicControl - a.value.magicControl, - strike: b.value.strike - a.value.strike, + precision: b.value.precision - a.value.precision, perception: b.value.perception - a.value.perception, mana: b.value.mana - a.value.mana, manaRegeneration: b.value.manaRegeneration - a.value.manaRegeneration, @@ -86,4 +105,22 @@ export class CharactersService { return !mainStatsZero || !valueStatsZero; } + + calculateValueStatistics({ main, value }: Statistics): ValueStatistics { + return { + life: value.life + main.strength + 1.5 * main.stamina, + mana: value.mana + main.spirit + 1.5 * main.intelligence + 0.5 * main.magic, + power: value.power + main.strength + 0.5 * main.agility, + precision: value.precision + 0.5 * main.strength + main.agility, + reaction: value.reaction + 0.5 * main.strength + main.agility + main.intelligence, + energy: value.energy + main.strength + 0.5 * main.stamina, + perception: value.perception + main.intelligence + 0.5 * main.spirit, + cover: value.cover + 1.5 * main.agility, + magicDefense: value.magicDefense + main.stamina + main.magic + 0.5 * main.spirit, + magicControl: value.magicControl + main.magic + main.spirit + 0.5 * main.intelligence, + magicTolerance: value.magicTolerance + 0.5 * main.magic + main.spirit, + manaRegeneration: value.manaRegeneration + 0.5 * main.magic + main.spirit, + authority: value.authority, + }; + } } diff --git a/src/app/validators/required-points-to-distribute-validator.ts b/src/app/validators/required-points-to-distribute-validator.ts index 29366a6..99af044 100644 --- a/src/app/validators/required-points-to-distribute-validator.ts +++ b/src/app/validators/required-points-to-distribute-validator.ts @@ -1,10 +1,13 @@ import { CharactersService } from '../services/characters.service'; import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'; import { MainStatistics } from '../models/character/main-statistics'; +import { ValueStatistics } from '../models/character/value-statistics'; export function requiredPointsToDistributeValidator(charactersService: CharactersService, requiredPointsToDistribute: number): ValidatorFn { - return (control: AbstractControl): ValidationErrors | null => { - const sum = charactersService.sumMainStatistics(control.value); + return (control: AbstractControl<{ main: MainStatistics; value: ValueStatistics }>): ValidationErrors | null => { + const mainSum = charactersService.sumMainStatistics(control.value.main); + const valueSum = charactersService.sumValueStatistics(control.value.value); + const sum = mainSum + valueSum / 3; // / 3 due to conversion if (sum !== requiredPointsToDistribute) { return { invalidDistributedPoints: true }; }