diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-09-10 14:49:38 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-09-10 14:49:38 -0400 |
commit | 55a24a3b7d1b3fcc07f0bb8e53b00abf23e651b3 (patch) | |
tree | e85911ccc1eca8c820d7b4f40c9e3b36aa121034 /webapp/src/components/game.rs | |
parent | 5ad23c12d718e5b4b6f9076ef2d29de5addd40fc (diff) |
Add nav bar with context
Diffstat (limited to 'webapp/src/components/game.rs')
-rw-r--r-- | webapp/src/components/game.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/webapp/src/components/game.rs b/webapp/src/components/game.rs index 33fb5b7..0f25fc3 100644 --- a/webapp/src/components/game.rs +++ b/webapp/src/components/game.rs @@ -1,11 +1,17 @@ use crate::bridge_engine::{self, Contract, Player}; use crate::card; use crate::card::Suit; -use crate::components::{Bidding, Hand, HandProps}; +use crate::components::{Bidding, Hand, HandProps, ShowBid}; use yew::prelude::*; pub const SUIT_DISPLAY_ORDER: [Suit; 4] = [Suit::Diamond, Suit::Club, Suit::Heart, Suit::Spade]; +#[derive(Debug)] +enum Phase { + Bidding, + Cardplay, +} + #[function_component(Game)] pub fn game() -> Html { let mut rng = rand::thread_rng(); @@ -25,12 +31,19 @@ pub fn game() -> Html { Callback::from(move |c| contract.set(Some(c))) }; + let phase = if contract.is_none() { + Phase::Bidding + } else { + Phase::Cardplay + }; + let shuffle = { let north = north.clone(); let west = west.clone(); let south = south.clone(); let east = east.clone(); let dealer = dealer.clone(); + let contract = contract.clone(); Callback::from(move |_| { let mut rng = rand::thread_rng(); @@ -42,19 +55,26 @@ pub fn game() -> Html { east.set(deal.east.into_iter().collect()); dealer.set(dealer.next()); + contract.set(None); }) }; html! { <> + <div class="nav"> + if let Some((contract, bidding)) = &*contract { + <ShowBid contract={contract.clone()} bidding={bidding.clone()}/> + } + <p>{ format!("Phase: {:?}", phase) }</p> + <button onclick={shuffle}>{ "Shuffle" }</button> + </div> <div class="center"> <p>{ format!("Dealer: {:?}", *dealer) }</p> - if let Some((contract, bidding)) = &*contract { - { format!("Got contract {:?}. Bidding was {:?}", contract, bidding) } + if let Some(_) = &*contract { + { "Let's play" } } else { <Bidding {on_contract} dealer={ *dealer } /> } - <button onclick={shuffle}>{ "Shuffle" }</button> </div> <div class="hand west"> <Hand ..(*west).clone() /> |