blob: 3e77598bb51567cfe2c765314f7a2aaae4278617 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
use crate::card::Suit;
#[allow(unused_imports)]
use log::{debug, error, info, warn};
use yew::prelude::*;
pub mod bridge_engine;
pub mod card;
pub mod components;
use bridge_engine::Player;
use components::{Bidding, Hand, HandProps};
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());
yew::start_app::<App>();
}
#[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>
</>
}
}
#[cfg(test)]
mod tests {
pub fn test_setup() {
dotenv::dotenv().ok();
let _ = env_logger::builder().is_test(true).try_init();
}
}
|