third time's the charm
This commit is contained in:
parent
723cd0b6e4
commit
2b95c642df
18 changed files with 547 additions and 173 deletions
|
|
@ -1,91 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::crossterm::event::KeyCode;
|
||||
use bevy_ratatui::event::KeyMessage;
|
||||
|
||||
use jong::game::GameState;
|
||||
|
||||
use crate::tui::states::*;
|
||||
|
||||
// TODO change this to handle console open request, esc for menu, etc, then
|
||||
// route other messages to other systems
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn input_system(
|
||||
mut messages: MessageReader<KeyMessage>,
|
||||
|
||||
curr_tuistate: Res<State<TuiState>>,
|
||||
curr_consolestate: Res<State<ConsoleState>>,
|
||||
curr_gamestate: Res<State<GameState>>,
|
||||
curr_zenstate: Option<Res<State<ZenState>>>,
|
||||
|
||||
mut next_tuistate: ResMut<NextState<TuiState>>,
|
||||
mut next_consolestate: ResMut<NextState<ConsoleState>>,
|
||||
mut next_gamestate: ResMut<NextState<GameState>>,
|
||||
mut next_zenstate: ResMut<NextState<ZenState>>,
|
||||
|
||||
mut exit: MessageWriter<AppExit>,
|
||||
) {
|
||||
let (ts, cs, gs) = (
|
||||
curr_tuistate.get(),
|
||||
curr_consolestate.get(),
|
||||
curr_gamestate.get(),
|
||||
);
|
||||
|
||||
for message in messages.read() {
|
||||
if let KeyCode::Char('`') = message.code {
|
||||
next_consolestate.set(!*curr_consolestate.get());
|
||||
continue;
|
||||
}
|
||||
|
||||
if *cs == ConsoleState::Open {
|
||||
let mut passthrough = false;
|
||||
match message.code {
|
||||
KeyCode::Up => todo!(),
|
||||
KeyCode::Down => todo!(),
|
||||
KeyCode::Home => todo!(),
|
||||
KeyCode::End => todo!(),
|
||||
KeyCode::PageUp => todo!(),
|
||||
KeyCode::PageDown => todo!(),
|
||||
KeyCode::Esc => next_consolestate.set(ConsoleState::Closed),
|
||||
_ => passthrough = true,
|
||||
}
|
||||
if !passthrough {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
match ts {
|
||||
TuiState::MainMenu => match message.code {
|
||||
KeyCode::Char('p') => {
|
||||
next_tuistate.set(TuiState::InGame);
|
||||
next_gamestate.set(GameState::Setup);
|
||||
}
|
||||
KeyCode::Char('z') => {
|
||||
if let Some(ref curr_zenstate) = curr_zenstate {
|
||||
match curr_zenstate.get() {
|
||||
ZenState::Menu => next_zenstate.set(ZenState::Zen),
|
||||
ZenState::Zen => next_zenstate.set(ZenState::Menu),
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Char('q') => {
|
||||
exit.write_default();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
TuiState::InGame => match gs {
|
||||
GameState::Setup => match message.code {
|
||||
_ => {}
|
||||
},
|
||||
GameState::Play => match message.code {
|
||||
KeyCode::Char('q') => {
|
||||
exit.write_default();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => todo!(),
|
||||
_ => unreachable!("TuiState::InGame but GameState invalid"),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue