summaryrefslogtreecommitdiff
path: root/webapp/src
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2022-12-03 13:49:54 -0500
committerKjetil Orbekk <kj@orbekk.com>2022-12-03 13:49:54 -0500
commite6933ac48848b598f870ff5a9d96a0336728620b (patch)
tree3c6b9e9c9a6100b1400dd1a02fc07fbb5803d7b7 /webapp/src
parent03ad7a9728c22a8016ade56f79049e32db5941ac (diff)
Display player turn in webapp
Diffstat (limited to 'webapp/src')
-rw-r--r--webapp/src/components/game.rs43
-rw-r--r--webapp/src/components/table.rs22
2 files changed, 35 insertions, 30 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>
diff --git a/webapp/src/components/table.rs b/webapp/src/components/table.rs
index a285449..7c0b3a3 100644
--- a/webapp/src/components/table.rs
+++ b/webapp/src/components/table.rs
@@ -1,10 +1,10 @@
-use crate::components::{Hand, BiddingTable, BiddingBox};
+use crate::components::{BiddingBox, BiddingTable, Hand};
use crate::use_app_context;
use crate::utils::ok_json;
use anyhow::Context;
use gloo_net::http::Request;
use log::info;
-use protocol::bridge_engine::GameStatePlayerView;
+use protocol::bridge_engine::{GameStatePlayerView, BiddingState, BiddingStatePlayerView};
use yew::prelude::*;
#[function_component(OnlineTable)]
@@ -72,24 +72,16 @@ pub fn table(props: &TableProps) -> Html {
})
};
let center = match &props.table {
- GameStatePlayerView::Bidding {
- bidding,
- ..
- } => html! {
+ GameStatePlayerView::Bidding(BiddingStatePlayerView { bidding, .. }) => html! {
<>
<BiddingTable bidding={bidding.clone()} />
<BiddingBox current_bid={bidding.highest_bid().clone()} { on_bid } />
+ { format!("It is {:?} to bid", bidding.current_bidder()) }
</>
},
- GameStatePlayerView::PassedOut {
- ..
- } => todo!(),
- GameStatePlayerView::Lead {
- ..
- } => todo!(),
- GameStatePlayerView::Play {
- ..
- } => todo!(),
+ GameStatePlayerView::PassedOut { .. } => todo!(),
+ GameStatePlayerView::Lead { .. } => todo!(),
+ GameStatePlayerView::Play { .. } => todo!(),
};
html! {
<>