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