This commit is contained in:
Tao Tien 2026-01-07 00:51:57 -08:00
parent b47ecbf45a
commit 53e4047e6a
8 changed files with 720 additions and 15 deletions

View file

@ -1,15 +1,133 @@
use bevy::prelude::*;
use std::{collections::VecDeque, time::Duration};
use crate::gui::{tiles::*, *};
use bevy::{app::ScheduleRunnerPlugin, input::keyboard::Key, prelude::*};
use bevy_ratatui::RatatuiPlugins;
use clap::{Parser, Subcommand};
use crate::tiles::*;
mod tiles;
mod yakus;
mod gui;
mod tui;
fn main() {
App::new()
// .add_plugins(DefaultPlugins)
.add_systems(Startup, init_table)
.add_systems(Startup, init_tileset)
.add_systems(Startup, init_environment)
.run();
#[derive(Parser)]
struct Args {
#[command(subcommand)]
mode: Mode,
}
#[derive(Subcommand)]
enum Mode {
RunGui,
RunTui,
}
fn main() {
let args = Args::parse();
let mut app = App::new();
let app = match args.mode {
Mode::RunGui => app.add_plugins(DefaultPlugins),
Mode::RunTui => app
.add_plugins((
MinimalPlugins.set(ScheduleRunnerPlugin::run_loop(Duration::from_secs_f32(
1. / 1.,
))),
RatatuiPlugins {
// enable_kitty_protocol: todo!(),
// enable_mouse_capture: todo!(),
enable_input_forwarding: true,
..Default::default()
},
))
.add_systems(Update, tui::draw_system),
};
app.init_resource::<Compass>()
.add_systems(Startup, init_match)
.add_systems(Startup, init_tiles);
app.run();
}
fn keyboard_input_system(
input: Res<ButtonInput<KeyCode>>,
key_input: Res<ButtonInput<Key>>,
) {
}
#[derive(Component)]
struct Player {
name: String,
}
#[derive(Component)]
struct Points(isize);
#[derive(Component)]
struct Dice(u8, u8);
#[derive(Resource)]
struct Compass {
prevalent_wind: Wind,
round: u8,
dealer_wind: Wind,
riichi: usize,
honba: usize,
}
impl Default for Compass {
fn default() -> Self {
Self {
prevalent_wind: Wind::Ton,
round: 1,
dealer_wind: Wind::Ton,
riichi: 0,
honba: 0,
}
}
}
#[derive(Resource)]
struct MatchSettings {
starting_points: isize,
player_count: u8,
}
#[derive(Component)]
struct Wall(VecDeque<Tile>);
fn next_round(mut compass: Res<Compass>) {}
fn init_match(mut commands: Commands, // , mut compass: ResMut<Compass>
) {
let starting = 25000;
let player_count = 4;
commands.insert_resource(MatchSettings {
starting_points: starting,
player_count,
});
let players = (1..=player_count)
.map(|i| {
(
Player {
name: format!("Player {i}"),
},
Points(starting),
)
})
.collect::<Vec<_>>();
commands.spawn_batch(players);
// *compass = Compass {
// prevalent_wind: Wind::Ton,
// round: 1,
// dealer_wind: todo!(),
// riichi: 0,
// honba: 0,
// }
}

58
src/tiles.rs Normal file
View file

@ -0,0 +1,58 @@
use bevy::prelude::*;
use strum::FromRepr;
#[derive(Component)]
pub(crate) enum Tile {
Pin(Number),
Sou(Number),
Man(Number),
Wind(Wind),
Dragon(Dragon),
}
#[derive(FromRepr)]
pub(crate) enum Number {
One = 1,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
}
#[derive(FromRepr)]
pub(crate) enum Wind {
Ton,
Nan,
Shaa,
Pei,
}
#[derive(FromRepr)]
pub(crate) enum Dragon {
Haku,
Hatsu,
Chun,
}
#[derive(Component)]
pub(crate) struct Dora;
pub fn init_tiles(mut commands: Commands) {
for _ in 0..4 {
for i in 1..=9 {
commands.spawn((Tile::Pin(Number::from_repr(i).unwrap()),));
commands.spawn((Tile::Sou(Number::from_repr(i).unwrap()),));
commands.spawn((Tile::Man(Number::from_repr(i).unwrap()),));
}
for i in 0..4 {
commands.spawn((Tile::Wind(Wind::from_repr(i).unwrap()),));
}
for i in 0..3 {
commands.spawn((Tile::Dragon(Dragon::from_repr(i).unwrap()),));
}
}
}

View file

19
src/tui/input.rs Normal file
View file

@ -0,0 +1,19 @@
// use bevy::ecs::message::MessageReader;
use bevy::app::AppExit;
use bevy::prelude::*;
use bevy_ratatui::crossterm::event::KeyCode;
use bevy_ratatui::event::KeyMessage;
pub(crate) fn input_system(
mut messages: MessageReader<KeyMessage>,
mut exit: MessageWriter<AppExit>,
) {
for message in messages.read() {
match message.code {
KeyCode::Char('q') => {
exit.write_default();
}
_ => {}
}
}
}

17
src/tui/mod.rs Normal file
View file

@ -0,0 +1,17 @@
use bevy::prelude::*;
use bevy_ratatui::RatatuiContext;
use crate::tiles::Tile;
pub(crate) mod input;
pub(crate) use input::input_system;
pub(crate) fn draw_system(mut context: ResMut<RatatuiContext>, query: Query<&Tile>) -> Result {
context.draw(|frame| {
let text = ratatui::text::Text::raw("tiny riichi");
frame.render_widget(text, frame.area());
})?;
Ok(())
}

1
src/yakus.rs Normal file
View file

@ -0,0 +1 @@
// const TSUMO;