Skip to main content

starbloom_base/
input.rs

1use std::collections::hash_map::HashMap;
2
3use bevy_ecs::prelude::*;
4use egor::input::*;
5use log::*;
6
7const TRACKED_KEYS: [KeyCode; 4] = [
8    KeyCode::ArrowUp,
9    KeyCode::ArrowDown,
10    KeyCode::ArrowLeft,
11    KeyCode::ArrowRight,
12];
13
14#[derive(Default, Resource)]
15pub struct InputCtx {
16    key_states: HashMap<KeyCode, bool>,
17}
18
19impl InputCtx {
20    pub fn key_held(&self, key: KeyCode) -> bool {
21        *self.key_states.get(&key).unwrap_or(&false)
22    }
23
24    pub fn update(&mut self, input: &Input) {
25        for key in TRACKED_KEYS {
26            self.key_states.insert(key, input.key_held(key));
27        }
28    }
29}