use std::{collections::HashSet, hash::Hash}; pub struct Input { pressed: HashSet, just_pressed: HashSet, just_released: HashSet, } impl Default for Input { fn default() -> Self { Self { pressed: Default::default(), just_pressed: Default::default(), just_released: Default::default(), } } } impl Input where T: Copy + Eq + Hash, { pub fn press(&mut self, input: T) { if !self.pressed(input) { self.just_pressed.insert(input); } self.pressed.insert(input); } pub fn pressed(&self, input: T) -> bool { self.pressed.contains(&input) } pub fn release(&mut self, input: T) { self.pressed.remove(&input); self.just_released.insert(input); } pub fn just_pressed(&self, input: T) -> bool { self.just_pressed.contains(&input) } pub fn just_released(&self, input: T) -> bool { self.just_released.contains(&input) } pub fn update(&mut self) { self.just_pressed.clear(); self.just_released.clear(); } }