fix deal crash
This commit is contained in:
parent
759ff410c2
commit
65ea256436
6 changed files with 15 additions and 55 deletions
|
|
@ -9,6 +9,7 @@ pub mod wall;
|
||||||
#[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq, Copy)]
|
#[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq, Copy)]
|
||||||
pub enum GameState {
|
pub enum GameState {
|
||||||
#[default]
|
#[default]
|
||||||
|
None,
|
||||||
Setup,
|
Setup,
|
||||||
// Deal,
|
// Deal,
|
||||||
Play,
|
Play,
|
||||||
|
|
@ -22,12 +23,16 @@ impl Plugin for Riichi {
|
||||||
.add_systems(Startup, init_match)
|
.add_systems(Startup, init_match)
|
||||||
.add_systems(Startup, tiles::init_tiles)
|
.add_systems(Startup, tiles::init_tiles)
|
||||||
.init_state::<GameState>()
|
.init_state::<GameState>()
|
||||||
.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
|
// semicolon stopper
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn setup_done(mut next: ResMut<NextState<GameState>>) {
|
||||||
|
next.set(GameState::Play);
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub(crate) struct Dice(u8, u8);
|
pub(crate) struct Dice(u8, u8);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
game::wall::{Wall, WallTiles},
|
game::wall::{InWall, Wall, WallTiles},
|
||||||
tiles::Tile,
|
tiles::Tile,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -28,14 +28,13 @@ pub struct InHand(pub Entity);
|
||||||
|
|
||||||
pub(crate) fn deal_hands(
|
pub(crate) fn deal_hands(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
wall: Single<Entity, With<Wall>>,
|
inwalls: Single<&WallTiles>,
|
||||||
wall_tiles: Populated<Entity, With<WallTiles>>,
|
walltiles: Single<Entity, With<WallTiles>>,
|
||||||
tiles: Populated<Entity, With<Tile>>,
|
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let hand = wall_tiles.iter().collect::<Vec<_>>();
|
let hand = inwalls.iter().collect::<Vec<_>>();
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.get_entity(*wall)?
|
.get_entity(*walltiles)?
|
||||||
.remove_children(hand.last_chunk::<13>().unwrap());
|
.remove_children(hand.last_chunk::<13>().unwrap());
|
||||||
|
|
||||||
commands.spawn((Hand, HandTiles(hand)));
|
commands.spawn((Hand, HandTiles(hand)));
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,10 @@ pub struct InWall(pub Entity);
|
||||||
pub(crate) fn build_wall(mut commands: Commands, tiles: Query<Entity, With<Tile>>) {
|
pub(crate) fn build_wall(mut commands: Commands, tiles: Query<Entity, With<Tile>>) {
|
||||||
let mut rng = rand::rng();
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
let mut shuffled = tiles
|
let mut shuffled = tiles.iter().collect::<Vec<_>>();
|
||||||
.iter()
|
|
||||||
.inspect(|e| debug!("{e:?}"))
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
shuffled.shuffle(&mut rng);
|
shuffled.shuffle(&mut rng);
|
||||||
|
|
||||||
commands.spawn((Wall, WallTiles(shuffled)));
|
commands.spawn((Wall, WallTiles(shuffled)));
|
||||||
|
|
||||||
|
trace!("build_wall");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ pub(crate) fn mainmenu_input(
|
||||||
match message.code {
|
match message.code {
|
||||||
KeyCode::Char('p') => {
|
KeyCode::Char('p') => {
|
||||||
next_tuistate.set(TuiState::InGame);
|
next_tuistate.set(TuiState::InGame);
|
||||||
next_gamestate.set(GameState::default());
|
next_gamestate.set(GameState::Setup);
|
||||||
}
|
}
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => {
|
||||||
exit.write_default();
|
exit.write_default();
|
||||||
|
|
|
||||||
|
|
@ -13,26 +13,9 @@ pub(crate) fn draw_ingame(
|
||||||
use ratatui::layout::Flex;
|
use ratatui::layout::Flex;
|
||||||
use ratatui::prelude::*;
|
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::<Result<Vec<_>>>()?;
|
|
||||||
|
|
||||||
// // let paragraph = Paragraph::new(wall.join(", ")).wrap(ratatui::widgets::Wrap { trim: true });
|
|
||||||
// Some(wall_tiles)
|
|
||||||
// } else {
|
|
||||||
// None
|
|
||||||
// };
|
|
||||||
|
|
||||||
tui_ctx.draw(|frame| {
|
tui_ctx.draw(|frame| {
|
||||||
// frame.render_widget(title, frame.area());
|
|
||||||
debug!("{}", 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 layout = Layout::horizontal(vec![Constraint::Max(5); 13]).flex(Flex::Start);
|
||||||
let mut area = frame.area();
|
let mut area = frame.area();
|
||||||
area.height = 4;
|
area.height = 4;
|
||||||
|
|
@ -40,13 +23,6 @@ pub(crate) fn draw_ingame(
|
||||||
for (tile, area) in rendered_hand.0.iter().zip(areas.iter()) {
|
for (tile, area) in rendered_hand.0.iter().zip(areas.iter()) {
|
||||||
frame.render_widget(tile, *area);
|
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(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -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 hand;
|
||||||
pub(crate) mod ingame;
|
pub(crate) mod ingame;
|
||||||
mod tiles;
|
mod tiles;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue