improved change color handling

This commit is contained in:
e7d 2016-11-05 22:51:49 +01:00
parent 816e236b73
commit fd5de54d1f

View File

@ -23,7 +23,9 @@ var gamepadIdentifiers = {
var activeGamepadIndex = null; var activeGamepadIndex = null;
var activeGamepadType = null; var activeGamepadType = null;
var activeGamepadIdentifier = null; var activeGamepadIdentifier = null;
var activeGamepadColor = null; var activeGamepadColorIndex = null;
var activeGamepadColorName = null;
var activeGamepadZoomLevel = 1;
var mapping = { var mapping = {
buttons: [], buttons: [],
axes: [] axes: []
@ -194,14 +196,31 @@ function updateVisualStatus() {
} }
function changeGamepadColor(gamepadColor) { function changeGamepadColor(gamepadColor) {
if (!! gamepadColor) { if (! activeGamepadIdentifier) {
activeGamepadColor = gamepadColor; return;
} else {
activeGamepadColor++;
if (activeGamepadColor > activeGamepadIdentifier.colors.length - 1) {
activeGamepadColor = 0;
} }
if (!! gamepadColor) {
if (! isNaN(parseInt(gamepadColor))) {
activeGamepadColorIndex = gamepadColor;
activeGamepadColorName = activeGamepadIdentifier.colors[activeGamepadColorIndex];
} else {
activeGamepadColorName = gamepadColor;
activeGamepadColorIndex = 0;
for (var gamepadColorName in activeGamepadIdentifier.colors) {
if (activeGamepadColorName === gamepadColorName) {
break;
}
activeGamepadColorIndex++;
}
}
} else {
activeGamepadColorIndex++;
if (activeGamepadColorIndex > activeGamepadIdentifier.colors.length - 1) {
activeGamepadColorIndex = 0;
}
activeGamepadColorName = activeGamepadIdentifier.colors[activeGamepadColorIndex];
} }
$gamepad.attr('data-color', activeGamepadIdentifier.colors[activeGamepadColor]); $gamepad.attr('data-color', activeGamepadIdentifier.colors[activeGamepadColor]);