Compare commits
No commits in common. "e7658fd36f9f2f2a6bd828d2e67139e0c45628b2" and "74bf702219b434ae7de40cb29973d0ad035a29b0" have entirely different histories.
e7658fd36f
...
74bf702219
12 changed files with 51 additions and 278 deletions
|
|
@ -1,39 +0,0 @@
|
||||||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
use super::player_or_bot_type::PlayerOrBot;
|
|
||||||
|
|
||||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
|
||||||
#[sats(crate = __lib)]
|
|
||||||
pub struct HandView {
|
|
||||||
pub player: PlayerOrBot,
|
|
||||||
pub hand_length: u8,
|
|
||||||
pub drawn: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::InModule for HandView {
|
|
||||||
type Module = super::RemoteModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Column accessor struct for the table `HandView`.
|
|
||||||
///
|
|
||||||
/// Provides typed access to columns for query building.
|
|
||||||
pub struct HandViewCols {
|
|
||||||
pub player: __sdk::__query_builder::Col<HandView, PlayerOrBot>,
|
|
||||||
pub hand_length: __sdk::__query_builder::Col<HandView, u8>,
|
|
||||||
pub drawn: __sdk::__query_builder::Col<HandView, bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl __sdk::__query_builder::HasCols for HandView {
|
|
||||||
type Cols = HandViewCols;
|
|
||||||
fn cols(table_name: &'static str) -> Self::Cols {
|
|
||||||
HandViewCols {
|
|
||||||
player: __sdk::__query_builder::Col::new(table_name, "player"),
|
|
||||||
hand_length: __sdk::__query_builder::Col::new(table_name, "hand_length"),
|
|
||||||
drawn: __sdk::__query_builder::Col::new(table_name, "drawn"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -20,7 +20,6 @@ pub mod dragon_type;
|
||||||
pub mod game_state_type;
|
pub mod game_state_type;
|
||||||
pub mod game_timer_table;
|
pub mod game_timer_table;
|
||||||
pub mod game_timer_type;
|
pub mod game_timer_type;
|
||||||
pub mod hand_view_type;
|
|
||||||
pub mod join_or_create_lobby_reducer;
|
pub mod join_or_create_lobby_reducer;
|
||||||
pub mod lobby_table;
|
pub mod lobby_table;
|
||||||
pub mod lobby_type;
|
pub mod lobby_type;
|
||||||
|
|
@ -38,7 +37,6 @@ pub mod suit_type;
|
||||||
pub mod tile_table;
|
pub mod tile_table;
|
||||||
pub mod tile_type;
|
pub mod tile_type;
|
||||||
pub mod turn_state_type;
|
pub mod turn_state_type;
|
||||||
pub mod view_closed_hands_table;
|
|
||||||
pub mod view_hand_table;
|
pub mod view_hand_table;
|
||||||
pub mod wall_table;
|
pub mod wall_table;
|
||||||
pub mod wind_type;
|
pub mod wind_type;
|
||||||
|
|
@ -57,7 +55,6 @@ pub use dragon_type::Dragon;
|
||||||
pub use game_state_type::GameState;
|
pub use game_state_type::GameState;
|
||||||
pub use game_timer_table::*;
|
pub use game_timer_table::*;
|
||||||
pub use game_timer_type::GameTimer;
|
pub use game_timer_type::GameTimer;
|
||||||
pub use hand_view_type::HandView;
|
|
||||||
pub use join_or_create_lobby_reducer::{
|
pub use join_or_create_lobby_reducer::{
|
||||||
join_or_create_lobby, set_flags_for_join_or_create_lobby, JoinOrCreateLobbyCallbackId,
|
join_or_create_lobby, set_flags_for_join_or_create_lobby, JoinOrCreateLobbyCallbackId,
|
||||||
};
|
};
|
||||||
|
|
@ -77,7 +74,6 @@ pub use suit_type::Suit;
|
||||||
pub use tile_table::*;
|
pub use tile_table::*;
|
||||||
pub use tile_type::Tile;
|
pub use tile_type::Tile;
|
||||||
pub use turn_state_type::TurnState;
|
pub use turn_state_type::TurnState;
|
||||||
pub use view_closed_hands_table::*;
|
|
||||||
pub use view_hand_table::*;
|
pub use view_hand_table::*;
|
||||||
pub use wall_table::*;
|
pub use wall_table::*;
|
||||||
pub use wind_type::Wind;
|
pub use wind_type::Wind;
|
||||||
|
|
@ -194,7 +190,6 @@ pub struct DbUpdate {
|
||||||
player_clock: __sdk::TableUpdate<PlayerClock>,
|
player_clock: __sdk::TableUpdate<PlayerClock>,
|
||||||
player_hand: __sdk::TableUpdate<PlayerHand>,
|
player_hand: __sdk::TableUpdate<PlayerHand>,
|
||||||
tile: __sdk::TableUpdate<DbTile>,
|
tile: __sdk::TableUpdate<DbTile>,
|
||||||
view_closed_hands: __sdk::TableUpdate<HandView>,
|
|
||||||
view_hand: __sdk::TableUpdate<PlayerHand>,
|
view_hand: __sdk::TableUpdate<PlayerHand>,
|
||||||
wall: __sdk::TableUpdate<DbWall>,
|
wall: __sdk::TableUpdate<DbWall>,
|
||||||
}
|
}
|
||||||
|
|
@ -229,9 +224,6 @@ impl TryFrom<__ws::DatabaseUpdate<__ws::BsatnFormat>> for DbUpdate {
|
||||||
"tile" => db_update
|
"tile" => db_update
|
||||||
.tile
|
.tile
|
||||||
.append(tile_table::parse_table_update(table_update)?),
|
.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" => db_update
|
||||||
.view_hand
|
.view_hand
|
||||||
.append(view_hand_table::parse_table_update(table_update)?),
|
.append(view_hand_table::parse_table_update(table_update)?),
|
||||||
|
|
@ -291,8 +283,6 @@ impl __sdk::DbUpdate for DbUpdate {
|
||||||
diff.wall = cache
|
diff.wall = cache
|
||||||
.apply_diff_to_table::<DbWall>("wall", &self.wall)
|
.apply_diff_to_table::<DbWall>("wall", &self.wall)
|
||||||
.with_updates_by_pk(|row| &row.lobby_id);
|
.with_updates_by_pk(|row| &row.lobby_id);
|
||||||
diff.view_closed_hands =
|
|
||||||
cache.apply_diff_to_table::<HandView>("view_closed_hands", &self.view_closed_hands);
|
|
||||||
diff.view_hand = cache.apply_diff_to_table::<PlayerHand>("view_hand", &self.view_hand);
|
diff.view_hand = cache.apply_diff_to_table::<PlayerHand>("view_hand", &self.view_hand);
|
||||||
|
|
||||||
diff
|
diff
|
||||||
|
|
@ -311,7 +301,6 @@ pub struct AppliedDiff<'r> {
|
||||||
player_clock: __sdk::TableAppliedDiff<'r, PlayerClock>,
|
player_clock: __sdk::TableAppliedDiff<'r, PlayerClock>,
|
||||||
player_hand: __sdk::TableAppliedDiff<'r, PlayerHand>,
|
player_hand: __sdk::TableAppliedDiff<'r, PlayerHand>,
|
||||||
tile: __sdk::TableAppliedDiff<'r, DbTile>,
|
tile: __sdk::TableAppliedDiff<'r, DbTile>,
|
||||||
view_closed_hands: __sdk::TableAppliedDiff<'r, HandView>,
|
|
||||||
view_hand: __sdk::TableAppliedDiff<'r, PlayerHand>,
|
view_hand: __sdk::TableAppliedDiff<'r, PlayerHand>,
|
||||||
wall: __sdk::TableAppliedDiff<'r, DbWall>,
|
wall: __sdk::TableAppliedDiff<'r, DbWall>,
|
||||||
__unused: std::marker::PhantomData<&'r ()>,
|
__unused: std::marker::PhantomData<&'r ()>,
|
||||||
|
|
@ -343,11 +332,6 @@ impl<'r> __sdk::AppliedDiff<'r> for AppliedDiff<'r> {
|
||||||
);
|
);
|
||||||
callbacks.invoke_table_row_callbacks::<PlayerHand>("player_hand", &self.player_hand, event);
|
callbacks.invoke_table_row_callbacks::<PlayerHand>("player_hand", &self.player_hand, event);
|
||||||
callbacks.invoke_table_row_callbacks::<DbTile>("tile", &self.tile, event);
|
callbacks.invoke_table_row_callbacks::<DbTile>("tile", &self.tile, event);
|
||||||
callbacks.invoke_table_row_callbacks::<HandView>(
|
|
||||||
"view_closed_hands",
|
|
||||||
&self.view_closed_hands,
|
|
||||||
event,
|
|
||||||
);
|
|
||||||
callbacks.invoke_table_row_callbacks::<PlayerHand>("view_hand", &self.view_hand, event);
|
callbacks.invoke_table_row_callbacks::<PlayerHand>("view_hand", &self.view_hand, event);
|
||||||
callbacks.invoke_table_row_callbacks::<DbWall>("wall", &self.wall, event);
|
callbacks.invoke_table_row_callbacks::<DbWall>("wall", &self.wall, event);
|
||||||
}
|
}
|
||||||
|
|
@ -1078,7 +1062,6 @@ impl __sdk::SpacetimeModule for RemoteModule {
|
||||||
player_clock_table::register_table(client_cache);
|
player_clock_table::register_table(client_cache);
|
||||||
player_hand_table::register_table(client_cache);
|
player_hand_table::register_table(client_cache);
|
||||||
tile_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);
|
view_hand_table::register_table(client_cache);
|
||||||
wall_table::register_table(client_cache);
|
wall_table::register_table(client_cache);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,112 +0,0 @@
|
||||||
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
|
|
||||||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
|
||||||
|
|
||||||
#![allow(unused, clippy::all)]
|
|
||||||
use super::hand_view_type::HandView;
|
|
||||||
use super::player_or_bot_type::PlayerOrBot;
|
|
||||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
|
||||||
|
|
||||||
/// Table handle for the table `view_closed_hands`.
|
|
||||||
///
|
|
||||||
/// Obtain a handle from the [`ViewClosedHandsTableAccess::view_closed_hands`] method on [`super::RemoteTables`],
|
|
||||||
/// like `ctx.db.view_closed_hands()`.
|
|
||||||
///
|
|
||||||
/// Users are encouraged not to explicitly reference this type,
|
|
||||||
/// but to directly chain method calls,
|
|
||||||
/// like `ctx.db.view_closed_hands().on_insert(...)`.
|
|
||||||
pub struct ViewClosedHandsTableHandle<'ctx> {
|
|
||||||
imp: __sdk::TableHandle<HandView>,
|
|
||||||
ctx: std::marker::PhantomData<&'ctx super::RemoteTables>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
/// Extension trait for access to the table `view_closed_hands`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`super::RemoteTables`].
|
|
||||||
pub trait ViewClosedHandsTableAccess {
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
/// Obtain a [`ViewClosedHandsTableHandle`], which mediates access to the table `view_closed_hands`.
|
|
||||||
fn view_closed_hands(&self) -> ViewClosedHandsTableHandle<'_>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ViewClosedHandsTableAccess for super::RemoteTables {
|
|
||||||
fn view_closed_hands(&self) -> ViewClosedHandsTableHandle<'_> {
|
|
||||||
ViewClosedHandsTableHandle {
|
|
||||||
imp: self.imp.get_table::<HandView>("view_closed_hands"),
|
|
||||||
ctx: std::marker::PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ViewClosedHandsInsertCallbackId(__sdk::CallbackId);
|
|
||||||
pub struct ViewClosedHandsDeleteCallbackId(__sdk::CallbackId);
|
|
||||||
|
|
||||||
impl<'ctx> __sdk::Table for ViewClosedHandsTableHandle<'ctx> {
|
|
||||||
type Row = HandView;
|
|
||||||
type EventContext = super::EventContext;
|
|
||||||
|
|
||||||
fn count(&self) -> u64 {
|
|
||||||
self.imp.count()
|
|
||||||
}
|
|
||||||
fn iter(&self) -> impl Iterator<Item = HandView> + '_ {
|
|
||||||
self.imp.iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
type InsertCallbackId = ViewClosedHandsInsertCallbackId;
|
|
||||||
|
|
||||||
fn on_insert(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
|
||||||
) -> ViewClosedHandsInsertCallbackId {
|
|
||||||
ViewClosedHandsInsertCallbackId(self.imp.on_insert(Box::new(callback)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_on_insert(&self, callback: ViewClosedHandsInsertCallbackId) {
|
|
||||||
self.imp.remove_on_insert(callback.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
type DeleteCallbackId = ViewClosedHandsDeleteCallbackId;
|
|
||||||
|
|
||||||
fn on_delete(
|
|
||||||
&self,
|
|
||||||
callback: impl FnMut(&Self::EventContext, &Self::Row) + Send + 'static,
|
|
||||||
) -> ViewClosedHandsDeleteCallbackId {
|
|
||||||
ViewClosedHandsDeleteCallbackId(self.imp.on_delete(Box::new(callback)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_on_delete(&self, callback: ViewClosedHandsDeleteCallbackId) {
|
|
||||||
self.imp.remove_on_delete(callback.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub(super) fn register_table(client_cache: &mut __sdk::ClientCache<super::RemoteModule>) {
|
|
||||||
let _table = client_cache.get_or_make_table::<HandView>("view_closed_hands");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub(super) fn parse_table_update(
|
|
||||||
raw_updates: __ws::TableUpdate<__ws::BsatnFormat>,
|
|
||||||
) -> __sdk::Result<__sdk::TableUpdate<HandView>> {
|
|
||||||
__sdk::TableUpdate::parse_table_update(raw_updates).map_err(|e| {
|
|
||||||
__sdk::InternalError::failed_parse("TableUpdate<HandView>", "TableUpdate")
|
|
||||||
.with_cause(e)
|
|
||||||
.into()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
/// Extension trait for query builder access to the table `HandView`.
|
|
||||||
///
|
|
||||||
/// Implemented for [`__sdk::QueryTableAccessor`].
|
|
||||||
pub trait view_closed_handsQueryTableAccess {
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
/// Get a query builder for the table `HandView`.
|
|
||||||
fn view_closed_hands(&self) -> __sdk::__query_builder::Table<HandView>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl view_closed_handsQueryTableAccess for __sdk::QueryTableAccessor {
|
|
||||||
fn view_closed_hands(&self) -> __sdk::__query_builder::Table<HandView> {
|
|
||||||
__sdk::__query_builder::Table::new("view_closed_hands")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -55,13 +55,4 @@ mod conversions {
|
||||||
Self::from_repr(value as usize).unwrap()
|
Self::from_repr(value as usize).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&crate::db::PlayerOrBot> for jong_types::PlayerOrBot {
|
|
||||||
fn from(value: &crate::db::PlayerOrBot) -> Self {
|
|
||||||
match value {
|
|
||||||
crate::PlayerOrBot::Player(id) => Self::Player { id: *id },
|
|
||||||
crate::PlayerOrBot::Bot(id) => Self::Bot { id: *id },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,12 @@ use spacetimedb::{
|
||||||
ReducerContext, ScheduleAt::Interval, Table as _, rand::seq::SliceRandom, reducer,
|
ReducerContext, ScheduleAt::Interval, Table as _, rand::seq::SliceRandom, reducer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use jong_types::{GameState, TurnState};
|
||||||
|
|
||||||
use crate::tables::{
|
use crate::tables::{
|
||||||
DbTile, DbWall, GameTimer, Lobby, PlayerClock, PlayerHand, bot, game_timer, lobby as _, player,
|
DbTile, DbWall, GameTimer, Lobby, PlayerClock, PlayerHand, PlayerOrBot, bot, game_timer,
|
||||||
player_clock, player_hand, tile as _, wall,
|
lobby as _, player, player_clock, player_hand, tile as _, wall,
|
||||||
};
|
};
|
||||||
use jong_types::{GameState, PlayerOrBot, TurnState};
|
|
||||||
|
|
||||||
mod hand;
|
mod hand;
|
||||||
mod lobby;
|
mod lobby;
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,8 @@ pub fn discard_tile(ctx: &ReducerContext, tile_id: u32) -> Result<(), String> {
|
||||||
hand.pond.push(dealt_tile);
|
hand.pond.push(dealt_tile);
|
||||||
hand.working_tile = None;
|
hand.working_tile = None;
|
||||||
hand.turn_state = TurnState::None;
|
hand.turn_state = TurnState::None;
|
||||||
ctx.db.player_hand().id().update(hand);
|
|
||||||
|
|
||||||
let mut clock = ctx.db.player_clock().player_id().find(player.id).unwrap();
|
ctx.db.player_hand().id().update(hand);
|
||||||
clock.renew();
|
|
||||||
ctx.db.player_clock().player_id().update(clock);
|
|
||||||
|
|
||||||
let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
|
let mut lobby = ctx.db.lobby().id().find(player.lobby_id).unwrap();
|
||||||
lobby.next_player();
|
lobby.next_player();
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ use std::time::Duration;
|
||||||
use log::info;
|
use log::info;
|
||||||
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
use spacetimedb::{ReducerContext, Table, rand::seq::SliceRandom, reducer};
|
||||||
|
|
||||||
use jong_types::PlayerOrBot;
|
|
||||||
|
|
||||||
use crate::tables::*;
|
use crate::tables::*;
|
||||||
|
|
||||||
#[reducer]
|
#[reducer]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use spacetimedb::{SpacetimeType, ViewContext, table, view};
|
use spacetimedb::{SpacetimeType, ViewContext, table, view};
|
||||||
|
|
||||||
use jong_types::{
|
use jong_types::{
|
||||||
PlayerOrBot,
|
|
||||||
states::{GameState, TurnState},
|
states::{GameState, TurnState},
|
||||||
tiles::Tile,
|
tiles::Tile,
|
||||||
};
|
};
|
||||||
|
|
@ -20,7 +19,6 @@ pub struct Lobby {
|
||||||
pub current_idx: u8,
|
pub current_idx: u8,
|
||||||
|
|
||||||
pub game_state: GameState,
|
pub game_state: GameState,
|
||||||
// pub open_hands: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[table(name = wall)]
|
#[table(name = wall)]
|
||||||
|
|
@ -41,6 +39,12 @@ pub struct DbTile {
|
||||||
pub tile: Tile,
|
pub tile: Tile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, SpacetimeType)]
|
||||||
|
pub enum PlayerOrBot {
|
||||||
|
Player { id: u32 },
|
||||||
|
Bot { id: u32 },
|
||||||
|
}
|
||||||
|
|
||||||
#[table(name = player, public)]
|
#[table(name = player, public)]
|
||||||
#[table(name = logged_out_player)]
|
#[table(name = logged_out_player)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -128,48 +132,3 @@ fn view_hand(ctx: &ViewContext) -> Option<PlayerHand> {
|
||||||
.find(ctx.sender)
|
.find(ctx.sender)
|
||||||
.and_then(|p| ctx.db.player_hand().player_id().find(p.id))
|
.and_then(|p| ctx.db.player_hand().player_id().find(p.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SpacetimeType, Clone, Copy)]
|
|
||||||
pub struct HandView {
|
|
||||||
pub player: PlayerOrBot,
|
|
||||||
pub hand_length: u8,
|
|
||||||
// pub melds: u8,
|
|
||||||
pub drawn: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[view(name = view_closed_hands, public)]
|
|
||||||
fn view_closed_hands(ctx: &ViewContext) -> Vec<HandView> {
|
|
||||||
let this_player = ctx.db.player().identity().find(ctx.sender).unwrap();
|
|
||||||
ctx.db
|
|
||||||
.lobby()
|
|
||||||
.id()
|
|
||||||
.find(this_player.lobby_id)
|
|
||||||
.unwrap()
|
|
||||||
.players
|
|
||||||
.iter()
|
|
||||||
.filter_map(|&player| {
|
|
||||||
let (hand_length, drawn) = match player {
|
|
||||||
PlayerOrBot::Player { id } => {
|
|
||||||
let player_hand = ctx.db.player_hand().player_id().find(id).unwrap();
|
|
||||||
(
|
|
||||||
player_hand.hand.len() as u8,
|
|
||||||
player_hand.turn_state == TurnState::Tsumo
|
|
||||||
&& player_hand.working_tile.is_some(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
PlayerOrBot::Bot { id } => {
|
|
||||||
let bot = ctx.db.bot().id().find(id).unwrap();
|
|
||||||
(
|
|
||||||
bot.hand.len() as u8,
|
|
||||||
bot.turn_state == TurnState::Tsumo && bot.working_tile.is_some(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Some(HandView {
|
|
||||||
player,
|
|
||||||
hand_length,
|
|
||||||
drawn,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,8 @@ mod derive_alias {
|
||||||
}
|
}
|
||||||
use derive_aliases::derive;
|
use derive_aliases::derive;
|
||||||
|
|
||||||
use spacetimedb::SpacetimeType;
|
|
||||||
|
|
||||||
pub mod states;
|
pub mod states;
|
||||||
pub mod tiles;
|
pub mod tiles;
|
||||||
|
|
||||||
pub use states::*;
|
pub use states::*;
|
||||||
pub use tiles::*;
|
pub use tiles::*;
|
||||||
|
|
||||||
#[derive(Debug, ..Copy, ..Eq, Hash)]
|
|
||||||
#[derive(SpacetimeType)]
|
|
||||||
pub enum PlayerOrBot {
|
|
||||||
Player { id: u32 },
|
|
||||||
Bot { id: u32 },
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use bevy_spacetimedb::{
|
||||||
|
|
||||||
use jong_db::{
|
use jong_db::{
|
||||||
self, DbConnection, LobbyTableAccess, PlayerHand, PlayerTableAccess, RemoteTables,
|
self, DbConnection, LobbyTableAccess, PlayerHand, PlayerTableAccess, RemoteTables,
|
||||||
ViewClosedHandsTableAccess, ViewHandTableAccess as _,
|
ViewHandTableAccess as _,
|
||||||
};
|
};
|
||||||
use jong_db::{add_bot, set_ready};
|
use jong_db::{add_bot, set_ready};
|
||||||
use jong_types::*;
|
use jong_types::*;
|
||||||
|
|
@ -27,10 +27,7 @@ impl Plugin for Riichi {
|
||||||
.add_table(RemoteTables::player)
|
.add_table(RemoteTables::player)
|
||||||
.add_table(RemoteTables::lobby)
|
.add_table(RemoteTables::lobby)
|
||||||
// TODO check bevy_spacetimedb PR status
|
// TODO check bevy_spacetimedb PR status
|
||||||
.add_view_with_pk(RemoteTables::view_hand, |p| p.id)
|
.add_view_with_pk(RemoteTables::view_hand, |p| p.id);
|
||||||
.add_view_with_pk(RemoteTables::view_closed_hands, |p| {
|
|
||||||
PlayerOrBot::from(&p.player)
|
|
||||||
});
|
|
||||||
let plugins =
|
let plugins =
|
||||||
if let Some(token) = creds_store().load().expect("i/o error loading credentials") {
|
if let Some(token) = creds_store().load().expect("i/o error loading credentials") {
|
||||||
// FIXME patch plugin so this takes Option?
|
// FIXME patch plugin so this takes Option?
|
||||||
|
|
@ -94,9 +91,8 @@ fn subscriptions(stdb: SpacetimeDB, mut commands: Commands) {
|
||||||
),
|
),
|
||||||
"SELECT l.* FROM lobby l JOIN player p ON l.id = p.lobby_id".to_string(),
|
"SELECT l.* FROM lobby l JOIN player p ON l.id = p.lobby_id".to_string(),
|
||||||
"SELECT c.* FROM player_clock c JOIN player p ON c.player_id = p.id".to_string(),
|
"SELECT c.* FROM player_clock c JOIN player p ON c.player_id = p.id".to_string(),
|
||||||
"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_hand".to_string(),
|
||||||
"SELECT * FROM view_closed_hands".to_string(),
|
"SELECT b.* FROM bot b JOIN lobby l ON l.id = b.lobby_id".to_string(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
while let Ok(event) = recv.recv() {
|
while let Ok(event) = recv.recv() {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_ratatui::RatatuiContext;
|
use bevy_ratatui::RatatuiContext;
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Flex, Layout, Margin},
|
layout::{Constraint, Layout, Margin},
|
||||||
prelude::Rect,
|
prelude::Rect,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -12,19 +12,15 @@ pub(crate) struct Overlays {
|
||||||
|
|
||||||
pub(crate) enum Overlay {}
|
pub(crate) enum Overlay {}
|
||||||
|
|
||||||
#[derive(Resource, Clone)]
|
#[derive(Resource, Clone, Copy)]
|
||||||
pub(crate) struct HandLayouts {
|
pub(crate) struct HandLayouts {
|
||||||
pub(crate) left_pond: Rect,
|
pub(crate) left_pond: Rect,
|
||||||
pub(crate) left_hand: Rect,
|
|
||||||
|
|
||||||
pub(crate) cross_pond: Rect,
|
pub(crate) cross_pond: Rect,
|
||||||
pub(crate) cross_hand: Rect,
|
|
||||||
|
|
||||||
pub(crate) right_pond: Rect,
|
pub(crate) right_pond: Rect,
|
||||||
pub(crate) right_hand: Rect,
|
|
||||||
|
|
||||||
pub(crate) this_pond: Rect,
|
pub(crate) this_pond: Rect,
|
||||||
pub(crate) this_pond_slots: Vec<Rect>,
|
pub(crate) left_hand: Rect,
|
||||||
|
pub(crate) cross_hand: Rect,
|
||||||
|
pub(crate) right_hand: Rect,
|
||||||
pub(crate) this_hand: Rect,
|
pub(crate) this_hand: Rect,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,28 +69,14 @@ fn tiles_areas(term_area: Rect) -> HandLayouts {
|
||||||
right_pond.height = cross_pond.height;
|
right_pond.height = cross_pond.height;
|
||||||
right_pond.y += cross_pond.height / 2;
|
right_pond.y += cross_pond.height / 2;
|
||||||
|
|
||||||
let this_pond_row_constraints = [Constraint::Max(4); 3];
|
|
||||||
let this_pond_col_constraints = [Constraint::Max(5); 6];
|
|
||||||
let this_pond_row_layouts = Layout::vertical(this_pond_row_constraints).flex(Flex::Start);
|
|
||||||
let this_pond_col_layouts = Layout::horizontal(this_pond_col_constraints).flex(Flex::Start);
|
|
||||||
let mut this_pond_rows = this_pond_row_layouts.areas::<3>(this_pond);
|
|
||||||
let this_pond_slots: Vec<_> = this_pond_rows
|
|
||||||
.iter()
|
|
||||||
.flat_map(|row| this_pond_col_layouts.areas::<6>(*row))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
HandLayouts {
|
HandLayouts {
|
||||||
left_pond,
|
left_pond,
|
||||||
left_hand,
|
|
||||||
|
|
||||||
cross_pond,
|
cross_pond,
|
||||||
cross_hand,
|
|
||||||
|
|
||||||
right_pond,
|
right_pond,
|
||||||
right_hand,
|
|
||||||
|
|
||||||
this_pond,
|
this_pond,
|
||||||
|
left_hand,
|
||||||
|
cross_hand,
|
||||||
|
right_hand,
|
||||||
this_hand,
|
this_hand,
|
||||||
this_pond_slots,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,21 @@ pub(crate) fn render(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn query_tester(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut tui: ResMut<RatatuiContext>,
|
||||||
|
|
||||||
|
hovered: Query<Entity, With<Hovered>>,
|
||||||
|
layouts: Res<HandLayouts>,
|
||||||
|
|
||||||
|
tiles: Query<&jong_types::Tile>,
|
||||||
|
// main_player: Single<(&Player, Entity /* , &Wind */), With<MainPlayer>>,
|
||||||
|
hand: Single<(&Children, Entity), With<Hand>>,
|
||||||
|
drawn_tile: Option<Single<Entity, With<Drawn>>>,
|
||||||
|
) {
|
||||||
|
trace!("owo")
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME we don't care about other players atm
|
// FIXME we don't care about other players atm
|
||||||
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
|
||||||
pub(crate) fn render_hand(
|
pub(crate) fn render_hand(
|
||||||
|
|
@ -108,7 +123,7 @@ pub(crate) fn render_hand(
|
||||||
drawn_tile: Option<Single<Entity, With<Drawn>>>,
|
drawn_tile: Option<Single<Entity, With<Drawn>>>,
|
||||||
) -> Result {
|
) -> Result {
|
||||||
let mut frame = tui.get_frame();
|
let mut frame = tui.get_frame();
|
||||||
debug_blocks(layouts.clone(), &mut frame);
|
debug_blocks(*layouts, &mut frame);
|
||||||
|
|
||||||
let hand: Vec<_> = hand
|
let hand: Vec<_> = hand
|
||||||
.0
|
.0
|
||||||
|
|
@ -219,8 +234,19 @@ pub(crate) fn render_pond(
|
||||||
})
|
})
|
||||||
.collect::<Result<_>>()?;
|
.collect::<Result<_>>()?;
|
||||||
|
|
||||||
for (rect, (_, tile)) in layouts.this_pond_slots.iter().zip(pond) {
|
let mut this_pond = layouts.this_pond;
|
||||||
frame.render_widget(tile, *rect);
|
let row_constraints = [Constraint::Max(4); 3];
|
||||||
|
let col_constraints = [Constraint::Max(5); 6];
|
||||||
|
let row_layouts = Layout::vertical(row_constraints).flex(Flex::Start);
|
||||||
|
let col_layouts = Layout::horizontal(col_constraints).flex(Flex::Start);
|
||||||
|
let mut rows = row_layouts.areas::<3>(this_pond);
|
||||||
|
|
||||||
|
for (rect, (_, tile)) in rows
|
||||||
|
.iter()
|
||||||
|
.flat_map(|row| col_layouts.areas::<6>(*row))
|
||||||
|
.zip(pond)
|
||||||
|
{
|
||||||
|
frame.render_widget(tile, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue