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