render main player's hand
This commit is contained in:
parent
30d19ed9d9
commit
314c3299ef
8 changed files with 134 additions and 97 deletions
|
|
@ -2,7 +2,6 @@ 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;
|
||||
|
|
@ -13,6 +12,7 @@ use crate::tui::{console::ConsoleState, menu::draw_mainmenu, render::ingame::dra
|
|||
mod console;
|
||||
mod menu;
|
||||
mod render;
|
||||
mod input;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)]
|
||||
pub(crate) enum TuiState {
|
||||
|
|
@ -59,7 +59,7 @@ impl Plugin for RiichiTui {
|
|||
// general setup
|
||||
.init_state::<TuiState>()
|
||||
.add_computed_state::<InGame>()
|
||||
.add_systems(Update, input_system)
|
||||
.add_systems(Update, input::kb_input_system)
|
||||
|
||||
// main menu
|
||||
.add_systems(Update, menu::draw_mainmenu.run_if(in_state(TuiState::MainMenu)))
|
||||
|
|
@ -67,62 +67,11 @@ impl Plugin for RiichiTui {
|
|||
// gaming
|
||||
.init_resource::<render::hand::RenderedHand>()
|
||||
.add_systems(Update, render::ingame::draw_ingame.run_if(in_state(InGame)))
|
||||
// .add_systems(Update, render::hand::render_changed_hand.run_if(in_state(InGame).and(in_state(GameState::Play))))
|
||||
.add_systems(Update, render::hand::render_hand.run_if(in_state(InGame).and(in_state(GameState::Play))))
|
||||
|
||||
// semicolon stopper
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#[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();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => todo!(),
|
||||
_ => unreachable!("TuiState::InGame but GameState invalid")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue