nes_rust/
default_input.rs1use std::collections::VecDeque;
2
3use input::Input;
4use button;
5
6pub struct DefaultInput {
7 events: VecDeque<(button::Button, button::Event)>
8}
9
10impl DefaultInput {
11 pub fn new() -> Self {
12 DefaultInput {
13 events: VecDeque::<(button::Button, button::Event)>::new()
14 }
15 }
16}
17
18impl Input for DefaultInput {
19 fn get_input(&mut self) -> Option<(button::Button, button::Event)> {
20 match self.events.len() > 0 {
21 true => self.events.pop_front(),
22 false => None
23 }
24 }
25
26 fn press(&mut self, button: button::Button) {
27 self.events.push_back((button, button::Event::Press));
28 }
29
30 fn release(&mut self, button: button::Button) {
31 self.events.push_back((button, button::Event::Release));
32 }
33}