detect hand change and render it
This commit is contained in:
parent
d506a25716
commit
3417384b86
9 changed files with 138 additions and 68 deletions
|
|
@ -3,30 +3,32 @@ use tracing::instrument;
|
|||
|
||||
use crate::tiles::{self, *};
|
||||
|
||||
mod player;
|
||||
pub mod player;
|
||||
pub mod wall;
|
||||
|
||||
pub struct Riichi;
|
||||
#[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq)]
|
||||
pub enum GameState {
|
||||
#[default]
|
||||
None,
|
||||
Setup,
|
||||
// Deal,
|
||||
Play,
|
||||
Score,
|
||||
}
|
||||
|
||||
pub struct Riichi;
|
||||
impl Plugin for Riichi {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<Compass>()
|
||||
.add_systems(Startup, init_match)
|
||||
.add_systems(Startup, (tiles::init_tiles, wall::build_wall).chain())
|
||||
.add_systems(Startup, tiles::init_tiles)
|
||||
.init_state::<GameState>()
|
||||
.add_systems(OnEnter(GameState::Setup), (wall::build_wall, player::deal_hands).chain())
|
||||
// semicolon stopper
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq)]
|
||||
enum GameState {
|
||||
#[default]
|
||||
Setup,
|
||||
Deal,
|
||||
Play,
|
||||
Score,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Dice(u8, u8);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,44 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
game::wall::{Wall, WallTiles},
|
||||
tiles::Tile,
|
||||
};
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Player {
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
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,
|
||||
wall: Single<Entity, With<Wall>>,
|
||||
wall_tiles: Query<Entity, With<WallTiles>>,
|
||||
tiles: Query<Entity, With<Tile>>,
|
||||
) -> Result {
|
||||
let hand = wall_tiles.iter().collect::<Vec<_>>();
|
||||
|
||||
commands
|
||||
.get_entity(*wall)?
|
||||
.remove_children(hand.last_chunk::<13>().unwrap());
|
||||
|
||||
commands.spawn((Hand, HandTiles(hand)));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,20 @@ use bevy::log::tracing::instrument;
|
|||
use bevy::prelude::*;
|
||||
use rand::seq::SliceRandom;
|
||||
|
||||
use crate::game::InWall;
|
||||
use crate::tiles::Tile;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Wall;
|
||||
|
||||
#[derive(Component)]
|
||||
#[relationship_target(relationship = InWall, linked_spawn)]
|
||||
pub struct WallTiles(Vec<Entity>);
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Wall;
|
||||
#[relationship(relationship_target = WallTiles)]
|
||||
pub struct InWall(pub Entity);
|
||||
|
||||
pub(crate) fn build_wall(mut commands: Commands, tiles: Query<Entity, With<Tile>>) -> Result {
|
||||
pub(crate) fn build_wall(mut commands: Commands, tiles: Query<Entity, With<Tile>>) {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let mut shuffled = tiles
|
||||
|
|
@ -21,7 +24,5 @@ pub(crate) fn build_wall(mut commands: Commands, tiles: Query<Entity, With<Tile>
|
|||
.collect::<Vec<_>>();
|
||||
shuffled.shuffle(&mut rng);
|
||||
|
||||
let mut wall = commands.spawn((Wall, WallTiles(shuffled)));
|
||||
|
||||
Ok(())
|
||||
commands.spawn((Wall, WallTiles(shuffled)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue