Simplify InputDefault::joy_axis code by using float instead of struct JoyAxis

This commit is contained in:
Marcel Admiraal 2021-12-25 08:45:37 +00:00
parent 4cadd50f0e
commit 949ea2b326
16 changed files with 73 additions and 141 deletions

View file

@ -597,24 +597,16 @@ void OS_JavaScript::process_joypads() {
continue;
}
for (int b = 0; b < s_btns_num; b++) {
float value = s_btns[b];
// Buttons 6 and 7 in the standard mapping need to be
// axis to be handled as JOY_ANALOG by Godot.
if (s_standard && (b == 6 || b == 7)) {
InputDefault::JoyAxis joy_axis;
joy_axis.min = 0;
joy_axis.value = value;
int a = b == 6 ? JOY_ANALOG_L2 : JOY_ANALOG_R2;
input->joy_axis(idx, a, joy_axis);
input->joy_axis(idx, b, s_btns[b]);
} else {
input->joy_button(idx, b, value);
input->joy_button(idx, b, s_btns[b]);
}
}
for (int a = 0; a < s_axes_num; a++) {
InputDefault::JoyAxis joy_axis;
joy_axis.min = -1;
joy_axis.value = s_axes[a];
input->joy_axis(idx, a, joy_axis);
input->joy_axis(idx, a, s_axes[a]);
}
}
}