(stash) render other players

This commit is contained in:
Tao Tien 2026-02-24 00:56:34 -08:00
parent 33cb9c7f97
commit cc07cc89c6
10 changed files with 249 additions and 14 deletions

View file

@ -0,0 +1,39 @@
// 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_or_bot_type::PlayerOrBot;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct HandView {
pub player: PlayerOrBot,
pub hand_length: u8,
pub drawn: bool,
}
impl __sdk::InModule for HandView {
type Module = super::RemoteModule;
}
/// Column accessor struct for the table `HandView`.
///
/// Provides typed access to columns for query building.
pub struct HandViewCols {
pub player: __sdk::__query_builder::Col<HandView, PlayerOrBot>,
pub hand_length: __sdk::__query_builder::Col<HandView, u8>,
pub drawn: __sdk::__query_builder::Col<HandView, bool>,
}
impl __sdk::__query_builder::HasCols for HandView {
type Cols = HandViewCols;
fn cols(table_name: &'static str) -> Self::Cols {
HandViewCols {
player: __sdk::__query_builder::Col::new(table_name, "player"),
hand_length: __sdk::__query_builder::Col::new(table_name, "hand_length"),
drawn: __sdk::__query_builder::Col::new(table_name, "drawn"),
}
}
}

View file

@ -20,6 +20,7 @@ pub mod dragon_type;
pub mod game_state_type;
pub mod game_timer_table;
pub mod game_timer_type;
pub mod hand_view_type;
pub mod join_or_create_lobby_reducer;
pub mod lobby_table;
pub mod lobby_type;
@ -37,6 +38,7 @@ pub mod suit_type;
pub mod tile_table;
pub mod tile_type;
pub mod turn_state_type;
pub mod view_closed_hands_table;
pub mod view_hand_table;
pub mod wall_table;
pub mod wind_type;
@ -55,6 +57,7 @@ pub use dragon_type::Dragon;
pub use game_state_type::GameState;
pub use game_timer_table::*;
pub use game_timer_type::GameTimer;
pub use hand_view_type::HandView;
pub use join_or_create_lobby_reducer::{
join_or_create_lobby, set_flags_for_join_or_create_lobby, JoinOrCreateLobbyCallbackId,
};
@ -74,6 +77,7 @@ pub use suit_type::Suit;
pub use tile_table::*;
pub use tile_type::Tile;
pub use turn_state_type::TurnState;
pub use view_closed_hands_table::*;
pub use view_hand_table::*;
pub use wall_table::*;
pub use wind_type::Wind;
@ -190,6 +194,7 @@ pub struct DbUpdate {
player_clock: __sdk::TableUpdate<PlayerClock>,
player_hand: __sdk::TableUpdate<PlayerHand>,
tile: __sdk::TableUpdate<DbTile>,
view_closed_hands: __sdk::TableUpdate<HandView>,
view_hand: __sdk::TableUpdate<PlayerHand>,
wall: __sdk::TableUpdate<DbWall>,
}
@ -224,6 +229,9 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
"tile" => db_update
.tile
.append(tile_table::parse_table_update(table_update)?),
"view_closed_hands" => db_update
.view_closed_hands
.append(view_closed_hands_table::parse_table_update(table_update)?),
"view_hand" => db_update
.view_hand
.append(view_hand_table::parse_table_update(table_update)?),
@ -283,6 +291,8 @@ impl __sdk::DbUpdate for DbUpdate {
diff.wall = cache
.apply_diff_to_table::<DbWall>("wall", &self.wall)
.with_updates_by_pk(|row| &row.lobby_id);
diff.view_closed_hands =
cache.apply_diff_to_table::<HandView>("view_closed_hands", &self.view_closed_hands);
diff.view_hand = cache.apply_diff_to_table::<PlayerHand>("view_hand", &self.view_hand);
diff
@ -301,6 +311,7 @@ pub struct AppliedDiff<'r> {
player_clock: __sdk::TableAppliedDiff<'r, PlayerClock>,
player_hand: __sdk::TableAppliedDiff<'r, PlayerHand>,
tile: __sdk::TableAppliedDiff<'r, DbTile>,
view_closed_hands: __sdk::TableAppliedDiff<'r, HandView>,
view_hand: __sdk::TableAppliedDiff<'r, PlayerHand>,
wall: __sdk::TableAppliedDiff<'r, DbWall>,
__unused: std::marker::PhantomData<&'r ()>,
@ -332,6 +343,11 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
);
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::<HandView>(
"view_closed_hands",
&self.view_closed_hands,
event,
);
callbacks.invoke_table_row_callbacks::<PlayerHand>("view_hand", &self.view_hand, event);
callbacks.invoke_table_row_callbacks::<DbWall>("wall", &self.wall, event);
}
@ -1062,6 +1078,7 @@ impl __sdk::SpacetimeModule for RemoteModule {
player_clock_table::register_table(client_cache);
player_hand_table::register_table(client_cache);
tile_table::register_table(client_cache);
view_closed_hands_table::register_table(client_cache);
view_hand_table::register_table(client_cache);
wall_table::register_table(client_cache);
}

