From ebffd8b19b943d0f2553e4f28e748a3ca6bae6f7 Mon Sep 17 00:00:00 2001 From: 0xAlcibiades <89996683+0xAlcibiades@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:04:24 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=200xAlcibi?= =?UTF-8?q?ades/rusty-pong@c7b88dc17f01aa57333d0c6507b7e66e85715235=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 252eddf..b4163f6 100644 --- a/index.html +++ b/index.html @@ -282,12 +282,30 @@

RUSTY PONG

playButton.textContent = "Click to Load Game"; gameContainer.appendChild(playButton); - // Helper function to move canvas into container + // Helper function to move canvas into container and focus it const moveCanvas = () => { const canvases = document.getElementsByTagName("canvas"); for (let canvas of canvases) { if (canvas.parentElement !== gameContainer) { gameContainer.appendChild(canvas); + // Add tabindex to make canvas focusable + canvas.setAttribute("tabindex", "0"); + // Focus the canvas + canvas.focus(); + // Maintain focus when clicking on canvas + canvas.addEventListener("mousedown", (e) => { + e.preventDefault(); + canvas.focus(); + }); + // Prevent focus loss on mobile touch + canvas.addEventListener( + "touchstart", + (e) => { + e.preventDefault(); + canvas.focus(); + }, + { passive: false }, + ); } } }; @@ -304,13 +322,15 @@

RUSTY PONG

window.webkitAudioContext)(); await audioContext.resume(); - // Watch for canvas creation and move it to container + // Enhanced observer to handle canvas creation and focus observer = new MutationObserver((mutations) => { for (let mutation of mutations) { if (mutation.addedNodes) { mutation.addedNodes.forEach((node) => { if (node.nodeName === "CANVAS") { gameContainer.appendChild(node); + node.setAttribute("tabindex", "0"); + node.focus(); } }); } @@ -324,21 +344,18 @@

RUSTY PONG

const { default: init } = await import("./rusty_pong.js"); await init(); - // Ensure canvas is in the right place + // Ensure canvas is in the right place and focused moveCanvas(); } catch (error) { - // Handle Bevy's control flow exception (not a real error) if (error.message?.includes("Using exceptions for control flow")) { loading.style.display = "none"; } else { - // Handle actual errors console.error("Failed to load WASM:", error); loading.textContent = "Failed to load game. Please refresh and try again."; loading.style.color = "#e43d1a"; } } finally { - // Clean up observer if it was created if (observer) { observer.disconnect(); }