weapon-modal.component.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. import { Component, Input } from '@angular/core';
  2. import { Weapon } from 'src/interfaces/weapon';
  3. import { Damage } from 'src/interfaces/damage';
  4. import { ModalService } from 'src/services/modal/modal.service';
  5. import { Editor } from 'ngx-editor';
  6. @Component({
  7. selector: 'app-weapon-modal',
  8. templateUrl: './weapon-modal.component.html',
  9. styleUrl: './weapon-modal.component.scss',
  10. })
  11. export class WeaponModalComponent {
  12. public constructor(private modalAccessor: ModalService) {}
  13. @Input() public item: any;
  14. @Input() public isUpdate: boolean = false;
  15. public name: string = '';
  16. public range: number[] = [5, 5];
  17. public hasReach: boolean = false;
  18. public throwRange: number[] = [5, 5];
  19. public attackBonus: string = '+0';
  20. public damage: Damage[] = [{ diceNumber: '', diceType: '', damageType: '' }];
  21. public hasAdditionalDamage: boolean = false;
  22. public additionalDamage: number = 0;
  23. public useAttributeModifier: boolean = false;
  24. public proficient: boolean = false;
  25. public isVersatile: boolean = false;
  26. public isTwoHanded: boolean = false;
  27. public isFinesse: boolean = false;
  28. public isRanged: boolean = false;
  29. public versatileDamage: string = '';
  30. public canBeThrown: boolean = false;
  31. public weight: string = 'normal';
  32. public isMagical: boolean = false;
  33. public magicBonus: number = 0;
  34. public description: string = '';
  35. active = 'damage';
  36. editor: Editor = new Editor();
  37. html = '';
  38. toolbar: any = [
  39. // default value
  40. ['bold', 'italic'],
  41. ['bullet_list'],
  42. [{ heading: ['h3', 'h4', 'h5', 'h6'] }],
  43. ];
  44. // Options for the select boxes
  45. public weights: string[] = ['leicht', 'normal', 'schwer'];
  46. public damageTypes: string[] = [
  47. 'bludgeoning',
  48. 'piercing',
  49. 'slashing',
  50. 'acid',
  51. 'cold',
  52. 'fire',
  53. 'force',
  54. 'lightning',
  55. 'necrotic',
  56. 'poison',
  57. 'psychic',
  58. 'radiant',
  59. 'thunder',
  60. ];
  61. public dice: string[] = ['W4', 'W6', 'W8', 'W10', 'W12', 'W20', 'W100'];
  62. public numbers: string[] = [
  63. '1',
  64. '2',
  65. '3',
  66. '4',
  67. '5',
  68. '6',
  69. '7',
  70. '8',
  71. '9',
  72. '10',
  73. ];
  74. public attackBonuses: string[] = [
  75. '-2',
  76. '-1',
  77. '+0',
  78. '+1',
  79. '+2',
  80. '+3',
  81. '+4',
  82. '+5',
  83. '+6',
  84. '+7',
  85. '+8',
  86. '+9',
  87. '+10',
  88. '+11',
  89. '+12',
  90. '+13',
  91. '+14',
  92. '+15',
  93. '+16',
  94. '+17',
  95. '+18',
  96. '+19',
  97. '+20',
  98. ];
  99. additonalDamages: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
  100. public magicBonuses: any[] = [
  101. { display: '+1', value: 1 },
  102. { display: '+2', value: 2 },
  103. { display: '+3', value: 3 },
  104. { display: '+4', value: 4 },
  105. { display: '+5', value: 5 },
  106. ];
  107. public ngOnInit(): void {
  108. if (this.isUpdate) {
  109. this.loadItem();
  110. }
  111. }
  112. public loadItem(): void {
  113. this.name = this.item.name;
  114. this.range = this.item.range;
  115. this.hasReach = this.item.hasReach;
  116. this.throwRange = this.item.throwRange;
  117. this.attackBonus = this.item.attackBonus;
  118. this.damage = this.item.damage;
  119. this.hasAdditionalDamage = this.item.hasAdditionalDamage;
  120. this.additionalDamage = this.item.additionalDamage;
  121. this.useAttributeModifier = this.item.useAttributeModifier;
  122. this.proficient = this.item.proficient;
  123. this.isVersatile = this.item.isVersatile;
  124. this.isTwoHanded = this.item.isTwoHanded;
  125. this.isFinesse = this.item.isFinesse;
  126. this.isRanged = this.item.isRanged;
  127. this.versatileDamage = this.item.versatileDamage;
  128. this.canBeThrown = this.item.canBeThrown;
  129. this.weight = this.item.weight;
  130. this.isMagical = this.item.isMagical;
  131. this.magicBonus = this.item.magicBonus;
  132. this.description = this.item.description;
  133. }
  134. // RESPONSES
  135. public cancel(): void {
  136. this.modalAccessor.handleModalClosing('cancel', undefined);
  137. this.resetItem();
  138. }
  139. public add(): void {
  140. console.log(this.createItem());
  141. this.modalAccessor.handleModalClosing('add', this.createItem());
  142. this.resetItem();
  143. }
  144. public update(): void {
  145. this.modalAccessor.handleModalClosing('update', this.createItem());
  146. this.resetItem();
  147. }
  148. public createItem(): Weapon {
  149. return {
  150. name: this.name,
  151. range: this.range,
  152. hasReach: this.hasReach,
  153. throwRange: this.throwRange,
  154. attackBonus: this.attackBonus,
  155. damage: this.damage,
  156. hasAdditionalDamage: this.hasAdditionalDamage,
  157. additionalDamage: this.additionalDamage,
  158. useAttributeModifier: this.useAttributeModifier,
  159. proficient: this.proficient,
  160. isVersatile: this.isVersatile,
  161. isTwoHanded: this.isTwoHanded,
  162. isFinesse: this.isFinesse,
  163. isRanged: this.isRanged,
  164. versatileDamage: this.versatileDamage,
  165. canBeThrown: this.canBeThrown,
  166. weight: this.weight,
  167. isMagical: this.isMagical,
  168. magicBonus: this.magicBonus,
  169. description: this.description,
  170. };
  171. }
  172. /**
  173. * Resets all values to their default values.
  174. */
  175. public resetItem(): void {
  176. this.name = '';
  177. this.range = [5, 5];
  178. this.hasReach = false;
  179. this.throwRange = [5, 5];
  180. this.attackBonus = '+0';
  181. this.damage = [{ diceNumber: '', diceType: '', damageType: '' }];
  182. this.hasAdditionalDamage = false;
  183. this.additionalDamage = 0;
  184. this.useAttributeModifier = false;
  185. this.proficient = false;
  186. this.isVersatile = false;
  187. this.isTwoHanded = false;
  188. this.isFinesse = false;
  189. this.isRanged = false;
  190. this.versatileDamage = '';
  191. this.canBeThrown = false;
  192. this.weight = 'normal';
  193. this.isMagical = false;
  194. this.magicBonus = 0;
  195. this.description = '';
  196. }
  197. // COMPONENT LOGIC
  198. public addDamage(): void {
  199. this.damage.push({ diceNumber: '', diceType: '', damageType: '' });
  200. }
  201. public removeDamage(index: number): void {
  202. this.damage.splice(index, 1);
  203. }
  204. }