View file

@ -0,0 +1,112 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use super::hand_view_type::HandView;
use super::player_or_bot_type::PlayerOrBot;
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
/// Table handle for the table `view_closed_hands`.
///
/// Obtain a handle from the [`ViewClosedHandsTableAccess::view_closed_hands`] method on [`super::RemoteTables`],
/// like `ctx.db.view_closed_hands()`.
///
/// Users are encouraged not to explicitly reference this type,
/// but to directly chain method calls,
/// like `ctx.db.view_closed_hands().on_insert(...)`.
pub struct ViewClosedHandsTableHandle<'ctx> {
imp: __sdk::TableHandle<HandView>,
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
}
#[allow(non_camel_case_types)]
/// Extension trait for access to the table `view_closed_hands`.
///
/// Implemented for [`super::RemoteTables`].
pub trait ViewClosedHandsTableAccess {
#[allow(non_snake_case)]
/// Obtain a [`ViewClosedHandsTableHandle`], which mediates access to the table `view_closed_hands`.
fn view_closed_hands(&self) -> ViewClosedHandsTableHandle<'_>;
}
impl ViewClosedHandsTableAccess for super::RemoteTables {
fn view_closed_hands(&self) -> ViewClosedHandsTableHandle<'_> {
ViewClosedHandsTableHandle {
imp: self.imp.get_table::<HandView>("view_closed_hands"),
ctx: std::marker::PhantomData,
}
}
}
pub struct ViewClosedHandsInsertCallbackId(__sdk::CallbackId);
pub struct ViewClosedHandsDeleteCallbackId(__sdk::CallbackId);
impl<'ctx> __sdk::Table for ViewClosedHandsTableHandle<'ctx> {
type Row = HandView;
type EventContext = super::EventContext;
fn count(&self) -> u64 {
self.imp.count()
}
fn iter(&self) -> impl Iterator<Item = HandView> + '_ {
self.imp.iter()
}
type InsertCallbackId = ViewClosedHandsInsertCallbackId;
fn on_insert(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> ViewClosedHandsInsertCallbackId {
ViewClosedHandsInsertCallbackId(self.imp.on_insert(Box::new(callback)))
}
fn remove_on_insert(&self, callback: ViewClosedHandsInsertCallbackId) {
self.imp.remove_on_insert(callback.0)
}
type DeleteCallbackId = ViewClosedHandsDeleteCallbackId;
fn on_delete(
&self,
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
) -> ViewClosedHandsDeleteCallbackId {
ViewClosedHandsDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
}
fn remove_on_delete(&self, callback: ViewClosedHandsDeleteCallbackId) {
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::<HandView>("view_closed_hands");
}
#[doc(hidden)]
pub(super) fn parse_table_update(
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
) -> __sdk::Result<__sdk::TableUpdate<HandView>> {
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
__sdk::InternalError::failed_parse("TableUpdate<HandView>", "TableUpdate")
.with_cause(e)
.into()
})
}
#[allow(non_camel_case_types)]
/// Extension trait for query builder access to the table `HandView`.
///
/// Implemented for [`__sdk::QueryTableAccessor`].
pub trait view_closed_handsQueryTableAccess {
#[allow(non_snake_case)]
/// Get a query builder for the table `HandView`.
fn view_closed_hands(&self) -> __sdk::__query_builder::Table<HandView>;
}
impl view_closed_handsQueryTableAccess for __sdk::QueryTableAccessor {
fn view_closed_hands(&self) -> __sdk::__query_builder::Table<HandView> {
__sdk::__query_builder::Table::new("view_closed_hands")
}
}