remove old
This commit is contained in:
parent
2b95c642df
commit
c06408a825
10 changed files with 0 additions and 634 deletions
|
|
@ -1,91 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::crossterm::event::KeyCode;
|
||||
use bevy_ratatui::event::KeyMessage;
|
||||
|
||||
use jong::game::GameState;
|
||||
|
||||
use crate::tui::states::*;
|
||||
|
||||
// TODO change this to handle console open request, esc for menu, etc, then
|
||||
// route other messages to other systems
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn input_system(
|
||||
mut messages: MessageReader<KeyMessage>,
|
||||
|
||||
curr_tuistate: Res<State<TuiState>>,
|
||||
curr_consolestate: Res<State<ConsoleState>>,
|
||||
curr_gamestate: Res<State<GameState>>,
|
||||
curr_zenstate: Option<Res<State<ZenState>>>,
|
||||
|
||||
mut next_tuistate: ResMut<NextState<TuiState>>,
|
||||
mut next_consolestate: ResMut<NextState<ConsoleState>>,
|
||||
mut next_gamestate: ResMut<NextState<GameState>>,
|
||||
mut next_zenstate: ResMut<NextState<ZenState>>,
|
||||
|
||||
mut exit: MessageWriter<AppExit>,
|
||||
) {
|
||||
let (ts, cs, gs) = (
|
||||
curr_tuistate.get(),
|
||||
curr_consolestate.get(),
|
||||
curr_gamestate.get(),
|
||||
);
|
||||
|
||||
for message in messages.read() {
|
||||
if let KeyCode::Char('`') = message.code {
|
||||
next_consolestate.set(!*curr_consolestate.get());
|
||||
continue;
|
||||
}
|
||||
|
||||
if *cs == ConsoleState::Open {
|
||||
let mut passthrough = false;
|
||||
match message.code {
|
||||
KeyCode::Up => todo!(),
|
||||
KeyCode::Down => todo!(),
|
||||
KeyCode::Home => todo!(),
|
||||
KeyCode::End => todo!(),
|
||||
KeyCode::PageUp => todo!(),
|
||||
KeyCode::PageDown => todo!(),
|
||||
KeyCode::Esc => next_consolestate.set(ConsoleState::Closed),
|
||||
_ => passthrough = true,
|
||||
}
|
||||
if !passthrough {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
match ts {
|
||||
TuiState::MainMenu => match message.code {
|
||||
KeyCode::Char('p') => {
|
||||
next_tuistate.set(TuiState::InGame);
|
||||
next_gamestate.set(GameState::Setup);
|
||||
}
|
||||
KeyCode::Char('z') => {
|
||||
if let Some(ref curr_zenstate) = curr_zenstate {
|
||||
match curr_zenstate.get() {
|
||||
ZenState::Menu => next_zenstate.set(ZenState::Zen),
|
||||
ZenState::Zen => next_zenstate.set(ZenState::Menu),
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Char('q') => {
|
||||
exit.write_default();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
TuiState::InGame => match gs {
|
||||
GameState::Setup => match message.code {
|
||||
_ => {}
|
||||
},
|
||||
GameState::Play => match message.code {
|
||||
KeyCode::Char('q') => {
|
||||
exit.write_default();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => todo!(),
|
||||
_ => unreachable!("TuiState::InGame but GameState invalid"),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
pub(crate) mod keyboard;
|
||||
pub(crate) mod mouse;
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::{RatatuiContext, event::MouseMessage};
|
||||
use ratatui::layout::Position;
|
||||
|
||||
use crate::tui::render::Hovered;
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct PickRegion {
|
||||
pub(crate) area: ratatui::prelude::Rect,
|
||||
}
|
||||
|
||||
// enum PickEvent {
|
||||
// Click { col: u16, row: u16 },
|
||||
// Hover { col: u16, row: u16 },
|
||||
// }
|
||||
|
||||
pub(crate) fn input_system(
|
||||
mut commands: Commands,
|
||||
mut messages: MessageReader<MouseMessage>,
|
||||
entities: Query<(Entity, &PickRegion)>,
|
||||
hovered: Query<(Entity, &PickRegion), With<Hovered>>,
|
||||
) -> Result {
|
||||
for message in messages.read() {
|
||||
let event = message.0;
|
||||
// let term_size = context.size().unwrap();
|
||||
let position = Position::new(event.column, event.row);
|
||||
match event.kind {
|
||||
ratatui::crossterm::event::MouseEventKind::Down(mouse_button) => match mouse_button {
|
||||
ratatui::crossterm::event::MouseButton::Left => {
|
||||
for (_entity, _region) in &entities {}
|
||||
}
|
||||
// ratatui::crossterm::event::MouseButton::Right => todo!(),
|
||||
// ratatui::crossterm::event::MouseButton::Middle => todo!(),
|
||||
_ => {}
|
||||
},
|
||||
// ratatui::crossterm::event::MouseEventKind::Up(mouse_button) => todo!(),
|
||||
// ratatui::crossterm::event::MouseEventKind::Drag(mouse_button) => todo!(),
|
||||
ratatui::crossterm::event::MouseEventKind::Moved => {
|
||||
for (entity, region) in &hovered {
|
||||
if !region.area.contains(position) {
|
||||
commands.get_entity(entity)?.remove::<Hovered>();
|
||||
}
|
||||
}
|
||||
for (entity, region) in &entities {
|
||||
// debug!(
|
||||
// "{:?}, {position:?}",
|
||||
// region.area.positions().collect::<Vec<_>>()
|
||||
// );
|
||||
if region.area.contains(position) {
|
||||
commands.get_entity(entity)?.insert(Hovered);
|
||||
// trace!("{entity:?} hovered!")
|
||||
}
|
||||
}
|
||||
}
|
||||
// ratatui::crossterm::event::MouseEventKind::ScrollDown => todo!(),
|
||||
// ratatui::crossterm::event::MouseEventKind::ScrollUp => todo!(),
|
||||
// ratatui::crossterm::event::MouseEventKind::ScrollLeft => todo!(),
|
||||
// ratatui::crossterm::event::MouseEventKind::ScrollRight => todo!(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use bevy::{app::ScheduleRunnerPlugin, prelude::*, state::app::StatesPlugin};
|
||||
use bevy_ratatui::RatatuiPlugins;
|
||||
|
||||
use jong::game::GameState;
|
||||
|
||||
use crate::tui::render::{WidgetStack, menu::Splash};
|
||||
use states::*;
|
||||
|
||||
mod render;
|
||||
mod input;
|
||||
mod states;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RiichiTui;
|
||||
impl Plugin for RiichiTui {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins((
|
||||
MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f32(
|
||||
1. / 60.,
|
||||
))),
|
||||
RatatuiPlugins {
|
||||
// enable_kitty_protocol: todo!(),
|
||||
enable_mouse_capture: true,
|
||||
enable_input_forwarding: true,
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
.add_plugins(StatesPlugin)
|
||||
|
||||
// general setup
|
||||
.init_state::<TuiState>()
|
||||
.add_computed_state::<InGame>()
|
||||
.init_resource::<WidgetStack>()
|
||||
.add_sub_state::<ZenState>()
|
||||
.init_resource::<Splash>()
|
||||
.init_state::<ConsoleState>()
|
||||
.add_systems(PostUpdate, render::draw_console.run_if(in_state(ConsoleState::Open)))
|
||||
|
||||
// input
|
||||
.add_systems(PreUpdate, input::keyboard::input_system)
|
||||
.add_systems(PreUpdate, input::mouse::input_system)
|
||||
|
||||
// main menu
|
||||
.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))))
|
||||
|
||||
// gaming
|
||||
.init_resource::<render::hand::RenderedHand>()
|
||||
.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)))
|
||||
|
||||
// render
|
||||
.add_systems(Last, render::draw_system.run_if(not(in_state(InGame))))
|
||||
|
||||
// semicolon stopper
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
use bevy::{platform::collections::HashMap, prelude::*};
|
||||
|
||||
use jong::{
|
||||
game::{hand::Hand, player::Player},
|
||||
tile::Tile,
|
||||
};
|
||||
|
||||
use crate::tui::render::tile::{self, RenderedTile};
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub(crate) struct RenderedHand(pub(crate) HashMap<Entity, Vec<Entity>>);
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub(crate) fn render_hands(
|
||||
mut commands: Commands,
|
||||
mut rendered_hand: ResMut<RenderedHand>,
|
||||
tiles: Populated<&Tile>,
|
||||
player_hands: Populated<(Entity, &Children), (With<Player>, Changed<Hand>)>,
|
||||
hands: Populated<&Children, (Changed<Hand>, Without<Player>)>,
|
||||
) -> Result {
|
||||
let mut rendered = HashMap::new();
|
||||
|
||||
for (player_ent, hand) in player_hands {
|
||||
let hand = hand.iter().next().unwrap();
|
||||
let tiles = hands
|
||||
.get(hand)?
|
||||
.iter()
|
||||
.map(|it| {
|
||||
tiles
|
||||
.get(it)
|
||||
// .inspect(|t| debug!("{t:?}"))
|
||||
.map(tile::draw_tile)
|
||||
.map(|p| commands.spawn(RenderedTile(p)).id())
|
||||
// .inspect(|e| debug!("{e:?}"))
|
||||
.unwrap()
|
||||
})
|
||||
.collect();
|
||||
rendered.insert(player_ent, tiles);
|
||||
}
|
||||
|
||||
rendered_hand.0 = rendered;
|
||||
|
||||
trace!("render_hands");
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::RatatuiContext;
|
||||
use jong::game::hand::DrawnTile;
|
||||
use jong::game::player::{MainPlayer, Player};
|
||||
use jong::tile::Tile;
|
||||
use ratatui::widgets::{Block, Borders};
|
||||
|
||||
use crate::tui::render::WidgetStack;
|
||||
use crate::tui::render::tile::draw_tile;
|
||||
use crate::tui::{
|
||||
input::mouse::PickRegion,
|
||||
render::{Hovered, hand, tile::RenderedTile},
|
||||
};
|
||||
|
||||
pub(crate) fn draw_system(
|
||||
mut tui_ctx: ResMut<RatatuiContext>,
|
||||
mut widgets: ResMut<WidgetStack>,
|
||||
) -> Result {
|
||||
tui_ctx.draw(|frame| {
|
||||
for widget in widgets.0.drain(..) {
|
||||
widget(frame)
|
||||
}
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn draw_ingame(
|
||||
mut commands: Commands,
|
||||
mut tui_ctx: ResMut<RatatuiContext>,
|
||||
tiles: Query<&Tile>,
|
||||
hovered_entity: Query<Entity, With<Hovered>>,
|
||||
main_player: Single<Entity, (With<Player>, With<MainPlayer>)>,
|
||||
rendered_tiles: Populated<&RenderedTile>,
|
||||
rendered_hand: Res<hand::RenderedHand>,
|
||||
drawn_tile: Option<Single<&DrawnTile, With<MainPlayer>>>,
|
||||
) -> Result {
|
||||
use ratatui::layout::Flex;
|
||||
use ratatui::prelude::*;
|
||||
|
||||
tui_ctx.draw(|frame| {
|
||||
// debug!("{}", frame.area());
|
||||
|
||||
let term_area = frame.area();
|
||||
|
||||
// TODO this is gross
|
||||
let constraints = [Constraint::Fill(3), Constraint::Fill(18)];
|
||||
let horizontal_slicer_right = Layout::horizontal(constraints);
|
||||
let vertical_slicer_bottom = Layout::vertical(constraints);
|
||||
let horizontal_slicer_left = Layout::horizontal(constraints.iter().rev());
|
||||
let vertical_slicer_top = Layout::vertical(constraints.iter().rev());
|
||||
let [left_hand, this_hand] = horizontal_slicer_right.areas::<2>(term_area);
|
||||
let [_, left_hand] = vertical_slicer_bottom.areas::<2>(left_hand);
|
||||
let [_, mut this_hand] = vertical_slicer_top.areas::<2>(this_hand);
|
||||
let [cross_hand, right_hand] = horizontal_slicer_left.areas::<2>(term_area);
|
||||
let [right_hand, _] = vertical_slicer_top.areas::<2>(right_hand);
|
||||
let [cross_hand, _] = vertical_slicer_bottom.areas::<2>(cross_hand);
|
||||
|
||||
let margin = Margin::new(
|
||||
(left_hand.width + right_hand.width) / 2,
|
||||
(cross_hand.height + this_hand.height) / 2,
|
||||
);
|
||||
let pond_area = term_area.inner(margin);
|
||||
let all_pond = Layout::horizontal([Constraint::Fill(1); 3]);
|
||||
let cross_pond =
|
||||
Layout::vertical([Constraint::Fill(1), Constraint::Max(1), Constraint::Fill(1)]);
|
||||
let [mut left_pond, center, mut right_pond] = all_pond.areas::<3>(pond_area);
|
||||
let [cross_pond, _compass, this_pond] = cross_pond.areas::<3>(center);
|
||||
// let shift = left_pond.height - cross_pond.height;
|
||||
left_pond.height = cross_pond.height;
|
||||
left_pond.y += cross_pond.height / 2;
|
||||
right_pond.height = cross_pond.height;
|
||||
right_pond.y += cross_pond.height / 2;
|
||||
|
||||
let debug_block = Block::new().borders(Borders::ALL);
|
||||
frame.render_widget(debug_block.clone(), this_hand);
|
||||
frame.render_widget(debug_block.clone(), left_hand);
|
||||
frame.render_widget(debug_block.clone(), cross_hand);
|
||||
frame.render_widget(debug_block.clone(), right_hand);
|
||||
frame.render_widget(debug_block.clone(), this_pond);
|
||||
frame.render_widget(debug_block.clone(), left_pond);
|
||||
frame.render_widget(debug_block.clone(), cross_pond);
|
||||
frame.render_widget(debug_block.clone(), right_pond);
|
||||
|
||||
// TODO attempt to merge blocks on smol term?
|
||||
if let Some(hand) = rendered_hand.0.get(&*main_player) {
|
||||
let hand_area_layout = Layout::horizontal([
|
||||
Constraint::Max(hand.len() as u16 * 5),
|
||||
Constraint::Max(if drawn_tile.is_some() { 7 } else { 0 }),
|
||||
Constraint::Fill(1),
|
||||
])
|
||||
.flex(Flex::SpaceBetween);
|
||||
let this_clamped = this_hand.height.abs_diff(5);
|
||||
if let Some(_val) = this_hand.height.checked_sub(this_clamped) {
|
||||
this_hand.height = 4
|
||||
} else {
|
||||
// FIXME show error
|
||||
panic!("terminal too small!");
|
||||
}
|
||||
this_hand.y += this_clamped + 1;
|
||||
let [this_hand, mut this_drawn, _this_meld] = hand_area_layout.areas::<3>(this_hand);
|
||||
|
||||
// this_hand
|
||||
let mut constraints = vec![Constraint::Max(5); hand.len()];
|
||||
constraints.push(Constraint::Fill(1));
|
||||
let layout = Layout::horizontal(constraints).flex(Flex::Start);
|
||||
let hand_areas = layout.split(this_hand);
|
||||
for (tile, mut tile_area) in hand.iter().zip(hand_areas.iter().cloned()) {
|
||||
// tile_area.height = 4;
|
||||
let mut widget = rendered_tiles.get(*tile).unwrap().0.clone();
|
||||
if hovered_entity.contains(*tile) {
|
||||
widget = widget.add_modifier(Modifier::BOLD);
|
||||
if let Some(val) = tile_area.y.checked_sub(1) {
|
||||
tile_area.y = val
|
||||
} else {
|
||||
// FIXME show error
|
||||
panic!("terminal too small!");
|
||||
}
|
||||
}
|
||||
commands
|
||||
.entity(*tile)
|
||||
.insert(PickRegion { area: tile_area });
|
||||
frame.render_widget(widget, tile_area);
|
||||
}
|
||||
|
||||
// this_drawn
|
||||
if let Some(tile) = drawn_tile {
|
||||
// this_drawn.height = 4;
|
||||
this_drawn.width = 5;
|
||||
this_drawn.x += 2;
|
||||
let mut widget = draw_tile(tiles.get(tile.0).unwrap());
|
||||
let mut hitbox = this_drawn;
|
||||
if hovered_entity.contains(tile.0) {
|
||||
widget = widget.add_modifier(Modifier::BOLD);
|
||||
if let Some(val) = hitbox.y.checked_sub(1) {
|
||||
hitbox.y = val
|
||||
} else {
|
||||
// FIXME show error
|
||||
panic!("terminal too small!");
|
||||
}
|
||||
hitbox.height += 1;
|
||||
}
|
||||
commands.entity(tile.0).insert(PickRegion { area: hitbox });
|
||||
frame.render_widget(widget, this_drawn);
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::RatatuiContext;
|
||||
use rand::rng;
|
||||
use rand::seq::SliceRandom;
|
||||
use ratatui::layout::Constraint;
|
||||
use ratatui::layout::Flex;
|
||||
use ratatui::layout::Layout;
|
||||
use ratatui::layout::Margin;
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::widgets::{Block, Clear};
|
||||
|
||||
use jong::tile::Tile;
|
||||
|
||||
use crate::tui::render::WidgetStack;
|
||||
use crate::tui::render::tile;
|
||||
|
||||
const MAINMENU_OPTIONS: [&str; 2] = [
|
||||
" ██╗██████╗ ██╗ ██╗ █████╗ ██╗ ██╗██╗
|
||||
██╔╝██╔══██╗╚██╗██║ ██╔══██╗╚██╗ ██╔╝██║
|
||||
██║ ██████╔╝ ██║██║ ███████║ ╚████╔╝ ██║
|
||||
██║ ██╔═══╝ ██║██║ ██╔══██║ ╚██╔╝ ╚═╝
|
||||
╚██╗██║ ██╔╝███████╗██║ ██║ ██║ ██╗
|
||||
╚═╝╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝
|
||||
",
|
||||
" ██╗ ██████╗ ██╗ ██╗ ██╗██╗████████╗ ██╗
|
||||
██╔╝██╔═══██╗╚██╗██║ ██║██║╚══██╔══╝██╗██╔╝
|
||||
██║ ██║ ██║ ██║██║ ██║██║ ██║ ╚═╝██║
|
||||
██║ ██║▄▄ ██║ ██║██║ ██║██║ ██║ ██╗██║
|
||||
╚██╗╚██████╔╝██╔╝╚██████╔╝██║ ██║ ╚═╝╚██╗
|
||||
╚═╝ ╚══▀▀═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝
|
||||
",
|
||||
];
|
||||
|
||||
pub(crate) fn draw_mainmenu(mut widgets: ResMut<WidgetStack>) {
|
||||
let options = MAINMENU_OPTIONS;
|
||||
let layout =
|
||||
Layout::vertical(vec![Constraint::Fill(1); options.len()]).flex(Flex::SpaceBetween);
|
||||
let block = Block::bordered();
|
||||
|
||||
widgets.0.push(Box::new(move |frame| {
|
||||
let area = frame
|
||||
.area()
|
||||
.centered(Constraint::Max(55), Constraint::Max(19));
|
||||
frame.render_widget(Clear, area);
|
||||
frame.render_widget(block, area);
|
||||
let areas = layout.split(area.centered(Constraint::Max(45), Constraint::Max(14)));
|
||||
for (opt, area) in options.into_iter().zip(areas.iter()) {
|
||||
let para = Paragraph::new(opt);
|
||||
frame.render_widget(para, *area)
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub(crate) struct Splash(pub Vec<Paragraph<'static>>);
|
||||
|
||||
pub(crate) fn init_splash(mut commands: Commands, tiles: Populated<&Tile>) {
|
||||
let tiles: Vec<_> = tiles
|
||||
.iter()
|
||||
.copied()
|
||||
.map(|tile| tile::draw_tile(&tile))
|
||||
.collect();
|
||||
|
||||
commands.insert_resource(Splash(tiles));
|
||||
trace!("init_splash")
|
||||
}
|
||||
|
||||
pub(crate) fn render_splash(mut splash: ResMut<Splash>) {
|
||||
let mut rng = rng();
|
||||
splash.0.shuffle(&mut rng);
|
||||
}
|
||||
|
||||
pub(crate) fn draw_splash(mut widgets: ResMut<WidgetStack>, splash: Res<Splash>) {
|
||||
let tiles: Vec<_> = splash.0.clone();
|
||||
widgets.0.push(Box::new(move |frame| {
|
||||
let area = frame.area().outer(Margin {
|
||||
horizontal: 1,
|
||||
vertical: 1,
|
||||
});
|
||||
let layout = Layout::horizontal(vec![Constraint::Length(5); (area.width / 5) as usize]);
|
||||
let areas = layout.split(area);
|
||||
let mut tile_chunks = tiles.chunks(areas.len()).cycle();
|
||||
for area in areas.iter() {
|
||||
let layout = Layout::vertical(vec![Constraint::Length(4); (area.height / 4) as usize]);
|
||||
let areas = layout.split(*area);
|
||||
// let tiles: Vec<_> = tile_it
|
||||
// .by_ref()
|
||||
// .take((area.height / 4 + 1) as usize)
|
||||
// .map(|t| tile::draw_tile(&t))
|
||||
// .collect();
|
||||
for (tile, area) in tile_chunks.next().unwrap().iter().zip(areas.iter()) {
|
||||
frame.render_widget(tile, *area);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_ratatui::RatatuiContext;
|
||||
use ratatui::{
|
||||
Frame,
|
||||
widgets::{Block, Clear},
|
||||
};
|
||||
use tui_logger::TuiLoggerWidget;
|
||||
|
||||
pub(crate) mod hand;
|
||||
pub(crate) mod ingame;
|
||||
pub(crate) mod menu;
|
||||
pub(crate) mod tile;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub(crate) struct WidgetStack(pub(crate) Vec<Box<dyn FnOnce(&mut Frame) + Send + Sync>>);
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct Hovered;
|
||||
|
||||
pub(crate) fn draw_console(mut widgets: ResMut<WidgetStack>) {
|
||||
widgets.0.push(Box::new(|frame| {
|
||||
let block = Block::bordered().title("console");
|
||||
frame.render_widget(Clear, frame.area());
|
||||
frame.render_widget(
|
||||
TuiLoggerWidget::default().block(block),
|
||||
frame.area(), /* .inner(Margin { horizontal: 8, vertical: 8 }) */
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
pub(crate) fn draw_system(
|
||||
mut tui_ctx: ResMut<RatatuiContext>,
|
||||
mut widgets: ResMut<WidgetStack>,
|
||||
) -> Result {
|
||||
tui_ctx.draw(|frame| {
|
||||
for widget in widgets.0.drain(..) {
|
||||
widget(frame)
|
||||
}
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
use ratatui::widgets::Paragraph;
|
||||
|
||||
use jong::tile::Tile;
|
||||
|
||||
#[derive(Component)]
|
||||
pub(crate) struct RenderedTile(pub(crate) Paragraph<'static>);
|
||||
|
||||
pub(crate) fn draw_tile(tile: &Tile) -> Paragraph<'static> {
|
||||
let block = ratatui::widgets::Block::bordered();
|
||||
|
||||
Paragraph::new(match &tile.suit {
|
||||
jong::tile::Suit::Pin(rank) => format!("{}\np", rank.0),
|
||||
jong::tile::Suit::Sou(rank) => format!("{}\ns", rank.0),
|
||||
jong::tile::Suit::Man(rank) => format!("{}\nm", rank.0),
|
||||
jong::tile::Suit::Wind(wind) => (match wind {
|
||||
jong::tile::Wind::Ton => "e\nw",
|
||||
jong::tile::Wind::Nan => "s\nw",
|
||||
jong::tile::Wind::Shaa => "w\nw",
|
||||
jong::tile::Wind::Pei => "n\nw",
|
||||
})
|
||||
.into(),
|
||||
jong::tile::Suit::Dragon(dragon) => (match dragon {
|
||||
jong::tile::Dragon::Haku => "w\nd",
|
||||
jong::tile::Dragon::Hatsu => "g\nd",
|
||||
jong::tile::Dragon::Chun => "r\nd",
|
||||
})
|
||||
.into(),
|
||||
})
|
||||
.block(block)
|
||||
.centered()
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, States, Default)]
|
||||
pub(crate) enum TuiState {
|
||||
#[default]
|
||||
MainMenu,
|
||||
InGame,
|
||||
}
|
||||
|
||||
#[derive(SubStates, Default, Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
#[source(TuiState = TuiState::MainMenu)]
|
||||
pub(crate) enum ZenState {
|
||||
#[default]
|
||||
Menu,
|
||||
Zen,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default, States)]
|
||||
pub(crate) enum ConsoleState {
|
||||
#[default]
|
||||
Closed,
|
||||
Open,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub(crate) struct InGame;
|
||||
|
||||
impl ComputedStates for InGame {
|
||||
type SourceStates = TuiState;
|
||||
|
||||
fn compute(sources: Self::SourceStates) -> Option<Self> {
|
||||
match sources {
|
||||
TuiState::InGame => Some(Self),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Not for ConsoleState {
|
||||
type Output = Self;
|
||||
|
||||
fn not(self) -> Self::Output {
|
||||
match self {
|
||||
ConsoleState::Open => ConsoleState::Closed,
|
||||
ConsoleState::Closed => ConsoleState::Open,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue