Something went wrong. Try again.
Bevy+Ratutui powered Monitoring of Pico-Strike devices
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#![allow(clippy::type_complexity)]
mod device;mod messages;mod net;mod state;
mod constants { include!(concat!(env!("OUT_DIR"), "/constants.rs"));}
use bevy::{ app::{AppExit, Plugin, PreUpdate}, ecs::{ message::{MessageReader, MessageWriter}, system::Res, }, state::{app::AppExtStates, state::State},};use bevy_ratatui::event::KeyMessage;
use crate::{ device::DevicePlugin, messages::StrikeMessage, net::NetPlugin, state::AppState,};
#[derive(Debug)]pub struct StrikerPlugin;
impl Plugin for StrikerPlugin { fn build(&self, app: &mut bevy::app::App) { app.init_state::<AppState>() .add_message::<StrikeMessage>() .add_plugins(( NetPlugin, DevicePlugin, )) .add_systems(PreUpdate, keybinds); }}
fn keybinds( state: Res<State<AppState>>, mut key_reader: MessageReader<KeyMessage>, mut strike_writer: MessageWriter<StrikeMessage>, mut app_exit: MessageWriter<AppExit>,) { use ratatui::crossterm::event::KeyCode; for message in key_reader.read() { match message.code { KeyCode::Char('s') if state.get() == &AppState::Home => { strike_writer.write(StrikeMessage::ToggleSearch); } KeyCode::Up if state.get() == &AppState::Home => { strike_writer.write(StrikeMessage::PrevDevice); } KeyCode::Down if state.get() == &AppState::Home => { strike_writer.write(StrikeMessage::NextDevice); } KeyCode::Enter | KeyCode::Char(' ') if state.get() == &AppState::Home => { strike_writer.write(StrikeMessage::MonitorDevice); } KeyCode::Backspace if state.get() == &AppState::Monitoring => { strike_writer.write(StrikeMessage::StopMonitoring); } KeyCode::Char('q') | KeyCode::Esc => { app_exit.write(AppExit::Success); } _ => {} } }}