jong/src/tui/mod.rs

77 lines
2 KiB
Rust
Raw Normal View History

2026-01-08 20:49:19 -08:00
use std::time::Duration;
2026-01-09 06:54:17 -08:00
use bevy::{app::ScheduleRunnerPlugin, prelude::*, state::app::StatesPlugin};
2026-01-09 23:14:29 -08:00
use bevy_ratatui::RatatuiPlugins;
2026-01-11 20:10:30 -08:00
use jong::game::GameState;
2026-01-13 00:01:38 -08:00
// use jong::game::wall::InWall;
2026-01-11 20:10:30 -08:00
2026-01-12 21:07:34 -08:00
2026-01-09 03:34:54 -08:00
mod console;
mod menu;
2026-01-09 23:14:29 -08:00
mod render;
2026-01-13 01:08:14 -08:00
mod input;
2026-01-08 20:49:19 -08:00
2026-01-11 20:10:30 -08:00
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)]
2026-01-12 21:07:34 -08:00
pub(crate) enum TuiState {
2026-01-11 20:10:30 -08:00
#[default]
2026-01-11 22:32:30 -08:00
MainMenu,
2026-01-11 20:10:30 -08:00
InGame,
}
2026-01-12 20:56:30 -08:00
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
struct InGame;
impl ComputedStates for InGame {
type SourceStates = TuiState;
fn compute(sources: Self::SourceStates) -> Option<Self> {
match sources {
TuiState::MainMenu => None,
TuiState::InGame => Some(Self),
}
}
2026-01-11 20:10:30 -08:00
}
2026-01-07 00:51:57 -08:00
2026-01-12 20:56:30 -08:00
#[derive(Default)]
pub struct RiichiTui;
2026-01-08 20:49:19 -08:00
impl Plugin for RiichiTui {
fn build(&self, app: &mut App) {
app.add_plugins((
MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f32(
2026-01-09 03:34:54 -08:00
1. / 60.,
2026-01-08 20:49:19 -08:00
))),
RatatuiPlugins {
// enable_kitty_protocol: todo!(),
enable_mouse_capture: true,
2026-01-12 01:54:59 -08:00
enable_input_forwarding: true,
2026-01-08 20:49:19 -08:00
..Default::default()
},
))
2026-01-09 03:34:54 -08:00
.add_plugins(StatesPlugin)
2026-01-12 01:54:59 -08:00
// console
2026-01-09 03:34:54 -08:00
.init_state::<console::ConsoleState>()
2026-01-13 03:48:53 -08:00
.add_systems(Last, console::draw_console.run_if(in_state(console::ConsoleState::Open)))
2026-01-12 01:54:59 -08:00
// general setup
2026-01-09 23:14:29 -08:00
.init_state::<TuiState>()
.add_computed_state::<InGame>()
2026-01-13 04:11:09 -08:00
.add_systems(PreUpdate, input::keyboard::input_system)
.add_systems(PreUpdate, input::mouse::input_system.chain())
2026-01-12 01:54:59 -08:00
// main menu
2026-01-13 04:11:09 -08:00
.add_systems(Update, menu::draw_mainmenu.run_if(in_state(TuiState::MainMenu)))
2026-01-12 01:54:59 -08:00
// gaming
2026-01-12 01:54:59 -08:00
.init_resource::<render::hand::RenderedHand>()
2026-01-13 04:11:09 -08:00
.add_systems(Update, render::hand::render_hands.run_if(in_state(InGame).and(in_state(GameState::Play))))
.add_systems(Update, render::ingame::draw_ingame.run_if(in_state(InGame)))
2026-01-12 01:54:59 -08:00
2026-01-09 03:34:54 -08:00
// semicolon stopper
;
2026-01-08 20:49:19 -08:00
}
}
2026-01-07 00:51:57 -08:00
2026-01-12 21:07:34 -08:00