diff --git a/src/game/mod.rs b/src/game/mod.rs index e1eec8b..95b20e1 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -9,6 +9,7 @@ pub mod wall; #[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq, Copy)] pub enum GameState { #[default] + None, Setup, // Deal, Play, @@ -22,12 +23,16 @@ impl Plugin for Riichi { .add_systems(Startup, init_match) .add_systems(Startup, tiles::init_tiles) .init_state::() - .add_systems(OnEnter(GameState::Setup), (wall::build_wall, player::deal_hands).chain()) + .add_systems(OnEnter(GameState::Setup), (wall::build_wall, player::deal_hands, setup_done).chain()) // semicolon stopper ; } } +fn setup_done(mut next: ResMut>) { + next.set(GameState::Play); +} + #[derive(Component)] pub(crate) struct Dice(u8, u8); diff --git a/src/game/player.rs b/src/game/player.rs index e14b982..d1d263f 100644 --- a/src/game/player.rs +++ b/src/game/player.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; use crate::{ - game::wall::{Wall, WallTiles}, + game::wall::{InWall, Wall, WallTiles}, tiles::Tile, }; @@ -28,14 +28,13 @@ pub struct InHand(pub Entity); pub(crate) fn deal_hands( mut commands: Commands, - wall: Single>, - wall_tiles: Populated>, - tiles: Populated>, + inwalls: Single<&WallTiles>, + walltiles: Single>, ) -> Result { - let hand = wall_tiles.iter().collect::>(); + let hand = inwalls.iter().collect::>(); commands - .get_entity(*wall)? + .get_entity(*walltiles)? .remove_children(hand.last_chunk::<13>().unwrap()); commands.spawn((Hand, HandTiles(hand))); diff --git a/src/game/wall.rs b/src/game/wall.rs index 96a4e6e..5202d0e 100644 --- a/src/game/wall.rs +++ b/src/game/wall.rs @@ -18,11 +18,10 @@ pub struct InWall(pub Entity); pub(crate) fn build_wall(mut commands: Commands, tiles: Query>) { let mut rng = rand::rng(); - let mut shuffled = tiles - .iter() - .inspect(|e| debug!("{e:?}")) - .collect::>(); + let mut shuffled = tiles.iter().collect::>(); shuffled.shuffle(&mut rng); commands.spawn((Wall, WallTiles(shuffled))); + + trace!("build_wall"); } diff --git a/src/tui/menu.rs b/src/tui/menu.rs index 72e0301..65da70b 100644 --- a/src/tui/menu.rs +++ b/src/tui/menu.rs @@ -39,7 +39,7 @@ pub(crate) fn mainmenu_input( match message.code { KeyCode::Char('p') => { next_tuistate.set(TuiState::InGame); - next_gamestate.set(GameState::default()); + next_gamestate.set(GameState::Setup); } KeyCode::Char('q') => { exit.write_default(); diff --git a/src/tui/render/ingame.rs b/src/tui/render/ingame.rs index 66fbbb3..642c3f8 100644 --- a/src/tui/render/ingame.rs +++ b/src/tui/render/ingame.rs @@ -13,26 +13,9 @@ pub(crate) fn draw_ingame( use ratatui::layout::Flex; use ratatui::prelude::*; - // let title = ratatui::text::Text::raw("tiny riichi"); - - // let wall = if let Some(wall_tiles) = wall_tiles { - // let wall_tiles = wall_tiles - // .iter() - // .map(|inwall| -> Result<_> { Ok(tiles.get(inwall).map(tiles::draw_tile)?) }) - // .collect::>>()?; - - // // let paragraph = Paragraph::new(wall.join(", ")).wrap(ratatui::widgets::Wrap { trim: true }); - // Some(wall_tiles) - // } else { - // None - // }; - tui_ctx.draw(|frame| { - // frame.render_widget(title, frame.area()); debug!("{}", frame.area()); - // if let Some(wall) = wall { - // // let tile_area = Rect::new(0, 0, 5, 4); let layout = Layout::horizontal(vec![Constraint::Max(5); 13]).flex(Flex::Start); let mut area = frame.area(); area.height = 4; @@ -40,13 +23,6 @@ pub(crate) fn draw_ingame( for (tile, area) in rendered_hand.0.iter().zip(areas.iter()) { frame.render_widget(tile, *area); } - - // // debug!("wall.len(): {}, areas.len(): {}", wall.len(), areas.len()); - // for (tile, rect) in wall.iter().zip(areas.iter()) { - // // debug!("{rect:?}"); - // frame.render_widget(tile, *rect); - // } - // } })?; Ok(()) diff --git a/src/tui/render/mod.rs b/src/tui/render/mod.rs index 1c8b3e4..fc6612a 100644 --- a/src/tui/render/mod.rs +++ b/src/tui/render/mod.rs @@ -1,22 +1,3 @@ -use bevy::ecs::system::SystemParam; -use bevy::prelude::*; -use bevy_ratatui::RatatuiContext; -use ratatui::{ - layout::{}, - widgets::Paragraph, -}; - -use jong::{ - game::{ - player::Hand, - wall::{Wall, WallTiles}, - }, - tiles::Tile, -}; - -use crate::tui::TuiState; - pub(crate) mod hand; pub(crate) mod ingame; mod tiles; -