危危危 clear_all 危危危
This commit is contained in:
parent
b6e7635122
commit
f71e32b0b9
4 changed files with 122 additions and 3 deletions
100
jong/src/stdb/clear_all_reducer.rs
Normal file
100
jong/src/stdb/clear_all_reducer.rs
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
// 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 ClearAllArgs {}
|
||||||
|
|
||||||
|
impl From<ClearAllArgs> for super::Reducer {
|
||||||
|
fn from(args: ClearAllArgs) -> Self {
|
||||||
|
Self::ClearAll
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl __sdk::InModule for ClearAllArgs {
|
||||||
|
type Module = super::RemoteModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ClearAllCallbackId(__sdk::CallbackId);
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
/// Extension trait for access to the reducer `clear_all`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::RemoteReducers`].
|
||||||
|
pub trait clear_all {
|
||||||
|
/// Request that the remote module invoke the reducer `clear_all` 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_clear_all`] callbacks.
|
||||||
|
fn clear_all(&self) -> __sdk::Result<()>;
|
||||||
|
/// 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`]
|
||||||
|
/// to determine the reducer's status.
|
||||||
|
///
|
||||||
|
/// The returned [`ClearAllCallbackId`] can be passed to [`Self::remove_on_clear_all`]
|
||||||
|
/// to cancel the callback.
|
||||||
|
fn on_clear_all(
|
||||||
|
&self,
|
||||||
|
callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
||||||
|
) -> ClearAllCallbackId;
|
||||||
|
/// Cancel a callback previously registered by [`Self::on_clear_all`],
|
||||||
|
/// causing it not to run in the future.
|
||||||
|
fn remove_on_clear_all(&self, callback: ClearAllCallbackId);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl clear_all for super::RemoteReducers {
|
||||||
|
fn clear_all(&self) -> __sdk::Result<()> {
|
||||||
|
self.imp.call_reducer("clear_all", ClearAllArgs {})
|
||||||
|
}
|
||||||
|
fn on_clear_all(
|
||||||
|
&self,
|
||||||
|
mut callback: impl FnMut(&super::ReducerEventContext) + Send + 'static,
|
||||||
|
) -> ClearAllCallbackId {
|
||||||
|
ClearAllCallbackId(self.imp.on_reducer(
|
||||||
|
"clear_all",
|
||||||
|
Box::new(move |ctx: &super::ReducerEventContext| {
|
||||||
|
#[allow(irrefutable_let_patterns)]
|
||||||
|
let super::ReducerEventContext {
|
||||||
|
event:
|
||||||
|
__sdk::ReducerEvent {
|
||||||
|
reducer: super::Reducer::ClearAll {},
|
||||||
|
..
|
||||||
|
},
|
||||||
|
..
|
||||||
|
} = ctx
|
||||||
|
else {
|
||||||
|
unreachable!()
|
||||||
|
};
|
||||||
|
callback(ctx)
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
fn remove_on_clear_all(&self, callback: ClearAllCallbackId) {
|
||||||
|
self.imp.remove_on_reducer("clear_all", callback.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
/// Extension trait for setting the call-flags for the reducer `clear_all`.
|
||||||
|
///
|
||||||
|
/// Implemented for [`super::SetReducerFlags`].
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
pub trait set_flags_for_clear_all {
|
||||||
|
/// Set the call-reducer flags for the reducer `clear_all` to `flags`.
|
||||||
|
///
|
||||||
|
/// This type is currently unstable and may be removed without a major version bump.
|
||||||
|
fn clear_all(&self, flags: __ws::CallReducerFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl set_flags_for_clear_all for super::SetReducerFlags {
|
||||||
|
fn clear_all(&self, flags: __ws::CallReducerFlags) {
|
||||||
|
self.imp.set_call_reducer_flags("clear_all", flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||||
pub mod add_bot_reducer;
|
pub mod add_bot_reducer;
|
||||||
pub mod bot_table;
|
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 discard_tile_reducer;
|
||||||
|
|
@ -37,6 +38,7 @@ pub mod wind_type;
|
||||||
pub use add_bot_reducer::{add_bot, set_flags_for_add_bot, AddBotCallbackId};
|
pub use add_bot_reducer::{add_bot, set_flags_for_add_bot, AddBotCallbackId};
|
||||||
pub use bot_table::*;
|
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 discard_tile_reducer::{discard_tile, set_flags_for_discard_tile, DiscardTileCallbackId};
|
||||||
|
|
@ -75,6 +77,7 @@ pub use wind_type::Wind;
|
||||||
|
|
||||||
pub enum Reducer {
|
pub enum Reducer {
|
||||||
AddBot { lobby_id: u32 },
|
AddBot { lobby_id: u32 },
|
||||||
|
ClearAll,
|
||||||
DiscardTile { tile_id: u32 },
|
DiscardTile { tile_id: u32 },
|
||||||
DrawTile,
|
DrawTile,
|
||||||
JoinOrCreateLobby { lobby_id: u32 },
|
JoinOrCreateLobby { lobby_id: u32 },
|
||||||
|
|
@ -93,6 +96,7 @@ 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::ClearAll => "clear_all",
|
||||||
Reducer::DiscardTile { .. } => "discard_tile",
|
Reducer::DiscardTile { .. } => "discard_tile",
|
||||||
Reducer::DrawTile => "draw_tile",
|
Reducer::DrawTile => "draw_tile",
|
||||||
Reducer::JoinOrCreateLobby { .. } => "join_or_create_lobby",
|
Reducer::JoinOrCreateLobby { .. } => "join_or_create_lobby",
|
||||||
|
|
@ -114,6 +118,13 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
|
||||||
&value.args,
|
&value.args,
|
||||||
)?
|
)?
|
||||||
.into()),
|
.into()),
|
||||||
|
"clear_all" => Ok(
|
||||||
|
__sdk::parse_reducer_args::<clear_all_reducer::ClearAllArgs>(
|
||||||
|
"clear_all",
|
||||||
|
&value.args,
|
||||||
|
)?
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
"discard_tile" => Ok(
|
"discard_tile" => Ok(
|
||||||
__sdk::parse_reducer_args::<discard_tile_reducer::DiscardTileArgs>(
|
__sdk::parse_reducer_args::<discard_tile_reducer::DiscardTileArgs>(
|
||||||
"discard_tile",
|
"discard_tile",
|
||||||
|
|
|
||||||
1
justfile
1
justfile
|
|
@ -13,6 +13,7 @@ default:
|
||||||
just --list
|
just --list
|
||||||
|
|
||||||
run-tui:
|
run-tui:
|
||||||
|
spacetime call jongline "clear_all"
|
||||||
cargo run -- run-tui
|
cargo run -- run-tui
|
||||||
|
|
||||||
update:
|
update:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use log::info;
|
use log::{debug, info};
|
||||||
use spacetimedb::{ReducerContext, Table, ViewContext, reducer, view};
|
use spacetimedb::{ReducerContext, Table, ViewContext, reducer, view};
|
||||||
|
|
||||||
use crate::tables::{player::player, *};
|
use crate::tables::{player::player, *};
|
||||||
|
|
@ -8,6 +8,13 @@ mod reducers {
|
||||||
}
|
}
|
||||||
mod tables;
|
mod tables;
|
||||||
|
|
||||||
|
#[reducer]
|
||||||
|
pub fn clear_all(ctx: &ReducerContext) {
|
||||||
|
for row in ctx.db.player().iter() {
|
||||||
|
ctx.db.player().delete(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[reducer(client_connected)]
|
#[reducer(client_connected)]
|
||||||
pub fn login_or_add_player(ctx: &ReducerContext) {
|
pub fn login_or_add_player(ctx: &ReducerContext) {
|
||||||
let identity = ctx.sender;
|
let identity = ctx.sender;
|
||||||
|
|
@ -24,10 +31,10 @@ pub fn login_or_add_player(ctx: &ReducerContext) {
|
||||||
pond: vec![],
|
pond: vec![],
|
||||||
drawn_tile: None,
|
drawn_tile: None,
|
||||||
}) {
|
}) {
|
||||||
info!("added player: {:?}", player);
|
debug!("added player: {:?}", player);
|
||||||
} else {
|
} else {
|
||||||
let player = ctx.db.player().identity().find(identity).unwrap();
|
let player = ctx.db.player().identity().find(identity).unwrap();
|
||||||
info!("player {:?} has reconnected", player)
|
debug!("player {:?} has reconnected", player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue