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 }