lobby list skeleton
This commit is contained in:
parent
ed77971e41
commit
b37ab4a37d
8 changed files with 477 additions and 368 deletions
593
Cargo.lock
generated
593
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -18,8 +18,11 @@ RUSTFLAGS="--cfg tokio_unstable" cargo run --bin server
|
||||||
|
|
||||||
- [x] move player creation on the server
|
- [x] move player creation on the server
|
||||||
- [x] move lobby creation on the server
|
- [x] move lobby creation on the server
|
||||||
|
- [ ] add clap configuration
|
||||||
- [ ] delete player
|
- [ ] delete player
|
||||||
- [ ] delete lobby
|
- [ ] delete lobby
|
||||||
- [ ] join existing lobbies
|
- [ ] join existing lobbies
|
||||||
- [ ] actually do the game
|
- [ ] actually do the game
|
||||||
- [ ] fixing ui (perpetual)
|
- [ ] fixing ui (perpetual)
|
||||||
|
- [ ] add unit testing
|
||||||
|
- [ ] reorganize modules
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ratatui::DefaultTerminal;
|
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)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
pub client: reqwest::Client,
|
pub client: reqwest::Client,
|
||||||
|
pub current_screen: CurrentScreen,
|
||||||
pub user: Option<String>,
|
pub user: Option<String>,
|
||||||
pub user_name: String,
|
pub user_name: String,
|
||||||
pub exit: bool,
|
pub exit: bool,
|
||||||
|
|
10
src/entity.rs
Normal file
10
src/entity.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,8 @@ pub enum MessageKind {
|
||||||
CreateLobby,
|
CreateLobby,
|
||||||
DeletePlayer,
|
DeletePlayer,
|
||||||
DeleteLobby,
|
DeleteLobby,
|
||||||
|
JoinLobby,
|
||||||
|
QuitLobby,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
|
|
|
@ -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!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ impl Server {
|
||||||
.route("/create/lobby", post(App::create_lobby))
|
.route("/create/lobby", post(App::create_lobby))
|
||||||
.route("/delete/player/{player_id}", get(App::delete_player))
|
.route("/delete/player/{player_id}", get(App::delete_player))
|
||||||
.route("/delete/lobby/{lobby_id}", get(App::delete_lobby))
|
.route("/delete/lobby/{lobby_id}", get(App::delete_lobby))
|
||||||
|
.route("/join/{lobby_id}", post(App::join_lobby))
|
||||||
.with_state(app.db);
|
.with_state(app.db);
|
||||||
|
|
||||||
axum::serve(listener, router).await.unwrap();
|
axum::serve(listener, router).await.unwrap();
|
||||||
|
|
24
src/ui.rs
24
src/ui.rs
|
@ -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) {
|
async fn handle_key_event(mut client: &mut Client, key_event: KeyEvent) {
|
||||||
match &client.popup {
|
match &client.popup {
|
||||||
false => {
|
false => {
|
||||||
|
match client.current_screen {
|
||||||
|
CurrentScreen::Menu => {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
KeyCode::Char('q') => Client::exit(client),
|
KeyCode::Char('q') => Client::exit(client),
|
||||||
KeyCode::Char('h') => {
|
KeyCode::Char('h') => {
|
||||||
|
@ -103,6 +111,9 @@ async fn handle_key_event(mut client: &mut Client, key_event: KeyEvent) {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CurrentScreen::LobbyList => todo!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
true => {
|
true => {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
_ => client.popup = false,
|
_ => 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) {
|
pub fn ui(frame: &mut Frame, app: &Client) {
|
||||||
|
match app.current_screen {
|
||||||
|
CurrentScreen::Menu => {
|
||||||
|
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
|
@ -136,8 +150,6 @@ pub fn ui(frame: &mut Frame, app: &Client) {
|
||||||
" create player ".into(),
|
" create player ".into(),
|
||||||
"2".blue().bold(),
|
"2".blue().bold(),
|
||||||
" create lobby ".into(),
|
" create lobby ".into(),
|
||||||
"3".blue().bold(),
|
|
||||||
" send player ".into(),
|
|
||||||
"<Q>".blue().bold(),
|
"<Q>".blue().bold(),
|
||||||
" quit ".into(),
|
" quit ".into(),
|
||||||
]);
|
]);
|
||||||
|
@ -183,6 +195,9 @@ pub fn ui(frame: &mut Frame, app: &Client) {
|
||||||
.block(btm_block),
|
.block(btm_block),
|
||||||
chunks[1],
|
chunks[1],
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
CurrentScreen::LobbyList => todo!(),
|
||||||
|
}
|
||||||
|
|
||||||
let popup_area = Rect {
|
let popup_area = Rect {
|
||||||
x: frame.area().width / 4,
|
x: frame.area().width / 4,
|
||||||
|
@ -191,8 +206,7 @@ pub fn ui(frame: &mut Frame, app: &Client) {
|
||||||
height: frame.area().height / 3,
|
height: frame.area().height / 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
match &app.popup {
|
if app.popup == true {
|
||||||
true => {
|
|
||||||
let popup = Popup::default()
|
let popup = Popup::default()
|
||||||
.title(app.popup_title.clone())
|
.title(app.popup_title.clone())
|
||||||
.content(app.popup_content.clone())
|
.content(app.popup_content.clone())
|
||||||
|
@ -200,7 +214,5 @@ pub fn ui(frame: &mut Frame, app: &Client) {
|
||||||
.title_style(Style::new().white().bold())
|
.title_style(Style::new().white().bold())
|
||||||
.border_style(Style::new().red());
|
.border_style(Style::new().red());
|
||||||
frame.render_widget(popup, popup_area);
|
frame.render_widget(popup, popup_area);
|
||||||
},
|
|
||||||
_ => ()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue