Skip to content

Commit

Permalink
Improve toast event scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
Indy2222 committed Jul 24, 2023
1 parent 2cf0417 commit 26d62cb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion crates/gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use text::TextPlugin;
pub use text::TextProps;
use textbox::TextBoxPlugin;
pub use textbox::{TextBoxCommands, TextBoxQuery};
pub use toast::ToastEvent;
use toast::ToastPlugin;
pub use toast::{ToastEvent, ToastSet};

mod body_text;
mod button;
Expand Down
9 changes: 7 additions & 2 deletions crates/gui/src/toast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ impl Plugin for ToastPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<ToastQueue>()
.add_event::<ToastEvent>()
.add_system(process_events.in_set(ToastSet::ProcessEvents))
.add_system(
process_events
.in_base_set(CoreSet::PostUpdate)
.in_set(ToastSet::ProcessEvents),
)
.add_system(
spawn_and_despawn
.in_base_set(CoreSet::PostUpdate)
.run_if(not(in_state(AppState::AppLoading)))
.after(ToastSet::ProcessEvents),
);
}
}

#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, SystemSet)]
pub enum ToastSet {
enum ToastSet {
ProcessEvents,
}

Expand Down
8 changes: 2 additions & 6 deletions crates/menu/src/gamelisting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use bevy::{prelude::*, time::Stopwatch};
use de_gui::{ButtonCommands, GuiCommands, LabelCommands, OuterStyle, ToastEvent, ToastSet};
use de_gui::{ButtonCommands, GuiCommands, LabelCommands, OuterStyle, ToastEvent};
use de_lobby_client::{ListGamesRequest, RequestEvent, ResponseEvent};
use de_lobby_model::GamePartial;

Expand All @@ -16,11 +16,7 @@ impl Plugin for GameListingPlugin {
app.add_system(setup.in_schedule(OnEnter(MenuState::GameListing)))
.add_system(cleanup.in_schedule(OnExit(MenuState::GameListing)))
.add_system(refresh_system.run_if(in_state(MenuState::GameListing)))
.add_system(
list_games_system
.run_if(in_state(MenuState::GameListing))
.before(ToastSet::ProcessEvents),
)
.add_system(list_games_system.run_if(in_state(MenuState::GameListing)))
.add_system(button_system.run_if(in_state(MenuState::GameListing)));
}
}
Expand Down
14 changes: 3 additions & 11 deletions crates/menu/src/signin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::prelude::*;
use de_gui::{
ButtonCommands, GuiCommands, LabelCommands, OuterStyle, SetFocusEvent, TextBoxCommands,
TextBoxQuery, ToastEvent, ToastSet,
TextBoxQuery, ToastEvent,
};
use de_lobby_client::{Authentication, LobbyRequest, SignInRequest, SignUpRequest};
use de_lobby_model::{User, UserWithPassword, UsernameAndPassword};
Expand All @@ -25,16 +25,8 @@ impl Plugin for SignInPlugin {
.run_if(resource_exists::<Inputs>())
.run_if(in_state(MenuState::SignIn)),
)
.add_system(
response_system::<SignInRequest>
.run_if(in_state(MenuState::SignIn))
.before(ToastSet::ProcessEvents),
)
.add_system(
response_system::<SignUpRequest>
.run_if(in_state(MenuState::SignIn))
.before(ToastSet::ProcessEvents),
)
.add_system(response_system::<SignInRequest>.run_if(in_state(MenuState::SignIn)))
.add_system(response_system::<SignUpRequest>.run_if(in_state(MenuState::SignIn)))
.add_system(auth_system.run_if(in_state(MenuState::SignIn)));
}
}
Expand Down

0 comments on commit 26d62cb

Please sign in to comment.