diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-09-22 09:15:09 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-09-22 09:15:09 -0400 |
commit | 030b45c000210b153b5ef224ddcaa668de763638 (patch) | |
tree | dfeb3d8c6ee803c41b96b2dd3f6da0fbe38614b2 /webapp | |
parent | d66f16ae60190eebe711f7f2fb931513d711cd32 (diff) |
Add component for current trick
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/src/bridge_engine.rs | 12 | ||||
-rw-r--r-- | webapp/src/components.rs | 2 | ||||
-rw-r--r-- | webapp/src/components/card.rs | 1 | ||||
-rw-r--r-- | webapp/src/components/game.rs | 15 | ||||
-rw-r--r-- | webapp/src/components/trick_in_play.rs | 23 |
5 files changed, 51 insertions, 2 deletions
diff --git a/webapp/src/bridge_engine.rs b/webapp/src/bridge_engine.rs index d58a8dc..b13d715 100644 --- a/webapp/src/bridge_engine.rs +++ b/webapp/src/bridge_engine.rs @@ -79,6 +79,14 @@ impl PlayTurn { } } + pub fn leader(&self) -> Player { + self.trick.leader + } + + pub fn cards_played(&self) -> &[Card] { + &self.trick.cards_played[..] + } + pub fn play(mut self: PlayTurn, card: Card) -> PlayResult { self.trick.cards_played.push(card); if self.trick.cards_played.len() >= 4 { @@ -114,6 +122,10 @@ impl PlayingDeal { } } + pub fn trick_in_play(&self) -> &PlayTurn { + &self.in_progress + } + pub fn deal(&self) -> &Deal { &self.deal } diff --git a/webapp/src/components.rs b/webapp/src/components.rs index 5deedb5..073de58 100644 --- a/webapp/src/components.rs +++ b/webapp/src/components.rs @@ -7,7 +7,9 @@ mod bidding_box; mod bidding; mod show_bid; mod game; +mod trick_in_play; +pub use self::trick_in_play::*; pub use self::card::*; pub use self::bidding_box::*; pub use self::bidding_table::*; diff --git a/webapp/src/components/card.rs b/webapp/src/components/card.rs index 5401899..d5aee36 100644 --- a/webapp/src/components/card.rs +++ b/webapp/src/components/card.rs @@ -24,5 +24,6 @@ pub fn ccard(props: &CardProps) -> Html { #[derive(PartialEq, Properties, Clone)] pub struct CardProps { pub card: card::Card, + #[prop_or_default] pub onclick: Callback<card::Card>, } diff --git a/webapp/src/components/game.rs b/webapp/src/components/game.rs index e893691..accdd33 100644 --- a/webapp/src/components/game.rs +++ b/webapp/src/components/game.rs @@ -2,7 +2,7 @@ use crate::bridge_engine::{self, Contract, Player, PlayingDeal, PlayingDealResul use crate::card; use crate::card::Deal; use crate::card::Suit; -use crate::components::{Bidding, Hand, ShowBid}; +use crate::components::{Bidding, Hand, ShowBid, TrickInPlay}; use log::{error, info}; use yew::prelude::*; @@ -108,7 +108,18 @@ pub fn game() -> Html { <Bidding {on_contract} dealer={dealer.clone()} /> } } - GameState::Play { .. } => html! { <p>{ "Time to play" }</p> }, + GameState::Play { + playing_deal, + contract, + bidding, + } => { + html! { + <> + <p>{ "Time to play" }</p> + <TrickInPlay in_progress={ playing_deal.trick_in_play().clone() } /> + </> + } + }, GameState::PassedOut { .. } => html! { <p>{ "Everyone passed" }</p> }, }; diff --git a/webapp/src/components/trick_in_play.rs b/webapp/src/components/trick_in_play.rs new file mode 100644 index 0000000..086a422 --- /dev/null +++ b/webapp/src/components/trick_in_play.rs @@ -0,0 +1,23 @@ +use yew::prelude::*; +use crate::bridge_engine::PlayTurn; +use crate::components::Card; + +#[function_component(TrickInPlay)] +pub fn trick_in_play(props: &TrickInPlayProps) -> Html { + let cards = props.in_progress.cards_played().iter().map(|card| { + html! { + <Card card={ card.clone() } /> + } + }); +html! { + <> + <p>{ format!("Leader: {:?}", props.in_progress.leader()) }</p> + { for cards } + </> +} +} + +#[derive(PartialEq, Properties, Clone)] +pub struct TrickInPlayProps { + pub in_progress: PlayTurn, +} |