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 17:05:56 -08:00
|
|
|
|
|
|
|
|
use crate::tui::render::{WidgetStack, menu::Splash};
|
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;
|
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::InGame => Some(Self),
|
2026-01-13 13:46:10 -08:00
|
|
|
_ => None,
|
2026-01-12 20:56:30 -08:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-11 20:10:30 -08:00
|
|
|
}
|
2026-01-07 00:51:57 -08:00
|
|
|
|
2026-01-13 13:46:10 -08:00
|
|
|
#[derive(SubStates, Default, Clone, Copy, PartialEq, Eq, Hash, Debug,)]
|
|
|
|
|
#[source(TuiState = TuiState::MainMenu)]
|
|
|
|
|
pub(crate) enum ZenState {
|
|
|
|
|
#[default]
|
|
|
|
|
Menu,
|
|
|
|
|
Zen,
|
|
|
|
|
}
|
|
|
|
|
|
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!(),
|
2026-01-11 23:41:27 -08:00
|
|
|
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
|
|
|
|
|
|
|
|
// general setup
|
2026-01-09 23:14:29 -08:00
|
|
|
.init_state::<TuiState>()
|
2026-01-11 23:41:27 -08:00
|
|
|
.add_computed_state::<InGame>()
|
2026-01-13 17:05:56 -08:00
|
|
|
.init_resource::<WidgetStack>()
|
|
|
|
|
.add_sub_state::<ZenState>()
|
|
|
|
|
.init_resource::<Splash>()
|
|
|
|
|
.init_state::<console::ConsoleState>()
|
|
|
|
|
.add_systems(PostUpdate, console::draw_console.run_if(in_state(console::ConsoleState::Open)))
|
|
|
|
|
|
|
|
|
|
// input
|
2026-01-13 04:11:09 -08:00
|
|
|
.add_systems(PreUpdate, input::keyboard::input_system)
|
2026-01-13 17:05:56 -08:00
|
|
|
.add_systems(PreUpdate, input::mouse::input_system)
|
2026-01-12 01:54:59 -08:00
|
|
|
|
2026-01-11 23:41:27 -08:00
|
|
|
// main menu
|
2026-01-13 17:05:56 -08:00
|
|
|
.add_systems(PostStartup, render::menu::init_splash)
|
|
|
|
|
.insert_resource(Time::<Fixed>::from_seconds(1.0))
|
|
|
|
|
.add_systems(FixedUpdate, render::menu::render_splash.run_if(in_state(TuiState::MainMenu)))
|
|
|
|
|
.add_systems(Update, render::menu::draw_splash.run_if(in_state(TuiState::MainMenu)))
|
|
|
|
|
.add_systems(Update, render::menu::draw_mainmenu.after(render::menu::draw_splash).run_if(in_state(TuiState::MainMenu).and(in_state(ZenState::Menu))))
|
2026-01-12 01:54:59 -08:00
|
|
|
|
2026-01-11 23:41:27 -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-13 17:05:56 -08:00
|
|
|
|
|
|
|
|
// render
|
|
|
|
|
.add_systems(Last, render::draw_system.run_if(not(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
|
|
|
|