we start printing again
This commit is contained in:
parent
65ea256436
commit
59399c3590
7 changed files with 114 additions and 52 deletions
54
src/game/hand.rs
Normal file
54
src/game/hand.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{game::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<Entity>);
|
||||
|
||||
pub(crate) fn deal_hands(
|
||||
mut commands: Commands,
|
||||
walltiles: Single<&WallTiles>,
|
||||
walltiles_entity: Single<Entity, With<WallTiles>>,
|
||||
) -> Result {
|
||||
let hand = walltiles.iter().collect::<Vec<_>>();
|
||||
|
||||
commands
|
||||
.get_entity(*walltiles_entity)?
|
||||
.remove_children(hand.last_chunk::<13>().unwrap());
|
||||
|
||||
commands.spawn((Hand, HandTiles(hand)));
|
||||
|
||||
trace!("dealt hands");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn sort_hand(
|
||||
mut commands: Commands,
|
||||
tiles: Populated<&Tile>,
|
||||
handtiles_entity: Single<Entity, With<HandTiles>>,
|
||||
handtiles: Single<&HandTiles, Changed<HandTiles>>,
|
||||
) -> Result {
|
||||
let mut hand: Vec<_> = handtiles
|
||||
.iter()
|
||||
.map(|e| -> Result<(_, _)> { Ok((tiles.get(e)?, e)) })
|
||||
.collect::<Result<_>>()?;
|
||||
|
||||
hand.sort_by_key(|(t, _)| t.suit);
|
||||
|
||||
let hand: Vec<_> = hand.iter().map(|(_, e)| *e).collect();
|
||||
|
||||
commands
|
||||
.get_entity(*handtiles_entity)?
|
||||
.replace_children(&hand);
|
||||
|
||||
trace!("sort_hand");
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ use tracing::instrument;
|
|||
|
||||
use crate::tiles::{self, *};
|
||||
|
||||
pub mod hand;
|
||||
pub mod player;
|
||||
pub mod wall;
|
||||
|
||||
|
|
@ -23,7 +24,8 @@ 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, setup_done).chain())
|
||||
.add_systems(OnEnter(GameState::Setup), (wall::build_wall, hand::deal_hands, setup_done).chain())
|
||||
// .add_systems(Update, systems)
|
||||
// semicolon stopper
|
||||
;
|
||||
}
|
||||
|
|
@ -31,6 +33,7 @@ impl Plugin for Riichi {
|
|||
|
||||
fn setup_done(mut next: ResMut<NextState<GameState>>) {
|
||||
next.set(GameState::Play);
|
||||
trace!("setup_done");
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
game::wall::{InWall, Wall, WallTiles},
|
||||
game::wall::{InWall, Wall},
|
||||
tiles::Tile,
|
||||
};
|
||||
|
||||
|
|
@ -15,30 +15,3 @@ fn spawn_players(mut commands: Commands) {}
|
|||
#[derive(Component)]
|
||||
pub(crate) struct Points(pub isize);
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Hand;
|
||||
|
||||
#[derive(Component)]
|
||||
#[relationship_target(relationship = InHand, linked_spawn)]
|
||||
pub struct HandTiles(Vec<Entity>);
|
||||
|
||||
#[derive(Component)]
|
||||
#[relationship(relationship_target = HandTiles)]
|
||||
pub struct InHand(pub Entity);
|
||||
|
||||
pub(crate) fn deal_hands(
|
||||
mut commands: Commands,
|
||||
inwalls: Single<&WallTiles>,
|
||||
walltiles: Single<Entity, With<WallTiles>>,
|
||||
) -> Result {
|
||||
let hand = inwalls.iter().collect::<Vec<_>>();
|
||||
|
||||
commands
|
||||
.get_entity(*walltiles)?
|
||||
.remove_children(hand.last_chunk::<13>().unwrap());
|
||||
|
||||
commands.spawn((Hand, HandTiles(hand)));
|
||||
|
||||
trace!("dealt hands");
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue