render main player's hand
This commit is contained in:
parent
30d19ed9d9
commit
314c3299ef
8 changed files with 134 additions and 97 deletions
|
|
@ -42,7 +42,7 @@ impl Plugin for Riichi {
|
|||
|
||||
fn shuffle_deal(
|
||||
mut commands: Commands,
|
||||
tiles: Query<Entity, With<Tile>>,
|
||||
tiles: Populated<Entity, With<Tile>>,
|
||||
players: Populated<Entity, With<Player>>,
|
||||
wall_ent: Single<Entity, With<Wall>>,
|
||||
mut next_gamestate: ResMut<NextState<GameState>>,
|
||||
|
|
@ -50,18 +50,27 @@ fn shuffle_deal(
|
|||
use rand::seq::SliceRandom;
|
||||
|
||||
let mut rng = rand::rng();
|
||||
let mut wall: Vec<_> = tiles.iter().collect();
|
||||
wall.shuffle(&mut rng);
|
||||
let mut walltiles: Vec<_> = tiles.iter().collect();
|
||||
walltiles.shuffle(&mut rng);
|
||||
|
||||
commands.get_entity(*wall_ent)?.replace_children(&wall);
|
||||
// commands.get_entity(*wall_ent)?.replace_children(&walltiles);
|
||||
|
||||
for player_ent in players {
|
||||
let handtiles = wall.split_off(13);
|
||||
commands.get_entity(*wall_ent)?.remove_children(&handtiles);
|
||||
let hand = commands.spawn(Hand).add_children(&handtiles).id();
|
||||
commands.get_entity(player_ent)?.replace_children(&[hand]);
|
||||
let handtiles = walltiles.split_off(walltiles.len() - 13);
|
||||
// commands.get_entity(*wall_ent)?.remove_children(&handtiles);
|
||||
|
||||
let hand_ent = commands.spawn(Hand).add_children(&handtiles).id();
|
||||
debug!("hand_ent: {hand_ent:?}");
|
||||
|
||||
commands
|
||||
.get_entity(player_ent)?
|
||||
.replace_children(&[hand_ent]);
|
||||
|
||||
debug!("dealt to player_ent {player_ent:?}");
|
||||
}
|
||||
|
||||
commands.get_entity(*wall_ent)?.replace_children(&walltiles);
|
||||
|
||||
next_gamestate.set(GameState::Play);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue