add a triggers meter toggle

This commit is contained in:
e7d 2020-08-19 12:01:06 +02:00
parent 56d6f98922
commit 38244961d3
No known key found for this signature in database
GPG Key ID: F320BE007C0B8881
6 changed files with 74 additions and 42 deletions

View File

@ -99,6 +99,7 @@ body {
font-size: 0.9em;
left: 50%;
min-width: 400px;
width: 600px;
padding: 20px;
position: absolute;
top: 50%;
@ -148,21 +149,23 @@ body {
}
kbd {
display: inline;
display: inline-block;
min-width: 1em;
padding: .2em .3em;
margin: 0 .2em;
font: normal 1em monospace;
text-align: center;
text-decoration: none;
-moz-border-radius: .3em;
-moz-user-select: none;
-webkit-border-radius: .3em;
-webkit-user-select: none;
border-radius: .3em;
border: none;
cursor: default;
-moz-user-select: none;
-webkit-user-select: none;
display: inline-block;
display: inline;
font: normal 1em monospace;
margin: 0 .2em;
min-width: 1em;
padding: .2em .6em;
text-align: center;
text-decoration: none;
font-weight: bold;
font-size: 14px;
user-select: none;
}

View File

@ -139,6 +139,10 @@
<th><kbd>H</kbd></th>
<td>Toggle this help menu</td>
</tr>
<tr>
<th><kbd>T</kbd></th>
<td>Toggle triggers meter mode</td>
</tr>
<tr>
<th><kbd>Delete</kbd>, <kbd>Escape</kbd></th>
<td>Clear active gamepad</td>

View File

@ -64,6 +64,7 @@ class Gamepad {
this.backgroundColorIndex = 0;
this.colorIndex = null;
this.colorName = null;
this.triggersMeter = false;
this.zoomMode = "manual";
this.zoomLevel = 1;
this.mapping = {
@ -232,6 +233,9 @@ class Gamepad {
case "KeyH":
this.toggleHelp();
break;
case "KeyT":
this.toggleTriggersMeter();
break;
case "NumpadAdd":
case "Equal":
this.changeZoom("+");
@ -741,23 +745,6 @@ class Gamepad {
}
}
/**
* Toggles the on-screen help message
*/
toggleHelp() {
this.$help.toggleClass("active");
// save statistics
if (!!window.ga) {
ga("send", "event", {
eventCategory: "Gamepad",
eventAction: "toggle-help",
eventLabel: "Toggle Help",
eventValue: this.$help.is("active"),
});
}
}
/**
* Toggles the debug template for the active gamepad, if any
*/
@ -781,6 +768,31 @@ class Gamepad {
// remap current gamepad
this.map(this.index);
}
/**
* Toggles the on-screen help message
*/
toggleHelp() {
this.$help.toggleClass("active");
// save statistics
if (!!window.ga) {
ga("send", "event", {
eventCategory: "Gamepad",
eventAction: "toggle-help",
eventLabel: "Toggle Help",
eventValue: this.$help.is("active"),
});
}
}
/**
* Toggles the triggers meter display
*/
toggleTriggersMeter() {
this.triggersMeter = !this.triggersMeter;
this.$gamepad[this.triggersMeter ? 'addClass' : 'removeClass']('triggers-meter');
}
}
window.gamepad = new Gamepad();

View File

@ -1,15 +1,22 @@
gamepad.updateButton = function($button) {
gamepad.updateButton = function ($button) {
const value = parseFloat($button.attr("data-value"), 10);
if ($button.is(".trigger")) {
$button.css({
// "opacity": `${(value) * 100}%`,
"clip-path": `inset(${(1 - value) * 100}% 0px 0px 0pc)`
});
$button.css(
gamepad.triggersMeter
? {
opacity: 1,
"clip-path": `inset(${(1 - value) * 100}% 0px 0px 0pc)`,
}
: {
opacity: `${value * 100}%`,
"clip-path": "none",
}
);
}
};
gamepad.updateAxis = function($axis) {
gamepad.updateAxis = function ($axis) {
const axisX = $axis.attr("data-value-x");
const axisY = $axis.attr("data-value-y");
@ -20,7 +27,7 @@ gamepad.updateAxis = function($axis) {
transform: `rotateX(${-parseFloat(
axisY * 30,
8
)}deg) rotateY(${parseFloat(axisX * 30, 8)}deg)`
)}deg) rotateY(${parseFloat(axisX * 30, 8)}deg)`,
});
}
};

View File

@ -136,7 +136,6 @@
background: url(buttons.svg);
width: 53px;
height: 53px;
/* display: none; */
}
#gamepad .button[data-pressed="true"] {

View File

@ -1,15 +1,22 @@
gamepad.updateButton = function($button) {
gamepad.updateButton = function ($button) {
const value = parseFloat($button.attr("data-value"), 10);
if ($button.is(".trigger")) {
$button.css({
// "opacity": `${(value) * 100}%`,
"clip-path": `inset(${(1 - value) * 100}% 0px 0px 0pc)`
});
$button.css(
gamepad.triggersMeter
? {
opacity: 1,
"clip-path": `inset(${(1 - value) * 100}% 0px 0px 0pc)`,
}
: {
opacity: `${value * 100}%`,
"clip-path": "none",
}
);
}
};
gamepad.updateAxis = function($axis) {
gamepad.updateAxis = function ($axis) {
const axisX = $axis.attr("data-value-x");
const axisY = $axis.attr("data-value-y");
@ -20,7 +27,7 @@ gamepad.updateAxis = function($axis) {
transform: `rotateX(${-parseFloat(
axisY * 30,
8
)}deg) rotateY(${parseFloat(axisX * 30, 8)}deg)`
)}deg) rotateY(${parseFloat(axisX * 30, 8)}deg)`,
});
}
};