M client/src/macros/async_task.rs => client/src/macros/async_task.rs +2 -1
@@ 88,10 88,11 @@ macro_rules! async_task_handle_call {
}
};
- ($call_type:ty, |$response:ident, $menu_data:ident, $no:ident| $handler_func:expr) => {
+ ($call_type:ty, |$response:ident, $global:ident, $menu_data:ident, $no:ident| $handler_func:expr) => {
pub fn handle_call(
mut commands: Commands,
mut tasks: Query<(Entity, &mut $call_type)>,
+ mut $global: ResMut<Global>,
mut $menu_data: ResMut<MenuData>,
mut $no: ResMut<NetworkingOptions>,
) {
M client/src/main.rs => client/src/main.rs +11 -0
@@ 6,6 6,7 @@
* See LICENSE for licensing information.
*/
+use api::user::User;
use bevy::prelude::*;
use bevy_editor_pls::EditorPlugin;
use bevy_egui::EguiPlugin;
@@ 56,6 57,10 @@ fn main() {
user_token: "".to_string(),
});
+ app.insert_resource(Global {
+ user: None,
+ });
+
// has handlers for all async tasks
app.add_plugin(plugins::AsyncTasksPlugin);
@@ 82,3 87,9 @@ pub struct NetworkingOptions {
/// feels wrong storing this here but "it's temporary"
user_token: String,
}
+
+#[derive(Resource)]
+pub struct Global {
+ /// details of the logged in user
+ user: Option<User>,
+}
M client/src/plugins/async_tasks/req_login.rs => client/src/plugins/async_tasks/req_login.rs +9 -3
@@ 8,8 8,8 @@
use crate::{
async_task_start_call, async_task_handle_call,
- api::{self, user::LoginResponse}, NetworkingOptions,
- plugins::{menu::MenuData, MenuUIState},
+ api::{self, user::{LoginResponse, User}}, NetworkingOptions,
+ plugins::{menu::MenuData, MenuUIState}, Global,
};
use bevy::{prelude::*, tasks::{Task, AsyncComputeTaskPool}};
@@ 30,11 30,17 @@ async_task_start_call!(LoginCallEvent, LoginCall, |ev, no| {
res
});
-async_task_handle_call!(LoginCall, |response, menu_data, no| {
+async_task_handle_call!(LoginCall, |response, global, menu_data, no| {
match response {
Err(_err) => panic!("login failed, handle me"),
Ok(resp) => {
info!("logged in {}", resp.username);
+ global.user = Some(User {
+ id: resp.id.clone(),
+ created_at: resp.created_at.clone(),
+ updated_at: resp.updated_at.clone(),
+ username: resp.username.clone(),
+ });
no.user_token = resp.token;
menu_data.ui_state = MenuUIState::Main;
}