merge all extra tables back into player for now
This commit is contained in:
parent
71ad4cada6
commit
9b01f6b96a
16 changed files with 66 additions and 579 deletions
|
|
@ -9,9 +9,8 @@ use spacetimedb::Identity;
|
|||
use spacetimedb_sdk::{DbContext, Table, credentials};
|
||||
|
||||
use crate::stdb::{
|
||||
self, DbConnection, HandTableAccess, LobbyTableAccess, PlayerTableAccess, RemoteTables,
|
||||
ViewPlayerHandTableAccess, add_bot, join_or_create_lobby, login_or_add_player, set_ready,
|
||||
shuffle_deal, start_game,
|
||||
self, DbConnection, LobbyTableAccess, PlayerTableAccess, RemoteTables, add_bot,
|
||||
join_or_create_lobby, login_or_add_player, set_ready, shuffle_deal, start_game,
|
||||
};
|
||||
use crate::{
|
||||
SpacetimeDB, creds_store,
|
||||
|
|
@ -51,10 +50,6 @@ impl Plugin for Riichi {
|
|||
.add_table(RemoteTables::player)
|
||||
.add_table(RemoteTables::lobby)
|
||||
|
||||
// TODO until views work, we're using RLS
|
||||
.add_table(RemoteTables::hand)
|
||||
// .add_table_without_pk(RemoteTables::view_player_hand)
|
||||
|
||||
// semicolon stopper
|
||||
;
|
||||
let plugins =
|
||||
|
|
@ -88,10 +83,6 @@ impl Plugin for Riichi {
|
|||
.add_systems(Update, on_lobby_insert_update)
|
||||
// .add_systems(OnEnter(GameState::Lobby), join_or_create_lobby)
|
||||
|
||||
// TODO figure out how to run_if OR run_if?
|
||||
.add_systems(Update, on_hand_insert_update.run_if(in_state(GameState::Deal)))
|
||||
.add_systems(Update, on_hand_insert_update.run_if(in_state(GameState::Play)))
|
||||
|
||||
// semicolon stopper
|
||||
;
|
||||
}
|
||||
|
|
@ -123,8 +114,6 @@ fn subscriptions(stdb: SpacetimeDB) {
|
|||
stdb.identity()
|
||||
),
|
||||
"SELECT l.* FROM lobby l JOIN player p ON l.host_player_id = p.id".to_string(),
|
||||
// "SELECT * FROM view_player_hand vph".to_string(),
|
||||
"SELECT * FROM hand".to_string(), // TODO remove once views work
|
||||
]);
|
||||
// .subscribe_to_all_tables();
|
||||
}
|
||||
|
|
@ -134,18 +123,43 @@ fn on_player_insert_update(
|
|||
mut messages: ReadInsertUpdateMessage<stdb::Player>,
|
||||
|
||||
mut commands: Commands,
|
||||
|
||||
tiles: Query<(&Tile, Entity)>,
|
||||
mut player: Option<Single<&mut player::Player>>,
|
||||
mut hand_ent: Option<Single<Entity, With<Hand>>>,
|
||||
) {
|
||||
use player::*;
|
||||
|
||||
for msg in messages.read() {
|
||||
// debug!("player_insert_update msg:\n{:#?}", msg.new);
|
||||
debug!("player_insert_update msg:\n{:#?}", msg.new);
|
||||
if let Some(ref player) = player {
|
||||
// if msg.old.as_ref().is_some_and(|m| !m.ready) && msg.new.ready {
|
||||
// trace!("entered ready");
|
||||
// // TODO add a start game button in the future
|
||||
// stdb.reducers().start_game().unwrap();
|
||||
// }
|
||||
let mut view: Vec<_> = msg.new.hand.iter().map(Tile::from).collect();
|
||||
// let mut tiles = tiles
|
||||
// .iter()
|
||||
// .filter(|(tt, _)| {
|
||||
// if let Some((i, _)) = view.iter().enumerate().find(|(_, t)| t == tt) {
|
||||
// view.swap_remove(i);
|
||||
// true
|
||||
// } else {
|
||||
// false
|
||||
// }
|
||||
// })
|
||||
// // .map(|(t, e)| e)
|
||||
// .collect::<Vec<_>>();
|
||||
// tiles.sort_by_key(|(t, e)| **t);
|
||||
// tiles.get_many(entities)
|
||||
|
||||
|
||||
let tiles = tiles.into_iter().map(|(_, e)| e).collect::<Vec<_>>();
|
||||
|
||||
commands
|
||||
.entity(**hand_ent.as_ref().unwrap())
|
||||
.replace_children(&tiles);
|
||||
} else {
|
||||
let player = Player {
|
||||
name: msg
|
||||
|
|
@ -211,31 +225,3 @@ fn on_lobby_insert_update(
|
|||
next_gamestate.set(msg.new.game_state.into());
|
||||
}
|
||||
}
|
||||
|
||||
fn on_hand_insert_update(
|
||||
stdb: SpacetimeDB,
|
||||
mut messages: ReadInsertUpdateMessage<stdb::Hand>,
|
||||
|
||||
mut commands: Commands,
|
||||
tiles: Query<(&Tile, Entity)>,
|
||||
hand_ent: Single<Entity, With<Hand>>,
|
||||
) {
|
||||
for msg in messages.read() {
|
||||
trace!("view_hand");
|
||||
let mut view: Vec<_> = msg.new.tiles.iter().map(Tile::from).collect();
|
||||
let tiles = tiles
|
||||
.iter()
|
||||
.filter(|(tt, _)| {
|
||||
if let Some((i, _)) = view.iter().enumerate().find(|(_, t)| t == tt) {
|
||||
view.swap_remove(i);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.map(|(_, e)| e)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
commands.entity(*hand_ent).replace_children(&tiles);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#![allow(unused, clippy::all)]
|
||||
use super::bot_type::Bot;
|
||||
use super::tile_type::Tile;
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
/// Table handle for the table `bot`.
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@
|
|||
#![allow(unused, clippy::all)]
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
use super::tile_type::Tile;
|
||||
|
||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||
#[sats(crate = __lib)]
|
||||
pub struct Bot {
|
||||
pub id: u32,
|
||||
pub lobby_id: u32,
|
||||
pub hand_id: u32,
|
||||
pub pond_id: u32,
|
||||
pub hand: Vec<Tile>,
|
||||
pub pond: Vec<Tile>,
|
||||
}
|
||||
|
||||
impl __sdk::InModule for Bot {
|
||||
|
|
|
|||
|
|
@ -1,144 +0,0 @@
|
|||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||
|
||||
#![allow(unused, clippy::all)]
|
||||
use super::hand_type::Hand;
|
||||
use super::player_or_bot_type::PlayerOrBot;
|
||||
use super::tile_type::Tile;
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
/// Table handle for the table `hand`.
|
||||
///
|
||||
/// Obtain a handle from the [`HandTableAccess::hand`] method on [`super::RemoteTables`],
|
||||
/// like `ctx.db.hand()`.
|
||||
///
|
||||
/// Users are encouraged not to explicitly reference this type,
|
||||
/// but to directly chain method calls,
|
||||
/// like `ctx.db.hand().on_insert(...)`.
|
||||
pub struct HandTableHandle<'ctx> {
|
||||
imp: __sdk::TableHandle<Hand>,
|
||||
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
/// Extension trait for access to the table `hand`.
|
||||
///
|
||||
/// Implemented for [`super::RemoteTables`].
|
||||
pub trait HandTableAccess {
|
||||
#[allow(non_snake_case)]
|
||||
/// Obtain a [`HandTableHandle`], which mediates access to the table `hand`.
|
||||
fn hand(&self) -> HandTableHandle<'_>;
|
||||
}
|
||||
|
||||
impl HandTableAccess for super::RemoteTables {
|
||||
fn hand(&self) -> HandTableHandle<'_> {
|
||||
HandTableHandle {
|
||||
imp: self.imp.get_table::<Hand>("hand"),
|
||||
ctx: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HandInsertCallbackId(__sdk::CallbackId);
|
||||
pub struct HandDeleteCallbackId(__sdk::CallbackId);
|
||||
|
||||
impl<'ctx> __sdk::Table for HandTableHandle<'ctx> {
|
||||
type Row = Hand;
|
||||
type EventContext = super::EventContext;
|
||||
|
||||
fn count(&self) -> u64 {
|
||||
self.imp.count()
|
||||
}
|
||||
fn iter(&self) -> impl Iterator<Item = Hand> + '_ {
|
||||
self.imp.iter()
|
||||
}
|
||||
|
||||
type InsertCallbackId = HandInsertCallbackId;
|
||||
|
||||
fn on_insert(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||
) -> HandInsertCallbackId {
|
||||
HandInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_insert(&self, callback: HandInsertCallbackId) {
|
||||
self.imp.remove_on_insert(callback.0)
|
||||
}
|
||||
|
||||
type DeleteCallbackId = HandDeleteCallbackId;
|
||||
|
||||
fn on_delete(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||
) -> HandDeleteCallbackId {
|
||||
HandDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_delete(&self, callback: HandDeleteCallbackId) {
|
||||
self.imp.remove_on_delete(callback.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||
let _table = client_cache.get_or_make_table::<Hand>("hand");
|
||||
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||
}
|
||||
pub struct HandUpdateCallbackId(__sdk::CallbackId);
|
||||
|
||||
impl<'ctx> __sdk::TableWithPrimaryKey for HandTableHandle<'ctx> {
|
||||
type UpdateCallbackId = HandUpdateCallbackId;
|
||||
|
||||
fn on_update(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
|
||||
) -> HandUpdateCallbackId {
|
||||
HandUpdateCallbackId(self.imp.on_update(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_update(&self, callback: HandUpdateCallbackId) {
|
||||
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<Hand>> {
|
||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||
__sdk::InternalError::failed_parse("TableUpdate<Hand>", "TableUpdate")
|
||||
.with_cause(e)
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
/// Access to the `id` unique index on the table `hand`,
|
||||
/// which allows point queries on the field of the same name
|
||||
/// via the [`HandIdUnique::find`] method.
|
||||
///
|
||||
/// Users are encouraged not to explicitly reference this type,
|
||||
/// but to directly chain method calls,
|
||||
/// like `ctx.db.hand().id().find(...)`.
|
||||
pub struct HandIdUnique<'ctx> {
|
||||
imp: __sdk::UniqueConstraintHandle<Hand, u32>,
|
||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||
}
|
||||
|
||||
impl<'ctx> HandTableHandle<'ctx> {
|
||||
/// Get a handle on the `id` unique index on the table `hand`.
|
||||
pub fn id(&self) -> HandIdUnique<'ctx> {
|
||||
HandIdUnique {
|
||||
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||
phantom: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx> HandIdUnique<'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<Hand> {
|
||||
self.imp.find(col_val)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||
|
||||
#![allow(unused, clippy::all)]
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
use super::player_or_bot_type::PlayerOrBot;
|
||||
use super::tile_type::Tile;
|
||||
|
||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||
#[sats(crate = __lib)]
|
||||
pub struct Hand {
|
||||
pub id: u32,
|
||||
pub owner: PlayerOrBot,
|
||||
pub sort: bool,
|
||||
pub tiles: Vec<Tile>,
|
||||
}
|
||||
|
||||
impl __sdk::InModule for Hand {
|
||||
type Module = super::RemoteModule;
|
||||
}
|
||||
|
|
@ -11,8 +11,6 @@ pub mod bot_table;
|
|||
pub mod bot_type;
|
||||
pub mod dragon_type;
|
||||
pub mod game_state_type;
|
||||
pub mod hand_table;
|
||||
pub mod hand_type;
|
||||
pub mod join_or_create_lobby_reducer;
|
||||
pub mod lobby_table;
|
||||
pub mod lobby_type;
|
||||
|
|
@ -20,8 +18,6 @@ pub mod login_or_add_player_reducer;
|
|||
pub mod player_or_bot_type;
|
||||
pub mod player_table;
|
||||
pub mod player_type;
|
||||
pub mod pond_table;
|
||||
pub mod pond_type;
|
||||
pub mod rank_type;
|
||||
pub mod set_ready_reducer;
|
||||
pub mod shuffle_deal_reducer;
|
||||
|
|
@ -29,7 +25,6 @@ pub mod start_game_reducer;
|
|||
pub mod suit_type;
|
||||
pub mod tile_type;
|
||||
pub mod turn_state_type;
|
||||
pub mod view_player_hand_table;
|
||||
pub mod wall_table;
|
||||
pub mod wall_type;
|
||||
pub mod wind_type;
|
||||
|
|
@ -39,8 +34,6 @@ pub use bot_table::*;
|
|||
pub use bot_type::Bot;
|
||||
pub use dragon_type::Dragon;
|
||||
pub use game_state_type::GameState;
|
||||
pub use hand_table::*;
|
||||
pub use hand_type::Hand;
|
||||
pub use join_or_create_lobby_reducer::{
|
||||
join_or_create_lobby, set_flags_for_join_or_create_lobby, JoinOrCreateLobbyCallbackId,
|
||||
};
|
||||
|
|
@ -52,8 +45,6 @@ pub use login_or_add_player_reducer::{
|
|||
pub use player_or_bot_type::PlayerOrBot;
|
||||
pub use player_table::*;
|
||||
pub use player_type::Player;
|
||||
pub use pond_table::*;
|
||||
pub use pond_type::Pond;
|
||||
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};
|
||||
|
|
@ -61,7 +52,6 @@ pub use start_game_reducer::{set_flags_for_start_game, start_game, StartGameCall
|
|||
pub use suit_type::Suit;
|
||||
pub use tile_type::Tile;
|
||||
pub use turn_state_type::TurnState;
|
||||
pub use view_player_hand_table::*;
|
||||
pub use wall_table::*;
|
||||
pub use wall_type::Wall;
|
||||
pub use wind_type::Wind;
|
||||
|
|
@ -152,11 +142,8 @@ impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer {
|
|||
#[doc(hidden)]
|
||||
pub struct DbUpdate {
|
||||
bot: __sdk::TableUpdate<Bot>,
|
||||
hand: __sdk::TableUpdate<Hand>,
|
||||
lobby: __sdk::TableUpdate<Lobby>,
|
||||
player: __sdk::TableUpdate<Player>,
|
||||
pond: __sdk::TableUpdate<Pond>,
|
||||
view_player_hand: __sdk::TableUpdate<Hand>,
|
||||
wall: __sdk::TableUpdate<Wall>,
|
||||
}
|
||||
|
||||
|
|
@ -169,21 +156,12 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
|||
"bot" => db_update
|
||||
.bot
|
||||
.append(bot_table::parse_table_update(table_update)?),
|
||||
"hand" => db_update
|
||||
.hand
|
||||
.append(hand_table::parse_table_update(table_update)?),
|
||||
"lobby" => db_update
|
||||
.lobby
|
||||
.append(lobby_table::parse_table_update(table_update)?),
|
||||
"player" => db_update
|
||||
.player
|
||||
.append(player_table::parse_table_update(table_update)?),
|
||||
"pond" => db_update
|
||||
.pond
|
||||
.append(pond_table::parse_table_update(table_update)?),
|
||||
"view_player_hand" => db_update
|
||||
.view_player_hand
|
||||
.append(view_player_hand_table::parse_table_update(table_update)?),
|
||||
"wall" => db_update
|
||||
.wall
|
||||
.append(wall_table::parse_table_update(table_update)?),
|
||||
|
|
@ -216,23 +194,15 @@ impl __sdk::DbUpdate for DbUpdate {
|
|||
diff.bot = cache
|
||||
.apply_diff_to_table::<Bot>("bot", &self.bot)
|
||||
.with_updates_by_pk(|row| &row.id);
|
||||
diff.hand = cache
|
||||
.apply_diff_to_table::<Hand>("hand", &self.hand)
|
||||
.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.pond = cache
|
||||
.apply_diff_to_table::<Pond>("pond", &self.pond)
|
||||
.with_updates_by_pk(|row| &row.id);
|
||||
diff.wall = cache
|
||||
.apply_diff_to_table::<Wall>("wall", &self.wall)
|
||||
.with_updates_by_pk(|row| &row.lobby_id);
|
||||
diff.view_player_hand =
|
||||
cache.apply_diff_to_table::<Hand>("view_player_hand", &self.view_player_hand);
|
||||
|
||||
diff
|
||||
}
|
||||
|
|
@ -243,11 +213,8 @@ impl __sdk::DbUpdate for DbUpdate {
|
|||
#[doc(hidden)]
|
||||
pub struct AppliedDiff<'r> {
|
||||
bot: __sdk::TableAppliedDiff<'r, Bot>,
|
||||
hand: __sdk::TableAppliedDiff<'r, Hand>,
|
||||
lobby: __sdk::TableAppliedDiff<'r, Lobby>,
|
||||
player: __sdk::TableAppliedDiff<'r, Player>,
|
||||
pond: __sdk::TableAppliedDiff<'r, Pond>,
|
||||
view_player_hand: __sdk::TableAppliedDiff<'r, Hand>,
|
||||
wall: __sdk::TableAppliedDiff<'r, Wall>,
|
||||
__unused: std::marker::PhantomData<&'r ()>,
|
||||
}
|
||||
|
|
@ -263,15 +230,8 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
|
|||
callbacks: &mut __sdk::DbCallbacks<RemoteModule>,
|
||||
) {
|
||||
callbacks.invoke_table_row_callbacks::<Bot>("bot", &self.bot, event);
|
||||
callbacks.invoke_table_row_callbacks::<Hand>("hand", &self.hand, event);
|
||||
callbacks.invoke_table_row_callbacks::<Lobby>("lobby", &self.lobby, event);
|
||||
callbacks.invoke_table_row_callbacks::<Player>("player", &self.player, event);
|
||||
callbacks.invoke_table_row_callbacks::<Pond>("pond", &self.pond, event);
|
||||
callbacks.invoke_table_row_callbacks::<Hand>(
|
||||
"view_player_hand",
|
||||
&self.view_player_hand,
|
||||
event,
|
||||
);
|
||||
callbacks.invoke_table_row_callbacks::<Wall>("wall", &self.wall, event);
|
||||
}
|
||||
}
|
||||
|
|
@ -993,11 +953,8 @@ impl __sdk::SpacetimeModule for RemoteModule {
|
|||
|
||||
fn register_tables(client_cache: &mut __sdk::ClientCache<Self>) {
|
||||
bot_table::register_table(client_cache);
|
||||
hand_table::register_table(client_cache);
|
||||
lobby_table::register_table(client_cache);
|
||||
player_table::register_table(client_cache);
|
||||
pond_table::register_table(client_cache);
|
||||
view_player_hand_table::register_table(client_cache);
|
||||
wall_table::register_table(client_cache);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#![allow(unused, clippy::all)]
|
||||
use super::player_type::Player;
|
||||
use super::tile_type::Tile;
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
/// Table handle for the table `player`.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
#![allow(unused, clippy::all)]
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
use super::tile_type::Tile;
|
||||
|
||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||
#[sats(crate = __lib)]
|
||||
pub struct Player {
|
||||
|
|
@ -11,9 +13,10 @@ pub struct Player {
|
|||
pub id: u32,
|
||||
pub name: Option<String>,
|
||||
pub lobby_id: u32,
|
||||
pub hand_id: u32,
|
||||
pub pond_id: u32,
|
||||
pub ready: bool,
|
||||
pub sort: bool,
|
||||
pub hand: Vec<Tile>,
|
||||
pub pond: Vec<Tile>,
|
||||
}
|
||||
|
||||
impl __sdk::InModule for Player {
|
||||
|
|
|
|||
|
|
@ -1,144 +0,0 @@
|
|||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||
|
||||
#![allow(unused, clippy::all)]
|
||||
use super::player_or_bot_type::PlayerOrBot;
|
||||
use super::pond_type::Pond;
|
||||
use super::tile_type::Tile;
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
/// Table handle for the table `pond`.
|
||||
///
|
||||
/// Obtain a handle from the [`PondTableAccess::pond`] method on [`super::RemoteTables`],
|
||||
/// like `ctx.db.pond()`.
|
||||
///
|
||||
/// Users are encouraged not to explicitly reference this type,
|
||||
/// but to directly chain method calls,
|
||||
/// like `ctx.db.pond().on_insert(...)`.
|
||||
pub struct PondTableHandle<'ctx> {
|
||||
imp: __sdk::TableHandle<Pond>,
|
||||
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
/// Extension trait for access to the table `pond`.
|
||||
///
|
||||
/// Implemented for [`super::RemoteTables`].
|
||||
pub trait PondTableAccess {
|
||||
#[allow(non_snake_case)]
|
||||
/// Obtain a [`PondTableHandle`], which mediates access to the table `pond`.
|
||||
fn pond(&self) -> PondTableHandle<'_>;
|
||||
}
|
||||
|
||||
impl PondTableAccess for super::RemoteTables {
|
||||
fn pond(&self) -> PondTableHandle<'_> {
|
||||
PondTableHandle {
|
||||
imp: self.imp.get_table::<Pond>("pond"),
|
||||
ctx: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PondInsertCallbackId(__sdk::CallbackId);
|
||||
pub struct PondDeleteCallbackId(__sdk::CallbackId);
|
||||
|
||||
impl<'ctx> __sdk::Table for PondTableHandle<'ctx> {
|
||||
type Row = Pond;
|
||||
type EventContext = super::EventContext;
|
||||
|
||||
fn count(&self) -> u64 {
|
||||
self.imp.count()
|
||||
}
|
||||
fn iter(&self) -> impl Iterator<Item = Pond> + '_ {
|
||||
self.imp.iter()
|
||||
}
|
||||
|
||||
type InsertCallbackId = PondInsertCallbackId;
|
||||
|
||||
fn on_insert(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||
) -> PondInsertCallbackId {
|
||||
PondInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_insert(&self, callback: PondInsertCallbackId) {
|
||||
self.imp.remove_on_insert(callback.0)
|
||||
}
|
||||
|
||||
type DeleteCallbackId = PondDeleteCallbackId;
|
||||
|
||||
fn on_delete(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||
) -> PondDeleteCallbackId {
|
||||
PondDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_delete(&self, callback: PondDeleteCallbackId) {
|
||||
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::<Pond>("pond");
|
||||
_table.add_unique_constraint::<u32>("id", |row| &row.id);
|
||||
}
|
||||
pub struct PondUpdateCallbackId(__sdk::CallbackId);
|
||||
|
||||
impl<'ctx> __sdk::TableWithPrimaryKey for PondTableHandle<'ctx> {
|
||||
type UpdateCallbackId = PondUpdateCallbackId;
|
||||
|
||||
fn on_update(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static,
|
||||
) -> PondUpdateCallbackId {
|
||||
PondUpdateCallbackId(self.imp.on_update(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_update(&self, callback: PondUpdateCallbackId) {
|
||||
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<Pond>> {
|
||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||
__sdk::InternalError::failed_parse("TableUpdate<Pond>", "TableUpdate")
|
||||
.with_cause(e)
|
||||
.into()
|
||||
})
|
||||
}
|
||||
|
||||
/// Access to the `id` unique index on the table `pond`,
|
||||
/// which allows point queries on the field of the same name
|
||||
/// via the [`PondIdUnique::find`] method.
|
||||
///
|
||||
/// Users are encouraged not to explicitly reference this type,
|
||||
/// but to directly chain method calls,
|
||||
/// like `ctx.db.pond().id().find(...)`.
|
||||
pub struct PondIdUnique<'ctx> {
|
||||
imp: __sdk::UniqueConstraintHandle<Pond, u32>,
|
||||
phantom: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||
}
|
||||
|
||||
impl<'ctx> PondTableHandle<'ctx> {
|
||||
/// Get a handle on the `id` unique index on the table `pond`.
|
||||
pub fn id(&self) -> PondIdUnique<'ctx> {
|
||||
PondIdUnique {
|
||||
imp: self.imp.get_unique_constraint::<u32>("id"),
|
||||
phantom: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'ctx> PondIdUnique<'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<Pond> {
|
||||
self.imp.find(col_val)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||
|
||||
#![allow(unused, clippy::all)]
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
use super::player_or_bot_type::PlayerOrBot;
|
||||
use super::tile_type::Tile;
|
||||
|
||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||
#[sats(crate = __lib)]
|
||||
pub struct Pond {
|
||||
pub id: u32,
|
||||
pub owner: PlayerOrBot,
|
||||
pub tiles: Vec<Tile>,
|
||||
}
|
||||
|
||||
impl __sdk::InModule for Pond {
|
||||
type Module = super::RemoteModule;
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||
|
||||
#![allow(unused, clippy::all)]
|
||||
use super::hand_type::Hand;
|
||||
use super::player_or_bot_type::PlayerOrBot;
|
||||
use super::tile_type::Tile;
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
/// Table handle for the table `view_player_hand`.
|
||||
///
|
||||
/// Obtain a handle from the [`ViewPlayerHandTableAccess::view_player_hand`] method on [`super::RemoteTables`],
|
||||
/// like `ctx.db.view_player_hand()`.
|
||||
///
|
||||
/// Users are encouraged not to explicitly reference this type,
|
||||
/// but to directly chain method calls,
|
||||
/// like `ctx.db.view_player_hand().on_insert(...)`.
|
||||
pub struct ViewPlayerHandTableHandle<'ctx> {
|
||||
imp: __sdk::TableHandle<Hand>,
|
||||
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
/// Extension trait for access to the table `view_player_hand`.
|
||||
///
|
||||
/// Implemented for [`super::RemoteTables`].
|
||||
pub trait ViewPlayerHandTableAccess {
|
||||
#[allow(non_snake_case)]
|
||||
/// Obtain a [`ViewPlayerHandTableHandle`], which mediates access to the table `view_player_hand`.
|
||||
fn view_player_hand(&self) -> ViewPlayerHandTableHandle<'_>;
|
||||
}
|
||||
|
||||
impl ViewPlayerHandTableAccess for super::RemoteTables {
|
||||
fn view_player_hand(&self) -> ViewPlayerHandTableHandle<'_> {
|
||||
ViewPlayerHandTableHandle {
|
||||
imp: self.imp.get_table::<Hand>("view_player_hand"),
|
||||
ctx: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ViewPlayerHandInsertCallbackId(__sdk::CallbackId);
|
||||
pub struct ViewPlayerHandDeleteCallbackId(__sdk::CallbackId);
|
||||
|
||||
impl<'ctx> __sdk::Table for ViewPlayerHandTableHandle<'ctx> {
|
||||
type Row = Hand;
|
||||
type EventContext = super::EventContext;
|
||||
|
||||
fn count(&self) -> u64 {
|
||||
self.imp.count()
|
||||
}
|
||||
fn iter(&self) -> impl Iterator<Item = Hand> + '_ {
|
||||
self.imp.iter()
|
||||
}
|
||||
|
||||
type InsertCallbackId = ViewPlayerHandInsertCallbackId;
|
||||
|
||||
fn on_insert(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||
) -> ViewPlayerHandInsertCallbackId {
|
||||
ViewPlayerHandInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_insert(&self, callback: ViewPlayerHandInsertCallbackId) {
|
||||
self.imp.remove_on_insert(callback.0)
|
||||
}
|
||||
|
||||
type DeleteCallbackId = ViewPlayerHandDeleteCallbackId;
|
||||
|
||||
fn on_delete(
|
||||
&self,
|
||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
||||
) -> ViewPlayerHandDeleteCallbackId {
|
||||
ViewPlayerHandDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
||||
}
|
||||
|
||||
fn remove_on_delete(&self, callback: ViewPlayerHandDeleteCallbackId) {
|
||||
self.imp.remove_on_delete(callback.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
||||
let _table = client_cache.get_or_make_table::<Hand>("view_player_hand");
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub(super) fn parse_table_update(
|
||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
||||
) -> __sdk::Result<__sdk::TableUpdate<Hand>> {
|
||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
||||
__sdk::InternalError::failed_parse("TableUpdate<Hand>", "TableUpdate")
|
||||
.with_cause(e)
|
||||
.into()
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue