From 814931c4f3e64ff4060977b49237dd90197df394 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 13 Feb 2023 11:06:40 +0200 Subject: [PATCH] feat(sdbclient): adhere to new create game API --- sdbclient/src/api/game/create.rs | 9 ++------- sdbclient/src/plugins/menu/play/creategamecall.rs | 2 +- sdbclient/src/plugins/menu/play/joingamecall.rs | 4 ++-- sdbclient/src/plugins/menu/play/ui.rs | 4 +++- sdbclient/src/runtime/menu/mod.rs | 6 +++--- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/sdbclient/src/api/game/create.rs b/sdbclient/src/api/game/create.rs index 3f312dd..3a3f90a 100644 --- a/sdbclient/src/api/game/create.rs +++ b/sdbclient/src/api/game/create.rs @@ -9,18 +9,13 @@ use reqwest; use serde::{Deserialize, Serialize}; -use super::APIErrorWrapper; - -#[derive(Debug, Serialize, Deserialize)] -pub struct ResultCreateGame { - pub id: String, -} +use super::{APIErrorWrapper, types::Game}; #[derive(Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum ResponseCreateGame { Error(APIErrorWrapper), - Valid(ResultCreateGame), + Valid(Game), } pub fn create(api_address: String, token: String) -> ResponseCreateGame { diff --git a/sdbclient/src/plugins/menu/play/creategamecall.rs b/sdbclient/src/plugins/menu/play/creategamecall.rs index 2d822b1..9f2f30d 100644 --- a/sdbclient/src/plugins/menu/play/creategamecall.rs +++ b/sdbclient/src/plugins/menu/play/creategamecall.rs @@ -68,7 +68,7 @@ pub(super) fn handle( rtdmenu.waiting_for_create_game_call = false; match create_game_call_response.game { ResponseCreateGame::Valid(res) => { - rtdmenu.cur_game_id = res.id.clone(); + rtdmenu.cur_game = Some(res.clone()); rtdmenu.play_menu_ui_state = PlayMenuUIState::InLobbyHost; console.send(PrintConsoleLine::new( diff --git a/sdbclient/src/plugins/menu/play/joingamecall.rs b/sdbclient/src/plugins/menu/play/joingamecall.rs index 5752d5e..626a0fa 100644 --- a/sdbclient/src/plugins/menu/play/joingamecall.rs +++ b/sdbclient/src/plugins/menu/play/joingamecall.rs @@ -39,7 +39,7 @@ pub(super) fn start( for _event in events.iter() { let api_address = cfg_dev.api_server.clone(); let token = cfg_user.user_token.clone(); - let game_id = rtdmenu.cur_game_id.clone(); + let game_id = rtdmenu.cur_game.as_ref().unwrap().id.clone(); let thread_pool = AsyncComputeTaskPool::get(); let task = thread_pool.spawn(async move { @@ -72,7 +72,7 @@ pub(super) fn handle( rtdmenu.play_menu_ui_state = PlayMenuUIState::InLobbyGuest; console.send(PrintConsoleLine::new( - format!("Joined game with id: '{}'", rtdmenu.cur_game_id).into(), + format!("Joined game with id: '{}'", rtdmenu.cur_game.as_ref().unwrap().id).into(), )); } ResponseJoinGame::Error(error) => { diff --git a/sdbclient/src/plugins/menu/play/ui.rs b/sdbclient/src/plugins/menu/play/ui.rs index 9566c0d..ea2b278 100644 --- a/sdbclient/src/plugins/menu/play/ui.rs +++ b/sdbclient/src/plugins/menu/play/ui.rs @@ -115,16 +115,18 @@ pub(super) fn show( if game.guest_id == cfg_user.id { ui.add_enabled(false, egui::Button::new("Joined")); if ui.button("Inspect").clicked() { + rtdmenu.cur_game = Some(game.clone()); rtdmenu.play_menu_ui_state = PlayMenuUIState::InLobbyGuest; } } else if game.host_id == cfg_user.id { ui.add_enabled(false, egui::Button::new("Host")); if ui.button("Inspect").clicked() { + rtdmenu.cur_game = Some(game.clone()); rtdmenu.play_menu_ui_state = PlayMenuUIState::InLobbyHost; } } else { if ui.button("Join").clicked() { - rtdmenu.cur_game_id = game.id.clone(); + rtdmenu.cur_game = Some(game.clone()); joingame_ev_w.send(JoinGameEvent); } } diff --git a/sdbclient/src/runtime/menu/mod.rs b/sdbclient/src/runtime/menu/mod.rs index 9c7900e..dd1115b 100644 --- a/sdbclient/src/runtime/menu/mod.rs +++ b/sdbclient/src/runtime/menu/mod.rs @@ -15,8 +15,8 @@ use crate::api::game::types::Game; pub(crate) struct RTDMenu { pub play_menu_ui_state: PlayMenuUIState, pub waiting_for_create_game_call: bool, - /// Current game ID, for showing lobby data etc - pub cur_game_id: String, + /// Current game + pub cur_game: Option, /// List of all forming games pub all_forming_games: Vec, pub waiting_for_all_forming_call: bool, @@ -28,7 +28,7 @@ impl Default for RTDMenu { Self { play_menu_ui_state: PlayMenuUIState::Main, waiting_for_create_game_call: false, - cur_game_id: String::from(""), + cur_game: None, all_forming_games: vec![], waiting_for_all_forming_call: false, waiting_for_join_game_call: false, -- 2.44.1