From 2ef5c1f1c7083dbaa678e42a92650d21f3c6e69c Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 15 Mar 2023 10:43:40 -0400 Subject: [PATCH] remove allowKeyOverlap prototype, it is not worth pursuing, see https://github.com/phetsims/scenery-phet/issues/790 and https://github.com/phetsims/scenery/issues/1445 --- js/listeners/KeyboardListener.ts | 57 +------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/js/listeners/KeyboardListener.ts b/js/listeners/KeyboardListener.ts index 41d05c8c6..ada767a25 100644 --- a/js/listeners/KeyboardListener.ts +++ b/js/listeners/KeyboardListener.ts @@ -111,9 +111,6 @@ type KeyboardListenerOptions = { // If fireOnHold true, this is the interval (in milliseconds) that the callback fires after the fireOnHoldDelay. fireOnHoldInterval?: number; - // TODO: Potential option to allow overlap between the keys of this KeyboardListener and another. - allowKeyOverlap?: boolean; - // Possible input types that decide when callbacks of the listener fire in response to input. See // ListenerFireTrigger type documentation. listenerFireTrigger?: ListenerFireTrigger; @@ -175,9 +172,6 @@ class KeyboardListener implements TInputLi private readonly _handle: boolean; private readonly _abort: boolean; - // TODO: Potentially a flag that could allow overlaps between keys of other KeyboardListeners. - private readonly _allowKeyOverlap: boolean; - private readonly _windowFocusListener: ( windowHasFocus: boolean ) => void; public constructor( providedOptions: KeyboardListenerOptions ) { @@ -191,8 +185,7 @@ class KeyboardListener implements TInputLi listenerFireTrigger: 'down', fireOnHold: false, fireOnHoldDelay: 400, - fireOnHoldInterval: 100, - allowKeyOverlap: false + fireOnHoldInterval: 100 }, providedOptions ); this._callback = options.callback; @@ -205,8 +198,6 @@ class KeyboardListener implements TInputLi this._activeKeyGroups = []; - this._allowKeyOverlap = options.allowKeyOverlap; - this.keysDown = false; this._global = options.global; @@ -227,12 +218,6 @@ class KeyboardListener implements TInputLi * Mostly required to fire with CallbackTimer since the callback cannot take arguments. */ public fireCallback( event: SceneryEvent | null, keyGroup: KeyGroup ): void { - - // TODO: Some initial work to check for overlap between other listeners that are responding to the same keys. - // if ( assert && event && !this._allowKeyOverlap ) { - // this.checkForTrailKeyCollisions( event, keyGroup ); - // } - this.keysPressed = keyGroup.naturalKeys; this._callback( event, this ); this.keysPressed = null; @@ -387,46 +372,6 @@ class KeyboardListener implements TInputLi this.handleCancel(); } - /** - * Throws an assertion if any Node along the trail has a KeyboardListener that is listening for key presses that - * overlap with this KeyboardListener, so both would fire. A lot of loops required to find this information, - * only run when assertions are enabled. Or consider optimizing. - * - * TODO: Still working on this function. This method works decently but has not been tested well and may not - * cover all cases. Still need to look for collisions against active global listeners as well. For that - * we will probably need a registry object. - */ - private checkForTrailKeyCollisions( event: SceneryEvent, myKeyGroup: KeyGroup ): void { - const trails = event.target.getTrails(); - - for ( let i = 0; i < trails.length; i++ ) { - const trail = trails[ i ]; - for ( let j = 0; j < trail.nodes.length; j++ ) { - const node = trail.nodes[ j ]; - for ( let k = 0; k < node.inputListeners.length; k++ ) { - const inputListener = node.inputListeners[ k ]; - if ( inputListener.listener instanceof KeyboardListener && - !inputListener.listener._allowKeyOverlap && - inputListener.listener !== this ) { - const ancestorKeyGroups = inputListener.listener._keyGroups; - - for ( let l = 0; l < ancestorKeyGroups.length; l++ ) { - const ancestorNaturalKeys = ancestorKeyGroups[ l ].naturalKeys; - - // There is an ovelrap if the last keys are the same, or if all keys of the ancestor are pressed while - // pressing the modifier keys of the descendant keys - const modifierOverlap = ancestorNaturalKeys.startsWith( myKeyGroup.naturalKeys ); - const finalKeysEqual = ancestorKeyGroups[ l ].key === myKeyGroup.key; - - assert && assert( !modifierOverlap && !finalKeysEqual, - `Keys collision with another KeyboardListener along this trail. My keys: ${myKeyGroup.naturalKeys}, other keys: '${ancestorNaturalKeys}, '` ); - } - } - } - } - } - } - /** * Dispose of this listener by disposing of any Callback timers. Then clear all KeyGroups. */