Refactor character click handling into method

This commit is contained in:
artisticMink 2023-10-28 12:50:42 +02:00
parent 6eb6527d11
commit 7f6b6615ab
1 changed files with 8 additions and 4 deletions

View File

@ -265,16 +265,14 @@ class CharacterGroupOverlay {
switch (this.state) {
case CharacterGroupOverlayState.browse:
this.container.classList.remove(CharacterGroupOverlay.selectModeClass);
[...this.container.getElementsByClassName(CharacterGroupOverlay.characterClass)]
.forEach(element => element.removeEventListener('click', this.toggleCharacterSelected));
this.#enableClickEventsForCharacters();
this.clearSelectedCharacters();
this.disableContextMenu();
CharacterContextMenu.hide();
break;
case CharacterGroupOverlayState.select:
this.container.classList.add(CharacterGroupOverlay.selectModeClass);
[...this.container.getElementsByClassName(CharacterGroupOverlay.characterClass)]
.forEach(element => element.addEventListener('click', this.toggleCharacterSelected));
this.#disableClickEventsForCharacters();
this.enableContextMenu();
break;
}
@ -282,6 +280,12 @@ class CharacterGroupOverlay {
this.stateChangeCallbacks.forEach(callback => callback(this.state));
}
#enableClickEventsForCharacters = () => [...this.container.getElementsByClassName(CharacterGroupOverlay.characterClass)]
.forEach(element => element.removeEventListener('click', this.toggleCharacterSelected));
#disableClickEventsForCharacters = () => [...this.container.getElementsByClassName(CharacterGroupOverlay.characterClass)]
.forEach(element => element.addEventListener('click', this.toggleCharacterSelected));
toggleCharacterSelected = event => {
event.stopPropagation();