reinit spacetimedb
This commit is contained in:
parent
d52a1c4d8e
commit
3ca8574a6e
19 changed files with 2934 additions and 12 deletions
13
spacetimedb/Cargo.toml
Normal file
13
spacetimedb/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "jongline"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
spacetimedb = "1.11.*"
|
||||
log = "0.4"
|
||||
61
spacetimedb/src/lib.rs
Normal file
61
spacetimedb/src/lib.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use spacetimedb::{reducer, table, Identity, ReducerContext};
|
||||
|
||||
#[table(name = player, public)]
|
||||
pub struct Player {
|
||||
#[primary_key]
|
||||
identity: Identity,
|
||||
name: Option<String>,
|
||||
host: bool,
|
||||
}
|
||||
|
||||
#[table(name = wall)]
|
||||
pub struct Wall {
|
||||
tiles: Vec<()>
|
||||
}
|
||||
|
||||
#[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 set_name(ctx: &ReducerContext, name: String) -> Result<(), String> {
|
||||
if name.is_empty() {
|
||||
return Err("names must not be empty".into());
|
||||
}
|
||||
if let Some(player) = ctx.db.player().identity().find(ctx.sender) {
|
||||
ctx.db.player().identity().update(Player {
|
||||
name: Some(name),
|
||||
..player
|
||||
});
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Cannot set name for unknown user".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[reducer]
|
||||
pub fn shuffle_wall(ctx: &ReducerContext) {}
|
||||
|
||||
// #[reducer]
|
||||
// pub fn add(ctx: &ReducerContext, name: String) {
|
||||
// ctx.db.player().insert(Player { name });
|
||||
// }
|
||||
|
||||
// #[reducer]
|
||||
// pub fn say_hello(ctx: &ReducerContext) {
|
||||
// for person in ctx.db.person().iter() {
|
||||
// log::info!("Hello, {}!", person.name);
|
||||
// }
|
||||
// log::info!("Hello, World!");
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue