|
@@ -1,7 +1,10 @@
|
|
|
-import { Component, EventEmitter, Output, Input } from '@angular/core';
|
|
|
|
|
|
|
+import { Component } from '@angular/core';
|
|
|
import { DataService } from 'src/services/data/data.service';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
|
|
|
+import { NgxSmartModalService } from 'ngx-smart-modal';
|
|
|
|
|
+import { DetailsService } from 'src/services/details/details.service';
|
|
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
|
import { Spell } from 'src/interfaces/spell';
|
|
import { Spell } from 'src/interfaces/spell';
|
|
|
|
|
+import { SpellDetailsComponent } from './spell-details/spell-details.component';
|
|
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
|
selector: 'spell-table',
|
|
selector: 'spell-table',
|
|
@@ -9,15 +12,17 @@ import { Spell } from 'src/interfaces/spell';
|
|
|
styleUrls: ['./spell-table.component.scss'],
|
|
styleUrls: ['./spell-table.component.scss'],
|
|
|
})
|
|
})
|
|
|
export class SpellTableComponent {
|
|
export class SpellTableComponent {
|
|
|
- public constructor(public dataAccessor: DataService) {}
|
|
|
|
|
|
|
+ public constructor(
|
|
|
|
|
+ public dataAccessor: DataService,
|
|
|
|
|
+ public ngxSmartModalService: NgxSmartModalService,
|
|
|
|
|
+ public detailsAccessor: DetailsService
|
|
|
|
|
+ ) {}
|
|
|
|
|
|
|
|
- @Output() public createNewSpell: EventEmitter<void> =
|
|
|
|
|
- new EventEmitter<void>();
|
|
|
|
|
- @Output() public updateSpellEvent: EventEmitter<any> =
|
|
|
|
|
- new EventEmitter<any>();
|
|
|
|
|
-
|
|
|
|
|
- @Input() public spellAttackBonus: string = '0';
|
|
|
|
|
- @Input() public spellSaveDC: number = 0;
|
|
|
|
|
|
|
+ public spellAttackBonus: string = '0';
|
|
|
|
|
+ public spellSaveDC: number = 0;
|
|
|
|
|
+ private spellcastingAttribute: string | undefined;
|
|
|
|
|
+ private spellcastingAttributeModifier: number = 0;
|
|
|
|
|
+ private proficiencyBonus: number = 2;
|
|
|
|
|
|
|
|
public spells!: Spell[];
|
|
public spells!: Spell[];
|
|
|
|
|
|
|
@@ -32,20 +37,39 @@ export class SpellTableComponent {
|
|
|
|
|
|
|
|
public ngOnInit(): void {
|
|
public ngOnInit(): void {
|
|
|
this.spells = this.dataAccessor.getSpells();
|
|
this.spells = this.dataAccessor.getSpells();
|
|
|
|
|
+ this.subscribeToData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public dropSpells(event: CdkDragDrop<string[]>): void {
|
|
|
|
|
- moveItemInArray(this.spells, event.previousIndex, event.currentIndex);
|
|
|
|
|
- this.updateSpellsInDatabase();
|
|
|
|
|
|
|
+ public openDetailsPanel(index: number): void {
|
|
|
|
|
+ this.detailsAccessor.openPanel(SpellDetailsComponent, {
|
|
|
|
|
+ spell: this.spells[index],
|
|
|
|
|
+ modifiers: {
|
|
|
|
|
+ attackBonus: this.spellAttackBonus,
|
|
|
|
|
+ saveDC: this.spellSaveDC,
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ const resultSubscription = this.detailsAccessor.result$.subscribe(
|
|
|
|
|
+ (result) => {
|
|
|
|
|
+ console.log(result);
|
|
|
|
|
+ if (result.state === 'delete') {
|
|
|
|
|
+ this.deleteSpell(index);
|
|
|
|
|
+ } else if (result.state === 'update') {
|
|
|
|
|
+ this.openSpellModificationModal(index);
|
|
|
|
|
+ }
|
|
|
|
|
+ resultSubscription.unsubscribe();
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public updateSpellsInDatabase(): void {
|
|
|
|
|
- this.dataAccessor.setSpells(this.spells);
|
|
|
|
|
|
|
+ public openSpellModal(): void {
|
|
|
|
|
+ this.ngxSmartModalService.getModal('spellModal').open();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public createSpell(): void {
|
|
|
|
|
- console.log('createWeapon()');
|
|
|
|
|
- this.createNewSpell.emit();
|
|
|
|
|
|
|
+ public openSpellModificationModal(index: number): void {
|
|
|
|
|
+ this.ngxSmartModalService
|
|
|
|
|
+ .getModal('spellModal')
|
|
|
|
|
+ .setData({ spell: this.spells[index], index: index });
|
|
|
|
|
+ this.ngxSmartModalService.getModal('spellModal').open();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public addSpell(spell: Spell) {
|
|
public addSpell(spell: Spell) {
|
|
@@ -53,11 +77,6 @@ export class SpellTableComponent {
|
|
|
this.updateSpellsInDatabase();
|
|
this.updateSpellsInDatabase();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public emitUpdateSpell(index: number): void {
|
|
|
|
|
- this.updateSpellEvent.emit({ spell: this.spells[index], index: index });
|
|
|
|
|
- console.log('emitUpdateWeapon()');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public updateSpell(spell: Spell, index: number): void {
|
|
public updateSpell(spell: Spell, index: number): void {
|
|
|
this.spells[index] = spell;
|
|
this.spells[index] = spell;
|
|
|
this.updateSpellsInDatabase();
|
|
this.updateSpellsInDatabase();
|
|
@@ -67,4 +86,43 @@ export class SpellTableComponent {
|
|
|
this.spells.splice(index, 1);
|
|
this.spells.splice(index, 1);
|
|
|
this.updateSpellsInDatabase();
|
|
this.updateSpellsInDatabase();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // utils
|
|
|
|
|
+
|
|
|
|
|
+ public dropSpells(event: CdkDragDrop<string[]>): void {
|
|
|
|
|
+ moveItemInArray(this.spells, event.previousIndex, event.currentIndex);
|
|
|
|
|
+ this.updateSpellsInDatabase();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public updateSpellsInDatabase(): void {
|
|
|
|
|
+ this.dataAccessor.setSpells(this.spells);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private computeSpellAttackBonusAndSaveDC(): void {
|
|
|
|
|
+ let attackBonus =
|
|
|
|
|
+ this.spellcastingAttributeModifier + this.proficiencyBonus;
|
|
|
|
|
+ this.spellSaveDC = 8 + attackBonus;
|
|
|
|
|
+ if (attackBonus >= 0) {
|
|
|
|
|
+ this.spellAttackBonus = '+' + attackBonus;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.spellAttackBonus = attackBonus.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private subscribeToData(): void {
|
|
|
|
|
+ // TODO: this.dataAccessor.getSpellcastingAttribute() oder so
|
|
|
|
|
+ this.spellcastingAttribute = 'intelligence';
|
|
|
|
|
+
|
|
|
|
|
+ this.dataAccessor.proficiency$.subscribe((value) => {
|
|
|
|
|
+ this.proficiencyBonus = value.value;
|
|
|
|
|
+ if (this.spellcastingAttribute) {
|
|
|
|
|
+ this.computeSpellAttackBonusAndSaveDC();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ // TODO: Modify depending on the actual spellcasting attribute
|
|
|
|
|
+ this.dataAccessor.intelligence$.subscribe((value) => {
|
|
|
|
|
+ this.spellcastingAttributeModifier = Math.floor((value.value - 10) / 2);
|
|
|
|
|
+ this.computeSpellAttackBonusAndSaveDC();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|