use std::collections::HashMap;

use glium::glutin;
use glutin::event::*;

pub use glutin::event::VirtualKeyCode as Key;

pub struct DeviceManager {
    key_map: HashMap<Key, ElementState>
}

impl DeviceManager {
    pub fn handle(&mut self, event: DeviceEvent) {
	match event {
	    DeviceEvent::Key(
		KeyboardInput{ virtual_keycode: Some(keycode), state, .. }
	    ) => self.update(keycode, state),
	    _ => (),
	};
    }
    pub fn new() -> Self {
	DeviceManager {
	    key_map: HashMap::new(),
	}
    }
    pub fn is_pressed(&self, key: &Key) -> bool {
	matches!(self.key_map.get(key), Some(ElementState::Pressed))
    }
    fn update(&mut self, key: Key, state: ElementState) {
	self.key_map.insert(key, state);
    }
	
}
