Skip to content

Commit

Permalink
Mouse buttons support
Browse files Browse the repository at this point in the history
  • Loading branch information
Deseteral committed Sep 30, 2023
1 parent 35e1fc8 commit 5a9d95f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/core/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export abstract class Input {
* Pointer position in screen space.
*/
public static readonly pointer: Vector2 = new Vector2();
public static pointerLeftPressed: boolean = false;
public static pointerRightPressed: boolean = false;

private static keyState: Map<string, boolean> = new Map();
private static previousKeyState: Map<string, boolean> = new Map();
Expand Down Expand Up @@ -121,5 +123,15 @@ export abstract class Input {
((y / canvas.clientHeight) * canvas.height) | 0,
);
});

canvas.addEventListener('mousedown', (e) => {
if (e.button === 0) Input.pointerLeftPressed = true;
if (e.button === 2) Input.pointerRightPressed = true;
});

canvas.addEventListener('mouseup', (e) => {
if (e.button === 0) Input.pointerLeftPressed = false;
if (e.button === 2) Input.pointerRightPressed = false;
});
}
}
2 changes: 2 additions & 0 deletions src/gfx/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ export class Screen {
canvas.width = width;
canvas.height = height;

canvas.addEventListener('contextmenu', e => e.preventDefault());

Check failure on line 447 in src/gfx/screen.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected parentheses around arrow function argument

const ctx = canvas.getContext('2d');
if (!ctx) {
throw new Error('An error occured while creating canvas context');
Expand Down
1 change: 0 additions & 1 deletion src/ponczek.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* TODO: Camera boundaries
* TODO: Camera shake
* TODO: Add loading map from texture in tilemap test scene
* TODO: Mouse buttons support
* TODO: Add support for triangle rendering
* TODO: Grid view scrolling
* TODO: Data structure for defining color palettes
Expand Down

0 comments on commit 5a9d95f

Please sign in to comment.