extract types
This commit is contained in:
parent
d7d567b0e6
commit
c86f8d93f1
30 changed files with 986 additions and 474 deletions
|
|
@ -11,4 +11,4 @@ crate-type = ["cdylib"]
|
|||
[dependencies]
|
||||
spacetimedb = { workspace = true }
|
||||
log = { workspace = true }
|
||||
jong = { workspace = true }
|
||||
jong-types = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
use spacetimedb::{Identity, ReducerContext, Table, rand::Rng, reducer, table};
|
||||
use spacetimedb::{rand::seq::SliceRandom, reducer, table, Identity, ReducerContext, Table};
|
||||
|
||||
use jong::tile::Tile;
|
||||
use jong_types::*;
|
||||
|
||||
#[table(name = player, public)]
|
||||
pub struct Player {
|
||||
#[primary_key]
|
||||
identity: Identity,
|
||||
#[auto_inc]
|
||||
id: u32,
|
||||
name: Option<String>,
|
||||
host: bool,
|
||||
}
|
||||
|
|
@ -15,20 +17,14 @@ pub struct Wall {
|
|||
tiles: Vec<Tile>,
|
||||
}
|
||||
|
||||
#[reducer(init)]
|
||||
pub fn init(_ctx: &ReducerContext) {
|
||||
// Called when the module is initially published
|
||||
#[table(name = hand)]
|
||||
pub struct Hand {
|
||||
player_id: u32,
|
||||
tiles: Vec<Tile>,
|
||||
}
|
||||
|
||||
#[reducer(client_connected)]
|
||||
pub fn identity_connected(_ctx: &ReducerContext) {
|
||||
// Called everytime a new client connects
|
||||
}
|
||||
|
||||
#[reducer(client_disconnected)]
|
||||
pub fn identity_disconnected(_ctx: &ReducerContext) {
|
||||
// Called everytime a client disconnects
|
||||
}
|
||||
#[reducer]
|
||||
pub fn add_player(ctx: &ReducerContext, name: Option<String>) {}
|
||||
|
||||
#[reducer]
|
||||
pub fn set_name(ctx: &ReducerContext, name: String) -> Result<(), String> {
|
||||
|
|
@ -49,14 +45,31 @@ pub fn set_name(ctx: &ReducerContext, name: String) -> Result<(), String> {
|
|||
#[reducer]
|
||||
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});
|
||||
let mut tiles: Vec<Tile> = tiles();
|
||||
tiles.shuffle(&mut rng);
|
||||
ctx.db.wall().insert(Wall { tiles });
|
||||
}
|
||||
|
||||
#[reducer]
|
||||
pub fn sort_hand(ctx: &ReducerContext) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
// #[reducer(init)]
|
||||
// pub fn init(_ctx: &ReducerContext) {
|
||||
// // Called when the module is initially published
|
||||
// }
|
||||
|
||||
// #[reducer(client_connected)]
|
||||
// pub fn identity_connected(_ctx: &ReducerContext) {
|
||||
// // Called everytime a new client connects
|
||||
// }
|
||||
|
||||
// #[reducer(client_disconnected)]
|
||||
// pub fn identity_disconnected(_ctx: &ReducerContext) {
|
||||
// // Called everytime a client disconnects
|
||||
// }
|
||||
|
||||
// #[reducer]
|
||||
// pub fn add(ctx: &ReducerContext, name: String) {
|
||||
// ctx.db.player().insert(Player { name });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue