summaryrefslogtreecommitdiffstats
path: root/platform
diff options
context:
space:
mode:
authorLisandro Lorea <lisandrolorea@gmail.com>2024-07-25 00:35:05 -0300
committerRémi Verschelde <rverschelde@gmail.com>2024-09-17 08:57:45 +0200
commitd92f9017c67ae93a51ef6796520ecc8e12d09d2e (patch)
tree9ef3fae2d924536b0313b8f4d9bc9c84997bf5ed /platform
parent34251cf5b3a16e65ac4c0322bdee722699865f7c (diff)
downloadredot-engine-d92f9017c67ae93a51ef6796520ecc8e12d09d2e.tar.gz
Fix gamepad triggers not working on web exports
Fixes #81758 DisplayServerWeb::process_joypads handles buttons 6 and 7 of the HTML5 Standard Gamepad as a special case by doing: `input->joy_axis(idx, (JoyAxis)b, s_btns[b]);` This doesn't work because there is no JoyAxis 6 or 7 in the enum To fix this we use JoyAxis::TRIGGER_LEFT and TRIGGER_RIGHT for button 6 and 7 However since we are now lying to input->joy_axis we also need to lie in the mappings for the standard gamepad in godotcontrollersdb.txt, otherwise input->joy_axis will try to find a mapping to axis 4(LT) and axis 5(RT) that's not defined. Therefore we set lefttrigger to +a4 and righttrigger to +a5 in the mapping, to match what we are actually sending. A cleaner, and more involved fix to this would be modifying input->joy_button so that it can handle analog buttons and map them to axes preserving their value instead of converting to boolean (cherry picked from commit 9dd372f3164f3daf01c02d1f4ba304ffde47f394)
Diffstat (limited to 'platform')
-rw-r--r--platform/web/display_server_web.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp
index 40de4e523b..4e55cc137a 100644
--- a/platform/web/display_server_web.cpp
+++ b/platform/web/display_server_web.cpp
@@ -902,8 +902,10 @@ void DisplayServerWeb::process_joypads() {
for (int b = 0; b < s_btns_num; b++) {
// Buttons 6 and 7 in the standard mapping need to be
// axis to be handled as JoyAxis::TRIGGER by Godot.
- if (s_standard && (b == 6 || b == 7)) {
- input->joy_axis(idx, (JoyAxis)b, s_btns[b]);
+ if (s_standard && (b == 6)) {
+ input->joy_axis(idx, JoyAxis::TRIGGER_LEFT, s_btns[b]);
+ } else if (s_standard && (b == 7)) {
+ input->joy_axis(idx, JoyAxis::TRIGGER_RIGHT, s_btns[b]);
} else {
input->joy_button(idx, (JoyButton)b, s_btns[b]);
}