73 lines
2.6 KiB
TypeScript
73 lines
2.6 KiB
TypeScript
import Conquer from '@burguillosinfo/conquer';
|
|
import ConquerUser from '@burguillosinfo/conquer/user';
|
|
import AbstractTopBarInterface from '@burguillosinfo/conquer/interface/abstract-top-bar-interface';
|
|
import ConquerUserCurrentEnemy from '@burguillosinfo/conquer/user-current-enemy'
|
|
|
|
export default class SelectFightUI extends AbstractTopBarInterface {
|
|
private enemies: ConquerUserCurrentEnemy[];
|
|
private form: HTMLElement | null = null;
|
|
|
|
constructor(enemies: ConquerUserCurrentEnemy[]) {
|
|
super();
|
|
this.enemies = enemies;
|
|
}
|
|
|
|
public async run(): Promise<void> {
|
|
const user = await ConquerUser.getSelfUser()
|
|
if (user === null) {
|
|
this.runCallbacks('close')
|
|
return
|
|
}
|
|
this.getMainNode().append(this.getForm());
|
|
this.populateEnemies();
|
|
this.getMainNode().classList.remove('conquer-display-none');
|
|
}
|
|
|
|
private populateEnemies(): void {
|
|
for (const enemy of this.enemies) {
|
|
this.appendEnemy(enemy);
|
|
}
|
|
}
|
|
|
|
private appendEnemy(enemy: ConquerUserCurrentEnemy) {
|
|
const form = this.getForm();
|
|
const enemyNode = this.getNodeFromTemplateId('conquer-select-fight-item-template');
|
|
this.getNameEnemyNodeElement(enemyNode).innerText = enemy.getSpecies().getName();
|
|
this.getLevelEnemyNodeElement(enemyNode).innerText = '' + enemy.getLevel();
|
|
this.getImageEnemyNodeElement(enemyNode).src = enemy.getSpecies().getImage();
|
|
form.append(enemyNode);
|
|
}
|
|
|
|
private getImageEnemyNodeElement(enemyNode: HTMLElement): HTMLImageElement {
|
|
const conquerImage = enemyNode.querySelector('.conquer-image');
|
|
if (!(conquerImage instanceof HTMLImageElement)) {
|
|
Conquer.fail('conquerImage is not HTMLImageElement.')
|
|
}
|
|
return conquerImage;
|
|
}
|
|
|
|
private getLevelEnemyNodeElement(enemyNode: HTMLElement): HTMLElement {
|
|
const conquerLevel = enemyNode.querySelector('.conquer-level');
|
|
if (!(conquerLevel instanceof HTMLElement)) {
|
|
Conquer.fail('conquerLevel is not HTMLElement.')
|
|
}
|
|
return conquerLevel;
|
|
}
|
|
|
|
private getNameEnemyNodeElement(enemyNode: HTMLElement): HTMLElement {
|
|
const conquerName = enemyNode.querySelector('.conquer-name');
|
|
if (!(conquerName instanceof HTMLElement)) {
|
|
Conquer.fail('conquerName is not HTMLElement.')
|
|
}
|
|
return conquerName;
|
|
}
|
|
|
|
private getForm(): HTMLElement {
|
|
if (this.form === null) {
|
|
const form = this.getNodeFromTemplateId('conquer-select-fight-list-template')
|
|
this.form = form;
|
|
}
|
|
return this.form;
|
|
}
|
|
}
|