use bevy::prelude::*; use crate::{ game::{player::Player, wall::WallTiles}, tiles::Tile, }; #[derive(Component)] pub struct Hand; #[derive(Component)] #[relationship(relationship_target = HandTiles)] pub struct InHand(pub Entity); #[derive(Component)] #[relationship_target(relationship = InHand, linked_spawn)] pub struct HandTiles(Vec); pub(crate) fn deal_hands( mut commands: Commands, walltiles: Single<&WallTiles>, walltiles_entity: Single>, players: Populated>, ) -> Result { let mut wall = walltiles.iter().collect::>(); for player_entity in players { let hand = wall.split_off(13); commands .get_entity(*walltiles_entity)? .remove_children(&hand); let handtiles = commands.spawn((Hand, HandTiles(hand))).id(); commands .get_entity(player_entity)? .add_children(&[handtiles]); } trace!("dealt hands"); Ok(()) } #[allow(clippy::type_complexity)] pub(crate) fn sort_hands( mut commands: Commands, tiles: Populated<&Tile>, mut hands: Populated<&mut Children, Changed>, ) -> Result { for (mut children) in hands { children.sort_unstable_by_key(|e| tiles.get(*e).unwrap().suit); trace!("sorted a hand") } trace!("sort_hands"); Ok(()) }