From ee4c492018e75306d4b9913cb089d479aa5a40a6 Mon Sep 17 00:00:00 2001 From: Tao Tien <29749622+taotien@users.noreply.github.com> Date: Thu, 8 Jan 2026 21:35:16 -0800 Subject: [PATCH] refactor a lil --- Cargo.lock | 22 +++++------ Cargo.toml | 4 +- src/gui/mod.rs | 2 - src/gui/tiles.rs | 99 ------------------------------------------------ src/lib.rs | 4 ++ src/main.rs | 7 +--- src/tiles.rs | 38 +++++++------------ src/tui/mod.rs | 2 +- 8 files changed, 34 insertions(+), 144 deletions(-) delete mode 100644 src/gui/tiles.rs create mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index cbabf55..716f5e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3084,6 +3084,17 @@ dependencies = [ "libc", ] +[[package]] +name = "jong" +version = "0.1.0" +dependencies = [ + "bevy", + "bevy_ratatui", + "clap", + "ratatui", + "strum 0.27.2", +] + [[package]] name = "js-sys" version = "0.3.83" @@ -4794,17 +4805,6 @@ dependencies = [ "strict-num", ] -[[package]] -name = "tiny_riichi" -version = "0.1.0" -dependencies = [ - "bevy", - "bevy_ratatui", - "clap", - "ratatui", - "strum 0.27.2", -] - [[package]] name = "tinyvec" version = "1.10.0" diff --git a/Cargo.toml b/Cargo.toml index 4501fc6..f2266ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,10 @@ [package] -name = "tiny_riichi" +name = "jong" version = "0.1.0" edition = "2024" +[lib] + [dependencies] bevy = { version = "0.17.3", features = ["dynamic_linking"] } bevy_ratatui = "0.10.0" diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 0961361..36ea966 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1,7 +1,5 @@ use bevy::{color::palettes::css::GREEN, prelude::*}; -pub(crate) mod tiles; - pub(crate) fn init_environment(mut commands: Commands) { commands.spawn(( DirectionalLight { diff --git a/src/gui/tiles.rs b/src/gui/tiles.rs deleted file mode 100644 index d0ef9ea..0000000 --- a/src/gui/tiles.rs +++ /dev/null @@ -1,99 +0,0 @@ -use bevy::{color::palettes::css::GREY, 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)] -struct Dora; - -pub fn init_tileset( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - let cuboid = Cuboid::new(25., 20., 16.); - - for _ in 0..4 { - for i in 1..=9 { - commands.spawn(( - ( - Mesh3d(meshes.add(cuboid)), - Transform::from_xyz(30., 0., 0.), - MeshMaterial3d(materials.add(std::convert::Into::::into(GREY))), - ), - Tile::Pin(Number::from_repr(i).unwrap()), - )); - commands.spawn(( - ( - Mesh3d(meshes.add(cuboid)), - Transform::from_xyz(30., 0., 0.), - MeshMaterial3d(materials.add(std::convert::Into::::into(GREY))), - ), - Tile::Sou(Number::from_repr(i).unwrap()), - )); - commands.spawn(( - ( - Mesh3d(meshes.add(cuboid)), - Transform::from_xyz(30., 0., 0.), - MeshMaterial3d(materials.add(std::convert::Into::::into(GREY))), - ), - Tile::Man(Number::from_repr(i).unwrap()), - )); - } - for i in 0..4 { - commands.spawn(( - ( - Mesh3d(meshes.add(cuboid)), - Transform::from_xyz(30., 0., 0.), - MeshMaterial3d(materials.add(std::convert::Into::::into(GREY))), - ), - Tile::Wind(Wind::from_repr(i).unwrap()), - )); - } - for i in 0..3 { - commands.spawn(( - ( - Mesh3d(meshes.add(cuboid)), - Transform::from_xyz(30., 0., 0.), - MeshMaterial3d(materials.add(std::convert::Into::::into(GREY))), - ), - Tile::Dragon(Dragon::from_repr(i).unwrap()), - )); - } - } -} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8a1fb07 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,4 @@ +pub mod tiles; +pub mod yakus; + +pub mod game; diff --git a/src/main.rs b/src/main.rs index 3d20dcd..2bfa232 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,6 @@ use bevy::prelude::*; use clap::{Parser, Subcommand}; -mod tiles; -mod yakus; - -mod game; - mod gui; mod tui; @@ -30,7 +25,7 @@ fn main() { Mode::RunTui => app.add_plugins(tui::RiichiTui), }; - app.add_plugins(game::Riichi); + app.add_plugins(jong::game::Riichi); app.run(); } diff --git a/src/tiles.rs b/src/tiles.rs index 6bb269d..8a75d3d 100644 --- a/src/tiles.rs +++ b/src/tiles.rs @@ -2,29 +2,19 @@ use bevy::prelude::*; use strum::FromRepr; #[derive(Component)] -pub(crate) enum Tile { - Pin(Number), - Sou(Number), - Man(Number), +pub enum Tile { + Pin(Rank), + Sou(Rank), + Man(Rank), Wind(Wind), Dragon(Dragon), } -#[derive(FromRepr)] -pub(crate) enum Number { - One = 1, - Two, - Three, - Four, - Five, - Six, - Seven, - Eight, - Nine, -} +#[derive(Deref, DerefMut)] +pub struct Rank(u8); #[derive(FromRepr)] -pub(crate) enum Wind { +pub enum Wind { Ton, Nan, Shaa, @@ -32,27 +22,27 @@ pub(crate) enum Wind { } #[derive(FromRepr)] -pub(crate) enum Dragon { +pub enum Dragon { Haku, Hatsu, Chun, } #[derive(Component)] -pub(crate) struct Dora; +pub 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()),)); + commands.spawn(Tile::Pin(Rank(i))); + commands.spawn(Tile::Sou(Rank(i))); + commands.spawn(Tile::Man(Rank(i))); } for i in 0..4 { - commands.spawn((Tile::Wind(Wind::from_repr(i).unwrap()),)); + commands.spawn(Tile::Wind(Wind::from_repr(i).unwrap())); } for i in 0..3 { - commands.spawn((Tile::Dragon(Dragon::from_repr(i).unwrap()),)); + commands.spawn(Tile::Dragon(Dragon::from_repr(i).unwrap())); } } } diff --git a/src/tui/mod.rs b/src/tui/mod.rs index 007589c..1c9822b 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -3,7 +3,7 @@ use std::time::Duration; use bevy::{app::ScheduleRunnerPlugin, prelude::*}; use bevy_ratatui::{RatatuiContext, RatatuiPlugins}; -use crate::tiles::Tile; +use jong::tiles::Tile; mod input;