summaryrefslogtreecommitdiff
path: root/webapp/src/components/game.rs
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/src/components/game.rs')
-rw-r--r--webapp/src/components/game.rs43
1 files changed, 28 insertions, 15 deletions
diff --git a/webapp/src/components/game.rs b/webapp/src/components/game.rs
index c5e2602..9d45095 100644
--- a/webapp/src/components/game.rs
+++ b/webapp/src/components/game.rs
@@ -1,6 +1,8 @@
-use protocol::bridge_engine::{DealInPlay, DealInPlayResult, Player, GameState, deal};
use crate::components::{Bidding, Hand, ShowBid, TrickInPlay, TricksPlayed};
use log::{error, info};
+use protocol::bridge_engine::{
+ deal, BiddingState, DealInPlay, DealInPlayResult, GameState, PlayState, Player,
+};
use yew::prelude::*;
fn init_state() -> GameState {
@@ -21,22 +23,27 @@ pub fn game() -> Html {
let on_card_clicked = {
let state = state.clone();
Callback::from(move |card| {
- if let GameState::Play {
+ if let GameState::Play(PlayState {
dealer,
playing_deal,
contract,
bidding,
- } = (*state).clone()
+ deal,
+ ..
+ }) = (*state).clone()
{
info!("Card clicked: {}", card);
match playing_deal.play(card) {
Err(err) => error!("Could not play card: {:?}", err),
- Ok(DealInPlayResult::InProgress(playing_deal)) => state.set(GameState::Play {
- dealer,
- playing_deal,
- contract,
- bidding,
- }),
+ Ok(DealInPlayResult::InProgress(playing_deal)) => {
+ state.set(GameState::Play(PlayState {
+ dealer,
+ playing_deal,
+ contract,
+ bidding,
+ deal,
+ }))
+ }
Ok(DealInPlayResult::PlayFinished(_tricks)) => todo!(),
};
}
@@ -44,19 +51,24 @@ pub fn game() -> Html {
};
let center = match &*state {
- GameState::Bidding { dealer, deal, bidding } => {
+ GameState::Bidding(BiddingState {
+ dealer,
+ deal,
+ bidding,
+ }) => {
let on_contract = {
let state = state.clone();
let dealer = dealer.clone();
let deal = deal.clone();
Callback::from(move |(contract, bidding)| {
state.set(match contract {
- Some(contract) => GameState::Play {
+ Some(contract) => GameState::Play(PlayState {
dealer,
+ deal: deal.clone(),
playing_deal: DealInPlay::new(dealer, deal.clone()),
contract,
bidding,
- },
+ }),
None => GameState::PassedOut {
dealer: dealer,
deal: deal.clone(),
@@ -69,12 +81,13 @@ pub fn game() -> Html {
<Bidding {on_contract} dealer={dealer.clone()} />
}
}
- GameState::Play {
+ GameState::Play(PlayState {
+ deal,
dealer,
playing_deal,
contract: _,
bidding: _,
- } => {
+ }) => {
html! {
<>
<TricksPlayed tricks={ playing_deal.tricks().clone() } />
@@ -88,7 +101,7 @@ pub fn game() -> Html {
html! {
<>
<div class="nav">
- if let GameState::Play { contract, bidding, .. } = &*state {
+ if let GameState::Play(PlayState { contract, bidding, .. }) = &*state {
<ShowBid contract={contract.clone()} bidding={bidding.clone()}/>
}
<button onclick={shuffle}>{ "Shuffle" }</button>