favorite-spells-modal.component.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Component, Input } from '@angular/core';
  2. import { Spell } from 'src/interfaces/spell';
  3. import { ModalService } from 'src/services/modal/modal.service';
  4. import { TranslateService } from '@ngx-translate/core';
  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 constructor(
  17. private modalAccessor: ModalService,
  18. public translate: TranslateService,
  19. ) {}
  20. public ngOnInit(): void {
  21. this.checkedSpells = Array(this.preparedSpells.length).fill(false);
  22. this.preparedSpells.forEach((spell, index) => {
  23. this.checkedSpells[index] = this.selectedSpells.some(
  24. (selectedSpell) => selectedSpell.id === spell.id,
  25. );
  26. });
  27. }
  28. public update(): void {
  29. const spells: Spell[] = this.preparedSpells.filter(
  30. (spell, index) => this.checkedSpells[index],
  31. );
  32. this.modalAccessor.handleModalClosing('update', spells);
  33. this.checkedSpells = [];
  34. }
  35. public cancel(): void {
  36. this.modalAccessor.handleModalClosing('cancel', undefined);
  37. this.checkedSpells = [];
  38. }
  39. }