54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
import Conquer from '@burguillosinfo/conquer'
|
|
export default class FightSelectorSlide {
|
|
private callbacks: Record<string, Array<() => void>> = {}
|
|
|
|
public on(eventName: string, callback: () => void): void {
|
|
if (this.callbacks[eventName] === undefined) {
|
|
this.callbacks[eventName] = []
|
|
}
|
|
this.callbacks[eventName].push(callback)
|
|
}
|
|
|
|
private runCallbacks(eventName: string) {
|
|
const callbacks = this.callbacks[eventName];
|
|
if (callbacks === undefined) {
|
|
return
|
|
}
|
|
for (const callback of callbacks) {
|
|
callback()
|
|
}
|
|
}
|
|
|
|
private getSelectorSlide(): HTMLElement {
|
|
const selectorSlide = document.querySelector('#fight-battle-selector-slide');
|
|
if (!(selectorSlide instanceof HTMLElement)) {
|
|
Conquer.fail('selectorSlide is not HTMLElement');
|
|
}
|
|
return selectorSlide;
|
|
}
|
|
public startHook(): void {
|
|
this.createEventListeners();
|
|
}
|
|
|
|
public getGlobalBattleButton(): HTMLElement {
|
|
const globalBattleButton = this.getSelectorSlide().querySelector('button.fight-global-button');
|
|
if (!(globalBattleButton instanceof HTMLElement)) {
|
|
Conquer.fail('globalBattleButton is not HTMLElement');
|
|
}
|
|
return globalBattleButton;
|
|
}
|
|
|
|
private createEventListeners(): void {
|
|
const globalBattleButton = this.getGlobalBattleButton();
|
|
globalBattleButton.addEventListener('click', () => {
|
|
this.runCallbacks('global-battle');
|
|
});
|
|
}
|
|
public show(): void {
|
|
this.getSelectorSlide().classList.remove('conquer-display-none');
|
|
}
|
|
public hide(): void {
|
|
this.getSelectorSlide().classList.add('conquer-display-none');
|
|
}
|
|
}
|