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",
"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",
]

View file

@ -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

View file

@ -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 }

View file

@ -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 {

View file

@ -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",

View file

@ -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 }

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)]
pub struct Player {
@ -10,7 +12,7 @@ pub struct Player {
#[table(name = wall)]
pub struct Wall {
tiles: Vec<()>
tiles: Vec<Tile>,
}
#[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<Tile> = todo();
// rng.fill();
// let tiles = rng.sh;
ctx.db.wall().insert(Wall {tiles});
}
// #[reducer]
// pub fn add(ctx: &ReducerContext, name: String) {