use futures::channel::mpsc::UnboundedSender; use leptos::prelude::*; use crate::app::{GameUiState, NetCommand}; use crate::trictrac::types::{PlayerAction, SerStage, SerTurnStage}; use super::board::Board; use super::score_panel::ScorePanel; #[component] pub fn GameScreen(state: GameUiState) -> impl IntoView { let vs = state.view_state.clone(); let player_id = state.player_id; let is_my_turn = vs.active_mp_player == Some(player_id); let status = match &vs.stage { SerStage::Ended => "Game over".to_string(), SerStage::PreGame => "Waiting for opponent…".to_string(), SerStage::InGame => match (is_my_turn, &vs.turn_stage) { (true, SerTurnStage::RollDice) => "Your turn — roll the dice".to_string(), (true, SerTurnStage::HoldOrGoChoice) => "Hold or Go?".to_string(), (true, SerTurnStage::Move) => "Your turn — move a checker".to_string(), (true, _) => "Your turn".to_string(), (false, _) => "Opponent's turn".to_string(), }, }; let dice_text = if vs.dice != (0, 0) { format!("Dice: {} & {}", vs.dice.0, vs.dice.1) } else { String::new() }; let cmd_tx = use_context::>() .expect("UnboundedSender not found in context"); let cmd_tx2 = cmd_tx.clone(); let show_roll = is_my_turn && vs.turn_stage == SerTurnStage::RollDice; let show_hold_go = is_my_turn && vs.turn_stage == SerTurnStage::HoldOrGoChoice; view! {
{status} {(!dice_text.is_empty()).then(|| view! { {dice_text} })}
{show_roll.then(|| view! { })} {show_hold_go.then(|| view! { })} {show_hold_go.then(|| { let cmd_tx3 = use_context::>() .expect("UnboundedSender not found in context"); view! { } })}
} }