2026-01-09 23:14:29 -08:00
|
|
|
use bevy::ecs::system::SystemParam;
|
|
|
|
|
use bevy::prelude::*;
|
|
|
|
|
use bevy_ratatui::RatatuiContext;
|
|
|
|
|
use ratatui::widgets::Paragraph;
|
|
|
|
|
|
2026-01-11 20:10:30 -08:00
|
|
|
use jong::{
|
|
|
|
|
game::{
|
|
|
|
|
player::{Hand, HandTiles},
|
|
|
|
|
wall::{Wall, WallTiles},
|
|
|
|
|
},
|
|
|
|
|
tiles::Tile,
|
|
|
|
|
};
|
2026-01-09 23:14:29 -08:00
|
|
|
|
|
|
|
|
mod tiles;
|
|
|
|
|
|
2026-01-11 20:10:30 -08:00
|
|
|
#[derive(Component)]
|
|
|
|
|
pub(crate) struct RenderedHand<'a>(Vec<Paragraph<'a>>);
|
|
|
|
|
|
|
|
|
|
pub(crate) fn render_changed_hand(
|
|
|
|
|
hand: Single<&HandTiles, Changed<HandTiles>>,
|
|
|
|
|
// hand_tiles: Query<&HandTiles, With<Hand>>,
|
2026-01-09 23:14:29 -08:00
|
|
|
tiles: Query<&Tile>,
|
2026-01-11 20:10:30 -08:00
|
|
|
mut target: Single<&'static mut RenderedHand>,
|
|
|
|
|
) -> Result {
|
|
|
|
|
let hand_tiles = hand
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|inhand| -> Result<_> { Ok(tiles.get(inhand).map(tiles::draw_tile)?) })
|
|
|
|
|
.collect::<Result<Vec<_>>>()?;
|
|
|
|
|
|
|
|
|
|
target.0 = hand_tiles;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn draw_ingame(
|
|
|
|
|
// tiles: Query<&Tile>,
|
|
|
|
|
// wall_tiles: Option<Single<&WallTiles, With<Wall>>>,
|
|
|
|
|
// hand_tiles: Query<&HandTiles, With<Hand>>,
|
|
|
|
|
rendered_hand: Single<&'static RenderedHand>,
|
2026-01-09 23:14:29 -08:00
|
|
|
mut tui_ctx: ResMut<RatatuiContext>,
|
|
|
|
|
) -> Result {
|
|
|
|
|
use ratatui::layout::Flex;
|
|
|
|
|
use ratatui::prelude::*;
|
|
|
|
|
|
2026-01-11 20:10:30 -08:00
|
|
|
// let title = ratatui::text::Text::raw("tiny riichi");
|
2026-01-09 23:14:29 -08:00
|
|
|
|
2026-01-11 20:10:30 -08:00
|
|
|
// let wall = if let Some(wall_tiles) = wall_tiles {
|
|
|
|
|
// let wall_tiles = wall_tiles
|
|
|
|
|
// .iter()
|
|
|
|
|
// .map(|inwall| -> Result<_> { Ok(tiles.get(inwall).map(tiles::draw_tile)?) })
|
|
|
|
|
// .collect::<Result<Vec<_>>>()?;
|
2026-01-09 23:14:29 -08:00
|
|
|
|
2026-01-11 20:10:30 -08:00
|
|
|
// // let paragraph = Paragraph::new(wall.join(", ")).wrap(ratatui::widgets::Wrap { trim: true });
|
|
|
|
|
// Some(wall_tiles)
|
|
|
|
|
// } else {
|
|
|
|
|
// None
|
|
|
|
|
// };
|
2026-01-09 23:14:29 -08:00
|
|
|
|
|
|
|
|
tui_ctx.draw(|frame| {
|
|
|
|
|
// frame.render_widget(title, frame.area());
|
|
|
|
|
debug!("{}", frame.area());
|
|
|
|
|
|
2026-01-11 20:10:30 -08:00
|
|
|
// 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);
|
|
|
|
|
for (tile, area) in rendered_hand.0.iter().zip(areas.iter()) {
|
|
|
|
|
frame.render_widget(tile, *area);
|
2026-01-09 23:14:29 -08:00
|
|
|
}
|
2026-01-11 20:10:30 -08:00
|
|
|
|
|
|
|
|
// // 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);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2026-01-09 23:14:29 -08:00
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|