render some tiles
This commit is contained in:
parent
bea146d439
commit
d506a25716
8 changed files with 129 additions and 60 deletions
55
src/tui/render.rs
Normal file
55
src/tui/render.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use bevy::ecs::system::SystemParam;
|
||||
use bevy::prelude::*;
|
||||
use bevy_ratatui::RatatuiContext;
|
||||
use ratatui::widgets::Paragraph;
|
||||
|
||||
use jong::game::wall::Wall;
|
||||
use jong::game::wall::WallTiles;
|
||||
use jong::tiles::Tile;
|
||||
|
||||
mod tiles;
|
||||
|
||||
pub(crate) fn draw_ingame(
|
||||
tiles: Query<&Tile>,
|
||||
wall: Option<Single<&WallTiles, With<Wall>>>,
|
||||
mut tui_ctx: ResMut<RatatuiContext>,
|
||||
) -> Result {
|
||||
use ratatui::layout::Flex;
|
||||
use ratatui::prelude::*;
|
||||
|
||||
let title = ratatui::text::Text::raw("tiny riichi");
|
||||
|
||||
let wall = if let Some(wall) = wall {
|
||||
let wall = wall
|
||||
.iter()
|
||||
.map(|inwall| -> Result<_> { Ok(tiles.get(inwall).map(tiles::draw_tile)?) })
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
// let paragraph = Paragraph::new(wall.join(", ")).wrap(ratatui::widgets::Wrap { trim: true });
|
||||
Some(wall)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
tui_ctx.draw(|frame| {
|
||||
// frame.render_widget(title, frame.area());
|
||||
debug!("{}", frame.area());
|
||||
|
||||
if let Some(wall) = wall {
|
||||
// let tile_area = Rect::new(0, 0, 5, 4);
|
||||
let layout = Layout::horizontal(vec![Constraint::Max(5); 13]).flex(Flex::Start);
|
||||
let mut area = frame.area();
|
||||
area.height = 4;
|
||||
let areas = layout.areas::<13>(area);
|
||||
// debug!("wall.len(): {}, areas.len(): {}", wall.len(), areas.len());
|
||||
for (tile, rect) in wall.iter().zip(areas.iter()) {
|
||||
// debug!("{rect:?}");
|
||||
frame.render_widget(tile, *rect);
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue