• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 14804036802

02 May 2025 09:58PM UTC coverage: 5.927% (-83.4%) from 89.28%
14804036802

Pull #3404

github

web-flow
Merge 5c103d7f8 into 0f2ccaeb2
Pull Request #3404: feat: added Graph module to Math

234 of 8383 branches covered (2.79%)

229 of 246 new or added lines in 1 file covered. (93.09%)

13145 existing lines in 208 files now uncovered.

934 of 15759 relevant lines covered (5.93%)

4.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/engine/Input/InputMapper.ts
1
import { Gamepads } from './Gamepad';
2
import { Keyboard } from './Keyboard';
3
import { PointerEventReceiver } from './PointerEventReceiver';
4

5
export interface InputsOptions {
6
  keyboard: Keyboard;
7
  gamepads: Gamepads;
8
  pointers: PointerEventReceiver;
9
}
10

11
/**
12
 * This allows you to map multiple inputs to specific commands! This is especially useful when
13
 * you need to allow multiple input sources to control a specific action.
14
 */
15
export class InputMapper {
UNCOV
16
  private _handlers = new Map<any, any>();
×
UNCOV
17
  constructor(public inputs: InputsOptions) {}
×
18

19
  /**
20
   * Executes the input map, called internally by Excalibur
21
   */
22
  execute() {
UNCOV
23
    for (const [input, command] of this._handlers.entries()) {
×
UNCOV
24
      const results = input(this.inputs);
×
UNCOV
25
      if (results) {
×
UNCOV
26
        command(results);
×
27
      }
28
    }
29
  }
30

31
  /**
32
   * This allows you to map multiple inputs to specific commands! This is useful
33
   *
34
   * The inputHandler should return a truthy value if you wish the commandHandler to fire.
35
   *
36
   * Example:
37
   * ```typescript
38
   * const moveRight = (amount: number) => { actor.vel.x = 100 * amount }
39
   * const moveLeft = (amount: number) => { actor.vel.x = -100 * amount }
40
   * const moveUp = (amount: number) => { actor.vel.y = -100 * amount }
41
   * const moveDown = (amount: number) => { actor.vel.y = 100 * amount }
42
   *
43
   * engine.inputMapper.on(({keyboard}) => keyboard.isHeld(ex.Keys.ArrowRight) ? 1 : 0, moveRight);
44
   * engine.inputMapper.on(({gamepads}) => gamepads.at(0).isButtonPressed(ex.Buttons.DpadRight) ? 1 : 0, moveRight);
45
   * engine.inputMapper.on(({gamepads}) => gamepads.at(0).getAxes(ex.Axes.LeftStickX) > 0 ?
46
   *  gamepads.at(0).getAxes(ex.Axes.LeftStickX) : 0, moveRight);
47
   * ```
48
   * @param inputHandler
49
   * @param commandHandler
50
   */
51
  on<TInputHandlerData>(
52
    inputHandler: (inputs: InputsOptions) => TInputHandlerData | false,
53
    commandHandler: (data: TInputHandlerData) => any
54
  ) {
UNCOV
55
    this._handlers.set(inputHandler, commandHandler);
×
56
  }
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc