spell-modal.component.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import { Component, Input } from '@angular/core';
  2. import { ModalService } from 'src/services/modal/modal.service';
  3. import { TranslatorService } from 'src/services/translator/translator.service';
  4. import { Damage } from 'src/interfaces/damage';
  5. import { Heal } from 'src/interfaces/heal';
  6. import { Spell } from 'src/interfaces/spell';
  7. import { Editor } from 'ngx-editor';
  8. @Component({
  9. selector: 'spell-modal',
  10. templateUrl: './spell-modal.component.html',
  11. styleUrls: ['./spell-modal.component.scss'],
  12. })
  13. export class SpellModalComponent {
  14. @Input() public spell: any;
  15. @Input() public level: number = 0;
  16. @Input() classes: string[] = [];
  17. @Input() public id: number = 0;
  18. @Input() public isModification: boolean = false;
  19. @Input() public isBasedOnOfficialSpell: boolean = false;
  20. // #region Properties
  21. public name: string = '';
  22. public german: string = '';
  23. public english: string = '';
  24. public image: string = '';
  25. public cost: string = 'action';
  26. public duration: number = 0;
  27. public durationtype: 'rounds' | 'minutes' | 'hours' | 'days' = 'rounds';
  28. public timeToCast: number = 0;
  29. public canRitual: boolean = false;
  30. public isRitual: boolean = false;
  31. public needsConcentration: boolean = false;
  32. public needsVerbal: boolean = false;
  33. public needsSomatic: boolean = false;
  34. public needsMaterial: boolean = false;
  35. public school: string = 'evocation';
  36. public description_de: string = '';
  37. public description_en: string = '';
  38. public doesDamage: boolean = false;
  39. public doesHeal: boolean = false;
  40. public needsAttackRoll: boolean = false;
  41. public needsSavingThrow: boolean = false;
  42. public savingThrowAttribute: string = '';
  43. public heal: Heal = {
  44. diceNumber: 0,
  45. diceType: 0,
  46. additionalHeal: 0,
  47. };
  48. public attackBonus: string = '';
  49. public damage: Damage[] = [{ diceNumber: 0, diceType: 0, damageType: '' }];
  50. public isRanged: boolean = false;
  51. public range: number = 5;
  52. public hasAreaOfEffect: boolean = false;
  53. public diameter: number = 5;
  54. public areaOfEffectType: string = 'circle';
  55. active = 'description';
  56. editor: Editor = new Editor();
  57. html = '';
  58. toolbar: any = [
  59. // default value
  60. ['bold', 'italic'],
  61. ['bullet_list'],
  62. [{ heading: ['h3', 'h4', 'h5', 'h6'] }],
  63. ];
  64. // #endregion
  65. public costs: string[] = ['action', 'bonus', 'reaction'];
  66. // #endregion
  67. public constructor(
  68. private modalAccessor: ModalService,
  69. public translator: TranslatorService,
  70. ) {}
  71. public ngOnInit(): void {
  72. if (this.isModification || this.isBasedOnOfficialSpell) {
  73. this.loadspell();
  74. }
  75. }
  76. // #region RESPONSES
  77. public cancel(): void {
  78. this.modalAccessor.handleModalClosing('cancel', undefined);
  79. this.resetSpell();
  80. }
  81. public add(): void {
  82. this.modalAccessor.handleModalClosing('add', this.createSpell());
  83. this.resetSpell();
  84. }
  85. public update(): void {
  86. this.modalAccessor.handleModalClosing('update', this.createSpell());
  87. this.resetSpell();
  88. }
  89. // #endregion
  90. // #region FUNCTIONS
  91. private loadspell(): void {
  92. if (this.isModification) {
  93. this.id = this.spell.id;
  94. this.german = this.spell.german;
  95. this.english = this.spell.english;
  96. // TODO: Implement internationalization
  97. this.name = this.spell.german;
  98. this.classes = this.spell.classes;
  99. } else {
  100. this.german = this.spell.german + ' (Kopie)';
  101. this.english = this.spell.english + ' (copy)';
  102. this.name = this.spell.german + ' (Kopie)';
  103. }
  104. this.image = this.spell.image;
  105. this.classes = this.spell.classes;
  106. this.level = this.spell.level;
  107. this.cost = this.spell.cost;
  108. this.canRitual = this.spell.canRitual;
  109. this.isRitual = this.spell.isRitual;
  110. this.duration = this.spell.duration;
  111. this.durationtype = this.spell.durationType;
  112. this.timeToCast = this.spell.timeToCast;
  113. this.needsConcentration = this.spell.needsConcentration;
  114. this.needsVerbal = this.spell.needsVerbal;
  115. this.needsSomatic = this.spell.needsSomatic;
  116. this.needsMaterial = this.spell.needsMaterial;
  117. this.school = this.spell.school;
  118. this.description_de = this.spell.description_de;
  119. this.description_en = this.spell.description_en;
  120. this.doesDamage = this.spell.doesDamage;
  121. this.needsSavingThrow = this.spell.needsSavingThrow;
  122. this.savingThrowAttribute = this.spell.savingThrowAttribute;
  123. this.damage = this.spell.damage;
  124. this.isRanged = this.spell.isRanged;
  125. this.range = this.spell.range;
  126. this.hasAreaOfEffect = this.spell.hasAreaOfEffect;
  127. this.diameter = this.spell.diameter;
  128. this.areaOfEffectType = this.spell.areaOfEffectType;
  129. this.needsAttackRoll = this.spell.needsAttackRoll;
  130. this.attackBonus = this.spell.attackBonus;
  131. this.doesHeal = this.spell.doesHeal;
  132. this.heal = this.spell.heal;
  133. }
  134. private createSpell(): Spell {
  135. const spell: Spell = {
  136. id: this.id,
  137. isCustom: true,
  138. english: this.name,
  139. german: this.name,
  140. image: this.image,
  141. classes: this.classes,
  142. duration: this.duration,
  143. durationType: this.durationtype,
  144. timeToCast: 0, // FIXME: only mocked
  145. damage: this.damage,
  146. heal: this.heal,
  147. level: parseInt(this.level.toString()),
  148. cost: this.cost,
  149. canRitual: this.canRitual,
  150. isRitual: this.isRitual,
  151. school: this.school,
  152. description_de: this.description_de,
  153. description_en: this.description_de,
  154. needsConcentration: this.needsConcentration,
  155. needsVerbal: this.needsVerbal,
  156. needsSomatic: this.needsSomatic,
  157. needsMaterial: this.needsMaterial,
  158. needsAttackRoll: this.needsSavingThrow ? false : this.needsAttackRoll,
  159. needsSavingThrow: this.needsSavingThrow,
  160. savingThrowAttribute: this.savingThrowAttribute,
  161. isRanged: this.isRanged,
  162. range: this.range,
  163. diameter: this.diameter,
  164. hasAreaOfEffect: this.hasAreaOfEffect,
  165. areaOfEffectType: this.areaOfEffectType,
  166. doesDamage: this.doesDamage,
  167. doesHeal: this.doesHeal,
  168. };
  169. return spell;
  170. }
  171. private resetSpell(): void {
  172. this.id = 0;
  173. this.german = '';
  174. this.english = '';
  175. this.name = '';
  176. this.image = '';
  177. this.classes = [];
  178. this.level = 0;
  179. this.cost = 'action';
  180. this.canRitual = false;
  181. this.isRitual = false;
  182. this.duration = 0;
  183. this.durationtype = 'rounds';
  184. this.timeToCast = 0;
  185. this.needsConcentration = false;
  186. this.needsVerbal = false;
  187. this.needsSomatic = false;
  188. this.needsMaterial = false;
  189. this.school = 'evocation';
  190. this.description_de = '';
  191. this.description_en = '';
  192. this.doesDamage = true;
  193. this.needsSavingThrow = false;
  194. this.savingThrowAttribute = '';
  195. this.damage = [{ diceNumber: 0, diceType: 0, damageType: '' }];
  196. this.isRanged = false;
  197. this.range = 5;
  198. this.hasAreaOfEffect = false;
  199. this.diameter = 5;
  200. this.areaOfEffectType = 'circle';
  201. this.needsAttackRoll = false;
  202. this.attackBonus = '';
  203. this.doesHeal = false;
  204. this.heal = { diceNumber: 0, diceType: 0, additionalHeal: 0 };
  205. }
  206. public addDamage(): void {
  207. this.damage.push({ diceNumber: 0, diceType: 0, damageType: '' });
  208. }
  209. public removeDamage(index: number): void {
  210. this.damage.splice(index, 1);
  211. }
  212. public setRitual(event: any): void {
  213. if (event.target.checked) {
  214. this.canRitual = true;
  215. }
  216. }
  217. public unsetRitual(event: any): void {
  218. if (!event.target.checked) {
  219. this.isRitual = false;
  220. }
  221. }
  222. // #endregion
  223. }