joypad clear buttons fn

This commit is contained in:
Alex Janka 2023-02-22 10:09:40 +11:00
parent 788afa49d4
commit a9886a773a

View file

@ -63,18 +63,7 @@ impl Joypad {
gamepads: ConnectedGamepadsIterator, gamepads: ConnectedGamepadsIterator,
) -> bool { ) -> bool {
let old = *self; let old = *self;
*self = Joypad { self.clear_buttons();
sel_action: self.sel_action,
sel_direction: self.sel_direction,
down: false,
up: false,
left: false,
right: false,
start: false,
select: false,
b: false,
a: false,
};
for (_, pad) in gamepads { for (_, pad) in gamepads {
self.down |= pad.is_pressed(Button::DPadDown); self.down |= pad.is_pressed(Button::DPadDown);
self.up |= pad.is_pressed(Button::DPadUp); self.up |= pad.is_pressed(Button::DPadUp);
@ -95,6 +84,17 @@ impl Joypad {
self.b |= keys.contains(&Key::Semicolon); self.b |= keys.contains(&Key::Semicolon);
*self != old *self != old
} }
fn clear_buttons(&mut self) {
self.down = false;
self.up = false;
self.left = false;
self.right = false;
self.start = false;
self.select = false;
self.a = false;
self.b = false;
}
} }
impl Default for Joypad { impl Default for Joypad {