From d7d567b0e6059b7108583e8c36ea49b532e01824 Mon Sep 17 00:00:00 2001 From: Tao Tien <29749622+taotien@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:18:47 -0800 Subject: [PATCH] insert shuffled wall --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ jong/Cargo.toml | 1 + jong/src/tile.rs | 21 ++++++++++++--------- jong/src/tui/render.rs | 6 +++--- spacetimedb/Cargo.toml | 5 +++-- spacetimedb/src/lib.rs | 16 +++++++++++++--- 7 files changed, 36 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28043e6..3d1aba9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3747,6 +3747,7 @@ dependencies = [ "log", "rand 0.9.2", "ratatui", + "spacetimedb", "strum 0.27.2", "tracing", "tracing-subscriber", @@ -3757,6 +3758,7 @@ dependencies = [ name = "jongline" version = "0.1.0" dependencies = [ + "jong", "log", "spacetimedb", ] diff --git a/Cargo.toml b/Cargo.toml index c5968cd..f83cf09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,8 @@ strum = "0.27.2" tracing = "0.1.44" tracing-subscriber = "0.3.22" tui-logger = "0.18.0" +jong = { version = "0.1.0", path = "jong" } +spacetimedb = "1.11.*" [profile.dev] opt-level = 1 diff --git a/jong/Cargo.toml b/jong/Cargo.toml index 74353e2..a00f4da 100644 --- a/jong/Cargo.toml +++ b/jong/Cargo.toml @@ -19,6 +19,7 @@ clap = { workspace = true, features = ["derive"] } log = { workspace = true, features = ["release_max_level_error", "max_level_trace"] } rand = { workspace = true } ratatui = { workspace = true } +spacetimedb.workspace = true strum = { workspace = true, features = ["derive"] } tracing = { workspace = true } tracing-subscriber = { workspace = true } diff --git a/jong/src/tile.rs b/jong/src/tile.rs index 6d93f90..37659c5 100644 --- a/jong/src/tile.rs +++ b/jong/src/tile.rs @@ -1,12 +1,13 @@ use bevy::prelude::*; +use spacetimedb::SpacetimeType; use strum::FromRepr; -#[derive(Component, Debug, Clone, Copy)] +#[derive(Component, Debug, Clone, Copy, SpacetimeType)] pub struct Tile { 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 { Man(Rank), Pin(Rank), @@ -27,10 +28,12 @@ impl Suit { } } -#[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy)] -pub struct Rank(pub u8); +#[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)] +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 { Ton, Nan, @@ -38,7 +41,7 @@ pub enum Wind { Pei, } -#[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy)] +#[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)] pub enum Dragon { Haku, Hatsu, @@ -53,13 +56,13 @@ pub fn init_tiles(mut commands: Commands) { for _ in 0..4 { for i in 1..=9 { tiles.push(Tile { - suit: Suit::Pin(Rank(i)), + suit: Suit::Pin(Rank { number: i }), }); tiles.push(Tile { - suit: Suit::Sou(Rank(i)), + suit: Suit::Sou(Rank { number: i }), }); tiles.push(Tile { - suit: Suit::Man(Rank(i)), + suit: Suit::Man(Rank { number: i }), }); } for i in 0..4 { diff --git a/jong/src/tui/render.rs b/jong/src/tui/render.rs index ae6aae5..b2bbdaa 100644 --- a/jong/src/tui/render.rs +++ b/jong/src/tui/render.rs @@ -23,9 +23,9 @@ pub(crate) struct PickRegion { fn render_tile(tile: &Tile, hovered: bool) -> Paragraph<'_> { let block = ratatui::widgets::Block::bordered(); let mut widget = 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::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", diff --git a/spacetimedb/Cargo.toml b/spacetimedb/Cargo.toml index 96c8641..4697101 100644 --- a/spacetimedb/Cargo.toml +++ b/spacetimedb/Cargo.toml @@ -9,5 +9,6 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -spacetimedb = "1.11.*" -log = "0.4" +spacetimedb = { workspace = true } +log = { workspace = true } +jong = { workspace = true } diff --git a/spacetimedb/src/lib.rs b/spacetimedb/src/lib.rs index cd942bd..3e45fc5 100644 --- a/spacetimedb/src/lib.rs +++ b/spacetimedb/src/lib.rs @@ -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)] pub struct Player { @@ -10,7 +12,7 @@ pub struct Player { #[table(name = wall)] pub struct Wall { - tiles: Vec<()> + tiles: Vec, } #[reducer(init)] @@ -45,7 +47,15 @@ pub fn set_name(ctx: &ReducerContext, name: String) -> Result<(), String> { } #[reducer] -pub fn shuffle_wall(ctx: &ReducerContext) {} +pub fn shuffle_wall(ctx: &ReducerContext) { + let mut rng = ctx.rng(); + let mut tiles: Vec = todo(); + + // rng.fill(); + // let tiles = rng.sh; + + ctx.db.wall().insert(Wall {tiles}); +} // #[reducer] // pub fn add(ctx: &ReducerContext, name: String) {