From 2205edfa06f3c9ddecfca2f01afc0f5e88c7d6fc Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Sat, 3 Dec 2022 17:26:07 -0500 Subject: Add server table state --- server/src/play.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'server/src') diff --git a/server/src/play.rs b/server/src/play.rs index 8d79977..33a14f9 100644 --- a/server/src/play.rs +++ b/server/src/play.rs @@ -74,11 +74,27 @@ impl Journal for DbJournal { } } +#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize)] +pub enum TableUpdate { + NewDeal(Deal, Player), + ChangeSettings(TableSettings), + Bid(Bid), +} + +#[derive(PartialEq, Eq, Clone, Debug, Serialize, Deserialize, Default)] +pub struct TableSettings { + west_player: Option, + nort_player: Option, + east_player: Option, + south_player: Option, +} + pub struct Table where J: Journal, { journal: J, + settings: TableSettings, game: GameState, } @@ -89,11 +105,11 @@ impl Table { impl Table { pub async fn new(mut journal: J) -> Result { let game = Self::init(&mut journal).await?; - Ok(Table { journal, game }) + Ok(Table { journal, game, settings: Default::default() }) } async fn init(journal: &mut J) -> Result { - let game = GameState::new(bridge_engine::deal(), Player::East); + let game = GameState::new(random(), Player::East); journal.append(0, json!(game)).await?; Ok(game) } @@ -104,7 +120,7 @@ impl Table { return Err(BridgeError::NotFound("table journal missing".to_string())); } let game = serde_json::from_value(games[games.len() - 1].clone())?; - Ok(Table { journal, game } ) + Ok(Table { journal, game, settings: Default::default() } ) } pub async fn new_or_replay(mut journal: J) -> Result { @@ -112,7 +128,7 @@ impl Table { if let Err(BridgeError::JournalConflict(..)) = game { return Self::replay(journal).await; } - Ok(Self { journal, game: game? } ) + Ok(Self { journal, game: game?, settings: Default::default() } ) } } -- cgit v1.2.3