favorite-spells-modal.component.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { Component, Input } from '@angular/core';
  2. import { CommonModule } from '@angular/common';
  3. import { Spell } from 'src/interfaces/spell';
  4. import { ModalService } from 'src/services/modal/modal.service';
  5. @Component({
  6. selector: 'app-favorite-spells-modal',
  7. templateUrl: './favorite-spells-modal.component.html',
  8. styleUrl: './favorite-spells-modal.component.scss',
  9. })
  10. export class FavoriteSpellsModalComponent {
  11. @Input() public preparedSpells: Spell[] = [];
  12. @Input() public selectedSpells: Spell[] = [];
  13. @Input() public spellAttackBonus: string = '0';
  14. @Input() public spellSaveDC: number = 0;
  15. checkedSpells: boolean[] = [];
  16. public attributes: any = {
  17. strength: 'STR',
  18. dexterity: 'DEX',
  19. constitution: 'CON',
  20. intelligence: 'INT',
  21. wisdom: 'WIS',
  22. charisma: 'CHA',
  23. };
  24. public areas: any = {
  25. cone: 'Kegel',
  26. sphere: 'Kugel',
  27. circle: 'Kreis',
  28. line: 'Linie',
  29. square: 'Quadrat',
  30. cube: 'Würfel',
  31. };
  32. public constructor(private modalAccessor: ModalService) {}
  33. public ngOnInit(): void {
  34. this.checkedSpells = Array(this.preparedSpells.length).fill(false);
  35. this.preparedSpells.forEach((spell, index) => {
  36. this.checkedSpells[index] = this.selectedSpells.some(
  37. (selectedSpell) => selectedSpell.id === spell.id
  38. );
  39. });
  40. }
  41. public update(): void {
  42. const spells: Spell[] = this.preparedSpells.filter(
  43. (spell, index) => this.checkedSpells[index]
  44. );
  45. this.modalAccessor.handleModalClosing('update', spells);
  46. this.checkedSpells = [];
  47. }
  48. public cancel(): void {
  49. this.modalAccessor.handleModalClosing('cancel', undefined);
  50. this.checkedSpells = [];
  51. }
  52. }