blob: 343967d4100df8cc7a16c3ded9f28bfa5df4f356 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
use std::sync::{Arc, Mutex};
use bevy::{prelude::*, utils::HashSet};
use crossterm::event::{Event, KeyCode};
#[derive(Resource, Default)]
pub struct TerminalInput {
pressed_keys: HashSet<KeyCode>,
released_keys: HashSet<KeyCode>,
}
impl TerminalInput {
pub fn is_pressed(&self, code: KeyCode) -> bool {
self.pressed_keys.contains(&code)
}
pub fn is_released(&self, code: KeyCode) -> bool {
self.released_keys.contains(&code)
}
pub(super) fn press(&mut self, code: KeyCode) {
if !self.is_pressed(code) {
self.pressed_keys.insert(code);
}
}
pub(super) fn release(&mut self, code: KeyCode) {
if self.is_pressed(code) {
self.pressed_keys.remove(&code);
}
if !self.is_released(code) {
self.released_keys.insert(code);
}
}
}
#[derive(Resource, Default)]
pub(super) struct EventQueue(pub(super) Arc<Mutex<Vec<Event>>>);
|