@@ -7,6 +7,7 @@ use pyri_state::prelude::*;
7
7
use crate :: core:: pause:: Pause ;
8
8
use crate :: core:: UpdateSet ;
9
9
use crate :: game:: actor:: level:: up:: LevelUp ;
10
+ use crate :: game:: actor:: level:: IsLevelDisplay ;
10
11
use crate :: game:: actor:: level:: Level ;
11
12
use crate :: screen:: fade_out;
12
13
use crate :: screen:: playing:: PlayingAssets ;
@@ -21,7 +22,7 @@ pub(super) fn plugin(app: &mut App) {
21
22
PlayingMenu :: Victory . on_edge ( Pause :: disable, ( Pause :: enable_default, open_victory_menu) ) ,
22
23
) ;
23
24
24
- app. init_resource :: < EndlessMode > ( ) ;
25
+ app. configure :: < EndlessMode > ( ) ;
25
26
26
27
app. add_systems (
27
28
Update ,
@@ -32,28 +33,40 @@ pub(super) fn plugin(app: &mut App) {
32
33
) ;
33
34
}
34
35
35
- #[ derive( Default , Resource ) ]
36
+ pub fn detect_victory (
37
+ level_display_query : Query < & Selection , With < IsLevelDisplay > > ,
38
+ level_query : Query < & Level > ,
39
+ endless_mode : Res < EndlessMode > ,
40
+ ) -> bool {
41
+ let selection = r ! ( false , level_display_query. get_single( ) ) ;
42
+ let level = r ! ( false , level_query. get( selection. 0 ) ) ;
43
+
44
+ !endless_mode. 0 && level. current >= 10
45
+ }
46
+
47
+ #[ derive( Resource , Reflect , Default ) ]
48
+ #[ reflect( Resource ) ]
36
49
pub struct EndlessMode ( bool ) ;
37
50
51
+ impl Configure for EndlessMode {
52
+ fn configure ( app : & mut App ) {
53
+ app. register_type :: < Self > ( ) ;
54
+ app. init_resource :: < Self > ( ) ;
55
+ app. add_systems ( StateFlush , Screen :: Playing . on_enter ( reset_endless_mode) ) ;
56
+ }
57
+ }
58
+
59
+ fn reset_endless_mode ( mut endless_mode : ResMut < EndlessMode > ) {
60
+ endless_mode. 0 = false ;
61
+ }
62
+
38
63
fn open_victory_menu ( mut commands : Commands , ui_root : Res < UiRoot > ) {
39
64
commands
40
65
. spawn_with ( victory_overlay)
41
66
. set_parent ( ui_root. body ) ;
42
67
commands. spawn_with ( victory_menu) . set_parent ( ui_root. body ) ;
43
68
}
44
69
45
- pub fn detect_victory ( level_query : Query < & Level > , endless_mode : Res < EndlessMode > ) -> bool {
46
- if endless_mode. 0 {
47
- return false ;
48
- }
49
-
50
- if let Some ( level) = level_query. iter ( ) . last ( ) {
51
- return level. current >= 10 ;
52
- }
53
-
54
- false
55
- }
56
-
57
70
fn victory_overlay ( mut entity : EntityWorldMut ) {
58
71
entity. add ( widget:: blocking_overlay) . insert ( (
59
72
Name :: new ( "VictoryOverlay" ) ,
@@ -123,10 +136,6 @@ fn button_container(mut entity: EntityWorldMut) {
123
136
} ) ;
124
137
}
125
138
126
- pub fn reset_endless_mode ( mut endless_mode : ResMut < EndlessMode > ) {
127
- endless_mode. 0 = false ;
128
- }
129
-
130
139
fn keep_playing_button ( mut entity : EntityWorldMut ) {
131
140
entity. add ( widget:: menu_button ( "Keep Playing" ) ) . insert ( (
132
141
On :: < Pointer < Click > > :: run (
@@ -165,7 +174,9 @@ fn restart_button(mut entity: EntityWorldMut) {
165
174
166
175
fn quit_to_title_button ( mut entity : EntityWorldMut ) {
167
176
entity. add ( widget:: menu_button ( "Quit to title" ) ) . insert ( (
168
- On :: < Pointer < Click > > :: run ( Screen :: Title . enter ( ) ) ,
177
+ On :: < Pointer < Click > > :: run ( |mut commands : Commands | {
178
+ commands. spawn_with ( fade_out ( Screen :: Title ) ) ;
179
+ } ) ,
169
180
Style {
170
181
height : Vw ( 9.0 ) ,
171
182
width : Vw ( 38.0 ) ,
0 commit comments