lobby list skeleton

This commit is contained in:
clizia 2025-04-18 14:22:23 +02:00
parent ed77971e41
commit b37ab4a37d
8 changed files with 477 additions and 368 deletions

593
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -18,8 +18,11 @@ RUSTFLAGS="--cfg tokio_unstable" cargo run --bin server
- [x] move player creation on the server
- [x] move lobby creation on the server
- [ ] add clap configuration
- [ ] delete player
- [ ] delete lobby
- [ ] join existing lobbies
- [ ] actually do the game
- [ ] fixing ui (perpetual)
- [ ] add unit testing
- [ ] reorganize modules

View file

@ -1,12 +1,13 @@
use anyhow::Result;
use ratatui::DefaultTerminal;
use crate::{message::{Message, MessageKind}, player::Player, ui::ui};
use crate::{message::{Message, MessageKind}, player::Player, ui::{ui, CurrentScreen}};
#[derive(Debug, Default)]
pub struct Client {
pub addr: String,
pub client: reqwest::Client,
pub current_screen: CurrentScreen,
pub user: Option<String>,
pub user_name: String,
pub exit: bool,

10
src/entity.rs Normal file
View file

@ -0,0 +1,10 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct Entity<T: Serialize>(T);
impl<T: Serialize> Entity<T> {
pub fn encode(&self) -> anyhow::Result<String, serde_json::Error> {
serde_json::to_string(&self)
}
}

View file

@ -17,6 +17,8 @@ pub enum MessageKind {
CreateLobby,
DeletePlayer,
DeleteLobby,
JoinLobby,
QuitLobby,
}
impl Message {

View file

@ -126,4 +126,11 @@ impl App {
}
}
pub async fn join_lobby(
State(db): State<AppState>,
Path(lobby_id): Path<String>
) -> Result<axum::response::Json<Message>, StatusCode> {
todo!()
}
}

View file

@ -33,6 +33,7 @@ impl Server {
.route("/create/lobby", post(App::create_lobby))
.route("/delete/player/{player_id}", get(App::delete_player))
.route("/delete/lobby/{lobby_id}", get(App::delete_lobby))
.route("/join/{lobby_id}", post(App::join_lobby))
.with_state(app.db);
axum::serve(listener, router).await.unwrap();

View file

@ -54,9 +54,17 @@ impl Widget for Popup<'_> {
}
}
#[derive(Debug, Default)]
pub enum CurrentScreen {
#[default] Menu,
LobbyList,
}
async fn handle_key_event(mut client: &mut Client, key_event: KeyEvent) {
match &client.popup {
false => {
match client.current_screen {
CurrentScreen::Menu => {
match key_event.code {
KeyCode::Char('q') => Client::exit(client),
KeyCode::Char('h') => {
@ -103,6 +111,9 @@ async fn handle_key_event(mut client: &mut Client, key_event: KeyEvent) {
_ => (),
}
}
CurrentScreen::LobbyList => todo!(),
}
}
true => {
match key_event.code {
_ => client.popup = false,
@ -123,6 +134,9 @@ pub async fn handle_events(client: &mut Client) -> anyhow::Result<()> {
}
pub fn ui(frame: &mut Frame, app: &Client) {
match app.current_screen {
CurrentScreen::Menu => {
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
@ -136,8 +150,6 @@ pub fn ui(frame: &mut Frame, app: &Client) {
" create player ".into(),
"2".blue().bold(),
" create lobby ".into(),
"3".blue().bold(),
" send player ".into(),
"<Q>".blue().bold(),
" quit ".into(),
]);
@ -183,6 +195,9 @@ pub fn ui(frame: &mut Frame, app: &Client) {
.block(btm_block),
chunks[1],
);
}
CurrentScreen::LobbyList => todo!(),
}
let popup_area = Rect {
x: frame.area().width / 4,
@ -191,8 +206,7 @@ pub fn ui(frame: &mut Frame, app: &Client) {
height: frame.area().height / 3,
};
match &app.popup {
true => {
if app.popup == true {
let popup = Popup::default()
.title(app.popup_title.clone())
.content(app.popup_content.clone())
@ -200,7 +214,5 @@ pub fn ui(frame: &mut Frame, app: &Client) {
.title_style(Style::new().white().bold())
.border_style(Style::new().red());
frame.render_widget(popup, popup_area);
},
_ => ()
}
}