11use bevy:: { prelude:: * , sprite:: Anchor , text:: TextBounds , window:: RequestRedraw } ;
22
33use crate :: {
4- BoardPosition , CurrentBoard ,
4+ BoardPosition , CurrentBoard , SolutionEvent ,
55 solver:: { FeasibleConstellations , RandomMoveChances } ,
66 total_progress:: TotalProgress ,
77} ;
@@ -22,6 +22,7 @@ impl Plugin for StatsPlugin {
2222 app. add_observer ( update_next_move_chance) ;
2323 app. add_observer ( update_overall_success) ;
2424 app. add_observer ( update_total_progress) ;
25+ app. add_observer ( update_solution_count) ;
2526 }
2627}
2728
@@ -34,6 +35,9 @@ struct NextMoveChanceText;
3435#[ derive( Component ) ]
3536struct TotalProgressText ;
3637
38+ #[ derive( Component ) ]
39+ struct SolutionText ;
40+
3741#[ derive( Component ) ]
3842struct OverallSuccessRatio ;
3943
@@ -64,6 +68,8 @@ fn add_text(mut commands: Commands, asset_server: Res<AssetServer>) {
6468 Vec3 :: from ( ( BoardPosition { x : 1 , y : 4 } . to_world_space ( ) , 1. ) ) + Vec3 :: new ( 0.5 , -0.5 , 0.0 ) ;
6569 let title_pos_2 =
6670 Vec3 :: from ( ( BoardPosition { x : 4 , y : 1 } . to_world_space ( ) , 1. ) ) + Vec3 :: new ( 0.5 , -0.5 , 0.0 ) ;
71+ let title_pos_3 =
72+ Vec3 :: from ( ( BoardPosition { x : 1 , y : 1 } . to_world_space ( ) , 1. ) ) + Vec3 :: new ( 0.5 , -0.5 , 0.0 ) ;
6773 let text_pos = title_pos - 1.0 * Vec3 :: Y ;
6874 commands
6975 . spawn ( (
@@ -113,6 +119,20 @@ fn add_text(mut commands: Commands, asset_server: Res<AssetServer>) {
113119 small_font. clone ( ) ,
114120 ) )
115121 . with_child ( ( TextSpan ( "" . into ( ) ) , small_font. clone ( ) ) ) ;
122+ commands
123+ . spawn ( (
124+ Text2d :: new ( "you have found " ) ,
125+ Transform :: from_scale ( Vec3 :: new ( 0.004 , 0.004 , 0.004 ) ) . with_translation ( title_pos_3) ,
126+ small_font. clone ( ) ,
127+ TextLayout :: new ( Justify :: Center , LineBreak :: WordBoundary ) ,
128+ TextBounds :: from ( Vec2 :: new ( 600.0 , 300.0 ) ) ,
129+ Anchor :: BOTTOM_RIGHT ,
130+ SolutionText ,
131+ ) )
132+ . with_child ( ( TextSpan ( " ? " . into ( ) ) , large_font. clone ( ) ) )
133+ . with_child ( ( TextSpan ( " solutions, " . into ( ) ) , small_font. clone ( ) ) )
134+ . with_child ( ( TextSpan ( " ? " . into ( ) ) , large_font. clone ( ) ) )
135+ . with_child ( ( TextSpan ( " of which are unique!" . into ( ) ) , small_font. clone ( ) ) ) ;
116136}
117137
118138fn update_overall_success (
@@ -193,3 +213,19 @@ fn update_total_progress(
193213 }
194214 request_redraw. write ( RequestRedraw ) ;
195215}
216+
217+ fn update_solution_count (
218+ _: On < UpdateStats > ,
219+ total_progress : Res < TotalProgress > ,
220+ solution_text : Query < Entity , With < SolutionText > > ,
221+ mut writer : TextUiWriter ,
222+ mut request_redraw : MessageWriter < RequestRedraw > ,
223+ ) {
224+ let num_solutions = total_progress. num_solutions ;
225+ let num_unique_solutions = total_progress. unique_solutions . len ( ) ;
226+ for text in solution_text {
227+ * writer. text ( text, 1 ) = format ! ( "{num_solutions}" ) ;
228+ * writer. text ( text, 3 ) = format ! ( "{num_unique_solutions}" ) ;
229+ }
230+ request_redraw. write ( RequestRedraw ) ;
231+ }
0 commit comments