Skip to content

Commit

Permalink
use overlay element to capture client input
Browse files Browse the repository at this point in the history
  • Loading branch information
n-at committed Sep 3, 2023
1 parent 9b1eb0d commit 099575e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions assets/css/netplay.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ body {
right: 0;
background-color: #000;
}
#game-overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 10;
}
#game-overlay:focus {
outline: none;
}
#game {
display: block;
margin: 0;
Expand Down
11 changes: 7 additions & 4 deletions assets/netplay-ui-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
document.getElementById('netplay-virtual-gamepad-toggle').addEventListener('click', virtualGamepadToggle);
document.getElementById('netplay-play').addEventListener('click', play);

window.addEventListener('keydown', controlsButtonDown);
window.addEventListener('keyup', controlsButtonUp);
setInterval(controlsPollGamepad, 1000 / 60);

if (fullscreenEnabled()) {
const fullscreenButton = document.getElementById('netplay-fullscreen');
fullscreenButton.addEventListener('click', fullscreen);
Expand All @@ -25,6 +21,13 @@
gameEl.addEventListener('pause', () => playScreen(true));
gameEl.disablePictureInPicture = true;

const gameOverlayEl = document.getElementById('game-overlay');
gameOverlayEl.addEventListener('keydown', controlsButtonDown);
gameOverlayEl.addEventListener('keyup', controlsButtonUp);
setInterval(controlsPollGamepad, 1000 / 60);

gameOverlayEl.focus();

loadControlScheme();
virtualGamepadInit();
virtualGamepadLoad();
Expand Down
1 change: 1 addition & 0 deletions templates/netplay.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</div>

<div id="game-container">
<div id="game-overlay" tabindex="0"></div>
<video id="game" disablepictureinpicture autoplay playsinline></video>

<div id="notifications" class="toast-container position-fixed p-3"></div>
Expand Down

0 comments on commit 099575e

Please sign in to comment.