we start printing again
This commit is contained in:
parent
65ea256436
commit
59399c3590
7 changed files with 114 additions and 52 deletions
|
|
@ -32,28 +32,51 @@ impl Plugin for RiichiTui {
|
|||
RatatuiPlugins {
|
||||
// enable_kitty_protocol: todo!(),
|
||||
enable_mouse_capture: true,
|
||||
// enable_input_forwarding: false,
|
||||
enable_input_forwarding: true,
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
.add_plugins(StatesPlugin)
|
||||
// setup console
|
||||
|
||||
// console
|
||||
.init_state::<console::ConsoleState>()
|
||||
.add_systems(Update, console::toggle_console)
|
||||
.add_systems(Update, console::draw_console.run_if(in_state(console::ConsoleState::Open)))
|
||||
// other setup
|
||||
|
||||
// general setup
|
||||
.init_state::<TuiState>()
|
||||
.add_computed_state::<InGame>()
|
||||
.add_systems(Update, curr_state)
|
||||
|
||||
// main menu
|
||||
.add_systems(Update, (menu::draw_mainmenu,menu::mainmenu_input).run_if(in_state(TuiState::MainMenu)))
|
||||
.add_systems(Update, (menu::draw_mainmenu, menu::mainmenu_input).run_if(in_state(TuiState::MainMenu)))
|
||||
|
||||
// gaming
|
||||
.add_systems(Update, render::ingame::draw_ingame.run_if(in_state(TuiState::InGame)))
|
||||
.init_resource::<render::hand::RenderedHand>()
|
||||
.add_systems(OnEnter(GameState::Play), render::hand::render_hand)
|
||||
.add_systems(Update, render::hand::render_changed_hand.run_if(in_state(InGame).and(in_state(GameState::Play))))
|
||||
.add_systems(Update, render::ingame::draw_ingame.run_if(in_state(TuiState::InGame)))
|
||||
|
||||
// semicolon stopper
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
fn curr_state(
|
||||
curr_gamestate: Option<Res<State<GameState>>>,
|
||||
curr_tuistate: Res<State<TuiState>>,
|
||||
curr_ingame: Option<Res<State<InGame>>>,
|
||||
) {
|
||||
if let Some(curr_gamestate) = curr_gamestate && curr_gamestate.is_changed(){
|
||||
trace!("GameState: {curr_gamestate:?}")
|
||||
}
|
||||
if curr_tuistate.is_changed() {
|
||||
trace!("TuiState: {curr_tuistate:?}")
|
||||
}
|
||||
if let Some(curr_ingame) = curr_ingame && curr_ingame.is_changed(){
|
||||
trace!("InGame: {curr_ingame:?}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
struct InGame;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,25 +1,37 @@
|
|||
use bevy::prelude::*;
|
||||
use ratatui::widgets::Paragraph;
|
||||
|
||||
use jong::game::player::HandTiles;
|
||||
use jong::game::hand::HandTiles;
|
||||
use jong::tiles::Tile;
|
||||
|
||||
use crate::tui::render::tiles;
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct RenderedHand<'a>(pub(crate) Vec<Paragraph<'a>>);
|
||||
#[derive(Resource, Default)]
|
||||
pub(crate) struct RenderedHand(pub(crate) Vec<Paragraph<'static>>);
|
||||
|
||||
pub(crate) fn render_changed_hand(
|
||||
hand: Single<&HandTiles, Changed<HandTiles>>,
|
||||
// hand_tiles: Query<&HandTiles, With<Hand>>,
|
||||
tiles: Query<&Tile>,
|
||||
mut target: Single<&'static mut RenderedHand>,
|
||||
tiles: Populated<&Tile>,
|
||||
mut target: ResMut<RenderedHand>,
|
||||
) -> Result {
|
||||
trace!("render_changed_hand");
|
||||
|
||||
render_hand(hand, tiles, target)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn render_hand(
|
||||
hand: Single<&HandTiles, Changed<HandTiles>>,
|
||||
tiles: Populated<&Tile>,
|
||||
mut target: ResMut<RenderedHand>,
|
||||
) -> Result {
|
||||
trace!("render_hand");
|
||||
|
||||
let hand_tiles = hand
|
||||
.iter()
|
||||
.map(|inhand| -> Result<_> { Ok(tiles.get(inhand).map(tiles::draw_tile)?) })
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
target.0 = hand_tiles;
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@ use bevy_ratatui::RatatuiContext;
|
|||
use crate::tui::render::hand;
|
||||
|
||||
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 hand::RenderedHand>,
|
||||
rendered_hand: Res<hand::RenderedHand>,
|
||||
mut tui_ctx: ResMut<RatatuiContext>,
|
||||
) -> Result {
|
||||
use ratatui::layout::Flex;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue