Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add joystick / gamepad support using distribution html files #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion dist/console-fullscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@
var scale = 1;
var margintop = 0;
var marginleft = 0;

var doGamepadReset = false;
var urlParams = new URLSearchParams(window.location.search);
var emulator = new metaEmulator.Emulator("emulator");
emulator.loadFromUrl(urlParams.has('bin') ? urlParams.get('bin') : "https://raw.githubusercontent.com/Rodot/Games-META/master/binaries/Solitaire/Solitaire.bin");
window.requestAnimationFrame(updateGamePadState);
var consoleelem = document.getElementById("console");
scale = setScale(consoleelem);
const dpadX = 108;
Expand Down Expand Up @@ -179,6 +180,41 @@
emulator.setButtonData(0b11111111);
}

function updateGamePadState() {
window.requestAnimationFrame(updateGamePadState);
if (!navigator) return;
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
if (!gamepads || gamepads.length == 0) return;
const gamepad = gamepads[0];
if(!gamepad) return;

let gamepadData = 0b11111111;
let buttonsCount = gamepad.buttons.length;
let axisCount = gamepad.axes.length;
if ((axisCount > 0 && gamepad.axes[0] < -.9) || (buttonsCount > 14 && gamepad.buttons[14].pressed)) gamepadData &= 0b11111101;
if ((axisCount > 0 && gamepad.axes[0] > .9) || (buttonsCount > 15 && gamepad.buttons[15].pressed)) gamepadData &= 0b11111011;
if ((axisCount > 1 && gamepad.axes[1] < -.9) || (buttonsCount > 12 && gamepad.buttons[12].pressed)) gamepadData &= 0b11110111;
if ((axisCount > 1 && gamepad.axes[1] > .9) || (buttonsCount > 13 && gamepad.buttons[13].pressed)) gamepadData &= 0b11111110;
if ((buttonsCount > 1 && gamepad.buttons[1].pressed) || (buttonsCount > 3 && gamepad.buttons[3].pressed)) gamepadData &= 0b11011111;
if ((buttonsCount > 0 && gamepad.buttons[0].pressed) || (buttonsCount > 2 && gamepad.buttons[2].pressed)) gamepadData &= 0b11101111;
if ((buttonsCount > 8 && gamepad.buttons[8].pressed)) gamepadData &= 0b10111111;
if ((buttonsCount > 9 && gamepad.buttons[9].pressed)) gamepadData &= 0b01111111;

if (gamepadData == 0b11111111)
{
if(doGamepadReset)
{
doGamepadReset = false;
emulator.setButtonData(gamepadData)
}
}
else
{
doGamepadReset = true;
emulator.setButtonData(gamepadData);
}
}

function handleTouches(event) {
event.preventDefault();

Expand Down
40 changes: 38 additions & 2 deletions dist/console.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@
<script src="url-search-params.js"></script>

<script>
var doGamepadReset = false;
var urlParams = new URLSearchParams(window.location.search);
var emulator = new metaEmulator.Emulator("emulator");
emulator.loadFromUrl(urlParams.has('bin') ? urlParams.get('bin') : "https://raw.githubusercontent.com/Rodot/Games-META/master/binaries/Solitaire/Solitaire.bin");

window.requestAnimationFrame(updateGamePadState);
const dpadX = 119;
const dpadY = 216;
const dpadDist = 87;
Expand Down Expand Up @@ -147,7 +148,42 @@
mousePressed = false;
emulator.setButtonData(0b11111111);
}


function updateGamePadState() {
window.requestAnimationFrame(updateGamePadState);
if (!navigator) return;
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
if (!gamepads || gamepads.length == 0) return;
const gamepad = gamepads[0];
if(!gamepad) return;

let gamepadData = 0b11111111;
let buttonsCount = gamepad.buttons.length;
let axisCount = gamepad.axes.length;
if ((axisCount > 0 && gamepad.axes[0] < -.9) || (buttonsCount > 14 && gamepad.buttons[14].pressed)) gamepadData &= 0b11111101;
if ((axisCount > 0 && gamepad.axes[0] > .9) || (buttonsCount > 15 && gamepad.buttons[15].pressed)) gamepadData &= 0b11111011;
if ((axisCount > 1 && gamepad.axes[1] < -.9) || (buttonsCount > 12 && gamepad.buttons[12].pressed)) gamepadData &= 0b11110111;
if ((axisCount > 1 && gamepad.axes[1] > .9) || (buttonsCount > 13 && gamepad.buttons[13].pressed)) gamepadData &= 0b11111110;
if ((buttonsCount > 1 && gamepad.buttons[1].pressed) || (buttonsCount > 3 && gamepad.buttons[3].pressed)) gamepadData &= 0b11011111;
if ((buttonsCount > 0 && gamepad.buttons[0].pressed) || (buttonsCount > 2 && gamepad.buttons[2].pressed)) gamepadData &= 0b11101111;
if ((buttonsCount > 8 && gamepad.buttons[8].pressed)) gamepadData &= 0b10111111;
if ((buttonsCount > 9 && gamepad.buttons[9].pressed)) gamepadData &= 0b01111111;

if (gamepadData == 0b11111111)
{
if(doGamepadReset)
{
doGamepadReset = false;
emulator.setButtonData(gamepadData)
}
}
else
{
doGamepadReset = true;
emulator.setButtonData(gamepadData);
}
}

