Compare commits
No commits in common. "400e903dd11ef42d196808f44287dfd448abc23b" and "7cbe10c19e502cdc5c23b27f736a25157ba86bd7" have entirely different histories.
400e903dd1
...
7cbe10c19e
32 changed files with 143 additions and 2817 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1 +1 @@
|
||||||
target
|
/target
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
[editor]
|
|
||||||
workspace-lsp-roots = ["jongline"]
|
|
||||||
1476
Cargo.lock
generated
1476
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
35
Cargo.toml
35
Cargo.toml
|
|
@ -1,3 +1,32 @@
|
||||||
[workspace]
|
[package]
|
||||||
resolver = "3"
|
name = "jong"
|
||||||
members = ["jong", "jongline"]
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
# license = "Source-First-1.1" # pending crates.io support
|
||||||
|
license-file = "LICENSE.typ"
|
||||||
|
description = "riichi mahjong"
|
||||||
|
readme = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bevy = { version = "0.17.3", features = ["dynamic_linking"] }
|
||||||
|
# bevy_ratatui = { git = "https://github.com/kenianbei/bevy_ratatui.git", rev = "e4b022308e08ab360ef89eca8e9f8b1c969e9a56" }
|
||||||
|
bevy_ratatui = { path = "/home/tao/clones/bevy_ratatui" }
|
||||||
|
clap = { version = "4.5.54", features = ["derive"] }
|
||||||
|
log = { version = "0.4.29", features = [
|
||||||
|
"release_max_level_error",
|
||||||
|
"max_level_trace",
|
||||||
|
] }
|
||||||
|
rand = "0.9.2"
|
||||||
|
ratatui = "0.30.0"
|
||||||
|
strum = { version = "0.27.2", features = ["derive"] }
|
||||||
|
tracing = "0.1.44"
|
||||||
|
tracing-subscriber = "0.3.22"
|
||||||
|
tui-logger = { version = "0.18.0", features = ["tracing-support", "crossterm"] }
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 1
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
opt-level = 3
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,7 @@
|
||||||
buildInputs =
|
buildInputs =
|
||||||
[
|
[
|
||||||
# Rust dependencies
|
# Rust dependencies
|
||||||
(rust-bin.nightly.latest.default.override {
|
(rust-bin.nightly.latest.default.override {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"];
|
|
||||||
})
|
|
||||||
pkg-config
|
pkg-config
|
||||||
]
|
]
|
||||||
++ lib.optionals (lib.strings.hasInfix "linux" system) [
|
++ lib.optionals (lib.strings.hasInfix "linux" system) [
|
||||||
|
|
@ -47,10 +44,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 [
|
LD_LIBRARY_PATH = lib.makeLibraryPath [
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "jong"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
# license = "Source-First-1.1" # pending crates.io support
|
|
||||||
license-file = "LICENSE.typ"
|
|
||||||
description = "riichi mahjong"
|
|
||||||
readme = false
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bevy = { version = "0.17.3", features = ["dynamic_linking"] }
|
|
||||||
# bevy_ratatui = { git = "https://github.com/kenianbei/bevy_ratatui.git", rev = "e4b022308e08ab360ef89eca8e9f8b1c969e9a56" }
|
|
||||||
bevy_ratatui = { path = "/home/tao/clones/bevy_ratatui" }
|
|
||||||
bevy_spacetimedb = "0.7"
|
|
||||||
clap = { version = "4.5.54", features = ["derive"] }
|
|
||||||
jongline = { version = "0.1.0", path = "../jongline" }
|
|
||||||
log = { version = "0.4.29", features = [
|
|
||||||
"release_max_level_error",
|
|
||||||
"max_level_trace",
|
|
||||||
] }
|
|
||||||
rand = "0.9.2"
|
|
||||||
ratatui = "0.30.0"
|
|
||||||
strum = { version = "0.27.2", features = ["derive"] }
|
|
||||||
tracing = "0.1.44"
|
|
||||||
tracing-subscriber = "0.3.22"
|
|
||||||
tui-logger = { version = "0.18.0", features = ["tracing-support", "crossterm"] }
|
|
||||||
|
|
||||||
[profile.dev]
|
|
||||||
opt-level = 1
|
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
|
||||||
opt-level = 3
|
|
||||||
|
|
@ -1,102 +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 AddArgs {
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<AddArgs> for super::Reducer {
|
|
||||||
fn from(args: AddArgs) -> Self {
|
|
||||||
Self::Add { name: args.name }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for AddArgs {
|
|
||||||
type Module = super::RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct AddCallbackId(__sdk::CallbackId);
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
/// Extension trait for access to the reducer `add`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::RemoteReducers`].
|
|
||||||
pub trait add {
|
|
||||||
/// Request that the remote module invoke the reducer `add` 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`] callbacks.
|
|
||||||
fn add(&self, name: String) -> __sdk::Result<()>;
|
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `add`.
|
|
||||||
///
|
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
|
||||||
/// to determine the reducer's status.
|
|
||||||
///
|
|
||||||
/// The returned [`AddCallbackId`] can be passed to [`Self::remove_on_add`]
|
|
||||||
/// to cancel the callback.
|
|
||||||
fn on_add(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static,
|
|
||||||
) -> AddCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_add`],
|
|
||||||
/// causing it not to run in the future.
|
|
||||||
fn remove_on_add(&self, callback: AddCallbackId);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl add for super::RemoteReducers {
|
|
||||||
fn add(&self, name: String) -> __sdk::Result<()> {
|
|
||||||
self.imp.call_reducer("add", AddArgs { name })
|
|
||||||
}
|
|
||||||
fn on_add(
|
|
||||||
&self,
|
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext, &String) + Send + 'static,
|
|
||||||
) -> AddCallbackId {
|
|
||||||
AddCallbackId(self.imp.on_reducer(
|
|
||||||
"add",
|
|
||||||
Box::new(move |ctx: &super::ReducerEventContext| {
|
|
||||||
#[allow(irrefutable_let_patterns)]
|
|
||||||
let super::ReducerEventContext {
|
|
||||||
event:
|
|
||||||
__sdk::ReducerEvent {
|
|
||||||
reducer: super::Reducer::Add { name },
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} = ctx
|
|
||||||
else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx, name)
|
|
||||||
}),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
fn remove_on_add(&self, callback: AddCallbackId) {
|
|
||||||
self.imp.remove_on_reducer("add", callback.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
/// Extension trait for setting the call-flags for the reducer `add`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub trait set_flags_for_add {
|
|
||||||
/// Set the call-reducer flags for the reducer `add` to `flags`.
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
fn add(&self, flags: __ws::CallReducerFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl set_flags_for_add for super::SetReducerFlags {
|
|
||||||
fn add(&self, flags: __ws::CallReducerFlags) {
|
|
||||||
self.imp.set_call_reducer_flags("add", flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,101 +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 IdentityConnectedArgs {}
|
|
||||||
|
|
||||||
impl From<IdentityConnectedArgs> for super::Reducer {
|
|
||||||
fn from(args: IdentityConnectedArgs) -> Self {
|
|
||||||
Self::IdentityConnected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for IdentityConnectedArgs {
|
|
||||||
type Module = super::RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct IdentityConnectedCallbackId(__sdk::CallbackId);
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
/// Extension trait for access to the reducer `identity_connected`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::RemoteReducers`].
|
|
||||||
pub trait identity_connected {
|
|
||||||
/// Request that the remote module invoke the reducer `identity_connected` 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_connected`] callbacks.
|
|
||||||
fn identity_connected(&self) -> __sdk::Result<()>;
|
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `identity_connected`.
|
|
||||||
///
|
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
|
||||||
/// to determine the reducer's status.
|
|
||||||
///
|
|
||||||
/// The returned [`IdentityConnectedCallbackId`] can be passed to [`Self::remove_on_identity_connected`]
|
|
||||||
/// to cancel the callback.
|
|
||||||
fn on_identity_connected(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
|
||||||
) -> IdentityConnectedCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_identity_connected`],
|
|
||||||
/// causing it not to run in the future.
|
|
||||||
fn remove_on_identity_connected(&self, callback: IdentityConnectedCallbackId);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl identity_connected for super::RemoteReducers {
|
|
||||||
fn identity_connected(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp
|
|
||||||
.call_reducer("identity_connected", IdentityConnectedArgs {})
|
|
||||||
}
|
|
||||||
fn on_identity_connected(
|
|
||||||
&self,
|
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
|
||||||
) -> IdentityConnectedCallbackId {
|
|
||||||
IdentityConnectedCallbackId(self.imp.on_reducer(
|
|
||||||
"identity_connected",
|
|
||||||
Box::new(move |ctx: &super::ReducerEventContext| {
|
|
||||||
#[allow(irrefutable_let_patterns)]
|
|
||||||
let super::ReducerEventContext {
|
|
||||||
event:
|
|
||||||
__sdk::ReducerEvent {
|
|
||||||
reducer: super::Reducer::IdentityConnected {},
|
|
||||||
..
|
|
||||||
},
|
|
||||||
..
|
|
||||||
} = ctx
|
|
||||||
else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx)
|
|
||||||
}),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
fn remove_on_identity_connected(&self, callback: IdentityConnectedCallbackId) {
|
|
||||||
self.imp.remove_on_reducer("identity_connected", callback.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
/// Extension trait for setting the call-flags for the reducer `identity_connected`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub trait set_flags_for_identity_connected {
|
|
||||||
/// Set the call-reducer flags for the reducer `identity_connected` to `flags`.
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
fn identity_connected(&self, flags: __ws::CallReducerFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl set_flags_for_identity_connected for super::SetReducerFlags {
|
|
||||||
fn identity_connected(&self, flags: __ws::CallReducerFlags) {
|
|
||||||
self.imp.set_call_reducer_flags("identity_connected", flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,865 +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.
|
|
||||||
|
|
||||||
// This was generated using spacetimedb cli version 1.11.3 (commit 02449737ca3b29e7e39679fccbef541a50f32094).
|
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
pub mod add_reducer;
|
|
||||||
pub mod identity_connected_reducer;
|
|
||||||
pub mod identity_disconnected_reducer;
|
|
||||||
pub mod player_type;
|
|
||||||
pub mod players_table;
|
|
||||||
|
|
||||||
pub use add_reducer::{add, set_flags_for_add, AddCallbackId};
|
|
||||||
pub use identity_connected_reducer::{
|
|
||||||
identity_connected, set_flags_for_identity_connected, IdentityConnectedCallbackId,
|
|
||||||
};
|
|
||||||
pub use identity_disconnected_reducer::{
|
|
||||||
identity_disconnected, set_flags_for_identity_disconnected, IdentityDisconnectedCallbackId,
|
|
||||||
};
|
|
||||||
pub use player_type::Player;
|
|
||||||
pub use players_table::*;
|
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
|
||||||
|
|
||||||
/// One of the reducers defined by this module.
|
|
||||||
///
|
|
||||||
/// Contained within a [`__sdk::ReducerEvent`] in [`EventContext`]s for reducer events
|
|
||||||
/// to indicate which reducer caused the event.
|
|
||||||
|
|
||||||
pub enum Reducer {
|
|
||||||
Add { name: String },
|
|
||||||
IdentityConnected,
|
|
||||||
IdentityDisconnected,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for Reducer {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::Reducer for Reducer {
|
|
||||||
fn reducer_name(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Reducer::Add { .. } => "add",
|
|
||||||
Reducer::IdentityConnected => "identity_connected",
|
|
||||||
Reducer::IdentityDisconnected => "identity_disconnected",
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
|
|
||||||
type Error = __sdk::Error;
|
|
||||||
fn try_from(value: __ws::ReducerCallInfo<__ws::BsatnFormat>) -> __sdk::Result<Self> {
|
|
||||||
match &value.reducer_name[..] {
|
|
||||||
"add" => {
|
|
||||||
Ok(__sdk::parse_reducer_args::<add_reducer::AddArgs>("add", &value.args)?.into())
|
|
||||||
}
|
|
||||||
"identity_connected" => Ok(__sdk::parse_reducer_args::<
|
|
||||||
identity_connected_reducer::IdentityConnectedArgs,
|
|
||||||
>("identity_connected", &value.args)?
|
|
||||||
.into()),
|
|
||||||
"identity_disconnected" => Ok(__sdk::parse_reducer_args::<
|
|
||||||
identity_disconnected_reducer::IdentityDisconnectedArgs,
|
|
||||||
>("identity_disconnected", &value.args)?
|
|
||||||
.into()),
|
|
||||||
unknown => {
|
|
||||||
Err(
|
|
||||||
__sdk::InternalError::unknown_name("reducer", unknown, "ReducerCallInfo")
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct DbUpdate {
|
|
||||||
players: __sdk::TableUpdate<Player>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
|
||||||
type Error = __sdk::Error;
|
|
||||||
fn try_from(raw: __ws::DatabaseUpdate<__ws::BsatnFormat>) -> Result<Self, Self::Error> {
|
|
||||||
let mut db_update = DbUpdate::default();
|
|
||||||
for table_update in raw.tables {
|
|
||||||
match &table_update.table_name[..] {
|
|
||||||
"players" => db_update
|
|
||||||
.players
|
|
||||||
.append(players_table::parse_table_update(table_update)?),
|
|
||||||
|
|
||||||
unknown => {
|
|
||||||
return Err(__sdk::InternalError::unknown_name(
|
|
||||||
"table",
|
|
||||||
unknown,
|
|
||||||
"DatabaseUpdate",
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(db_update)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for DbUpdate {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbUpdate for DbUpdate {
|
|
||||||
fn apply_to_client_cache(
|
|
||||||
&self,
|
|
||||||
cache: &mut __sdk::ClientCache<RemoteModule>,
|
|
||||||
) -> AppliedDiff<'_> {
|
|
||||||
let mut diff = AppliedDiff::default();
|
|
||||||
|
|
||||||
diff.players = cache.apply_diff_to_table::<Player>("players", &self.players);
|
|
||||||
|
|
||||||
diff
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct AppliedDiff<'r> {
|
|
||||||
players: __sdk::TableAppliedDiff<'r, Player>,
|
|
||||||
__unused: std::marker::PhantomData<&'r ()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for AppliedDiff<'_> {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
|
|
||||||
fn invoke_row_callbacks(
|
|
||||||
&self,
|
|
||||||
event: &EventContext,
|
|
||||||
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
|
|
||||||
) {
|
|
||||||
callbacks.invoke_table_row_callbacks::<Player>("players", &self.players, event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct RemoteModule;
|
|
||||||
|
|
||||||
impl __sdk::InModule for RemoteModule {
|
|
||||||
type Module = Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `reducers` field of [`EventContext`] and [`DbConnection`],
|
|
||||||
/// with methods provided by extension traits for each reducer defined by the module.
|
|
||||||
pub struct RemoteReducers {
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for RemoteReducers {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `procedures` field of [`DbConnection`] and other [`DbContext`] types,
|
|
||||||
/// with methods provided by extension traits for each procedure defined by the module.
|
|
||||||
pub struct RemoteProcedures {
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for RemoteProcedures {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
/// The `set_reducer_flags` field of [`DbConnection`],
|
|
||||||
/// with methods provided by extension traits for each reducer defined by the module.
|
|
||||||
/// Each method sets the flags for the reducer with the same name.
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub struct SetReducerFlags {
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for SetReducerFlags {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The `db` field of [`EventContext`] and [`DbConnection`],
|
|
||||||
/// with methods provided by extension traits for each table defined by the module.
|
|
||||||
pub struct RemoteTables {
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for RemoteTables {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A connection to a remote module, including a materialized view of a subset of the database.
|
|
||||||
///
|
|
||||||
/// Connect to a remote module by calling [`DbConnection::builder`]
|
|
||||||
/// and using the [`__sdk::DbConnectionBuilder`] builder-pattern constructor.
|
|
||||||
///
|
|
||||||
/// You must explicitly advance the connection by calling any one of:
|
|
||||||
///
|
|
||||||
/// - [`DbConnection::frame_tick`].
|
|
||||||
/// - [`DbConnection::run_threaded`].
|
|
||||||
/// - [`DbConnection::run_async`].
|
|
||||||
/// - [`DbConnection::advance_one_message`].
|
|
||||||
/// - [`DbConnection::advance_one_message_blocking`].
|
|
||||||
/// - [`DbConnection::advance_one_message_async`].
|
|
||||||
///
|
|
||||||
/// Which of these methods you should call depends on the specific needs of your application,
|
|
||||||
/// but you must call one of them, or else the connection will never progress.
|
|
||||||
pub struct DbConnection {
|
|
||||||
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
|
|
||||||
pub db: RemoteTables,
|
|
||||||
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
|
|
||||||
pub reducers: RemoteReducers,
|
|
||||||
#[doc(hidden)]
|
|
||||||
/// Access to setting the call-flags of each reducer defined for each reducer defined by the module
|
|
||||||
/// via extension traits implemented for [`SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub set_reducer_flags: SetReducerFlags,
|
|
||||||
|
|
||||||
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
|
|
||||||
pub procedures: RemoteProcedures,
|
|
||||||
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for DbConnection {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbContext for DbConnection {
|
|
||||||
type DbView = RemoteTables;
|
|
||||||
type Reducers = RemoteReducers;
|
|
||||||
type Procedures = RemoteProcedures;
|
|
||||||
type SetReducerFlags = SetReducerFlags;
|
|
||||||
|
|
||||||
fn db(&self) -> &Self::DbView {
|
|
||||||
&self.db
|
|
||||||
}
|
|
||||||
fn reducers(&self) -> &Self::Reducers {
|
|
||||||
&self.reducers
|
|
||||||
}
|
|
||||||
fn procedures(&self) -> &Self::Procedures {
|
|
||||||
&self.procedures
|
|
||||||
}
|
|
||||||
fn set_reducer_flags(&self) -> &Self::SetReducerFlags {
|
|
||||||
&self.set_reducer_flags
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.imp.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disconnect(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
|
|
||||||
|
|
||||||
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
|
|
||||||
__sdk::SubscriptionBuilder::new(&self.imp)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_identity(&self) -> Option<__sdk::Identity> {
|
|
||||||
self.imp.try_identity()
|
|
||||||
}
|
|
||||||
fn connection_id(&self) -> __sdk::ConnectionId {
|
|
||||||
self.imp.connection_id()
|
|
||||||
}
|
|
||||||
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
|
|
||||||
self.imp.try_connection_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DbConnection {
|
|
||||||
/// Builder-pattern constructor for a connection to a remote module.
|
|
||||||
///
|
|
||||||
/// See [`__sdk::DbConnectionBuilder`] for required and optional configuration for the new connection.
|
|
||||||
pub fn builder() -> __sdk::DbConnectionBuilder<RemoteModule> {
|
|
||||||
__sdk::DbConnectionBuilder::new()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// If any WebSocket messages are waiting, process one of them.
|
|
||||||
///
|
|
||||||
/// Returns `true` if a message was processed, or `false` if the queue is empty.
|
|
||||||
/// Callers should invoke this message in a loop until it returns `false`
|
|
||||||
/// or for as much time is available to process messages.
|
|
||||||
///
|
|
||||||
/// Returns an error if the connection is disconnected.
|
|
||||||
/// If the disconnection in question was normal,
|
|
||||||
/// i.e. the result of a call to [`__sdk::DbContext::disconnect`],
|
|
||||||
/// the returned error will be downcastable to [`__sdk::DisconnectedError`].
|
|
||||||
///
|
|
||||||
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
|
|
||||||
/// Most applications should call [`Self::frame_tick`] each frame
|
|
||||||
/// to fully exhaust the queue whenever time is available.
|
|
||||||
pub fn advance_one_message(&self) -> __sdk::Result<bool> {
|
|
||||||
self.imp.advance_one_message()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Process one WebSocket message, potentially blocking the current thread until one is received.
|
|
||||||
///
|
|
||||||
/// Returns an error if the connection is disconnected.
|
|
||||||
/// If the disconnection in question was normal,
|
|
||||||
/// i.e. the result of a call to [`__sdk::DbContext::disconnect`],
|
|
||||||
/// the returned error will be downcastable to [`__sdk::DisconnectedError`].
|
|
||||||
///
|
|
||||||
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
|
|
||||||
/// Most applications should call [`Self::run_threaded`] to spawn a thread
|
|
||||||
/// which advances the connection automatically.
|
|
||||||
pub fn advance_one_message_blocking(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.advance_one_message_blocking()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Process one WebSocket message, `await`ing until one is received.
|
|
||||||
///
|
|
||||||
/// Returns an error if the connection is disconnected.
|
|
||||||
/// If the disconnection in question was normal,
|
|
||||||
/// i.e. the result of a call to [`__sdk::DbContext::disconnect`],
|
|
||||||
/// the returned error will be downcastable to [`__sdk::DisconnectedError`].
|
|
||||||
///
|
|
||||||
/// This is a low-level primitive exposed for power users who need significant control over scheduling.
|
|
||||||
/// Most applications should call [`Self::run_async`] to run an `async` loop
|
|
||||||
/// which advances the connection when polled.
|
|
||||||
pub async fn advance_one_message_async(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.advance_one_message_async().await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Process all WebSocket messages waiting in the queue,
|
|
||||||
/// then return without `await`ing or blocking the current thread.
|
|
||||||
pub fn frame_tick(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.frame_tick()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Spawn a thread which processes WebSocket messages as they are received.
|
|
||||||
pub fn run_threaded(&self) -> std::thread::JoinHandle<()> {
|
|
||||||
self.imp.run_threaded()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Run an `async` loop which processes WebSocket messages when polled.
|
|
||||||
pub async fn run_async(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.run_async().await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbConnection for DbConnection {
|
|
||||||
fn new(imp: __sdk::DbContextImpl<RemoteModule>) -> Self {
|
|
||||||
Self {
|
|
||||||
db: RemoteTables { imp: imp.clone() },
|
|
||||||
reducers: RemoteReducers { imp: imp.clone() },
|
|
||||||
procedures: RemoteProcedures { imp: imp.clone() },
|
|
||||||
set_reducer_flags: SetReducerFlags { imp: imp.clone() },
|
|
||||||
imp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A handle on a subscribed query.
|
|
||||||
// TODO: Document this better after implementing the new subscription API.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct SubscriptionHandle {
|
|
||||||
imp: __sdk::SubscriptionHandleImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for SubscriptionHandle {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::SubscriptionHandle for SubscriptionHandle {
|
|
||||||
fn new(imp: __sdk::SubscriptionHandleImpl<RemoteModule>) -> Self {
|
|
||||||
Self { imp }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if this subscription has been terminated due to an unsubscribe call or an error.
|
|
||||||
fn is_ended(&self) -> bool {
|
|
||||||
self.imp.is_ended()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if this subscription has been applied and has not yet been unsubscribed.
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.imp.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unsubscribe from the query controlled by this `SubscriptionHandle`,
|
|
||||||
/// then run `on_end` when its rows are removed from the client cache.
|
|
||||||
fn unsubscribe_then(self, on_end: __sdk::OnEndedCallback<RemoteModule>) -> __sdk::Result<()> {
|
|
||||||
self.imp.unsubscribe_then(Some(on_end))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unsubscribe(self) -> __sdk::Result<()> {
|
|
||||||
self.imp.unsubscribe_then(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Alias trait for a [`__sdk::DbContext`] connected to this module,
|
|
||||||
/// with that trait's associated types bounded to this module's concrete types.
|
|
||||||
///
|
|
||||||
/// Users can use this trait as a boundary on definitions which should accept
|
|
||||||
/// either a [`DbConnection`] or an [`EventContext`] and operate on either.
|
|
||||||
pub trait RemoteDbContext:
|
|
||||||
__sdk::DbContext<
|
|
||||||
DbView = RemoteTables,
|
|
||||||
Reducers = RemoteReducers,
|
|
||||||
SetReducerFlags = SetReducerFlags,
|
|
||||||
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
|
|
||||||
>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
impl<
|
|
||||||
Ctx: __sdk::DbContext<
|
|
||||||
DbView = RemoteTables,
|
|
||||||
Reducers = RemoteReducers,
|
|
||||||
SetReducerFlags = SetReducerFlags,
|
|
||||||
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
|
|
||||||
>,
|
|
||||||
> RemoteDbContext for Ctx
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An [`__sdk::DbContext`] augmented with a [`__sdk::Event`],
|
|
||||||
/// passed to [`__sdk::Table::on_insert`], [`__sdk::Table::on_delete`] and [`__sdk::TableWithPrimaryKey::on_update`] callbacks.
|
|
||||||
pub struct EventContext {
|
|
||||||
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
|
|
||||||
pub db: RemoteTables,
|
|
||||||
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
|
|
||||||
pub reducers: RemoteReducers,
|
|
||||||
/// Access to setting the call-flags of each reducer defined for each reducer defined by the module
|
|
||||||
/// via extension traits implemented for [`SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub set_reducer_flags: SetReducerFlags,
|
|
||||||
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
|
|
||||||
pub procedures: RemoteProcedures,
|
|
||||||
/// The event which caused these callbacks to run.
|
|
||||||
pub event: __sdk::Event<Reducer>,
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::AbstractEventContext for EventContext {
|
|
||||||
type Event = __sdk::Event<Reducer>;
|
|
||||||
fn event(&self) -> &Self::Event {
|
|
||||||
&self.event
|
|
||||||
}
|
|
||||||
fn new(imp: __sdk::DbContextImpl<RemoteModule>, event: Self::Event) -> Self {
|
|
||||||
Self {
|
|
||||||
db: RemoteTables { imp: imp.clone() },
|
|
||||||
reducers: RemoteReducers { imp: imp.clone() },
|
|
||||||
set_reducer_flags: SetReducerFlags { imp: imp.clone() },
|
|
||||||
procedures: RemoteProcedures { imp: imp.clone() },
|
|
||||||
event,
|
|
||||||
imp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for EventContext {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbContext for EventContext {
|
|
||||||
type DbView = RemoteTables;
|
|
||||||
type Reducers = RemoteReducers;
|
|
||||||
type Procedures = RemoteProcedures;
|
|
||||||
type SetReducerFlags = SetReducerFlags;
|
|
||||||
|
|
||||||
fn db(&self) -> &Self::DbView {
|
|
||||||
&self.db
|
|
||||||
}
|
|
||||||
fn reducers(&self) -> &Self::Reducers {
|
|
||||||
&self.reducers
|
|
||||||
}
|
|
||||||
fn procedures(&self) -> &Self::Procedures {
|
|
||||||
&self.procedures
|
|
||||||
}
|
|
||||||
fn set_reducer_flags(&self) -> &Self::SetReducerFlags {
|
|
||||||
&self.set_reducer_flags
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.imp.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disconnect(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
|
|
||||||
|
|
||||||
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
|
|
||||||
__sdk::SubscriptionBuilder::new(&self.imp)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_identity(&self) -> Option<__sdk::Identity> {
|
|
||||||
self.imp.try_identity()
|
|
||||||
}
|
|
||||||
fn connection_id(&self) -> __sdk::ConnectionId {
|
|
||||||
self.imp.connection_id()
|
|
||||||
}
|
|
||||||
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
|
|
||||||
self.imp.try_connection_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::EventContext for EventContext {}
|
|
||||||
|
|
||||||
/// An [`__sdk::DbContext`] augmented with a [`__sdk::ReducerEvent`],
|
|
||||||
/// passed to on-reducer callbacks.
|
|
||||||
pub struct ReducerEventContext {
|
|
||||||
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
|
|
||||||
pub db: RemoteTables,
|
|
||||||
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
|
|
||||||
pub reducers: RemoteReducers,
|
|
||||||
/// Access to setting the call-flags of each reducer defined for each reducer defined by the module
|
|
||||||
/// via extension traits implemented for [`SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub set_reducer_flags: SetReducerFlags,
|
|
||||||
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
|
|
||||||
pub procedures: RemoteProcedures,
|
|
||||||
/// The event which caused these callbacks to run.
|
|
||||||
pub event: __sdk::ReducerEvent<Reducer>,
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::AbstractEventContext for ReducerEventContext {
|
|
||||||
type Event = __sdk::ReducerEvent<Reducer>;
|
|
||||||
fn event(&self) -> &Self::Event {
|
|
||||||
&self.event
|
|
||||||
}
|
|
||||||
fn new(imp: __sdk::DbContextImpl<RemoteModule>, event: Self::Event) -> Self {
|
|
||||||
Self {
|
|
||||||
db: RemoteTables { imp: imp.clone() },
|
|
||||||
reducers: RemoteReducers { imp: imp.clone() },
|
|
||||||
set_reducer_flags: SetReducerFlags { imp: imp.clone() },
|
|
||||||
procedures: RemoteProcedures { imp: imp.clone() },
|
|
||||||
event,
|
|
||||||
imp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for ReducerEventContext {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbContext for ReducerEventContext {
|
|
||||||
type DbView = RemoteTables;
|
|
||||||
type Reducers = RemoteReducers;
|
|
||||||
type Procedures = RemoteProcedures;
|
|
||||||
type SetReducerFlags = SetReducerFlags;
|
|
||||||
|
|
||||||
fn db(&self) -> &Self::DbView {
|
|
||||||
&self.db
|
|
||||||
}
|
|
||||||
fn reducers(&self) -> &Self::Reducers {
|
|
||||||
&self.reducers
|
|
||||||
}
|
|
||||||
fn procedures(&self) -> &Self::Procedures {
|
|
||||||
&self.procedures
|
|
||||||
}
|
|
||||||
fn set_reducer_flags(&self) -> &Self::SetReducerFlags {
|
|
||||||
&self.set_reducer_flags
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.imp.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disconnect(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
|
|
||||||
|
|
||||||
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
|
|
||||||
__sdk::SubscriptionBuilder::new(&self.imp)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_identity(&self) -> Option<__sdk::Identity> {
|
|
||||||
self.imp.try_identity()
|
|
||||||
}
|
|
||||||
fn connection_id(&self) -> __sdk::ConnectionId {
|
|
||||||
self.imp.connection_id()
|
|
||||||
}
|
|
||||||
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
|
|
||||||
self.imp.try_connection_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::ReducerEventContext for ReducerEventContext {}
|
|
||||||
|
|
||||||
/// An [`__sdk::DbContext`] passed to procedure callbacks.
|
|
||||||
pub struct ProcedureEventContext {
|
|
||||||
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
|
|
||||||
pub db: RemoteTables,
|
|
||||||
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
|
|
||||||
pub reducers: RemoteReducers,
|
|
||||||
/// Access to setting the call-flags of each reducer defined for each reducer defined by the module
|
|
||||||
/// via extension traits implemented for [`SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub set_reducer_flags: SetReducerFlags,
|
|
||||||
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
|
|
||||||
pub procedures: RemoteProcedures,
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::AbstractEventContext for ProcedureEventContext {
|
|
||||||
type Event = ();
|
|
||||||
fn event(&self) -> &Self::Event {
|
|
||||||
&()
|
|
||||||
}
|
|
||||||
fn new(imp: __sdk::DbContextImpl<RemoteModule>, _event: Self::Event) -> Self {
|
|
||||||
Self {
|
|
||||||
db: RemoteTables { imp: imp.clone() },
|
|
||||||
reducers: RemoteReducers { imp: imp.clone() },
|
|
||||||
procedures: RemoteProcedures { imp: imp.clone() },
|
|
||||||
set_reducer_flags: SetReducerFlags { imp: imp.clone() },
|
|
||||||
imp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for ProcedureEventContext {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbContext for ProcedureEventContext {
|
|
||||||
type DbView = RemoteTables;
|
|
||||||
type Reducers = RemoteReducers;
|
|
||||||
type Procedures = RemoteProcedures;
|
|
||||||
type SetReducerFlags = SetReducerFlags;
|
|
||||||
|
|
||||||
fn db(&self) -> &Self::DbView {
|
|
||||||
&self.db
|
|
||||||
}
|
|
||||||
fn reducers(&self) -> &Self::Reducers {
|
|
||||||
&self.reducers
|
|
||||||
}
|
|
||||||
fn procedures(&self) -> &Self::Procedures {
|
|
||||||
&self.procedures
|
|
||||||
}
|
|
||||||
fn set_reducer_flags(&self) -> &Self::SetReducerFlags {
|
|
||||||
&self.set_reducer_flags
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.imp.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disconnect(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
|
|
||||||
|
|
||||||
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
|
|
||||||
__sdk::SubscriptionBuilder::new(&self.imp)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_identity(&self) -> Option<__sdk::Identity> {
|
|
||||||
self.imp.try_identity()
|
|
||||||
}
|
|
||||||
fn connection_id(&self) -> __sdk::ConnectionId {
|
|
||||||
self.imp.connection_id()
|
|
||||||
}
|
|
||||||
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
|
|
||||||
self.imp.try_connection_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::ProcedureEventContext for ProcedureEventContext {}
|
|
||||||
|
|
||||||
/// An [`__sdk::DbContext`] passed to [`__sdk::SubscriptionBuilder::on_applied`] and [`SubscriptionHandle::unsubscribe_then`] callbacks.
|
|
||||||
pub struct SubscriptionEventContext {
|
|
||||||
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
|
|
||||||
pub db: RemoteTables,
|
|
||||||
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
|
|
||||||
pub reducers: RemoteReducers,
|
|
||||||
/// Access to setting the call-flags of each reducer defined for each reducer defined by the module
|
|
||||||
/// via extension traits implemented for [`SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub set_reducer_flags: SetReducerFlags,
|
|
||||||
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
|
|
||||||
pub procedures: RemoteProcedures,
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::AbstractEventContext for SubscriptionEventContext {
|
|
||||||
type Event = ();
|
|
||||||
fn event(&self) -> &Self::Event {
|
|
||||||
&()
|
|
||||||
}
|
|
||||||
fn new(imp: __sdk::DbContextImpl<RemoteModule>, _event: Self::Event) -> Self {
|
|
||||||
Self {
|
|
||||||
db: RemoteTables { imp: imp.clone() },
|
|
||||||
reducers: RemoteReducers { imp: imp.clone() },
|
|
||||||
procedures: RemoteProcedures { imp: imp.clone() },
|
|
||||||
set_reducer_flags: SetReducerFlags { imp: imp.clone() },
|
|
||||||
imp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for SubscriptionEventContext {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbContext for SubscriptionEventContext {
|
|
||||||
type DbView = RemoteTables;
|
|
||||||
type Reducers = RemoteReducers;
|
|
||||||
type Procedures = RemoteProcedures;
|
|
||||||
type SetReducerFlags = SetReducerFlags;
|
|
||||||
|
|
||||||
fn db(&self) -> &Self::DbView {
|
|
||||||
&self.db
|
|
||||||
}
|
|
||||||
fn reducers(&self) -> &Self::Reducers {
|
|
||||||
&self.reducers
|
|
||||||
}
|
|
||||||
fn procedures(&self) -> &Self::Procedures {
|
|
||||||
&self.procedures
|
|
||||||
}
|
|
||||||
fn set_reducer_flags(&self) -> &Self::SetReducerFlags {
|
|
||||||
&self.set_reducer_flags
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.imp.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disconnect(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
|
|
||||||
|
|
||||||
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
|
|
||||||
__sdk::SubscriptionBuilder::new(&self.imp)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_identity(&self) -> Option<__sdk::Identity> {
|
|
||||||
self.imp.try_identity()
|
|
||||||
}
|
|
||||||
fn connection_id(&self) -> __sdk::ConnectionId {
|
|
||||||
self.imp.connection_id()
|
|
||||||
}
|
|
||||||
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
|
|
||||||
self.imp.try_connection_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::SubscriptionEventContext for SubscriptionEventContext {}
|
|
||||||
|
|
||||||
/// An [`__sdk::DbContext`] augmented with a [`__sdk::Error`],
|
|
||||||
/// passed to [`__sdk::DbConnectionBuilder::on_disconnect`], [`__sdk::DbConnectionBuilder::on_connect_error`] and [`__sdk::SubscriptionBuilder::on_error`] callbacks.
|
|
||||||
pub struct ErrorContext {
|
|
||||||
/// Access to tables defined by the module via extension traits implemented for [`RemoteTables`].
|
|
||||||
pub db: RemoteTables,
|
|
||||||
/// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`].
|
|
||||||
pub reducers: RemoteReducers,
|
|
||||||
/// Access to setting the call-flags of each reducer defined for each reducer defined by the module
|
|
||||||
/// via extension traits implemented for [`SetReducerFlags`].
|
|
||||||
///
|
|
||||||
/// This type is currently unstable and may be removed without a major version bump.
|
|
||||||
pub set_reducer_flags: SetReducerFlags,
|
|
||||||
/// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`].
|
|
||||||
pub procedures: RemoteProcedures,
|
|
||||||
/// The event which caused these callbacks to run.
|
|
||||||
pub event: Option<__sdk::Error>,
|
|
||||||
imp: __sdk::DbContextImpl<RemoteModule>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::AbstractEventContext for ErrorContext {
|
|
||||||
type Event = Option<__sdk::Error>;
|
|
||||||
fn event(&self) -> &Self::Event {
|
|
||||||
&self.event
|
|
||||||
}
|
|
||||||
fn new(imp: __sdk::DbContextImpl<RemoteModule>, event: Self::Event) -> Self {
|
|
||||||
Self {
|
|
||||||
db: RemoteTables { imp: imp.clone() },
|
|
||||||
reducers: RemoteReducers { imp: imp.clone() },
|
|
||||||
set_reducer_flags: SetReducerFlags { imp: imp.clone() },
|
|
||||||
procedures: RemoteProcedures { imp: imp.clone() },
|
|
||||||
event,
|
|
||||||
imp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for ErrorContext {
|
|
||||||
type Module = RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::DbContext for ErrorContext {
|
|
||||||
type DbView = RemoteTables;
|
|
||||||
type Reducers = RemoteReducers;
|
|
||||||
type Procedures = RemoteProcedures;
|
|
||||||
type SetReducerFlags = SetReducerFlags;
|
|
||||||
|
|
||||||
fn db(&self) -> &Self::DbView {
|
|
||||||
&self.db
|
|
||||||
}
|
|
||||||
fn reducers(&self) -> &Self::Reducers {
|
|
||||||
&self.reducers
|
|
||||||
}
|
|
||||||
fn procedures(&self) -> &Self::Procedures {
|
|
||||||
&self.procedures
|
|
||||||
}
|
|
||||||
fn set_reducer_flags(&self) -> &Self::SetReducerFlags {
|
|
||||||
&self.set_reducer_flags
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_active(&self) -> bool {
|
|
||||||
self.imp.is_active()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn disconnect(&self) -> __sdk::Result<()> {
|
|
||||||
self.imp.disconnect()
|
|
||||||
}
|
|
||||||
|
|
||||||
type SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>;
|
|
||||||
|
|
||||||
fn subscription_builder(&self) -> Self::SubscriptionBuilder {
|
|
||||||
__sdk::SubscriptionBuilder::new(&self.imp)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_identity(&self) -> Option<__sdk::Identity> {
|
|
||||||
self.imp.try_identity()
|
|
||||||
}
|
|
||||||
fn connection_id(&self) -> __sdk::ConnectionId {
|
|
||||||
self.imp.connection_id()
|
|
||||||
}
|
|
||||||
fn try_connection_id(&self) -> Option<__sdk::ConnectionId> {
|
|
||||||
self.imp.try_connection_id()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::ErrorContext for ErrorContext {}
|
|
||||||
|
|
||||||
impl __sdk::SpacetimeModule for RemoteModule {
|
|
||||||
type DbConnection = DbConnection;
|
|
||||||
type EventContext = EventContext;
|
|
||||||
type ReducerEventContext = ReducerEventContext;
|
|
||||||
type ProcedureEventContext = ProcedureEventContext;
|
|
||||||
type SubscriptionEventContext = SubscriptionEventContext;
|
|
||||||
type ErrorContext = ErrorContext;
|
|
||||||
type Reducer = Reducer;
|
|
||||||
type DbView = RemoteTables;
|
|
||||||
type Reducers = RemoteReducers;
|
|
||||||
type SetReducerFlags = SetReducerFlags;
|
|
||||||
type DbUpdate = DbUpdate;
|
|
||||||
type AppliedDiff<'r> = AppliedDiff<'r>;
|
|
||||||
type SubscriptionHandle = SubscriptionHandle;
|
|
||||||
|
|
||||||
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
|
|
||||||
players_table::register_table(client_cache);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +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 struct Player {
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for Player {
|
|
||||||
type Module = super::RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
@ -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::player_type::Player;
|
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
/// Table handle for the table `players`.
|
|
||||||
///
|
|
||||||
/// Obtain a handle from the [`PlayersTableAccess::players`] method on [`super::RemoteTables`],
|
|
||||||
/// like `ctx.db.players()`.
|
|
||||||
///
|
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
|
||||||
/// but to directly chain method calls,
|
|
||||||
/// like `ctx.db.players().on_insert(...)`.
|
|
||||||
pub struct PlayersTableHandle<'ctx> {
|
|
||||||
imp: __sdk::TableHandle<Player>,
|
|
||||||
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
/// Extension trait for access to the table `players`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::RemoteTables`].
|
|
||||||
pub trait PlayersTableAccess {
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
/// Obtain a [`PlayersTableHandle`], which mediates access to the table `players`.
|
|
||||||
fn players(&self) -> PlayersTableHandle<'_>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PlayersTableAccess for super::RemoteTables {
|
|
||||||
fn players(&self) -> PlayersTableHandle<'_> {
|
|
||||||
PlayersTableHandle {
|
|
||||||
imp: self.imp.get_table::<Player>("players"),
|
|
||||||
ctx: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PlayersInsertCallbackId(__sdk::CallbackId);
|
|
||||||
pub struct PlayersDeleteCallbackId(__sdk::CallbackId);
|
|
||||||
|
|
||||||
impl<'ctx> __sdk::Table for PlayersTableHandle<'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 = PlayersInsertCallbackId;
|
|
||||||
|
|
||||||
fn on_insert(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
|
||||||
) -> PlayersInsertCallbackId {
|
|
||||||
PlayersInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_on_insert(&self, callback: PlayersInsertCallbackId) {
|
|
||||||
self.imp.remove_on_insert(callback.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteCallbackId = PlayersDeleteCallbackId;
|
|
||||||
|
|
||||||
fn on_delete(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
|
||||||
) -> PlayersDeleteCallbackId {
|
|
||||||
PlayersDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_on_delete(&self, callback: PlayersDeleteCallbackId) {
|
|
||||||
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>("players");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#![feature(stmt_expr_attributes, iter_array_chunks)]
|
|
||||||
|
|
||||||
use bevy::prelude::*;
|
|
||||||
use bevy_spacetimedb::StdbConnection;
|
|
||||||
|
|
||||||
mod jongline_bindings;
|
|
||||||
use jongline_bindings::*;
|
|
||||||
|
|
||||||
pub mod game;
|
|
||||||
pub mod tile;
|
|
||||||
pub mod yakus;
|
|
||||||
|
|
||||||
trait EnumNextCycle {
|
|
||||||
fn next(&self) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type SpacetimeDb<'a> = Res<'a, StdbConnection<DbConnection>>;
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
[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"
|
|
||||||
# jong = { version = "0.1.0", path = "../jong" }
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
use spacetimedb::{reducer, ConnectionId, Identity, ReducerContext, Table};
|
|
||||||
|
|
||||||
// use jong::tile::Tile;
|
|
||||||
|
|
||||||
#[spacetimedb::table(name = player)]
|
|
||||||
pub struct Player {
|
|
||||||
username: String,
|
|
||||||
|
|
||||||
identity: Identity,
|
|
||||||
connection_id: ConnectionId,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[spacetimedb::table(name = table, public)]
|
|
||||||
pub struct Table {
|
|
||||||
players: Player,
|
|
||||||
hands: [Hand; 4],
|
|
||||||
}
|
|
||||||
|
|
||||||
#[spacetimedb::table(name = wall)]
|
|
||||||
pub struct Wall {
|
|
||||||
// tiles: Vec<Tile>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[spacetimedb::table(name = hand)]
|
|
||||||
pub struct Hand {
|
|
||||||
// hand: Vec<Tile>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[spacetimedb::table(name = drawn)]
|
|
||||||
pub struct Drawn {
|
|
||||||
// tile: Tile,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called everytime a client disconnects
|
|
||||||
#[reducer(client_disconnected)]
|
|
||||||
pub fn identity_disconnected(ctx: &ReducerContext) {
|
|
||||||
ctx.db.player().identity().delete(ctx.sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[reducer]
|
|
||||||
pub fn create_player(ctx: &ReducerContext, username: String) {
|
|
||||||
let connection_id = ctx.connection_id.unwrap();
|
|
||||||
let identity = ctx.identity();
|
|
||||||
ctx.db.players().insert(Player {
|
|
||||||
username,
|
|
||||||
connection_id,
|
|
||||||
identity,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[spacetimedb::reducer]
|
|
||||||
// pub fn say_hello(ctx: &ReducerContext) {
|
|
||||||
// for person in ctx.db.person().iter() {
|
|
||||||
// log::info!("Hello, {}!", person.name);
|
|
||||||
// }
|
|
||||||
// log::info!("Hello, World!");
|
|
||||||
// }
|
|
||||||
3
justfile
3
justfile
|
|
@ -11,6 +11,3 @@ run-tui:
|
||||||
update:
|
update:
|
||||||
cargo update
|
cargo update
|
||||||
nix flake update
|
nix flake update
|
||||||
|
|
||||||
generate-db-bindings:
|
|
||||||
spacetime generate --lang rust --out-dir jong/src/jongline_bindings --project-path jongline
|
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ pub(crate) fn ron_chi_pon_kan(
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
// received.sort_unstable_by_key(|(c, t)| c);
|
received.sort_unstable_by_key(|(c, t)| c);
|
||||||
// received.sort_unstable_by_key(|m| m.);
|
// received.sort_unstable_by_key(|m| m.);
|
||||||
|
|
||||||
next_turnstate.set(curr_turnstate.next());
|
next_turnstate.set(curr_turnstate.next());
|
||||||
9
src/lib.rs
Normal file
9
src/lib.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#![feature(stmt_expr_attributes, iter_array_chunks)]
|
||||||
|
|
||||||
|
pub mod game;
|
||||||
|
pub mod tile;
|
||||||
|
pub mod yakus;
|
||||||
|
|
||||||
|
trait EnumNextCycle {
|
||||||
|
fn next(&self) -> Self;
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use bevy::{log::LogPlugin, prelude::*};
|
use bevy::{log::LogPlugin, prelude::*};
|
||||||
use bevy_spacetimedb::{StdbConnection, StdbPlugin, TableMessages};
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use tracing::Level;
|
use tracing::Level;
|
||||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
@ -47,14 +46,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
app.add_plugins(
|
|
||||||
StdbPlugin::default()
|
|
||||||
.with_uri("http://localhost:3000")
|
|
||||||
.with_module_name("jongline")
|
|
||||||
.with_run_fn(DbConnection::run_threaded)
|
|
||||||
.add_partial_table(RemoteTables::players, TableMessages::no_update()),
|
|
||||||
);
|
|
||||||
|
|
||||||
app.add_plugins(jong::game::Riichi);
|
app.add_plugins(jong::game::Riichi);
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue