This commit is contained in:
Tao Tien 2026-01-12 20:56:30 -08:00
parent 59399c3590
commit 81cb5c24d4
5 changed files with 17 additions and 43 deletions

View file

@ -18,11 +18,22 @@ enum TuiState {
InGame,
}
#[derive(Default)]
pub struct RiichiTui {
// player_names: Vec<String>,
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
struct InGame;
impl ComputedStates for InGame {
type SourceStates = TuiState;
fn compute(sources: Self::SourceStates) -> Option<Self> {
match sources {
TuiState::MainMenu => None,
TuiState::InGame => Some(Self),
}
}
}
#[derive(Default)]
pub struct RiichiTui;
impl Plugin for RiichiTui {
fn build(&self, app: &mut App) {
app.add_plugins((
@ -45,48 +56,17 @@ impl Plugin for RiichiTui {
// general setup
.init_state::<TuiState>()
.add_computed_state::<InGame>()
.add_systems(Update, curr_state)
// main menu
.add_systems(Update, (menu::draw_mainmenu, menu::mainmenu_input).run_if(in_state(TuiState::MainMenu)))
// gaming
.init_resource::<render::hand::RenderedHand>()
.add_systems(OnEnter(GameState::Play), render::hand::render_hand)
.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::ingame::draw_ingame.run_if(in_state(TuiState::InGame)))
// semicolon stopper
;
}
}
fn curr_state(
curr_gamestate: Option<Res<State<GameState>>>,
curr_tuistate: Res<State<TuiState>>,
curr_ingame: Option<Res<State<InGame>>>,
) {
if let Some(curr_gamestate) = curr_gamestate && curr_gamestate.is_changed(){
trace!("GameState: {curr_gamestate:?}")
}
if curr_tuistate.is_changed() {
trace!("TuiState: {curr_tuistate:?}")
}
if let Some(curr_ingame) = curr_ingame && curr_ingame.is_changed(){
trace!("InGame: {curr_ingame:?}")
}
}
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
struct InGame;
impl ComputedStates for InGame {
type SourceStates = TuiState;
fn compute(sources: Self::SourceStates) -> Option<Self> {
match sources {
TuiState::MainMenu => None,
TuiState::InGame => Some(Self),
}
}
}