function handleTouches(event) {
event.preventDefault();

Expand Down
40 changes: 38 additions & 2 deletions dist/console2-fullscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@
var scale = 1;
var margintop = 0;
var marginleft = 0;

var doGamepadReset = false;
var urlParams = new URLSearchParams(window.location.search);
var emulator = new metaEmulator.Emulator("emulator");
emulator.loadFromUrl(urlParams.has('bin') ? urlParams.get('bin') : "https://raw.githubusercontent.com/Rodot/Games-META/master/binaries/Solitaire/Solitaire.bin");
window.requestAnimationFrame(updateGamePadState);
var consoleelem = document.getElementById("console");
scale = setScale(consoleelem);
const dpadX = 108;
Expand Down Expand Up @@ -148,7 +149,7 @@
controls.addEventListener("mousedown", handleMouseDown);
controls.addEventListener("mousemove", handleMouseMove);
controls.addEventListener("mouseup", handleMouseUp);

function windowResize()
{
scale = setScale(consoleelem);
Expand Down Expand Up @@ -181,6 +182,41 @@
emulator.setButtonData(0b11111111);
}

function updateGamePadState() {
window.requestAnimationFrame(updateGamePadState);
if (!navigator) return;
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
if (!gamepads || gamepads.length == 0) return;
const gamepad = gamepads[0];
if(!gamepad) return;

let gamepadData = 0b11111111;
let buttonsCount = gamepad.buttons.length;
let axisCount = gamepad.axes.length;
if ((axisCount > 0 && gamepad.axes[0] < -.9) || (buttonsCount > 14 && gamepad.buttons[14].pressed)) gamepadData &= 0b11111101;
if ((axisCount > 0 && gamepad.axes[0] > .9) || (buttonsCount > 15 && gamepad.buttons[15].pressed)) gamepadData &= 0b11111011;
if ((axisCount > 1 && gamepad.axes[1] < -.9) || (buttonsCount > 12 && gamepad.buttons[12].pressed)) gamepadData &= 0b11110111;
if ((axisCount > 1 && gamepad.axes[1] > .9) || (buttonsCount > 13 && gamepad.buttons[13].pressed)) gamepadData &= 0b11111110;
if ((buttonsCount > 1 && gamepad.buttons[1].pressed) || (buttonsCount > 3 && gamepad.buttons[3].pressed)) gamepadData &= 0b11011111;
if ((buttonsCount > 0 && gamepad.buttons[0].pressed) || (buttonsCount > 2 && gamepad.buttons[2].pressed)) gamepadData &= 0b11101111;
if ((buttonsCount > 8 && gamepad.buttons[8].pressed)) gamepadData &= 0b10111111;
if ((buttonsCount > 9 && gamepad.buttons[9].pressed)) gamepadData &= 0b01111111;

if (gamepadData == 0b11111111)
{
if(doGamepadReset)
{
doGamepadReset = false;
emulator.setButtonData(gamepadData)
}
}
else
{
doGamepadReset = true;
emulator.setButtonData(gamepadData);
}
}

function handleTouches(event) {
event.preventDefault();

Expand Down
37 changes: 37 additions & 0 deletions dist/console2.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
var urlParams = new URLSearchParams(window.location.search);
var emulator = new metaEmulator.Emulator("emulator");
emulator.loadFromUrl(urlParams.has('bin') ? urlParams.get('bin') : "https://raw.githubusercontent.com/Rodot/Games-META/master/binaries/Solitaire/Solitaire.bin");
var doGamepadReset = false;
window.requestAnimationFrame(updateGamePadState);

const dpadX = 119;
const dpadY = 216;
Expand Down Expand Up @@ -148,6 +150,41 @@
emulator.setButtonData(0b11111111);
}

function updateGamePadState() {
window.requestAnimationFrame(updateGamePadState);
if (!navigator) return;
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
if (!gamepads || gamepads.length == 0) return;
const gamepad = gamepads[0];
if(!gamepad) return;

let gamepadData = 0b11111111;
let buttonsCount = gamepad.buttons.length;
let axisCount = gamepad.axes.length;
if ((axisCount > 0 && gamepad.axes[0] < -.9) || (buttonsCount > 14 && gamepad.buttons[14].pressed)) gamepadData &= 0b11111101;
if ((axisCount > 0 && gamepad.axes[0] > .9) || (buttonsCount > 15 && gamepad.buttons[15].pressed)) gamepadData &= 0b11111011;
if ((axisCount > 1 && gamepad.axes[1] < -.9) || (buttonsCount > 12 && gamepad.buttons[12].pressed)) gamepadData &= 0b11110111;
if ((axisCount > 1 && gamepad.axes[1] > .9) || (buttonsCount > 13 && gamepad.buttons[13].pressed)) gamepadData &= 0b11111110;
if ((buttonsCount > 1 && gamepad.buttons[1].pressed) || (buttonsCount > 3 && gamepad.buttons[3].pressed)) gamepadData &= 0b11011111;
if ((buttonsCount > 0 && gamepad.buttons[0].pressed) || (buttonsCount > 2 && gamepad.buttons[2].pressed)) gamepadData &= 0b11101111;
if ((buttonsCount > 8 && gamepad.buttons[8].pressed)) gamepadData &= 0b10111111;
if ((buttonsCount > 9 && gamepad.buttons[9].pressed)) gamepadData &= 0b01111111;

if (gamepadData == 0b11111111)
{
if(doGamepadReset)
{
doGamepadReset = false;
emulator.setButtonData(gamepadData)
}
}
else
{
doGamepadReset = true;
emulator.setButtonData(gamepadData);
}
}

function handleTouches(event) {
event.preventDefault();

Expand Down
38 changes: 37 additions & 1 deletion dist/emulator-fullscreen.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@

document.getElementById("start").style.display = "none";
}

var doGamepadReset = false;
var emulator = new metaEmulator.Emulator("emulator");
emulator.autoStart = false;
window.requestAnimationFrame(updateGamePadState);
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('bin')) {
if (urlParams.has('autostart'))
Expand All @@ -94,6 +95,41 @@
}
emulator.loadFromUrl(urlParams.get('bin'));
}

