Skip to content

Commit

Permalink
Enabled to start with a gamepad in Pyxel We
Browse files Browse the repository at this point in the history
  • Loading branch information
kitao committed Jan 5, 2023
1 parent fed69ca commit 6779ad8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Suppressed clippy warnings
- Updated Pyodide version to 0.22.0
- Enabled to start with a gamepad in Pyxel Web

# 1.9.8

Expand Down
19 changes: 11 additions & 8 deletions wasm/pyxel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const NO_SLEEP_URL =
"https://cdnjs.cloudflare.com/ajax/libs/nosleep/0.12.0/NoSleep.min.js";
const PYODIDE_SDL2_URL =
"https://cdn.jsdelivr.net/gh/kitao/pyodide-sdl2@0.22.0/pyodide.js";
const PYXEL_WHEEL_PATH = "pyxel-1.9.8-cp37-abi3-emscripten_3_1_29_wasm32.whl";
const PYXEL_WHEEL_PATH = "pyxel-1.9.9-cp37-abi3-emscripten_3_1_29_wasm32.whl";
const PYXEL_LOGO_PATH = "../docs/images/pyxel_logo_76x32.png";
const TOUCH_TO_START_PATH = "../docs/images/touch_to_start_114x14.png";
const CLICK_TO_START_PATH = "../docs/images/click_to_start_114x14.png";
Expand Down Expand Up @@ -44,7 +44,6 @@ function _setStyleSheet() {
async function launchPyxel(params) {
console.log("Launch Pyxel");
console.log(params);
_allowGamepadConnection();
_suppressPinchOperations();
await _createScreenElements();
let pyodide = await _loadPyodideAndPyxel();
Expand All @@ -53,12 +52,6 @@ async function launchPyxel(params) {
await _executePyxelCommand(pyodide, params);
}

function _allowGamepadConnection() {
window.addEventListener("gamepadconnected", (event) => {
console.log(`Connected '${event.gamepad.id}'`);
});
}

function _suppressPinchOperations() {
let touchHandler = (event) => {
if (event.touches.length > 1) {
Expand Down Expand Up @@ -247,6 +240,15 @@ function _isTouchDevice() {
);
}

function _allowGamepadConnection() {
window.addEventListener("gamepadconnected", (event) => {
console.log(`Connected '${event.gamepad.id}'`);
if (document.body) {
document.body.dispatchEvent(new MouseEvent("click"));
}
});
}

async function _waitForInput() {
let pyxelScreen = document.querySelector("div#pyxel-screen");
let logoImage = document.querySelector("img#pyxel-logo");
Expand All @@ -259,6 +261,7 @@ async function _waitForInput() {
await _waitForEvent(promptImage, "load");
pyxelScreen.appendChild(promptImage);
_updateScreenElementsSize();
_allowGamepadConnection();
await _waitForEvent(document.body, "click");
promptImage.remove();
}
Expand Down

0 comments on commit 6779ad8

Please # to comment.