@@ 22,18 22,10 @@ use crate::{
},
};
-pub fn connect_events(
- mut commands: Commands,
- mut ev: EventReader<ConnectEvent>,
- client: Client,
- mut data: ResMut<ConnectScreenData>,
-) {
+pub fn connect_events(mut ev: EventReader<ConnectEvent>, client: Client) {
for _ in ev.iter() {
if let Ok(server_address) = client.server_address() {
info!("Laurelin client connected to: '{}'", server_address);
-
- data.state = ConnectState::Login;
- commands.insert_resource(NextState(MenuState::Menu));
}
}
}
@@ 57,12 49,25 @@ pub fn disconnect_events(mut ev: EventReader<DisconnectEvent>) {
}
}
-pub fn message_events(mut ev: EventReader<MessageEvents>, mut cfg_user: ResMut<CfgUser>) {
+pub fn message_events(
+ mut commands: Commands,
+ mut ev: EventReader<MessageEvents>,
+ mut cfg_user: ResMut<CfgUser>,
+ mut data: ResMut<ConnectScreenData>,
+) {
for events in ev.iter() {
for aa_message in events.read::<AfterAuthChannel, AfterAuth>() {
// TODO: move handling to a separate function?
+
+ // save details from AfterAuth
cfg_user.username = aa_message.username;
cfg_user.cookie = aa_message.cookie;
+
+ // reset the connection screen to login
+ data.state = ConnectState::Login;
+
+ // take us to the main menu
+ commands.insert_resource(NextState(MenuState::Menu));
}
}
}