function updateGamePadState() {
window.requestAnimationFrame(updateGamePadState);
if (!navigator) return;
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
if (!gamepads || gamepads.length == 0) return;
const gamepad = gamepads[0];
if(!gamepad) return;

let gamepadData = 0b11111111;
let buttonsCount = gamepad.buttons.length;
let axisCount = gamepad.axes.length;
if ((axisCount > 0 && gamepad.axes[0] < -.9) || (buttonsCount > 14 && gamepad.buttons[14].pressed)) gamepadData &= 0b11111101;
if ((axisCount > 0 && gamepad.axes[0] > .9) || (buttonsCount > 15 && gamepad.buttons[15].pressed)) gamepadData &= 0b11111011;
if ((axisCount > 1 && gamepad.axes[1] < -.9) || (buttonsCount > 12 && gamepad.buttons[12].pressed)) gamepadData &= 0b11110111;
if ((axisCount > 1 && gamepad.axes[1] > .9) || (buttonsCount > 13 && gamepad.buttons[13].pressed)) gamepadData &= 0b11111110;
if ((buttonsCount > 1 && gamepad.buttons[1].pressed) || (buttonsCount > 3 && gamepad.buttons[3].pressed)) gamepadData &= 0b11011111;
if ((buttonsCount > 0 && gamepad.buttons[0].pressed) || (buttonsCount > 2 && gamepad.buttons[2].pressed)) gamepadData &= 0b11101111;
if ((buttonsCount > 8 && gamepad.buttons[8].pressed)) gamepadData &= 0b10111111;
if ((buttonsCount > 9 && gamepad.buttons[9].pressed)) gamepadData &= 0b01111111;

if (gamepadData == 0b11111111)
{
if(doGamepadReset)
{
doGamepadReset = false;
emulator.setButtonData(gamepadData)
}
}
else
{
doGamepadReset = true;
emulator.setButtonData(gamepadData);
}
}
</script>
</body>

Expand Down
38 changes: 37 additions & 1 deletion dist/emulator.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@
<script src="url-search-params.js"></script>

<script>
var doGamepadReset = false;
var emulator = new metaEmulator.Emulator("emulator");
emulator.autoStart = false;

window.requestAnimationFrame(updateGamePadState);
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('bin')) {
emulator.loadFromUrl(urlParams.get('bin'));
Expand All @@ -73,6 +74,41 @@

document.getElementById("start").style.display = "none";
}

