|
@@ -54,7 +54,8 @@ export class JournalSpellcardsComponent {
|
|
|
|
|
|
public constructor(
|
|
public constructor(
|
|
public dataAccessor: DataService,
|
|
public dataAccessor: DataService,
|
|
- private modalAccessor: ModalService
|
|
|
|
|
|
+ private modalAccessor: ModalService,
|
|
|
|
+ private spellsService: SpellsService
|
|
) {
|
|
) {
|
|
this.loadSpells();
|
|
this.loadSpells();
|
|
this.hideEmptySpelllists();
|
|
this.hideEmptySpelllists();
|
|
@@ -88,11 +89,18 @@ export class JournalSpellcardsComponent {
|
|
(result) => {
|
|
(result) => {
|
|
resultSubscription.unsubscribe();
|
|
resultSubscription.unsubscribe();
|
|
if (result.state === 'delete') {
|
|
if (result.state === 'delete') {
|
|
|
|
+ this.spellsService.deleteCustomSpell(spell);
|
|
|
|
+ this.dataAccessor.deleteCustomSpell(spell);
|
|
|
|
+ this.dataAccessor.removeFavoriteSpell(spell);
|
|
|
|
+ this.getSpellList(level).splice(spellIndex, 1);
|
|
|
|
+ this.updateSpellsInDatabase(level);
|
|
|
|
+ } else if (result.state === 'remove') {
|
|
|
|
+ this.dataAccessor.removeFavoriteSpell(spell);
|
|
this.getSpellList(level).splice(spellIndex, 1);
|
|
this.getSpellList(level).splice(spellIndex, 1);
|
|
this.updateSpellsInDatabase(level);
|
|
this.updateSpellsInDatabase(level);
|
|
} else if (result.state === 'update') {
|
|
} else if (result.state === 'update') {
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
- this.openSpellModal(true, level, spellIndex);
|
|
|
|
|
|
+ this.openSpellModificationModal(level, spellIndex);
|
|
}, 100);
|
|
}, 100);
|
|
} else if (result.state === 'add') {
|
|
} else if (result.state === 'add') {
|
|
this.dataAccessor.addFavoriteSpell(spell);
|
|
this.dataAccessor.addFavoriteSpell(spell);
|
|
@@ -101,62 +109,74 @@ export class JournalSpellcardsComponent {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- public openSpellModal(
|
|
|
|
- isUpdate: boolean,
|
|
|
|
- level: number,
|
|
|
|
- spellIndex?: number
|
|
|
|
- ): void {
|
|
|
|
|
|
+ // TODO: Update favorites, when modifying a spell
|
|
|
|
+ public openSpellModificationModal(level: number, index: number): void {
|
|
this.modalAccessor.openModal(SpellModalComponent, {
|
|
this.modalAccessor.openModal(SpellModalComponent, {
|
|
spell:
|
|
spell:
|
|
- spellIndex !== undefined
|
|
|
|
- ? JSON.parse(JSON.stringify(this.getSpellList(level)![spellIndex]))
|
|
|
|
|
|
+ index !== undefined
|
|
|
|
+ ? JSON.parse(JSON.stringify(this.getSpellList(level)![index]))
|
|
: undefined,
|
|
: undefined,
|
|
- isUpdate: isUpdate,
|
|
|
|
- level: level,
|
|
|
|
|
|
+ isModification: true,
|
|
});
|
|
});
|
|
const resultSubscription = this.modalAccessor.result$.subscribe(
|
|
const resultSubscription = this.modalAccessor.result$.subscribe(
|
|
(result) => {
|
|
(result) => {
|
|
if (result.state === 'update') {
|
|
if (result.state === 'update') {
|
|
// level was not modified
|
|
// level was not modified
|
|
if (level === result.data.level) {
|
|
if (level === result.data.level) {
|
|
- this.updateSpell(result.data, level!, spellIndex!);
|
|
|
|
|
|
+ this.updateSpell(result.data, level, index);
|
|
|
|
+ this.dataAccessor.updateFavoriteSpell(result.data);
|
|
|
|
+ this.dataAccessor.updateCustomSpell(result.data);
|
|
} else {
|
|
} else {
|
|
// level was modified
|
|
// level was modified
|
|
- this.getSpellList(level).splice(spellIndex!, 1);
|
|
|
|
|
|
+ this.getSpellList(level).splice(index, 1);
|
|
this.addSpell(result.data, result.data.level);
|
|
this.addSpell(result.data, result.data.level);
|
|
}
|
|
}
|
|
- } else if (result.state === 'add') {
|
|
|
|
- this.addSpell(result.data, level);
|
|
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error('REsult state from modal: ' + result.state);
|
|
}
|
|
}
|
|
resultSubscription.unsubscribe();
|
|
resultSubscription.unsubscribe();
|
|
}
|
|
}
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- public openSpellModalModifyOfficial(spell: Spell): void {
|
|
|
|
|
|
+ /**
|
|
|
|
+ * In this modal new spells can be created. This can be completely new spells or
|
|
|
|
+ * modified official spells. If successful, the spell is added to the spell list,
|
|
|
|
+ * sent to the daService and sent to the spellsService which in return sends it to the dataBase
|
|
|
|
+ * @param level
|
|
|
|
+ * @param isBasedOnOfficialSpell
|
|
|
|
+ * @param spell
|
|
|
|
+ */
|
|
|
|
+ public openSpellCreationModal(
|
|
|
|
+ level: number,
|
|
|
|
+ isBasedOnOfficialSpell: boolean,
|
|
|
|
+ spell?: Spell
|
|
|
|
+ ): void {
|
|
this.modalAccessor.openModal(SpellModalComponent, {
|
|
this.modalAccessor.openModal(SpellModalComponent, {
|
|
- spell: spell,
|
|
|
|
- isUpdate: true,
|
|
|
|
- level: spell.level,
|
|
|
|
|
|
+ spell: isBasedOnOfficialSpell ? spell : undefined,
|
|
|
|
+ level: level,
|
|
|
|
+ id: this.dataAccessor.customSpellId,
|
|
|
|
+ isBasedOnOfficialSpell: isBasedOnOfficialSpell,
|
|
|
|
+ classes: [this.dataAccessor.characterData.class],
|
|
});
|
|
});
|
|
const resultSubscription = this.modalAccessor.result$.subscribe(
|
|
const resultSubscription = this.modalAccessor.result$.subscribe(
|
|
(result) => {
|
|
(result) => {
|
|
- if (result.state === 'update') {
|
|
|
|
- this.addSpell(result.data, result.data.level);
|
|
|
|
|
|
+ if (result.state === 'add') {
|
|
|
|
+ console.warn('Add spell: ', result.data);
|
|
|
|
+
|
|
|
|
+ this.addSpell(result.data, level);
|
|
|
|
+ // this.spellsService.addCustomSpell(result.data);
|
|
|
|
+ this.dataAccessor.addCustomSpell(result.data);
|
|
|
|
+ } else {
|
|
|
|
+ console.warn('Result state from modal: ' + result.state);
|
|
}
|
|
}
|
|
resultSubscription.unsubscribe();
|
|
resultSubscription.unsubscribe();
|
|
}
|
|
}
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- public handleSpellSelection(data: any, level: number): void {
|
|
|
|
- const newSpell = data.spell;
|
|
|
|
- const isToModify = data.isToModify;
|
|
|
|
- if (isToModify) {
|
|
|
|
- this.openSpellModalModifyOfficial(newSpell);
|
|
|
|
- } else {
|
|
|
|
- this.addSpell(newSpell, level);
|
|
|
|
- }
|
|
|
|
|
|
+ public handleSpellSelection(spell: Spell, level: number): void {
|
|
|
|
+ this.addSpell(spell, level);
|
|
}
|
|
}
|
|
|
|
|
|
public addSpell(spell: Spell, level: number) {
|
|
public addSpell(spell: Spell, level: number) {
|
|
@@ -253,42 +273,72 @@ export class JournalSpellcardsComponent {
|
|
case 'cdk-drop-list-0':
|
|
case 'cdk-drop-list-0':
|
|
movedSpell.level = 0;
|
|
movedSpell.level = 0;
|
|
this.updateSpellsInDatabase(0);
|
|
this.updateSpellsInDatabase(0);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-1':
|
|
case 'cdk-drop-list-1':
|
|
movedSpell.level = 1;
|
|
movedSpell.level = 1;
|
|
this.updateSpellsInDatabase(1);
|
|
this.updateSpellsInDatabase(1);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-2':
|
|
case 'cdk-drop-list-2':
|
|
movedSpell.level = 2;
|
|
movedSpell.level = 2;
|
|
this.updateSpellsInDatabase(2);
|
|
this.updateSpellsInDatabase(2);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-3':
|
|
case 'cdk-drop-list-3':
|
|
movedSpell.level = 3;
|
|
movedSpell.level = 3;
|
|
this.updateSpellsInDatabase(3);
|
|
this.updateSpellsInDatabase(3);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-4':
|
|
case 'cdk-drop-list-4':
|
|
movedSpell.level = 4;
|
|
movedSpell.level = 4;
|
|
this.updateSpellsInDatabase(4);
|
|
this.updateSpellsInDatabase(4);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-5':
|
|
case 'cdk-drop-list-5':
|
|
movedSpell.level = 5;
|
|
movedSpell.level = 5;
|
|
this.updateSpellsInDatabase(5);
|
|
this.updateSpellsInDatabase(5);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-6':
|
|
case 'cdk-drop-list-6':
|
|
movedSpell.level = 6;
|
|
movedSpell.level = 6;
|
|
this.updateSpellsInDatabase(6);
|
|
this.updateSpellsInDatabase(6);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-7':
|
|
case 'cdk-drop-list-7':
|
|
movedSpell.level = 7;
|
|
movedSpell.level = 7;
|
|
this.updateSpellsInDatabase(7);
|
|
this.updateSpellsInDatabase(7);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-8':
|
|
case 'cdk-drop-list-8':
|
|
movedSpell.level = 8;
|
|
movedSpell.level = 8;
|
|
this.updateSpellsInDatabase(8);
|
|
this.updateSpellsInDatabase(8);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case 'cdk-drop-list-9':
|
|
case 'cdk-drop-list-9':
|
|
movedSpell.level = 9;
|
|
movedSpell.level = 9;
|
|
this.updateSpellsInDatabase(9);
|
|
this.updateSpellsInDatabase(9);
|
|
|
|
+ if (movedSpell.isCustom) {
|
|
|
|
+ this.dataAccessor.updateCustomSpell(movedSpell);
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -326,7 +376,7 @@ export class JournalSpellcardsComponent {
|
|
}
|
|
}
|
|
|
|
|
|
public dragEnd(event: any) {
|
|
public dragEnd(event: any) {
|
|
- if (event.event.target.classList.contains('deletion-card')) {
|
|
|
|
|
|
+ if (event.event.target.classList.contains('removal-card')) {
|
|
this.getSpellList(this.draggingIndex!).splice(
|
|
this.getSpellList(this.draggingIndex!).splice(
|
|
event.source.element.nativeElement.id,
|
|
event.source.element.nativeElement.id,
|
|
1
|
|
1
|