Spaces:
Running
Running
File size: 848 Bytes
e6b949c 9332801 e6b949c 9332801 e6b949c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import { InputHandler } from "./InputHandler";
class Controls {
private _inputHandlers: InputHandler[];
constructor(inputHandlers: InputHandler[], canvas: HTMLCanvasElement) {
this._inputHandlers = inputHandlers;
window.addEventListener("keydown", this.handleInput.bind(this));
canvas.addEventListener("mousedown", this.handleInput.bind(this));
canvas.addEventListener("mousemove", this.handleInput.bind(this));
canvas.addEventListener("mouseup", this.handleInput.bind(this));
canvas.addEventListener("click", this.handleInput.bind(this));
canvas.addEventListener("contextmenu", this.handleInput.bind(this));
}
handleInput(event: Event) {
for (const handler of this._inputHandlers) {
handler.handleInput(event);
}
}
}
export { Controls };
|