state advancer reducer
This commit is contained in:
parent
c12667938e
commit
e2c9c815ec
44 changed files with 2063 additions and 773 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1229,6 +1229,7 @@ dependencies = [
|
||||||
"bitflags 2.11.0",
|
"bitflags 2.11.0",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
"smol_str",
|
||||||
"tracing",
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
# https://devenv.sh/packages/
|
# https://devenv.sh/packages/
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
# lspmux
|
lspmux
|
||||||
pkg-config
|
pkg-config
|
||||||
|
|
||||||
# spacetimedb
|
# spacetimedb
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,13 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -14,8 +20,8 @@ impl From<AddBotArgs> for super::Reducer {
|
||||||
fn from(args: AddBotArgs) -> Self {
|
fn from(args: AddBotArgs) -> Self {
|
||||||
Self::AddBot {
|
Self::AddBot {
|
||||||
lobby_id: args.lobby_id,
|
lobby_id: args.lobby_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for AddBotArgs {
|
impl __sdk::InModule for AddBotArgs {
|
||||||
|
|
@ -34,7 +40,8 @@ pub trait add_bot {
|
||||||
/// 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_bot`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_add_bot`] callbacks.
|
||||||
fn add_bot(&self, lobby_id: u32) -> __sdk::Result<()>;
|
fn add_bot(&self, lobby_id: u32,
|
||||||
|
) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `add_bot`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `add_bot`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
|
@ -42,39 +49,35 @@ pub trait add_bot {
|
||||||
///
|
///
|
||||||
/// The returned [`AddBotCallbackId`] can be passed to [`Self::remove_on_add_bot`]
|
/// The returned [`AddBotCallbackId`] can be passed to [`Self::remove_on_add_bot`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_add_bot(
|
fn on_add_bot(&self, callback: impl FnMut(&super::ReducerEventContext, &u32, ) + Send + 'static) -> AddBotCallbackId;
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static,
|
|
||||||
) -> AddBotCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_add_bot`],
|
/// Cancel a callback previously registered by [`Self::on_add_bot`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_add_bot(&self, callback: AddBotCallbackId);
|
fn remove_on_add_bot(&self, callback: AddBotCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl add_bot for super::RemoteReducers {
|
impl add_bot for super::RemoteReducers {
|
||||||
fn add_bot(&self, lobby_id: u32) -> __sdk::Result<()> {
|
fn add_bot(&self, lobby_id: u32,
|
||||||
self.imp.call_reducer("add_bot", AddBotArgs { lobby_id })
|
) -> __sdk::Result<()> {
|
||||||
|
self.imp.call_reducer("add_bot", AddBotArgs { lobby_id, })
|
||||||
}
|
}
|
||||||
fn on_add_bot(
|
fn on_add_bot(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext, &u32, ) + Send + 'static,
|
||||||
) -> AddBotCallbackId {
|
) -> AddBotCallbackId {
|
||||||
AddBotCallbackId(self.imp.on_reducer(
|
AddBotCallbackId(self.imp.on_reducer(
|
||||||
"add_bot",
|
"add_bot",
|
||||||
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::AddBot {
|
||||||
reducer: super::Reducer::AddBot { lobby_id },
|
lobby_id,
|
||||||
..
|
|
||||||
},
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
..
|
..
|
||||||
} = ctx
|
} = ctx else { unreachable!() };
|
||||||
else {
|
callback(ctx, lobby_id, )
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx, lobby_id)
|
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -102,3 +105,4 @@ impl set_flags_for_add_bot for super::SetReducerFlags {
|
||||||
self.imp.set_call_reducer_flags("add_bot", flags);
|
self.imp.set_call_reducer_flags("add_bot", flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
109
jong-db/src/db/advance_game_reducer.rs
Normal file
109
jong-db/src/db/advance_game_reducer.rs
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
// 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::game_timer_type::GameTimer;
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub(super) struct AdvanceGameArgs {
|
||||||
|
pub game_timer: GameTimer,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AdvanceGameArgs> for super::Reducer {
|
||||||
|
fn from(args: AdvanceGameArgs) -> Self {
|
||||||
|
Self::AdvanceGame {
|
||||||
|
game_timer: args.game_timer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for AdvanceGameArgs {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AdvanceGameCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the reducer `advance_game`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
|
pub trait advance_game {
|
||||||
|
/// Request that the remote module invoke the reducer `advance_game` 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_advance_game`] callbacks.
|
||||||
|
fn advance_game(&self, game_timer: GameTimer,
|
||||||
|
) -> __sdk::Result<()>;
|
||||||
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `advance_game`.
|
||||||
|
///
|
||||||
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
/// to determine the reducer's status.
|
||||||
|
///
|
||||||
|
/// The returned [`AdvanceGameCallbackId`] can be passed to [`Self::remove_on_advance_game`]
|
||||||
|
/// to cancel the callback.
|
||||||
|
fn on_advance_game(&self, callback: impl FnMut(&super::ReducerEventContext, &GameTimer, ) + Send + 'static) -> AdvanceGameCallbackId;
|
||||||
|
/// Cancel a callback previously registered by [`Self::on_advance_game`],
|
||||||
|
/// causing it not to run in the future.
|
||||||
|
fn remove_on_advance_game(&self, callback: AdvanceGameCallbackId);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl advance_game for super::RemoteReducers {
|
||||||
|
fn advance_game(&self, game_timer: GameTimer,
|
||||||
|
) -> __sdk::Result<()> {
|
||||||
|
self.imp.call_reducer("advance_game", AdvanceGameArgs { game_timer, })
|
||||||
|
}
|
||||||
|
fn on_advance_game(
|
||||||
|
&self,
|
||||||
|
mut callback: impl FnMut(&super::ReducerEventContext, &GameTimer, ) + Send + 'static,
|
||||||
|
) -> AdvanceGameCallbackId {
|
||||||
|
AdvanceGameCallbackId(self.imp.on_reducer(
|
||||||
|
"advance_game",
|
||||||
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
|
#[allow(irrefutable_let_patterns)]
|
||||||
|
let super::ReducerEventContext {
|
||||||
|
event: __sdk::ReducerEvent {
|
||||||
|
reducer: super::Reducer::AdvanceGame {
|
||||||
|
game_timer,
|
||||||
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
|
..
|
||||||
|
} = ctx else { unreachable!() };
|
||||||
|
callback(ctx, game_timer, )
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
fn remove_on_advance_game(&self, callback: AdvanceGameCallbackId) {
|
||||||
|
self.imp.remove_on_reducer("advance_game", callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// Extension trait for setting the call-flags for the reducer `advance_game`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
pub trait set_flags_for_advance_game {
|
||||||
|
/// Set the call-reducer flags for the reducer `advance_game` to `flags`.
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
fn advance_game(&self, flags: __ws::CallReducerFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl set_flags_for_advance_game for super::SetReducerFlags {
|
||||||
|
fn advance_game(&self, flags: __ws::CallReducerFlags) {
|
||||||
|
self.imp.set_call_reducer_flags("advance_game", flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,9 +2,15 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{
|
||||||
|
self as __sdk,
|
||||||
|
__lib,
|
||||||
|
__sats,
|
||||||
|
__ws,
|
||||||
|
};
|
||||||
use super::bot_type::Bot;
|
use super::bot_type::Bot;
|
||||||
|
use super::turn_state_type::TurnState;
|
||||||
use super::db_tile_type::DbTile;
|
use super::db_tile_type::DbTile;
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
/// Table handle for the table `bot`.
|
/// Table handle for the table `bot`.
|
||||||
///
|
///
|
||||||
|
|
@ -45,12 +51,8 @@ impl<'ctx> __sdk::Table for BotTableHandle<'ctx> {
|
||||||
type Row = Bot;
|
type Row = Bot;
|
||||||
type EventContext = super::EventContext;
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
fn count(&self) -> u64 {
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
self.imp.count()
|
fn iter(&self) -> impl Iterator<Item = Bot> + '_ { self.imp.iter() }
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = Bot> + '_ {
|
|
||||||
self.imp.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
type InsertCallbackId = BotInsertCallbackId;
|
type InsertCallbackId = BotInsertCallbackId;
|
||||||
|
|
||||||
|
|
@ -81,7 +83,8 @@ impl<'ctx> __sdk::Table for BotTableHandle<'ctx> {
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||||
let _table = client_cache.get_or_make_table::<Bot>("bot");
|
|
||||||
|
let _table = client_cache.get_or_make_table::<Bot>("bot");
|
||||||
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||||
}
|
}
|
||||||
pub struct BotUpdateCallbackId(__sdk::CallbackId);
|
pub struct BotUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
@ -101,43 +104,46 @@ impl<'ctx> __sdk::TableWithPrimaryKey for BotTableHandle<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn parse_table_update(
|
pub(super) fn parse_table_update(
|
||||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
) -> __sdk::Result<__sdk::TableUpdate<Bot>> {
|
) -> __sdk::Result<__sdk::TableUpdate<Bot>> {
|
||||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
__sdk::InternalError::failed_parse("TableUpdate<Bot>", "TableUpdate")
|
__sdk::InternalError::failed_parse(
|
||||||
.with_cause(e)
|
"TableUpdate<Bot>",
|
||||||
.into()
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access to the `id` unique index on the table `bot`,
|
/// Access to the `id` unique index on the table `bot`,
|
||||||
/// which allows point queries on the field of the same name
|
/// which allows point queries on the field of the same name
|
||||||
/// via the [`BotIdUnique::find`] method.
|
/// via the [`BotIdUnique::find`] method.
|
||||||
///
|
///
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
/// but to directly chain method calls,
|
/// but to directly chain method calls,
|
||||||
/// like `ctx.db.bot().id().find(...)`.
|
/// like `ctx.db.bot().id().find(...)`.
|
||||||
pub struct BotIdUnique<'ctx> {
|
pub struct BotIdUnique<'ctx> {
|
||||||
imp: __sdk::UniqueConstraintHandle<Bot, u32>,
|
imp: __sdk::UniqueConstraintHandle<Bot, u32>,
|
||||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> BotTableHandle<'ctx> {
|
|
||||||
/// Get a handle on the `id` unique index on the table `bot`.
|
|
||||||
pub fn id(&self) -> BotIdUnique<'ctx> {
|
|
||||||
BotIdUnique {
|
|
||||||
imp: self.imp.get_unique_constraint::<u32>("id"),
|
|
||||||
phantom: std::marker::PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> BotIdUnique<'ctx> {
|
impl<'ctx> BotTableHandle<'ctx> {
|
||||||
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
/// Get a handle on the `id` unique index on the table `bot`.
|
||||||
/// if such a row is present in the client cache.
|
pub fn id(&self) -> BotIdUnique<'ctx> {
|
||||||
pub fn find(&self, col_val: &u32) -> Option<Bot> {
|
BotIdUnique {
|
||||||
self.imp.find(col_val)
|
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||||
}
|
phantom: std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> BotIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<Bot> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,8 +2,14 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::turn_state_type::TurnState;
|
||||||
use super::db_tile_type::DbTile;
|
use super::db_tile_type::DbTile;
|
||||||
|
|
||||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
|
@ -11,11 +17,14 @@ use super::db_tile_type::DbTile;
|
||||||
pub struct Bot {
|
pub struct Bot {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub lobby_id: u32,
|
pub lobby_id: u32,
|
||||||
pub hand: Vec<DbTile>,
|
pub turn_state: TurnState,
|
||||||
pub pond: Vec<DbTile>,
|
pub hand: Vec::<DbTile>,
|
||||||
pub drawn_tile: Option<DbTile>,
|
pub pond: Vec::<DbTile>,
|
||||||
|
pub working_tile: Option::<DbTile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Bot {
|
impl __sdk::InModule for Bot {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,23 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#[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 ClearAllArgs {}
|
pub(super) struct ClearAllArgs {
|
||||||
|
}
|
||||||
|
|
||||||
impl From<ClearAllArgs> for super::Reducer {
|
impl From<ClearAllArgs> for super::Reducer {
|
||||||
fn from(args: ClearAllArgs) -> Self {
|
fn from(args: ClearAllArgs) -> Self {
|
||||||
Self::ClearAll
|
Self::ClearAll
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for ClearAllArgs {
|
impl __sdk::InModule for ClearAllArgs {
|
||||||
|
|
@ -30,7 +37,7 @@ pub trait clear_all {
|
||||||
/// 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_clear_all`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_clear_all`] callbacks.
|
||||||
fn clear_all(&self) -> __sdk::Result<()>;
|
fn clear_all(&self, ) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `clear_all`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `clear_all`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
|
@ -38,39 +45,34 @@ pub trait clear_all {
|
||||||
///
|
///
|
||||||
/// The returned [`ClearAllCallbackId`] can be passed to [`Self::remove_on_clear_all`]
|
/// The returned [`ClearAllCallbackId`] can be passed to [`Self::remove_on_clear_all`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_clear_all(
|
fn on_clear_all(&self, callback: impl FnMut(&super::ReducerEventContext, ) + Send + 'static) -> ClearAllCallbackId;
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
|
||||||
) -> ClearAllCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_clear_all`],
|
/// Cancel a callback previously registered by [`Self::on_clear_all`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_clear_all(&self, callback: ClearAllCallbackId);
|
fn remove_on_clear_all(&self, callback: ClearAllCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl clear_all for super::RemoteReducers {
|
impl clear_all for super::RemoteReducers {
|
||||||
fn clear_all(&self) -> __sdk::Result<()> {
|
fn clear_all(&self, ) -> __sdk::Result<()> {
|
||||||
self.imp.call_reducer("clear_all", ClearAllArgs {})
|
self.imp.call_reducer("clear_all", ClearAllArgs { })
|
||||||
}
|
}
|
||||||
fn on_clear_all(
|
fn on_clear_all(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext, ) + Send + 'static,
|
||||||
) -> ClearAllCallbackId {
|
) -> ClearAllCallbackId {
|
||||||
ClearAllCallbackId(self.imp.on_reducer(
|
ClearAllCallbackId(self.imp.on_reducer(
|
||||||
"clear_all",
|
"clear_all",
|
||||||
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::ClearAll {
|
||||||
reducer: super::Reducer::ClearAll {},
|
|
||||||
..
|
|
||||||
},
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
..
|
..
|
||||||
} = ctx
|
} = ctx else { unreachable!() };
|
||||||
else {
|
callback(ctx, )
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx)
|
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -98,3 +100,4 @@ impl set_flags_for_clear_all for super::SetReducerFlags {
|
||||||
self.imp.set_call_reducer_flags("clear_all", flags);
|
self.imp.set_call_reducer_flags("clear_all", flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
103
jong-db/src/db/connect_reducer.rs
Normal file
103
jong-db/src/db/connect_reducer.rs
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
// 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 ConnectArgs {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ConnectArgs> for super::Reducer {
|
||||||
|
fn from(args: ConnectArgs) -> Self {
|
||||||
|
Self::Connect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for ConnectArgs {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ConnectCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the reducer `connect`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
|
pub trait connect {
|
||||||
|
/// Request that the remote module invoke the reducer `connect` 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_connect`] callbacks.
|
||||||
|
fn connect(&self, ) -> __sdk::Result<()>;
|
||||||
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `connect`.
|
||||||
|
///
|
||||||
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
/// to determine the reducer's status.
|
||||||
|
///
|
||||||
|
/// The returned [`ConnectCallbackId`] can be passed to [`Self::remove_on_connect`]
|
||||||
|
/// to cancel the callback.
|
||||||
|
fn on_connect(&self, callback: impl FnMut(&super::ReducerEventContext, ) + Send + 'static) -> ConnectCallbackId;
|
||||||
|
/// Cancel a callback previously registered by [`Self::on_connect`],
|
||||||
|
/// causing it not to run in the future.
|
||||||
|
fn remove_on_connect(&self, callback: ConnectCallbackId);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl connect for super::RemoteReducers {
|
||||||
|
fn connect(&self, ) -> __sdk::Result<()> {
|
||||||
|
self.imp.call_reducer("connect", ConnectArgs { })
|
||||||
|
}
|
||||||
|
fn on_connect(
|
||||||
|
&self,
|
||||||
|
mut callback: impl FnMut(&super::ReducerEventContext, ) + Send + 'static,
|
||||||
|
) -> ConnectCallbackId {
|
||||||
|
ConnectCallbackId(self.imp.on_reducer(
|
||||||
|
"connect",
|
||||||
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
|
#[allow(irrefutable_let_patterns)]
|
||||||
|
let super::ReducerEventContext {
|
||||||
|
event: __sdk::ReducerEvent {
|
||||||
|
reducer: super::Reducer::Connect {
|
||||||
|
|
||||||
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
|
..
|
||||||
|
} = ctx else { unreachable!() };
|
||||||
|
callback(ctx, )
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
fn remove_on_connect(&self, callback: ConnectCallbackId) {
|
||||||
|
self.imp.remove_on_reducer("connect", callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// Extension trait for setting the call-flags for the reducer `connect`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
pub trait set_flags_for_connect {
|
||||||
|
/// Set the call-reducer flags for the reducer `connect` to `flags`.
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
fn connect(&self, flags: __ws::CallReducerFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl set_flags_for_connect for super::SetReducerFlags {
|
||||||
|
fn connect(&self, flags: __ws::CallReducerFlags) {
|
||||||
|
self.imp.set_call_reducer_flags("connect", flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
use super::tile_type::Tile;
|
use super::tile_type::Tile;
|
||||||
|
|
||||||
|
|
@ -13,6 +18,8 @@ pub struct DbTile {
|
||||||
pub tile: Tile,
|
pub tile: Tile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for DbTile {
|
impl __sdk::InModule for DbTile {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
use super::db_tile_type::DbTile;
|
use super::db_tile_type::DbTile;
|
||||||
|
|
||||||
|
|
@ -10,9 +15,11 @@ use super::db_tile_type::DbTile;
|
||||||
#[sats(crate = __lib)]
|
#[sats(crate = __lib)]
|
||||||
pub struct DbWall {
|
pub struct DbWall {
|
||||||
pub lobby_id: u32,
|
pub lobby_id: u32,
|
||||||
pub tiles: Vec<DbTile>,
|
pub tiles: Vec::<DbTile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for DbWall {
|
impl __sdk::InModule for DbWall {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,13 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -14,8 +20,8 @@ impl From<DiscardTileArgs> for super::Reducer {
|
||||||
fn from(args: DiscardTileArgs) -> Self {
|
fn from(args: DiscardTileArgs) -> Self {
|
||||||
Self::DiscardTile {
|
Self::DiscardTile {
|
||||||
tile_id: args.tile_id,
|
tile_id: args.tile_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for DiscardTileArgs {
|
impl __sdk::InModule for DiscardTileArgs {
|
||||||
|
|
@ -34,7 +40,8 @@ pub trait discard_tile {
|
||||||
/// 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_discard_tile`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_discard_tile`] callbacks.
|
||||||
fn discard_tile(&self, tile_id: u32) -> __sdk::Result<()>;
|
fn discard_tile(&self, tile_id: u32,
|
||||||
|
) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `discard_tile`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `discard_tile`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
|
@ -42,40 +49,35 @@ pub trait discard_tile {
|
||||||
///
|
///
|
||||||
/// The returned [`DiscardTileCallbackId`] can be passed to [`Self::remove_on_discard_tile`]
|
/// The returned [`DiscardTileCallbackId`] can be passed to [`Self::remove_on_discard_tile`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_discard_tile(
|
fn on_discard_tile(&self, callback: impl FnMut(&super::ReducerEventContext, &u32, ) + Send + 'static) -> DiscardTileCallbackId;
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static,
|
|
||||||
) -> DiscardTileCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_discard_tile`],
|
/// Cancel a callback previously registered by [`Self::on_discard_tile`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_discard_tile(&self, callback: DiscardTileCallbackId);
|
fn remove_on_discard_tile(&self, callback: DiscardTileCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl discard_tile for super::RemoteReducers {
|
impl discard_tile for super::RemoteReducers {
|
||||||
fn discard_tile(&self, tile_id: u32) -> __sdk::Result<()> {
|
fn discard_tile(&self, tile_id: u32,
|
||||||
self.imp
|
) -> __sdk::Result<()> {
|
||||||
.call_reducer("discard_tile", DiscardTileArgs { tile_id })
|
self.imp.call_reducer("discard_tile", DiscardTileArgs { tile_id, })
|
||||||
}
|
}
|
||||||
fn on_discard_tile(
|
fn on_discard_tile(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext, &u32, ) + Send + 'static,
|
||||||
) -> DiscardTileCallbackId {
|
) -> DiscardTileCallbackId {
|
||||||
DiscardTileCallbackId(self.imp.on_reducer(
|
DiscardTileCallbackId(self.imp.on_reducer(
|
||||||
"discard_tile",
|
"discard_tile",
|
||||||
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::DiscardTile {
|
||||||
reducer: super::Reducer::DiscardTile { tile_id },
|
tile_id,
|
||||||
..
|
|
||||||
},
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
..
|
..
|
||||||
} = ctx
|
} = ctx else { unreachable!() };
|
||||||
else {
|
callback(ctx, tile_id, )
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx, tile_id)
|
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -103,3 +105,4 @@ impl set_flags_for_discard_tile for super::SetReducerFlags {
|
||||||
self.imp.set_call_reducer_flags("discard_tile", flags);
|
self.imp.set_call_reducer_flags("discard_tile", flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
103
jong-db/src/db/disconnect_reducer.rs
Normal file
103
jong-db/src/db/disconnect_reducer.rs
Normal file
|
|
@ -0,0 +1,103 @@
|
||||||
|
// 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 DisconnectArgs {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<DisconnectArgs> for super::Reducer {
|
||||||
|
fn from(args: DisconnectArgs) -> Self {
|
||||||
|
Self::Disconnect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for DisconnectArgs {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DisconnectCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the reducer `disconnect`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
|
pub trait disconnect {
|
||||||
|
/// Request that the remote module invoke the reducer `disconnect` 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_disconnect`] callbacks.
|
||||||
|
fn disconnect(&self, ) -> __sdk::Result<()>;
|
||||||
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `disconnect`.
|
||||||
|
///
|
||||||
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
/// to determine the reducer's status.
|
||||||
|
///
|
||||||
|
/// The returned [`DisconnectCallbackId`] can be passed to [`Self::remove_on_disconnect`]
|
||||||
|
/// to cancel the callback.
|
||||||
|
fn on_disconnect(&self, callback: impl FnMut(&super::ReducerEventContext, ) + Send + 'static) -> DisconnectCallbackId;
|
||||||
|
/// Cancel a callback previously registered by [`Self::on_disconnect`],
|
||||||
|
/// causing it not to run in the future.
|
||||||
|
fn remove_on_disconnect(&self, callback: DisconnectCallbackId);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl disconnect for super::RemoteReducers {
|
||||||
|
fn disconnect(&self, ) -> __sdk::Result<()> {
|
||||||
|
self.imp.call_reducer("disconnect", DisconnectArgs { })
|
||||||
|
}
|
||||||
|
fn on_disconnect(
|
||||||
|
&self,
|
||||||
|
mut callback: impl FnMut(&super::ReducerEventContext, ) + Send + 'static,
|
||||||
|
) -> DisconnectCallbackId {
|
||||||
|
DisconnectCallbackId(self.imp.on_reducer(
|
||||||
|
"disconnect",
|
||||||
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
|
#[allow(irrefutable_let_patterns)]
|
||||||
|
let super::ReducerEventContext {
|
||||||
|
event: __sdk::ReducerEvent {
|
||||||
|
reducer: super::Reducer::Disconnect {
|
||||||
|
|
||||||
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
|
..
|
||||||
|
} = ctx else { unreachable!() };
|
||||||
|
callback(ctx, )
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
fn remove_on_disconnect(&self, callback: DisconnectCallbackId) {
|
||||||
|
self.imp.remove_on_reducer("disconnect", callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// Extension trait for setting the call-flags for the reducer `disconnect`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
pub trait set_flags_for_disconnect {
|
||||||
|
/// Set the call-reducer flags for the reducer `disconnect` to `flags`.
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
fn disconnect(&self, flags: __ws::CallReducerFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl set_flags_for_disconnect for super::SetReducerFlags {
|
||||||
|
fn disconnect(&self, flags: __ws::CallReducerFlags) {
|
||||||
|
self.imp.set_call_reducer_flags("disconnect", flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -13,8 +18,12 @@ pub enum Dragon {
|
||||||
Hatsu,
|
Hatsu,
|
||||||
|
|
||||||
Chun,
|
Chun,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Dragon {
|
impl __sdk::InModule for Dragon {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -19,8 +24,12 @@ pub enum GameState {
|
||||||
Play,
|
Play,
|
||||||
|
|
||||||
Exit,
|
Exit,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for GameState {
|
impl __sdk::InModule for GameState {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
178
jong-db/src/db/game_timer_table.rs
Normal file
178
jong-db/src/db/game_timer_table.rs
Normal file
|
|
@ -0,0 +1,178 @@
|
||||||
|
// 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::game_timer_type::GameTimer;
|
||||||
|
|
||||||
|
/// Table handle for the table `game_timer`.
|
||||||
|
///
|
||||||
|
/// Obtain a handle from the [`GameTimerTableAccess::game_timer`] method on [`super::RemoteTables`],
|
||||||
|
/// like `ctx.db.game_timer()`.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.game_timer().on_insert(...)`.
|
||||||
|
pub struct GameTimerTableHandle<'ctx> {
|
||||||
|
imp: __sdk::TableHandle<GameTimer>,
|
||||||
|
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the table `game_timer`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteTables`].
|
||||||
|
pub trait GameTimerTableAccess {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
/// Obtain a [`GameTimerTableHandle`], which mediates access to the table `game_timer`.
|
||||||
|
fn game_timer(&self) -> GameTimerTableHandle<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GameTimerTableAccess for super::RemoteTables {
|
||||||
|
fn game_timer(&self) -> GameTimerTableHandle<'_> {
|
||||||
|
GameTimerTableHandle {
|
||||||
|
imp: self.imp.get_table::<GameTimer>("game_timer"),
|
||||||
|
ctx: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct GameTimerInsertCallbackId(__sdk::CallbackId);
|
||||||
|
pub struct GameTimerDeleteCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::Table for GameTimerTableHandle<'ctx> {
|
||||||
|
type Row = GameTimer;
|
||||||
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
|
fn iter(&self) -> impl Iterator<Item = GameTimer> + '_ { self.imp.iter() }
|
||||||
|
|
||||||
|
type InsertCallbackId = GameTimerInsertCallbackId;
|
||||||
|
|
||||||
|
fn on_insert(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> GameTimerInsertCallbackId {
|
||||||
|
GameTimerInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_insert(&self, callback: GameTimerInsertCallbackId) {
|
||||||
|
self.imp.remove_on_insert(callback.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteCallbackId = GameTimerDeleteCallbackId;
|
||||||
|
|
||||||
|
fn on_delete(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> GameTimerDeleteCallbackId {
|
||||||
|
GameTimerDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_delete(&self, callback: GameTimerDeleteCallbackId) {
|
||||||
|
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::<GameTimer>("game_timer");
|
||||||
|
_table.add_unique_constraint::<u64>("id", |row| &row.id);
|
||||||
|
_table.add_unique_constraint::<u32>("lobby_id", |row| &row.lobby_id);
|
||||||
|
}
|
||||||
|
pub struct GameTimerUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::TableWithPrimaryKey for GameTimerTableHandle<'ctx> {
|
||||||
|
type UpdateCallbackId = GameTimerUpdateCallbackId;
|
||||||
|
|
||||||
|
fn on_update(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
|
||||||
|
) -> GameTimerUpdateCallbackId {
|
||||||
|
GameTimerUpdateCallbackId(self.imp.on_update(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_update(&self, callback: GameTimerUpdateCallbackId) {
|
||||||
|
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<GameTimer>> {
|
||||||
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
|
__sdk::InternalError::failed_parse(
|
||||||
|
"TableUpdate<GameTimer>",
|
||||||
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `id` unique index on the table `game_timer`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`GameTimerIdUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.game_timer().id().find(...)`.
|
||||||
|
pub struct GameTimerIdUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<GameTimer, u64>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> GameTimerTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `id` unique index on the table `game_timer`.
|
||||||
|
pub fn id(&self) -> GameTimerIdUnique<'ctx> {
|
||||||
|
GameTimerIdUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<u64>("id"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> GameTimerIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u64) -> Option<GameTimer> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `lobby_id` unique index on the table `game_timer`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`GameTimerLobbyIdUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.game_timer().lobby_id().find(...)`.
|
||||||
|
pub struct GameTimerLobbyIdUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<GameTimer, u32>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> GameTimerTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `lobby_id` unique index on the table `game_timer`.
|
||||||
|
pub fn lobby_id(&self) -> GameTimerLobbyIdUnique<'ctx> {
|
||||||
|
GameTimerLobbyIdUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<u32>("lobby_id"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> GameTimerLobbyIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `lobby_id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<GameTimer> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
25
jong-db/src/db/game_timer_type.rs
Normal file
25
jong-db/src/db/game_timer_type.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
// 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 GameTimer {
|
||||||
|
pub id: u64,
|
||||||
|
pub lobby_id: u32,
|
||||||
|
pub scheduled_at: __sdk::ScheduleAt,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl __sdk::InModule for GameTimer {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,7 +2,13 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -14,8 +20,8 @@ impl From<JoinOrCreateLobbyArgs> for super::Reducer {
|
||||||
fn from(args: JoinOrCreateLobbyArgs) -> Self {
|
fn from(args: JoinOrCreateLobbyArgs) -> Self {
|
||||||
Self::JoinOrCreateLobby {
|
Self::JoinOrCreateLobby {
|
||||||
lobby_id: args.lobby_id,
|
lobby_id: args.lobby_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for JoinOrCreateLobbyArgs {
|
impl __sdk::InModule for JoinOrCreateLobbyArgs {
|
||||||
|
|
@ -34,7 +40,8 @@ pub trait join_or_create_lobby {
|
||||||
/// 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_join_or_create_lobby`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_join_or_create_lobby`] callbacks.
|
||||||
fn join_or_create_lobby(&self, lobby_id: u32) -> __sdk::Result<()>;
|
fn join_or_create_lobby(&self, lobby_id: u32,
|
||||||
|
) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `join_or_create_lobby`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `join_or_create_lobby`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
|
@ -42,46 +49,40 @@ pub trait join_or_create_lobby {
|
||||||
///
|
///
|
||||||
/// The returned [`JoinOrCreateLobbyCallbackId`] can be passed to [`Self::remove_on_join_or_create_lobby`]
|
/// The returned [`JoinOrCreateLobbyCallbackId`] can be passed to [`Self::remove_on_join_or_create_lobby`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_join_or_create_lobby(
|
fn on_join_or_create_lobby(&self, callback: impl FnMut(&super::ReducerEventContext, &u32, ) + Send + 'static) -> JoinOrCreateLobbyCallbackId;
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static,
|
|
||||||
) -> JoinOrCreateLobbyCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_join_or_create_lobby`],
|
/// Cancel a callback previously registered by [`Self::on_join_or_create_lobby`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_join_or_create_lobby(&self, callback: JoinOrCreateLobbyCallbackId);
|
fn remove_on_join_or_create_lobby(&self, callback: JoinOrCreateLobbyCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl join_or_create_lobby for super::RemoteReducers {
|
impl join_or_create_lobby for super::RemoteReducers {
|
||||||
fn join_or_create_lobby(&self, lobby_id: u32) -> __sdk::Result<()> {
|
fn join_or_create_lobby(&self, lobby_id: u32,
|
||||||
self.imp
|
) -> __sdk::Result<()> {
|
||||||
.call_reducer("join_or_create_lobby", JoinOrCreateLobbyArgs { lobby_id })
|
self.imp.call_reducer("join_or_create_lobby", JoinOrCreateLobbyArgs { lobby_id, })
|
||||||
}
|
}
|
||||||
fn on_join_or_create_lobby(
|
fn on_join_or_create_lobby(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext, &u32, ) + Send + 'static,
|
||||||
) -> JoinOrCreateLobbyCallbackId {
|
) -> JoinOrCreateLobbyCallbackId {
|
||||||
JoinOrCreateLobbyCallbackId(self.imp.on_reducer(
|
JoinOrCreateLobbyCallbackId(self.imp.on_reducer(
|
||||||
"join_or_create_lobby",
|
"join_or_create_lobby",
|
||||||
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::JoinOrCreateLobby {
|
||||||
reducer: super::Reducer::JoinOrCreateLobby { lobby_id },
|
lobby_id,
|
||||||
..
|
|
||||||
},
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
..
|
..
|
||||||
} = ctx
|
} = ctx else { unreachable!() };
|
||||||
else {
|
callback(ctx, lobby_id, )
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx, lobby_id)
|
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
fn remove_on_join_or_create_lobby(&self, callback: JoinOrCreateLobbyCallbackId) {
|
fn remove_on_join_or_create_lobby(&self, callback: JoinOrCreateLobbyCallbackId) {
|
||||||
self.imp
|
self.imp.remove_on_reducer("join_or_create_lobby", callback.0)
|
||||||
.remove_on_reducer("join_or_create_lobby", callback.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,7 +102,7 @@ pub trait set_flags_for_join_or_create_lobby {
|
||||||
|
|
||||||
impl set_flags_for_join_or_create_lobby for super::SetReducerFlags {
|
impl set_flags_for_join_or_create_lobby for super::SetReducerFlags {
|
||||||
fn join_or_create_lobby(&self, flags: __ws::CallReducerFlags) {
|
fn join_or_create_lobby(&self, flags: __ws::CallReducerFlags) {
|
||||||
self.imp
|
self.imp.set_call_reducer_flags("join_or_create_lobby", flags);
|
||||||
.set_call_reducer_flags("join_or_create_lobby", flags);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,15 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
#![allow(unused, clippy::all)]
|
||||||
use super::game_state_type::GameState;
|
use spacetimedb_sdk::__codegen::{
|
||||||
|
self as __sdk,
|
||||||
|
__lib,
|
||||||
|
__sats,
|
||||||
|
__ws,
|
||||||
|
};
|
||||||
use super::lobby_type::Lobby;
|
use super::lobby_type::Lobby;
|
||||||
use super::player_or_bot_type::PlayerOrBot;
|
use super::player_or_bot_type::PlayerOrBot;
|
||||||
use super::turn_state_type::TurnState;
|
use super::game_state_type::GameState;
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
/// Table handle for the table `lobby`.
|
/// Table handle for the table `lobby`.
|
||||||
///
|
///
|
||||||
|
|
@ -47,12 +51,8 @@ impl<'ctx> __sdk::Table for LobbyTableHandle<'ctx> {
|
||||||
type Row = Lobby;
|
type Row = Lobby;
|
||||||
type EventContext = super::EventContext;
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
fn count(&self) -> u64 {
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
self.imp.count()
|
fn iter(&self) -> impl Iterator<Item = Lobby> + '_ { self.imp.iter() }
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = Lobby> + '_ {
|
|
||||||
self.imp.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
type InsertCallbackId = LobbyInsertCallbackId;
|
type InsertCallbackId = LobbyInsertCallbackId;
|
||||||
|
|
||||||
|
|
@ -83,9 +83,9 @@ impl<'ctx> __sdk::Table for LobbyTableHandle<'ctx> {
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||||
let _table = client_cache.get_or_make_table::<Lobby>("lobby");
|
|
||||||
|
let _table = client_cache.get_or_make_table::<Lobby>("lobby");
|
||||||
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||||
_table.add_unique_constraint::<u32>("host_player_id", |row| &row.host_player_id);
|
|
||||||
}
|
}
|
||||||
pub struct LobbyUpdateCallbackId(__sdk::CallbackId);
|
pub struct LobbyUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
|
@ -104,73 +104,46 @@ impl<'ctx> __sdk::TableWithPrimaryKey for LobbyTableHandle<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn parse_table_update(
|
pub(super) fn parse_table_update(
|
||||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
) -> __sdk::Result<__sdk::TableUpdate<Lobby>> {
|
) -> __sdk::Result<__sdk::TableUpdate<Lobby>> {
|
||||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
__sdk::InternalError::failed_parse("TableUpdate<Lobby>", "TableUpdate")
|
__sdk::InternalError::failed_parse(
|
||||||
.with_cause(e)
|
"TableUpdate<Lobby>",
|
||||||
.into()
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access to the `id` unique index on the table `lobby`,
|
/// Access to the `id` unique index on the table `lobby`,
|
||||||
/// which allows point queries on the field of the same name
|
/// which allows point queries on the field of the same name
|
||||||
/// via the [`LobbyIdUnique::find`] method.
|
/// via the [`LobbyIdUnique::find`] method.
|
||||||
///
|
///
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
/// but to directly chain method calls,
|
/// but to directly chain method calls,
|
||||||
/// like `ctx.db.lobby().id().find(...)`.
|
/// like `ctx.db.lobby().id().find(...)`.
|
||||||
pub struct LobbyIdUnique<'ctx> {
|
pub struct LobbyIdUnique<'ctx> {
|
||||||
imp: __sdk::UniqueConstraintHandle<Lobby, u32>,
|
imp: __sdk::UniqueConstraintHandle<Lobby, u32>,
|
||||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> LobbyTableHandle<'ctx> {
|
|
||||||
/// Get a handle on the `id` unique index on the table `lobby`.
|
|
||||||
pub fn id(&self) -> LobbyIdUnique<'ctx> {
|
|
||||||
LobbyIdUnique {
|
|
||||||
imp: self.imp.get_unique_constraint::<u32>("id"),
|
|
||||||
phantom: std::marker::PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> LobbyIdUnique<'ctx> {
|
impl<'ctx> LobbyTableHandle<'ctx> {
|
||||||
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
/// Get a handle on the `id` unique index on the table `lobby`.
|
||||||
/// if such a row is present in the client cache.
|
pub fn id(&self) -> LobbyIdUnique<'ctx> {
|
||||||
pub fn find(&self, col_val: &u32) -> Option<Lobby> {
|
LobbyIdUnique {
|
||||||
self.imp.find(col_val)
|
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||||
}
|
phantom: std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/// Access to the `host_player_id` unique index on the table `lobby`,
|
|
||||||
/// which allows point queries on the field of the same name
|
|
||||||
/// via the [`LobbyHostPlayerIdUnique::find`] method.
|
|
||||||
///
|
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
|
||||||
/// but to directly chain method calls,
|
|
||||||
/// like `ctx.db.lobby().host_player_id().find(...)`.
|
|
||||||
pub struct LobbyHostPlayerIdUnique<'ctx> {
|
|
||||||
imp: __sdk::UniqueConstraintHandle<Lobby, u32>,
|
|
||||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> LobbyTableHandle<'ctx> {
|
|
||||||
/// Get a handle on the `host_player_id` unique index on the table `lobby`.
|
|
||||||
pub fn host_player_id(&self) -> LobbyHostPlayerIdUnique<'ctx> {
|
|
||||||
LobbyHostPlayerIdUnique {
|
|
||||||
imp: self.imp.get_unique_constraint::<u32>("host_player_id"),
|
|
||||||
phantom: std::marker::PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> LobbyHostPlayerIdUnique<'ctx> {
|
impl<'ctx> LobbyIdUnique<'ctx> {
|
||||||
/// Find the subscribed row whose `host_player_id` column value is equal to `col_val`,
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
/// if such a row is present in the client cache.
|
/// if such a row is present in the client cache.
|
||||||
pub fn find(&self, col_val: &u32) -> Option<Lobby> {
|
pub fn find(&self, col_val: &u32) -> Option<Lobby> {
|
||||||
self.imp.find(col_val)
|
self.imp.find(col_val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2,24 +2,28 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
use super::game_state_type::GameState;
|
|
||||||
use super::player_or_bot_type::PlayerOrBot;
|
use super::player_or_bot_type::PlayerOrBot;
|
||||||
use super::turn_state_type::TurnState;
|
use super::game_state_type::GameState;
|
||||||
|
|
||||||
#[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 Lobby {
|
pub struct Lobby {
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub host_player_id: u32,
|
pub players: Vec::<PlayerOrBot>,
|
||||||
pub players: Vec<PlayerOrBot>,
|
|
||||||
pub dealer_idx: u8,
|
pub dealer_idx: u8,
|
||||||
pub current_idx: u8,
|
pub current_idx: u8,
|
||||||
pub game_state: GameState,
|
pub game_state: GameState,
|
||||||
pub turn_state: TurnState,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Lobby {
|
impl __sdk::InModule for Lobby {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
178
jong-db/src/db/logged_out_player_table.rs
Normal file
178
jong-db/src/db/logged_out_player_table.rs
Normal file
|
|
@ -0,0 +1,178 @@
|
||||||
|
// 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::player_type::Player;
|
||||||
|
|
||||||
|
/// Table handle for the table `logged_out_player`.
|
||||||
|
///
|
||||||
|
/// Obtain a handle from the [`LoggedOutPlayerTableAccess::logged_out_player`] method on [`super::RemoteTables`],
|
||||||
|
/// like `ctx.db.logged_out_player()`.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.logged_out_player().on_insert(...)`.
|
||||||
|
pub struct LoggedOutPlayerTableHandle<'ctx> {
|
||||||
|
imp: __sdk::TableHandle<Player>,
|
||||||
|
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the table `logged_out_player`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteTables`].
|
||||||
|
pub trait LoggedOutPlayerTableAccess {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
/// Obtain a [`LoggedOutPlayerTableHandle`], which mediates access to the table `logged_out_player`.
|
||||||
|
fn logged_out_player(&self) -> LoggedOutPlayerTableHandle<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LoggedOutPlayerTableAccess for super::RemoteTables {
|
||||||
|
fn logged_out_player(&self) -> LoggedOutPlayerTableHandle<'_> {
|
||||||
|
LoggedOutPlayerTableHandle {
|
||||||
|
imp: self.imp.get_table::<Player>("logged_out_player"),
|
||||||
|
ctx: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LoggedOutPlayerInsertCallbackId(__sdk::CallbackId);
|
||||||
|
pub struct LoggedOutPlayerDeleteCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::Table for LoggedOutPlayerTableHandle<'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 = LoggedOutPlayerInsertCallbackId;
|
||||||
|
|
||||||
|
fn on_insert(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> LoggedOutPlayerInsertCallbackId {
|
||||||
|
LoggedOutPlayerInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_insert(&self, callback: LoggedOutPlayerInsertCallbackId) {
|
||||||
|
self.imp.remove_on_insert(callback.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteCallbackId = LoggedOutPlayerDeleteCallbackId;
|
||||||
|
|
||||||
|
fn on_delete(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> LoggedOutPlayerDeleteCallbackId {
|
||||||
|
LoggedOutPlayerDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_delete(&self, callback: LoggedOutPlayerDeleteCallbackId) {
|
||||||
|
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>("logged_out_player");
|
||||||
|
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||||
|
_table.add_unique_constraint::<__sdk::Identity>("identity", |row| &row.identity);
|
||||||
|
}
|
||||||
|
pub struct LoggedOutPlayerUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::TableWithPrimaryKey for LoggedOutPlayerTableHandle<'ctx> {
|
||||||
|
type UpdateCallbackId = LoggedOutPlayerUpdateCallbackId;
|
||||||
|
|
||||||
|
fn on_update(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
|
||||||
|
) -> LoggedOutPlayerUpdateCallbackId {
|
||||||
|
LoggedOutPlayerUpdateCallbackId(self.imp.on_update(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_update(&self, callback: LoggedOutPlayerUpdateCallbackId) {
|
||||||
|
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 `id` unique index on the table `logged_out_player`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`LoggedOutPlayerIdUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.logged_out_player().id().find(...)`.
|
||||||
|
pub struct LoggedOutPlayerIdUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<Player, u32>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> LoggedOutPlayerTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `id` unique index on the table `logged_out_player`.
|
||||||
|
pub fn id(&self) -> LoggedOutPlayerIdUnique<'ctx> {
|
||||||
|
LoggedOutPlayerIdUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> LoggedOutPlayerIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<Player> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `identity` unique index on the table `logged_out_player`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`LoggedOutPlayerIdentityUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.logged_out_player().identity().find(...)`.
|
||||||
|
pub struct LoggedOutPlayerIdentityUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<Player, __sdk::Identity>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> LoggedOutPlayerTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `identity` unique index on the table `logged_out_player`.
|
||||||
|
pub fn identity(&self) -> LoggedOutPlayerIdentityUnique<'ctx> {
|
||||||
|
LoggedOutPlayerIdentityUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<__sdk::Identity>("identity"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> LoggedOutPlayerIdentityUnique<'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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -4,73 +4,80 @@
|
||||||
// This was generated using spacetimedb cli version 1.11.3 (commit 02449737ca3b29e7e39679fccbef541a50f32094).
|
// This was generated using spacetimedb cli version 1.11.3 (commit 02449737ca3b29e7e39679fccbef541a50f32094).
|
||||||
|
|
||||||
#![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_bot_reducer;
|
|
||||||
pub mod advance_state_timer_table;
|
|
||||||
pub mod advance_state_timer_type;
|
|
||||||
pub mod bot_table;
|
|
||||||
pub mod bot_type;
|
pub mod bot_type;
|
||||||
pub mod clear_all_reducer;
|
|
||||||
pub mod db_tile_type;
|
pub mod db_tile_type;
|
||||||
pub mod db_wall_type;
|
pub mod db_wall_type;
|
||||||
pub mod discard_tile_reducer;
|
|
||||||
pub mod dragon_type;
|
pub mod dragon_type;
|
||||||
pub mod draw_tile_reducer;
|
|
||||||
pub mod game_state_type;
|
pub mod game_state_type;
|
||||||
pub mod join_or_create_lobby_reducer;
|
pub mod game_timer_type;
|
||||||
pub mod lobby_table;
|
|
||||||
pub mod lobby_type;
|
pub mod lobby_type;
|
||||||
pub mod login_or_add_player_reducer;
|
|
||||||
pub mod player_or_bot_type;
|
|
||||||
pub mod player_table;
|
|
||||||
pub mod player_type;
|
pub mod player_type;
|
||||||
|
pub mod player_clock_type;
|
||||||
|
pub mod player_hand_type;
|
||||||
|
pub mod player_or_bot_type;
|
||||||
pub mod rank_type;
|
pub mod rank_type;
|
||||||
pub mod set_ready_reducer;
|
|
||||||
pub mod shuffle_deal_reducer;
|
|
||||||
pub mod skip_call_reducer;
|
|
||||||
pub mod start_game_reducer;
|
|
||||||
pub mod suit_type;
|
pub mod suit_type;
|
||||||
pub mod tile_table;
|
|
||||||
pub mod tile_type;
|
pub mod tile_type;
|
||||||
pub mod turn_state_type;
|
pub mod turn_state_type;
|
||||||
pub mod wall_table;
|
|
||||||
pub mod wind_type;
|
pub mod wind_type;
|
||||||
|
pub mod add_bot_reducer;
|
||||||
|
pub mod advance_game_reducer;
|
||||||
|
pub mod clear_all_reducer;
|
||||||
|
pub mod connect_reducer;
|
||||||
|
pub mod discard_tile_reducer;
|
||||||
|
pub mod disconnect_reducer;
|
||||||
|
pub mod join_or_create_lobby_reducer;
|
||||||
|
pub mod set_ready_reducer;
|
||||||
|
pub mod bot_table;
|
||||||
|
pub mod game_timer_table;
|
||||||
|
pub mod lobby_table;
|
||||||
|
pub mod logged_out_player_table;
|
||||||
|
pub mod player_table;
|
||||||
|
pub mod player_clock_table;
|
||||||
|
pub mod player_hand_table;
|
||||||
|
pub mod tile_table;
|
||||||
|
pub mod wall_table;
|
||||||
|
|
||||||
pub use add_bot_reducer::{add_bot, set_flags_for_add_bot, AddBotCallbackId};
|
|
||||||
pub use advance_state_timer_table::*;
|
|
||||||
pub use advance_state_timer_type::AdvanceStateTimer;
|
|
||||||
pub use bot_table::*;
|
|
||||||
pub use bot_type::Bot;
|
pub use bot_type::Bot;
|
||||||
pub use clear_all_reducer::{clear_all, set_flags_for_clear_all, ClearAllCallbackId};
|
|
||||||
pub use db_tile_type::DbTile;
|
pub use db_tile_type::DbTile;
|
||||||
pub use db_wall_type::DbWall;
|
pub use db_wall_type::DbWall;
|
||||||
pub use discard_tile_reducer::{discard_tile, set_flags_for_discard_tile, DiscardTileCallbackId};
|
|
||||||
pub use dragon_type::Dragon;
|
pub use dragon_type::Dragon;
|
||||||
pub use draw_tile_reducer::{draw_tile, set_flags_for_draw_tile, DrawTileCallbackId};
|
|
||||||
pub use game_state_type::GameState;
|
pub use game_state_type::GameState;
|
||||||
pub use join_or_create_lobby_reducer::{
|
pub use game_timer_type::GameTimer;
|
||||||
join_or_create_lobby, set_flags_for_join_or_create_lobby, JoinOrCreateLobbyCallbackId,
|
|
||||||
};
|
|
||||||
pub use lobby_table::*;
|
|
||||||
pub use lobby_type::Lobby;
|
pub use lobby_type::Lobby;
|
||||||
pub use login_or_add_player_reducer::{
|
|
||||||
login_or_add_player, set_flags_for_login_or_add_player, LoginOrAddPlayerCallbackId,
|
|
||||||
};
|
|
||||||
pub use player_or_bot_type::PlayerOrBot;
|
|
||||||
pub use player_table::*;
|
|
||||||
pub use player_type::Player;
|
pub use player_type::Player;
|
||||||
|
pub use player_clock_type::PlayerClock;
|
||||||
|
pub use player_hand_type::PlayerHand;
|
||||||
|
pub use player_or_bot_type::PlayerOrBot;
|
||||||
pub use rank_type::Rank;
|
pub use rank_type::Rank;
|
||||||
pub use set_ready_reducer::{set_flags_for_set_ready, set_ready, SetReadyCallbackId};
|
|
||||||
pub use shuffle_deal_reducer::{set_flags_for_shuffle_deal, shuffle_deal, ShuffleDealCallbackId};
|
|
||||||
pub use skip_call_reducer::{set_flags_for_skip_call, skip_call, SkipCallCallbackId};
|
|
||||||
pub use start_game_reducer::{set_flags_for_start_game, start_game, StartGameCallbackId};
|
|
||||||
pub use suit_type::Suit;
|
pub use suit_type::Suit;
|
||||||
pub use tile_table::*;
|
|
||||||
pub use tile_type::Tile;
|
pub use tile_type::Tile;
|
||||||
pub use turn_state_type::TurnState;
|
pub use turn_state_type::TurnState;
|
||||||
pub use wall_table::*;
|
|
||||||
pub use wind_type::Wind;
|
pub use wind_type::Wind;
|
||||||
|
pub use bot_table::*;
|
||||||
|
pub use game_timer_table::*;
|
||||||
|
pub use lobby_table::*;
|
||||||
|
pub use logged_out_player_table::*;
|
||||||
|
pub use player_table::*;
|
||||||
|
pub use player_clock_table::*;
|
||||||
|
pub use player_hand_table::*;
|
||||||
|
pub use tile_table::*;
|
||||||
|
pub use wall_table::*;
|
||||||
|
pub use add_bot_reducer::{add_bot, set_flags_for_add_bot, AddBotCallbackId};
|
||||||
|
pub use advance_game_reducer::{advance_game, set_flags_for_advance_game, AdvanceGameCallbackId};
|
||||||
|
pub use clear_all_reducer::{clear_all, set_flags_for_clear_all, ClearAllCallbackId};
|
||||||
|
pub use connect_reducer::{connect, set_flags_for_connect, ConnectCallbackId};
|
||||||
|
pub use discard_tile_reducer::{discard_tile, set_flags_for_discard_tile, DiscardTileCallbackId};
|
||||||
|
pub use disconnect_reducer::{disconnect, set_flags_for_disconnect, DisconnectCallbackId};
|
||||||
|
pub use join_or_create_lobby_reducer::{join_or_create_lobby, set_flags_for_join_or_create_lobby, JoinOrCreateLobbyCallbackId};
|
||||||
|
pub use set_ready_reducer::{set_ready, set_flags_for_set_ready, SetReadyCallbackId};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
|
||||||
|
|
@ -80,18 +87,27 @@ pub use wind_type::Wind;
|
||||||
/// to indicate which reducer caused the event.
|
/// to indicate which reducer caused the event.
|
||||||
|
|
||||||
pub enum Reducer {
|
pub enum Reducer {
|
||||||
AddBot { lobby_id: u32 },
|
AddBot {
|
||||||
ClearAll,
|
lobby_id: u32,
|
||||||
DiscardTile { tile_id: u32 },
|
} ,
|
||||||
DrawTile,
|
AdvanceGame {
|
||||||
JoinOrCreateLobby { lobby_id: u32 },
|
game_timer: GameTimer,
|
||||||
LoginOrAddPlayer,
|
} ,
|
||||||
SetReady { ready: bool },
|
ClearAll ,
|
||||||
ShuffleDeal { lobby_id: u32 },
|
Connect ,
|
||||||
SkipCall,
|
DiscardTile {
|
||||||
StartGame,
|
tile_id: u32,
|
||||||
|
} ,
|
||||||
|
Disconnect ,
|
||||||
|
JoinOrCreateLobby {
|
||||||
|
lobby_id: u32,
|
||||||
|
} ,
|
||||||
|
SetReady {
|
||||||
|
ready: bool,
|
||||||
|
} ,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Reducer {
|
impl __sdk::InModule for Reducer {
|
||||||
type Module = RemoteModule;
|
type Module = RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
@ -99,140 +115,74 @@ 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::AddBot { .. } => "add_bot",
|
Reducer::AddBot { .. } => "add_bot",
|
||||||
|
Reducer::AdvanceGame { .. } => "advance_game",
|
||||||
Reducer::ClearAll => "clear_all",
|
Reducer::ClearAll => "clear_all",
|
||||||
|
Reducer::Connect => "connect",
|
||||||
Reducer::DiscardTile { .. } => "discard_tile",
|
Reducer::DiscardTile { .. } => "discard_tile",
|
||||||
Reducer::DrawTile => "draw_tile",
|
Reducer::Disconnect => "disconnect",
|
||||||
Reducer::JoinOrCreateLobby { .. } => "join_or_create_lobby",
|
Reducer::JoinOrCreateLobby { .. } => "join_or_create_lobby",
|
||||||
Reducer::LoginOrAddPlayer => "login_or_add_player",
|
|
||||||
Reducer::SetReady { .. } => "set_ready",
|
Reducer::SetReady { .. } => "set_ready",
|
||||||
Reducer::ShuffleDeal { .. } => "shuffle_deal",
|
|
||||||
Reducer::SkipCall => "skip_call",
|
|
||||||
Reducer::StartGame => "start_game",
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
|
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_bot" => Ok(__sdk::parse_reducer_args::<add_bot_reducer::AddBotArgs>(
|
"add_bot" => Ok(__sdk::parse_reducer_args::<add_bot_reducer::AddBotArgs>("add_bot", &value.args)?.into()),
|
||||||
"add_bot",
|
"advance_game" => Ok(__sdk::parse_reducer_args::<advance_game_reducer::AdvanceGameArgs>("advance_game", &value.args)?.into()),
|
||||||
&value.args,
|
"clear_all" => Ok(__sdk::parse_reducer_args::<clear_all_reducer::ClearAllArgs>("clear_all", &value.args)?.into()),
|
||||||
)?
|
"connect" => Ok(__sdk::parse_reducer_args::<connect_reducer::ConnectArgs>("connect", &value.args)?.into()),
|
||||||
.into()),
|
"discard_tile" => Ok(__sdk::parse_reducer_args::<discard_tile_reducer::DiscardTileArgs>("discard_tile", &value.args)?.into()),
|
||||||
"clear_all" => Ok(
|
"disconnect" => Ok(__sdk::parse_reducer_args::<disconnect_reducer::DisconnectArgs>("disconnect", &value.args)?.into()),
|
||||||
__sdk::parse_reducer_args::<clear_all_reducer::ClearAllArgs>(
|
"join_or_create_lobby" => Ok(__sdk::parse_reducer_args::<join_or_create_lobby_reducer::JoinOrCreateLobbyArgs>("join_or_create_lobby", &value.args)?.into()),
|
||||||
"clear_all",
|
"set_ready" => Ok(__sdk::parse_reducer_args::<set_ready_reducer::SetReadyArgs>("set_ready", &value.args)?.into()),
|
||||||
&value.args,
|
unknown => Err(__sdk::InternalError::unknown_name("reducer", unknown, "ReducerCallInfo").into()),
|
||||||
)?
|
}
|
||||||
.into(),
|
}
|
||||||
),
|
|
||||||
"discard_tile" => Ok(
|
|
||||||
__sdk::parse_reducer_args::<discard_tile_reducer::DiscardTileArgs>(
|
|
||||||
"discard_tile",
|
|
||||||
&value.args,
|
|
||||||
)?
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
"draw_tile" => Ok(
|
|
||||||
__sdk::parse_reducer_args::<draw_tile_reducer::DrawTileArgs>(
|
|
||||||
"draw_tile",
|
|
||||||
&value.args,
|
|
||||||
)?
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
"join_or_create_lobby" => Ok(__sdk::parse_reducer_args::<
|
|
||||||
join_or_create_lobby_reducer::JoinOrCreateLobbyArgs,
|
|
||||||
>("join_or_create_lobby", &value.args)?
|
|
||||||
.into()),
|
|
||||||
"login_or_add_player" => Ok(__sdk::parse_reducer_args::<
|
|
||||||
login_or_add_player_reducer::LoginOrAddPlayerArgs,
|
|
||||||
>("login_or_add_player", &value.args)?
|
|
||||||
.into()),
|
|
||||||
"set_ready" => Ok(
|
|
||||||
__sdk::parse_reducer_args::<set_ready_reducer::SetReadyArgs>(
|
|
||||||
"set_ready",
|
|
||||||
&value.args,
|
|
||||||
)?
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
"shuffle_deal" => Ok(
|
|
||||||
__sdk::parse_reducer_args::<shuffle_deal_reducer::ShuffleDealArgs>(
|
|
||||||
"shuffle_deal",
|
|
||||||
&value.args,
|
|
||||||
)?
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
"skip_call" => Ok(
|
|
||||||
__sdk::parse_reducer_args::<skip_call_reducer::SkipCallArgs>(
|
|
||||||
"skip_call",
|
|
||||||
&value.args,
|
|
||||||
)?
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
"start_game" => Ok(
|
|
||||||
__sdk::parse_reducer_args::<start_game_reducer::StartGameArgs>(
|
|
||||||
"start_game",
|
|
||||||
&value.args,
|
|
||||||
)?
|
|
||||||
.into(),
|
|
||||||
),
|
|
||||||
unknown => {
|
|
||||||
Err(
|
|
||||||
__sdk::InternalError::unknown_name("reducer", unknown, "ReducerCallInfo")
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct DbUpdate {
|
pub struct DbUpdate {
|
||||||
advance_state_timer: __sdk::TableUpdate<AdvanceStateTimer>,
|
bot: __sdk::TableUpdate<Bot>,
|
||||||
bot: __sdk::TableUpdate<Bot>,
|
game_timer: __sdk::TableUpdate<GameTimer>,
|
||||||
lobby: __sdk::TableUpdate<Lobby>,
|
lobby: __sdk::TableUpdate<Lobby>,
|
||||||
|
logged_out_player: __sdk::TableUpdate<Player>,
|
||||||
player: __sdk::TableUpdate<Player>,
|
player: __sdk::TableUpdate<Player>,
|
||||||
|
player_clock: __sdk::TableUpdate<PlayerClock>,
|
||||||
|
player_hand: __sdk::TableUpdate<PlayerHand>,
|
||||||
tile: __sdk::TableUpdate<DbTile>,
|
tile: __sdk::TableUpdate<DbTile>,
|
||||||
wall: __sdk::TableUpdate<DbWall>,
|
wall: __sdk::TableUpdate<DbWall>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
||||||
type Error = __sdk::Error;
|
type Error = __sdk::Error;
|
||||||
fn try_from(raw: __ws::DatabaseUpdate<__ws::BsatnFormat>) -> Result<Self, Self::Error> {
|
fn try_from(raw: __ws::DatabaseUpdate<__ws::BsatnFormat>) -> Result<Self, Self::Error> {
|
||||||
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[..] {
|
||||||
"advance_state_timer" => db_update
|
|
||||||
.advance_state_timer
|
"bot" => db_update.bot.append(bot_table::parse_table_update(table_update)?),
|
||||||
.append(advance_state_timer_table::parse_table_update(table_update)?),
|
"game_timer" => db_update.game_timer.append(game_timer_table::parse_table_update(table_update)?),
|
||||||
"bot" => db_update
|
"lobby" => db_update.lobby.append(lobby_table::parse_table_update(table_update)?),
|
||||||
.bot
|
"logged_out_player" => db_update.logged_out_player.append(logged_out_player_table::parse_table_update(table_update)?),
|
||||||
.append(bot_table::parse_table_update(table_update)?),
|
"player" => db_update.player.append(player_table::parse_table_update(table_update)?),
|
||||||
"lobby" => db_update
|
"player_clock" => db_update.player_clock.append(player_clock_table::parse_table_update(table_update)?),
|
||||||
.lobby
|
"player_hand" => db_update.player_hand.append(player_hand_table::parse_table_update(table_update)?),
|
||||||
.append(lobby_table::parse_table_update(table_update)?),
|
"tile" => db_update.tile.append(tile_table::parse_table_update(table_update)?),
|
||||||
"player" => db_update
|
"wall" => db_update.wall.append(wall_table::parse_table_update(table_update)?),
|
||||||
.player
|
|
||||||
.append(player_table::parse_table_update(table_update)?),
|
|
||||||
"tile" => db_update
|
|
||||||
.tile
|
|
||||||
.append(tile_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(
|
||||||
"table",
|
"table",
|
||||||
unknown,
|
unknown,
|
||||||
"DatabaseUpdate",
|
"DatabaseUpdate",
|
||||||
)
|
).into());
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -245,73 +195,58 @@ impl __sdk::InModule for DbUpdate {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::DbUpdate for DbUpdate {
|
impl __sdk::DbUpdate for DbUpdate {
|
||||||
fn apply_to_client_cache(
|
fn apply_to_client_cache(&self, cache: &mut __sdk::ClientCache<RemoteModule>) -> AppliedDiff<'_> {
|
||||||
&self,
|
let mut diff = AppliedDiff::default();
|
||||||
cache: &mut __sdk::ClientCache<RemoteModule>,
|
|
||||||
) -> AppliedDiff<'_> {
|
diff.bot = cache.apply_diff_to_table::<Bot>("bot", &self.bot).with_updates_by_pk(|row| &row.id);
|
||||||
let mut diff = AppliedDiff::default();
|
diff.game_timer = cache.apply_diff_to_table::<GameTimer>("game_timer", &self.game_timer).with_updates_by_pk(|row| &row.id);
|
||||||
|
diff.lobby = cache.apply_diff_to_table::<Lobby>("lobby", &self.lobby).with_updates_by_pk(|row| &row.id);
|
||||||
|
diff.logged_out_player = cache.apply_diff_to_table::<Player>("logged_out_player", &self.logged_out_player).with_updates_by_pk(|row| &row.identity);
|
||||||
|
diff.player = cache.apply_diff_to_table::<Player>("player", &self.player).with_updates_by_pk(|row| &row.identity);
|
||||||
|
diff.player_clock = cache.apply_diff_to_table::<PlayerClock>("player_clock", &self.player_clock).with_updates_by_pk(|row| &row.id);
|
||||||
|
diff.player_hand = cache.apply_diff_to_table::<PlayerHand>("player_hand", &self.player_hand).with_updates_by_pk(|row| &row.id);
|
||||||
|
diff.tile = cache.apply_diff_to_table::<DbTile>("tile", &self.tile).with_updates_by_pk(|row| &row.id);
|
||||||
|
diff.wall = cache.apply_diff_to_table::<DbWall>("wall", &self.wall).with_updates_by_pk(|row| &row.lobby_id);
|
||||||
|
|
||||||
diff.advance_state_timer = cache
|
diff
|
||||||
.apply_diff_to_table::<AdvanceStateTimer>(
|
}
|
||||||
"advance_state_timer",
|
|
||||||
&self.advance_state_timer,
|
|
||||||
)
|
|
||||||
.with_updates_by_pk(|row| &row.scheduled_id);
|
|
||||||
diff.bot = cache
|
|
||||||
.apply_diff_to_table::<Bot>("bot", &self.bot)
|
|
||||||
.with_updates_by_pk(|row| &row.id);
|
|
||||||
diff.lobby = cache
|
|
||||||
.apply_diff_to_table::<Lobby>("lobby", &self.lobby)
|
|
||||||
.with_updates_by_pk(|row| &row.id);
|
|
||||||
diff.player = cache
|
|
||||||
.apply_diff_to_table::<Player>("player", &self.player)
|
|
||||||
.with_updates_by_pk(|row| &row.identity);
|
|
||||||
diff.tile = cache
|
|
||||||
.apply_diff_to_table::<DbTile>("tile", &self.tile)
|
|
||||||
.with_updates_by_pk(|row| &row.id);
|
|
||||||
diff.wall = cache
|
|
||||||
.apply_diff_to_table::<DbWall>("wall", &self.wall)
|
|
||||||
.with_updates_by_pk(|row| &row.lobby_id);
|
|
||||||
|
|
||||||
diff
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct AppliedDiff<'r> {
|
pub struct AppliedDiff<'r> {
|
||||||
advance_state_timer: __sdk::TableAppliedDiff<'r, AdvanceStateTimer>,
|
bot: __sdk::TableAppliedDiff<'r, Bot>,
|
||||||
bot: __sdk::TableAppliedDiff<'r, Bot>,
|
game_timer: __sdk::TableAppliedDiff<'r, GameTimer>,
|
||||||
lobby: __sdk::TableAppliedDiff<'r, Lobby>,
|
lobby: __sdk::TableAppliedDiff<'r, Lobby>,
|
||||||
|
logged_out_player: __sdk::TableAppliedDiff<'r, Player>,
|
||||||
player: __sdk::TableAppliedDiff<'r, Player>,
|
player: __sdk::TableAppliedDiff<'r, Player>,
|
||||||
|
player_clock: __sdk::TableAppliedDiff<'r, PlayerClock>,
|
||||||
|
player_hand: __sdk::TableAppliedDiff<'r, PlayerHand>,
|
||||||
tile: __sdk::TableAppliedDiff<'r, DbTile>,
|
tile: __sdk::TableAppliedDiff<'r, DbTile>,
|
||||||
wall: __sdk::TableAppliedDiff<'r, DbWall>,
|
wall: __sdk::TableAppliedDiff<'r, DbWall>,
|
||||||
__unused: std::marker::PhantomData<&'r ()>,
|
__unused: std::marker::PhantomData<&'r ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for AppliedDiff<'_> {
|
impl __sdk::InModule for AppliedDiff<'_> {
|
||||||
type Module = RemoteModule;
|
type Module = RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
|
impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
|
||||||
fn invoke_row_callbacks(
|
fn invoke_row_callbacks(&self, event: &EventContext, callbacks: &mut __sdk::DbCallbacks<RemoteModule>) {
|
||||||
&self,
|
callbacks.invoke_table_row_callbacks::<Bot>("bot", &self.bot, event);
|
||||||
event: &EventContext,
|
callbacks.invoke_table_row_callbacks::<GameTimer>("game_timer", &self.game_timer, event);
|
||||||
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
|
|
||||||
) {
|
|
||||||
callbacks.invoke_table_row_callbacks::<AdvanceStateTimer>(
|
|
||||||
"advance_state_timer",
|
|
||||||
&self.advance_state_timer,
|
|
||||||
event,
|
|
||||||
);
|
|
||||||
callbacks.invoke_table_row_callbacks::<Bot>("bot", &self.bot, event);
|
|
||||||
callbacks.invoke_table_row_callbacks::<Lobby>("lobby", &self.lobby, event);
|
callbacks.invoke_table_row_callbacks::<Lobby>("lobby", &self.lobby, event);
|
||||||
|
callbacks.invoke_table_row_callbacks::<Player>("logged_out_player", &self.logged_out_player, event);
|
||||||
callbacks.invoke_table_row_callbacks::<Player>("player", &self.player, event);
|
callbacks.invoke_table_row_callbacks::<Player>("player", &self.player, event);
|
||||||
|
callbacks.invoke_table_row_callbacks::<PlayerClock>("player_clock", &self.player_clock, event);
|
||||||
|
callbacks.invoke_table_row_callbacks::<PlayerHand>("player_hand", &self.player_hand, event);
|
||||||
callbacks.invoke_table_row_callbacks::<DbTile>("tile", &self.tile, event);
|
callbacks.invoke_table_row_callbacks::<DbTile>("tile", &self.tile, event);
|
||||||
callbacks.invoke_table_row_callbacks::<DbWall>("wall", &self.wall, event);
|
callbacks.invoke_table_row_callbacks::<DbWall>("wall", &self.wall, event);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct RemoteModule;
|
pub struct RemoteModule;
|
||||||
|
|
@ -564,6 +499,7 @@ impl __sdk::SubscriptionHandle for SubscriptionHandle {
|
||||||
fn unsubscribe(self) -> __sdk::Result<()> {
|
fn unsubscribe(self) -> __sdk::Result<()> {
|
||||||
self.imp.unsubscribe_then(None)
|
self.imp.unsubscribe_then(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Alias trait for a [`__sdk::DbContext`] connected to this module,
|
/// Alias trait for a [`__sdk::DbContext`] connected to this module,
|
||||||
|
|
@ -571,25 +507,19 @@ impl __sdk::SubscriptionHandle for SubscriptionHandle {
|
||||||
///
|
///
|
||||||
/// Users can use this trait as a boundary on definitions which should accept
|
/// Users can use this trait as a boundary on definitions which should accept
|
||||||
/// either a [`DbConnection`] or an [`EventContext`] and operate on either.
|
/// either a [`DbConnection`] or an [`EventContext`] and operate on either.
|
||||||
pub trait RemoteDbContext:
|
pub trait RemoteDbContext: __sdk::DbContext<
|
||||||
__sdk::DbContext<
|
|
||||||
DbView = RemoteTables,
|
DbView = RemoteTables,
|
||||||
Reducers = RemoteReducers,
|
Reducers = RemoteReducers,
|
||||||
SetReducerFlags = SetReducerFlags,
|
SetReducerFlags = SetReducerFlags,
|
||||||
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
|
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
|
||||||
>
|
> {}
|
||||||
{
|
impl<Ctx: __sdk::DbContext<
|
||||||
}
|
DbView = RemoteTables,
|
||||||
impl<
|
Reducers = RemoteReducers,
|
||||||
Ctx: __sdk::DbContext<
|
SetReducerFlags = SetReducerFlags,
|
||||||
DbView = RemoteTables,
|
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
|
||||||
Reducers = RemoteReducers,
|
>> RemoteDbContext for Ctx {}
|
||||||
SetReducerFlags = SetReducerFlags,
|
|
||||||
SubscriptionBuilder = __sdk::SubscriptionBuilder<RemoteModule>,
|
|
||||||
>,
|
|
||||||
> RemoteDbContext for Ctx
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An [`__sdk::DbContext`] augmented with a [`__sdk::Event`],
|
/// An [`__sdk::DbContext`] augmented with a [`__sdk::Event`],
|
||||||
/// passed to [`__sdk::Table::on_insert`], [`__sdk::Table::on_delete`] and [`__sdk::TableWithPrimaryKey::on_update`] callbacks.
|
/// passed to [`__sdk::Table::on_insert`], [`__sdk::Table::on_delete`] and [`__sdk::TableWithPrimaryKey::on_update`] callbacks.
|
||||||
|
|
@ -1014,6 +944,7 @@ impl __sdk::DbContext for ErrorContext {
|
||||||
impl __sdk::ErrorContext for ErrorContext {}
|
impl __sdk::ErrorContext for ErrorContext {}
|
||||||
|
|
||||||
impl __sdk::SpacetimeModule for RemoteModule {
|
impl __sdk::SpacetimeModule for RemoteModule {
|
||||||
|
|
||||||
type DbConnection = DbConnection;
|
type DbConnection = DbConnection;
|
||||||
type EventContext = EventContext;
|
type EventContext = EventContext;
|
||||||
type ReducerEventContext = ReducerEventContext;
|
type ReducerEventContext = ReducerEventContext;
|
||||||
|
|
@ -1028,12 +959,15 @@ impl __sdk::SpacetimeModule for RemoteModule {
|
||||||
type AppliedDiff<'r> = AppliedDiff<'r>;
|
type AppliedDiff<'r> = AppliedDiff<'r>;
|
||||||
type SubscriptionHandle = SubscriptionHandle;
|
type SubscriptionHandle = SubscriptionHandle;
|
||||||
|
|
||||||
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
|
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
|
||||||
advance_state_timer_table::register_table(client_cache);
|
bot_table::register_table(client_cache);
|
||||||
bot_table::register_table(client_cache);
|
game_timer_table::register_table(client_cache);
|
||||||
lobby_table::register_table(client_cache);
|
lobby_table::register_table(client_cache);
|
||||||
|
logged_out_player_table::register_table(client_cache);
|
||||||
player_table::register_table(client_cache);
|
player_table::register_table(client_cache);
|
||||||
|
player_clock_table::register_table(client_cache);
|
||||||
|
player_hand_table::register_table(client_cache);
|
||||||
tile_table::register_table(client_cache);
|
tile_table::register_table(client_cache);
|
||||||
wall_table::register_table(client_cache);
|
wall_table::register_table(client_cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
178
jong-db/src/db/player_clock_table.rs
Normal file
178
jong-db/src/db/player_clock_table.rs
Normal file
|
|
@ -0,0 +1,178 @@
|
||||||
|
// 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::player_clock_type::PlayerClock;
|
||||||
|
|
||||||
|
/// Table handle for the table `player_clock`.
|
||||||
|
///
|
||||||
|
/// Obtain a handle from the [`PlayerClockTableAccess::player_clock`] method on [`super::RemoteTables`],
|
||||||
|
/// like `ctx.db.player_clock()`.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player_clock().on_insert(...)`.
|
||||||
|
pub struct PlayerClockTableHandle<'ctx> {
|
||||||
|
imp: __sdk::TableHandle<PlayerClock>,
|
||||||
|
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the table `player_clock`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteTables`].
|
||||||
|
pub trait PlayerClockTableAccess {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
/// Obtain a [`PlayerClockTableHandle`], which mediates access to the table `player_clock`.
|
||||||
|
fn player_clock(&self) -> PlayerClockTableHandle<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerClockTableAccess for super::RemoteTables {
|
||||||
|
fn player_clock(&self) -> PlayerClockTableHandle<'_> {
|
||||||
|
PlayerClockTableHandle {
|
||||||
|
imp: self.imp.get_table::<PlayerClock>("player_clock"),
|
||||||
|
ctx: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PlayerClockInsertCallbackId(__sdk::CallbackId);
|
||||||
|
pub struct PlayerClockDeleteCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::Table for PlayerClockTableHandle<'ctx> {
|
||||||
|
type Row = PlayerClock;
|
||||||
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
|
fn iter(&self) -> impl Iterator<Item = PlayerClock> + '_ { self.imp.iter() }
|
||||||
|
|
||||||
|
type InsertCallbackId = PlayerClockInsertCallbackId;
|
||||||
|
|
||||||
|
fn on_insert(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerClockInsertCallbackId {
|
||||||
|
PlayerClockInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_insert(&self, callback: PlayerClockInsertCallbackId) {
|
||||||
|
self.imp.remove_on_insert(callback.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteCallbackId = PlayerClockDeleteCallbackId;
|
||||||
|
|
||||||
|
fn on_delete(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerClockDeleteCallbackId {
|
||||||
|
PlayerClockDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_delete(&self, callback: PlayerClockDeleteCallbackId) {
|
||||||
|
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::<PlayerClock>("player_clock");
|
||||||
|
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||||
|
_table.add_unique_constraint::<u32>("player_id", |row| &row.player_id);
|
||||||
|
}
|
||||||
|
pub struct PlayerClockUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::TableWithPrimaryKey for PlayerClockTableHandle<'ctx> {
|
||||||
|
type UpdateCallbackId = PlayerClockUpdateCallbackId;
|
||||||
|
|
||||||
|
fn on_update(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerClockUpdateCallbackId {
|
||||||
|
PlayerClockUpdateCallbackId(self.imp.on_update(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_update(&self, callback: PlayerClockUpdateCallbackId) {
|
||||||
|
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<PlayerClock>> {
|
||||||
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
|
__sdk::InternalError::failed_parse(
|
||||||
|
"TableUpdate<PlayerClock>",
|
||||||
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `id` unique index on the table `player_clock`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`PlayerClockIdUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player_clock().id().find(...)`.
|
||||||
|
pub struct PlayerClockIdUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<PlayerClock, u32>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerClockTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `id` unique index on the table `player_clock`.
|
||||||
|
pub fn id(&self) -> PlayerClockIdUnique<'ctx> {
|
||||||
|
PlayerClockIdUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerClockIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<PlayerClock> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `player_id` unique index on the table `player_clock`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`PlayerClockPlayerIdUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player_clock().player_id().find(...)`.
|
||||||
|
pub struct PlayerClockPlayerIdUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<PlayerClock, u32>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerClockTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `player_id` unique index on the table `player_clock`.
|
||||||
|
pub fn player_id(&self) -> PlayerClockPlayerIdUnique<'ctx> {
|
||||||
|
PlayerClockPlayerIdUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<u32>("player_id"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerClockPlayerIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `player_id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<PlayerClock> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
26
jong-db/src/db/player_clock_type.rs
Normal file
26
jong-db/src/db/player_clock_type.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
// 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 PlayerClock {
|
||||||
|
pub id: u32,
|
||||||
|
pub player_id: u32,
|
||||||
|
pub renewable: u16,
|
||||||
|
pub total: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl __sdk::InModule for PlayerClock {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
180
jong-db/src/db/player_hand_table.rs
Normal file
180
jong-db/src/db/player_hand_table.rs
Normal file
|
|
@ -0,0 +1,180 @@
|
||||||
|
// 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::player_hand_type::PlayerHand;
|
||||||
|
use super::turn_state_type::TurnState;
|
||||||
|
use super::db_tile_type::DbTile;
|
||||||
|
|
||||||
|
/// Table handle for the table `player_hand`.
|
||||||
|
///
|
||||||
|
/// Obtain a handle from the [`PlayerHandTableAccess::player_hand`] method on [`super::RemoteTables`],
|
||||||
|
/// like `ctx.db.player_hand()`.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player_hand().on_insert(...)`.
|
||||||
|
pub struct PlayerHandTableHandle<'ctx> {
|
||||||
|
imp: __sdk::TableHandle<PlayerHand>,
|
||||||
|
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the table `player_hand`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteTables`].
|
||||||
|
pub trait PlayerHandTableAccess {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
/// Obtain a [`PlayerHandTableHandle`], which mediates access to the table `player_hand`.
|
||||||
|
fn player_hand(&self) -> PlayerHandTableHandle<'_>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerHandTableAccess for super::RemoteTables {
|
||||||
|
fn player_hand(&self) -> PlayerHandTableHandle<'_> {
|
||||||
|
PlayerHandTableHandle {
|
||||||
|
imp: self.imp.get_table::<PlayerHand>("player_hand"),
|
||||||
|
ctx: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PlayerHandInsertCallbackId(__sdk::CallbackId);
|
||||||
|
pub struct PlayerHandDeleteCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::Table for PlayerHandTableHandle<'ctx> {
|
||||||
|
type Row = PlayerHand;
|
||||||
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
|
fn iter(&self) -> impl Iterator<Item = PlayerHand> + '_ { self.imp.iter() }
|
||||||
|
|
||||||
|
type InsertCallbackId = PlayerHandInsertCallbackId;
|
||||||
|
|
||||||
|
fn on_insert(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerHandInsertCallbackId {
|
||||||
|
PlayerHandInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_insert(&self, callback: PlayerHandInsertCallbackId) {
|
||||||
|
self.imp.remove_on_insert(callback.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteCallbackId = PlayerHandDeleteCallbackId;
|
||||||
|
|
||||||
|
fn on_delete(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerHandDeleteCallbackId {
|
||||||
|
PlayerHandDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_delete(&self, callback: PlayerHandDeleteCallbackId) {
|
||||||
|
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::<PlayerHand>("player_hand");
|
||||||
|
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||||
|
_table.add_unique_constraint::<u32>("player_id", |row| &row.player_id);
|
||||||
|
}
|
||||||
|
pub struct PlayerHandUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
impl<'ctx> __sdk::TableWithPrimaryKey for PlayerHandTableHandle<'ctx> {
|
||||||
|
type UpdateCallbackId = PlayerHandUpdateCallbackId;
|
||||||
|
|
||||||
|
fn on_update(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
|
||||||
|
) -> PlayerHandUpdateCallbackId {
|
||||||
|
PlayerHandUpdateCallbackId(self.imp.on_update(Box::new(callback)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_on_update(&self, callback: PlayerHandUpdateCallbackId) {
|
||||||
|
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<PlayerHand>> {
|
||||||
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
|
__sdk::InternalError::failed_parse(
|
||||||
|
"TableUpdate<PlayerHand>",
|
||||||
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `id` unique index on the table `player_hand`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`PlayerHandIdUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player_hand().id().find(...)`.
|
||||||
|
pub struct PlayerHandIdUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<PlayerHand, u32>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerHandTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `id` unique index on the table `player_hand`.
|
||||||
|
pub fn id(&self) -> PlayerHandIdUnique<'ctx> {
|
||||||
|
PlayerHandIdUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerHandIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<PlayerHand> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access to the `player_id` unique index on the table `player_hand`,
|
||||||
|
/// which allows point queries on the field of the same name
|
||||||
|
/// via the [`PlayerHandPlayerIdUnique::find`] method.
|
||||||
|
///
|
||||||
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
|
/// but to directly chain method calls,
|
||||||
|
/// like `ctx.db.player_hand().player_id().find(...)`.
|
||||||
|
pub struct PlayerHandPlayerIdUnique<'ctx> {
|
||||||
|
imp: __sdk::UniqueConstraintHandle<PlayerHand, u32>,
|
||||||
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerHandTableHandle<'ctx> {
|
||||||
|
/// Get a handle on the `player_id` unique index on the table `player_hand`.
|
||||||
|
pub fn player_id(&self) -> PlayerHandPlayerIdUnique<'ctx> {
|
||||||
|
PlayerHandPlayerIdUnique {
|
||||||
|
imp: self.imp.get_unique_constraint::<u32>("player_id"),
|
||||||
|
phantom: std::marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> PlayerHandPlayerIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `player_id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<PlayerHand> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
30
jong-db/src/db/player_hand_type.rs
Normal file
30
jong-db/src/db/player_hand_type.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
// 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::turn_state_type::TurnState;
|
||||||
|
use super::db_tile_type::DbTile;
|
||||||
|
|
||||||
|
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||||
|
#[sats(crate = __lib)]
|
||||||
|
pub struct PlayerHand {
|
||||||
|
pub id: u32,
|
||||||
|
pub player_id: u32,
|
||||||
|
pub turn_state: TurnState,
|
||||||
|
pub pond: Vec::<DbTile>,
|
||||||
|
pub hand: Vec::<DbTile>,
|
||||||
|
pub working_tile: Option::<DbTile>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl __sdk::InModule for PlayerHand {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,7 +2,13 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -10,8 +16,12 @@ pub enum PlayerOrBot {
|
||||||
Player(u32),
|
Player(u32),
|
||||||
|
|
||||||
Bot(u32),
|
Bot(u32),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for PlayerOrBot {
|
impl __sdk::InModule for PlayerOrBot {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,13 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
#![allow(unused, clippy::all)]
|
||||||
use super::db_tile_type::DbTile;
|
use spacetimedb_sdk::__codegen::{
|
||||||
|
self as __sdk,
|
||||||
|
__lib,
|
||||||
|
__sats,
|
||||||
|
__ws,
|
||||||
|
};
|
||||||
use super::player_type::Player;
|
use super::player_type::Player;
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
/// Table handle for the table `player`.
|
/// Table handle for the table `player`.
|
||||||
///
|
///
|
||||||
|
|
@ -45,12 +49,8 @@ impl<'ctx> __sdk::Table for PlayerTableHandle<'ctx> {
|
||||||
type Row = Player;
|
type Row = Player;
|
||||||
type EventContext = super::EventContext;
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
fn count(&self) -> u64 {
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
self.imp.count()
|
fn iter(&self) -> impl Iterator<Item = Player> + '_ { self.imp.iter() }
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = Player> + '_ {
|
|
||||||
self.imp.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
type InsertCallbackId = PlayerInsertCallbackId;
|
type InsertCallbackId = PlayerInsertCallbackId;
|
||||||
|
|
||||||
|
|
@ -81,9 +81,10 @@ impl<'ctx> __sdk::Table for PlayerTableHandle<'ctx> {
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
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);
|
let _table = client_cache.get_or_make_table::<Player>("player");
|
||||||
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||||
|
_table.add_unique_constraint::<__sdk::Identity>("identity", |row| &row.identity);
|
||||||
}
|
}
|
||||||
pub struct PlayerUpdateCallbackId(__sdk::CallbackId);
|
pub struct PlayerUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
|
@ -102,75 +103,76 @@ impl<'ctx> __sdk::TableWithPrimaryKey for PlayerTableHandle<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn parse_table_update(
|
pub(super) fn parse_table_update(
|
||||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
) -> __sdk::Result<__sdk::TableUpdate<Player>> {
|
) -> __sdk::Result<__sdk::TableUpdate<Player>> {
|
||||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
__sdk::InternalError::failed_parse("TableUpdate<Player>", "TableUpdate")
|
__sdk::InternalError::failed_parse(
|
||||||
.with_cause(e)
|
"TableUpdate<Player>",
|
||||||
.into()
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access to the `identity` unique index on the table `player`,
|
/// Access to the `id` unique index on the table `player`,
|
||||||
/// which allows point queries on the field of the same name
|
/// which allows point queries on the field of the same name
|
||||||
/// via the [`PlayerIdentityUnique::find`] method.
|
/// via the [`PlayerIdUnique::find`] method.
|
||||||
///
|
///
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
/// but to directly chain method calls,
|
/// but to directly chain method calls,
|
||||||
/// like `ctx.db.player().identity().find(...)`.
|
/// like `ctx.db.player().id().find(...)`.
|
||||||
pub struct PlayerIdentityUnique<'ctx> {
|
pub struct PlayerIdUnique<'ctx> {
|
||||||
imp: __sdk::UniqueConstraintHandle<Player, __sdk::Identity>,
|
imp: __sdk::UniqueConstraintHandle<Player, u32>,
|
||||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
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> {
|
impl<'ctx> PlayerTableHandle<'ctx> {
|
||||||
/// Find the subscribed row whose `identity` column value is equal to `col_val`,
|
/// Get a handle on the `id` unique index on the table `player`.
|
||||||
/// if such a row is present in the client cache.
|
pub fn id(&self) -> PlayerIdUnique<'ctx> {
|
||||||
pub fn find(&self, col_val: &__sdk::Identity) -> Option<Player> {
|
PlayerIdUnique {
|
||||||
self.imp.find(col_val)
|
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||||
}
|
phantom: std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/// Access to the `id` unique index on the table `player`,
|
|
||||||
/// which allows point queries on the field of the same name
|
|
||||||
/// via the [`PlayerIdUnique::find`] method.
|
|
||||||
///
|
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
|
||||||
/// but to directly chain method calls,
|
|
||||||
/// like `ctx.db.player().id().find(...)`.
|
|
||||||
pub struct PlayerIdUnique<'ctx> {
|
|
||||||
imp: __sdk::UniqueConstraintHandle<Player, u32>,
|
|
||||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> PlayerTableHandle<'ctx> {
|
|
||||||
/// Get a handle on the `id` unique index on the table `player`.
|
|
||||||
pub fn id(&self) -> PlayerIdUnique<'ctx> {
|
|
||||||
PlayerIdUnique {
|
|
||||||
imp: self.imp.get_unique_constraint::<u32>("id"),
|
|
||||||
phantom: std::marker::PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> PlayerIdUnique<'ctx> {
|
impl<'ctx> PlayerIdUnique<'ctx> {
|
||||||
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
/// if such a row is present in the client cache.
|
/// if such a row is present in the client cache.
|
||||||
pub fn find(&self, col_val: &u32) -> Option<Player> {
|
pub fn find(&self, col_val: &u32) -> Option<Player> {
|
||||||
self.imp.find(col_val)
|
self.imp.find(col_val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,24 +2,27 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
use super::db_tile_type::DbTile;
|
|
||||||
|
|
||||||
#[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 Player {
|
pub struct Player {
|
||||||
pub identity: __sdk::Identity,
|
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub name: Option<String>,
|
pub identity: __sdk::Identity,
|
||||||
|
pub name: Option::<String>,
|
||||||
pub lobby_id: u32,
|
pub lobby_id: u32,
|
||||||
pub ready: bool,
|
pub ready: bool,
|
||||||
pub sort: bool,
|
pub sort: bool,
|
||||||
pub hand: Vec<DbTile>,
|
|
||||||
pub pond: Vec<DbTile>,
|
|
||||||
pub drawn_tile: Option<DbTile>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Player {
|
impl __sdk::InModule for Player {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,13 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -10,6 +16,8 @@ pub struct Rank {
|
||||||
pub number: u8,
|
pub number: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Rank {
|
impl __sdk::InModule for Rank {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,13 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -12,8 +18,10 @@ pub(super) struct SetReadyArgs {
|
||||||
|
|
||||||
impl From<SetReadyArgs> for super::Reducer {
|
impl From<SetReadyArgs> for super::Reducer {
|
||||||
fn from(args: SetReadyArgs) -> Self {
|
fn from(args: SetReadyArgs) -> Self {
|
||||||
Self::SetReady { ready: args.ready }
|
Self::SetReady {
|
||||||
}
|
ready: args.ready,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl __sdk::InModule for SetReadyArgs {
|
impl __sdk::InModule for SetReadyArgs {
|
||||||
|
|
@ -32,7 +40,8 @@ pub trait set_ready {
|
||||||
/// 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_set_ready`] callbacks.
|
/// and its status can be observed by listening for [`Self::on_set_ready`] callbacks.
|
||||||
fn set_ready(&self, ready: bool) -> __sdk::Result<()>;
|
fn set_ready(&self, ready: bool,
|
||||||
|
) -> __sdk::Result<()>;
|
||||||
/// Register a callback to run whenever we are notified of an invocation of the reducer `set_ready`.
|
/// Register a callback to run whenever we are notified of an invocation of the reducer `set_ready`.
|
||||||
///
|
///
|
||||||
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
/// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`]
|
||||||
|
|
@ -40,39 +49,35 @@ pub trait set_ready {
|
||||||
///
|
///
|
||||||
/// The returned [`SetReadyCallbackId`] can be passed to [`Self::remove_on_set_ready`]
|
/// The returned [`SetReadyCallbackId`] can be passed to [`Self::remove_on_set_ready`]
|
||||||
/// to cancel the callback.
|
/// to cancel the callback.
|
||||||
fn on_set_ready(
|
fn on_set_ready(&self, callback: impl FnMut(&super::ReducerEventContext, &bool, ) + Send + 'static) -> SetReadyCallbackId;
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&super::ReducerEventContext, &bool) + Send + 'static,
|
|
||||||
) -> SetReadyCallbackId;
|
|
||||||
/// Cancel a callback previously registered by [`Self::on_set_ready`],
|
/// Cancel a callback previously registered by [`Self::on_set_ready`],
|
||||||
/// causing it not to run in the future.
|
/// causing it not to run in the future.
|
||||||
fn remove_on_set_ready(&self, callback: SetReadyCallbackId);
|
fn remove_on_set_ready(&self, callback: SetReadyCallbackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl set_ready for super::RemoteReducers {
|
impl set_ready for super::RemoteReducers {
|
||||||
fn set_ready(&self, ready: bool) -> __sdk::Result<()> {
|
fn set_ready(&self, ready: bool,
|
||||||
self.imp.call_reducer("set_ready", SetReadyArgs { ready })
|
) -> __sdk::Result<()> {
|
||||||
|
self.imp.call_reducer("set_ready", SetReadyArgs { ready, })
|
||||||
}
|
}
|
||||||
fn on_set_ready(
|
fn on_set_ready(
|
||||||
&self,
|
&self,
|
||||||
mut callback: impl FnMut(&super::ReducerEventContext, &bool) + Send + 'static,
|
mut callback: impl FnMut(&super::ReducerEventContext, &bool, ) + Send + 'static,
|
||||||
) -> SetReadyCallbackId {
|
) -> SetReadyCallbackId {
|
||||||
SetReadyCallbackId(self.imp.on_reducer(
|
SetReadyCallbackId(self.imp.on_reducer(
|
||||||
"set_ready",
|
"set_ready",
|
||||||
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::SetReady {
|
||||||
reducer: super::Reducer::SetReady { ready },
|
ready,
|
||||||
..
|
|
||||||
},
|
},
|
||||||
|
..
|
||||||
|
},
|
||||||
..
|
..
|
||||||
} = ctx
|
} = ctx else { unreachable!() };
|
||||||
else {
|
callback(ctx, ready, )
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
callback(ctx, ready)
|
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -100,3 +105,4 @@ impl set_flags_for_set_ready for super::SetReducerFlags {
|
||||||
self.imp.set_call_reducer_flags("set_ready", flags);
|
self.imp.set_call_reducer_flags("set_ready", flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,16 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
use super::dragon_type::Dragon;
|
|
||||||
use super::rank_type::Rank;
|
use super::rank_type::Rank;
|
||||||
use super::wind_type::Wind;
|
use super::wind_type::Wind;
|
||||||
|
use super::dragon_type::Dragon;
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -20,8 +25,12 @@ pub enum Suit {
|
||||||
Wind(Wind),
|
Wind(Wind),
|
||||||
|
|
||||||
Dragon(Dragon),
|
Dragon(Dragon),
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Suit {
|
impl __sdk::InModule for Suit {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,14 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
#![allow(unused, clippy::all)]
|
||||||
|
use spacetimedb_sdk::__codegen::{
|
||||||
|
self as __sdk,
|
||||||
|
__lib,
|
||||||
|
__sats,
|
||||||
|
__ws,
|
||||||
|
};
|
||||||
use super::db_tile_type::DbTile;
|
use super::db_tile_type::DbTile;
|
||||||
use super::tile_type::Tile;
|
use super::tile_type::Tile;
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
/// Table handle for the table `tile`.
|
/// Table handle for the table `tile`.
|
||||||
///
|
///
|
||||||
|
|
@ -45,12 +50,8 @@ impl<'ctx> __sdk::Table for TileTableHandle<'ctx> {
|
||||||
type Row = DbTile;
|
type Row = DbTile;
|
||||||
type EventContext = super::EventContext;
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
fn count(&self) -> u64 {
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
self.imp.count()
|
fn iter(&self) -> impl Iterator<Item = DbTile> + '_ { self.imp.iter() }
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = DbTile> + '_ {
|
|
||||||
self.imp.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
type InsertCallbackId = TileInsertCallbackId;
|
type InsertCallbackId = TileInsertCallbackId;
|
||||||
|
|
||||||
|
|
@ -81,7 +82,8 @@ impl<'ctx> __sdk::Table for TileTableHandle<'ctx> {
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||||
let _table = client_cache.get_or_make_table::<DbTile>("tile");
|
|
||||||
|
let _table = client_cache.get_or_make_table::<DbTile>("tile");
|
||||||
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||||
}
|
}
|
||||||
pub struct TileUpdateCallbackId(__sdk::CallbackId);
|
pub struct TileUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
@ -101,43 +103,46 @@ impl<'ctx> __sdk::TableWithPrimaryKey for TileTableHandle<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn parse_table_update(
|
pub(super) fn parse_table_update(
|
||||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
) -> __sdk::Result<__sdk::TableUpdate<DbTile>> {
|
) -> __sdk::Result<__sdk::TableUpdate<DbTile>> {
|
||||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
__sdk::InternalError::failed_parse("TableUpdate<DbTile>", "TableUpdate")
|
__sdk::InternalError::failed_parse(
|
||||||
.with_cause(e)
|
"TableUpdate<DbTile>",
|
||||||
.into()
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access to the `id` unique index on the table `tile`,
|
/// Access to the `id` unique index on the table `tile`,
|
||||||
/// which allows point queries on the field of the same name
|
/// which allows point queries on the field of the same name
|
||||||
/// via the [`TileIdUnique::find`] method.
|
/// via the [`TileIdUnique::find`] method.
|
||||||
///
|
///
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
/// but to directly chain method calls,
|
/// but to directly chain method calls,
|
||||||
/// like `ctx.db.tile().id().find(...)`.
|
/// like `ctx.db.tile().id().find(...)`.
|
||||||
pub struct TileIdUnique<'ctx> {
|
pub struct TileIdUnique<'ctx> {
|
||||||
imp: __sdk::UniqueConstraintHandle<DbTile, u32>,
|
imp: __sdk::UniqueConstraintHandle<DbTile, u32>,
|
||||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> TileTableHandle<'ctx> {
|
|
||||||
/// Get a handle on the `id` unique index on the table `tile`.
|
|
||||||
pub fn id(&self) -> TileIdUnique<'ctx> {
|
|
||||||
TileIdUnique {
|
|
||||||
imp: self.imp.get_unique_constraint::<u32>("id"),
|
|
||||||
phantom: std::marker::PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> TileIdUnique<'ctx> {
|
impl<'ctx> TileTableHandle<'ctx> {
|
||||||
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
/// Get a handle on the `id` unique index on the table `tile`.
|
||||||
/// if such a row is present in the client cache.
|
pub fn id(&self) -> TileIdUnique<'ctx> {
|
||||||
pub fn find(&self, col_val: &u32) -> Option<DbTile> {
|
TileIdUnique {
|
||||||
self.imp.find(col_val)
|
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||||
}
|
phantom: std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> TileIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<DbTile> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
use super::suit_type::Suit;
|
use super::suit_type::Suit;
|
||||||
|
|
||||||
|
|
@ -12,6 +17,8 @@ pub struct Tile {
|
||||||
pub suit: Suit,
|
pub suit: Suit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Tile {
|
impl __sdk::InModule for Tile {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -19,8 +24,12 @@ pub enum TurnState {
|
||||||
RonChiiPonKan,
|
RonChiiPonKan,
|
||||||
|
|
||||||
End,
|
End,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for TurnState {
|
impl __sdk::InModule for TurnState {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,14 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
#![allow(unused, clippy::all)]
|
||||||
use super::db_tile_type::DbTile;
|
use spacetimedb_sdk::__codegen::{
|
||||||
|
self as __sdk,
|
||||||
|
__lib,
|
||||||
|
__sats,
|
||||||
|
__ws,
|
||||||
|
};
|
||||||
use super::db_wall_type::DbWall;
|
use super::db_wall_type::DbWall;
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
use super::db_tile_type::DbTile;
|
||||||
|
|
||||||
/// Table handle for the table `wall`.
|
/// Table handle for the table `wall`.
|
||||||
///
|
///
|
||||||
|
|
@ -45,12 +50,8 @@ impl<'ctx> __sdk::Table for WallTableHandle<'ctx> {
|
||||||
type Row = DbWall;
|
type Row = DbWall;
|
||||||
type EventContext = super::EventContext;
|
type EventContext = super::EventContext;
|
||||||
|
|
||||||
fn count(&self) -> u64 {
|
fn count(&self) -> u64 { self.imp.count() }
|
||||||
self.imp.count()
|
fn iter(&self) -> impl Iterator<Item = DbWall> + '_ { self.imp.iter() }
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = DbWall> + '_ {
|
|
||||||
self.imp.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
type InsertCallbackId = WallInsertCallbackId;
|
type InsertCallbackId = WallInsertCallbackId;
|
||||||
|
|
||||||
|
|
@ -81,7 +82,8 @@ impl<'ctx> __sdk::Table for WallTableHandle<'ctx> {
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||||
let _table = client_cache.get_or_make_table::<DbWall>("wall");
|
|
||||||
|
let _table = client_cache.get_or_make_table::<DbWall>("wall");
|
||||||
_table.add_unique_constraint::<u32>("lobby_id", |row| &row.lobby_id);
|
_table.add_unique_constraint::<u32>("lobby_id", |row| &row.lobby_id);
|
||||||
}
|
}
|
||||||
pub struct WallUpdateCallbackId(__sdk::CallbackId);
|
pub struct WallUpdateCallbackId(__sdk::CallbackId);
|
||||||
|
|
@ -101,43 +103,46 @@ impl<'ctx> __sdk::TableWithPrimaryKey for WallTableHandle<'ctx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub(super) fn parse_table_update(
|
pub(super) fn parse_table_update(
|
||||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||||
) -> __sdk::Result<__sdk::TableUpdate<DbWall>> {
|
) -> __sdk::Result<__sdk::TableUpdate<DbWall>> {
|
||||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||||
__sdk::InternalError::failed_parse("TableUpdate<DbWall>", "TableUpdate")
|
__sdk::InternalError::failed_parse(
|
||||||
.with_cause(e)
|
"TableUpdate<DbWall>",
|
||||||
.into()
|
"TableUpdate",
|
||||||
|
).with_cause(e).into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access to the `lobby_id` unique index on the table `wall`,
|
/// Access to the `lobby_id` unique index on the table `wall`,
|
||||||
/// which allows point queries on the field of the same name
|
/// which allows point queries on the field of the same name
|
||||||
/// via the [`WallLobbyIdUnique::find`] method.
|
/// via the [`WallLobbyIdUnique::find`] method.
|
||||||
///
|
///
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
/// Users are encouraged not to explicitly reference this type,
|
||||||
/// but to directly chain method calls,
|
/// but to directly chain method calls,
|
||||||
/// like `ctx.db.wall().lobby_id().find(...)`.
|
/// like `ctx.db.wall().lobby_id().find(...)`.
|
||||||
pub struct WallLobbyIdUnique<'ctx> {
|
pub struct WallLobbyIdUnique<'ctx> {
|
||||||
imp: __sdk::UniqueConstraintHandle<DbWall, u32>,
|
imp: __sdk::UniqueConstraintHandle<DbWall, u32>,
|
||||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> WallTableHandle<'ctx> {
|
|
||||||
/// Get a handle on the `lobby_id` unique index on the table `wall`.
|
|
||||||
pub fn lobby_id(&self) -> WallLobbyIdUnique<'ctx> {
|
|
||||||
WallLobbyIdUnique {
|
|
||||||
imp: self.imp.get_unique_constraint::<u32>("lobby_id"),
|
|
||||||
phantom: std::marker::PhantomData,
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'ctx> WallLobbyIdUnique<'ctx> {
|
impl<'ctx> WallTableHandle<'ctx> {
|
||||||
/// Find the subscribed row whose `lobby_id` column value is equal to `col_val`,
|
/// Get a handle on the `lobby_id` unique index on the table `wall`.
|
||||||
/// if such a row is present in the client cache.
|
pub fn lobby_id(&self) -> WallLobbyIdUnique<'ctx> {
|
||||||
pub fn find(&self, col_val: &u32) -> Option<DbWall> {
|
WallLobbyIdUnique {
|
||||||
self.imp.find(col_val)
|
imp: self.imp.get_unique_constraint::<u32>("lobby_id"),
|
||||||
}
|
phantom: std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'ctx> WallLobbyIdUnique<'ctx> {
|
||||||
|
/// Find the subscribed row whose `lobby_id` column value is equal to `col_val`,
|
||||||
|
/// if such a row is present in the client cache.
|
||||||
|
pub fn find(&self, col_val: &u32) -> Option<DbWall> {
|
||||||
|
self.imp.find(col_val)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -2,7 +2,12 @@
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||||
|
|
||||||
#![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,
|
||||||
|
};
|
||||||
|
|
||||||
#[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)]
|
||||||
|
|
@ -15,8 +20,12 @@ pub enum Wind {
|
||||||
Shaa,
|
Shaa,
|
||||||
|
|
||||||
Pei,
|
Pei,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl __sdk::InModule for Wind {
|
impl __sdk::InModule for Wind {
|
||||||
type Module = super::RemoteModule;
|
type Module = super::RemoteModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,9 @@
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use spacetimedb::{ReducerContext, Table, reducer};
|
use spacetimedb::{ReducerContext, Table, reducer};
|
||||||
|
|
||||||
use jong_types::TurnState;
|
|
||||||
|
|
||||||
use crate::tables::*;
|
use crate::tables::*;
|
||||||
|
|
||||||
mod reducers {
|
mod reducers;
|
||||||
mod deal;
|
|
||||||
mod hand;
|
|
||||||
mod lobby;
|
|
||||||
}
|
|
||||||
mod tables;
|
mod tables;
|
||||||
|
|
||||||
#[reducer]
|
#[reducer]
|
||||||
|
|
@ -32,27 +26,40 @@ pub fn clear_all(ctx: &ReducerContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[reducer(client_connected)]
|
#[reducer(client_connected)]
|
||||||
pub fn login_or_add_player(ctx: &ReducerContext) {
|
pub fn connect(ctx: &ReducerContext) -> Result<(), String> {
|
||||||
let identity = ctx.sender;
|
let player = if let Some(player) = ctx.db.logged_out_player().identity().find(ctx.sender) {
|
||||||
|
let player = ctx.db.player().insert(player);
|
||||||
// TODO remove player on disconnect
|
ctx.db.logged_out_player().identity().delete(ctx.sender);
|
||||||
if let Ok(player) = ctx.db.player().try_insert(Player {
|
player
|
||||||
identity,
|
|
||||||
id: 0,
|
|
||||||
name: None,
|
|
||||||
lobby_id: 0,
|
|
||||||
ready: false,
|
|
||||||
sort: true,
|
|
||||||
hand: vec![],
|
|
||||||
pond: vec![],
|
|
||||||
drawn_tile: None,
|
|
||||||
turn_state: TurnState::None,
|
|
||||||
}) {
|
|
||||||
debug!("added player: {:?}", player);
|
|
||||||
} else {
|
} else {
|
||||||
let player = ctx.db.player().identity().find(identity).unwrap();
|
ctx.db.player().try_insert(Player {
|
||||||
debug!("player {:?} has reconnected", player)
|
identity: ctx.sender,
|
||||||
}
|
id: 0,
|
||||||
|
name: None,
|
||||||
|
lobby_id: 0,
|
||||||
|
ready: false,
|
||||||
|
sort: true,
|
||||||
|
})?
|
||||||
|
};
|
||||||
|
|
||||||
|
debug!("player connected: {:?}", player);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[reducer(client_disconnected)]
|
||||||
|
pub fn disconnect(ctx: &ReducerContext) -> Result<(), String> {
|
||||||
|
let player = ctx
|
||||||
|
.db
|
||||||
|
.player()
|
||||||
|
.identity()
|
||||||
|
.find(ctx.sender)
|
||||||
|
.ok_or_else(|| format!("can't find player {}", ctx.sender))?;
|
||||||
|
|
||||||
|
ctx.db.logged_out_player().insert(player);
|
||||||
|
ctx.db.player().identity().delete(ctx.sender);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[reducer(init)]
|
// #[reducer(init)]
|
||||||
|
|
@ -65,11 +72,6 @@ pub fn login_or_add_player(ctx: &ReducerContext) {
|
||||||
// // Called everytime a new client connects
|
// // 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 });
|
||||||
|
|
|
||||||
118
jong-line/src/reducers.rs
Normal file
118
jong-line/src/reducers.rs
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use spacetimedb::{ReducerContext, ScheduleAt::Interval, reducer};
|
||||||
|
|
||||||
|
use jong_types::{GameState, TurnState};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
reducers::deal::shuffle_deal,
|
||||||
|
tables::{
|
||||||
|
GameTimer, PlayerClock, PlayerOrBot, bot, game_timer, lobby as _, player_clock,
|
||||||
|
player_hand, wall,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
mod deal;
|
||||||
|
mod hand;
|
||||||
|
mod lobby;
|
||||||
|
|
||||||
|
#[reducer]
|
||||||
|
pub fn advance_game(ctx: &ReducerContext, mut game_timer: GameTimer) -> Result<(), String> {
|
||||||
|
// checks every second (or more? when users make moves) on whether to advance the game's various states
|
||||||
|
// TODO this, or allow player/debug to call this?
|
||||||
|
if !ctx.sender_auth().is_internal() {
|
||||||
|
return Err("This reducer can only be called by the scheduler".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(mut lobby) = ctx.db.lobby().id().find(game_timer.lobby_id) {
|
||||||
|
match lobby.game_state {
|
||||||
|
GameState::Setup => {
|
||||||
|
// TODO reduce interval beforehand so we don't wait a second?
|
||||||
|
// TODO keep a count to clear stale lobbies
|
||||||
|
lobby.game_state = GameState::Deal;
|
||||||
|
}
|
||||||
|
GameState::Deal => {
|
||||||
|
// TODO reduce interval beforehand so this can animate?
|
||||||
|
shuffle_deal(ctx, lobby.id);
|
||||||
|
}
|
||||||
|
GameState::Play => {
|
||||||
|
let curr_player = lobby.players.get(lobby.current_idx as usize).unwrap();
|
||||||
|
match curr_player {
|
||||||
|
PlayerOrBot::Player { id: player_id } => {
|
||||||
|
let mut clock = ctx.db.player_clock().player_id().find(player_id).unwrap();
|
||||||
|
let mut hand = ctx.db.player_hand().player_id().find(player_id).unwrap();
|
||||||
|
match hand.turn_state {
|
||||||
|
TurnState::None => {
|
||||||
|
// TODO draw tile
|
||||||
|
if let Some(mut wall) = ctx.db.wall().lobby_id().find(lobby.id)
|
||||||
|
&& let Some(tile) = wall.tiles.pop()
|
||||||
|
{
|
||||||
|
hand.working_tile = Some(tile);
|
||||||
|
hand.turn_state = TurnState::Tsumo;
|
||||||
|
ctx.db.wall().lobby_id().update(wall);
|
||||||
|
ctx.db.player_hand().id().update(hand);
|
||||||
|
} else {
|
||||||
|
// TODO out of tiles
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TurnState::Tsumo => {
|
||||||
|
if clock.tick() {
|
||||||
|
ctx.db.player_clock().id().update(clock);
|
||||||
|
} else {
|
||||||
|
// TODO auto-discard
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TurnState::Menzen => {}
|
||||||
|
TurnState::RiichiKan => {}
|
||||||
|
TurnState::RonChiiPonKan => {}
|
||||||
|
TurnState::End => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PlayerOrBot::Bot { id: bot_id } => {
|
||||||
|
let b = ctx.db.bot().id().find(bot_id).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GameState::Exit => {
|
||||||
|
ctx.db.game_timer().id().delete(game_timer.id);
|
||||||
|
ctx.db.lobby().id().delete(lobby.id);
|
||||||
|
// TODO reset all player lobbies, delete bots, etc?
|
||||||
|
// is there a way to do this automatically, or rely on elsewhere's checks clearing the state?
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO handle stale lobbies
|
||||||
|
// TODO should this delete the timer?
|
||||||
|
_ => Err(format!("lobby {} in impossible state", lobby.id))?,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.db.game_timer().id().update(game_timer);
|
||||||
|
} else {
|
||||||
|
ctx.db.game_timer().id().delete(game_timer.id);
|
||||||
|
Err(format!(
|
||||||
|
"ran schedule {} for empty lobby {}",
|
||||||
|
game_timer.id, game_timer.lobby_id
|
||||||
|
))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerClock {
|
||||||
|
fn tick(&mut self) -> bool {
|
||||||
|
if self.renewable > 0 {
|
||||||
|
self.renewable -= 1;
|
||||||
|
true
|
||||||
|
} else if self.total > 0 {
|
||||||
|
self.total -= 1;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn renew(&mut self) {
|
||||||
|
self.renewable = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,18 +1,13 @@
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
||||||
|
|
||||||
use super::hand::deal_hands;
|
|
||||||
use crate::tables::*;
|
use crate::tables::*;
|
||||||
|
|
||||||
#[reducer]
|
|
||||||
pub fn shuffle_deal(ctx: &ReducerContext, lobby_id: u32) {
|
pub fn shuffle_deal(ctx: &ReducerContext, lobby_id: u32) {
|
||||||
debug!("lobby_id: {lobby_id}");
|
debug!("lobby_id: {lobby_id}");
|
||||||
let mut lobby = ctx.db.lobby().id().find(lobby_id).unwrap();
|
let mut lobby = ctx.db.lobby().id().find(lobby_id).unwrap();
|
||||||
|
|
||||||
if lobby.game_state == jong_types::states::GameState::Setup {
|
if lobby.game_state == jong_types::states::GameState::Deal {
|
||||||
lobby.game_state = jong_types::states::GameState::Deal;
|
|
||||||
lobby = ctx.db.lobby().id().update(lobby);
|
|
||||||
|
|
||||||
let tiles = new_shuffled_wall(ctx);
|
let tiles = new_shuffled_wall(ctx);
|
||||||
|
|
||||||
ctx.db.wall().insert(DbWall {
|
ctx.db.wall().insert(DbWall {
|
||||||
|
|
@ -24,7 +19,6 @@ pub fn shuffle_deal(ctx: &ReducerContext, lobby_id: u32) {
|
||||||
deal_hands(ctx, lobby_id);
|
deal_hands(ctx, lobby_id);
|
||||||
|
|
||||||
lobby.game_state = jong_types::states::GameState::Play;
|
lobby.game_state = jong_types::states::GameState::Play;
|
||||||
lobby.turn_state = jong_types::states::TurnState::Tsumo;
|
|
||||||
ctx.db.lobby().id().update(lobby);
|
ctx.db.lobby().id().update(lobby);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -39,3 +33,32 @@ pub fn new_shuffled_wall(ctx: &ReducerContext) -> Vec<DbTile> {
|
||||||
|
|
||||||
wall
|
wall
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deal_hands(ctx: &ReducerContext, lobby_id: u32) {
|
||||||
|
let players = ctx.db.player().lobby_id().filter(lobby_id);
|
||||||
|
let bots = ctx.db.bot().lobby_id().filter(lobby_id);
|
||||||
|
|
||||||
|
let mut wall = ctx.db.wall().lobby_id().find(lobby_id).unwrap();
|
||||||
|
|
||||||
|
// FIXME rectify deal orders
|
||||||
|
for player in players {
|
||||||
|
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
|
||||||
|
wall = ctx.db.wall().lobby_id().update(wall);
|
||||||
|
tiles.sort_by_key(|t| t.tile);
|
||||||
|
ctx.db.player_hand().insert(PlayerHand {
|
||||||
|
id: 0,
|
||||||
|
player_id: player.id,
|
||||||
|
turn_state: jong_types::TurnState::None,
|
||||||
|
pond: vec![],
|
||||||
|
hand: tiles,
|
||||||
|
working_tile: None,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for mut bot in bots {
|
||||||
|
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
|
||||||
|
wall = ctx.db.wall().lobby_id().update(wall);
|
||||||
|
tiles.sort_by_key(|t| t.tile);
|
||||||
|
bot.hand = tiles;
|
||||||
|
ctx.db.bot().id().update(bot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,66 +1,27 @@
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
use spacetimedb::{ReducerContext, reducer};
|
use spacetimedb::{ReducerContext, reducer};
|
||||||
|
|
||||||
use crate::tables::{player::player, *};
|
|
||||||
use jong_types::states::TurnState;
|
use jong_types::states::TurnState;
|
||||||
|
|
||||||
pub fn deal_hands(ctx: &ReducerContext, lobby_id: u32) {
|
use crate::tables::*;
|
||||||
let players = ctx.db.player().lobby_id().filter(lobby_id);
|
|
||||||
let bots = ctx.db.bot().lobby_id().filter(lobby_id);
|
|
||||||
|
|
||||||
let mut wall = ctx.db.wall().lobby_id().find(lobby_id).unwrap();
|
|
||||||
|
|
||||||
// FIXME rectify deal orders
|
|
||||||
for mut player in players {
|
|
||||||
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
|
|
||||||
wall = ctx.db.wall().lobby_id().update(wall);
|
|
||||||
tiles.sort_by_key(|t| t.tile);
|
|
||||||
player.hand = tiles;
|
|
||||||
ctx.db.player().id().update(player);
|
|
||||||
}
|
|
||||||
for mut bot in bots {
|
|
||||||
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
|
|
||||||
wall = ctx.db.wall().lobby_id().update(wall);
|
|
||||||
tiles.sort_by_key(|t| t.tile);
|
|
||||||
bot.hand = tiles;
|
|
||||||
ctx.db.bot().id().update(bot);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[reducer]
|
|
||||||
pub fn draw_tile(ctx: &ReducerContext) {
|
|
||||||
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
|
||||||
let mut wall = ctx.db.wall().lobby_id().find(player.lobby_id).unwrap();
|
|
||||||
|
|
||||||
// TODO if no more tiles, exhaust somehow
|
|
||||||
|
|
||||||
player.drawn_tile = wall.tiles.pop();
|
|
||||||
|
|
||||||
ctx.db.wall().lobby_id().update(wall);
|
|
||||||
ctx.db.player().id().update(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO make sure this can't be called or just error here?
|
// TODO make sure this can't be called or just error here?
|
||||||
#[reducer]
|
#[reducer]
|
||||||
pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> {
|
pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> {
|
||||||
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
let player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
||||||
let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
|
let mut hand = ctx.db.player_hand().player_id().find(player.id).unwrap();
|
||||||
|
|
||||||
let dealt_tile = if let Some(dealt) = ctx.db.tile().id().find(tile_id) {
|
let dealt_tile = if let Some(dealt) = ctx.db.tile().id().find(tile_id) {
|
||||||
if let Some(drawn) = player.drawn_tile {
|
if let Some(drawn) = hand.working_tile {
|
||||||
if drawn.id == dealt.id {
|
if drawn.id == dealt.id {
|
||||||
// dealt from drawn tile
|
// dealt from drawn tile
|
||||||
dealt
|
dealt
|
||||||
} else if let Some((i, _)) = player
|
} else if let Some((i, _)) = hand.hand.iter().enumerate().find(|(_, t)| t.id == tile_id)
|
||||||
.hand
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.find(|(_, t)| t.id == tile_id)
|
|
||||||
{
|
{
|
||||||
// dealt from hand
|
// dealt from hand
|
||||||
let dealt = player.hand.remove(i);
|
let dealt = hand.hand.remove(i);
|
||||||
player.hand.push(drawn);
|
hand.hand.push(drawn);
|
||||||
player.hand.sort_by_key(|t| t.tile);
|
hand.hand.sort_by_key(|t| t.tile);
|
||||||
|
|
||||||
dealt
|
dealt
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -82,54 +43,53 @@ pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> {
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
player.pond.push(dealt_tile);
|
hand.pond.push(dealt_tile);
|
||||||
player.drawn_tile = None;
|
hand.working_tile = None;
|
||||||
lobby.turn_state = TurnState::RonChiiPonKan;
|
hand.turn_state = TurnState::None;
|
||||||
|
|
||||||
let player = ctx.db.player().id().update(player);
|
ctx.db.player_hand().id().update(hand);
|
||||||
ctx.db.lobby().id().update(lobby);
|
|
||||||
|
|
||||||
debug!("player {} discarded tile {:?}", player.id, dealt_tile.tile);
|
debug!("player {} discarded tile {:?}", player.id, dealt_tile.tile);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[reducer]
|
// #[reducer]
|
||||||
pub fn skip_call(ctx: &ReducerContext) {
|
// pub fn skip_call(ctx: &ReducerContext) {
|
||||||
trace!("skip_call");
|
// trace!("skip_call");
|
||||||
|
|
||||||
let player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
// let player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
||||||
let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
|
// let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
|
||||||
|
|
||||||
lobby.turn_state = TurnState::Tsumo;
|
// lobby.turn_state = TurnState::Tsumo;
|
||||||
lobby.current_idx += 1;
|
// lobby.current_idx += 1;
|
||||||
if lobby.current_idx >= 3 {
|
// if lobby.current_idx >= 3 {
|
||||||
lobby.current_idx = 0;
|
// lobby.current_idx = 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// FIXME where better can this go
|
// // FIXME where better can this go
|
||||||
bot_moves(ctx, &mut lobby);
|
// bot_moves(ctx, &mut lobby);
|
||||||
|
|
||||||
ctx.db.player().id().update(player);
|
// ctx.db.player().id().update(player);
|
||||||
ctx.db.lobby().id().update(lobby);
|
// ctx.db.lobby().id().update(lobby);
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn bot_moves(ctx: &ReducerContext, lobby: &mut Lobby) {
|
// fn bot_moves(ctx: &ReducerContext, lobby: &mut Lobby) {
|
||||||
let mut wall = ctx.db.wall().lobby_id().find(lobby.id).unwrap();
|
// let mut wall = ctx.db.wall().lobby_id().find(lobby.id).unwrap();
|
||||||
if let Some(PlayerOrBot::Bot { id }) = lobby.players.get(lobby.current_idx as usize + 1) {
|
// if let Some(PlayerOrBot::Bot { id }) = lobby.players.get(lobby.current_idx as usize + 1) {
|
||||||
let mut bot = ctx.db.bot().id().find(id).unwrap();
|
// let mut bot = ctx.db.bot().id().find(id).unwrap();
|
||||||
bot.pond.push(wall.tiles.pop().unwrap());
|
// bot.pond.push(wall.tiles.pop().unwrap());
|
||||||
ctx.db.bot().id().update(bot);
|
// ctx.db.bot().id().update(bot);
|
||||||
lobby.turn_state = TurnState::RonChiiPonKan;
|
// lobby.turn_state = TurnState::RonChiiPonKan;
|
||||||
} else {
|
// } else {
|
||||||
lobby.turn_state = TurnState::Tsumo;
|
// lobby.turn_state = TurnState::Tsumo;
|
||||||
}
|
// }
|
||||||
|
|
||||||
lobby.current_idx += 1;
|
// lobby.current_idx += 1;
|
||||||
if lobby.current_idx >= 3 {
|
// if lobby.current_idx >= 3 {
|
||||||
lobby.current_idx = 0;
|
// lobby.current_idx = 0;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// #[view(name = view_player_hand, public)]
|
// #[view(name = view_player_hand, public)]
|
||||||
// pub fn view_player_hand(ctx: &ViewContext) -> Option<Hand> {
|
// pub fn view_player_hand(ctx: &ViewContext) -> Option<Hand> {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
||||||
|
|
||||||
|
|
@ -5,18 +7,16 @@ use crate::tables::*;
|
||||||
|
|
||||||
#[reducer]
|
#[reducer]
|
||||||
pub fn join_or_create_lobby(ctx: &ReducerContext, mut lobby_id: u32) -> Result<(), String> {
|
pub fn join_or_create_lobby(ctx: &ReducerContext, mut lobby_id: u32) -> Result<(), String> {
|
||||||
let ok_or = ctx
|
let mut player = ctx
|
||||||
.db
|
.db
|
||||||
.player()
|
.player()
|
||||||
.identity()
|
.identity()
|
||||||
.find(ctx.sender)
|
.find(ctx.sender)
|
||||||
.ok_or(format!("cannot find player {}", ctx.sender))?;
|
.ok_or(format!("cannot find player {}", ctx.sender))?;
|
||||||
let mut player = ok_or;
|
|
||||||
|
|
||||||
if lobby_id == 0 {
|
if lobby_id == 0 {
|
||||||
let lobby = ctx.db.lobby().insert(Lobby {
|
let lobby = ctx.db.lobby().insert(Lobby {
|
||||||
id: 0,
|
id: 0,
|
||||||
host_player_id: player.id,
|
|
||||||
players: vec![PlayerOrBot::Player { id: player.id }],
|
players: vec![PlayerOrBot::Player { id: player.id }],
|
||||||
game_state: jong_types::states::GameState::Lobby,
|
game_state: jong_types::states::GameState::Lobby,
|
||||||
dealer_idx: 0,
|
dealer_idx: 0,
|
||||||
|
|
@ -49,7 +49,8 @@ pub fn add_bot(ctx: &ReducerContext, lobby_id: u32) -> Result<(), String> {
|
||||||
lobby_id,
|
lobby_id,
|
||||||
hand: vec![],
|
hand: vec![],
|
||||||
pond: vec![],
|
pond: vec![],
|
||||||
drawn_tile: None,
|
working_tile: None,
|
||||||
|
turn_state: jong_types::TurnState::None,
|
||||||
});
|
});
|
||||||
lobby.players.push(PlayerOrBot::Bot { id: bot.id });
|
lobby.players.push(PlayerOrBot::Bot { id: bot.id });
|
||||||
ctx.db.lobby().id().update(lobby);
|
ctx.db.lobby().id().update(lobby);
|
||||||
|
|
@ -61,29 +62,33 @@ pub fn add_bot(ctx: &ReducerContext, lobby_id: u32) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[reducer]
|
#[reducer]
|
||||||
pub fn set_ready(ctx: &ReducerContext, ready: bool) {
|
pub fn set_ready(ctx: &ReducerContext, ready: bool) -> Result<(), String> {
|
||||||
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
let mut player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
||||||
player.ready = ready;
|
player.ready = ready;
|
||||||
|
player = ctx.db.player().identity().update(player);
|
||||||
|
|
||||||
ctx.db.player().identity().update(player);
|
if let Some(mut lobby) = ctx.db.lobby().id().find(player.lobby_id)
|
||||||
}
|
|
||||||
|
|
||||||
#[reducer]
|
|
||||||
pub fn start_game(ctx: &ReducerContext) {
|
|
||||||
let player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
|
||||||
if let Some(mut lobby) = ctx.db.lobby().host_player_id().find(player.id)
|
|
||||||
&& lobby.players.len() == 4
|
&& lobby.players.len() == 4
|
||||||
&& lobby.players.iter().all(|p| match p {
|
&& ctx.db.player().lobby_id().filter(lobby.id).all(|p| p.ready)
|
||||||
PlayerOrBot::Player { id } => ctx.db.player().id().find(id).is_some_and(|p| p.ready),
|
|
||||||
PlayerOrBot::Bot { id } => ctx.db.bot().id().find(id).is_some(),
|
|
||||||
})
|
|
||||||
{
|
{
|
||||||
lobby.game_state = jong_types::states::GameState::Setup;
|
lobby.game_state = jong_types::states::GameState::Setup;
|
||||||
lobby.players.shuffle(&mut ctx.rng());
|
lobby.players.shuffle(&mut ctx.rng());
|
||||||
lobby.dealer_idx += 1;
|
let lobby = ctx.db.lobby().id().update(lobby);
|
||||||
if lobby.dealer_idx > 3 {
|
|
||||||
lobby.dealer_idx = 0;
|
// TODO should we schedule this outside so that we can clear out stale lobbies?
|
||||||
}
|
ctx.db.game_timer().insert(GameTimer {
|
||||||
ctx.db.lobby().id().update(lobby);
|
id: 0,
|
||||||
|
lobby_id: lobby.id,
|
||||||
|
scheduled_at: spacetimedb::ScheduleAt::Interval(Duration::from_secs(1).into()),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// if lobby doesn't exist, reset player state
|
||||||
|
player.lobby_id = 0;
|
||||||
|
player.ready = false;
|
||||||
|
player = ctx.db.player().identity().update(player);
|
||||||
|
|
||||||
|
return Err(format!("couldn't find lobby with id: {}", player.lobby_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use spacetimedb::{SpacetimeType, table};
|
use spacetimedb::{SpacetimeType, table};
|
||||||
|
|
||||||
use jong_types::{
|
use jong_types::{
|
||||||
|
|
@ -5,6 +7,8 @@ use jong_types::{
|
||||||
tiles::Tile,
|
tiles::Tile,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::reducers::advance_game;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[table(name = lobby, public)]
|
#[table(name = lobby, public)]
|
||||||
pub struct Lobby {
|
pub struct Lobby {
|
||||||
|
|
@ -12,8 +16,6 @@ pub struct Lobby {
|
||||||
#[auto_inc]
|
#[auto_inc]
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
|
|
||||||
#[unique]
|
|
||||||
pub host_player_id: u32,
|
|
||||||
pub players: Vec<PlayerOrBot>,
|
pub players: Vec<PlayerOrBot>,
|
||||||
pub dealer_idx: u8,
|
pub dealer_idx: u8,
|
||||||
pub current_idx: u8,
|
pub current_idx: u8,
|
||||||
|
|
@ -45,41 +47,55 @@ pub enum PlayerOrBot {
|
||||||
Bot { id: u32 },
|
Bot { id: u32 },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[table(name = advance_state_timer)]
|
|
||||||
pub struct AdvanceStateTimer {
|
|
||||||
#[primary_key]
|
|
||||||
#[auto_inc]
|
|
||||||
scheduled_id: u64,
|
|
||||||
scheduled_at: spacetimedb::ScheduleAt,
|
|
||||||
|
|
||||||
lobby_id: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME this shant be public, use views
|
// FIXME this shant be public, use views
|
||||||
#[table(name = player, public)]
|
#[table(name = player, public)]
|
||||||
|
#[table(name = logged_out_player)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
#[primary_key]
|
|
||||||
pub identity: spacetimedb::Identity,
|
|
||||||
|
|
||||||
#[unique]
|
#[unique]
|
||||||
#[auto_inc]
|
#[auto_inc]
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
|
|
||||||
|
#[primary_key]
|
||||||
|
pub identity: spacetimedb::Identity,
|
||||||
|
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
|
||||||
#[index(btree)]
|
#[index(btree)]
|
||||||
pub lobby_id: u32,
|
pub lobby_id: u32,
|
||||||
pub ready: bool,
|
pub ready: bool,
|
||||||
|
|
||||||
|
pub sort: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[table(name = player_clock, public)]
|
||||||
|
pub struct PlayerClock {
|
||||||
|
#[primary_key]
|
||||||
|
pub id: u32,
|
||||||
|
|
||||||
|
#[unique]
|
||||||
|
pub player_id: u32,
|
||||||
|
|
||||||
|
pub renewable: u16,
|
||||||
|
pub total: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[table(name = player_hand)]
|
||||||
|
pub struct PlayerHand {
|
||||||
|
#[primary_key]
|
||||||
|
#[auto_inc]
|
||||||
|
pub id: u32,
|
||||||
|
|
||||||
|
#[unique]
|
||||||
|
pub player_id: u32,
|
||||||
|
|
||||||
pub turn_state: TurnState,
|
pub turn_state: TurnState,
|
||||||
|
|
||||||
pub sort: bool,
|
|
||||||
|
|
||||||
pub hand: Vec<DbTile>,
|
|
||||||
pub pond: Vec<DbTile>,
|
pub pond: Vec<DbTile>,
|
||||||
|
pub hand: Vec<DbTile>,
|
||||||
|
|
||||||
pub drawn_tile: Option<DbTile>,
|
/// drawn or callable tile
|
||||||
|
pub working_tile: Option<DbTile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[table(name = bot)]
|
#[table(name = bot)]
|
||||||
|
|
@ -91,8 +107,22 @@ pub struct Bot {
|
||||||
#[index(btree)]
|
#[index(btree)]
|
||||||
pub lobby_id: u32,
|
pub lobby_id: u32,
|
||||||
|
|
||||||
|
pub turn_state: TurnState,
|
||||||
|
|
||||||
pub hand: Vec<DbTile>,
|
pub hand: Vec<DbTile>,
|
||||||
pub pond: Vec<DbTile>,
|
pub pond: Vec<DbTile>,
|
||||||
|
|
||||||
pub drawn_tile: Option<DbTile>,
|
pub working_tile: Option<DbTile>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[table(name = game_timer, scheduled(advance_game))]
|
||||||
|
pub struct GameTimer {
|
||||||
|
#[primary_key]
|
||||||
|
#[auto_inc]
|
||||||
|
pub id: u64,
|
||||||
|
|
||||||
|
#[unique]
|
||||||
|
pub lobby_id: u32,
|
||||||
|
|
||||||
|
pub scheduled_at: spacetimedb::ScheduleAt,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use bevy_spacetimedb::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use jong_db::{self, DbConnection, LobbyTableAccess, PlayerTableAccess, RemoteTables};
|
use jong_db::{self, DbConnection, LobbyTableAccess, PlayerTableAccess, RemoteTables};
|
||||||
use jong_db::{add_bot, draw_tile, set_ready, shuffle_deal, skip_call, start_game};
|
use jong_db::{add_bot, set_ready};
|
||||||
use jong_types::*;
|
use jong_types::*;
|
||||||
|
|
||||||
pub mod player;
|
pub mod player;
|
||||||
|
|
@ -121,7 +121,7 @@ fn on_player_insert_update(
|
||||||
};
|
};
|
||||||
|
|
||||||
for msg in messages.read() {
|
for msg in messages.read() {
|
||||||
match msg.new.turn_state {
|
/* match msg.new.turn_state {
|
||||||
jong_db::TurnState::None => {}
|
jong_db::TurnState::None => {}
|
||||||
jong_db::TurnState::Tsumo => {
|
jong_db::TurnState::Tsumo => {
|
||||||
stdb.reducers().draw_tile().unwrap();
|
stdb.reducers().draw_tile().unwrap();
|
||||||
|
|
@ -171,7 +171,7 @@ fn on_player_insert_update(
|
||||||
if let Some(dbt) = &msg.new.drawn_tile {
|
if let Some(dbt) = &msg.new.drawn_tile {
|
||||||
debug!("drew tile with id: {}", dbt.id);
|
debug!("drew tile with id: {}", dbt.id);
|
||||||
commands.spawn((Tile::from(&dbt.tile), TileId(dbt.id), Drawn));
|
commands.spawn((Tile::from(&dbt.tile), TileId(dbt.id), Drawn));
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,12 +205,12 @@ fn on_lobby_insert_update(
|
||||||
stdb.reducers().add_bot(player.lobby_id).unwrap();
|
stdb.reducers().add_bot(player.lobby_id).unwrap();
|
||||||
}
|
}
|
||||||
stdb.reducers().set_ready(true).unwrap();
|
stdb.reducers().set_ready(true).unwrap();
|
||||||
stdb.reducers().start_game().unwrap();
|
// stdb.reducers().start_game().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jong_db::GameState::Setup => {
|
jong_db::GameState::Setup => {
|
||||||
trace!("game entered setup");
|
trace!("game entered setup");
|
||||||
stdb.reducers().shuffle_deal(player.lobby_id).unwrap();
|
// stdb.reducers().shuffle_deal(player.lobby_id).unwrap();
|
||||||
}
|
}
|
||||||
jong_db::GameState::Deal => {
|
jong_db::GameState::Deal => {
|
||||||
trace!("game entered deal");
|
trace!("game entered deal");
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ use bevy_ratatui::crossterm::event::KeyCode;
|
||||||
use bevy_ratatui::event::KeyMessage;
|
use bevy_ratatui::event::KeyMessage;
|
||||||
use jong_db::PlayerTableAccess;
|
use jong_db::PlayerTableAccess;
|
||||||
use jong_db::join_or_create_lobby;
|
use jong_db::join_or_create_lobby;
|
||||||
use jong_db::start_game;
|
|
||||||
use tui_logger::TuiWidgetEvent;
|
use tui_logger::TuiWidgetEvent;
|
||||||
|
|
||||||
use jong::SpacetimeDB;
|
use jong::SpacetimeDB;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue