render some tiles
This commit is contained in:
parent
bea146d439
commit
d506a25716
8 changed files with 129 additions and 60 deletions
|
|
@ -1,11 +1,13 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use bevy::{app::ScheduleRunnerPlugin, prelude::*, state::app::StatesPlugin};
|
||||
use bevy_ratatui::{RatatuiContext, RatatuiPlugins};
|
||||
use jong::{game::wall::Wall, tiles::Tile};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use bevy_ratatui::RatatuiPlugins;
|
||||
use jong::tiles::InWall;
|
||||
use ratatui::{text::ToSpan, widgets::Paragraph};
|
||||
|
||||
mod console;
|
||||
mod input;
|
||||
mod render;
|
||||
|
||||
pub struct RiichiTui;
|
||||
|
||||
|
|
@ -26,50 +28,17 @@ impl Plugin for RiichiTui {
|
|||
.init_state::<console::ConsoleState>()
|
||||
.add_systems(Update, console::toggle_console)
|
||||
.add_systems(Update, console::draw_console.run_if(in_state(console::ConsoleState::Open)))
|
||||
.init_state::<TuiState>()
|
||||
.add_systems(Update, input::keyboard_input_system)
|
||||
.add_systems(Update, draw_system)
|
||||
.add_systems(Update, render::draw_ingame.run_if(in_state(TuiState::InGame)))
|
||||
// semicolon stopper
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States)]
|
||||
// enum TuiState {
|
||||
// MainMenu,
|
||||
// InGame,
|
||||
// }
|
||||
|
||||
pub(crate) fn draw_system(
|
||||
// mut commands: Commands,
|
||||
wall: Option<Single<&Wall>>,
|
||||
tiles: Option<Populated<&Tile>>,
|
||||
mut tui_ctx: ResMut<RatatuiContext>,
|
||||
) -> Result {
|
||||
let title = ratatui::text::Text::raw("tiny riichi");
|
||||
let wall = if let Some(wall) = wall {
|
||||
let text = (*wall)
|
||||
.iter()
|
||||
.map(|c| {
|
||||
tiles
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.get(c)
|
||||
.map(|tile| format!("{tile:?}"))
|
||||
})
|
||||
.collect::<Result<String, _>>()?;
|
||||
|
||||
Some(Paragraph::new(text))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
tui_ctx.draw(|frame| {
|
||||
frame.render_widget(title, frame.area());
|
||||
|
||||
if let Some(wall) = wall {
|
||||
frame.render_widget(wall, frame.area());
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)]
|
||||
enum TuiState {
|
||||
MainMenu,
|
||||
#[default]
|
||||
InGame,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue