Skip to content

Commit

Permalink
Leave game
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 committed Aug 2, 2023
1 parent 6922daf commit 2d31cb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions crates/menu/src/multiplayer/joined.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use bevy::prelude::*;
use de_core::state::AppState;
use de_multiplayer::ShutdownMultiplayerEvent;

use super::MultiplayerState;

pub(crate) struct JoinedGamePlugin;

impl Plugin for JoinedGamePlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnExit(MultiplayerState::GameJoined), cleanup);
}
}

fn cleanup(state: Res<State<AppState>>, mut shutdown: EventWriter<ShutdownMultiplayerEvent>) {
if state.as_ref() != &AppState::InGame {
shutdown.send(ShutdownMultiplayerEvent);
}
}
6 changes: 4 additions & 2 deletions crates/menu/src/multiplayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use de_core::nested_state;
use de_multiplayer::MultiplayerShuttingDownEvent;

use self::{
create::CreateGamePlugin, gamelisting::GameListingPlugin, setup::SetupGamePlugin,
signin::SignInPlugin,
create::CreateGamePlugin, gamelisting::GameListingPlugin, joined::JoinedGamePlugin,
setup::SetupGamePlugin, signin::SignInPlugin,
};
use crate::{menu::ScreenStatePlugin, MenuState};

mod create;
mod gamelisting;
mod joined;
mod requests;
mod setup;
mod signin;
Expand All @@ -25,6 +26,7 @@ impl Plugin for MultiplayerPlugin {
GameListingPlugin,
CreateGamePlugin,
SetupGamePlugin,
JoinedGamePlugin,
))
.add_systems(
PostUpdate,
Expand Down

0 comments on commit 2d31cb6

Please sign in to comment.