feat: add client_web (leptos impl. for 'multiplayer' project)
This commit is contained in:
parent
46416cdaef
commit
44451d8642
15 changed files with 1661 additions and 9 deletions
6
client_web/src/components/connecting_screen.rs
Normal file
6
client_web/src/components/connecting_screen.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
use leptos::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub fn ConnectingScreen() -> impl IntoView {
|
||||
view! { <p class="connecting">"Connecting…"</p> }
|
||||
}
|
||||
25
client_web/src/components/game_screen.rs
Normal file
25
client_web/src/components/game_screen.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use leptos::prelude::*;
|
||||
|
||||
use crate::app::GameUiState;
|
||||
use crate::trictrac::types::SerStage;
|
||||
|
||||
#[component]
|
||||
pub fn GameScreen(state: GameUiState) -> impl IntoView {
|
||||
let status = match state.view_state.stage {
|
||||
SerStage::Ended => "Game over",
|
||||
SerStage::PreGame => "Waiting for players…",
|
||||
SerStage::InGame => match state.view_state.active_mp_player {
|
||||
Some(id) if id == state.player_id => "Your turn",
|
||||
Some(_) => "Opponent's turn",
|
||||
None => "…",
|
||||
},
|
||||
};
|
||||
|
||||
view! {
|
||||
<div class="game-container">
|
||||
<p class="status-bar">{status}</p>
|
||||
// Board and score panel will be added in a subsequent step.
|
||||
<p>"Board placeholder"</p>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
54
client_web/src/components/login_screen.rs
Normal file
54
client_web/src/components/login_screen.rs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
use futures::channel::mpsc::UnboundedSender;
|
||||
use leptos::prelude::*;
|
||||
|
||||
use crate::app::NetCommand;
|
||||
|
||||
#[component]
|
||||
pub fn LoginScreen(error: Option<String>) -> impl IntoView {
|
||||
let (room_name, set_room_name) = signal(String::new());
|
||||
|
||||
let cmd_tx = use_context::<UnboundedSender<NetCommand>>()
|
||||
.expect("UnboundedSender<NetCommand> not found in context");
|
||||
|
||||
let cmd_tx_create = cmd_tx.clone();
|
||||
let cmd_tx_join = cmd_tx;
|
||||
|
||||
view! {
|
||||
<div class="login-container">
|
||||
<h1>"Trictrac"</h1>
|
||||
|
||||
{error.map(|err| view! { <p class="error-msg">{err}</p> })}
|
||||
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Room name"
|
||||
prop:value=move || room_name.get()
|
||||
on:input=move |ev| set_room_name.set(event_target_value(&ev))
|
||||
/>
|
||||
|
||||
<button
|
||||
class="btn btn-primary"
|
||||
disabled=move || room_name.get().is_empty()
|
||||
on:click=move |_| {
|
||||
cmd_tx_create
|
||||
.unbounded_send(NetCommand::CreateRoom { room: room_name.get() })
|
||||
.ok();
|
||||
}
|
||||
>
|
||||
"Create Room"
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn btn-secondary"
|
||||
disabled=move || room_name.get().is_empty()
|
||||
on:click=move |_| {
|
||||
cmd_tx_join
|
||||
.unbounded_send(NetCommand::JoinRoom { room: room_name.get() })
|
||||
.ok();
|
||||
}
|
||||
>
|
||||
"Join Room"
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
7
client_web/src/components/mod.rs
Normal file
7
client_web/src/components/mod.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mod connecting_screen;
|
||||
mod game_screen;
|
||||
mod login_screen;
|
||||
|
||||
pub use connecting_screen::ConnectingScreen;
|
||||
pub use game_screen::GameScreen;
|
||||
pub use login_screen::LoginScreen;
|
||||
Loading…
Add table
Add a link
Reference in a new issue