function updateGamePadState() {
window.requestAnimationFrame(updateGamePadState);
if (!navigator) return;
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
if (!gamepads || gamepads.length == 0) return;
const gamepad = gamepads[0];
if(!gamepad) return;

let gamepadData = 0b11111111;
let buttonsCount = gamepad.buttons.length;
let axisCount = gamepad.axes.length;
if ((axisCount > 0 && gamepad.axes[0] < -.9) || (buttonsCount > 14 && gamepad.buttons[14].pressed)) gamepadData &= 0b11111101;
if ((axisCount > 0 && gamepad.axes[0] > .9) || (buttonsCount > 15 && gamepad.buttons[15].pressed)) gamepadData &= 0b11111011;
if ((axisCount > 1 && gamepad.axes[1] < -.9) || (buttonsCount > 12 && gamepad.buttons[12].pressed)) gamepadData &= 0b11110111;
if ((axisCount > 1 && gamepad.axes[1] > .9) || (buttonsCount > 13 && gamepad.buttons[13].pressed)) gamepadData &= 0b11111110;
if ((buttonsCount > 1 && gamepad.buttons[1].pressed) || (buttonsCount > 3 && gamepad.buttons[3].pressed)) gamepadData &= 0b11011111;
if ((buttonsCount > 0 && gamepad.buttons[0].pressed) || (buttonsCount > 2 && gamepad.buttons[2].pressed)) gamepadData &= 0b11101111;
if ((buttonsCount > 8 && gamepad.buttons[8].pressed)) gamepadData &= 0b10111111;
if ((buttonsCount > 9 && gamepad.buttons[9].pressed)) gamepadData &= 0b01111111;

if (gamepadData == 0b11111111)
{
if(doGamepadReset)
{
doGamepadReset = false;
emulator.setButtonData(gamepadData)
}
}
else
{
doGamepadReset = true;
emulator.setButtonData(gamepadData);
}
}
</script>
</body>

Expand Down
40 changes: 39 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ <h2>Upload Game</h2>
<script src="meta-emulator.js"></script>

<script>
var doGamepadReset = false;
var emulator = new metaEmulator.Emulator("emulator");

window.requestAnimationFrame(updateGamePadState);

document.getElementById("file-upload").onchange = function() {
if (this.files.length == 1) {
var f = this.files[0];
Expand Down Expand Up @@ -215,6 +217,42 @@ <h2>Upload Game</h2>
document.addEventListener('keydown', handler);
}

function updateGamePadState() {
window.requestAnimationFrame(updateGamePadState);
if (!navigator) return;
const gamepads = navigator.getGamepads ? navigator.getGamepads() : (navigator.webkitGetGamepads ? navigator.webkitGetGamepads() : []);
if (!gamepads || gamepads.length == 0) return;
const gamepad = gamepads[0];
if(!gamepad) return;


let gamepadData = 0b11111111;
let buttonsCount = gamepad.buttons.length;
let axisCount = gamepad.axes.length;
if ((axisCount > 0 && gamepad.axes[0] < -.9) || (buttonsCount > 14 && gamepad.buttons[14].pressed)) gamepadData &= 0b11111101;
if ((axisCount > 0 && gamepad.axes[0] > .9) || (buttonsCount > 15 && gamepad.buttons[15].pressed)) gamepadData &= 0b11111011;
if ((axisCount > 1 && gamepad.axes[1] < -.9) || (buttonsCount > 12 && gamepad.buttons[12].pressed)) gamepadData &= 0b11110111;
if ((axisCount > 1 && gamepad.axes[1] > .9) || (buttonsCount > 13 && gamepad.buttons[13].pressed)) gamepadData &= 0b11111110;
if ((buttonsCount > 1 && gamepad.buttons[1].pressed) || (buttonsCount > 3 && gamepad.buttons[3].pressed)) gamepadData &= 0b11011111;
if ((buttonsCount > 0 && gamepad.buttons[0].pressed) || (buttonsCount > 2 && gamepad.buttons[2].pressed)) gamepadData &= 0b11101111;
if ((buttonsCount > 8 && gamepad.buttons[8].pressed)) gamepadData &= 0b10111111;
if ((buttonsCount > 9 && gamepad.buttons[9].pressed)) gamepadData &= 0b01111111;

if (gamepadData == 0b11111111)
{
if(doGamepadReset)
{
doGamepadReset = false;
emulator.setButtonData(gamepadData)
}
}
else
{
doGamepadReset = true;
emulator.setButtonData(gamepadData);
}
}

</script>
</body>

Expand Down