stash
This commit is contained in:
parent
02b40ef344
commit
3182916832
7 changed files with 85 additions and 14 deletions
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
EnumNextCycle,
|
||||
game::{
|
||||
GameMessage, GameState,
|
||||
hand::{DrawnTile, Hand},
|
||||
hand::{DiscardedTile, DrawnTile, Hand},
|
||||
player::Player,
|
||||
wall::Wall,
|
||||
},
|
||||
|
|
@ -127,9 +127,10 @@ pub(crate) fn tsumo(
|
|||
|
||||
let drawn = walltiles.last().unwrap();
|
||||
commands.entity(*wall_ent).remove_child(*drawn);
|
||||
commands.entity(curr_player.0).insert(DrawnTile(*drawn));
|
||||
let drawn_ent = commands.spawn(DrawnTile(*drawn)).id();
|
||||
commands.entity(curr_player.0).add_child(drawn_ent);
|
||||
|
||||
debug!("drew: {:?}", drawn);
|
||||
debug!("drew: ent: {drawn_ent:?} tile_ent: {:?}", drawn);
|
||||
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
|
@ -138,6 +139,7 @@ pub(crate) fn menzen(
|
|||
curr_turnstate: Res<State<TurnState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
trace!("menzen check");
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
||||
|
|
@ -145,14 +147,17 @@ pub(crate) fn riichi_kan(
|
|||
curr_turnstate: Res<State<TurnState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
trace!("riichi_kan");
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments, irrefutable_let_patterns)]
|
||||
pub(crate) fn discard(
|
||||
mut commands: Commands,
|
||||
mut reader: MessageReader<GameMessage>,
|
||||
|
||||
currplayer: Res<CurrentPlayer>,
|
||||
drawntile: Single<Entity, With<DrawnTile>>,
|
||||
drawntile: Single<(&DrawnTile, Entity), With<DrawnTile>>,
|
||||
player_hands: Populated<(&Player, &Children), With<Hand>>,
|
||||
hands: Populated<&Children, (With<Hand>, Without<Player>)>,
|
||||
|
||||
|
|
@ -160,17 +165,42 @@ pub(crate) fn discard(
|
|||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
let curr = currplayer.0;
|
||||
let hand_ent = player_hands.get(curr).unwrap().1.iter().next().unwrap();
|
||||
let hand = hands.get(hand_ent).unwrap();
|
||||
let hand = player_hands.get(curr).unwrap().1.iter().next().unwrap();
|
||||
let handtiles = hands.get(hand).unwrap();
|
||||
let (drawntile, drawn_ent) = *drawntile;
|
||||
|
||||
// debug!("discard turn for: {curr:?}");
|
||||
|
||||
while let Some(message) = reader.read().next() {
|
||||
if let GameMessage::Discarded(entity) = message {
|
||||
if *entity == *drawntile {
|
||||
} else if hand.contains(entity) {
|
||||
debug!("{curr:?} discarded: {entity:?}");
|
||||
// commands.entity(drawn_ent).despawn();
|
||||
if *entity == drawntile.0 {
|
||||
} else if handtiles.contains(entity) {
|
||||
commands
|
||||
.entity(hand)
|
||||
.remove_child(*entity)
|
||||
.add_child(drawntile.0);
|
||||
} else {
|
||||
panic!("discarded illegal player tile?")
|
||||
}
|
||||
commands.spawn(DiscardedTile(*entity));
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn ron_chi_pon_kan(
|
||||
curr_turnstate: Res<State<TurnState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
||||
pub(crate) fn end(
|
||||
curr_turnstate: Res<State<TurnState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
next_turnstate.set(curr_turnstate.next());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue