diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2022-12-22 13:31:24 -0500 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2022-12-22 13:39:11 -0500 |
commit | 22452073063b9211aa2aa38a1b1e2cf2e44cf133 (patch) | |
tree | 7988fed422b019a6ff5ba057d17f83082b05c440 /webapp/src | |
parent | c2145b91775be375779884a2a97365396923aba1 (diff) |
Delete outdated `game` component
Diffstat (limited to 'webapp/src')
-rw-r--r-- | webapp/src/components.rs | 2 | ||||
-rw-r--r-- | webapp/src/components/game.rs | 135 | ||||
-rw-r--r-- | webapp/src/main.rs | 6 | ||||
-rw-r--r-- | webapp/src/routing.rs | 2 |
4 files changed, 1 insertions, 144 deletions
diff --git a/webapp/src/components.rs b/webapp/src/components.rs index aa3636f..d4b03ee 100644 --- a/webapp/src/components.rs +++ b/webapp/src/components.rs @@ -6,7 +6,6 @@ mod bidding_box; mod bidding_table; mod card; mod error_info; -mod game; mod hand; mod show_bid; mod table; @@ -19,7 +18,6 @@ pub use self::bidding_box::*; pub use self::bidding_table::*; pub use self::card::*; pub use self::error_info::*; -pub use self::game::*; pub use self::hand::*; pub use self::show_bid::*; pub use self::table::*; diff --git a/webapp/src/components/game.rs b/webapp/src/components/game.rs deleted file mode 100644 index c590357..0000000 --- a/webapp/src/components/game.rs +++ /dev/null @@ -1,135 +0,0 @@ -use crate::components::{Bidding, Hand, ShowBid, TrickInPlay, TricksPlayed}; -use log::{error, info}; -use protocol::bridge_engine::{ - BiddingState, DealInPlay, DealInPlayResult, GameState, PlayState, Player, -}; -use rand::random; -use yew::prelude::*; - -fn init_state() -> GameState { - GameState::new(random(), Player::East) -} - -#[function_component(Game)] -pub fn game() -> Html { - let state = use_state(|| init_state()); - - let shuffle = { - let state = state.clone(); - Callback::from(move |_| { - state.set(init_state()); - }) - }; - - let on_card_clicked = { - let state = state.clone(); - Callback::from(move |card| { - if let GameState::Play(PlayState { - dealer, - playing_deal, - contract, - bidding, - 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(PlayState { - dealer, - playing_deal, - contract, - bidding, - deal, - })) - } - Ok(DealInPlayResult::PlayFinished(_tricks)) => todo!(), - }; - } - }) - }; - - let center = match &*state { - 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(PlayState { - dealer, - deal: deal.clone(), - playing_deal: DealInPlay::new(dealer, deal.clone()), - contract, - bidding, - }), - None => GameState::PassedOut { - dealer: dealer, - deal: deal.clone(), - bidding: bidding, - }, - }); - }) - }; - html! { - <Bidding {on_contract} dealer={dealer.clone()} /> - } - } - GameState::Play(PlayState { - deal, - dealer, - playing_deal, - contract: _, - bidding: _, - }) => { - html! { - <> - <TricksPlayed tricks={ playing_deal.tricks().clone() } /> - <TrickInPlay in_progress={ playing_deal.trick_in_play().clone() } /> - </> - } - } - GameState::PassedOut { .. } => html! { <p>{ "Everyone passed" }</p> }, - }; - - html! { - <> - <div class="nav"> - if let GameState::Play(PlayState { contract, bidding, .. }) = &*state { - <ShowBid contract={contract.clone()} bidding={bidding.clone()}/> - } - <button onclick={shuffle}>{ "Shuffle" }</button> - </div> - <div class="center"> - { center } - </div> - <div class="hand west"> - <Hand cards={ state.deal().west.clone() } - on_card_clicked={ on_card_clicked.clone() } - /> - </div> - <div class="hand north"> - <Hand cards={ state.deal().north.clone() } - on_card_clicked={ on_card_clicked.clone() } - /> - </div> - <div class="hand east"> - <Hand cards={ state.deal().east.clone() } - on_card_clicked={ on_card_clicked.clone() } - /> - </div> - <div class="hand south"> - <Hand cards={ state.deal().south.clone() } - on_card_clicked={ on_card_clicked.clone() } - /> - </div> - </> - } -} diff --git a/webapp/src/main.rs b/webapp/src/main.rs index f99dfe0..73531d5 100644 --- a/webapp/src/main.rs +++ b/webapp/src/main.rs @@ -4,7 +4,7 @@ use yew::prelude::*; use yew_router::prelude::*; pub mod components; pub mod utils; -use components::{AppContextProvider, ErrorInfo, Game, OnlineTable}; +use components::{AppContextProvider, ErrorInfo, OnlineTable}; extern crate wee_alloc; pub mod routing; use crate::{components::use_app_context, routing::Route}; @@ -60,7 +60,6 @@ fn home() -> Html { html! { <ul> <li>{ user }</li> - <li><Link<Route> to={Route::Playground}>{ "Playground" }</Link<Route>></li> <li><button onclick={create_table}>{ "Create table" }</button></li> </ul> } @@ -79,9 +78,6 @@ fn header() -> Html { fn switch(routes: &Route) -> Html { let main = match routes { Route::Home => html! { <Home/> }, - Route::Playground => html! { - <div class="game-layout"><Game /></div> - }, Route::Table { id } => html! { <OnlineTable table={ protocol::Table { id: *id } } /> }, diff --git a/webapp/src/routing.rs b/webapp/src/routing.rs index e451791..57d4af0 100644 --- a/webapp/src/routing.rs +++ b/webapp/src/routing.rs @@ -5,8 +5,6 @@ use uuid::Uuid; pub enum Route { #[at("/")] Home, - #[at("/playground")] - Playground, #[at("/table/:id")] Table { id: Uuid }, } |