aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Silas Bartha <[email protected]>2024-06-05 13:40:23 -0400
committerLibravatar Silas Bartha <[email protected]>2024-06-05 13:40:23 -0400
commitc30929cbd3302ddb869d25e7ea2bd151a4cdb91e (patch)
treec5cb54be35806a98843c317822ca80f7eba0bc49
parent1addc01cacaf148547d999be0e4f964eabeed834 (diff)
Ensured key release events are processed by input resource first
-rw-r--r--Cargo.toml2
-rw-r--r--src/input/systems.rs30
2 files changed, 21 insertions, 11 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 14f8c5c..62adeb5 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "bevy_terminal_display"
-version = "0.2.1"
+version = "0.2.2"
edition = "2021"
[dependencies]
diff --git a/src/input/systems.rs b/src/input/systems.rs
index 3b7f11d..810c08e 100644
--- a/src/input/systems.rs
+++ b/src/input/systems.rs
@@ -1,5 +1,7 @@
+use std::cmp::Ordering;
+
use bevy::prelude::*;
-use crossterm::event::{read, Event, KeyEventKind};
+use crossterm::event::{read, Event, KeyEvent, KeyEventKind};
use super::{events::TerminalInputEvent, resources::{EventQueue, TerminalInput}};
@@ -29,18 +31,26 @@ pub fn input_handling(
) {
input.clear_released();
let mut event_queue = event_queue.0.lock().unwrap();
+ let mut key_events = Vec::<KeyEvent>::new();
while let Some(event) = event_queue.pop() {
if let Event::Key(event) = event {
- match event.kind {
- KeyEventKind::Press => {
- input.press(event.code);
- }
- KeyEventKind::Release => {
- input.release(event.code);
- }
- _ => (),
- }
+ info!("{:?}", event);
+ key_events.push(event);
}
event_writer.send(TerminalInputEvent(event));
}
+
+ key_events.sort_by(|&a, &b| a.kind.partial_cmp(&b.kind).unwrap_or(Ordering::Equal));
+ for event in key_events {
+ info!("{:?}", event);
+ match event.kind {
+ KeyEventKind::Press => {
+ input.press(event.code);
+ }
+ KeyEventKind::Release => {
+ input.release(event.code);
+ }
+ _ => (),
+ }
+ }
}