| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- import { Component, Input } from '@angular/core';
- import { ModalService } from 'src/services/modal/modal.service';
- import { TranslatorService } from 'src/services/translator/translator.service';
- import { Damage } from 'src/interfaces/damage';
- import { Heal } from 'src/interfaces/heal';
- import { Spell } from 'src/interfaces/spell';
- import { Editor } from 'ngx-editor';
- @Component({
- selector: 'spell-modal',
- templateUrl: './spell-modal.component.html',
- styleUrls: ['./spell-modal.component.scss'],
- })
- export class SpellModalComponent {
- @Input() public spell: any;
- @Input() public level: number = 0;
- @Input() classes: string[] = [];
- @Input() public id: number = 0;
- @Input() public isModification: boolean = false;
- @Input() public isBasedOnOfficialSpell: boolean = false;
- // #region Properties
- public name: string = '';
- public german: string = '';
- public english: string = '';
- public image: string = '';
- public cost: string = 'action';
- public duration: number = 0;
- public durationtype: 'rounds' | 'minutes' | 'hours' | 'days' = 'rounds';
- public timeToCast: number = 0;
- public canRitual: boolean = false;
- public isRitual: boolean = false;
- public needsConcentration: boolean = false;
- public needsVerbal: boolean = false;
- public needsSomatic: boolean = false;
- public needsMaterial: boolean = false;
- public school: string = 'evocation';
- public description_de: string = '';
- public description_en: string = '';
- public doesDamage: boolean = false;
- public doesHeal: boolean = false;
- public needsAttackRoll: boolean = false;
- public needsSavingThrow: boolean = false;
- public savingThrowAttribute: string = '';
- public heal: Heal = {
- diceNumber: 0,
- diceType: 0,
- additionalHeal: 0,
- };
- public attackBonus: string = '';
- public damage: Damage[] = [{ diceNumber: 0, diceType: 0, damageType: '' }];
- public isRanged: boolean = false;
- public range: number = 5;
- public hasAreaOfEffect: boolean = false;
- public diameter: number = 5;
- public areaOfEffectType: string = 'circle';
- active = 'description';
- editor: Editor = new Editor();
- html = '';
- toolbar: any = [
- // default value
- ['bold', 'italic'],
- ['bullet_list'],
- [{ heading: ['h3', 'h4', 'h5', 'h6'] }],
- ];
- // #endregion
- public costs: string[] = ['action', 'bonus', 'reaction'];
- // #endregion
- public constructor(
- private modalAccessor: ModalService,
- public translator: TranslatorService,
- ) {}
- public ngOnInit(): void {
- if (this.isModification || this.isBasedOnOfficialSpell) {
- this.loadspell();
- }
- }
- // #region RESPONSES
- public cancel(): void {
- this.modalAccessor.handleModalClosing('cancel', undefined);
- this.resetSpell();
- }
- public add(): void {
- this.modalAccessor.handleModalClosing('add', this.createSpell());
- this.resetSpell();
- }
- public update(): void {
- this.modalAccessor.handleModalClosing('update', this.createSpell());
- this.resetSpell();
- }
- // #endregion
- // #region FUNCTIONS
- private loadspell(): void {
- if (this.isModification) {
- this.id = this.spell.id;
- this.german = this.spell.german;
- this.english = this.spell.english;
- // TODO: Implement internationalization
- this.name = this.spell.german;
- this.classes = this.spell.classes;
- } else {
- this.german = this.spell.german + ' (Kopie)';
- this.english = this.spell.english + ' (copy)';
- this.name = this.spell.german + ' (Kopie)';
- }
- this.image = this.spell.image;
- this.classes = this.spell.classes;
- this.level = this.spell.level;
- this.cost = this.spell.cost;
- this.canRitual = this.spell.canRitual;
- this.isRitual = this.spell.isRitual;
- this.duration = this.spell.duration;
- this.durationtype = this.spell.durationType;
- this.timeToCast = this.spell.timeToCast;
- this.needsConcentration = this.spell.needsConcentration;
- this.needsVerbal = this.spell.needsVerbal;
- this.needsSomatic = this.spell.needsSomatic;
- this.needsMaterial = this.spell.needsMaterial;
- this.school = this.spell.school;
- this.description_de = this.spell.description_de;
- this.description_en = this.spell.description_en;
- this.doesDamage = this.spell.doesDamage;
- this.needsSavingThrow = this.spell.needsSavingThrow;
- this.savingThrowAttribute = this.spell.savingThrowAttribute;
- this.damage = this.spell.damage;
- this.isRanged = this.spell.isRanged;
- this.range = this.spell.range;
- this.hasAreaOfEffect = this.spell.hasAreaOfEffect;
- this.diameter = this.spell.diameter;
- this.areaOfEffectType = this.spell.areaOfEffectType;
- this.needsAttackRoll = this.spell.needsAttackRoll;
- this.attackBonus = this.spell.attackBonus;
- this.doesHeal = this.spell.doesHeal;
- this.heal = this.spell.heal;
- }
- private createSpell(): Spell {
- const spell: Spell = {
- id: this.id,
- isCustom: true,
- english: this.name,
- german: this.name,
- image: this.image,
- classes: this.classes,
- duration: this.duration,
- durationType: this.durationtype,
- timeToCast: 0, // FIXME: only mocked
- damage: this.damage,
- heal: this.heal,
- level: parseInt(this.level.toString()),
- cost: this.cost,
- canRitual: this.canRitual,
- isRitual: this.isRitual,
- school: this.school,
- description_de: this.description_de,
- description_en: this.description_de,
- needsConcentration: this.needsConcentration,
- needsVerbal: this.needsVerbal,
- needsSomatic: this.needsSomatic,
- needsMaterial: this.needsMaterial,
- needsAttackRoll: this.needsSavingThrow ? false : this.needsAttackRoll,
- needsSavingThrow: this.needsSavingThrow,
- savingThrowAttribute: this.savingThrowAttribute,
- isRanged: this.isRanged,
- range: this.range,
- diameter: this.diameter,
- hasAreaOfEffect: this.hasAreaOfEffect,
- areaOfEffectType: this.areaOfEffectType,
- doesDamage: this.doesDamage,
- doesHeal: this.doesHeal,
- };
- return spell;
- }
- private resetSpell(): void {
- this.id = 0;
- this.german = '';
- this.english = '';
- this.name = '';
- this.image = '';
- this.classes = [];
- this.level = 0;
- this.cost = 'action';
- this.canRitual = false;
- this.isRitual = false;
- this.duration = 0;
- this.durationtype = 'rounds';
- this.timeToCast = 0;
- this.needsConcentration = false;
- this.needsVerbal = false;
- this.needsSomatic = false;
- this.needsMaterial = false;
- this.school = 'evocation';
- this.description_de = '';
- this.description_en = '';
- this.doesDamage = true;
- this.needsSavingThrow = false;
- this.savingThrowAttribute = '';
- this.damage = [{ diceNumber: 0, diceType: 0, damageType: '' }];
- this.isRanged = false;
- this.range = 5;
- this.hasAreaOfEffect = false;
- this.diameter = 5;
- this.areaOfEffectType = 'circle';
- this.needsAttackRoll = false;
- this.attackBonus = '';
- this.doesHeal = false;
- this.heal = { diceNumber: 0, diceType: 0, additionalHeal: 0 };
- }
- public addDamage(): void {
- this.damage.push({ diceNumber: 0, diceType: 0, damageType: '' });
- }
- public removeDamage(index: number): void {
- this.damage.splice(index, 1);
- }
- public setRitual(event: any): void {
- if (event.target.checked) {
- this.canRitual = true;
- }
- }
- public unsetRitual(event: any): void {
- if (!event.target.checked) {
- this.isRitual = false;
- }
- }
- // #endregion
- }
|