Skip to content

Commit

Permalink
Add exit button, but not for wasm (#109)
Browse files Browse the repository at this point in the history
Partially: #92
  • Loading branch information
MiniaczQ committed Jul 11, 2024
1 parent ad5e2af commit 4384f60
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/screen/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub(super) fn plugin(app: &mut App) {
enum TitleAction {
Play,
Credits,
/// Exit doesn't work well with embedded applications.
#[cfg(not(target = "wasm"))]
Exit,
}

fn enter_title(mut commands: Commands) {
Expand All @@ -26,18 +29,27 @@ fn enter_title(mut commands: Commands) {
.with_children(|children| {
children.button("Play").insert(TitleAction::Play);
children.button("Credits").insert(TitleAction::Credits);

#[cfg(not(target = "wasm"))]
children.button("Exit").insert(TitleAction::Exit);
});
}

fn handle_title_action(
mut next_screen: ResMut<NextState<Screen>>,
mut button_query: InteractionQuery<&TitleAction>,
mut app_exit: EventWriter<AppExit>,
) {
for (interaction, action) in &mut button_query {
if matches!(interaction, Interaction::Pressed) {
match action {
TitleAction::Play => next_screen.set(Screen::Playing),
TitleAction::Credits => next_screen.set(Screen::Credits),

#[cfg(not(target = "wasm"))]
TitleAction::Exit => {
app_exit.send(AppExit::Success);
}
}
}
}
Expand Down

0 comments on commit 4384f60

Please sign in to comment.