DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

10bc627d82a1e50f0c1b51d10b8682156fa2cc53 — Jonni Liljamo 1 year, 9 months ago 78b9e55
fix(client): wait for AfterAuth before going to menu
1 files changed, 15 insertions(+), 10 deletions(-)

M client/src/plugins/networking/systems/events.rs
M client/src/plugins/networking/systems/events.rs => client/src/plugins/networking/systems/events.rs +15 -10
@@ 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));
        }
    }
}