add an option to change background color

This commit is contained in:
e7d 2019-05-07 14:58:39 +02:00
parent 813df6f4ca
commit 81f8bd8a95
2 changed files with 30 additions and 1 deletions

View File

@ -43,6 +43,10 @@
<th><kbd>0</kbd></th>
<td>Reset gamepad zoom</td>
</tr>
<tr>
<th><kbd>B</kbd></th>
<td>Change background color</td>
</tr>
<tr>
<th><kbd>C</kbd></th>
<td>Change active gamepad color</td>

View File

@ -11,11 +11,15 @@ class Gamepad {
this.gamepadDemo = new GamepadDemo(this);
// cached DOM references
this.$body = $('body');
this.$gamepad = $('.gamepad');
this.$nogamepad = $('.no-gamepad');
this.$debug = $('.debug');
this.$help = $('.help');
this.backgroundColors = ['transparent', 'dimgrey', 'black', 'green', 'magenta'];
this.backgroundColorIndex = 0;
// gamepad collection default values
this.gamepads = {};
this.gamepadIdentifiers = {
@ -150,6 +154,9 @@ class Gamepad {
case "Escape":
this.removeGamepad(true);
break;
case "KeyB":
this.changeBackgroundColor();
break;
case "KeyC":
this.changeGamepadColor();
break;
@ -436,6 +443,25 @@ class Gamepad {
}
}
/**
* Changes the background color
*
* @param {any} backgroundColor
*/
changeBackgroundColor(backgroundColor) {
if ('undefined' === typeof gamepadColor) {
this.backgroundColorIndex++;
if (this.backgroundColorIndex > this.backgroundColors.length - 1) {
this.backgroundColorIndex = 0;
}
} else {
this.backgroundColorIndex = backgroundColor;
}
this.$body.css('background', this.backgroundColors[this.backgroundColorIndex]);
}
/**
* Changes the active gamepad color
*
@ -447,7 +473,6 @@ class Gamepad {
return;
}
const activeGamepad = this.getActiveGamepad();
if ('undefined' === typeof gamepadColor) {
// no color was specified, load the next one in list
this.activeGamepadColorIndex++;