Skip to content

Commit

Permalink
fix: [#2762] wasPressed in input mapper (#2766)
Browse files Browse the repository at this point in the history
Closes #2762

## Changes:

- Changes the input mapper execution order to run input mapping before clearing keyboard events per frame
  • Loading branch information
eonarheim authored Sep 16, 2023
1 parent 6354bc3 commit 021c099
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
36 changes: 30 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,40 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [Unreleased]

### Breaking Changes

-

### Deprecated

-

### Added

-

### Fixed

- Fixed issue with input mapper where `keyboard.wasPressed(...)` did not fire

### Updates

-

### Changed

-

<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->

## [v0.28.0]

### Breaking Changes

- Removed `ex.Class` base class type, this was a common base class for many excalibur types that provided old on/off event functionality. This functionality has been preserved on the types that had it before using `ex.EventEmitter`

### Deprecated
Expand Down Expand Up @@ -193,11 +222,6 @@ stored `ex.Graphics` causing them to be shared across clones.
- Excalibur resources by default no longer add cache busting query string to resources. All built in resources now expose a `bustCache` property to allow setting this before loading, for example `ex.Sound.bustCache`.



<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->
<!--------------------------------- DO NOT EDIT BELOW THIS LINE --------------------------------->

## [0.27.0] - 2022-07-08

### Breaking Changes
Expand Down
4 changes: 2 additions & 2 deletions src/engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,9 @@ O|===|* >________________>\n\
// suspend updates until loading is finished
this._loader.update(this, delta);
// Update input listeners
this.inputMapper.execute();
this.input.keyboard.update();
this.input.gamepads.update();
this.inputMapper.execute();
return;
}

Expand All @@ -1225,9 +1225,9 @@ O|===|* >________________>\n\
this._postupdate(delta);

// Update input listeners
this.inputMapper.execute();
this.input.keyboard.update();
this.input.gamepads.update();
this.inputMapper.execute();
}

/**
Expand Down
22 changes: 22 additions & 0 deletions src/spec/InputMapperSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ex from '@excalibur';
import { TestUtils } from './util/TestUtils';

describe('An InputMapper', () => {
it('exists', () => {
Expand Down Expand Up @@ -49,4 +50,25 @@ describe('An InputMapper', () => {
expect(command).toHaveBeenCalledTimes(0);
});

it('can fire wasPressed events when used in a engine', () => {

const engine = TestUtils.engine({ width: 100, height: 100 });

const clock = engine.clock as ex.TestClock;
clock.start();
engine.input.keyboard.triggerEvent('down', ex.Keys.Space);

const sut = engine.inputMapper;
const keyPressedSpy = jasmine.createSpy('keyPressed');
const keyReleasedSpy = jasmine.createSpy('keyReleased');
sut.on(({keyboard}) => keyboard.wasPressed(ex.Keys.Space), keyPressedSpy);
sut.on(({keyboard}) => keyboard.wasReleased(ex.Keys.Space), keyReleasedSpy);

clock.step();
expect(keyPressedSpy).toHaveBeenCalled();

engine.input.keyboard.triggerEvent('up', ex.Keys.Space);
clock.step();
expect(keyReleasedSpy).toHaveBeenCalled();
});
});

0 comments on commit 021c099

Please sign in to comment.