turnstates

This commit is contained in:
Tao Tien 2026-01-13 12:38:41 -08:00
parent 8a8a702a08
commit 6e6b792a58
7 changed files with 133 additions and 41 deletions

View file

@ -1,13 +1,16 @@
use bevy::{ecs::relationship::RelationshipSourceCollection, prelude::*};
use crate::{
game::{player::Player /* wall::WallTiles */},
game::{GameState, player::Player, wall::Wall /* wall::WallTiles */},
tile::Tile,
};
#[derive(Component)]
pub struct Hand;
#[derive(Component)]
pub struct Drawn(pub Entity);
// #[derive(Component, Default)]
// enum SortHand {
// #[default]
@ -26,3 +29,38 @@ pub(crate) fn sort_hands(
}
Ok(())
}
pub(crate) fn shuffle_deal(
mut commands: Commands,
tiles: Populated<Entity, With<Tile>>,
players: Populated<Entity, With<Player>>,
wall_ent: Single<Entity, With<Wall>>,
mut next_gamestate: ResMut<NextState<GameState>>,
) -> Result {
use rand::seq::SliceRandom;
let mut rng = rand::rng();
let mut walltiles: Vec<_> = tiles.iter().collect();
walltiles.shuffle(&mut rng);
// commands.get_entity(*wall_ent)?.replace_children(&walltiles);
for player_ent in players {
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(())
}