Skip to content

Commit

Permalink
Add shortcut for vibration
Browse files Browse the repository at this point in the history
  • Loading branch information
pmanikas committed Nov 22, 2024
1 parent 06f4ce7 commit f62720b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ class GamepadController {
requestAnimationFrame(this.gameLoop.bind(this));
}

private vibrateOnVKeyPress(event: KeyboardEvent): void {
if (event.key === "v") this.vibrate();
}

private initializeVibration(gamepad: Gamepad): void {
if (!gamepad.vibrationActuator) return;

Expand All @@ -190,10 +194,11 @@ class GamepadController {

Object.assign(vibrateButton, {
className: "vibrate-button",
textContent: "Vibrate"
textContent: "Vibrate (V)"
});

vibrateButton.addEventListener("click", () => this.vibrate(GamepadController.DEFAULT_VIBRATION_DURATION));
document.addEventListener("keyup", (event) => this.vibrateOnVKeyPress(event));

document.body.appendChild(vibrateButton);
this.vibrate(GamepadController.DEFAULT_VIBRATION_DURATION);
Expand Down Expand Up @@ -224,6 +229,7 @@ class GamepadController {
this.elements.svgContainer.innerHTML = "";
this.elements.detectingScreen.classList.add("active");
document.querySelector(".vibrate-button")?.remove();
document.removeEventListener("keyup", (event) => this.vibrateOnVKeyPress(event));
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/assets/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ body {

.vibrate-button {
display: block;
height: 40px;
background-color: var(--c-primary);
color: var(--c-secondary);
padding: calc(var(--s-base) / 2);
border: 1px solid var(--c-secondary);
border-bottom-width: 3px;
border-radius: var(--border-radius);
cursor: pointer;
box-shadow: 0 0 10px var(--shadow);
Expand All @@ -99,6 +101,11 @@ body {
background-color: var(--c-primary-faded);
}

.vibrate-button:active, .vibrate-button.active {
border-bottom-width: 1px;
transform: scaleY(0.95)
}

.vibrate {
animation: vibrate 0.1s linear infinite;
}

0 comments on commit f62720b

Please sign in to comment.