add an option to change background color
This commit is contained in:
parent
813df6f4ca
commit
81f8bd8a95
@ -43,6 +43,10 @@
|
|||||||
<th><kbd>0</kbd></th>
|
<th><kbd>0</kbd></th>
|
||||||
<td>Reset gamepad zoom</td>
|
<td>Reset gamepad zoom</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th><kbd>B</kbd></th>
|
||||||
|
<td>Change background color</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th><kbd>C</kbd></th>
|
<th><kbd>C</kbd></th>
|
||||||
<td>Change active gamepad color</td>
|
<td>Change active gamepad color</td>
|
||||||
|
@ -11,11 +11,15 @@ class Gamepad {
|
|||||||
this.gamepadDemo = new GamepadDemo(this);
|
this.gamepadDemo = new GamepadDemo(this);
|
||||||
|
|
||||||
// cached DOM references
|
// cached DOM references
|
||||||
|
this.$body = $('body');
|
||||||
this.$gamepad = $('.gamepad');
|
this.$gamepad = $('.gamepad');
|
||||||
this.$nogamepad = $('.no-gamepad');
|
this.$nogamepad = $('.no-gamepad');
|
||||||
this.$debug = $('.debug');
|
this.$debug = $('.debug');
|
||||||
this.$help = $('.help');
|
this.$help = $('.help');
|
||||||
|
|
||||||
|
this.backgroundColors = ['transparent', 'dimgrey', 'black', 'green', 'magenta'];
|
||||||
|
this.backgroundColorIndex = 0;
|
||||||
|
|
||||||
// gamepad collection default values
|
// gamepad collection default values
|
||||||
this.gamepads = {};
|
this.gamepads = {};
|
||||||
this.gamepadIdentifiers = {
|
this.gamepadIdentifiers = {
|
||||||
@ -150,6 +154,9 @@ class Gamepad {
|
|||||||
case "Escape":
|
case "Escape":
|
||||||
this.removeGamepad(true);
|
this.removeGamepad(true);
|
||||||
break;
|
break;
|
||||||
|
case "KeyB":
|
||||||
|
this.changeBackgroundColor();
|
||||||
|
break;
|
||||||
case "KeyC":
|
case "KeyC":
|
||||||
this.changeGamepadColor();
|
this.changeGamepadColor();
|
||||||
break;
|
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
|
* Changes the active gamepad color
|
||||||
*
|
*
|
||||||
@ -447,7 +473,6 @@ class Gamepad {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeGamepad = this.getActiveGamepad();
|
|
||||||
if ('undefined' === typeof gamepadColor) {
|
if ('undefined' === typeof gamepadColor) {
|
||||||
// no color was specified, load the next one in list
|
// no color was specified, load the next one in list
|
||||||
this.activeGamepadColorIndex++;
|
this.activeGamepadColorIndex++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user