diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-09-07 21:03:07 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-09-07 21:05:17 -0400 |
commit | f92ca7acbf6998f8cd2cb6b7e1116fcbd29767e4 (patch) | |
tree | 597eb56bfda5a11fddded9a1e739e42abe0a435d /webapp/src/main.rs | |
parent | 1fa6d19a698f62ea2e57164fa1e5f088a8e2ac62 (diff) |
Add game component integrated with bidding component
Diffstat (limited to 'webapp/src/main.rs')
-rw-r--r-- | webapp/src/main.rs | 43 |
1 files changed, 2 insertions, 41 deletions
diff --git a/webapp/src/main.rs b/webapp/src/main.rs index 3e77598..b6d75ee 100644 --- a/webapp/src/main.rs +++ b/webapp/src/main.rs @@ -5,16 +5,13 @@ use yew::prelude::*; pub mod bridge_engine; pub mod card; pub mod components; -use bridge_engine::Player; -use components::{Bidding, Hand, HandProps}; +use components::Game; extern crate wee_alloc; // Use `wee_alloc` as the global allocator. #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; -pub const SUIT_DISPLAY_ORDER: [Suit; 4] = [Suit::Diamond, Suit::Club, Suit::Heart, Suit::Spade]; - fn main() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); wasm_logger::init(wasm_logger::Config::default()); @@ -23,45 +20,9 @@ fn main() { #[function_component(App)] pub fn app() -> Html { - let mut rng = rand::thread_rng(); - let mut deal = card::deal(&mut rng); - deal.sort(&SUIT_DISPLAY_ORDER, card::RankOrder::Descending); - - let north = use_state(|| HandProps::from_iter(deal.north.into_iter())); - let west = use_state(|| HandProps::from_iter(deal.west.into_iter())); - let south = use_state(|| HandProps::from_iter(deal.south.into_iter())); - let east = use_state(|| HandProps::from_iter(deal.east.into_iter())); - - let shuffle = { - let north = north.clone(); - let west = west.clone(); - let south = south.clone(); - let east = east.clone(); - - Callback::from(move |_| { - let mut rng = rand::thread_rng(); - let mut deal = card::deal(&mut rng); - deal.sort(&SUIT_DISPLAY_ORDER, card::RankOrder::Descending); - north.set(deal.north.into_iter().collect()); - west.set(deal.west.into_iter().collect()); - south.set(deal.south.into_iter().collect()); - east.set(deal.east.into_iter().collect()); - }) - }; - html! { <> - <Bidding dealer={ Player::East } /> - <p>{ "North" }</p> - <Hand ..(*north).clone() /> - <p>{ "West" }</p> - <Hand ..(*west).clone() /> - <p>{ "South" }</p> - <Hand ..(*south).clone() /> - <p>{ "East" }</p> - <Hand ..(*east).clone() /> - <p>{ "Controls" }</p> - <button onclick={shuffle}>{ "Shuffle" }</button> + <Game /> </> } } |