insert shuffled wall

This commit is contained in:
Tao Tien 2026-02-07 00:18:47 -08:00
parent 3ca8574a6e
commit d7d567b0e6
7 changed files with 36 additions and 17 deletions

2
Cargo.lock generated
View file

@ -3747,6 +3747,7 @@ dependencies = [
"log", "log",
"rand 0.9.2", "rand 0.9.2",
"ratatui", "ratatui",
"spacetimedb",
"strum 0.27.2", "strum 0.27.2",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
@ -3757,6 +3758,7 @@ dependencies = [
name = "jongline" name = "jongline"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"jong",
"log", "log",
"spacetimedb", "spacetimedb",
] ]

View file

@ -14,6 +14,8 @@ strum = "0.27.2"
tracing = "0.1.44" tracing = "0.1.44"
tracing-subscriber = "0.3.22" tracing-subscriber = "0.3.22"
tui-logger = "0.18.0" tui-logger = "0.18.0"
jong = { version = "0.1.0", path = "jong" }
spacetimedb = "1.11.*"
[profile.dev] [profile.dev]
opt-level = 1 opt-level = 1

View file

@ -19,6 +19,7 @@ clap = { workspace = true, features = ["derive"] }
log = { workspace = true, features = ["release_max_level_error", "max_level_trace"] } log = { workspace = true, features = ["release_max_level_error", "max_level_trace"] }
rand = { workspace = true } rand = { workspace = true }
ratatui = { workspace = true } ratatui = { workspace = true }
spacetimedb.workspace = true
strum = { workspace = true, features = ["derive"] } strum = { workspace = true, features = ["derive"] }
tracing = { workspace = true } tracing = { workspace = true }
tracing-subscriber = { workspace = true } tracing-subscriber = { workspace = true }

View file

@ -1,12 +1,13 @@
use bevy::prelude::*; use bevy::prelude::*;
use spacetimedb::SpacetimeType;
use strum::FromRepr; use strum::FromRepr;
#[derive(Component, Debug, Clone, Copy)] #[derive(Component, Debug, Clone, Copy, SpacetimeType)]
pub struct Tile { pub struct Tile {
pub suit: Suit, pub suit: Suit,
} }
#[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy)] #[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub enum Suit { pub enum Suit {
Man(Rank), Man(Rank),
Pin(Rank), Pin(Rank),
@ -27,10 +28,12 @@ impl Suit {
} }
} }
#[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy)] #[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub struct Rank(pub u8); pub struct Rank {
pub number: u8,
}
#[derive(FromRepr, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy)] #[derive(FromRepr, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub enum Wind { pub enum Wind {
Ton, Ton,
Nan, Nan,
@ -38,7 +41,7 @@ pub enum Wind {
Pei, Pei,
} }
#[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy)] #[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
pub enum Dragon { pub enum Dragon {
Haku, Haku,
Hatsu, Hatsu,
@ -53,13 +56,13 @@ pub fn init_tiles(mut commands: Commands) {
for _ in 0..4 { for _ in 0..4 {
for i in 1..=9 { for i in 1..=9 {
tiles.push(Tile { tiles.push(Tile {
suit: Suit::Pin(Rank(i)), suit: Suit::Pin(Rank { number: i }),
}); });
tiles.push(Tile { tiles.push(Tile {
suit: Suit::Sou(Rank(i)), suit: Suit::Sou(Rank { number: i }),
}); });
tiles.push(Tile { tiles.push(Tile {
suit: Suit::Man(Rank(i)), suit: Suit::Man(Rank { number: i }),
}); });
} }
for i in 0..4 { for i in 0..4 {

View file

@ -23,9 +23,9 @@ pub(crate) struct PickRegion {
fn render_tile(tile: &Tile, hovered: bool) -> Paragraph<'_> { fn render_tile(tile: &Tile, hovered: bool) -> Paragraph<'_> {
let block = ratatui::widgets::Block::bordered(); let block = ratatui::widgets::Block::bordered();
let mut widget = Paragraph::new(match &tile.suit { let mut widget = Paragraph::new(match &tile.suit {
jong::tile::Suit::Pin(rank) => format!("{}\np", rank.0), jong::tile::Suit::Pin(rank) => format!("{}\np", rank.number),
jong::tile::Suit::Sou(rank) => format!("{}\ns", rank.0), jong::tile::Suit::Sou(rank) => format!("{}\ns", rank.number),
jong::tile::Suit::Man(rank) => format!("{}\nm", rank.0), jong::tile::Suit::Man(rank) => format!("{}\nm", rank.number),
jong::tile::Suit::Wind(wind) => (match wind { jong::tile::Suit::Wind(wind) => (match wind {
jong::tile::Wind::Ton => "e\nw", jong::tile::Wind::Ton => "e\nw",
jong::tile::Wind::Nan => "s\nw", jong::tile::Wind::Nan => "s\nw",

View file

@ -9,5 +9,6 @@ edition = "2021"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
spacetimedb = "1.11.*" spacetimedb = { workspace = true }
log = "0.4" log = { workspace = true }
jong = { workspace = true }

View file

@ -1,4 +1,6 @@
use spacetimedb::{reducer, table, Identity, ReducerContext}; use spacetimedb::{Identity, ReducerContext, Table, rand::Rng, reducer, table};
use jong::tile::Tile;
#[table(name = player, public)] #[table(name = player, public)]
pub struct Player { pub struct Player {
@ -10,7 +12,7 @@ pub struct Player {
#[table(name = wall)] #[table(name = wall)]
pub struct Wall { pub struct Wall {
tiles: Vec<()> tiles: Vec<Tile>,
} }
#[reducer(init)] #[reducer(init)]
@ -45,7 +47,15 @@ pub fn set_name(ctx: &ReducerContext, name: String) -> Result<(), String> {
} }
#[reducer] #[reducer]
pub fn shuffle_wall(ctx: &ReducerContext) {} pub fn shuffle_wall(ctx: &ReducerContext) {
let mut rng = ctx.rng();
let mut tiles: Vec<Tile> = todo();
// rng.fill();
// let tiles = rng.sh;
ctx.db.wall().insert(Wall {tiles});
}
// #[reducer] // #[reducer]
// pub fn add(ctx: &ReducerContext, name: String) { // pub fn add(ctx: &ReducerContext, name: String) {