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)]
|
||||
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::<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
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_done(mut next: ResMut<NextState<GameState>>) {
|
||||
next.set(GameState::Play);
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Dice(u8, u8);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Entity, With<Wall>>,
|
||||
wall_tiles: Populated<Entity, With<WallTiles>>,
|
||||
tiles: Populated<Entity, With<Tile>>,
|
||||
inwalls: Single<&WallTiles>,
|
||||
walltiles: Single<Entity, With<WallTiles>>,
|
||||
) -> Result {
|
||||
let hand = wall_tiles.iter().collect::<Vec<_>>();
|
||||
let hand = inwalls.iter().collect::<Vec<_>>();
|
||||
|
||||
commands
|
||||
.get_entity(*wall)?
|
||||
.get_entity(*walltiles)?
|
||||
.remove_children(hand.last_chunk::<13>().unwrap());
|
||||
|
||||
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>>) {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let mut shuffled = tiles
|
||||
.iter()
|
||||
.inspect(|e| debug!("{e:?}"))
|
||||
.collect::<Vec<_>>();
|
||||
let mut shuffled = tiles.iter().collect::<Vec<_>>();
|
||||
shuffled.shuffle(&mut rng);
|
||||
|
||||
commands.spawn((Wall, WallTiles(shuffled)));
|
||||
|
||||
trace!("build_wall");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue