M client/src/main.rs => client/src/main.rs +10 -2
@@ 19,7 19,7 @@ use naia_bevy_client::{
Client, ClientConfig as NaiaClientConfig, Plugin as NaiaClientPlugin, ReceiveEvents,
};
-use laurelin_shared::server::protocol::protocol;
+use laurelin_shared::{server::protocol::protocol, types::user::UserPub};
mod cfg;
mod constants;
@@ 44,6 44,11 @@ pub enum GameState {
Game,
}
+#[derive(Resource)]
+pub struct Global {
+ pub users_cache: Vec<UserPub>,
+}
+
#[derive(SystemSet, Debug, Hash, PartialEq, Eq, Clone)]
struct MainLoop;
@@ 93,7 98,10 @@ fn main() {
//app.add_plugin(ScriptingPlugin).add_plugin(lua::LuaPlugin);
- app.insert_resource(cfg::CfgDirs(
+ app.insert_resource(Global {
+ users_cache: vec![],
+ })
+ .insert_resource(cfg::CfgDirs(
directories::ProjectDirs::from("com", "liljamo", "deckbuilder")
.expect("failed to get project directories"),
));
M client/src/plugins/networking/mod.rs => client/src/plugins/networking/mod.rs +2 -0
@@ 19,10 19,12 @@ impl Plugin for NetworkingPlugin {
app.add_event::<send::game::GameCreateEvent>()
.add_event::<send::game::GameAllFormingEvent>()
.add_event::<send::game::GameMyGamesEvent>()
+ .add_event::<send::user::PubUserDetailsEvent>()
.add_systems((
send::game::create_event,
send::game::all_forming_event,
send::game::my_games_event,
+ send::user::pub_user_details_event,
))
.add_systems(
(
M client/src/plugins/networking/systems/events/receive/mod.rs => client/src/plugins/networking/systems/events/receive/mod.rs +8 -0
@@ 25,6 25,7 @@ use crate::{
},
MenuState,
},
+ Global,
};
pub fn connect_events(mut ev: EventReader<ConnectEvent>, client: Client) {
@@ 57,6 58,7 @@ pub fn disconnect_events(mut ev: EventReader<DisconnectEvent>) {
pub fn message_events(
mut commands: Commands,
mut ev: EventReader<MessageEvents>,
+ mut global: ResMut<Global>,
mut cfg_user: ResMut<CfgUser>,
mut connect_data: ResMut<ConnectScreenData>,
mut play_data: ResMut<PlayScreenData>,
@@ 99,6 101,12 @@ pub fn message_events(
play_data.my_games = response.games.unwrap();
play_data.waiting_for_my_games = false;
}
+ DataRequestType::PubUserDetails => {
+ // TODO: handle possible error
+ global
+ .users_cache
+ .push(response.users.unwrap().get(0).unwrap().clone());
+ }
}
}
}
M client/src/plugins/networking/systems/events/send/game.rs => client/src/plugins/networking/systems/events/send/game.rs +10 -3
@@ 16,18 16,25 @@ use naia_bevy_client::Client;
use super::data_request;
pub struct GameCreateEvent;
-data_request!(create_event, GameCreateEvent, DataRequestType::GameCreate);
+data_request!(
+ create_event,
+ GameCreateEvent,
+ DataRequestType::GameCreate,
+ |ev| None
+);
pub struct GameAllFormingEvent;
data_request!(
all_forming_event,
GameAllFormingEvent,
- DataRequestType::GameAllForming
+ DataRequestType::GameAllForming,
+ |ev| None
);
pub struct GameMyGamesEvent;
data_request!(
my_games_event,
GameMyGamesEvent,
- DataRequestType::GameMyGames
+ DataRequestType::GameMyGames,
+ |ev| None
);
M client/src/plugins/networking/systems/events/send/mod.rs => client/src/plugins/networking/systems/events/send/mod.rs +5 -2
@@ 7,13 7,16 @@
*/
pub mod game;
+pub mod user;
macro_rules! data_request {
- ($fni:ident, $event:ident, $reqtype:expr) => {
+ ($fni:ident, $event:ident, $reqtype:expr, |$ev:ident| $data:expr) => {
pub fn $fni(mut ev: EventReader<$event>, mut client: Client) {
- for _ in ev.iter() {
+ #[allow(unused_variables)]
+ for $ev in ev.iter() {
client.send_message::<DataRequestChannel, DataRequest>(&DataRequest::new(
$reqtype as u8,
+ $data,
));
}
}
A client/src/plugins/networking/systems/events/send/user.rs => client/src/plugins/networking/systems/events/send/user.rs +26 -0
@@ 0,0 1,26 @@
+/*
+ * This file is part of laurelin/client
+ * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
+ *
+ * Licensed under GPL-3.0-only.
+ * See LICENSE for licensing information.
+ */
+
+use bevy::prelude::EventReader;
+use laurelin_shared::server::{
+ channels::DataRequestChannel,
+ messages::{DataRequest, DataRequestType},
+};
+use naia_bevy_client::Client;
+
+use super::data_request;
+
+pub struct PubUserDetailsEvent {
+ pub id: String,
+}
+data_request!(
+ pub_user_details_event,
+ PubUserDetailsEvent,
+ DataRequestType::PubUserDetails,
+ |ev| Some(ev.id.clone())
+);