spawn each player and hand
This commit is contained in:
parent
50fd406dbf
commit
f6bd7fd6f7
3 changed files with 79 additions and 75 deletions
|
|
@ -228,6 +228,8 @@ fn view_hand(
|
|||
// trace!("view_hand");
|
||||
if let Some(view) = stdb.db().view_player_hand().iter().next() {
|
||||
let mut view = view.tiles.iter().map(Tile::from).collect::<Vec<_>>();
|
||||
// view.sort();
|
||||
debug!("view: {view:?}");
|
||||
|
||||
let tiles = tiles
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ pub(crate) fn render(
|
|||
// // trace!("arg!");
|
||||
// }
|
||||
|
||||
// FIXME we don't care about other players atm
|
||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||
pub(crate) fn render_hands(
|
||||
mut commands: Commands,
|
||||
|
|
@ -124,7 +125,7 @@ pub(crate) fn render_hands(
|
|||
main_player: Single<(&Player, Entity /* , &Wind */), With<MainPlayer>>,
|
||||
curr_player: Single<Entity, With<CurrentPlayer>>,
|
||||
players: Query<(&Player, Entity, &Children)>,
|
||||
hands: Query<(&Children, Entity), (With<Hand>, Without<Player>)>,
|
||||
hands: Query<(&Children, Entity), With<Hand>>,
|
||||
// drawn_tile: Single<Entity, With<Drawn>>,
|
||||
) -> Result {
|
||||
let mut frame = tui.get_frame();
|
||||
|
|
@ -132,10 +133,10 @@ pub(crate) fn render_hands(
|
|||
|
||||
for (hand, hand_ent) in hands {
|
||||
// debug!("{hand:?}");
|
||||
let (player, player_ent, _) = players
|
||||
.iter()
|
||||
.find(|(_, e, c)| c.contains(&hand_ent))
|
||||
.unwrap();
|
||||
// let (player, player_ent, _) = players
|
||||
// .iter()
|
||||
// .find(|(_, e, c)| c.contains(&hand_ent))
|
||||
// .unwrap();
|
||||
let hand: Vec<_> = hand
|
||||
.iter()
|
||||
.map(|entity| -> Result<_> {
|
||||
|
|
@ -147,80 +148,81 @@ pub(crate) fn render_hands(
|
|||
})
|
||||
.collect::<Result<_>>()?;
|
||||
|
||||
if player == main_player.0 {
|
||||
// split main box into thirds
|
||||
let mut this_hand = layouts.this_hand;
|
||||
// let this_drawer = drawn_tile..is_some_and(|dt| dt.0 == player);
|
||||
let this_drawer = player_ent == *curr_player;
|
||||
let tile_drawn = if this_drawer { 7 } else { 0 };
|
||||
let hand_draw_meld = Layout::horizontal([
|
||||
Constraint::Max(hand.len() as u16 * 5),
|
||||
Constraint::Max(tile_drawn),
|
||||
Constraint::Fill(1),
|
||||
])
|
||||
.flex(Flex::SpaceBetween);
|
||||
this_hand = this_hand.offset(Offset {
|
||||
x: 0,
|
||||
y: this_hand.height.abs_diff(5) as i32 + 1,
|
||||
});
|
||||
this_hand = this_hand.resize(Size {
|
||||
width: this_hand.width,
|
||||
height: 4,
|
||||
});
|
||||
let [hand_area, drawn_area, meld_area] = hand_draw_meld.areas::<3>(this_hand);
|
||||
let (player, player_ent) = *main_player;
|
||||
// if player == main_player.0 {
|
||||
// split main box into thirds
|
||||
let mut this_hand = layouts.this_hand;
|
||||
// let this_drawer = drawn_tile..is_some_and(|dt| dt.0 == player);
|
||||
let this_drawer = player_ent == *curr_player;
|
||||
let tile_drawn = if this_drawer { 7 } else { 0 };
|
||||
let hand_draw_meld = Layout::horizontal([
|
||||
Constraint::Max(hand.len() as u16 * 5),
|
||||
Constraint::Max(tile_drawn),
|
||||
Constraint::Fill(1),
|
||||
])
|
||||
.flex(Flex::SpaceBetween);
|
||||
this_hand = this_hand.offset(Offset {
|
||||
x: 0,
|
||||
y: this_hand.height.abs_diff(5) as i32 + 1,
|
||||
});
|
||||
this_hand = this_hand.resize(Size {
|
||||
width: this_hand.width,
|
||||
height: 4,
|
||||
});
|
||||
let [hand_area, drawn_area, meld_area] = hand_draw_meld.areas::<3>(this_hand);
|
||||
|
||||
// split hand area into tile areas
|
||||
let mut constraints = vec![Constraint::Max(5); hand.len()];
|
||||
constraints.push(Constraint::Fill(1));
|
||||
let layout = Layout::horizontal(constraints).flex(Flex::Start);
|
||||
let tile_areas = layout.split(hand_area);
|
||||
// split hand area into tile areas
|
||||
let mut constraints = vec![Constraint::Max(5); hand.len()];
|
||||
constraints.push(Constraint::Fill(1));
|
||||
let layout = Layout::horizontal(constraints).flex(Flex::Start);
|
||||
let tile_areas = layout.split(hand_area);
|
||||
|
||||
for ((entity, widget, hovered), mut area) in
|
||||
hand.into_iter().zip(tile_areas.iter().copied())
|
||||
{
|
||||
if hovered {
|
||||
area = area.offset(Offset { x: 0, y: -1 });
|
||||
let mut hitbox = area.as_size();
|
||||
hitbox.height += 1;
|
||||
commands.entity(entity).insert(PickRegion {
|
||||
area: area.resize(hitbox),
|
||||
});
|
||||
} else {
|
||||
commands.entity(entity).insert(PickRegion { area });
|
||||
}
|
||||
frame.render_widget(widget, area);
|
||||
for ((entity, widget, hovered), mut area) in
|
||||
hand.into_iter().zip(tile_areas.iter().copied())
|
||||
{
|
||||
if hovered {
|
||||
area = area.offset(Offset { x: 0, y: -1 });
|
||||
let mut hitbox = area.as_size();
|
||||
hitbox.height += 1;
|
||||
commands.entity(entity).insert(PickRegion {
|
||||
area: area.resize(hitbox),
|
||||
});
|
||||
} else {
|
||||
commands.entity(entity).insert(PickRegion { area });
|
||||
}
|
||||
|
||||
// tsumo tile
|
||||
// if this_drawer {
|
||||
// // trace!("this_drawer");
|
||||
// let mut area = drawn_area.resize(Size {
|
||||
// width: 5,
|
||||
// height: 4,
|
||||
// });
|
||||
// area = area.offset(Offset { x: 2, y: 0 });
|
||||
// let hovered = hovered.contains(*drawn_tile);
|
||||
// let widget = render_tile(tiles.get(*drawn_tile)?, hovered);
|
||||
// if hovered {
|
||||
// area = area.offset(Offset { x: 0, y: -1 });
|
||||
// let mut hitbox = area.as_size();
|
||||
// hitbox.height += 1;
|
||||
// commands.entity(*drawn_tile).insert(PickRegion {
|
||||
// area: area.resize(hitbox),
|
||||
// });
|
||||
// } else {
|
||||
// commands.entity(*drawn_tile).insert(PickRegion { area });
|
||||
// }
|
||||
// frame.render_widget(widget, area);
|
||||
// }
|
||||
// TODO draw melds
|
||||
} else {
|
||||
// match mainplayer.1.relate(wind) {
|
||||
// jong::game::round::WindRelation::Shimocha => todo!(),
|
||||
// jong::game::round::WindRelation::Toimen => todo!(),
|
||||
// jong::game::round::WindRelation::Kamicha => todo!(),
|
||||
// }
|
||||
frame.render_widget(widget, area);
|
||||
}
|
||||
|
||||
// tsumo tile
|
||||
// if this_drawer {
|
||||
// // trace!("this_drawer");
|
||||
// let mut area = drawn_area.resize(Size {
|
||||
// width: 5,
|
||||
// height: 4,
|
||||
// });
|
||||
// area = area.offset(Offset { x: 2, y: 0 });
|
||||
// let hovered = hovered.contains(*drawn_tile);
|
||||
// let widget = render_tile(tiles.get(*drawn_tile)?, hovered);
|
||||
// if hovered {
|
||||
// area = area.offset(Offset { x: 0, y: -1 });
|
||||
// let mut hitbox = area.as_size();
|
||||
// hitbox.height += 1;
|
||||
// commands.entity(*drawn_tile).insert(PickRegion {
|
||||
// area: area.resize(hitbox),
|
||||
// });
|
||||
// } else {
|
||||
// commands.entity(*drawn_tile).insert(PickRegion { area });
|
||||
// }
|
||||
// frame.render_widget(widget, area);
|
||||
// }
|
||||
// TODO draw melds
|
||||
// } else {
|
||||
// match mainplayer.1.relate(wind) {
|
||||
// jong::game::round::WindRelation::Shimocha => todo!(),
|
||||
// jong::game::round::WindRelation::Toimen => todo!(),
|
||||
// jong::game::round::WindRelation::Kamicha => todo!(),
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue