summaryrefslogtreecommitdiff
path: root/src/input.rs
blob: c86daf49063176ae0beb1b3dc85086f9361e1db8 (plain)
use crossterm::event::KeyCode;
use rustc_hash::FxHashSet;

#[derive(Debug, Default, Clone)]
pub struct InputManager {
	pressed_keys: FxHashSet<KeyCode>,
}

impl InputManager {
	pub fn new() -> Self {
		Self {
			pressed_keys: FxHashSet::default(),
		}
	}

	pub fn press_key(&mut self, key_code: KeyCode) {
		self.pressed_keys.insert(key_code);
	}

	pub fn reset_next_frame(&mut self) {
		self.pressed_keys.clear();
	}

	pub fn is_key_pressed_this_frame(&self, key_code: KeyCode) -> bool {
		self.pressed_keys.contains(&key_code)
	}
}