diff --git a/Cargo.lock b/Cargo.lock index 9d28fe1..f3d8fff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2217,15 +2217,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "convert_case" version = "0.10.0" @@ -2754,6 +2745,12 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" +[[package]] +name = "ecow" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78e4f79b296fbaab6ce2e22d52cb4c7f010fe0ebe7a32e34fa25885fd797bd02" + [[package]] name = "either" version = "1.15.0" @@ -4023,17 +4020,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "lean_string" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "962df00ba70ac8d5ca5c064e17e5c3d090c087fd8d21aa45096c716b169da514" -dependencies = [ - "castaway", - "itoa", - "ryu", -] - [[package]] name = "leb128fmt" version = "0.1.0" @@ -4323,9 +4309,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.14" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" dependencies = [ "libc", "log", @@ -4858,9 +4844,9 @@ dependencies = [ [[package]] name = "openssl-probe" -version = "0.1.6" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" [[package]] name = "openssl-sys" @@ -5765,12 +5751,12 @@ checksum = "4904c83c6e51f1b9b08bfa5a86f35a51798e8307186e6f5513852210a219c0bb" [[package]] name = "security-framework" -version = "2.11.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" dependencies = [ "bitflags 2.11.0", - "core-foundation 0.9.4", + "core-foundation 0.10.1", "core-foundation-sys", "libc", "security-framework-sys", @@ -6070,9 +6056,9 @@ dependencies = [ [[package]] name = "spacetimedb" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb9556aaf74b2bff490660cdb9681a45f84c648aa745a11d61ef38ee4245048" +checksum = "503ac8c991a76998d4ba699ef9b7f0085d3d7c363d1fcce4219314f909746bca" dependencies = [ "anyhow", "bytemuck", @@ -6093,9 +6079,9 @@ dependencies = [ [[package]] name = "spacetimedb-bindings-macro" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea86ac365c991dff6f468bf23d4dbec88ba3737fe07285a35ff047363cf4d16" +checksum = "1214628a7c29ee58255d511b7c4dbaaa463bc5022dba9401f264c1c85b5a891c" dependencies = [ "heck 0.4.1", "humantime", @@ -6107,18 +6093,18 @@ dependencies = [ [[package]] name = "spacetimedb-bindings-sys" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81c8920e17bc35bbdbe5195974df2f4778f9954907ec6d726693c8bc7b8f105c" +checksum = "d4777d90692bade6601887a21a074b71c157b34a92a5cfc8d5ecb46a0c571094" dependencies = [ "spacetimedb-primitives", ] [[package]] name = "spacetimedb-client-api-messages" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4e7c961c8180dfd02f1371aec33ff4d413788ed084810e2f3ef26be005e0f52" +checksum = "745d7ab0f81e3f6333d3ee353ce314b73841fbfe06adad69ab43efa791301da3" dependencies = [ "bytes", "bytestring", @@ -6138,9 +6124,9 @@ dependencies = [ [[package]] name = "spacetimedb-data-structures" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46af9a2830f4eeb1fd9cd3f43458a5acedc4e749317438a961299633514af47e" +checksum = "b5d85162537b1eeb6eac39383e34ca27aafcbf26987753172ca3de1de1e3a838" dependencies = [ "ahash", "crossbeam-queue", @@ -6153,9 +6139,9 @@ dependencies = [ [[package]] name = "spacetimedb-lib" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "580db5e0e718f52e98134e465088cc29d5f0fc2c8da3c812f0eb303d289bec5f" +checksum = "6c5e91c66b10dc38cce01928d3f77313276e34c635504e54afdec6f186a2fc9c" dependencies = [ "anyhow", "bitflags 2.11.0", @@ -6177,9 +6163,9 @@ dependencies = [ [[package]] name = "spacetimedb-memory-usage" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e6c3b3d6c002409a49660314ff359fc84b4ee7fdd3f868ee1cf6adf5bcbe2d4" +checksum = "eb9c081d3ffafa9c2fa11194b4ea3329773d979e342944b0128282bcbf5d3343" dependencies = [ "decorum", "ethnum", @@ -6187,9 +6173,9 @@ dependencies = [ [[package]] name = "spacetimedb-metrics" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00d469629100b1bd9d5a6ea2ab5c5f4aff8f63f631f20d39968cca909d5bad3c" +checksum = "985858969f693529c8624ce195cb747a34f7c84f3097418f595f795c0559fbd1" dependencies = [ "arrayvec", "itertools 0.12.1", @@ -6199,9 +6185,9 @@ dependencies = [ [[package]] name = "spacetimedb-primitives" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4adc6d5be578f5cf51179fc2ff26ba57125390610cc1ded51db417955ef4e4c" +checksum = "8f0321a161fa39f0937aceb436b47115cd811212799ddaf7996a8ecac3476d8d" dependencies = [ "bitflags 2.11.0", "either", @@ -6213,18 +6199,18 @@ dependencies = [ [[package]] name = "spacetimedb-query-builder" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d58043175057a72b22be6258d375d17f8bd9d344bc4d9a5f6d16c1244bb0769" +checksum = "9df8137b6dc2739d4efbc6218c5fb106f1e105a1345819a74053b677bd38c429" dependencies = [ "spacetimedb-lib", ] [[package]] name = "spacetimedb-sats" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9d1353d105fac30eb3b5f6a997a9028ad4e7cd7b6bcb48bca8c77687c17e556" +checksum = "f4e07b1bc933156b0cbe6b6c759e57381ce95df52c4522d9c3d71df59c01cf20" dependencies = [ "anyhow", "arrayvec", @@ -6239,7 +6225,6 @@ dependencies = [ "ethnum", "hex", "itertools 0.12.1", - "lean_string", "rand 0.9.2", "second-stack", "serde", @@ -6255,20 +6240,19 @@ dependencies = [ [[package]] name = "spacetimedb-schema" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f72983323b38e3966c70cf57c50ac0fbf54b6648f65f7ef1a02a2456c5725af" +checksum = "c2763b4769028f111032f00b35635f6cbb0562f54a59d05775f5ea66d7b8f8d2" dependencies = [ "anyhow", - "convert_case 0.6.0", "derive_more 0.99.20", + "ecow", "enum-as-inner", "enum-map", "indexmap 2.13.0", "insta", "itertools 0.12.1", "lazy_static", - "lean_string", "petgraph 0.6.5", "serde_json", "smallvec", @@ -6286,9 +6270,9 @@ dependencies = [ [[package]] name = "spacetimedb-sdk" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8dd5a40d5aa7893ed1c71d73b7103b0326d1e4294c3c63fbd82a05754e15eae" +checksum = "243f7b433aa0ba1d665aeb9db397b9bd40698d80817840d8fa8d8bfe74e99f00" dependencies = [ "anymap", "base64 0.21.7", @@ -6300,7 +6284,6 @@ dependencies = [ "home", "http", "log", - "native-tls", "once_cell", "prometheus", "rand 0.9.2", @@ -6318,9 +6301,9 @@ dependencies = [ [[package]] name = "spacetimedb-sql-parser" -version = "2.0.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ddf20b921097b6233ab3205101833ed8a1b795358ae3feaa81a5c29cc452aea" +checksum = "98cd63f69d4d6b074771830d8f8d12ce52c253179940c1bd02a50adeba7a9485" dependencies = [ "derive_more 0.99.20", "spacetimedb-lib", diff --git a/Cargo.toml b/Cargo.toml index cb5202b..1c9bb29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,9 +12,10 @@ bevy.default-features = false bevy_ratatui = "0.11.1" bevy_spacetimedb = "0.7" -spacetimedb.version = "2.0.1" +spacetimedb.version = "1.12.*" spacetimedb.features = ["unstable"] -spacetimedb-sdk = "2.0.1" + +spacetimedb-sdk = "1.12.*" strum.version = "0.27.2" strum.features = ["derive"] diff --git a/jong-db/src/db/add_bot_reducer.rs b/jong-db/src/db/add_bot_reducer.rs index 364d021..eccf63a 100644 --- a/jong-db/src/db/add_bot_reducer.rs +++ b/jong-db/src/db/add_bot_reducer.rs @@ -22,6 +22,8 @@ impl __sdk::InModule for AddBotArgs { type Module = super::RemoteModule; } +pub struct AddBotCallbackId(__sdk::CallbackId); + #[allow(non_camel_case_types)] /// Extension trait for access to the reducer `add_bot`. /// @@ -31,38 +33,72 @@ pub trait add_bot { /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and this method provides no way to listen for its completion status. - /// /// Use [`add_bot:add_bot_then`] to run a callback after the reducer completes. - fn add_bot(&self, lobby_id: u32) -> __sdk::Result<()> { - self.add_bot_then(lobby_id, |_, _| {}) - } - - /// Request that the remote module invoke the reducer `add_bot` to run as soon as possible, - /// registering `callback` to run when we are notified that the reducer completed. + /// and its status can be observed by listening for [`Self::on_add_bot`] callbacks. + 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`. /// - /// 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 with the `callback`. - fn add_bot_then( + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`AddBotCallbackId`] can be passed to [`Self::remove_on_add_bot`] + /// to cancel the callback. + fn on_add_bot( &self, - lobby_id: u32, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()>; + callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static, + ) -> AddBotCallbackId; + /// Cancel a callback previously registered by [`Self::on_add_bot`], + /// causing it not to run in the future. + fn remove_on_add_bot(&self, callback: AddBotCallbackId); } impl add_bot for super::RemoteReducers { - fn add_bot_then( + fn add_bot(&self, lobby_id: u32) -> __sdk::Result<()> { + self.imp.call_reducer("add_bot", AddBotArgs { lobby_id }) + } + fn on_add_bot( &self, - lobby_id: u32, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()> { - self.imp - .invoke_reducer_with_callback(AddBotArgs { lobby_id }, callback) + mut callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static, + ) -> AddBotCallbackId { + AddBotCallbackId(self.imp.on_reducer( + "add_bot", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::AddBot { lobby_id }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, lobby_id) + }), + )) + } + fn remove_on_add_bot(&self, callback: AddBotCallbackId) { + self.imp.remove_on_reducer("add_bot", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `add_bot`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_add_bot { + /// Set the call-reducer flags for the reducer `add_bot` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn add_bot(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_add_bot for super::SetReducerFlags { + fn add_bot(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("add_bot", flags); } } diff --git a/jong-db/src/db/advance_game_reducer.rs b/jong-db/src/db/advance_game_reducer.rs index d8e3ce9..a35faad 100644 --- a/jong-db/src/db/advance_game_reducer.rs +++ b/jong-db/src/db/advance_game_reducer.rs @@ -24,6 +24,8 @@ 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`. /// @@ -33,38 +35,73 @@ pub trait advance_game { /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and this method provides no way to listen for its completion status. - /// /// Use [`advance_game:advance_game_then`] to run a callback after the reducer completes. - fn advance_game(&self, game_timer: GameTimer) -> __sdk::Result<()> { - self.advance_game_then(game_timer, |_, _| {}) - } - - /// Request that the remote module invoke the reducer `advance_game` to run as soon as possible, - /// registering `callback` to run when we are notified that the reducer completed. + /// 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`. /// - /// 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 with the `callback`. - fn advance_game_then( + /// 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, - game_timer: GameTimer, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()>; + 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_then( - &self, - game_timer: GameTimer, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()> { + fn advance_game(&self, game_timer: GameTimer) -> __sdk::Result<()> { self.imp - .invoke_reducer_with_callback(AdvanceGameArgs { game_timer }, callback) + .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); } } diff --git a/jong-db/src/db/bot_table.rs b/jong-db/src/db/bot_table.rs index 0c81cf5..d062239 100644 --- a/jong-db/src/db/bot_table.rs +++ b/jong-db/src/db/bot_table.rs @@ -80,6 +80,11 @@ impl<'ctx> __sdk::Table for BotTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("bot"); + _table.add_unique_constraint::("id", |row| &row.id); +} pub struct BotUpdateCallbackId(__sdk::CallbackId); impl<'ctx> __sdk::TableWithPrimaryKey for BotTableHandle<'ctx> { @@ -97,6 +102,17 @@ impl<'ctx> __sdk::TableWithPrimaryKey for BotTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + /// Access to the `id` unique index on the table `bot`, /// which allows point queries on the field of the same name /// via the [`BotIdUnique::find`] method. @@ -127,23 +143,6 @@ impl<'ctx> BotIdUnique<'ctx> { } } -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("bot"); - _table.add_unique_constraint::("id", |row| &row.id); -} - -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::v2::TableUpdate, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} - #[allow(non_camel_case_types)] /// Extension trait for query builder access to the table `Bot`. /// diff --git a/jong-db/src/db/bot_type.rs b/jong-db/src/db/bot_type.rs index 5981868..58acb75 100644 --- a/jong-db/src/db/bot_type.rs +++ b/jong-db/src/db/bot_type.rs @@ -65,5 +65,3 @@ impl __sdk::__query_builder::HasIxCols for Bot { } } } - -impl __sdk::__query_builder::CanBeLookupTable for Bot {} diff --git a/jong-db/src/db/clear_all_reducer.rs b/jong-db/src/db/clear_all_reducer.rs index 49a6454..5870024 100644 --- a/jong-db/src/db/clear_all_reducer.rs +++ b/jong-db/src/db/clear_all_reducer.rs @@ -18,6 +18,8 @@ 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`. /// @@ -27,36 +29,72 @@ pub trait clear_all { /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and this method provides no way to listen for its completion status. - /// /// Use [`clear_all:clear_all_then`] to run a callback after the reducer completes. - fn clear_all(&self) -> __sdk::Result<()> { - self.clear_all_then(|_, _| {}) - } - - /// Request that the remote module invoke the reducer `clear_all` to run as soon as possible, - /// registering `callback` to run when we are notified that the reducer completed. + /// 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`. /// - /// 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 with the `callback`. - fn clear_all_then( + /// 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 FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()>; + 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_then( + fn clear_all(&self) -> __sdk::Result<()> { + self.imp.call_reducer("clear_all", ClearAllArgs {}) + } + fn on_clear_all( &self, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()> { - self.imp - .invoke_reducer_with_callback(ClearAllArgs {}, callback) + 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); } } diff --git a/jong-db/src/db/connect_reducer.rs b/jong-db/src/db/connect_reducer.rs new file mode 100644 index 0000000..a59a446 --- /dev/null +++ b/jong-db/src/db/connect_reducer.rs @@ -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 ConnectArgs {} + +impl From 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); + } +} diff --git a/jong-db/src/db/db_tile_type.rs b/jong-db/src/db/db_tile_type.rs index d4fd63d..9bd4f8e 100644 --- a/jong-db/src/db/db_tile_type.rs +++ b/jong-db/src/db/db_tile_type.rs @@ -50,5 +50,3 @@ impl __sdk::__query_builder::HasIxCols for DbTile { } } } - -impl __sdk::__query_builder::CanBeLookupTable for DbTile {} diff --git a/jong-db/src/db/db_wall_type.rs b/jong-db/src/db/db_wall_type.rs index 6d46d7f..47ec2cc 100644 --- a/jong-db/src/db/db_wall_type.rs +++ b/jong-db/src/db/db_wall_type.rs @@ -50,5 +50,3 @@ impl __sdk::__query_builder::HasIxCols for DbWall { } } } - -impl __sdk::__query_builder::CanBeLookupTable for DbWall {} diff --git a/jong-db/src/db/discard_tile_reducer.rs b/jong-db/src/db/discard_tile_reducer.rs index 43f0cbb..c3bcb15 100644 --- a/jong-db/src/db/discard_tile_reducer.rs +++ b/jong-db/src/db/discard_tile_reducer.rs @@ -22,6 +22,8 @@ impl __sdk::InModule for DiscardTileArgs { type Module = super::RemoteModule; } +pub struct DiscardTileCallbackId(__sdk::CallbackId); + #[allow(non_camel_case_types)] /// Extension trait for access to the reducer `discard_tile`. /// @@ -31,38 +33,73 @@ pub trait discard_tile { /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and this method provides no way to listen for its completion status. - /// /// Use [`discard_tile:discard_tile_then`] to run a callback after the reducer completes. - fn discard_tile(&self, tile_id: u32) -> __sdk::Result<()> { - self.discard_tile_then(tile_id, |_, _| {}) - } - - /// Request that the remote module invoke the reducer `discard_tile` to run as soon as possible, - /// registering `callback` to run when we are notified that the reducer completed. + /// and its status can be observed by listening for [`Self::on_discard_tile`] callbacks. + 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`. /// - /// 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 with the `callback`. - fn discard_tile_then( + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`DiscardTileCallbackId`] can be passed to [`Self::remove_on_discard_tile`] + /// to cancel the callback. + fn on_discard_tile( &self, - tile_id: u32, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()>; + callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static, + ) -> DiscardTileCallbackId; + /// Cancel a callback previously registered by [`Self::on_discard_tile`], + /// causing it not to run in the future. + fn remove_on_discard_tile(&self, callback: DiscardTileCallbackId); } impl discard_tile for super::RemoteReducers { - fn discard_tile_then( - &self, - tile_id: u32, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()> { + fn discard_tile(&self, tile_id: u32) -> __sdk::Result<()> { self.imp - .invoke_reducer_with_callback(DiscardTileArgs { tile_id }, callback) + .call_reducer("discard_tile", DiscardTileArgs { tile_id }) + } + fn on_discard_tile( + &self, + mut callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static, + ) -> DiscardTileCallbackId { + DiscardTileCallbackId(self.imp.on_reducer( + "discard_tile", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::DiscardTile { tile_id }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, tile_id) + }), + )) + } + fn remove_on_discard_tile(&self, callback: DiscardTileCallbackId) { + self.imp.remove_on_reducer("discard_tile", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `discard_tile`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_discard_tile { + /// Set the call-reducer flags for the reducer `discard_tile` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn discard_tile(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_discard_tile for super::SetReducerFlags { + fn discard_tile(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("discard_tile", flags); } } diff --git a/jong-db/src/db/disconnect_reducer.rs b/jong-db/src/db/disconnect_reducer.rs new file mode 100644 index 0000000..026d4b1 --- /dev/null +++ b/jong-db/src/db/disconnect_reducer.rs @@ -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 DisconnectArgs {} + +impl From 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); + } +} diff --git a/jong-db/src/db/game_timer_table.rs b/jong-db/src/db/game_timer_table.rs index 2aa5ed2..9d29ade 100644 --- a/jong-db/src/db/game_timer_table.rs +++ b/jong-db/src/db/game_timer_table.rs @@ -78,6 +78,12 @@ impl<'ctx> __sdk::Table for GameTimerTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("game_timer"); + _table.add_unique_constraint::("id", |row| &row.id); + _table.add_unique_constraint::("lobby_id", |row| &row.lobby_id); +} pub struct GameTimerUpdateCallbackId(__sdk::CallbackId); impl<'ctx> __sdk::TableWithPrimaryKey for GameTimerTableHandle<'ctx> { @@ -95,6 +101,17 @@ impl<'ctx> __sdk::TableWithPrimaryKey for GameTimerTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "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. @@ -155,24 +172,6 @@ impl<'ctx> GameTimerLobbyIdUnique<'ctx> { } } -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("game_timer"); - _table.add_unique_constraint::("id", |row| &row.id); - _table.add_unique_constraint::("lobby_id", |row| &row.lobby_id); -} - -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::v2::TableUpdate, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} - #[allow(non_camel_case_types)] /// Extension trait for query builder access to the table `GameTimer`. /// diff --git a/jong-db/src/db/game_timer_type.rs b/jong-db/src/db/game_timer_type.rs index 31d3fa3..80b8a73 100644 --- a/jong-db/src/db/game_timer_type.rs +++ b/jong-db/src/db/game_timer_type.rs @@ -53,5 +53,3 @@ impl __sdk::__query_builder::HasIxCols for GameTimer { } } } - -impl __sdk::__query_builder::CanBeLookupTable for GameTimer {} diff --git a/jong-db/src/db/join_or_create_lobby_reducer.rs b/jong-db/src/db/join_or_create_lobby_reducer.rs index aaeb31c..2545903 100644 --- a/jong-db/src/db/join_or_create_lobby_reducer.rs +++ b/jong-db/src/db/join_or_create_lobby_reducer.rs @@ -22,6 +22,8 @@ impl __sdk::InModule for JoinOrCreateLobbyArgs { type Module = super::RemoteModule; } +pub struct JoinOrCreateLobbyCallbackId(__sdk::CallbackId); + #[allow(non_camel_case_types)] /// Extension trait for access to the reducer `join_or_create_lobby`. /// @@ -31,38 +33,75 @@ pub trait join_or_create_lobby { /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and this method provides no way to listen for its completion status. - /// /// Use [`join_or_create_lobby:join_or_create_lobby_then`] to run a callback after the reducer completes. - fn join_or_create_lobby(&self, lobby_id: u32) -> __sdk::Result<()> { - self.join_or_create_lobby_then(lobby_id, |_, _| {}) - } - - /// Request that the remote module invoke the reducer `join_or_create_lobby` to run as soon as possible, - /// registering `callback` to run when we are notified that the reducer completed. + /// 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<()>; + /// Register a callback to run whenever we are notified of an invocation of the reducer `join_or_create_lobby`. /// - /// 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 with the `callback`. - fn join_or_create_lobby_then( + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`JoinOrCreateLobbyCallbackId`] can be passed to [`Self::remove_on_join_or_create_lobby`] + /// to cancel the callback. + fn on_join_or_create_lobby( &self, - lobby_id: u32, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()>; + callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static, + ) -> JoinOrCreateLobbyCallbackId; + /// Cancel a callback previously registered by [`Self::on_join_or_create_lobby`], + /// causing it not to run in the future. + fn remove_on_join_or_create_lobby(&self, callback: JoinOrCreateLobbyCallbackId); } impl join_or_create_lobby for super::RemoteReducers { - fn join_or_create_lobby_then( - &self, - lobby_id: u32, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()> { + fn join_or_create_lobby(&self, lobby_id: u32) -> __sdk::Result<()> { self.imp - .invoke_reducer_with_callback(JoinOrCreateLobbyArgs { lobby_id }, callback) + .call_reducer("join_or_create_lobby", JoinOrCreateLobbyArgs { lobby_id }) + } + fn on_join_or_create_lobby( + &self, + mut callback: impl FnMut(&super::ReducerEventContext, &u32) + Send + 'static, + ) -> JoinOrCreateLobbyCallbackId { + JoinOrCreateLobbyCallbackId(self.imp.on_reducer( + "join_or_create_lobby", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::JoinOrCreateLobby { lobby_id }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, lobby_id) + }), + )) + } + fn remove_on_join_or_create_lobby(&self, callback: JoinOrCreateLobbyCallbackId) { + self.imp + .remove_on_reducer("join_or_create_lobby", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `join_or_create_lobby`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_join_or_create_lobby { + /// Set the call-reducer flags for the reducer `join_or_create_lobby` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn join_or_create_lobby(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_join_or_create_lobby for super::SetReducerFlags { + fn join_or_create_lobby(&self, flags: __ws::CallReducerFlags) { + self.imp + .set_call_reducer_flags("join_or_create_lobby", flags); } } diff --git a/jong-db/src/db/lobby_table.rs b/jong-db/src/db/lobby_table.rs index 696c723..8d7f499 100644 --- a/jong-db/src/db/lobby_table.rs +++ b/jong-db/src/db/lobby_table.rs @@ -80,6 +80,11 @@ impl<'ctx> __sdk::Table for LobbyTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("lobby"); + _table.add_unique_constraint::("id", |row| &row.id); +} pub struct LobbyUpdateCallbackId(__sdk::CallbackId); impl<'ctx> __sdk::TableWithPrimaryKey for LobbyTableHandle<'ctx> { @@ -97,6 +102,17 @@ impl<'ctx> __sdk::TableWithPrimaryKey for LobbyTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + /// Access to the `id` unique index on the table `lobby`, /// which allows point queries on the field of the same name /// via the [`LobbyIdUnique::find`] method. @@ -127,23 +143,6 @@ impl<'ctx> LobbyIdUnique<'ctx> { } } -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("lobby"); - _table.add_unique_constraint::("id", |row| &row.id); -} - -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::v2::TableUpdate, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} - #[allow(non_camel_case_types)] /// Extension trait for query builder access to the table `Lobby`. /// diff --git a/jong-db/src/db/lobby_type.rs b/jong-db/src/db/lobby_type.rs index 942a58a..af8dda7 100644 --- a/jong-db/src/db/lobby_type.rs +++ b/jong-db/src/db/lobby_type.rs @@ -60,5 +60,3 @@ impl __sdk::__query_builder::HasIxCols for Lobby { } } } - -impl __sdk::__query_builder::CanBeLookupTable for Lobby {} diff --git a/jong-db/src/db/logged_out_player_table.rs b/jong-db/src/db/logged_out_player_table.rs new file mode 100644 index 0000000..1de7240 --- /dev/null +++ b/jong-db/src/db/logged_out_player_table.rs @@ -0,0 +1,191 @@ +// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE +// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. + +#![allow(unused, clippy::all)] +use super::player_type::Player; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `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, + 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::("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 + '_ { + 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) { + let _table = client_cache.get_or_make_table::("logged_out_player"); + _table.add_unique_constraint::("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> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "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, + 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::("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 { + 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, + 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 { + self.imp.find(col_val) + } +} + +#[allow(non_camel_case_types)] +/// Extension trait for query builder access to the table `Player`. +/// +/// Implemented for [`__sdk::QueryTableAccessor`]. +pub trait logged_out_playerQueryTableAccess { + #[allow(non_snake_case)] + /// Get a query builder for the table `Player`. + fn logged_out_player(&self) -> __sdk::__query_builder::Table; +} + +impl logged_out_playerQueryTableAccess for __sdk::QueryTableAccessor { + fn logged_out_player(&self) -> __sdk::__query_builder::Table { + __sdk::__query_builder::Table::new("logged_out_player") + } +} diff --git a/jong-db/src/db/mod.rs b/jong-db/src/db/mod.rs index 234f175..0f928b7 100644 --- a/jong-db/src/db/mod.rs +++ b/jong-db/src/db/mod.rs @@ -1,7 +1,7 @@ // THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE // WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD. -// This was generated using spacetimedb cli version 2.0.1 (commit a4d29daec8ed35ce4913a335b7210b9ae3933d00). +// This was generated using spacetimedb cli version 1.12.0 (commit 4fdb8d923f39ed592931ad4c7e6391ed99b9fe3a). #![allow(unused, clippy::all)] use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; @@ -11,9 +11,11 @@ pub mod advance_game_reducer; pub mod bot_table; pub mod bot_type; pub mod clear_all_reducer; +pub mod connect_reducer; pub mod db_tile_type; pub mod db_wall_type; pub mod discard_tile_reducer; +pub mod disconnect_reducer; pub mod dragon_type; pub mod game_state_type; pub mod game_timer_table; @@ -22,8 +24,10 @@ pub mod hand_view_type; pub mod join_or_create_lobby_reducer; pub mod lobby_table; pub mod lobby_type; +pub mod logged_out_player_table; pub mod player_clock_table; pub mod player_clock_type; +pub mod player_hand_table; pub mod player_hand_type; pub mod player_or_bot_type; pub mod player_table; @@ -31,41 +35,51 @@ pub mod player_type; pub mod rank_type; pub mod set_ready_reducer; 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; -pub use add_bot_reducer::add_bot; -pub use advance_game_reducer::advance_game; +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 bot_table::*; pub use bot_type::Bot; -pub use clear_all_reducer::clear_all; +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 db_tile_type::DbTile; pub use db_wall_type::DbWall; -pub use discard_tile_reducer::discard_tile; +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 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; +pub use join_or_create_lobby_reducer::{ + join_or_create_lobby, set_flags_for_join_or_create_lobby, JoinOrCreateLobbyCallbackId, +}; pub use lobby_table::*; pub use lobby_type::Lobby; +pub use logged_out_player_table::*; pub use player_clock_table::*; pub use player_clock_type::PlayerClock; +pub use player_hand_table::*; pub use player_hand_type::PlayerHand; pub use player_or_bot_type::PlayerOrBot; pub use player_table::*; pub use player_type::Player; pub use rank_type::Rank; -pub use set_ready_reducer::set_ready; +pub use set_ready_reducer::{set_flags_for_set_ready, set_ready, SetReadyCallbackId}; 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; #[derive(Clone, PartialEq, Debug)] @@ -79,7 +93,9 @@ pub enum Reducer { AddBot { lobby_id: u32 }, AdvanceGame { game_timer: GameTimer }, ClearAll, + Connect, DiscardTile { tile_id: u32 }, + Disconnect, JoinOrCreateLobby { lobby_id: u32 }, SetReady { ready: bool }, } @@ -94,40 +110,74 @@ impl __sdk::Reducer for Reducer { Reducer::AddBot { .. } => "add_bot", Reducer::AdvanceGame { .. } => "advance_game", Reducer::ClearAll => "clear_all", + Reducer::Connect => "connect", Reducer::DiscardTile { .. } => "discard_tile", + Reducer::Disconnect => "disconnect", Reducer::JoinOrCreateLobby { .. } => "join_or_create_lobby", Reducer::SetReady { .. } => "set_ready", _ => unreachable!(), } } - #[allow(clippy::clone_on_copy)] - fn args_bsatn(&self) -> Result, __sats::bsatn::EncodeError> { - match self { - Reducer::AddBot { lobby_id } => __sats::bsatn::to_vec(&add_bot_reducer::AddBotArgs { - lobby_id: lobby_id.clone(), - }), - Reducer::AdvanceGame { game_timer } => { - __sats::bsatn::to_vec(&advance_game_reducer::AdvanceGameArgs { - game_timer: game_timer.clone(), - }) +} +impl TryFrom<__ws::ReducerCallInfo<__ws::BsatnFormat>> for Reducer { + type Error = __sdk::Error; + fn try_from(value: __ws::ReducerCallInfo<__ws::BsatnFormat>) -> __sdk::Result { + match &value.reducer_name[..] { + "add_bot" => Ok(__sdk::parse_reducer_args::( + "add_bot", + &value.args, + )? + .into()), + "advance_game" => Ok( + __sdk::parse_reducer_args::( + "advance_game", + &value.args, + )? + .into(), + ), + "clear_all" => Ok( + __sdk::parse_reducer_args::( + "clear_all", + &value.args, + )? + .into(), + ), + "connect" => Ok(__sdk::parse_reducer_args::( + "connect", + &value.args, + )? + .into()), + "discard_tile" => Ok( + __sdk::parse_reducer_args::( + "discard_tile", + &value.args, + )? + .into(), + ), + "disconnect" => Ok( + __sdk::parse_reducer_args::( + "disconnect", + &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()), + "set_ready" => Ok( + __sdk::parse_reducer_args::( + "set_ready", + &value.args, + )? + .into(), + ), + unknown => { + Err( + __sdk::InternalError::unknown_name("reducer", unknown, "ReducerCallInfo") + .into(), + ) } - Reducer::ClearAll => __sats::bsatn::to_vec(&clear_all_reducer::ClearAllArgs {}), - Reducer::DiscardTile { tile_id } => { - __sats::bsatn::to_vec(&discard_tile_reducer::DiscardTileArgs { - tile_id: tile_id.clone(), - }) - } - Reducer::JoinOrCreateLobby { lobby_id } => { - __sats::bsatn::to_vec(&join_or_create_lobby_reducer::JoinOrCreateLobbyArgs { - lobby_id: lobby_id.clone(), - }) - } - Reducer::SetReady { ready } => { - __sats::bsatn::to_vec(&set_ready_reducer::SetReadyArgs { - ready: ready.clone(), - }) - } - _ => unreachable!(), } } } @@ -139,17 +189,21 @@ pub struct DbUpdate { bot: __sdk::TableUpdate, game_timer: __sdk::TableUpdate, lobby: __sdk::TableUpdate, + logged_out_player: __sdk::TableUpdate, player: __sdk::TableUpdate, player_clock: __sdk::TableUpdate, + player_hand: __sdk::TableUpdate, + tile: __sdk::TableUpdate, view_closed_hands: __sdk::TableUpdate, view_hand: __sdk::TableUpdate, + wall: __sdk::TableUpdate, } -impl TryFrom<__ws::v2::TransactionUpdate> for DbUpdate { +impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate { type Error = __sdk::Error; - fn try_from(raw: __ws::v2::TransactionUpdate) -> Result { + fn try_from(raw: __ws::DatabaseUpdate<__ws::BsatnFormat>) -> Result { let mut db_update = DbUpdate::default(); - for table_update in __sdk::transaction_update_iter_table_updates(raw) { + for table_update in raw.tables { match &table_update.table_name[..] { "bot" => db_update .bot @@ -160,18 +214,30 @@ impl TryFrom<__ws::v2::TransactionUpdate> for DbUpdate { "lobby" => db_update .lobby .append(lobby_table::parse_table_update(table_update)?), + "logged_out_player" => db_update + .logged_out_player + .append(logged_out_player_table::parse_table_update(table_update)?), "player" => db_update .player .append(player_table::parse_table_update(table_update)?), "player_clock" => db_update .player_clock .append(player_clock_table::parse_table_update(table_update)?), + "player_hand" => db_update + .player_hand + .append(player_hand_table::parse_table_update(table_update)?), + "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)?), + "wall" => db_update + .wall + .append(wall_table::parse_table_update(table_update)?), unknown => { return Err(__sdk::InternalError::unknown_name( @@ -207,86 +273,30 @@ impl __sdk::DbUpdate for DbUpdate { diff.lobby = cache .apply_diff_to_table::("lobby", &self.lobby) .with_updates_by_pk(|row| &row.id); + diff.logged_out_player = cache + .apply_diff_to_table::("logged_out_player", &self.logged_out_player) + .with_updates_by_pk(|row| &row.identity); diff.player = cache .apply_diff_to_table::("player", &self.player) .with_updates_by_pk(|row| &row.identity); diff.player_clock = cache .apply_diff_to_table::("player_clock", &self.player_clock) .with_updates_by_pk(|row| &row.id); + diff.player_hand = cache + .apply_diff_to_table::("player_hand", &self.player_hand) + .with_updates_by_pk(|row| &row.id); + diff.tile = cache + .apply_diff_to_table::("tile", &self.tile) + .with_updates_by_pk(|row| &row.id); + diff.wall = cache + .apply_diff_to_table::("wall", &self.wall) + .with_updates_by_pk(|row| &row.lobby_id); diff.view_closed_hands = cache.apply_diff_to_table::("view_closed_hands", &self.view_closed_hands); diff.view_hand = cache.apply_diff_to_table::("view_hand", &self.view_hand); diff } - fn parse_initial_rows(raw: __ws::v2::QueryRows) -> __sdk::Result { - let mut db_update = DbUpdate::default(); - for table_rows in raw.tables { - match &table_rows.table[..] { - "bot" => db_update - .bot - .append(__sdk::parse_row_list_as_inserts(table_rows.rows)?), - "game_timer" => db_update - .game_timer - .append(__sdk::parse_row_list_as_inserts(table_rows.rows)?), - "lobby" => db_update - .lobby - .append(__sdk::parse_row_list_as_inserts(table_rows.rows)?), - "player" => db_update - .player - .append(__sdk::parse_row_list_as_inserts(table_rows.rows)?), - "player_clock" => db_update - .player_clock - .append(__sdk::parse_row_list_as_inserts(table_rows.rows)?), - "view_closed_hands" => db_update - .view_closed_hands - .append(__sdk::parse_row_list_as_inserts(table_rows.rows)?), - "view_hand" => db_update - .view_hand - .append(__sdk::parse_row_list_as_inserts(table_rows.rows)?), - unknown => { - return Err( - __sdk::InternalError::unknown_name("table", unknown, "QueryRows").into(), - ); - } - } - } - Ok(db_update) - } - fn parse_unsubscribe_rows(raw: __ws::v2::QueryRows) -> __sdk::Result { - let mut db_update = DbUpdate::default(); - for table_rows in raw.tables { - match &table_rows.table[..] { - "bot" => db_update - .bot - .append(__sdk::parse_row_list_as_deletes(table_rows.rows)?), - "game_timer" => db_update - .game_timer - .append(__sdk::parse_row_list_as_deletes(table_rows.rows)?), - "lobby" => db_update - .lobby - .append(__sdk::parse_row_list_as_deletes(table_rows.rows)?), - "player" => db_update - .player - .append(__sdk::parse_row_list_as_deletes(table_rows.rows)?), - "player_clock" => db_update - .player_clock - .append(__sdk::parse_row_list_as_deletes(table_rows.rows)?), - "view_closed_hands" => db_update - .view_closed_hands - .append(__sdk::parse_row_list_as_deletes(table_rows.rows)?), - "view_hand" => db_update - .view_hand - .append(__sdk::parse_row_list_as_deletes(table_rows.rows)?), - unknown => { - return Err( - __sdk::InternalError::unknown_name("table", unknown, "QueryRows").into(), - ); - } - } - } - Ok(db_update) - } } #[derive(Default)] @@ -296,10 +306,14 @@ pub struct AppliedDiff<'r> { bot: __sdk::TableAppliedDiff<'r, Bot>, game_timer: __sdk::TableAppliedDiff<'r, GameTimer>, lobby: __sdk::TableAppliedDiff<'r, Lobby>, + logged_out_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>, view_closed_hands: __sdk::TableAppliedDiff<'r, HandView>, view_hand: __sdk::TableAppliedDiff<'r, PlayerHand>, + wall: __sdk::TableAppliedDiff<'r, DbWall>, __unused: std::marker::PhantomData<&'r ()>, } @@ -316,18 +330,26 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> { callbacks.invoke_table_row_callbacks::("bot", &self.bot, event); callbacks.invoke_table_row_callbacks::("game_timer", &self.game_timer, event); callbacks.invoke_table_row_callbacks::("lobby", &self.lobby, event); + callbacks.invoke_table_row_callbacks::( + "logged_out_player", + &self.logged_out_player, + event, + ); callbacks.invoke_table_row_callbacks::("player", &self.player, event); callbacks.invoke_table_row_callbacks::( "player_clock", &self.player_clock, event, ); + callbacks.invoke_table_row_callbacks::("player_hand", &self.player_hand, event); + callbacks.invoke_table_row_callbacks::("tile", &self.tile, event); callbacks.invoke_table_row_callbacks::( "view_closed_hands", &self.view_closed_hands, event, ); callbacks.invoke_table_row_callbacks::("view_hand", &self.view_hand, event); + callbacks.invoke_table_row_callbacks::("wall", &self.wall, event); } } @@ -358,6 +380,20 @@ impl __sdk::InModule for RemoteProcedures { type Module = RemoteModule; } +#[doc(hidden)] +/// The `set_reducer_flags` field of [`DbConnection`], +/// with methods provided by extension traits for each reducer defined by the module. +/// Each method sets the flags for the reducer with the same name. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub struct SetReducerFlags { + imp: __sdk::DbContextImpl, +} + +impl __sdk::InModule for SetReducerFlags { + type Module = RemoteModule; +} + /// The `db` field of [`EventContext`] and [`DbConnection`], /// with methods provided by extension traits for each table defined by the module. pub struct RemoteTables { @@ -390,6 +426,11 @@ pub struct DbConnection { /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. pub reducers: RemoteReducers, #[doc(hidden)] + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. pub procedures: RemoteProcedures, @@ -405,6 +446,7 @@ impl __sdk::DbContext for DbConnection { type DbView = RemoteTables; type Reducers = RemoteReducers; type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { &self.db @@ -415,6 +457,9 @@ impl __sdk::DbContext for DbConnection { fn procedures(&self) -> &Self::Procedures { &self.procedures } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } fn is_active(&self) -> bool { self.imp.is_active() @@ -518,6 +563,7 @@ impl __sdk::DbConnection for DbConnection { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, procedures: RemoteProcedures { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, imp, } } @@ -569,6 +615,7 @@ pub trait RemoteDbContext: __sdk::DbContext< DbView = RemoteTables, Reducers = RemoteReducers, + SetReducerFlags = SetReducerFlags, SubscriptionBuilder = __sdk::SubscriptionBuilder, > { @@ -577,6 +624,7 @@ impl< Ctx: __sdk::DbContext< DbView = RemoteTables, Reducers = RemoteReducers, + SetReducerFlags = SetReducerFlags, SubscriptionBuilder = __sdk::SubscriptionBuilder, >, > RemoteDbContext for Ctx @@ -590,6 +638,11 @@ pub struct EventContext { pub db: RemoteTables, /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. pub procedures: RemoteProcedures, /// The event which caused these callbacks to run. @@ -606,6 +659,7 @@ impl __sdk::AbstractEventContext for EventContext { Self { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, procedures: RemoteProcedures { imp: imp.clone() }, event, imp, @@ -621,6 +675,7 @@ impl __sdk::DbContext for EventContext { type DbView = RemoteTables; type Reducers = RemoteReducers; type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { &self.db @@ -631,6 +686,9 @@ impl __sdk::DbContext for EventContext { fn procedures(&self) -> &Self::Procedures { &self.procedures } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } fn is_active(&self) -> bool { self.imp.is_active() @@ -666,6 +724,11 @@ pub struct ReducerEventContext { pub db: RemoteTables, /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. pub procedures: RemoteProcedures, /// The event which caused these callbacks to run. @@ -682,6 +745,7 @@ impl __sdk::AbstractEventContext for ReducerEventContext { Self { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, procedures: RemoteProcedures { imp: imp.clone() }, event, imp, @@ -697,6 +761,7 @@ impl __sdk::DbContext for ReducerEventContext { type DbView = RemoteTables; type Reducers = RemoteReducers; type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { &self.db @@ -707,6 +772,9 @@ impl __sdk::DbContext for ReducerEventContext { fn procedures(&self) -> &Self::Procedures { &self.procedures } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } fn is_active(&self) -> bool { self.imp.is_active() @@ -741,6 +809,11 @@ pub struct ProcedureEventContext { pub db: RemoteTables, /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. pub procedures: RemoteProcedures, imp: __sdk::DbContextImpl, @@ -756,6 +829,7 @@ impl __sdk::AbstractEventContext for ProcedureEventContext { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, procedures: RemoteProcedures { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, imp, } } @@ -769,6 +843,7 @@ impl __sdk::DbContext for ProcedureEventContext { type DbView = RemoteTables; type Reducers = RemoteReducers; type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { &self.db @@ -779,6 +854,9 @@ impl __sdk::DbContext for ProcedureEventContext { fn procedures(&self) -> &Self::Procedures { &self.procedures } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } fn is_active(&self) -> bool { self.imp.is_active() @@ -813,6 +891,11 @@ pub struct SubscriptionEventContext { pub db: RemoteTables, /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. pub procedures: RemoteProcedures, imp: __sdk::DbContextImpl, @@ -828,6 +911,7 @@ impl __sdk::AbstractEventContext for SubscriptionEventContext { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, procedures: RemoteProcedures { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, imp, } } @@ -841,6 +925,7 @@ impl __sdk::DbContext for SubscriptionEventContext { type DbView = RemoteTables; type Reducers = RemoteReducers; type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { &self.db @@ -851,6 +936,9 @@ impl __sdk::DbContext for SubscriptionEventContext { fn procedures(&self) -> &Self::Procedures { &self.procedures } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } fn is_active(&self) -> bool { self.imp.is_active() @@ -886,6 +974,11 @@ pub struct ErrorContext { pub db: RemoteTables, /// Access to reducers defined by the module via extension traits implemented for [`RemoteReducers`]. pub reducers: RemoteReducers, + /// Access to setting the call-flags of each reducer defined for each reducer defined by the module + /// via extension traits implemented for [`SetReducerFlags`]. + /// + /// This type is currently unstable and may be removed without a major version bump. + pub set_reducer_flags: SetReducerFlags, /// Access to procedures defined by the module via extension traits implemented for [`RemoteProcedures`]. pub procedures: RemoteProcedures, /// The event which caused these callbacks to run. @@ -902,6 +995,7 @@ impl __sdk::AbstractEventContext for ErrorContext { Self { db: RemoteTables { imp: imp.clone() }, reducers: RemoteReducers { imp: imp.clone() }, + set_reducer_flags: SetReducerFlags { imp: imp.clone() }, procedures: RemoteProcedures { imp: imp.clone() }, event, imp, @@ -917,6 +1011,7 @@ impl __sdk::DbContext for ErrorContext { type DbView = RemoteTables; type Reducers = RemoteReducers; type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; fn db(&self) -> &Self::DbView { &self.db @@ -927,6 +1022,9 @@ impl __sdk::DbContext for ErrorContext { fn procedures(&self) -> &Self::Procedures { &self.procedures } + fn set_reducer_flags(&self) -> &Self::SetReducerFlags { + &self.set_reducer_flags + } fn is_active(&self) -> bool { self.imp.is_active() @@ -965,7 +1063,7 @@ impl __sdk::SpacetimeModule for RemoteModule { type Reducer = Reducer; type DbView = RemoteTables; type Reducers = RemoteReducers; - type Procedures = RemoteProcedures; + type SetReducerFlags = SetReducerFlags; type DbUpdate = DbUpdate; type AppliedDiff<'r> = AppliedDiff<'r>; type SubscriptionHandle = SubscriptionHandle; @@ -975,18 +1073,13 @@ impl __sdk::SpacetimeModule for RemoteModule { bot_table::register_table(client_cache); game_timer_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_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); } - const ALL_TABLE_NAMES: &'static [&'static str] = &[ - "bot", - "game_timer", - "lobby", - "player", - "player_clock", - "view_closed_hands", - "view_hand", - ]; } diff --git a/jong-db/src/db/player_clock_table.rs b/jong-db/src/db/player_clock_table.rs index 82093ad..79a0eb0 100644 --- a/jong-db/src/db/player_clock_table.rs +++ b/jong-db/src/db/player_clock_table.rs @@ -78,6 +78,12 @@ impl<'ctx> __sdk::Table for PlayerClockTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("player_clock"); + _table.add_unique_constraint::("id", |row| &row.id); + _table.add_unique_constraint::("player_id", |row| &row.player_id); +} pub struct PlayerClockUpdateCallbackId(__sdk::CallbackId); impl<'ctx> __sdk::TableWithPrimaryKey for PlayerClockTableHandle<'ctx> { @@ -95,6 +101,17 @@ impl<'ctx> __sdk::TableWithPrimaryKey for PlayerClockTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "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. @@ -155,24 +172,6 @@ impl<'ctx> PlayerClockPlayerIdUnique<'ctx> { } } -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("player_clock"); - _table.add_unique_constraint::("id", |row| &row.id); - _table.add_unique_constraint::("player_id", |row| &row.player_id); -} - -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::v2::TableUpdate, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} - #[allow(non_camel_case_types)] /// Extension trait for query builder access to the table `PlayerClock`. /// diff --git a/jong-db/src/db/player_clock_type.rs b/jong-db/src/db/player_clock_type.rs index 59998c7..6ae3212 100644 --- a/jong-db/src/db/player_clock_type.rs +++ b/jong-db/src/db/player_clock_type.rs @@ -56,5 +56,3 @@ impl __sdk::__query_builder::HasIxCols for PlayerClock { } } } - -impl __sdk::__query_builder::CanBeLookupTable for PlayerClock {} diff --git a/jong-db/src/db/player_hand_table.rs b/jong-db/src/db/player_hand_table.rs new file mode 100644 index 0000000..4b1af06 --- /dev/null +++ b/jong-db/src/db/player_hand_table.rs @@ -0,0 +1,191 @@ +// 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::db_tile_type::DbTile; +use super::player_hand_type::PlayerHand; +use super::turn_state_type::TurnState; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// 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, + 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::("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 + '_ { + 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) { + let _table = client_cache.get_or_make_table::("player_hand"); + _table.add_unique_constraint::("id", |row| &row.id); + _table.add_unique_constraint::("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> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "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, + 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::("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 { + 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, + 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::("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 { + self.imp.find(col_val) + } +} + +#[allow(non_camel_case_types)] +/// Extension trait for query builder access to the table `PlayerHand`. +/// +/// Implemented for [`__sdk::QueryTableAccessor`]. +pub trait player_handQueryTableAccess { + #[allow(non_snake_case)] + /// Get a query builder for the table `PlayerHand`. + fn player_hand(&self) -> __sdk::__query_builder::Table; +} + +impl player_handQueryTableAccess for __sdk::QueryTableAccessor { + fn player_hand(&self) -> __sdk::__query_builder::Table { + __sdk::__query_builder::Table::new("player_hand") + } +} diff --git a/jong-db/src/db/player_hand_type.rs b/jong-db/src/db/player_hand_type.rs index 6715afa..dfa7dbf 100644 --- a/jong-db/src/db/player_hand_type.rs +++ b/jong-db/src/db/player_hand_type.rs @@ -65,5 +65,3 @@ impl __sdk::__query_builder::HasIxCols for PlayerHand { } } } - -impl __sdk::__query_builder::CanBeLookupTable for PlayerHand {} diff --git a/jong-db/src/db/player_table.rs b/jong-db/src/db/player_table.rs index 7972a6e..78db0f7 100644 --- a/jong-db/src/db/player_table.rs +++ b/jong-db/src/db/player_table.rs @@ -78,6 +78,12 @@ impl<'ctx> __sdk::Table for PlayerTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("player"); + _table.add_unique_constraint::("id", |row| &row.id); + _table.add_unique_constraint::<__sdk::Identity>("identity", |row| &row.identity); +} pub struct PlayerUpdateCallbackId(__sdk::CallbackId); impl<'ctx> __sdk::TableWithPrimaryKey for PlayerTableHandle<'ctx> { @@ -95,6 +101,17 @@ impl<'ctx> __sdk::TableWithPrimaryKey for PlayerTableHandle<'ctx> { } } +#[doc(hidden)] +pub(super) fn parse_table_update( + raw_updates: __ws::TableUpdate<__ws::BsatnFormat>, +) -> __sdk::Result<__sdk::TableUpdate> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + /// 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. @@ -157,24 +174,6 @@ impl<'ctx> PlayerIdentityUnique<'ctx> { } } -#[doc(hidden)] -pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { - let _table = client_cache.get_or_make_table::("player"); - _table.add_unique_constraint::("id", |row| &row.id); - _table.add_unique_constraint::<__sdk::Identity>("identity", |row| &row.identity); -} - -#[doc(hidden)] -pub(super) fn parse_table_update( - raw_updates: __ws::v2::TableUpdate, -) -> __sdk::Result<__sdk::TableUpdate> { - __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { - __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") - .with_cause(e) - .into() - }) -} - #[allow(non_camel_case_types)] /// Extension trait for query builder access to the table `Player`. /// diff --git a/jong-db/src/db/player_type.rs b/jong-db/src/db/player_type.rs index a4b8634..be770b6 100644 --- a/jong-db/src/db/player_type.rs +++ b/jong-db/src/db/player_type.rs @@ -64,5 +64,3 @@ impl __sdk::__query_builder::HasIxCols for Player { } } } - -impl __sdk::__query_builder::CanBeLookupTable for Player {} diff --git a/jong-db/src/db/set_ready_reducer.rs b/jong-db/src/db/set_ready_reducer.rs index 2aaf204..bebd7cf 100644 --- a/jong-db/src/db/set_ready_reducer.rs +++ b/jong-db/src/db/set_ready_reducer.rs @@ -20,6 +20,8 @@ impl __sdk::InModule for SetReadyArgs { type Module = super::RemoteModule; } +pub struct SetReadyCallbackId(__sdk::CallbackId); + #[allow(non_camel_case_types)] /// Extension trait for access to the reducer `set_ready`. /// @@ -29,38 +31,72 @@ pub trait set_ready { /// /// This method returns immediately, and errors only if we are unable to send the request. /// The reducer will run asynchronously in the future, - /// and this method provides no way to listen for its completion status. - /// /// Use [`set_ready:set_ready_then`] to run a callback after the reducer completes. - fn set_ready(&self, ready: bool) -> __sdk::Result<()> { - self.set_ready_then(ready, |_, _| {}) - } - - /// Request that the remote module invoke the reducer `set_ready` to run as soon as possible, - /// registering `callback` to run when we are notified that the reducer completed. + /// and its status can be observed by listening for [`Self::on_set_ready`] callbacks. + 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`. /// - /// 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 with the `callback`. - fn set_ready_then( + /// Callbacks should inspect the [`__sdk::ReducerEvent`] contained in the [`super::ReducerEventContext`] + /// to determine the reducer's status. + /// + /// The returned [`SetReadyCallbackId`] can be passed to [`Self::remove_on_set_ready`] + /// to cancel the callback. + fn on_set_ready( &self, - ready: bool, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()>; + callback: impl FnMut(&super::ReducerEventContext, &bool) + Send + 'static, + ) -> SetReadyCallbackId; + /// Cancel a callback previously registered by [`Self::on_set_ready`], + /// causing it not to run in the future. + fn remove_on_set_ready(&self, callback: SetReadyCallbackId); } impl set_ready for super::RemoteReducers { - fn set_ready_then( + fn set_ready(&self, ready: bool) -> __sdk::Result<()> { + self.imp.call_reducer("set_ready", SetReadyArgs { ready }) + } + fn on_set_ready( &self, - ready: bool, - - callback: impl FnOnce(&super::ReducerEventContext, Result, __sdk::InternalError>) - + Send - + 'static, - ) -> __sdk::Result<()> { - self.imp - .invoke_reducer_with_callback(SetReadyArgs { ready }, callback) + mut callback: impl FnMut(&super::ReducerEventContext, &bool) + Send + 'static, + ) -> SetReadyCallbackId { + SetReadyCallbackId(self.imp.on_reducer( + "set_ready", + Box::new(move |ctx: &super::ReducerEventContext| { + #[allow(irrefutable_let_patterns)] + let super::ReducerEventContext { + event: + __sdk::ReducerEvent { + reducer: super::Reducer::SetReady { ready }, + .. + }, + .. + } = ctx + else { + unreachable!() + }; + callback(ctx, ready) + }), + )) + } + fn remove_on_set_ready(&self, callback: SetReadyCallbackId) { + self.imp.remove_on_reducer("set_ready", callback.0) + } +} + +#[allow(non_camel_case_types)] +#[doc(hidden)] +/// Extension trait for setting the call-flags for the reducer `set_ready`. +/// +/// Implemented for [`super::SetReducerFlags`]. +/// +/// This type is currently unstable and may be removed without a major version bump. +pub trait set_flags_for_set_ready { + /// Set the call-reducer flags for the reducer `set_ready` to `flags`. + /// + /// This type is currently unstable and may be removed without a major version bump. + fn set_ready(&self, flags: __ws::CallReducerFlags); +} + +impl set_flags_for_set_ready for super::SetReducerFlags { + fn set_ready(&self, flags: __ws::CallReducerFlags) { + self.imp.set_call_reducer_flags("set_ready", flags); } } diff --git a/jong-db/src/db/tile_table.rs b/jong-db/src/db/tile_table.rs new file mode 100644 index 0000000..e23f10e --- /dev/null +++ b/jong-db/src/db/tile_table.rs @@ -0,0 +1,159 @@ +// 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::db_tile_type::DbTile; +use super::tile_type::Tile; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `tile`. +/// +/// Obtain a handle from the [`TileTableAccess::tile`] method on [`super::RemoteTables`], +/// like `ctx.db.tile()`. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.tile().on_insert(...)`. +pub struct TileTableHandle<'ctx> { + imp: __sdk::TableHandle, + ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +#[allow(non_camel_case_types)] +/// Extension trait for access to the table `tile`. +/// +/// Implemented for [`super::RemoteTables`]. +pub trait TileTableAccess { + #[allow(non_snake_case)] + /// Obtain a [`TileTableHandle`], which mediates access to the table `tile`. + fn tile(&self) -> TileTableHandle<'_>; +} + +impl TileTableAccess for super::RemoteTables { + fn tile(&self) -> TileTableHandle<'_> { + TileTableHandle { + imp: self.imp.get_table::("tile"), + ctx: std::marker::PhantomData, + } + } +} + +pub struct TileInsertCallbackId(__sdk::CallbackId); +pub struct TileDeleteCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::Table for TileTableHandle<'ctx> { + type Row = DbTile; + type EventContext = super::EventContext; + + fn count(&self) -> u64 { + self.imp.count() + } + fn iter(&self) -> impl Iterator + '_ { + self.imp.iter() + } + + type InsertCallbackId = TileInsertCallbackId; + + fn on_insert( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> TileInsertCallbackId { + TileInsertCallbackId(self.imp.on_insert(Box::new(callback))) + } + + fn remove_on_insert(&self, callback: TileInsertCallbackId) { + self.imp.remove_on_insert(callback.0) + } + + type DeleteCallbackId = TileDeleteCallbackId; + + fn on_delete( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> TileDeleteCallbackId { + TileDeleteCallbackId(self.imp.on_delete(Box::new(callback))) + } + + fn remove_on_delete(&self, callback: TileDeleteCallbackId) { + self.imp.remove_on_delete(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("tile"); + _table.add_unique_constraint::("id", |row| &row.id); +} +pub struct TileUpdateCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::TableWithPrimaryKey for TileTableHandle<'ctx> { + type UpdateCallbackId = TileUpdateCallbackId; + + fn on_update( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static, + ) -> TileUpdateCallbackId { + TileUpdateCallbackId(self.imp.on_update(Box::new(callback))) + } + + fn remove_on_update(&self, callback: TileUpdateCallbackId) { + 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> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + +/// Access to the `id` unique index on the table `tile`, +/// which allows point queries on the field of the same name +/// via the [`TileIdUnique::find`] method. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.tile().id().find(...)`. +pub struct TileIdUnique<'ctx> { + imp: __sdk::UniqueConstraintHandle, + 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::("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 { + self.imp.find(col_val) + } +} + +#[allow(non_camel_case_types)] +/// Extension trait for query builder access to the table `DbTile`. +/// +/// Implemented for [`__sdk::QueryTableAccessor`]. +pub trait tileQueryTableAccess { + #[allow(non_snake_case)] + /// Get a query builder for the table `DbTile`. + fn tile(&self) -> __sdk::__query_builder::Table; +} + +impl tileQueryTableAccess for __sdk::QueryTableAccessor { + fn tile(&self) -> __sdk::__query_builder::Table { + __sdk::__query_builder::Table::new("tile") + } +} diff --git a/jong-db/src/db/view_closed_hands_table.rs b/jong-db/src/db/view_closed_hands_table.rs index b2d7c0f..d0ca254 100644 --- a/jong-db/src/db/view_closed_hands_table.rs +++ b/jong-db/src/db/view_closed_hands_table.rs @@ -86,7 +86,7 @@ pub(super) fn register_table(client_cache: &mut __sdk::ClientCache, ) -> __sdk::Result<__sdk::TableUpdate> { __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") diff --git a/jong-db/src/db/view_hand_table.rs b/jong-db/src/db/view_hand_table.rs index b5b21af..1a9adbf 100644 --- a/jong-db/src/db/view_hand_table.rs +++ b/jong-db/src/db/view_hand_table.rs @@ -87,7 +87,7 @@ pub(super) fn register_table(client_cache: &mut __sdk::ClientCache, ) -> __sdk::Result<__sdk::TableUpdate> { __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") diff --git a/jong-db/src/db/wall_table.rs b/jong-db/src/db/wall_table.rs new file mode 100644 index 0000000..70c4010 --- /dev/null +++ b/jong-db/src/db/wall_table.rs @@ -0,0 +1,159 @@ +// 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::db_tile_type::DbTile; +use super::db_wall_type::DbWall; +use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; + +/// Table handle for the table `wall`. +/// +/// Obtain a handle from the [`WallTableAccess::wall`] method on [`super::RemoteTables`], +/// like `ctx.db.wall()`. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.wall().on_insert(...)`. +pub struct WallTableHandle<'ctx> { + imp: __sdk::TableHandle, + ctx: std::marker::PhantomData<&'ctx super::RemoteTables>, +} + +#[allow(non_camel_case_types)] +/// Extension trait for access to the table `wall`. +/// +/// Implemented for [`super::RemoteTables`]. +pub trait WallTableAccess { + #[allow(non_snake_case)] + /// Obtain a [`WallTableHandle`], which mediates access to the table `wall`. + fn wall(&self) -> WallTableHandle<'_>; +} + +impl WallTableAccess for super::RemoteTables { + fn wall(&self) -> WallTableHandle<'_> { + WallTableHandle { + imp: self.imp.get_table::("wall"), + ctx: std::marker::PhantomData, + } + } +} + +pub struct WallInsertCallbackId(__sdk::CallbackId); +pub struct WallDeleteCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::Table for WallTableHandle<'ctx> { + type Row = DbWall; + type EventContext = super::EventContext; + + fn count(&self) -> u64 { + self.imp.count() + } + fn iter(&self) -> impl Iterator + '_ { + self.imp.iter() + } + + type InsertCallbackId = WallInsertCallbackId; + + fn on_insert( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> WallInsertCallbackId { + WallInsertCallbackId(self.imp.on_insert(Box::new(callback))) + } + + fn remove_on_insert(&self, callback: WallInsertCallbackId) { + self.imp.remove_on_insert(callback.0) + } + + type DeleteCallbackId = WallDeleteCallbackId; + + fn on_delete( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static, + ) -> WallDeleteCallbackId { + WallDeleteCallbackId(self.imp.on_delete(Box::new(callback))) + } + + fn remove_on_delete(&self, callback: WallDeleteCallbackId) { + self.imp.remove_on_delete(callback.0) + } +} + +#[doc(hidden)] +pub(super) fn register_table(client_cache: &mut __sdk::ClientCache) { + let _table = client_cache.get_or_make_table::("wall"); + _table.add_unique_constraint::("lobby_id", |row| &row.lobby_id); +} +pub struct WallUpdateCallbackId(__sdk::CallbackId); + +impl<'ctx> __sdk::TableWithPrimaryKey for WallTableHandle<'ctx> { + type UpdateCallbackId = WallUpdateCallbackId; + + fn on_update( + &self, + callback: impl FnMut(&Self::EventContext, &Self::Row, &Self::Row) + Send + 'static, + ) -> WallUpdateCallbackId { + WallUpdateCallbackId(self.imp.on_update(Box::new(callback))) + } + + fn remove_on_update(&self, callback: WallUpdateCallbackId) { + 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> { + __sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| { + __sdk::InternalError::failed_parse("TableUpdate", "TableUpdate") + .with_cause(e) + .into() + }) +} + +/// Access to the `lobby_id` unique index on the table `wall`, +/// which allows point queries on the field of the same name +/// via the [`WallLobbyIdUnique::find`] method. +/// +/// Users are encouraged not to explicitly reference this type, +/// but to directly chain method calls, +/// like `ctx.db.wall().lobby_id().find(...)`. +pub struct WallLobbyIdUnique<'ctx> { + imp: __sdk::UniqueConstraintHandle, + 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::("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 { + self.imp.find(col_val) + } +} + +#[allow(non_camel_case_types)] +/// Extension trait for query builder access to the table `DbWall`. +/// +/// Implemented for [`__sdk::QueryTableAccessor`]. +pub trait wallQueryTableAccess { + #[allow(non_snake_case)] + /// Get a query builder for the table `DbWall`. + fn wall(&self) -> __sdk::__query_builder::Table; +} + +impl wallQueryTableAccess for __sdk::QueryTableAccessor { + fn wall(&self) -> __sdk::__query_builder::Table { + __sdk::__query_builder::Table::new("wall") + } +} diff --git a/jong-line/src/lib.rs b/jong-line/src/lib.rs index 2161226..42ca574 100644 --- a/jong-line/src/lib.rs +++ b/jong-line/src/lib.rs @@ -29,14 +29,14 @@ pub fn clear_all(ctx: &ReducerContext) { #[reducer(client_connected)] pub fn connect(ctx: &ReducerContext) -> Result<(), String> { - let player = if let Some(player) = ctx.db.logged_out_player().identity().find(ctx.sender()) { + let player = if let Some(player) = ctx.db.logged_out_player().identity().find(ctx.sender) { let player = ctx.db.player().insert(player); - ctx.db.logged_out_player().identity().delete(ctx.sender()); + ctx.db.logged_out_player().identity().delete(ctx.sender); player } else { - debug!("inserting new player with identity {:?}", ctx.sender()); + debug!("inserting new player with identity {:?}", ctx.sender); ctx.db.player().try_insert(Player { - identity: ctx.sender(), + identity: ctx.sender, id: 0, name: None, lobby_id: 0, @@ -56,11 +56,11 @@ pub fn disconnect(ctx: &ReducerContext) -> Result<(), String> { .db .player() .identity() - .find(ctx.sender()) - .ok_or_else(|| format!("can't find player {} to disconnect", ctx.sender()))?; + .find(ctx.sender) + .ok_or_else(|| format!("can't find player {} to disconnect", ctx.sender))?; let player = ctx.db.logged_out_player().insert(player); - if !ctx.db.player().identity().delete(ctx.sender()) { + if !ctx.db.player().identity().delete(ctx.sender) { Err("can't delete row")? } @@ -97,7 +97,7 @@ pub fn disconnect(ctx: &ReducerContext) -> Result<(), String> { // if name.is_empty() { // return Err("names must not be empty".into()); // } -// if let Some(player) = ctx.db.player().identity().find(ctx.sender()) { +// if let Some(player) = ctx.db.player().identity().find(ctx.sender) { // ctx.db.player().identity().update(Player { // name: Some(name), // ..player diff --git a/jong-line/src/reducers.rs b/jong-line/src/reducers.rs index 3b07aa3..83fad96 100644 --- a/jong-line/src/reducers.rs +++ b/jong-line/src/reducers.rs @@ -16,14 +16,13 @@ mod lobby; #[reducer] pub fn advance_game(ctx: &ReducerContext, mut game_timer: GameTimer) -> Result<(), String> { - advance_game_private(ctx, game_timer) -} - -#[reducer] -pub fn advance_game_private(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) { trace!("running schedule for lobby {}", lobby.id); match lobby.game_state { diff --git a/jong-line/src/reducers/hand.rs b/jong-line/src/reducers/hand.rs index da67516..fd2f861 100644 --- a/jong-line/src/reducers/hand.rs +++ b/jong-line/src/reducers/hand.rs @@ -8,7 +8,7 @@ use crate::tables::*; // TODO make sure this can't be called or just error here? #[reducer] pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> { - let player = ctx.db.player().identity().find(ctx.sender()).unwrap(); + let player = ctx.db.player().identity().find(ctx.sender).unwrap(); let mut hand = ctx.db.player_hand().player_id().find(player.id).unwrap(); // TODO we can probably remove a buncha these errors @@ -51,7 +51,7 @@ pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> { let mut clock = ctx.db.player_clock().player_id().find(player.id).unwrap(); clock.renew(); - ctx.db.player_clock().id().update(clock); + ctx.db.player_clock().player_id().update(clock); let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap(); lobby.next_player(); diff --git a/jong-line/src/reducers/lobby.rs b/jong-line/src/reducers/lobby.rs index 46bcf96..05e9c84 100644 --- a/jong-line/src/reducers/lobby.rs +++ b/jong-line/src/reducers/lobby.rs @@ -13,8 +13,8 @@ pub fn join_or_create_lobby(ctx: &ReducerContext, mut lobby_id: u32) -> Result<( .db .player() .identity() - .find(ctx.sender()) - .ok_or(format!("cannot find player {}", ctx.sender()))?; + .find(ctx.sender) + .ok_or(format!("cannot find player {}", ctx.sender))?; if lobby_id == 0 && player.lobby_id == 0 { // TODO check first if player is already in a lobby @@ -74,7 +74,7 @@ pub fn add_bot(ctx: &ReducerContext, lobby_id: u32) -> Result<(), String> { #[reducer] 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 = ctx.db.player().identity().update(player); diff --git a/jong-line/src/tables.rs b/jong-line/src/tables.rs index fdf75d5..52c49ba 100644 --- a/jong-line/src/tables.rs +++ b/jong-line/src/tables.rs @@ -6,10 +6,10 @@ use jong_types::{ tiles::Tile, }; -use crate::reducers::advance_game_private; +use crate::reducers::advance_game; #[derive(Debug, Clone)] -#[table(accessor = lobby, public)] +#[table(name = lobby, public)] pub struct Lobby { #[primary_key] #[auto_inc] @@ -23,7 +23,7 @@ pub struct Lobby { // pub open_hands: bool, } -#[table(accessor = wall)] +#[table(name = wall)] pub struct DbWall { #[primary_key] pub lobby_id: u32, @@ -31,7 +31,7 @@ pub struct DbWall { pub tiles: Vec, } -#[table(accessor = tile)] +#[table(name = tile)] #[derive(Debug, Clone, Copy)] pub struct DbTile { #[primary_key] @@ -41,8 +41,8 @@ pub struct DbTile { pub tile: Tile, } -#[table(accessor = player, public)] -#[table(accessor = logged_out_player)] +#[table(name = player, public)] +#[table(name = logged_out_player)] #[derive(Debug)] pub struct Player { #[unique] @@ -61,7 +61,7 @@ pub struct Player { pub sort: bool, } -#[table(accessor = player_clock, public)] +#[table(name = player_clock, public)] pub struct PlayerClock { #[primary_key] pub id: u32, @@ -73,7 +73,7 @@ pub struct PlayerClock { pub total: u16, } -#[table(accessor = player_hand)] +#[table(name = player_hand)] pub struct PlayerHand { #[primary_key] #[auto_inc] @@ -91,7 +91,7 @@ pub struct PlayerHand { pub working_tile: Option, } -#[table(accessor = bot, public)] +#[table(name = bot, public)] pub struct Bot { #[primary_key] #[auto_inc] @@ -108,7 +108,7 @@ pub struct Bot { pub working_tile: Option, } -#[table(accessor = game_timer, scheduled(advance_game_private), public)] +#[table(name = game_timer, scheduled(advance_game))] pub struct GameTimer { #[primary_key] #[auto_inc] @@ -120,12 +120,12 @@ pub struct GameTimer { pub scheduled_at: spacetimedb::ScheduleAt, } -#[view(accessor = view_hand, public)] +#[view(name = view_hand, public)] fn view_hand(ctx: &ViewContext) -> Option { ctx.db .player() .identity() - .find(ctx.sender()) + .find(ctx.sender) .and_then(|p| ctx.db.player_hand().player_id().find(p.id)) } @@ -137,11 +137,10 @@ pub struct HandView { pub drawn: bool, } -#[view(accessor = view_closed_hands, public)] +#[view(name = view_closed_hands, public)] fn view_closed_hands(ctx: &ViewContext) -> Vec { - if let Some(this_player) = ctx.db.player().identity().find(ctx.sender()) - && let Some(lobby) = ctx.db.lobby().id().find(this_player.lobby_id) - { + let this_player = ctx.db.player().identity().find(ctx.sender).unwrap(); + if let Some(lobby) = ctx.db.lobby().id().find(this_player.lobby_id) { lobby .players .iter() diff --git a/jong/src/riichi.rs b/jong/src/riichi.rs index 7b2b902..d5ae098 100644 --- a/jong/src/riichi.rs +++ b/jong/src/riichi.rs @@ -4,7 +4,7 @@ use bevy_spacetimedb::{ ReadUpdateMessage, StdbPlugin, }; -use jong_db::{self, GameTimerTableAccess, add_bot, set_ready}; +use jong_db::{self, add_bot, set_ready}; use jong_db::{ BotTableAccess, DbConnection, LobbyTableAccess, PlayerHand, PlayerTableAccess, RemoteTables, ViewClosedHandsTableAccess, ViewHandTableAccess, @@ -26,7 +26,6 @@ impl Plugin for Riichi { .with_run_fn(DbConnection::run_threaded) .add_table(RemoteTables::player) .add_table(RemoteTables::lobby) - .add_table(RemoteTables::game_timer) // TODO check bevy_spacetimedb PR status .add_view_with_pk(RemoteTables::view_hand, |p| p.id) .add_view_with_pk(RemoteTables::view_closed_hands, |p| { @@ -103,7 +102,6 @@ fn subscriptions(stdb: SpacetimeDB, mut commands: Commands) { "SELECT b.* FROM bot b JOIN lobby l ON l.id = b.lobby_id".to_string(), "SELECT * FROM view_hand".to_string(), "SELECT * FROM view_closed_hands".to_string(), - "SELECT g.* FROM game_timer g JOIN player p ON g.lobby_id = p.lobby_id".to_string(), ]); while let Ok(event) = recv.recv() { @@ -226,13 +224,12 @@ fn on_player_insert_update( mut commands: Commands, main_player: Option>, - other_players: Query<&Player, Without>, + other_players: Query<&Player>, mut next_turnstate: ResMut>, ) { for msg in messages.read() { debug!("on_player_insert_update: {:?}", msg.new); - assert_eq!(msg.new.identity, stdb.identity()); if main_player.is_none() && msg.new.identity == stdb.identity() { // trace!("spawn_main_player"); spawn_main_player(&stdb, &mut commands, &mut next_turnstate, &msg.new); diff --git a/jong/src/tui.rs b/jong/src/tui.rs index ce195ee..75df4b8 100644 --- a/jong/src/tui.rs +++ b/jong/src/tui.rs @@ -4,11 +4,10 @@ use std::time::Duration; use bevy::{app::ScheduleRunnerPlugin, prelude::*, state::app::StatesPlugin}; use bevy_ratatui::RatatuiPlugins; -use spacetimedb_sdk::Table; use tui_logger::TuiWidgetState; use jong::{SpacetimeDB, riichi::player::*}; -use jong_db::{self, GameTimerTableAccess, advance_game, discard_tile as _}; +use jong_db::{self, discard_tile as _}; use jong_types::states::{GameState, TurnState}; mod input; @@ -107,13 +106,9 @@ fn discard_tile( tiles: Query<&TileId>, ) { // FIXME why is this not consuming the messages? - // TODO disable this when we're not current player? while let Some(message) = selected.read().next() { if let Ok(tile_id) = tiles.get(message.0) { stdb.reducers().discard_tile(tile_id.0).unwrap(); - stdb.reducers() - .advance_game(stdb.db().game_timer().iter().next().unwrap()) - .unwrap(); commands.entity(drawn.0).remove::(); } } diff --git a/jong/src/tui/render.rs b/jong/src/tui/render.rs index be3e717..817e713 100644 --- a/jong/src/tui/render.rs +++ b/jong/src/tui/render.rs @@ -165,7 +165,7 @@ pub(crate) fn render_main_hand( let hand: Vec<_> = hand .iter() .find_map(|(c, e)| { - // debug!("main_player children: {:?}", *main_player); + debug!("main_player children: {:?}", *main_player); if main_player.contains(&e) { Some(c) } else { @@ -301,5 +301,3 @@ pub(crate) fn render_main_pond( Ok(()) } - -pub(crate) fn render_other_hands() {} diff --git a/justfile b/justfile index 4467e36..4541442 100644 --- a/justfile +++ b/justfile @@ -18,10 +18,10 @@ spacetime: devenv up spacetime_dev: - spacetime dev --module-bindings-path jong-db/src/db jong-line --delete-data=always --yes --server-only + spacetime dev --module-project-path jong-line --module-bindings-path jong-db/src/db jong-line --delete-data=always spacetime_generate-bindings: - spacetime generate --lang rust --out-dir jong-db/src/db --module-path jong-line + spacetime generate --lang rust --out-dir jong-db/src/db --project-path jong-line spacetime_restart_dev: mprocs -s localhost:4050 --ctl $"({c: restart-proc, name: spacetimedb_dev} | to yaml)" diff --git a/spacetime.json b/spacetime.json deleted file mode 100644 index 339050e..0000000 --- a/spacetime.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "dev": { - "run": "" - }, - "_source-config": "spacetime.local.json", - "module-path": "jong-line", - "server": "local", - "database": "jong-line" -} diff --git a/spacetime.local.json b/spacetime.local.json deleted file mode 100644 index 946b285..0000000 --- a/spacetime.local.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "database": "jong-line" -} \ No newline at end of file