From b3060266e4d4e6da4141f5e7690162d017aaacf7 Mon Sep 17 00:00:00 2001 From: Ryan Khetlyr Date: Mon, 9 Dec 2024 05:01:24 -0800 Subject: [PATCH] fix win-loss updating --- src/components/game.rs | 73 +++++++++++++++++++++++++++----------- src/main.rs | 79 ++++++++++++++++++++++-------------------- 2 files changed, 93 insertions(+), 59 deletions(-) diff --git a/src/components/game.rs b/src/components/game.rs index 164f402..8daee40 100644 --- a/src/components/game.rs +++ b/src/components/game.rs @@ -70,6 +70,7 @@ pub fn Game( #[prop(into)] opponent: Opponent, #[prop(into)] speed: GameSpeed, #[prop(into)] on_exit: Callback<()>, + #[prop(into)] on_stats_update: Callback<()>, ) -> impl IntoView { let game_state = RwSignal::new({ let mut state = GameState::new(player_name, opponent); @@ -302,27 +303,56 @@ pub fn Game( {move || { let current_state = game_state.get(); if current_state.current_round < 8 { - view! { - + view! { +
+

+ "Choose your next board" +

+
+ 1, + GameSpeed::Quick => 5, + GameSpeed::Relaxed => 10, + GameSpeed::Chill => 999999, + }); + game_state.set(current_state); + } + > + Board option + + } + } + /> +
+
}.into_any() } else { let current_state_clone = current_state.clone(); // Clone here for the second button @@ -361,6 +391,7 @@ pub fn Game( if let Some(opponent) = current_state_clone.player2.clone() { let won = current_state_clone.player1_score > current_state_clone.player2_score; let _ = update_opponent_stats(&opponent.id, won); + on_stats_update.run(()); } on_exit.run(()); } diff --git a/src/main.rs b/src/main.rs index 1acb02a..666727c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -195,41 +195,38 @@ fn App() -> impl IntoView { {move || (!show_form.get()).then(|| view! {
-

"Opponents"

-
- -
- - {if matches!(opponent.opponent_type, OpponentType::Computer) { "C" } else { "H" }} - - {opponent.name.clone()} - {move || { - if let Some(user_data) = load_user_data() { - if let Some(stats) = user_data.opponent_stats.get(&opponent_for_stats.id) { - view! { - - "(" {stats.wins} "-" {stats.losses} ")" - - }.into_any() - } else { - view! { - "(0-0)" - }.into_any() - } - } else { - view! { - "(0-0)" - }.into_any() - } - }} -
-
+

"Opponents"

+
+ +
+ + {if matches!(opponent.opponent_type, OpponentType::Computer) { "C" } else { "H" }} + + {opponent.name.clone()} + + "(" {move || opponent_stats.get().0} "-" {move || opponent_stats.get().1} ")" + +
+
{ let delete_opponent = opponent.clone(); view! { @@ -377,12 +374,18 @@ fn App() -> impl IntoView {
})}
- {move || show_game.get().map(|(opponent, speed)| view! { // Change this line to destructure both values + {move || show_game.get().map(|(opponent, speed)| view! { })} {move || show_profile.get().then(|| view! {