|
@@ -1,7 +1,8 @@
|
|
-import { Component, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
|
|
+import { Component, Input, Output, EventEmitter, inject } from '@angular/core';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
import { DataService } from 'src/services/data/data.service';
|
|
import { Spell } from 'src/interfaces/spell';
|
|
import { Spell } from 'src/interfaces/spell';
|
|
import { SpellsService } from 'src/services/spells/spells.service';
|
|
import { SpellsService } from 'src/services/spells/spells.service';
|
|
|
|
+import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: 'add-card',
|
|
selector: 'add-card',
|
|
@@ -11,23 +12,18 @@ import { SpellsService } from 'src/services/spells/spells.service';
|
|
export class AddCardComponent {
|
|
export class AddCardComponent {
|
|
@Input() level!: number;
|
|
@Input() level!: number;
|
|
@Input() alreadyUsedSpells!: any[];
|
|
@Input() alreadyUsedSpells!: any[];
|
|
-
|
|
|
|
- @Output() createNewSpell = new EventEmitter<any>();
|
|
|
|
- @Output() createNewSpellFromOfficial = new EventEmitter<any>();
|
|
|
|
@Output() onSpellSelected = new EventEmitter<any>();
|
|
@Output() onSpellSelected = new EventEmitter<any>();
|
|
|
|
|
|
public newSpellName: string = '';
|
|
public newSpellName: string = '';
|
|
private classAvailableSpells: any[] = [];
|
|
private classAvailableSpells: any[] = [];
|
|
private allAvailableSpells: any[] = [];
|
|
private allAvailableSpells: any[] = [];
|
|
public availableSpells: any[] = [];
|
|
public availableSpells: any[] = [];
|
|
- public isModification: boolean | undefined;
|
|
|
|
- public state: number = 1;
|
|
|
|
|
|
+ public isIdle: boolean = true;
|
|
public showAll: boolean = false;
|
|
public showAll: boolean = false;
|
|
|
|
|
|
- public constructor(
|
|
|
|
- private spellsAccessor: SpellsService,
|
|
|
|
- private dataAccessor: DataService,
|
|
|
|
- ) {}
|
|
|
|
|
|
+ private spellsAccessor = inject(SpellsService);
|
|
|
|
+ private dataAccessor = inject(DataService);
|
|
|
|
+ public translate: any = inject(TranslateService);
|
|
|
|
|
|
public ngOnInit(): void {
|
|
public ngOnInit(): void {
|
|
this.classAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
this.classAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
@@ -47,35 +43,7 @@ export class AddCardComponent {
|
|
|
|
|
|
public toggleShowAll(): void {
|
|
public toggleShowAll(): void {
|
|
this.showAll = !this.showAll;
|
|
this.showAll = !this.showAll;
|
|
- if (this.isModification) {
|
|
|
|
- this.filterSpellArrayForModification();
|
|
|
|
- } else {
|
|
|
|
- this.filterSpellArray();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public emitNewSpell(): void {
|
|
|
|
- this.createNewSpell.emit(this.level);
|
|
|
|
- this.resetThis();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public emitNewSpellFromOfficial(spell: Spell): void {
|
|
|
|
- this.createNewSpellFromOfficial.emit(spell);
|
|
|
|
- this.resetThis();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public continueToSpellSelection(modify: boolean): void {
|
|
|
|
- this.classAvailableSpells = this.spellsAccessor.getAvailableSpells(
|
|
|
|
- this.level,
|
|
|
|
- this.dataAccessor.characterData.class,
|
|
|
|
- );
|
|
|
|
- this.isModification = modify;
|
|
|
|
- if (modify) {
|
|
|
|
- this.filterSpellArrayForModification();
|
|
|
|
- } else {
|
|
|
|
- this.filterSpellArray();
|
|
|
|
- }
|
|
|
|
- this.closeOthers();
|
|
|
|
|
|
+ this.filterSpellArray();
|
|
}
|
|
}
|
|
|
|
|
|
public spellSelected(spell: any): void {
|
|
public spellSelected(spell: any): void {
|
|
@@ -89,8 +57,7 @@ export class AddCardComponent {
|
|
|
|
|
|
public resetThis(): void {
|
|
public resetThis(): void {
|
|
this.newSpellName = '';
|
|
this.newSpellName = '';
|
|
- this.state = 1;
|
|
|
|
- this.isModification = undefined;
|
|
|
|
|
|
+ this.isIdle = true;
|
|
this.showAll = false;
|
|
this.showAll = false;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -115,21 +82,4 @@ export class AddCardComponent {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public filterSpellArrayForModification(): void {
|
|
|
|
- let array = this.showAll
|
|
|
|
- ? this.allAvailableSpells
|
|
|
|
- : this.classAvailableSpells;
|
|
|
|
- if (this.newSpellName.length > 0) {
|
|
|
|
- this.availableSpells = array.filter(
|
|
|
|
- (spell) =>
|
|
|
|
- spell.german
|
|
|
|
- .toLowerCase()
|
|
|
|
- .includes(this.newSpellName.toLowerCase()) ||
|
|
|
|
- spell.english.toLowerCase().includes(this.newSpellName.toLowerCase()),
|
|
|
|
- );
|
|
|
|
- } else {
|
|
|
|
- this.availableSpells = array;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|