From 646db8328611f21a5850cc9834b6c72bfdf0c829 Mon Sep 17 00:00:00 2001 From: Silas Bartha Date: Fri, 26 Apr 2024 01:27:13 -0400 Subject: Initial Commit --- src/resources.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/resources.rs (limited to 'src/resources.rs') diff --git a/src/resources.rs b/src/resources.rs new file mode 100644 index 0000000..343967d --- /dev/null +++ b/src/resources.rs @@ -0,0 +1,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, + released_keys: HashSet, +} + +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>>); -- cgit v1.2.3