|
@@ -17,10 +17,12 @@ export class AddCardComponent {
|
|
|
@Output() onSpellSelected = new EventEmitter<any>();
|
|
|
|
|
|
public newSpellName: string = '';
|
|
|
+ private classAvailableSpells: any[] = [];
|
|
|
private allAvailableSpells: any[] = [];
|
|
|
public availableSpells: any[] = [];
|
|
|
public isModification: boolean | undefined;
|
|
|
public state: number = 1;
|
|
|
+ public showAll: boolean = false;
|
|
|
|
|
|
public constructor(
|
|
|
private spellsAccessor: SpellsService,
|
|
@@ -28,39 +30,49 @@ export class AddCardComponent {
|
|
|
) {}
|
|
|
|
|
|
public ngOnInit(): void {
|
|
|
- this.allAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
|
+ this.classAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
|
this.level,
|
|
|
this.dataAccessor.characterData.class,
|
|
|
);
|
|
|
+ this.allAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
|
+ this.level,
|
|
|
+ );
|
|
|
+ console.log('all: ', this.allAvailableSpells);
|
|
|
+ console.log('class: ', this.classAvailableSpells);
|
|
|
+
|
|
|
this.filterSpellArray();
|
|
|
this.spellsAccessor.closeSubject$.subscribe((level) => {
|
|
|
- console.log('Close subject received: ', level);
|
|
|
-
|
|
|
if (level !== this.level) {
|
|
|
this.resetThis();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ public toggleShowAll(): void {
|
|
|
+ this.showAll = !this.showAll;
|
|
|
+ if (this.isModification) {
|
|
|
+ this.filterSpellArrayForModification();
|
|
|
+ } else {
|
|
|
+ this.filterSpellArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public emitNewSpell(): void {
|
|
|
- console.warn('Emitting new spell to create: ', this.level);
|
|
|
this.createNewSpell.emit(this.level);
|
|
|
this.resetThis();
|
|
|
}
|
|
|
|
|
|
public emitNewSpellFromOfficial(spell: Spell): void {
|
|
|
- console.warn('Emitting new spell to modify from official: ', spell);
|
|
|
-
|
|
|
this.createNewSpellFromOfficial.emit(spell);
|
|
|
this.resetThis();
|
|
|
}
|
|
|
|
|
|
public continueToSpellSelection(modify: boolean): void {
|
|
|
- this.allAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
|
+ this.classAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
|
this.level,
|
|
|
this.dataAccessor.characterData.class,
|
|
|
);
|
|
|
- this.filterSpellArray();
|
|
|
+ // this.filterSpellArray();
|
|
|
this.isModification = modify;
|
|
|
if (modify) {
|
|
|
this.filterSpellArrayForModification();
|
|
@@ -86,8 +98,11 @@ export class AddCardComponent {
|
|
|
}
|
|
|
|
|
|
public filterSpellArray(): void {
|
|
|
- if (this.newSpellName.length >= 1) {
|
|
|
- this.availableSpells = this.allAvailableSpells.filter(
|
|
|
+ let array = this.showAll
|
|
|
+ ? this.allAvailableSpells
|
|
|
+ : this.classAvailableSpells;
|
|
|
+ if (this.newSpellName.length > 0) {
|
|
|
+ this.availableSpells = array.filter(
|
|
|
(spell) =>
|
|
|
(spell.german
|
|
|
.toLowerCase()
|
|
@@ -98,15 +113,19 @@ export class AddCardComponent {
|
|
|
!this.alreadyUsedSpells.includes(spell.id),
|
|
|
);
|
|
|
} else {
|
|
|
- this.availableSpells = this.allAvailableSpells.filter(
|
|
|
+ this.availableSpells = array.filter(
|
|
|
(spell) => !this.alreadyUsedSpells.includes(spell.id),
|
|
|
);
|
|
|
}
|
|
|
+ console.log('available: ', this.availableSpells);
|
|
|
}
|
|
|
|
|
|
public filterSpellArrayForModification(): void {
|
|
|
- if (this.newSpellName.length >= 1) {
|
|
|
- this.availableSpells = this.allAvailableSpells.filter(
|
|
|
+ let array = this.showAll
|
|
|
+ ? this.allAvailableSpells
|
|
|
+ : this.classAvailableSpells;
|
|
|
+ if (this.newSpellName.length > 0) {
|
|
|
+ this.availableSpells = array.filter(
|
|
|
(spell) =>
|
|
|
spell.german
|
|
|
.toLowerCase()
|
|
@@ -114,7 +133,8 @@ export class AddCardComponent {
|
|
|
spell.english.toLowerCase().includes(this.newSpellName.toLowerCase()),
|
|
|
);
|
|
|
} else {
|
|
|
- this.availableSpells = this.allAvailableSpells;
|
|
|
+ this.availableSpells = array;
|
|
|
}
|
|
|
+ console.log('available: ', this.availableSpells);
|
|
|
}
|
|
|
}
|