From: Josh Simmons Date: Mon, 13 May 2024 21:25:55 +0000 (+0200) Subject: shark: Use match for key bindings X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=52a481747e5ee74b9fb80e2b4fc5ea13e3ad9fc1;p=josh%2Fnarcissus shark: Use match for key bindings --- diff --git a/title/shark/src/main.rs b/title/shark/src/main.rs index 9e3d2c8..37aef79 100644 --- a/title/shark/src/main.rs +++ b/title/shark/src/main.rs @@ -1217,46 +1217,23 @@ pub fn main() { continue 'poll_events; } - if key == Key::Escape { - break 'main; - } - - { - let value = match pressed { - PressedState::Released => 0.0, - PressedState::Pressed => 1.0, - }; - - if key == Key::Left || key == Key::A { - action_queue.push(ActionEvent { - action: Action::Left, - value, - }) - } - if key == Key::Right || key == Key::D { - action_queue.push(ActionEvent { - action: Action::Right, - value, - }) - } - if key == Key::Up || key == Key::W { - action_queue.push(ActionEvent { - action: Action::Up, - value, - }) - } - if key == Key::Down || key == Key::S { - action_queue.push(ActionEvent { - action: Action::Down, - value, - }) - } - if key == Key::Space { - action_queue.push(ActionEvent { - action: Action::Damage, - value, - }) - } + let action = match key { + Key::Left | Key::A => Some(Action::Left), + Key::Right | Key::D => Some(Action::Right), + Key::Up | Key::W => Some(Action::Up), + Key::Down | Key::S => Some(Action::Down), + Key::Space => Some(Action::Damage), + Key::Escape => break 'main, + _ => None, + }; + + let value = match pressed { + PressedState::Released => 0.0, + PressedState::Pressed => 1.0, + }; + + if let Some(action) = action { + action_queue.push(ActionEvent { action, value }) } } Quit => {