big ass input system
This commit is contained in:
parent
81cb5c24d4
commit
a6079103a4
6 changed files with 73 additions and 44 deletions
|
|
@ -2,17 +2,20 @@ use std::time::Duration;
|
|||
|
||||
use bevy::{app::ScheduleRunnerPlugin, prelude::*, state::app::StatesPlugin};
|
||||
use bevy_ratatui::RatatuiPlugins;
|
||||
use bevy_ratatui::event::KeyMessage;
|
||||
use ratatui::{text::ToSpan, widgets::Paragraph};
|
||||
|
||||
use jong::game::GameState;
|
||||
use jong::game::wall::InWall;
|
||||
|
||||
use crate::tui::console::ConsoleState;
|
||||
|
||||
mod console;
|
||||
mod menu;
|
||||
mod render;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)]
|
||||
enum TuiState {
|
||||
pub(crate) enum TuiState {
|
||||
#[default]
|
||||
MainMenu,
|
||||
InGame,
|
||||
|
|
@ -56,9 +59,10 @@ impl Plugin for RiichiTui {
|
|||
// general setup
|
||||
.init_state::<TuiState>()
|
||||
.add_computed_state::<InGame>()
|
||||
.add_systems(Update, input_system)
|
||||
|
||||
// main menu
|
||||
.add_systems(Update, (menu::draw_mainmenu, menu::mainmenu_input).run_if(in_state(TuiState::MainMenu)))
|
||||
.add_systems(Update, menu::draw_mainmenu.run_if(in_state(TuiState::MainMenu)))
|
||||
|
||||
// gaming
|
||||
.init_resource::<render::hand::RenderedHand>()
|
||||
|
|
@ -70,3 +74,55 @@ impl Plugin for RiichiTui {
|
|||
}
|
||||
}
|
||||
|
||||
#[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>>,
|
||||
|
||||
mut next_tuistate: ResMut<NextState<TuiState>>,
|
||||
mut next_consolestate: ResMut<NextState<ConsoleState>>,
|
||||
mut next_gamestate: ResMut<NextState<GameState>>,
|
||||
|
||||
mut exit: MessageWriter<AppExit>,
|
||||
) {
|
||||
use bevy_ratatui::crossterm::event::KeyCode;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
match ts {
|
||||
TuiState::MainMenu => match message.code {
|
||||
KeyCode::Char('p') => {
|
||||
next_tuistate.set(TuiState::InGame);
|
||||
next_gamestate.set(GameState::Setup);
|
||||
}
|
||||
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();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
GameState::Score => todo!(),
|
||||
_ => unreachable!("TuiState::InGame but GameState invalid")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue