diff --git a/src/game.rs b/src/game.rs index 28f1923..180a839 100644 --- a/src/game.rs +++ b/src/game.rs @@ -4,8 +4,9 @@ use crossterm::event::{Event, KeyCode}; use ratatui::{ Frame, buffer::{Buffer, Cell}, - layout::Rect, + layout::{Constraint, Layout, Rect}, style::Color, + text::{Line, Text}, widgets::{Block, Widget}, }; @@ -81,14 +82,14 @@ impl Tile { ..self } } - + fn may_enter(&self) -> bool { match self.style { TileStyle::Wall => false, _ => true, } } - + fn dashtination(&self) -> bool { self.action.is_some() } @@ -129,7 +130,8 @@ impl GameModel { tiles.get_mut(P2::new(2, 2)).map(|tile| { *tile = Tile::new(TileStyle::Portal(Portal { kind: PortalKind::Ladder, - })).with_action(GameEvent::Navigate(NavigationTarget::Parent)) + })) + .with_action(GameEvent::Navigate(NavigationTarget::Parent)) }); } @@ -138,15 +140,24 @@ impl GameModel { tiles.get_mut(P2::new(10, 2 + i as isize)).map(|tile| { *tile = Tile::new(TileStyle::Portal(Portal { kind: PortalKind::Portal, - })).with_action(GameEvent::Navigate(NavigationTarget::Path(entry.clone()))) + })) + .with_action( + GameEvent::Navigate(NavigationTarget::Path(entry.clone())), + ) }); } else { - tiles.get_mut(P2::new(10, 2 + i as isize)).map(|tile| { - *tile = Tile::new(TileStyle::Box) - }); + tiles + .get_mut(P2::new(10, 2 + i as isize)) + .map(|tile| *tile = Tile::new(TileStyle::Box)); } - for (j, c) in entry.file_name().unwrap().to_string_lossy().chars().enumerate() { + for (j, c) in entry + .file_name() + .unwrap() + .to_string_lossy() + .chars() + .enumerate() + { tiles .get_mut(P2::new(11 + j as isize, 2 + i as isize)) .map(|tile| *tile = Tile::new(TileStyle::Char(c))); @@ -166,7 +177,6 @@ impl GameModel { } fn update_game(self, event: GameEvent) -> Result { - match event { GameEvent::Quit => Err(self.path), GameEvent::Nop => Ok(self), @@ -199,11 +209,15 @@ impl GameModel { Ok(Self { player_pos, ..self }) } GameEvent::Interact => { - let opt_action = self.room.tiles.get(self.player_pos).and_then(|tile| tile.action.clone()); + let opt_action = self + .room + .tiles + .get(self.player_pos) + .and_then(|tile| tile.action.clone()); if let Some(action) = opt_action { self.update_game(action) - } else { + } else { Ok(self) } } @@ -218,18 +232,37 @@ impl GameModel { } pub fn render(&self, frame: &mut Frame) { - let camera_block = Block::bordered().title("camera"); - let camera_area = camera_block.inner(frame.area()); + let layout = + Layout::vertical([Constraint::Fill(1), Constraint::Length(3)]).split(frame.area()); + + let camera_block_area = layout[0]; + let info_block_area = layout[1]; + + let camera_block = Block::bordered() + .title("camera") + .title_bottom(Line::from("move: h, j, k, l enter: e up: r quit: q").right_aligned()); + let camera_area = camera_block.inner(camera_block_area); let camera = CameraWidget::new(self); - frame.render_widget(camera_block, frame.area()); + let info_block = Block::bordered().title("cwd"); + let info_area = info_block.inner(info_block_area); + let info = Text::raw(self.path.to_string_lossy()); + + frame.render_widget(camera_block, camera_block_area); frame.render_widget(camera, camera_area); + + frame.render_widget(info_block, info_block_area); + frame.render_widget(info, info_area); } fn render_tiles(&self) -> Grid { - let mut tiles = Grid::from_fn(self.room.tiles.dims.x, - self.room.tiles.dims.y, |x, y| { - self.room.tiles.get(P2::new(x as isize, y as isize)).unwrap().style.clone() + let mut tiles = Grid::from_fn(self.room.tiles.dims.x, self.room.tiles.dims.y, |x, y| { + self.room + .tiles + .get(P2::new(x as isize, y as isize)) + .unwrap() + .style + .clone() }); tiles