added zoom handling
This commit is contained in:
parent
fd5de54d1f
commit
c0c005221a
@ -33,7 +33,7 @@ var mapping = {
|
|||||||
|
|
||||||
window.addEventListener("gamepadconnected", onGamepadConnect);
|
window.addEventListener("gamepadconnected", onGamepadConnect);
|
||||||
window.addEventListener("gamepaddisconnected", onGamepadDisconnect);
|
window.addEventListener("gamepaddisconnected", onGamepadDisconnect);
|
||||||
window.addEventListener("keypress", onKeyPress);
|
window.addEventListener("keydown", onKeyDown);
|
||||||
|
|
||||||
function onGamepadConnect(e) {
|
function onGamepadConnect(e) {
|
||||||
addGamepad(e.gamepad);
|
addGamepad(e.gamepad);
|
||||||
@ -43,16 +43,23 @@ function onGamepadDisconnect(e) {
|
|||||||
removeGamepad(e.gamepad.index);
|
removeGamepad(e.gamepad.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onKeyPress(e) {
|
function onKeyDown(e) {
|
||||||
switch (e.key) {
|
switch (e.code) {
|
||||||
case "d":
|
case "Delete":
|
||||||
case "D":
|
case "Escape":
|
||||||
removeGamepad(activeGamepadIndex);
|
removeGamepad(activeGamepadIndex);
|
||||||
break;
|
break;
|
||||||
case "c":
|
case "KeyC":
|
||||||
case "C":
|
|
||||||
changeGamepadColor();
|
changeGamepadColor();
|
||||||
break;
|
break;
|
||||||
|
case "NumpadAdd":
|
||||||
|
case "Equal":
|
||||||
|
changeZoom("+");
|
||||||
|
break;
|
||||||
|
case "NumpadSubtract":
|
||||||
|
case "Minus":
|
||||||
|
changeZoom("-");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +113,7 @@ function mapGamepad(gamepad) {
|
|||||||
if (gamepadIdentifiers[gamepadType].id.test(gamepad.id)) {
|
if (gamepadIdentifiers[gamepadType].id.test(gamepad.id)) {
|
||||||
activeGamepadType = gamepadType;
|
activeGamepadType = gamepadType;
|
||||||
activeGamepadIdentifier = gamepadIdentifiers[gamepadType];
|
activeGamepadIdentifier = gamepadIdentifiers[gamepadType];
|
||||||
activeGamepadColor = 0;
|
activeGamepadColorIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +127,16 @@ function mapGamepad(gamepad) {
|
|||||||
if ($.urlParam('color')) {
|
if ($.urlParam('color')) {
|
||||||
changeGamepadColor($.urlParam('color'));
|
changeGamepadColor($.urlParam('color'));
|
||||||
}
|
}
|
||||||
|
if ($.urlParam('c')) {
|
||||||
|
changeGamepadColor($.urlParam('c'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($.urlParam('zoom')) {
|
||||||
|
changeZoom($.urlParam('zoom'));
|
||||||
|
}
|
||||||
|
if ($.urlParam('z')) {
|
||||||
|
changeZoom($.urlParam('z'));
|
||||||
|
}
|
||||||
|
|
||||||
mapping.buttons = [];
|
mapping.buttons = [];
|
||||||
for (var buttonIndex = 0; buttonIndex < gamepad.buttons.length; buttonIndex++) {
|
for (var buttonIndex = 0; buttonIndex < gamepad.buttons.length; buttonIndex++) {
|
||||||
@ -223,5 +240,35 @@ function changeGamepadColor(gamepadColor) {
|
|||||||
activeGamepadColorName = activeGamepadIdentifier.colors[activeGamepadColorIndex];
|
activeGamepadColorName = activeGamepadIdentifier.colors[activeGamepadColorIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
$gamepad.attr('data-color', activeGamepadIdentifier.colors[activeGamepadColor]);
|
$gamepad.attr('data-color', activeGamepadColorName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeZoom(zoomLevel) {
|
||||||
|
if (! activeGamepadIdentifier) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! zoomLevel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('+' === zoomLevel && activeGamepadZoomLevel < 2) {
|
||||||
|
activeGamepadZoomLevel += 0.1;
|
||||||
|
}
|
||||||
|
if ('-' === zoomLevel && activeGamepadZoomLevel > 0.2) {
|
||||||
|
activeGamepadZoomLevel -= 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isNaN(zoomLevel = parseFloat(zoomLevel))) {
|
||||||
|
activeGamepadZoomLevel = zoomLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
// hack: fix floatjs float issues
|
||||||
|
activeGamepadZoomLevel = +activeGamepadZoomLevel.toFixed(1);
|
||||||
|
|
||||||
|
$gamepad.css('transform', 'translate(-50%, -50%) scale(' + activeGamepadZoomLevel + ', ' + activeGamepadZoomLevel + ')');
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleHelp(zoomLevel) {
|
||||||
|
$help.toggleClass('active');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user