weapons-container.component.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import { Component, ViewChild } from '@angular/core';
  2. import { DataService } from 'src/services/data/data.service';
  3. import { Weapon } from 'src/interfaces/weapon';
  4. import { Spell } from 'src/interfaces/spell';
  5. import { Damage } from 'src/interfaces/damage';
  6. import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
  7. import { NgxSmartModalService, NgxSmartModalComponent } from 'ngx-smart-modal';
  8. @Component({
  9. selector: 'app-weapons-container',
  10. templateUrl: './weapons-container.component.html',
  11. styleUrls: ['./weapons-container.component.scss'],
  12. })
  13. export class WeaponsContainerComponent {
  14. public constructor(
  15. public dataAccessor: DataService,
  16. public ngxSmartModalService: NgxSmartModalService
  17. ) {}
  18. public active: number = 1;
  19. public newWeaponName: string = '';
  20. public newWeaponDamageType: string = '';
  21. public newWeaponRange: string = '';
  22. public newWeaponAttackBonus: string = '';
  23. public newWeaponDamage: Damage[] = [{ damage: '', damageType: '' }];
  24. public newWeaponProficient: boolean = false;
  25. public newWeaponAttribute: string = '';
  26. public newWeaponIsVersatile: boolean = false;
  27. public newWeaponIsTwoHanded: boolean = false;
  28. public newWeaponIsFinesse: boolean = false;
  29. public newWeaponIsRanged: boolean = false;
  30. public newWeaponVersatileDamage: Damage[] = [{ damage: '', damageType: '' }];
  31. // public weaponAttributes: string[] = [
  32. // 'Strength',
  33. // 'Dexterity',
  34. // 'Constitution',
  35. // 'Intelligence',
  36. // 'Wisdom',
  37. // 'Charisma',
  38. // ];
  39. public damageTypes: string[] = [
  40. 'Wucht',
  41. 'Stich',
  42. 'Hieb',
  43. 'Feuer',
  44. 'Kälte',
  45. 'Blitz',
  46. 'Gift',
  47. 'Säure',
  48. 'Nekrotisch',
  49. 'Psychisch',
  50. 'Heilig',
  51. 'Göttlich',
  52. 'Kraft',
  53. ];
  54. public weapons: Weapon[] = [
  55. {
  56. name: 'Dagger',
  57. damage: [{ damage: '1d4', damageType: 'Stich' }],
  58. attackBonus: '+5',
  59. range: '20/60',
  60. isFinesse: true,
  61. proficient: true,
  62. isTwoHanded: false,
  63. isVersatile: false,
  64. isRanged: false,
  65. },
  66. ];
  67. public newSpellName: string = '';
  68. public newSpellAttackBonus: string = '';
  69. public newSpellDamage: string = '';
  70. public newSpellType: string = '';
  71. public newSpellRange: string = '';
  72. public newSpellProficient: boolean = false;
  73. public newSpellAttribute: string = '';
  74. public spells: Spell[] = [
  75. {
  76. name: 'Fireball',
  77. damage: '8d6',
  78. attackBonus: '0',
  79. range: '150',
  80. type: 'Fire',
  81. attribute: 'Dexterity',
  82. level: 3,
  83. },
  84. ];
  85. public ngOnInit(): void {
  86. this.weapons = this.dataAccessor.getWeapons();
  87. this.spells = this.dataAccessor.getSpells();
  88. }
  89. public dropWeapons(event: CdkDragDrop<string[]>): void {
  90. moveItemInArray(this.weapons, event.previousIndex, event.currentIndex);
  91. this.updateWeapons();
  92. }
  93. public dropSpells(event: CdkDragDrop<string[]>): void {
  94. moveItemInArray(this.spells, event.previousIndex, event.currentIndex);
  95. this.updateSpells();
  96. }
  97. public updateWeapons(): void {
  98. this.dataAccessor.setWeapons(this.weapons);
  99. }
  100. public updateSpells(): void {
  101. this.dataAccessor.setSpells(this.spells);
  102. }
  103. public openWeaponModal(): void {
  104. this.ngxSmartModalService.getModal('weaponModal').open();
  105. }
  106. public addWeapon(): void {
  107. const newWeapon: Weapon = {
  108. name: this.newWeaponName,
  109. damage: this.newWeaponDamage,
  110. attackBonus: this.newWeaponAttackBonus,
  111. range: this.newWeaponRange,
  112. proficient: this.newWeaponProficient,
  113. isTwoHanded: this.newWeaponIsTwoHanded,
  114. isVersatile: this.newWeaponIsVersatile,
  115. isFinesse: this.newWeaponIsFinesse,
  116. isRanged: this.newWeaponIsRanged,
  117. versatileDamage: this.newWeaponIsVersatile
  118. ? this.newWeaponVersatileDamage
  119. : undefined,
  120. };
  121. console.log('test if versatileDamage is present?', newWeapon);
  122. this.weapons.push(newWeapon);
  123. this.ngxSmartModalService.getModal('weaponModal').close();
  124. }
  125. public openSpellModal(): void {
  126. this.ngxSmartModalService.getModal('spellModal').open();
  127. }
  128. public addSpell(): void {
  129. this.spells.push({
  130. name: this.newSpellName,
  131. damage: this.newSpellDamage,
  132. attackBonus: this.newSpellAttackBonus,
  133. range: this.newSpellRange,
  134. type: this.newSpellType,
  135. level: 0,
  136. attribute: this.newSpellAttribute,
  137. });
  138. this.ngxSmartModalService.getModal('spellModal').close();
  139. }
  140. }