Skip to content

Commit

Permalink
fix: [#3087] blockInput: true blocks input accessors (#3235)
Browse files Browse the repository at this point in the history
Closes #3087
  • Loading branch information
eonarheim authored Oct 15, 2024
1 parent 0624e76 commit 7f3cae7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ are doing mtv adjustments during precollision.

### Fixed

- Fixed issue where `blockInput: true` on scene transition only blocked input events, not accessors like `wasHeld(...)` etc.
- Fixed issue where users could not easily define a custom `RendererPlugin` because the type was not exposed
- Fixed issue where `ex.Fade` sometimes would not complete depending on the elapsed time
- Fixed issue where `ex.PolygonColliders` would get trapped in infinite loop for degenerate polygons (< 3 vertices)
Expand Down
9 changes: 9 additions & 0 deletions src/engine/Input/Keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ export class Keyboard {
* @param key Test whether a key was just pressed
*/
public wasPressed(key: Keys): boolean {
if (!this._enabled) {
return false;
}
return this._keysDown.indexOf(key) > -1;
}

Expand All @@ -425,6 +428,9 @@ export class Keyboard {
* @param key Test whether a key is held down
*/
public isHeld(key: Keys): boolean {
if (!this._enabled) {
return false;
}
return this._keys.indexOf(key) > -1;
}

Expand All @@ -433,6 +439,9 @@ export class Keyboard {
* @param key Test whether a key was just released
*/
public wasReleased(key: Keys): boolean {
if (!this._enabled) {
return false;
}
return this._keysUp.indexOf(key) > -1;
}

Expand Down
15 changes: 15 additions & 0 deletions src/engine/Input/PointerEventReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ export class PointerEventReceiver {
* @param pointerId
*/
public isDown(pointerId: number) {
if (!this._enabled) {
return false;
}
return this.currentFramePointerDown.get(pointerId) ?? false;
}

Expand All @@ -132,27 +135,39 @@ export class PointerEventReceiver {
* @param pointerId
*/
public wasDown(pointerId: number) {
if (!this._enabled) {
return false;
}
return this.lastFramePointerDown.get(pointerId) ?? false;
}

/**
* Whether the Pointer is currently dragging.
*/
public isDragging(pointerId: number): boolean {
if (!this._enabled) {
return false;
}
return this.isDown(pointerId);
}

/**
* Whether the Pointer just started dragging.
*/
public isDragStart(pointerId: number): boolean {
if (!this._enabled) {
return false;
}
return this.isDown(pointerId) && !this.wasDown(pointerId);
}

/**
* Whether the Pointer just ended dragging.
*/
public isDragEnd(pointerId: number): boolean {
if (!this._enabled) {
return false;
}
return !this.isDown(pointerId) && this.wasDown(pointerId);
}

Expand Down

0 comments on commit 7f3cae7

Please sign in to comment.