Skip to content

Commit

Permalink
feat: simplified code by using std::visit
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed Mar 28, 2024
1 parent 20dad44 commit a1619f8
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/platform/linux/inputtino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,27 +533,12 @@ namespace platf {
return;
}

if (std::holds_alternative<inputtino::PS5Joypad>(*gamepad->joypad)) {
auto &gc = std::get<inputtino::PS5Joypad>(*gamepad->joypad);
gc.set_pressed_buttons(gamepad_state.buttonFlags);
gc.set_stick(inputtino::Joypad::LS, gamepad_state.lsX, gamepad_state.lsY);
gc.set_stick(inputtino::Joypad::RS, gamepad_state.rsX, gamepad_state.rsY);
gc.set_triggers(gamepad_state.lt, gamepad_state.rt);
}
else if (std::holds_alternative<inputtino::XboxOneJoypad>(*gamepad->joypad)) {
auto &gc = std::get<inputtino::XboxOneJoypad>(*gamepad->joypad);
std::visit([gamepad_state](inputtino::Joypad & gc){
gc.set_pressed_buttons(gamepad_state.buttonFlags);
gc.set_stick(inputtino::Joypad::LS, gamepad_state.lsX, gamepad_state.lsY);
gc.set_stick(inputtino::Joypad::RS, gamepad_state.rsX, gamepad_state.rsY);
gc.set_triggers(gamepad_state.lt, gamepad_state.rt);
}
else if (std::holds_alternative<inputtino::SwitchJoypad>(*gamepad->joypad)) {
auto &gc = std::get<inputtino::SwitchJoypad>(*gamepad->joypad);
gc.set_pressed_buttons(gamepad_state.buttonFlags);
gc.set_stick(inputtino::Joypad::LS, gamepad_state.lsX, gamepad_state.lsY);
gc.set_stick(inputtino::Joypad::RS, gamepad_state.rsX, gamepad_state.rsY);
gc.set_triggers(gamepad_state.lt, gamepad_state.rt);
}
}, *gamepad->joypad);

Check warning on line 541 in src/platform/linux/inputtino.cpp

View check run for this annotation

Codecov / codecov/patch

src/platform/linux/inputtino.cpp#L537-L541

Added lines #L537 - L541 were not covered by tests
}

void
Expand Down

0 comments on commit a1619f8

Please sign in to comment.