diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-03 17:26:07 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-03 17:26:07 -0500 |
commit | 2205edfa06f3c9ddecfca2f01afc0f5e88c7d6fc (patch) | |
tree | b30b30efe05d37079474f0d1727079c1440cbc67 /server/src | |
parent | 581e9ec21a85a3d2f908016c28d831e8022cb1f4 (diff) |
Add server table state
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/play.rs | 24 |
1 files changed, 20 insertions, 4 deletions
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<String>, + nort_player: Option<String>, + east_player: Option<String>, + south_player: Option<String>, +} + pub struct Table<J> where J: Journal, { journal: J, + settings: TableSettings, game: GameState, } @@ -89,11 +105,11 @@ impl<J: Journal> Table<J> { impl<J: Journal> Table<J> { pub async fn new(mut journal: J) -> Result<Self, BridgeError> { 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<GameState, BridgeError> { - 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<J: Journal> Table<J> { 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<Self, BridgeError> { @@ -112,7 +128,7 @@ impl<J: Journal> Table<J> { if let Err(BridgeError::JournalConflict(..)) = game { return Self::replay(journal).await; } - Ok(Self { journal, game: game? } ) + Ok(Self { journal, game: game?, settings: Default::default() } ) } } |