-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a1f6ec
commit 109947d
Showing
17 changed files
with
245 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use leptos::{component, view, CollectView, IntoView, SignalGet}; | ||
|
||
use crate::{ | ||
models::projections, | ||
utils::{use_events, use_game_id}, | ||
}; | ||
|
||
#[component] | ||
pub fn lobby() -> impl IntoView { | ||
let events = use_events(); | ||
let game_id = use_game_id(); | ||
|
||
let players = move || projections::players(&events.get()); | ||
let player_count = move || players().len(); | ||
let ready_count = move || { | ||
players() | ||
.into_iter() | ||
.filter_map(|(_, info)| info.ready.then_some(true)) | ||
.count() | ||
}; | ||
|
||
view! { | ||
<div class="host-lobby-container"> | ||
<div class="top-row"> | ||
<div>"Lobby: " <span data-testid="game_code">{game_id}</span></div> | ||
<div>"Ready: " {ready_count} "/" {player_count}</div> | ||
</div> | ||
<div class="avatar-previews"> | ||
|
||
{move || { | ||
players() | ||
.values() | ||
.map(|info| { | ||
view! { | ||
<div class="avatar-container"> | ||
<img | ||
class="profile-picture" | ||
src="https://upload.wikimedia.org/wikipedia/commons/8/89/Portrait_Placeholder.png" | ||
/> | ||
<div class="name">{info.name.clone()}</div> | ||
<div class="status"> | ||
"Ready: " {if info.ready { "✅" } else { "❌" }} | ||
</div> | ||
</div> | ||
} | ||
}) | ||
.collect_view() | ||
}} | ||
|
||
</div> | ||
</div> | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
mod lobby; | ||
pub use lobby::*; | ||
|
||
mod pre_game; | ||
pub use pre_game::*; | ||
|
||
mod race; | ||
pub use race::*; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use leptos::*; | ||
|
||
#[component] | ||
pub fn pre_game() -> impl IntoView { | ||
view! { <h1>"Host pregame screen!"</h1> } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use leptos::*; | ||
|
||
#[component] | ||
pub fn race() -> impl IntoView { | ||
view! { <h1>"Host race screen!"</h1> } | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,24 @@ | ||
mod player_lobby; | ||
use leptos::{component, view, IntoView}; | ||
use leptos_meta::{provide_meta_context, Stylesheet}; | ||
use leptos_reactive::create_memo; | ||
pub use player_lobby::*; | ||
|
||
mod host_lobby; | ||
pub use host_lobby::*; | ||
|
||
mod game_wrapper; | ||
pub use game_wrapper::*; | ||
use crate::{models::events::Event, utils::use_events}; | ||
|
||
mod join_screen; | ||
pub use join_screen::*; | ||
use router::Router; | ||
|
||
mod game_wrapper; | ||
mod host; | ||
mod main_menu; | ||
pub use main_menu::*; | ||
|
||
mod player_pregame; | ||
pub use player_pregame::*; | ||
|
||
use leptos::{component, view, IntoView}; | ||
use leptos_meta::{provide_meta_context, Stylesheet}; | ||
use leptos_router::{Route, Router, Routes}; | ||
|
||
use crate::{models::events::Event, utils::use_events}; | ||
mod player; | ||
mod router; | ||
|
||
#[component] | ||
pub fn app() -> impl leptos::IntoView { | ||
provide_meta_context(); | ||
|
||
view! { | ||
<Stylesheet id="leptos" href="/pkg/style.css"/> | ||
|
||
<Router> | ||
<Routes> | ||
<Route path="/" view=MainMenu/> | ||
<Route | ||
path="/host/:game_id" | ||
view=|| { | ||
view! { | ||
<GameConnectionWrapper> | ||
<GameStateRouter lobby=HostLobby pre_game=PlayerPreGame/> | ||
</GameConnectionWrapper> | ||
} | ||
} | ||
/> | ||
|
||
<Route path="/play" view=JoinScreen/> | ||
<Route | ||
path="/play/:game_id" | ||
view=|| { | ||
view! { | ||
<GameConnectionWrapper> | ||
<GameStateRouter lobby=PlayerLobby pre_game=PlayerPreGame/> | ||
</GameConnectionWrapper> | ||
} | ||
} | ||
/> | ||
|
||
</Routes> | ||
</Router> | ||
} | ||
} | ||
|
||
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)] | ||
enum GameState { | ||
#[default] | ||
Lobby, | ||
PreGame, | ||
Race, | ||
Summary, | ||
FinalScreen, | ||
} | ||
|
||
#[component] | ||
pub fn game_state_router<Lobby, LobbyIV, PreGame, PreGameIV>( | ||
lobby: Lobby, | ||
pre_game: PreGame, | ||
) -> impl IntoView | ||
where | ||
Lobby: Fn() -> LobbyIV + 'static, | ||
LobbyIV: IntoView + 'static, | ||
PreGame: Fn() -> PreGameIV + 'static, | ||
PreGameIV: IntoView + 'static, | ||
{ | ||
let events = use_events(); | ||
|
||
let state = create_memo(move |_| { | ||
events() | ||
.iter() | ||
.rev() | ||
.find_map(|event| match event { | ||
Event::GameCreated { .. } => Some(GameState::Lobby), | ||
Event::GameStarted => Some(GameState::PreGame), | ||
Event::RaceStarted => Some(GameState::Race), | ||
Event::RaceFinished { .. } => Some(GameState::Summary), | ||
Event::GameFinished => Some(GameState::FinalScreen), | ||
_ => None, | ||
}) | ||
.unwrap_or_default() | ||
}); | ||
|
||
move || match state() { | ||
GameState::Lobby => lobby().into_view(), | ||
GameState::PreGame => pre_game().into_view(), | ||
GameState::Race => todo!(), | ||
GameState::Summary => todo!(), | ||
GameState::FinalScreen => todo!(), | ||
<Router/> | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod join; | ||
pub use join::*; | ||
|
||
mod lobby; | ||
pub use lobby::*; | ||
|
||
mod pregame; | ||
pub use pregame::*; | ||
|
||
mod race; | ||
pub use race::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.