From d2c89141eae4f0932cab1f98147b0085f1e07290 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 24 May 2023 22:13:14 +0300 Subject: [PATCH] feat(client): end game endpoint call --- client/src/api/game/end.rs | 18 ++++++++ client/src/api/game/mod.rs | 3 ++ client/src/plugins/async_tasks/mod.rs | 6 +++ .../src/plugins/async_tasks/req_game_end.rs | 41 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 client/src/api/game/end.rs create mode 100644 client/src/plugins/async_tasks/req_game_end.rs diff --git a/client/src/api/game/end.rs b/client/src/api/game/end.rs new file mode 100644 index 0000000..36647c6 --- /dev/null +++ b/client/src/api/game/end.rs @@ -0,0 +1,18 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use crate::{post_request_auth, NetworkingOptions}; + +// NOTE: this response isn't actually used +pub type EndResponse = Result; + +pub fn end(no: &NetworkingOptions, game_id: &str) -> EndResponse { + let res = post_request_auth!(no, &format!("/game/{}/end", &game_id), &{}); + + Ok(res.text().unwrap()) +} diff --git a/client/src/api/game/mod.rs b/client/src/api/game/mod.rs index 4e4aff4..09dd17c 100644 --- a/client/src/api/game/mod.rs +++ b/client/src/api/game/mod.rs @@ -35,6 +35,9 @@ pub use create_action::*; mod details; pub use details::*; +mod end; +pub use end::*; + #[derive(Deserialize, Serialize, Clone, PartialEq)] pub enum Command { InitSupplyPile { diff --git a/client/src/plugins/async_tasks/mod.rs b/client/src/plugins/async_tasks/mod.rs index 7abd8a7..6483c74 100644 --- a/client/src/plugins/async_tasks/mod.rs +++ b/client/src/plugins/async_tasks/mod.rs @@ -32,6 +32,9 @@ pub use req_game_details::GameDetailsCallEvent; mod req_game_action_create; pub use req_game_action_create::GameActionCreateCallEvent; +mod req_game_end; +pub use req_game_end::GameEndCallEvent; + mod parse_game_status; pub use parse_game_status::ParseGameStatusEvent; @@ -47,6 +50,7 @@ impl Plugin for AsyncTasksPlugin { .add_event::() .add_event::() .add_event::() + .add_event::() .add_event::() .add_systems( ( @@ -71,6 +75,8 @@ impl Plugin for AsyncTasksPlugin { req_game_details::handle_call, req_game_action_create::start_call, req_game_action_create::handle_call, + req_game_end::start_call, + req_game_end::handle_call, ) .chain(), ) diff --git a/client/src/plugins/async_tasks/req_game_end.rs b/client/src/plugins/async_tasks/req_game_end.rs new file mode 100644 index 0000000..e8aa0de --- /dev/null +++ b/client/src/plugins/async_tasks/req_game_end.rs @@ -0,0 +1,41 @@ +/* + * This file is part of laurelin_client + * Copyright (C) 2023 Jonni Liljamo + * + * Licensed under GPL-3.0-only. + * See LICENSE for licensing information. + */ + +use crate::{ + api::{self, game::EndResponse}, + async_task_handle_call, async_task_start_call, + plugins::menu::MenuData, + NetworkingOptions, +}; + +use bevy::{ + prelude::*, + tasks::{AsyncComputeTaskPool, Task}, +}; +use futures_lite::future; + +#[derive(Component)] +pub struct GameEndCall(Task); + +#[derive(Clone)] +pub struct GameEndCallEvent { + pub game_id: String, +} + +async_task_start_call!(GameEndCallEvent, GameEndCall, |ev, no| { + api::game::end(&no, &ev.game_id) +}); + +async_task_handle_call!(GameEndCall, |response, _menu_data| { + match response { + Err(_err) => panic!("game end failed, handle me"), + Ok(resp) => { + info!("ended game {}", resp); + } + } +}); -- 2.44.1