extract types

This commit is contained in:
Tao Tien 2026-02-07 17:46:03 -08:00
parent d7d567b0e6
commit c86f8d93f1
30 changed files with 986 additions and 474 deletions

View file

@ -10,17 +10,23 @@ readme = false
[lib]
[dependencies]
bevy = { workspace = true, features = ["dynamic_linking"] }
bevy_ratatui = { workspace = true }
# bevy_ratatui = { git = "https://github.com/kenianbei/bevy_ratatui.git", rev = "e4b022308e08ab360ef89eca8e9f8b1c969e9a56" }
# bevy_ratatui = { path = "/home/tao/clones/bevy_ratatui" }
bevy_spacetimedb = { workspace = true }
bevy.features = ["dynamic_linking"]
bevy.version = "0.17.3"
bevy_ratatui = "0.10.0"
bevy_spacetimedb = "0.7"
clap = { workspace = true, features = ["derive"] }
log = { workspace = true, features = ["release_max_level_error", "max_level_trace"] }
jong-types = { version = "0.1.0", path = "../jong-types" }
log = { workspace = true, features = [
"release_max_level_error",
"max_level_trace",
] }
rand = { workspace = true }
ratatui = { workspace = true }
ratatui = "0.30.0"
spacetimedb.workspace = true
strum = { workspace = true, features = ["derive"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
tui-logger = { workspace = true, features = ["tracing-support", "crossterm"] }
tui-logger.features = ["tracing-support", "crossterm"]
tui-logger.version = "0.18.0"

View file

@ -2,10 +2,8 @@ use std::mem::discriminant;
use bevy::prelude::*;
use crate::{
game::{GameState, player::Player, wall::Wall},
tile::Tile,
};
use crate::game::{GameState, player::Player, wall::Wall};
use jong_types::*;
#[derive(Component)]
pub struct Hand;

View file

@ -1,80 +1,59 @@
use bevy::prelude::*;
use spacetimedb::SpacetimeType;
use strum::FromRepr;
// use spacetimedb::SpacetimeType;
// use strum::FromRepr;
#[derive(Component, Debug, Clone, Copy, SpacetimeType)]
pub struct Tile {
pub suit: Suit,
}
use jong_types::*;
#[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub enum Suit {
Man(Rank),
Pin(Rank),
Sou(Rank),
Wind(Wind),
Dragon(Dragon),
}
// #[derive(Component, Debug, Clone, Copy, SpacetimeType)]
// pub struct Tile {
// pub suit: Suit,
// }
impl Suit {
pub fn rank(&self) -> Option<Rank> {
match self {
Suit::Man(rank) => Some(*rank),
Suit::Pin(rank) => Some(*rank),
Suit::Sou(rank) => Some(*rank),
// Suit::Wind(wind) | Suit::Dragon(dragon) => None,
_ => None,
}
}
}
// #[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
// pub enum Suit {
// Man(Rank),
// Pin(Rank),
// Sou(Rank),
// Wind(Wind),
// Dragon(Dragon),
// }
#[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub struct Rank {
pub number: u8,
}
// impl Suit {
// pub fn rank(&self) -> Option<Rank> {
// match self {
// Suit::Man(rank) => Some(*rank),
// Suit::Pin(rank) => Some(*rank),
// Suit::Sou(rank) => Some(*rank),
// // Suit::Wind(wind) | Suit::Dragon(dragon) => None,
// _ => None,
// }
// }
// }
#[derive(FromRepr, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub enum Wind {
Ton,
Nan,
Shaa,
Pei,
}
// #[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
// pub struct Rank {
// pub number: u8,
// }
#[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub enum Dragon {
Haku,
Hatsu,
Chun,
}
// #[derive(FromRepr, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
// pub enum Wind {
// Ton,
// Nan,
// Shaa,
// Pei,
// }
// #[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
// pub enum Dragon {
// Haku,
// Hatsu,
// Chun,
// }
#[derive(Component)]
pub struct Dora;
pub fn init_tiles(mut commands: Commands) {
let mut tiles = vec![];
for _ in 0..4 {
for i in 1..=9 {
tiles.push(Tile {
suit: Suit::Pin(Rank { number: i }),
});
tiles.push(Tile {
suit: Suit::Sou(Rank { number: i }),
});
tiles.push(Tile {
suit: Suit::Man(Rank { number: i }),
});
}
for i in 0..4 {
tiles.push(Tile {
suit: Suit::Wind(Wind::from_repr(i).unwrap()),
});
}
for i in 0..3 {
tiles.push(Tile {
suit: Suit::Dragon(Dragon::from_repr(i).unwrap()),
});
}
}
let tiles = tiles();
commands.spawn_batch(tiles);
}

View file

@ -9,7 +9,7 @@ use ratatui::widgets::{Block, Borders, Clear, Paragraph};
use jong::game::hand::{Drawn, Hand};
use jong::game::player::{CurrentPlayer, MainPlayer, Player};
use jong::game::round::Wind;
use jong::tile::Tile;
// use jong_types::*;
use crate::tui::input::Hovered;
use crate::tui::layout::*;
@ -20,23 +20,24 @@ pub(crate) struct PickRegion {
pub(crate) area: Rect,
}
fn render_tile(tile: &Tile, hovered: bool) -> Paragraph<'_> {
fn render_tile(tile: &jong_types::Tile, hovered: bool) -> Paragraph<'_> {
use jong_types::*;
let block = ratatui::widgets::Block::bordered();
let mut widget = Paragraph::new(match &tile.suit {
jong::tile::Suit::Pin(rank) => format!("{}\np", rank.number),
jong::tile::Suit::Sou(rank) => format!("{}\ns", rank.number),
jong::tile::Suit::Man(rank) => format!("{}\nm", rank.number),
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",
Suit::Pin(rank) => format!("{}\np", rank.number),
Suit::Sou(rank) => format!("{}\ns", rank.number),
Suit::Man(rank) => format!("{}\nm", rank.number),
Suit::Wind(wind) => (match wind {
Wind::Ton => "e\nw",
Wind::Nan => "s\nw",
Wind::Shaa => "w\nw",
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",
Suit::Dragon(dragon) => (match dragon {
Dragon::Haku => "w\nd",
Dragon::Hatsu => "g\nd",
Dragon::Chun => "r\nd",
})
.into(),
})
@ -102,7 +103,7 @@ pub(crate) fn render_hands(
hovered: Query<Entity, With<Hovered>>,
layouts: Res<HandLayouts>,
tiles: Query<&Tile>,
tiles: Query<&jong_types::Tile>,
main_player: Single<(&Player, Entity, &Wind), With<MainPlayer>>,
curr_player: Single<Entity, With<CurrentPlayer>>,
players: Query<(&Player, Entity, &Children)>,