Ensured key release events are processed by input resource first
This commit is contained in:
parent
1addc01cac
commit
c30929cbd3
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bevy_terminal_display"
|
name = "bevy_terminal_display"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use crossterm::event::{read, Event, KeyEventKind};
|
use crossterm::event::{read, Event, KeyEvent, KeyEventKind};
|
||||||
|
|
||||||
use super::{events::TerminalInputEvent, resources::{EventQueue, TerminalInput}};
|
use super::{events::TerminalInputEvent, resources::{EventQueue, TerminalInput}};
|
||||||
|
|
||||||
@ -29,18 +31,26 @@ pub fn input_handling(
|
|||||||
) {
|
) {
|
||||||
input.clear_released();
|
input.clear_released();
|
||||||
let mut event_queue = event_queue.0.lock().unwrap();
|
let mut event_queue = event_queue.0.lock().unwrap();
|
||||||
|
let mut key_events = Vec::<KeyEvent>::new();
|
||||||
while let Some(event) = event_queue.pop() {
|
while let Some(event) = event_queue.pop() {
|
||||||
if let Event::Key(event) = event {
|
if let Event::Key(event) = event {
|
||||||
match event.kind {
|
info!("{:?}", event);
|
||||||
KeyEventKind::Press => {
|
key_events.push(event);
|
||||||
input.press(event.code);
|
|
||||||
}
|
|
||||||
KeyEventKind::Release => {
|
|
||||||
input.release(event.code);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
event_writer.send(TerminalInputEvent(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);
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user