M => +12 -0
@@ 12,6 12,7 @@ use bevy::{
};
mod ui;
use laurelin_shared::types::game::Game;
pub use ui::*;
#[derive(Default, Resource, Reflect)]
@@ 19,6 20,17 @@ pub use ui::*;
pub struct PlayScreenData {
pub state: PlayScreenState,
pub browse_state: PlayScreenBrowseState,
pub waiting_for_create_game: bool,
pub waiting_for_all_forming: bool,
pub waiting_for_my_games: bool,
#[reflect(ignore)]
pub cur_game: Option<Game>,
#[reflect(ignore)]
pub all_forming: Vec<Game>,
#[reflect(ignore)]
pub my_games: Vec<Game>,
}
#[derive(Default, PartialEq, Clone, Reflect)]
M => +33 -27
@@ 9,7 9,14 @@
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts};
use crate::{cfg::CfgUser, plugins::menu::MenuState, util::egui::menuwindow};
use crate::{
cfg::CfgUser,
plugins::{
menu::MenuState,
networking::send::game::{GameAllFormingEvent, GameCreateEvent, GameMyGamesEvent},
},
util::egui::menuwindow,
};
use super::{PlayScreenBrowseState, PlayScreenData, PlayScreenState};
@@ 18,6 25,9 @@ pub fn ui(
mut egui_contexts: EguiContexts,
mut data: ResMut<PlayScreenData>,
cfg_user: Res<CfgUser>,
mut creategame_ev_w: EventWriter<GameCreateEvent>,
mut allforming_ev_w: EventWriter<GameAllFormingEvent>,
mut mygames_ev_w: EventWriter<GameMyGamesEvent>,
) {
menuwindow(
egui_contexts.ctx_mut(),
@@ 67,19 77,19 @@ pub fn ui(
if ui.button("Refresh").clicked() {
match data.browse_state {
PlayScreenBrowseState::Forming => {
//if !rtdmenu.waiting_for_all_forming_call {
// allforming_ev_w.send(AllFormingEvent);
//}
if !data.waiting_for_all_forming {
allforming_ev_w.send(GameAllFormingEvent);
}
}
PlayScreenBrowseState::InProgress => {
//if !rtdmenu.waiting_for_my_games_call {
// mygames_ev_w.send(MyGamesEvent);
//}
if !data.waiting_for_my_games {
mygames_ev_w.send(GameMyGamesEvent);
}
}
PlayScreenBrowseState::Finished => {
//if !rtdmenu.waiting_for_my_games_call {
// mygames_ev_w.send(MyGamesEvent);
//}
if !data.waiting_for_my_games {
mygames_ev_w.send(GameMyGamesEvent);
}
}
}
}
@@ 104,18 114,16 @@ pub fn ui(
}
PlayScreenState::CreateGame => {
ui.vertical_centered(|ui| {
ui.add_enabled_ui(
/* !rtdmenu.waiting_for_create_game_call */ false,
|ui| {
if ui.button("Confirm").clicked() {
//creategame_ev_w.send(CreateGameEvent);
}
ui.add_enabled_ui(!data.waiting_for_create_game, |ui| {
if ui.button("Confirm").clicked() {
data.waiting_for_create_game = true;
creategame_ev_w.send(GameCreateEvent);
}
if ui.button("Cancel").clicked() {
data.state = PlayScreenState::Main;
}
},
);
if ui.button("Cancel").clicked() {
data.state = PlayScreenState::Main;
}
});
});
}
PlayScreenState::InLobbyHost => {
@@ 141,18 149,17 @@ pub fn ui(
);
}
fn browse_forming(ui: &mut egui::Ui, rtdmenu: &mut PlayScreenData, cfg_user: &CfgUser) {
/*
if rtdmenu.waiting_for_all_forming_call {
fn browse_forming(ui: &mut egui::Ui, data: &mut PlayScreenData, cfg_user: &CfgUser) {
if data.waiting_for_all_forming {
ui.horizontal(|ui| {
ui.spinner();
ui.label("loading...");
});
} else {
if rtdmenu.all_forming_games.is_empty() {
if data.all_forming.is_empty() {
ui.label("No forming games found.");
} else {
for game in rtdmenu.all_forming_games.clone() {
for game in data.all_forming.clone() {
egui::Frame::none()
.fill(egui::Color32::BLACK)
.rounding(4.)
@@ 191,7 198,6 @@ fn browse_forming(ui: &mut egui::Ui, rtdmenu: &mut PlayScreenData, cfg_user: &Cf
}
}
}
*/
}
fn browse_inprogress(ui: &mut egui::Ui, rtdmenu: &mut PlayScreenData) {
M client/src/plugins/networking/mod.rs => client/src/plugins/networking/mod.rs +20 -11
@@ 10,21 10,30 @@ use bevy::prelude::*;
use naia_bevy_client::ReceiveEvents;
mod systems;
+pub use systems::events::{receive, send};
pub struct NetworkingPlugin;
impl Plugin for NetworkingPlugin {
fn build(&self, app: &mut App) {
- app.add_systems(
- (
- systems::events::connect_events,
- systems::events::reject_events,
- systems::events::disconnect_events,
- systems::events::message_events,
- systems::events::tick_events,
- )
- .chain()
- .in_set(ReceiveEvents),
- );
+ app.add_event::<send::game::GameCreateEvent>()
+ .add_event::<send::game::GameAllFormingEvent>()
+ .add_event::<send::game::GameMyGamesEvent>()
+ .add_systems((
+ send::game::create_event,
+ send::game::all_forming_event,
+ send::game::my_games_event,
+ ))
+ .add_systems(
+ (
+ receive::connect_events,
+ receive::reject_events,
+ receive::disconnect_events,
+ receive::message_events,
+ receive::tick_events,
+ )
+ .chain()
+ .in_set(ReceiveEvents),
+ );
}
}
A client/src/plugins/networking/systems/events/mod.rs => client/src/plugins/networking/systems/events/mod.rs +10 -0
@@ 0,0 1,10 @@
+/*
+ * 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.
+ */
+
+pub mod receive;
+pub mod send;
R client/src/plugins/networking/systems/events.rs => client/src/plugins/networking/systems/events/receive/mod.rs +29 -4
@@ 7,7 7,10 @@
*/
use bevy::prelude::*;
-use laurelin_shared::server::{channels::AfterAuthChannel, messages::AfterAuth};
+use laurelin_shared::server::{
+ channels::{AfterAuthChannel, DataRequestChannel},
+ messages::{AfterAuth, DataRequestResponse, DataRequestType},
+};
use naia_bevy_client::{
events::{ClientTickEvent, ConnectEvent, DisconnectEvent, MessageEvents, RejectEvent},
Client,
@@ 16,7 19,10 @@ use naia_bevy_client::{
use crate::{
cfg::CfgUser,
plugins::menu::{
- ui::connect::{ConnectScreenData, ConnectState},
+ ui::{
+ connect::{ConnectScreenData, ConnectState},
+ play::PlayScreenData,
+ },
MenuState,
},
};
@@ 52,7 58,8 @@ pub fn message_events(
mut commands: Commands,
mut ev: EventReader<MessageEvents>,
mut cfg_user: ResMut<CfgUser>,
- mut data: ResMut<ConnectScreenData>,
+ mut connect_data: ResMut<ConnectScreenData>,
+ mut play_data: ResMut<PlayScreenData>,
) {
for events in ev.iter() {
for aa_message in events.read::<AfterAuthChannel, AfterAuth>() {
@@ 63,11 70,29 @@ pub fn message_events(
cfg_user.cookie = aa_message.cookie;
// reset the connection screen to login
- data.state = ConnectState::Login;
+ connect_data.state = ConnectState::Login;
// take us to the main menu
commands.insert_resource(NextState(Some(MenuState::Menu)));
}
+
+ for response in events.read::<DataRequestChannel, DataRequestResponse>() {
+ match DataRequestType::from_u8(&response.r#type) {
+ DataRequestType::GameCreate => {
+ // TODO: set cur_game, send player to lobby screen
+ }
+ DataRequestType::GameAllForming => {
+ // TODO: handle possible error
+ play_data.all_forming = serde_json::from_str(&response.data).unwrap();
+ play_data.waiting_for_all_forming = false;
+ }
+ DataRequestType::GameMyGames => {
+ // TODO: handle possible error
+ play_data.my_games = serde_json::from_str(&response.data).unwrap();
+ play_data.waiting_for_my_games = false;
+ }
+ }
+ }
}
}
A client/src/plugins/networking/systems/events/send/game.rs => client/src/plugins/networking/systems/events/send/game.rs +33 -0
@@ 0,0 1,33 @@
+/*
+ * 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 GameCreateEvent;
+data_request!(create_event, GameCreateEvent, DataRequestType::GameCreate);
+
+pub struct GameAllFormingEvent;
+data_request!(
+ all_forming_event,
+ GameAllFormingEvent,
+ DataRequestType::GameAllForming
+);
+
+pub struct GameMyGamesEvent;
+data_request!(
+ my_games_event,
+ GameMyGamesEvent,
+ DataRequestType::GameMyGames
+);
A client/src/plugins/networking/systems/events/send/mod.rs => client/src/plugins/networking/systems/events/send/mod.rs +22 -0
@@ 0,0 1,22 @@
+/*
+ * 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.
+ */
+
+pub mod game;
+
+macro_rules! data_request {
+ ($fni:ident, $event:ident, $reqtype:expr) => {
+ pub fn $fni(mut ev: EventReader<$event>, mut client: Client) {
+ for _ in ev.iter() {
+ client.send_message::<DataRequestChannel, DataRequest>(&DataRequest::new(
+ $reqtype as u8,
+ ));
+ }
+ }
+ };
+}
+use data_request;
M shared/src/types/game.rs => shared/src/types/game.rs +1 -1
@@ 21,7 21,7 @@ pub const GAMESTATE_CANCELLED: i16 = 3;
pub const GAMETURN_HOST: i16 = 0;
pub const GAMETURN_GUEST: i16 = 1;
-#[derive(Serialize, Deserialize, Queryable)]
+#[derive(Serialize, Deserialize, Queryable, Clone)]
pub struct Game {
pub id: Uuid,
pub created_at: NaiveDateTime,