File tree 4 files changed +24
-37
lines changed
4 files changed +24
-37
lines changed Original file line number Diff line number Diff line change @@ -87,10 +87,6 @@ pub(crate) enum GameState {
87
87
Splash ,
88
88
}
89
89
90
- // a label component to tell us which things are loaded in the Game GameState
91
- #[ derive( Component ) ]
92
- struct OnGameScreen ;
93
-
94
90
#[ derive( Component ) ]
95
91
struct Player {
96
92
health : i32
@@ -114,7 +110,6 @@ fn setup_sys(
114
110
Mesh2d ( meshes. add ( Annulus :: new ( 25.0 , 50.0 ) ) ) ,
115
111
MeshMaterial2d ( materials. add ( Color :: WHITE ) ) ,
116
112
Transform :: from_xyz ( 0. , - window_height / 2. + 75. , 0. ) ,
117
- OnGameScreen ,
118
113
) ) ;
119
114
}
120
115
@@ -134,12 +129,4 @@ fn player_move_sys(
134
129
player_tf. translation . x = ( player_tf. translation . x + move_distance) . min ( width / 2. )
135
130
}
136
131
}
137
- }
138
-
139
- // stole this directly from an example but it seems a sensible way of removing
140
- // unneeded Entities with a given Component indiscriminantly
141
- fn despawn_entities < T : Component > ( to_despawn : Query < Entity , With < T > > , mut commands : Commands ) {
142
- for entity in & to_despawn {
143
- commands. entity ( entity) . despawn_recursive ( ) ;
144
- }
145
- }
132
+ }
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use super::{
10
10
MenuContainerNode ,
11
11
MenuButtonAction ,
12
12
MenuFont ,
13
+ OnMenuScreen ,
13
14
MENU_TEXT_COLOR
14
15
} ;
15
16
@@ -38,16 +39,7 @@ impl Plugin for MenuPlugin {
38
39
}
39
40
}
40
41
41
- /// Tag Entities with this if they appear on any menu screen
42
- ///
43
- /// Can be useful to despawn (or otherwise affect)
44
- /// the entire Menu regardless of where you are in it
45
- /// e.g. if you hit Esc while in [`GameState::Menu`] it should despawn all
46
- /// [`OnMenuScreen`] entities and switch to [`GameState::Gam`e], which would be difficult to do
47
- /// if we used only [`OnMainMenuScreen`] and [`OnSettingsMenuScreen`]
48
- #[ derive( Component ) ]
49
- struct OnMenuScreen ;
50
- /// Tag Entities with this if they are visible on [MenuState::MainMenu]
42
+ // Tag Entities with this if they are visible on [MenuState::MainMenu]
51
43
#[ derive( Component ) ]
52
44
struct OnMainMenuScreen ;
53
45
/// Tag Entities with this if they are visible on [MenuState::Settings]
Original file line number Diff line number Diff line change @@ -4,10 +4,7 @@ pub mod main_menu;
4
4
5
5
use bevy:: prelude:: * ;
6
6
use std:: { path:: PathBuf , sync:: LazyLock } ;
7
- use super :: {
8
- GameState ,
9
- despawn_entities
10
- } ;
7
+ use super :: GameState ;
11
8
use main_menu:: {
12
9
MenuState ,
13
10
MenuPlugin
@@ -43,6 +40,17 @@ impl Plugin for UiPlugin {
43
40
}
44
41
}
45
42
43
+ /// Tag Entities with this if they appear on any menu screen
44
+ ///
45
+ /// Can be useful to despawn (or otherwise affect)
46
+ /// the entire Menu regardless of where you are in it
47
+ /// e.g. if you hit Esc while in [`GameState::Menu`] it should despawn all
48
+ /// [`OnMenuScreen`] entities and switch to [`GameState::Gam`e], which would be difficult to do
49
+ /// if we used only [`OnMainMenuScreen`] and [`OnSettingsMenuScreen`]
50
+
51
+ #[ derive ( Component ) ]
52
+ pub struct OnMenuScreen ;
53
+
46
54
/// Enum of all the actions a [Button] should be able to perform,
47
55
/// with [MenuButtonAction] and [PauseButtonAction] variants
48
56
/// To use the variants:
@@ -253,4 +261,12 @@ pub fn pause_menu_listener_sys(
253
261
}
254
262
}
255
263
}
264
+ }
265
+
266
+ // stole this directly from an example but it seems a sensible way of removing
267
+ // unneeded Entities with a given Component indiscriminantly
268
+ fn despawn_entities < T : Component > ( to_despawn : Query < Entity , With < T > > , mut commands : Commands ) {
269
+ for entity in & to_despawn {
270
+ commands. entity ( entity) . despawn_recursive ( ) ;
271
+ }
256
272
}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use super::{
10
10
MenuContainerNode ,
11
11
ButtonNode ,
12
12
MenuFont ,
13
+ OnMenuScreen ,
13
14
MENU_TEXT_COLOR
14
15
} ;
15
16
use super :: main_menu:: {
@@ -38,15 +39,6 @@ impl Plugin for PausePlugin {
38
39
}
39
40
}
40
41
41
- /// Tag Entities with this if they appear on any menu screen
42
- ///
43
- /// Can be useful to despawn (or otherwise affect)
44
- /// the entire Menu regardless of where you are in it
45
- /// e.g. if you hit Esc while in [`GameState::Menu`] it should despawn all
46
- /// [`OnMenuScreen`] entities and switch to [`GameState::Game`], which would be difficult to do
47
- /// if we used only [`OnPauseMenuScreen`] and [`OnSettingsMenuScreen`]
48
- #[ derive( Component ) ]
49
- struct OnMenuScreen ;
50
42
/// Tag Entities with this if they are visible on [PauseMenuState::PauseMenu]
51
43
#[ derive( Component ) ]
52
44
struct OnPauseMenuScreen ;
You can’t perform that action at this time.
0 commit comments