extract types
This commit is contained in:
parent
d7d567b0e6
commit
c86f8d93f1
30 changed files with 986 additions and 474 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
|
@ -3744,6 +3744,7 @@ dependencies = [
|
||||||
"bevy_ratatui",
|
"bevy_ratatui",
|
||||||
"bevy_spacetimedb",
|
"bevy_spacetimedb",
|
||||||
"clap",
|
"clap",
|
||||||
|
"jong-types",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.9.2",
|
"rand 0.9.2",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
|
@ -3754,11 +3755,20 @@ dependencies = [
|
||||||
"tui-logger",
|
"tui-logger",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jong-types"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bevy",
|
||||||
|
"spacetimedb",
|
||||||
|
"strum 0.27.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jongline"
|
name = "jongline"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jong",
|
"jong-types",
|
||||||
"log",
|
"log",
|
||||||
"spacetimedb",
|
"spacetimedb",
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,16 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
members = ["jong", "spacetimedb"]
|
members = ["jong", "jong-types", "spacetimedb"]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
bevy = "0.17.3"
|
|
||||||
bevy_ratatui = "0.10.0"
|
|
||||||
bevy_spacetimedb = "0.7"
|
|
||||||
clap = "4.5.54"
|
clap = "4.5.54"
|
||||||
log = "0.4.29"
|
log = "0.4.29"
|
||||||
rand = "0.9.2"
|
rand = "0.9.2"
|
||||||
ratatui = "0.30.0"
|
|
||||||
strum = "0.27.2"
|
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"
|
|
||||||
jong = { version = "0.1.0", path = "jong" }
|
jong = { version = "0.1.0", path = "jong" }
|
||||||
|
jong-types = { version = "0.1.0", path = "jong-types" }
|
||||||
spacetimedb = "1.11.*"
|
spacetimedb = "1.11.*"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|
|
||||||
11
flake.nix
11
flake.nix
|
|
@ -22,6 +22,12 @@
|
||||||
in {
|
in {
|
||||||
devShells.default = with pkgs;
|
devShells.default = with pkgs;
|
||||||
mkShell rec {
|
mkShell rec {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkg-config
|
||||||
|
# spacetimedb
|
||||||
|
openssl
|
||||||
|
binaryen
|
||||||
|
];
|
||||||
buildInputs =
|
buildInputs =
|
||||||
[
|
[
|
||||||
# Rust dependencies
|
# Rust dependencies
|
||||||
|
|
@ -29,7 +35,6 @@
|
||||||
extensions = ["rust-src" "rust-docs" "rustc-codegen-cranelift" "rust-analyzer" "rustfmt"];
|
extensions = ["rust-src" "rust-docs" "rustc-codegen-cranelift" "rust-analyzer" "rustfmt"];
|
||||||
targets = ["x86_64-unknown-linux-gnu" "wasm32-unknown-unknown"];
|
targets = ["x86_64-unknown-linux-gnu" "wasm32-unknown-unknown"];
|
||||||
})
|
})
|
||||||
pkg-config
|
|
||||||
]
|
]
|
||||||
++ lib.optionals (lib.strings.hasInfix "linux" system) [
|
++ lib.optionals (lib.strings.hasInfix "linux" system) [
|
||||||
# for Linux
|
# for Linux
|
||||||
|
|
@ -47,10 +52,6 @@
|
||||||
xorg.libXrandr
|
xorg.libXrandr
|
||||||
libxkbcommon
|
libxkbcommon
|
||||||
wayland
|
wayland
|
||||||
|
|
||||||
# spacetimedb
|
|
||||||
openssl
|
|
||||||
binaryen
|
|
||||||
];
|
];
|
||||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
|
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
|
||||||
|
|
|
||||||
13
jong-types/Cargo.toml
Normal file
13
jong-types/Cargo.toml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "jong-types"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy.version = "0.17.3"
|
||||||
|
bevy.default-features = false
|
||||||
|
spacetimedb.workspace = true
|
||||||
|
strum.workspace = true
|
||||||
|
strum.features = ["derive"]
|
||||||
77
jong-types/src/lib.rs
Normal file
77
jong-types/src/lib.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use spacetimedb::SpacetimeType;
|
||||||
|
use strum::FromRepr;
|
||||||
|
|
||||||
|
#[derive(Component, Debug, Clone, Copy, SpacetimeType)]
|
||||||
|
pub struct Tile {
|
||||||
|
pub suit: Suit,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||||
|
pub enum Suit {
|
||||||
|
Man(Rank),
|
||||||
|
Pin(Rank),
|
||||||
|
Sou(Rank),
|
||||||
|
Wind(Wind),
|
||||||
|
Dragon(Dragon),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Suit {
|
||||||
|
pub fn rank(&self) -> Option<Rank> {
|
||||||
|
match self {
|
||||||
|
Suit::Man(rank) => Some(*rank),
|
||||||
|
Suit::Pin(rank) => Some(*rank),
|
||||||
|
Suit::Sou(rank) => Some(*rank),
|
||||||
|
// Suit::Wind(wind) | Suit::Dragon(dragon) => None,
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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, SpacetimeType)]
|
||||||
|
pub enum Wind {
|
||||||
|
Ton,
|
||||||
|
Nan,
|
||||||
|
Shaa,
|
||||||
|
Pei,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||||
|
pub enum Dragon {
|
||||||
|
Haku,
|
||||||
|
Hatsu,
|
||||||
|
Chun,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tiles() -> Vec<Tile> {
|
||||||
|
let mut tiles = vec![];
|
||||||
|
for _ in 0..4 {
|
||||||
|
for i in 1..=9 {
|
||||||
|
tiles.push(Tile {
|
||||||
|
suit: Suit::Pin(Rank { number: i }),
|
||||||
|
});
|
||||||
|
tiles.push(Tile {
|
||||||
|
suit: Suit::Sou(Rank { number: i }),
|
||||||
|
});
|
||||||
|
tiles.push(Tile {
|
||||||
|
suit: Suit::Man(Rank { number: i }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for i in 0..4 {
|
||||||
|
tiles.push(Tile {
|
||||||
|
suit: Suit::Wind(Wind::from_repr(i).unwrap()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for i in 0..3 {
|
||||||
|
tiles.push(Tile {
|
||||||
|
suit: Suit::Dragon(Dragon::from_repr(i).unwrap()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tiles
|
||||||
|
}
|
||||||
|
|
@ -10,17 +10,23 @@ readme = false
|
||||||
[lib]
|
[lib]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { workspace = true, features = ["dynamic_linking"] }
|
|
||||||
bevy_ratatui = { workspace = true }
|
|
||||||
# bevy_ratatui = { git = "https://github.com/kenianbei/bevy_ratatui.git", rev = "e4b022308e08ab360ef89eca8e9f8b1c969e9a56" }
|
# bevy_ratatui = { git = "https://github.com/kenianbei/bevy_ratatui.git", rev = "e4b022308e08ab360ef89eca8e9f8b1c969e9a56" }
|
||||||
# bevy_ratatui = { path = "/home/tao/clones/bevy_ratatui" }
|
# bevy_ratatui = { path = "/home/tao/clones/bevy_ratatui" }
|
||||||
bevy_spacetimedb = { workspace = true }
|
bevy.features = ["dynamic_linking"]
|
||||||
|
bevy.version = "0.17.3"
|
||||||
|
bevy_ratatui = "0.10.0"
|
||||||
|
bevy_spacetimedb = "0.7"
|
||||||
clap = { workspace = true, features = ["derive"] }
|
clap = { workspace = true, features = ["derive"] }
|
||||||
log = { workspace = true, features = ["release_max_level_error", "max_level_trace"] }
|
jong-types = { version = "0.1.0", path = "../jong-types" }
|
||||||
|
log = { workspace = true, features = [
|
||||||
|
"release_max_level_error",
|
||||||
|
"max_level_trace",
|
||||||
|
] }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
ratatui = { workspace = true }
|
ratatui = "0.30.0"
|
||||||
spacetimedb.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 }
|
||||||
tui-logger = { workspace = true, features = ["tracing-support", "crossterm"] }
|
tui-logger.features = ["tracing-support", "crossterm"]
|
||||||
|
tui-logger.version = "0.18.0"
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,8 @@ use std::mem::discriminant;
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::game::{GameState, player::Player, wall::Wall};
|
||||||
game::{GameState, player::Player, wall::Wall},
|
use jong_types::*;
|
||||||
tile::Tile,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Hand;
|
pub struct Hand;
|
||||||
|
|
|
||||||
111
jong/src/tile.rs
111
jong/src/tile.rs
|
|
@ -1,80 +1,59 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use spacetimedb::SpacetimeType;
|
// use spacetimedb::SpacetimeType;
|
||||||
use strum::FromRepr;
|
// use strum::FromRepr;
|
||||||
|
|
||||||
#[derive(Component, Debug, Clone, Copy, SpacetimeType)]
|
use jong_types::*;
|
||||||
pub struct Tile {
|
|
||||||
pub suit: Suit,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
// #[derive(Component, Debug, Clone, Copy, SpacetimeType)]
|
||||||
pub enum Suit {
|
// pub struct Tile {
|
||||||
Man(Rank),
|
// pub suit: Suit,
|
||||||
Pin(Rank),
|
// }
|
||||||
Sou(Rank),
|
|
||||||
Wind(Wind),
|
|
||||||
Dragon(Dragon),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Suit {
|
// #[derive(/* MapEntities, */ Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||||
pub fn rank(&self) -> Option<Rank> {
|
// pub enum Suit {
|
||||||
match self {
|
// Man(Rank),
|
||||||
Suit::Man(rank) => Some(*rank),
|
// Pin(Rank),
|
||||||
Suit::Pin(rank) => Some(*rank),
|
// Sou(Rank),
|
||||||
Suit::Sou(rank) => Some(*rank),
|
// Wind(Wind),
|
||||||
// Suit::Wind(wind) | Suit::Dragon(dragon) => None,
|
// Dragon(Dragon),
|
||||||
_ => None,
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
// impl Suit {
|
||||||
pub struct Rank {
|
// pub fn rank(&self) -> Option<Rank> {
|
||||||
pub number: u8,
|
// match self {
|
||||||
}
|
// Suit::Man(rank) => Some(*rank),
|
||||||
|
// Suit::Pin(rank) => Some(*rank),
|
||||||
|
// Suit::Sou(rank) => Some(*rank),
|
||||||
|
// // Suit::Wind(wind) | Suit::Dragon(dragon) => None,
|
||||||
|
// _ => None,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
#[derive(FromRepr, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
// #[derive(Deref, DerefMut, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||||
pub enum Wind {
|
// pub struct Rank {
|
||||||
Ton,
|
// pub number: u8,
|
||||||
Nan,
|
// }
|
||||||
Shaa,
|
|
||||||
Pei,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
// #[derive(FromRepr, Debug, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||||
pub enum Dragon {
|
// pub enum Wind {
|
||||||
Haku,
|
// Ton,
|
||||||
Hatsu,
|
// Nan,
|
||||||
Chun,
|
// Shaa,
|
||||||
}
|
// Pei,
|
||||||
|
// }
|
||||||
|
|
||||||
|
// #[derive(Debug, FromRepr, PartialEq, PartialOrd, Eq, Ord, Clone, Copy, SpacetimeType)]
|
||||||
|
// pub enum Dragon {
|
||||||
|
// Haku,
|
||||||
|
// Hatsu,
|
||||||
|
// Chun,
|
||||||
|
// }
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Dora;
|
pub struct Dora;
|
||||||
|
|
||||||
pub fn init_tiles(mut commands: Commands) {
|
pub fn init_tiles(mut commands: Commands) {
|
||||||
let mut tiles = vec![];
|
let tiles = tiles();
|
||||||
for _ in 0..4 {
|
|
||||||
for i in 1..=9 {
|
|
||||||
tiles.push(Tile {
|
|
||||||
suit: Suit::Pin(Rank { number: i }),
|
|
||||||
});
|
|
||||||
tiles.push(Tile {
|
|
||||||
suit: Suit::Sou(Rank { number: i }),
|
|
||||||
});
|
|
||||||
tiles.push(Tile {
|
|
||||||
suit: Suit::Man(Rank { number: i }),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
for i in 0..4 {
|
|
||||||
tiles.push(Tile {
|
|
||||||
suit: Suit::Wind(Wind::from_repr(i).unwrap()),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
for i in 0..3 {
|
|
||||||
tiles.push(Tile {
|
|
||||||
suit: Suit::Dragon(Dragon::from_repr(i).unwrap()),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
commands.spawn_batch(tiles);
|
commands.spawn_batch(tiles);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use ratatui::widgets::{Block, Borders, Clear, Paragraph};
|
||||||
use jong::game::hand::{Drawn, Hand};
|
use jong::game::hand::{Drawn, Hand};
|
||||||
use jong::game::player::{CurrentPlayer, MainPlayer, Player};
|
use jong::game::player::{CurrentPlayer, MainPlayer, Player};
|
||||||
use jong::game::round::Wind;
|
use jong::game::round::Wind;
|
||||||
use jong::tile::Tile;
|
// use jong_types::*;
|
||||||
|
|
||||||
use crate::tui::input::Hovered;
|
use crate::tui::input::Hovered;
|
||||||
use crate::tui::layout::*;
|
use crate::tui::layout::*;
|
||||||
|
|
@ -20,23 +20,24 @@ pub(crate) struct PickRegion {
|
||||||
pub(crate) area: Rect,
|
pub(crate) area: Rect,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_tile(tile: &Tile, hovered: bool) -> Paragraph<'_> {
|
fn render_tile(tile: &jong_types::Tile, hovered: bool) -> Paragraph<'_> {
|
||||||
|
use jong_types::*;
|
||||||
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.number),
|
Suit::Pin(rank) => format!("{}\np", rank.number),
|
||||||
jong::tile::Suit::Sou(rank) => format!("{}\ns", rank.number),
|
Suit::Sou(rank) => format!("{}\ns", rank.number),
|
||||||
jong::tile::Suit::Man(rank) => format!("{}\nm", rank.number),
|
Suit::Man(rank) => format!("{}\nm", rank.number),
|
||||||
jong::tile::Suit::Wind(wind) => (match wind {
|
Suit::Wind(wind) => (match wind {
|
||||||
jong::tile::Wind::Ton => "e\nw",
|
Wind::Ton => "e\nw",
|
||||||
jong::tile::Wind::Nan => "s\nw",
|
Wind::Nan => "s\nw",
|
||||||
jong::tile::Wind::Shaa => "w\nw",
|
Wind::Shaa => "w\nw",
|
||||||
jong::tile::Wind::Pei => "n\nw",
|
Wind::Pei => "n\nw",
|
||||||
})
|
})
|
||||||
.into(),
|
.into(),
|
||||||
jong::tile::Suit::Dragon(dragon) => (match dragon {
|
Suit::Dragon(dragon) => (match dragon {
|
||||||
jong::tile::Dragon::Haku => "w\nd",
|
Dragon::Haku => "w\nd",
|
||||||
jong::tile::Dragon::Hatsu => "g\nd",
|
Dragon::Hatsu => "g\nd",
|
||||||
jong::tile::Dragon::Chun => "r\nd",
|
Dragon::Chun => "r\nd",
|
||||||
})
|
})
|
||||||
.into(),
|
.into(),
|
||||||
})
|
})
|
||||||
|
|
@ -102,7 +103,7 @@ pub(crate) fn render_hands(
|
||||||
hovered: Query<Entity, With<Hovered>>,
|
hovered: Query<Entity, With<Hovered>>,
|
||||||
layouts: Res<HandLayouts>,
|
layouts: Res<HandLayouts>,
|
||||||
|
|
||||||
tiles: Query<&Tile>,
|
tiles: Query<&jong_types::Tile>,
|
||||||
main_player: Single<(&Player, Entity, &Wind), With<MainPlayer>>,
|
main_player: Single<(&Player, Entity, &Wind), With<MainPlayer>>,
|
||||||
curr_player: Single<Entity, With<CurrentPlayer>>,
|
curr_player: Single<Entity, With<CurrentPlayer>>,
|
||||||
players: Query<(&Player, Entity, &Children)>,
|
players: Query<(&Player, Entity, &Children)>,
|
||||||
|
|
|
||||||
2
justfile
2
justfile
|
|
@ -14,4 +14,4 @@ update:
|
||||||
nix flake update
|
nix flake update
|
||||||
|
|
||||||
spacetime:
|
spacetime:
|
||||||
spacetime dev --module-bindings-path modules_bindings
|
spacetime dev --module-bindings-path module_bindings fantastic-key-0909
|
||||||
|
|
|
||||||
102
module_bindings/add_player_reducer.rs
Normal file
102
module_bindings/add_player_reducer.rs
Normal file
|
|
@ -0,0 +1,102 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub(super) struct AddPlayerArgs {
|
||||||
|
pub name: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AddPlayerArgs> for super::Reducer {
|
||||||
|
fn from(args: AddPlayerArgs) -> Self {
|
||||||
|
Self::AddPlayer { name: args.name }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for AddPlayerArgs {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AddPlayerCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the reducer `add_player`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
|
pub trait add_player {
|
||||||
|
/// Request that the remote module invoke the reducer `add_player` to run as soon as possible.
|
||||||
|
///
|
||||||
|
/// This method returns immediately, and errors only if we are unable to send the request.
|
||||||
|
/// The reducer will run asynchronously in the future,
|
||||||
|
/// and its status can be observed by listening for [`Self::on_add_player`] callbacks.
|
||||||
|
fn add_player(&self, name: Option<String>) -> __sdk::Result<()>;
|
||||||
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `add_player`.
|
||||||
|
///
|
||||||
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
/// to determine the reducer's status.
|
||||||
|
///
|
||||||
|
/// The returned [`AddPlayerCallbackId`] can be passed to [`Self::remove_on_add_player`]
|
||||||
|
/// to cancel the callback.
|
||||||
|
fn on_add_player(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&super::ReducerEventContext, &Option<String>) + Send + 'static,
|
||||||
|
) -> AddPlayerCallbackId;
|
||||||
|
/// Cancel a callback previously registered by [`Self::on_add_player`],
|
||||||
|
/// causing it not to run in the future.
|
||||||
|
fn remove_on_add_player(&self, callback: AddPlayerCallbackId);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl add_player for super::RemoteReducers {
|
||||||
|
fn add_player(&self, name: Option<String>) -> __sdk::Result<()> {
|
||||||
|
self.imp.call_reducer("add_player", AddPlayerArgs { name })
|
||||||
|
}
|
||||||
|
fn on_add_player(
|
||||||
|
&self,
|
||||||
|
mut callback: impl FnMut(&super::ReducerEventContext, &Option<String>) + Send + 'static,
|
||||||
|
) -> AddPlayerCallbackId {
|
||||||
|
AddPlayerCallbackId(self.imp.on_reducer(
|
||||||
|
"add_player",
|
||||||
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
|
#[allow(irrefutable_let_patterns)]
|
||||||
|
let super::ReducerEventContext {
|
||||||
|
event:
|
||||||
|
__sdk::ReducerEvent {
|
||||||
|
reducer: super::Reducer::AddPlayer { name },
|
||||||
|
..
|
||||||
|
},
|
||||||
|
..
|
||||||
|
} = ctx
|
||||||
|
else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
callback(ctx, name)
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
fn remove_on_add_player(&self, callback: AddPlayerCallbackId) {
|
||||||
|
self.imp.remove_on_reducer("add_player", callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// Extension trait for setting the call-flags for the reducer `add_player`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
pub trait set_flags_for_add_player {
|
||||||
|
/// Set the call-reducer flags for the reducer `add_player` to `flags`.
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
fn add_player(&self, flags: __ws::CallReducerFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl set_flags_for_add_player for super::SetReducerFlags {
|
||||||
|
fn add_player(&self, flags: __ws::CallReducerFlags) {
|
||||||
|
self.imp.set_call_reducer_flags("add_player", flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
20
module_bindings/dragon_type.rs
Normal file
20
module_bindings/dragon_type.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
#[derive(Copy, Eq, Hash)]
|
||||||
|
pub enum Dragon {
|
||||||
|
Haku,
|
||||||
|
|
||||||
|
Hatsu,
|
||||||
|
|
||||||
|
Chun,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for Dragon {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
96
module_bindings/hand_table.rs
Normal file
96
module_bindings/hand_table.rs
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use super::hand_type::Hand;
|
||||||
|
use super::tile_type::Tile;
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
/// Table handle for the table `hand`.
|
||||||
|
///
|
||||||
|
/// Obtain a handle from the [`HandTableAccess::hand`] method on [`super::RemoteTables`],
|
||||||
|
/// like `ctx.db.hand()`.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.hand().on_insert(...)`.
|
||||||
|
pub struct HandTableHandle<'ctx> {
|
||||||
|
imp: __sdk::TableHandle<Hand>,
|
||||||
|
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the table `hand`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteTables`].
|
||||||
|
pub trait HandTableAccess {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
/// Obtain a [`HandTableHandle`], which mediates access to the table `hand`.
|
||||||
|
fn hand(&self) -> HandTableHandle<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HandTableAccess for super::RemoteTables {
|
||||||
|
fn hand(&self) -> HandTableHandle<'_> {
|
||||||
|
HandTableHandle {
|
||||||
|
imp: self.imp.get_table::<Hand>("hand"),
|
||||||
|
ctx: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct HandInsertCallbackId(__sdk::CallbackId);
|
||||||
|
pub struct HandDeleteCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::Table for HandTableHandle<'ctx> {
|
||||||
|
type Row = Hand;
|
||||||
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
|
fn count(&self) -> u64 {
|
||||||
|
self.imp.count()
|
||||||
|
}
|
||||||
|
fn iter(&self) -> impl Iterator<Item = Hand> + '_ {
|
||||||
|
self.imp.iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
type InsertCallbackId = HandInsertCallbackId;
|
||||||
|
|
||||||
|
fn on_insert(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> HandInsertCallbackId {
|
||||||
|
HandInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_insert(&self, callback: HandInsertCallbackId) {
|
||||||
|
self.imp.remove_on_insert(callback.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteCallbackId = HandDeleteCallbackId;
|
||||||
|
|
||||||
|
fn on_delete(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> HandDeleteCallbackId {
|
||||||
|
HandDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_delete(&self, callback: HandDeleteCallbackId) {
|
||||||
|
self.imp.remove_on_delete(callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||||
|
let _table = client_cache.get_or_make_table::<Hand>("hand");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(super) fn parse_table_update(
|
||||||
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
|
) -> __sdk::Result<__sdk::TableUpdate<Hand>> {
|
||||||
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
|
__sdk::InternalError::failed_parse("TableUpdate<Hand>", "TableUpdate")
|
||||||
|
.with_cause(e)
|
||||||
|
.into()
|
||||||
|
})
|
||||||
|
}
|
||||||
18
module_bindings/hand_type.rs
Normal file
18
module_bindings/hand_type.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
use super::tile_type::Tile;
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub struct Hand {
|
||||||
|
pub player_id: u32,
|
||||||
|
pub tiles: Vec<Tile>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for Hand {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
@ -1,103 +0,0 @@
|
||||||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
|
||||||
#[sats(crate = __lib)]
|
|
||||||
pub(super) struct IdentityDisconnectedArgs {}
|
|
||||||
|
|
||||||
impl From<IdentityDisconnectedArgs> for super::Reducer {
|
|
||||||
fn from(args: IdentityDisconnectedArgs) -> Self {
|
|
||||||
Self::IdentityDisconnected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for IdentityDisconnectedArgs {
|
|
||||||
type Module = super::RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct IdentityDisconnectedCallbackId(__sdk::CallbackId);
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
/// Extension trait for access to the reducer `identity_disconnected`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::RemoteReducers`].
|
|
||||||
pub trait identity_disconnected {
|
|
||||||
/// Request that the remote module invoke the reducer `identity_disconnected` to run as soon as possible.
|
|
||||||
///
|
|
||||||
/// This method returns immediately, and errors only if we are unable to send the request.
|
|
||||||
/// The reducer will run asynchronously in the future,
|
|
||||||
/// and its status can be observed by listening for [`Self::on_identity_disconnected`] callbacks.
|
|
||||||
fn identity_disconnected(&self) -> __sdk::Result<()>;
|
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `identity_disconnected`.
|
|
||||||
///
|
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
|
||||||
/// to determine the reducer's status.
|
|
||||||
///
|
|
||||||
/// The returned [`IdentityDisconnectedCallbackId`] can be passed to [`Self::remove_on_identity_disconnected`]
|
|
||||||
/// to cancel the callback.
|
|
||||||
fn on_identity_disconnected(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
|
||||||
) -> IdentityDisconnectedCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_identity_disconnected`],
|
|
||||||
/// causing it not to run in the future.
|
|
||||||
fn remove_on_identity_disconnected(&self, callback: IdentityDisconnectedCallbackId);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl identity_disconnected for super::RemoteReducers {
|
|
||||||
fn identity_disconnected(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp
|
|
||||||
.call_reducer("identity_disconnected", IdentityDisconnectedArgs {})
|
|
||||||
}
|
|
||||||
fn on_identity_disconnected(
|
|
||||||
&self,
|
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
|
||||||
) -> IdentityDisconnectedCallbackId {
|
|
||||||
IdentityDisconnectedCallbackId(self.imp.on_reducer(
|
|
||||||
"identity_disconnected",
|
|
||||||
Box::new(move |ctx: &super::ReducerEventContext| {
|
|
||||||
#[allow(irrefutable_let_patterns)]
|
|
||||||
let super::ReducerEventContext {
|
|
||||||
event:
|
|
||||||
__sdk::ReducerEvent {
|
|
||||||
reducer: super::Reducer::IdentityDisconnected {},
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} = ctx
|
|
||||||
else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx)
|
|
||||||
}),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
fn remove_on_identity_disconnected(&self, callback: IdentityDisconnectedCallbackId) {
|
|
||||||
self.imp
|
|
||||||
.remove_on_reducer("identity_disconnected", callback.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
/// Extension trait for setting the call-flags for the reducer `identity_disconnected`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub trait set_flags_for_identity_disconnected {
|
|
||||||
/// Set the call-reducer flags for the reducer `identity_disconnected` to `flags`.
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
fn identity_disconnected(&self, flags: __ws::CallReducerFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl set_flags_for_identity_disconnected for super::SetReducerFlags {
|
|
||||||
fn identity_disconnected(&self, flags: __ws::CallReducerFlags) {
|
|
||||||
self.imp
|
|
||||||
.set_call_reducer_flags("identity_disconnected", flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,23 +6,37 @@
|
||||||
#![allow(unused, clippy::all)]
|
#![allow(unused, clippy::all)]
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
pub mod add_reducer;
|
pub mod add_player_reducer;
|
||||||
pub mod identity_connected_reducer;
|
pub mod dragon_type;
|
||||||
pub mod identity_disconnected_reducer;
|
pub mod hand_table;
|
||||||
pub mod person_table;
|
pub mod hand_type;
|
||||||
pub mod person_type;
|
pub mod player_table;
|
||||||
pub mod say_hello_reducer;
|
pub mod player_type;
|
||||||
|
pub mod rank_type;
|
||||||
|
pub mod set_name_reducer;
|
||||||
|
pub mod shuffle_wall_reducer;
|
||||||
|
pub mod sort_hand_reducer;
|
||||||
|
pub mod suit_type;
|
||||||
|
pub mod tile_type;
|
||||||
|
pub mod wall_table;
|
||||||
|
pub mod wall_type;
|
||||||
|
pub mod wind_type;
|
||||||
|
|
||||||
pub use add_reducer::{add, set_flags_for_add, AddCallbackId};
|
pub use add_player_reducer::{add_player, set_flags_for_add_player, AddPlayerCallbackId};
|
||||||
pub use identity_connected_reducer::{
|
pub use dragon_type::Dragon;
|
||||||
identity_connected, set_flags_for_identity_connected, IdentityConnectedCallbackId,
|
pub use hand_table::*;
|
||||||
};
|
pub use hand_type::Hand;
|
||||||
pub use identity_disconnected_reducer::{
|
pub use player_table::*;
|
||||||
identity_disconnected, set_flags_for_identity_disconnected, IdentityDisconnectedCallbackId,
|
pub use player_type::Player;
|
||||||
};
|
pub use rank_type::Rank;
|
||||||
pub use person_table::*;
|
pub use set_name_reducer::{set_flags_for_set_name, set_name, SetNameCallbackId};
|
||||||
pub use person_type::Person;
|
pub use shuffle_wall_reducer::{set_flags_for_shuffle_wall, shuffle_wall, ShuffleWallCallbackId};
|
||||||
pub use say_hello_reducer::{say_hello, set_flags_for_say_hello, SayHelloCallbackId};
|
pub use sort_hand_reducer::{set_flags_for_sort_hand, sort_hand, SortHandCallbackId};
|
||||||
|
pub use suit_type::Suit;
|
||||||
|
pub use tile_type::Tile;
|
||||||
|
pub use wall_table::*;
|
||||||
|
pub use wall_type::Wall;
|
||||||
|
pub use wind_type::Wind;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
|
||||||
|
|
@ -32,10 +46,10 @@ pub use say_hello_reducer::{say_hello, set_flags_for_say_hello, SayHelloCallback
|
||||||
/// to indicate which reducer caused the event.
|
/// to indicate which reducer caused the event.
|
||||||
|
|
||||||
pub enum Reducer {
|
pub enum Reducer {
|
||||||
Add { name: String },
|
AddPlayer { name: Option<String> },
|
||||||
IdentityConnected,
|
SetName { name: String },
|
||||||
IdentityDisconnected,
|
ShuffleWall,
|
||||||
SayHello,
|
SortHand,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for Reducer {
|
impl __sdk::InModule for Reducer {
|
||||||
|
|
@ -45,10 +59,10 @@ impl __sdk::InModule for Reducer {
|
||||||
impl __sdk::Reducer for Reducer {
|
impl __sdk::Reducer for Reducer {
|
||||||
fn reducer_name(&self) -> &'static str {
|
fn reducer_name(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Reducer::Add { .. } => "add",
|
Reducer::AddPlayer { .. } => "add_player",
|
||||||
Reducer::IdentityConnected => "identity_connected",
|
Reducer::SetName { .. } => "set_name",
|
||||||
Reducer::IdentityDisconnected => "identity_disconnected",
|
Reducer::ShuffleWall => "shuffle_wall",
|
||||||
Reducer::SayHello => "say_hello",
|
Reducer::SortHand => "sort_hand",
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -57,20 +71,28 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
|
||||||
type Error = __sdk::Error;
|
type Error = __sdk::Error;
|
||||||
fn try_from(value: __ws::ReducerCallInfo<__ws::BsatnFormat>) -> __sdk::Result<Self> {
|
fn try_from(value: __ws::ReducerCallInfo<__ws::BsatnFormat>) -> __sdk::Result<Self> {
|
||||||
match &value.reducer_name[..] {
|
match &value.reducer_name[..] {
|
||||||
"add" => {
|
"add_player" => Ok(
|
||||||
Ok(__sdk::parse_reducer_args::<add_reducer::AddArgs>("add", &value.args)?.into())
|
__sdk::parse_reducer_args::<add_player_reducer::AddPlayerArgs>(
|
||||||
}
|
"add_player",
|
||||||
"identity_connected" => Ok(__sdk::parse_reducer_args::<
|
&value.args,
|
||||||
identity_connected_reducer::IdentityConnectedArgs,
|
)?
|
||||||
>("identity_connected", &value.args)?
|
.into(),
|
||||||
|
),
|
||||||
|
"set_name" => Ok(__sdk::parse_reducer_args::<set_name_reducer::SetNameArgs>(
|
||||||
|
"set_name",
|
||||||
|
&value.args,
|
||||||
|
)?
|
||||||
.into()),
|
.into()),
|
||||||
"identity_disconnected" => Ok(__sdk::parse_reducer_args::<
|
"shuffle_wall" => Ok(
|
||||||
identity_disconnected_reducer::IdentityDisconnectedArgs,
|
__sdk::parse_reducer_args::<shuffle_wall_reducer::ShuffleWallArgs>(
|
||||||
>("identity_disconnected", &value.args)?
|
"shuffle_wall",
|
||||||
.into()),
|
&value.args,
|
||||||
"say_hello" => Ok(
|
)?
|
||||||
__sdk::parse_reducer_args::<say_hello_reducer::SayHelloArgs>(
|
.into(),
|
||||||
"say_hello",
|
),
|
||||||
|
"sort_hand" => Ok(
|
||||||
|
__sdk::parse_reducer_args::<sort_hand_reducer::SortHandArgs>(
|
||||||
|
"sort_hand",
|
||||||
&value.args,
|
&value.args,
|
||||||
)?
|
)?
|
||||||
.into(),
|
.into(),
|
||||||
|
|
@ -89,7 +111,9 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct DbUpdate {
|
pub struct DbUpdate {
|
||||||
person: __sdk::TableUpdate<Person>,
|
hand: __sdk::TableUpdate<Hand>,
|
||||||
|
player: __sdk::TableUpdate<Player>,
|
||||||
|
wall: __sdk::TableUpdate<Wall>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
||||||
|
|
@ -98,9 +122,15 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
||||||
let mut db_update = DbUpdate::default();
|
let mut db_update = DbUpdate::default();
|
||||||
for table_update in raw.tables {
|
for table_update in raw.tables {
|
||||||
match &table_update.table_name[..] {
|
match &table_update.table_name[..] {
|
||||||
"person" => db_update
|
"hand" => db_update
|
||||||
.person
|
.hand
|
||||||
.append(person_table::parse_table_update(table_update)?),
|
.append(hand_table::parse_table_update(table_update)?),
|
||||||
|
"player" => db_update
|
||||||
|
.player
|
||||||
|
.append(player_table::parse_table_update(table_update)?),
|
||||||
|
"wall" => db_update
|
||||||
|
.wall
|
||||||
|
.append(wall_table::parse_table_update(table_update)?),
|
||||||
|
|
||||||
unknown => {
|
unknown => {
|
||||||
return Err(__sdk::InternalError::unknown_name(
|
return Err(__sdk::InternalError::unknown_name(
|
||||||
|
|
@ -127,7 +157,11 @@ impl __sdk::DbUpdate for DbUpdate {
|
||||||
) -> AppliedDiff<'_> {
|
) -> AppliedDiff<'_> {
|
||||||
let mut diff = AppliedDiff::default();
|
let mut diff = AppliedDiff::default();
|
||||||
|
|
||||||
diff.person = cache.apply_diff_to_table::<Person>("person", &self.person);
|
diff.hand = cache.apply_diff_to_table::<Hand>("hand", &self.hand);
|
||||||
|
diff.player = cache
|
||||||
|
.apply_diff_to_table::<Player>("player", &self.player)
|
||||||
|
.with_updates_by_pk(|row| &row.identity);
|
||||||
|
diff.wall = cache.apply_diff_to_table::<Wall>("wall", &self.wall);
|
||||||
|
|
||||||
diff
|
diff
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +171,9 @@ impl __sdk::DbUpdate for DbUpdate {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct AppliedDiff<'r> {
|
pub struct AppliedDiff<'r> {
|
||||||
person: __sdk::TableAppliedDiff<'r, Person>,
|
hand: __sdk::TableAppliedDiff<'r, Hand>,
|
||||||
|
player: __sdk::TableAppliedDiff<'r, Player>,
|
||||||
|
wall: __sdk::TableAppliedDiff<'r, Wall>,
|
||||||
__unused: std::marker::PhantomData<&'r ()>,
|
__unused: std::marker::PhantomData<&'r ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -151,7 +187,9 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
|
||||||
event: &EventContext,
|
event: &EventContext,
|
||||||
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
|
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
|
||||||
) {
|
) {
|
||||||
callbacks.invoke_table_row_callbacks::<Person>("person", &self.person, event);
|
callbacks.invoke_table_row_callbacks::<Hand>("hand", &self.hand, event);
|
||||||
|
callbacks.invoke_table_row_callbacks::<Player>("player", &self.player, event);
|
||||||
|
callbacks.invoke_table_row_callbacks::<Wall>("wall", &self.wall, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -871,6 +909,8 @@ impl __sdk::SpacetimeModule for RemoteModule {
|
||||||
type SubscriptionHandle = SubscriptionHandle;
|
type SubscriptionHandle = SubscriptionHandle;
|
||||||
|
|
||||||
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
|
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
|
||||||
person_table::register_table(client_cache);
|
hand_table::register_table(client_cache);
|
||||||
|
player_table::register_table(client_cache);
|
||||||
|
wall_table::register_table(client_cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
|
||||||
use super::person_type::Person;
|
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
/// Table handle for the table `person`.
|
|
||||||
///
|
|
||||||
/// Obtain a handle from the [`PersonTableAccess::person`] method on [`super::RemoteTables`],
|
|
||||||
/// like `ctx.db.person()`.
|
|
||||||
///
|
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
|
||||||
/// but to directly chain method calls,
|
|
||||||
/// like `ctx.db.person().on_insert(...)`.
|
|
||||||
pub struct PersonTableHandle<'ctx> {
|
|
||||||
imp: __sdk::TableHandle<Person>,
|
|
||||||
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
/// Extension trait for access to the table `person`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::RemoteTables`].
|
|
||||||
pub trait PersonTableAccess {
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
/// Obtain a [`PersonTableHandle`], which mediates access to the table `person`.
|
|
||||||
fn person(&self) -> PersonTableHandle<'_>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PersonTableAccess for super::RemoteTables {
|
|
||||||
fn person(&self) -> PersonTableHandle<'_> {
|
|
||||||
PersonTableHandle {
|
|
||||||
imp: self.imp.get_table::<Person>("person"),
|
|
||||||
ctx: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PersonInsertCallbackId(__sdk::CallbackId);
|
|
||||||
pub struct PersonDeleteCallbackId(__sdk::CallbackId);
|
|
||||||
|
|
||||||
impl<'ctx> __sdk::Table for PersonTableHandle<'ctx> {
|
|
||||||
type Row = Person;
|
|
||||||
type EventContext = super::EventContext;
|
|
||||||
|
|
||||||
fn count(&self) -> u64 {
|
|
||||||
self.imp.count()
|
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = Person> + '_ {
|
|
||||||
self.imp.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
type InsertCallbackId = PersonInsertCallbackId;
|
|
||||||
|
|
||||||
fn on_insert(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
|
||||||
) -> PersonInsertCallbackId {
|
|
||||||
PersonInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_on_insert(&self, callback: PersonInsertCallbackId) {
|
|
||||||
self.imp.remove_on_insert(callback.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteCallbackId = PersonDeleteCallbackId;
|
|
||||||
|
|
||||||
fn on_delete(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
|
||||||
) -> PersonDeleteCallbackId {
|
|
||||||
PersonDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_on_delete(&self, callback: PersonDeleteCallbackId) {
|
|
||||||
self.imp.remove_on_delete(callback.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
|
||||||
let _table = client_cache.get_or_make_table::<Person>("person");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub(super) fn parse_table_update(
|
|
||||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
|
||||||
) -> __sdk::Result<__sdk::TableUpdate<Person>> {
|
|
||||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
|
||||||
__sdk::InternalError::failed_parse("TableUpdate<Person>", "TableUpdate")
|
|
||||||
.with_cause(e)
|
|
||||||
.into()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
144
module_bindings/player_table.rs
Normal file
144
module_bindings/player_table.rs
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use super::player_type::Player;
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
/// Table handle for the table `player`.
|
||||||
|
///
|
||||||
|
/// Obtain a handle from the [`PlayerTableAccess::player`] method on [`super::RemoteTables`],
|
||||||
|
/// like `ctx.db.player()`.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player().on_insert(...)`.
|
||||||
|
pub struct PlayerTableHandle<'ctx> {
|
||||||
|
imp: __sdk::TableHandle<Player>,
|
||||||
|
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the table `player`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteTables`].
|
||||||
|
pub trait PlayerTableAccess {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
/// Obtain a [`PlayerTableHandle`], which mediates access to the table `player`.
|
||||||
|
fn player(&self) -> PlayerTableHandle<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerTableAccess for super::RemoteTables {
|
||||||
|
fn player(&self) -> PlayerTableHandle<'_> {
|
||||||
|
PlayerTableHandle {
|
||||||
|
imp: self.imp.get_table::<Player>("player"),
|
||||||
|
ctx: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PlayerInsertCallbackId(__sdk::CallbackId);
|
||||||
|
pub struct PlayerDeleteCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::Table for PlayerTableHandle<'ctx> {
|
||||||
|
type Row = Player;
|
||||||
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
|
fn count(&self) -> u64 {
|
||||||
|
self.imp.count()
|
||||||
|
}
|
||||||
|
fn iter(&self) -> impl Iterator<Item = Player> + '_ {
|
||||||
|
self.imp.iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
type InsertCallbackId = PlayerInsertCallbackId;
|
||||||
|
|
||||||
|
fn on_insert(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerInsertCallbackId {
|
||||||
|
PlayerInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_insert(&self, callback: PlayerInsertCallbackId) {
|
||||||
|
self.imp.remove_on_insert(callback.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteCallbackId = PlayerDeleteCallbackId;
|
||||||
|
|
||||||
|
fn on_delete(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerDeleteCallbackId {
|
||||||
|
PlayerDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_delete(&self, callback: PlayerDeleteCallbackId) {
|
||||||
|
self.imp.remove_on_delete(callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||||
|
let _table = client_cache.get_or_make_table::<Player>("player");
|
||||||
|
_table.add_unique_constraint::<__sdk::Identity>("identity", |row| &row.identity);
|
||||||
|
}
|
||||||
|
pub struct PlayerUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::TableWithPrimaryKey for PlayerTableHandle<'ctx> {
|
||||||
|
type UpdateCallbackId = PlayerUpdateCallbackId;
|
||||||
|
|
||||||
|
fn on_update(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerUpdateCallbackId {
|
||||||
|
PlayerUpdateCallbackId(self.imp.on_update(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_update(&self, callback: PlayerUpdateCallbackId) {
|
||||||
|
self.imp.remove_on_update(callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(super) fn parse_table_update(
|
||||||
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
|
) -> __sdk::Result<__sdk::TableUpdate<Player>> {
|
||||||
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
|
__sdk::InternalError::failed_parse("TableUpdate<Player>", "TableUpdate")
|
||||||
|
.with_cause(e)
|
||||||
|
.into()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `identity` unique index on the table `player`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`PlayerIdentityUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player().identity().find(...)`.
|
||||||
|
pub struct PlayerIdentityUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<Player, __sdk::Identity>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `identity` unique index on the table `player`.
|
||||||
|
pub fn identity(&self) -> PlayerIdentityUnique<'ctx> {
|
||||||
|
PlayerIdentityUnique {
|
||||||
|
imp: self
|
||||||
|
.imp
|
||||||
|
.get_unique_constraint::<__sdk::Identity>("identity"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerIdentityUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `identity` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &__sdk::Identity) -> Option<Player> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
18
module_bindings/player_type.rs
Normal file
18
module_bindings/player_type.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub struct Player {
|
||||||
|
pub identity: __sdk::Identity,
|
||||||
|
pub id: u32,
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub host: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for Player {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
@ -6,10 +6,10 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
#[sats(crate = __lib)]
|
#[sats(crate = __lib)]
|
||||||
pub struct Person {
|
pub struct Rank {
|
||||||
pub name: String,
|
pub number: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for Person {
|
impl __sdk::InModule for Rank {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
@ -6,65 +6,65 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
#[sats(crate = __lib)]
|
#[sats(crate = __lib)]
|
||||||
pub(super) struct AddArgs {
|
pub(super) struct SetNameArgs {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AddArgs> for super::Reducer {
|
impl From<SetNameArgs> for super::Reducer {
|
||||||
fn from(args: AddArgs) -> Self {
|
fn from(args: SetNameArgs) -> Self {
|
||||||
Self::Add { name: args.name }
|
Self::SetName { name: args.name }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for AddArgs {
|
impl __sdk::InModule for SetNameArgs {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AddCallbackId(__sdk::CallbackId);
|
pub struct SetNameCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
/// Extension trait for access to the reducer `add`.
|
/// Extension trait for access to the reducer `set_name`.
|
||||||
///
|
///
|
||||||
/// Implemented for [`super::RemoteReducers`].
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
pub trait add {
|
pub trait set_name {
|
||||||
/// Request that the remote module invoke the reducer `add` to run as soon as possible.
|
/// Request that the remote module invoke the reducer `set_name` to run as soon as possible.
|
||||||
///
|
///
|
||||||
/// This method returns immediately, and errors only if we are unable to send the request.
|
/// This method returns immediately, and errors only if we are unable to send the request.
|
||||||
/// The reducer will run asynchronously in the future,
|
/// The reducer will run asynchronously in the future,
|
||||||
/// and its status can be observed by listening for [`Self::on_add`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_set_name`] callbacks.
|
||||||
fn add(&self, name: String) -> __sdk::Result<()>;
|
fn set_name(&self, name: String) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `add`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `set_name`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
/// to determine the reducer's status.
|
/// to determine the reducer's status.
|
||||||
///
|
///
|
||||||
/// The returned [`AddCallbackId`] can be passed to [`Self::remove_on_add`]
|
/// The returned [`SetNameCallbackId`] can be passed to [`Self::remove_on_set_name`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_add(
|
fn on_set_name(
|
||||||
&self,
|
&self,
|
||||||
callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static,
|
callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static,
|
||||||
) -> AddCallbackId;
|
) -> SetNameCallbackId;
|
||||||
/// Cancel a callback previously registered by [`Self::on_add`],
|
/// Cancel a callback previously registered by [`Self::on_set_name`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_add(&self, callback: AddCallbackId);
|
fn remove_on_set_name(&self, callback: SetNameCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl add for super::RemoteReducers {
|
impl set_name for super::RemoteReducers {
|
||||||
fn add(&self, name: String) -> __sdk::Result<()> {
|
fn set_name(&self, name: String) -> __sdk::Result<()> {
|
||||||
self.imp.call_reducer("add", AddArgs { name })
|
self.imp.call_reducer("set_name", SetNameArgs { name })
|
||||||
}
|
}
|
||||||
fn on_add(
|
fn on_set_name(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static,
|
||||||
) -> AddCallbackId {
|
) -> SetNameCallbackId {
|
||||||
AddCallbackId(self.imp.on_reducer(
|
SetNameCallbackId(self.imp.on_reducer(
|
||||||
"add",
|
"set_name",
|
||||||
Box::new(move |ctx: &super::ReducerEventContext| {
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
let super::ReducerEventContext {
|
let super::ReducerEventContext {
|
||||||
event:
|
event:
|
||||||
__sdk::ReducerEvent {
|
__sdk::ReducerEvent {
|
||||||
reducer: super::Reducer::Add { name },
|
reducer: super::Reducer::SetName { name },
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
|
|
@ -76,27 +76,27 @@ impl add for super::RemoteReducers {
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
fn remove_on_add(&self, callback: AddCallbackId) {
|
fn remove_on_set_name(&self, callback: SetNameCallbackId) {
|
||||||
self.imp.remove_on_reducer("add", callback.0)
|
self.imp.remove_on_reducer("set_name", callback.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Extension trait for setting the call-flags for the reducer `add`.
|
/// Extension trait for setting the call-flags for the reducer `set_name`.
|
||||||
///
|
///
|
||||||
/// Implemented for [`super::SetReducerFlags`].
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
///
|
///
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
pub trait set_flags_for_add {
|
pub trait set_flags_for_set_name {
|
||||||
/// Set the call-reducer flags for the reducer `add` to `flags`.
|
/// Set the call-reducer flags for the reducer `set_name` to `flags`.
|
||||||
///
|
///
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
fn add(&self, flags: __ws::CallReducerFlags);
|
fn set_name(&self, flags: __ws::CallReducerFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl set_flags_for_add for super::SetReducerFlags {
|
impl set_flags_for_set_name for super::SetReducerFlags {
|
||||||
fn add(&self, flags: __ws::CallReducerFlags) {
|
fn set_name(&self, flags: __ws::CallReducerFlags) {
|
||||||
self.imp.set_call_reducer_flags("add", flags);
|
self.imp.set_call_reducer_flags("set_name", flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,64 +6,63 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
#[sats(crate = __lib)]
|
#[sats(crate = __lib)]
|
||||||
pub(super) struct IdentityConnectedArgs {}
|
pub(super) struct ShuffleWallArgs {}
|
||||||
|
|
||||||
impl From<IdentityConnectedArgs> for super::Reducer {
|
impl From<ShuffleWallArgs> for super::Reducer {
|
||||||
fn from(args: IdentityConnectedArgs) -> Self {
|
fn from(args: ShuffleWallArgs) -> Self {
|
||||||
Self::IdentityConnected
|
Self::ShuffleWall
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for IdentityConnectedArgs {
|
impl __sdk::InModule for ShuffleWallArgs {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IdentityConnectedCallbackId(__sdk::CallbackId);
|
pub struct ShuffleWallCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
/// Extension trait for access to the reducer `identity_connected`.
|
/// Extension trait for access to the reducer `shuffle_wall`.
|
||||||
///
|
///
|
||||||
/// Implemented for [`super::RemoteReducers`].
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
pub trait identity_connected {
|
pub trait shuffle_wall {
|
||||||
/// Request that the remote module invoke the reducer `identity_connected` to run as soon as possible.
|
/// Request that the remote module invoke the reducer `shuffle_wall` to run as soon as possible.
|
||||||
///
|
///
|
||||||
/// This method returns immediately, and errors only if we are unable to send the request.
|
/// This method returns immediately, and errors only if we are unable to send the request.
|
||||||
/// The reducer will run asynchronously in the future,
|
/// The reducer will run asynchronously in the future,
|
||||||
/// and its status can be observed by listening for [`Self::on_identity_connected`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_shuffle_wall`] callbacks.
|
||||||
fn identity_connected(&self) -> __sdk::Result<()>;
|
fn shuffle_wall(&self) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `identity_connected`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `shuffle_wall`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
/// to determine the reducer's status.
|
/// to determine the reducer's status.
|
||||||
///
|
///
|
||||||
/// The returned [`IdentityConnectedCallbackId`] can be passed to [`Self::remove_on_identity_connected`]
|
/// The returned [`ShuffleWallCallbackId`] can be passed to [`Self::remove_on_shuffle_wall`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_identity_connected(
|
fn on_shuffle_wall(
|
||||||
&self,
|
&self,
|
||||||
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
||||||
) -> IdentityConnectedCallbackId;
|
) -> ShuffleWallCallbackId;
|
||||||
/// Cancel a callback previously registered by [`Self::on_identity_connected`],
|
/// Cancel a callback previously registered by [`Self::on_shuffle_wall`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_identity_connected(&self, callback: IdentityConnectedCallbackId);
|
fn remove_on_shuffle_wall(&self, callback: ShuffleWallCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl identity_connected for super::RemoteReducers {
|
impl shuffle_wall for super::RemoteReducers {
|
||||||
fn identity_connected(&self) -> __sdk::Result<()> {
|
fn shuffle_wall(&self) -> __sdk::Result<()> {
|
||||||
self.imp
|
self.imp.call_reducer("shuffle_wall", ShuffleWallArgs {})
|
||||||
.call_reducer("identity_connected", IdentityConnectedArgs {})
|
|
||||||
}
|
}
|
||||||
fn on_identity_connected(
|
fn on_shuffle_wall(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
||||||
) -> IdentityConnectedCallbackId {
|
) -> ShuffleWallCallbackId {
|
||||||
IdentityConnectedCallbackId(self.imp.on_reducer(
|
ShuffleWallCallbackId(self.imp.on_reducer(
|
||||||
"identity_connected",
|
"shuffle_wall",
|
||||||
Box::new(move |ctx: &super::ReducerEventContext| {
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
let super::ReducerEventContext {
|
let super::ReducerEventContext {
|
||||||
event:
|
event:
|
||||||
__sdk::ReducerEvent {
|
__sdk::ReducerEvent {
|
||||||
reducer: super::Reducer::IdentityConnected {},
|
reducer: super::Reducer::ShuffleWall {},
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
|
|
@ -75,27 +74,27 @@ impl identity_connected for super::RemoteReducers {
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
fn remove_on_identity_connected(&self, callback: IdentityConnectedCallbackId) {
|
fn remove_on_shuffle_wall(&self, callback: ShuffleWallCallbackId) {
|
||||||
self.imp.remove_on_reducer("identity_connected", callback.0)
|
self.imp.remove_on_reducer("shuffle_wall", callback.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Extension trait for setting the call-flags for the reducer `identity_connected`.
|
/// Extension trait for setting the call-flags for the reducer `shuffle_wall`.
|
||||||
///
|
///
|
||||||
/// Implemented for [`super::SetReducerFlags`].
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
///
|
///
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
pub trait set_flags_for_identity_connected {
|
pub trait set_flags_for_shuffle_wall {
|
||||||
/// Set the call-reducer flags for the reducer `identity_connected` to `flags`.
|
/// Set the call-reducer flags for the reducer `shuffle_wall` to `flags`.
|
||||||
///
|
///
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
fn identity_connected(&self, flags: __ws::CallReducerFlags);
|
fn shuffle_wall(&self, flags: __ws::CallReducerFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl set_flags_for_identity_connected for super::SetReducerFlags {
|
impl set_flags_for_shuffle_wall for super::SetReducerFlags {
|
||||||
fn identity_connected(&self, flags: __ws::CallReducerFlags) {
|
fn shuffle_wall(&self, flags: __ws::CallReducerFlags) {
|
||||||
self.imp.set_call_reducer_flags("identity_connected", flags);
|
self.imp.set_call_reducer_flags("shuffle_wall", flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,63 +6,63 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
#[sats(crate = __lib)]
|
#[sats(crate = __lib)]
|
||||||
pub(super) struct SayHelloArgs {}
|
pub(super) struct SortHandArgs {}
|
||||||
|
|
||||||
impl From<SayHelloArgs> for super::Reducer {
|
impl From<SortHandArgs> for super::Reducer {
|
||||||
fn from(args: SayHelloArgs) -> Self {
|
fn from(args: SortHandArgs) -> Self {
|
||||||
Self::SayHello
|
Self::SortHand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for SayHelloArgs {
|
impl __sdk::InModule for SortHandArgs {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SayHelloCallbackId(__sdk::CallbackId);
|
pub struct SortHandCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
/// Extension trait for access to the reducer `say_hello`.
|
/// Extension trait for access to the reducer `sort_hand`.
|
||||||
///
|
///
|
||||||
/// Implemented for [`super::RemoteReducers`].
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
pub trait say_hello {
|
pub trait sort_hand {
|
||||||
/// Request that the remote module invoke the reducer `say_hello` to run as soon as possible.
|
/// Request that the remote module invoke the reducer `sort_hand` to run as soon as possible.
|
||||||
///
|
///
|
||||||
/// This method returns immediately, and errors only if we are unable to send the request.
|
/// This method returns immediately, and errors only if we are unable to send the request.
|
||||||
/// The reducer will run asynchronously in the future,
|
/// The reducer will run asynchronously in the future,
|
||||||
/// and its status can be observed by listening for [`Self::on_say_hello`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_sort_hand`] callbacks.
|
||||||
fn say_hello(&self) -> __sdk::Result<()>;
|
fn sort_hand(&self) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `say_hello`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `sort_hand`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
/// to determine the reducer's status.
|
/// to determine the reducer's status.
|
||||||
///
|
///
|
||||||
/// The returned [`SayHelloCallbackId`] can be passed to [`Self::remove_on_say_hello`]
|
/// The returned [`SortHandCallbackId`] can be passed to [`Self::remove_on_sort_hand`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_say_hello(
|
fn on_sort_hand(
|
||||||
&self,
|
&self,
|
||||||
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
||||||
) -> SayHelloCallbackId;
|
) -> SortHandCallbackId;
|
||||||
/// Cancel a callback previously registered by [`Self::on_say_hello`],
|
/// Cancel a callback previously registered by [`Self::on_sort_hand`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_say_hello(&self, callback: SayHelloCallbackId);
|
fn remove_on_sort_hand(&self, callback: SortHandCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl say_hello for super::RemoteReducers {
|
impl sort_hand for super::RemoteReducers {
|
||||||
fn say_hello(&self) -> __sdk::Result<()> {
|
fn sort_hand(&self) -> __sdk::Result<()> {
|
||||||
self.imp.call_reducer("say_hello", SayHelloArgs {})
|
self.imp.call_reducer("sort_hand", SortHandArgs {})
|
||||||
}
|
}
|
||||||
fn on_say_hello(
|
fn on_sort_hand(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
||||||
) -> SayHelloCallbackId {
|
) -> SortHandCallbackId {
|
||||||
SayHelloCallbackId(self.imp.on_reducer(
|
SortHandCallbackId(self.imp.on_reducer(
|
||||||
"say_hello",
|
"sort_hand",
|
||||||
Box::new(move |ctx: &super::ReducerEventContext| {
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
#[allow(irrefutable_let_patterns)]
|
#[allow(irrefutable_let_patterns)]
|
||||||
let super::ReducerEventContext {
|
let super::ReducerEventContext {
|
||||||
event:
|
event:
|
||||||
__sdk::ReducerEvent {
|
__sdk::ReducerEvent {
|
||||||
reducer: super::Reducer::SayHello {},
|
reducer: super::Reducer::SortHand {},
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
|
|
@ -74,27 +74,27 @@ impl say_hello for super::RemoteReducers {
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
fn remove_on_say_hello(&self, callback: SayHelloCallbackId) {
|
fn remove_on_sort_hand(&self, callback: SortHandCallbackId) {
|
||||||
self.imp.remove_on_reducer("say_hello", callback.0)
|
self.imp.remove_on_reducer("sort_hand", callback.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
/// Extension trait for setting the call-flags for the reducer `say_hello`.
|
/// Extension trait for setting the call-flags for the reducer `sort_hand`.
|
||||||
///
|
///
|
||||||
/// Implemented for [`super::SetReducerFlags`].
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
///
|
///
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
pub trait set_flags_for_say_hello {
|
pub trait set_flags_for_sort_hand {
|
||||||
/// Set the call-reducer flags for the reducer `say_hello` to `flags`.
|
/// Set the call-reducer flags for the reducer `sort_hand` to `flags`.
|
||||||
///
|
///
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
fn say_hello(&self, flags: __ws::CallReducerFlags);
|
fn sort_hand(&self, flags: __ws::CallReducerFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl set_flags_for_say_hello for super::SetReducerFlags {
|
impl set_flags_for_sort_hand for super::SetReducerFlags {
|
||||||
fn say_hello(&self, flags: __ws::CallReducerFlags) {
|
fn sort_hand(&self, flags: __ws::CallReducerFlags) {
|
||||||
self.imp.set_call_reducer_flags("say_hello", flags);
|
self.imp.set_call_reducer_flags("sort_hand", flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
27
module_bindings/suit_type.rs
Normal file
27
module_bindings/suit_type.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
use super::dragon_type::Dragon;
|
||||||
|
use super::rank_type::Rank;
|
||||||
|
use super::wind_type::Wind;
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub enum Suit {
|
||||||
|
Man(Rank),
|
||||||
|
|
||||||
|
Pin(Rank),
|
||||||
|
|
||||||
|
Sou(Rank),
|
||||||
|
|
||||||
|
Wind(Wind),
|
||||||
|
|
||||||
|
Dragon(Dragon),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for Suit {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
17
module_bindings/tile_type.rs
Normal file
17
module_bindings/tile_type.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
use super::suit_type::Suit;
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub struct Tile {
|
||||||
|
pub suit: Suit,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for Tile {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
96
module_bindings/wall_table.rs
Normal file
96
module_bindings/wall_table.rs
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use super::tile_type::Tile;
|
||||||
|
use super::wall_type::Wall;
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
/// Table handle for the table `wall`.
|
||||||
|
///
|
||||||
|
/// Obtain a handle from the [`WallTableAccess::wall`] method on [`super::RemoteTables`],
|
||||||
|
/// like `ctx.db.wall()`.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.wall().on_insert(...)`.
|
||||||
|
pub struct WallTableHandle<'ctx> {
|
||||||
|
imp: __sdk::TableHandle<Wall>,
|
||||||
|
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the table `wall`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteTables`].
|
||||||
|
pub trait WallTableAccess {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
/// Obtain a [`WallTableHandle`], which mediates access to the table `wall`.
|
||||||
|
fn wall(&self) -> WallTableHandle<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WallTableAccess for super::RemoteTables {
|
||||||
|
fn wall(&self) -> WallTableHandle<'_> {
|
||||||
|
WallTableHandle {
|
||||||
|
imp: self.imp.get_table::<Wall>("wall"),
|
||||||
|
ctx: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WallInsertCallbackId(__sdk::CallbackId);
|
||||||
|
pub struct WallDeleteCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::Table for WallTableHandle<'ctx> {
|
||||||
|
type Row = Wall;
|
||||||
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
|
fn count(&self) -> u64 {
|
||||||
|
self.imp.count()
|
||||||
|
}
|
||||||
|
fn iter(&self) -> impl Iterator<Item = Wall> + '_ {
|
||||||
|
self.imp.iter()
|
||||||
|
}
|
||||||
|
|
||||||
|
type InsertCallbackId = WallInsertCallbackId;
|
||||||
|
|
||||||
|
fn on_insert(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> WallInsertCallbackId {
|
||||||
|
WallInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_insert(&self, callback: WallInsertCallbackId) {
|
||||||
|
self.imp.remove_on_insert(callback.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteCallbackId = WallDeleteCallbackId;
|
||||||
|
|
||||||
|
fn on_delete(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> WallDeleteCallbackId {
|
||||||
|
WallDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_delete(&self, callback: WallDeleteCallbackId) {
|
||||||
|
self.imp.remove_on_delete(callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||||
|
let _table = client_cache.get_or_make_table::<Wall>("wall");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(super) fn parse_table_update(
|
||||||
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
|
) -> __sdk::Result<__sdk::TableUpdate<Wall>> {
|
||||||
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
|
__sdk::InternalError::failed_parse("TableUpdate<Wall>", "TableUpdate")
|
||||||
|
.with_cause(e)
|
||||||
|
.into()
|
||||||
|
})
|
||||||
|
}
|
||||||
17
module_bindings/wall_type.rs
Normal file
17
module_bindings/wall_type.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
use super::tile_type::Tile;
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub struct Wall {
|
||||||
|
pub tiles: Vec<Tile>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for Wall {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
22
module_bindings/wind_type.rs
Normal file
22
module_bindings/wind_type.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||||
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
#[derive(Copy, Eq, Hash)]
|
||||||
|
pub enum Wind {
|
||||||
|
Ton,
|
||||||
|
|
||||||
|
Nan,
|
||||||
|
|
||||||
|
Shaa,
|
||||||
|
|
||||||
|
Pei,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for Wind {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
@ -11,4 +11,4 @@ crate-type = ["cdylib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
spacetimedb = { workspace = true }
|
spacetimedb = { workspace = true }
|
||||||
log = { 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)]
|
#[table(name = player, public)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
#[primary_key]
|
#[primary_key]
|
||||||
identity: Identity,
|
identity: Identity,
|
||||||
|
#[auto_inc]
|
||||||
|
id: u32,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
host: bool,
|
host: bool,
|
||||||
}
|
}
|
||||||
|
|
@ -15,20 +17,14 @@ pub struct Wall {
|
||||||
tiles: Vec<Tile>,
|
tiles: Vec<Tile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[reducer(init)]
|
#[table(name = hand)]
|
||||||
pub fn init(_ctx: &ReducerContext) {
|
pub struct Hand {
|
||||||
// Called when the module is initially published
|
player_id: u32,
|
||||||
|
tiles: Vec<Tile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[reducer(client_connected)]
|
#[reducer]
|
||||||
pub fn identity_connected(_ctx: &ReducerContext) {
|
pub fn add_player(ctx: &ReducerContext, name: Option<String>) {}
|
||||||
// Called everytime a new client connects
|
|
||||||
}
|
|
||||||
|
|
||||||
#[reducer(client_disconnected)]
|
|
||||||
pub fn identity_disconnected(_ctx: &ReducerContext) {
|
|
||||||
// Called everytime a client disconnects
|
|
||||||
}
|
|
||||||
|
|
||||||
#[reducer]
|
#[reducer]
|
||||||
pub fn set_name(ctx: &ReducerContext, name: String) -> Result<(), String> {
|
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]
|
#[reducer]
|
||||||
pub fn shuffle_wall(ctx: &ReducerContext) {
|
pub fn shuffle_wall(ctx: &ReducerContext) {
|
||||||
let mut rng = ctx.rng();
|
let mut rng = ctx.rng();
|
||||||
let mut tiles: Vec<Tile> = todo();
|
let mut tiles: Vec<Tile> = tiles();
|
||||||
|
tiles.shuffle(&mut rng);
|
||||||
// rng.fill();
|
ctx.db.wall().insert(Wall { tiles });
|
||||||
// let tiles = rng.sh;
|
|
||||||
|
|
||||||
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]
|
// #[reducer]
|
||||||
// pub fn add(ctx: &ReducerContext, name: String) {
|
// pub fn add(ctx: &ReducerContext, name: String) {
|
||||||
// ctx.db.player().insert(Player { name });
|
// ctx.db.player().insert(Player { name });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue