@@ -204,7 +204,7 @@ fn startup(mut commands: Commands, windows: Query<&Window>) {
204
204
// Set current goal to be to acquire gold
205
205
planner. current_goal = Some ( gold_goal. clone ( ) ) ;
206
206
207
- let text_style = TextStyle {
207
+ let text_style = TextFont {
208
208
font_size : 18.0 ,
209
209
..default ( )
210
210
} ;
@@ -220,13 +220,10 @@ fn startup(mut commands: Commands, windows: Query<&Window>) {
220
220
) )
221
221
. with_children ( |subcommands| {
222
222
subcommands. spawn ( (
223
- Text2dBundle {
224
- transform : Transform :: from_translation ( Vec3 :: new ( 10.0 , -10.0 , 10.0 ) ) ,
225
- text : Text :: from_section ( "" , text_style. clone ( ) )
226
- . with_justify ( JustifyText :: Left ) ,
227
- text_anchor : bevy:: sprite:: Anchor :: TopLeft ,
228
- ..default ( )
229
- } ,
223
+ Transform :: from_translation ( Vec3 :: new ( 10.0 , -10.0 , 10.0 ) ) ,
224
+ Text2d ( "" . into ( ) ) ,
225
+ text_style,
226
+ bevy:: sprite:: Anchor :: TopLeft ,
230
227
NeedsText ,
231
228
) ) ;
232
229
} ) ;
@@ -364,7 +361,7 @@ fn handle_go_to_house_action(
364
361
365
362
go_to_location :: < GoToHouseAction > (
366
363
& mut at_location,
367
- time. delta_seconds ( ) ,
364
+ time. delta_secs ( ) ,
368
365
& mut t_entity,
369
366
t_house. translation ,
370
367
Location :: House ,
@@ -390,7 +387,7 @@ fn handle_go_to_smelter_action(
390
387
391
388
go_to_location :: < GoToSmelterAction > (
392
389
& mut at_location,
393
- time. delta_seconds ( ) ,
390
+ time. delta_secs ( ) ,
394
391
& mut t_entity,
395
392
t_smelter. translation ,
396
393
Location :: Smelter ,
@@ -417,7 +414,7 @@ fn handle_go_to_outside_action(
417
414
418
415
go_to_location :: < GoToOutsideAction > (
419
416
& mut at_location,
420
- time. delta_seconds ( ) ,
417
+ time. delta_secs ( ) ,
421
418
& mut t_entity,
422
419
new_pos,
423
420
Location :: Outside ,
@@ -443,7 +440,7 @@ fn handle_go_to_merchant_action(
443
440
444
441
go_to_location :: < GoToMerchantAction > (
445
442
& mut at_location,
446
- time. delta_seconds ( ) ,
443
+ time. delta_secs ( ) ,
447
444
& mut t_entity,
448
445
t_destination. translation ,
449
446
Location :: Merchant ,
@@ -474,7 +471,7 @@ fn handle_go_to_mushroom_action(
474
471
475
472
go_to_location :: < GoToMushroomAction > (
476
473
& mut at_location,
477
- time. delta_seconds ( ) ,
474
+ time. delta_secs ( ) ,
478
475
& mut t_entity,
479
476
mushroom. 1 ,
480
477
Location :: Mushroom ,
@@ -503,7 +500,7 @@ fn handle_go_to_ore_action(
503
500
504
501
go_to_location :: < GoToOreAction > (
505
502
& mut at_location,
506
- time. delta_seconds ( ) ,
503
+ time. delta_secs ( ) ,
507
504
& mut t_entity,
508
505
closest. 1 ,
509
506
Location :: Ore ,
@@ -581,7 +578,7 @@ fn handle_sleep_action(
581
578
planner. always_plan = false ;
582
579
583
580
let r = rng. gen_range ( 5.0 ..20.0 ) ;
584
- let val: f64 = r * time. delta_seconds_f64 ( ) ;
581
+ let val: f64 = r * time. delta_secs_f64 ( ) ;
585
582
energy. 0 += val;
586
583
if energy. 0 >= 100.0 {
587
584
commands. entity ( entity) . remove :: < SleepAction > ( ) ;
@@ -670,7 +667,7 @@ fn handle_mine_ore_action(
670
667
671
668
// Mining consumes energy!
672
669
let r = rng. gen_range ( 5.0 ..10.0 ) ;
673
- let val: f64 = r * time. delta_seconds_f64 ( ) ;
670
+ let val: f64 = r * time. delta_secs_f64 ( ) ;
674
671
energy. 0 -= val;
675
672
// If we're running out of energy before finishing, stop mining for now
676
673
if energy. 0 <= 0.0 {
@@ -726,7 +723,7 @@ fn handle_smelt_ore_action(
726
723
let mut rng = rand:: thread_rng ( ) ;
727
724
// Smelting consumes even more energy!
728
725
let r = rng. gen_range ( 10.0 ..15.0 ) ;
729
- let val: f64 = r * time. delta_seconds_f64 ( ) ;
726
+ let val: f64 = r * time. delta_secs_f64 ( ) ;
730
727
energy. 0 -= val;
731
728
if energy. 0 <= 0.0 {
732
729
commands. entity ( entity) . remove :: < SmeltOreAction > ( ) ;
@@ -778,15 +775,15 @@ fn over_time_needs_change(time: Res<Time>, mut query: Query<(&mut Hunger, &mut E
778
775
for ( mut hunger, mut energy) in query. iter_mut ( ) {
779
776
// Increase hunger
780
777
let r = rng. gen_range ( 10.0 ..20.0 ) ;
781
- let val: f64 = r * time. delta_seconds_f64 ( ) ;
778
+ let val: f64 = r * time. delta_secs_f64 ( ) ;
782
779
hunger. 0 += val;
783
780
if hunger. 0 > 100.0 {
784
781
hunger. 0 = 100.0 ;
785
782
}
786
783
787
784
// Decrease energy
788
785
let r = rng. gen_range ( 1.0 ..10.0 ) ;
789
- let val: f64 = r * time. delta_seconds_f64 ( ) ;
786
+ let val: f64 = r * time. delta_secs_f64 ( ) ;
790
787
energy. 0 -= val;
791
788
if energy. 0 < 0.0 {
792
789
energy. 0 = 0.0 ;
@@ -818,7 +815,8 @@ fn print_current_local_state(
818
815
Option < & GoToMerchantAction > ,
819
816
) > ,
820
817
// action_query: Query<&dyn ActionComponent>,
821
- mut q_child : Query < & mut Text , With < NeedsText > > ,
818
+ q_child : Query < Entity , With < NeedsText > > ,
819
+ mut text_writer : Text2dWriter ,
822
820
) {
823
821
for ( entity, hunger, energy, has_ore, has_metal, gold_amount, children) in query. iter ( ) {
824
822
let hunger = hunger. 0 ;
@@ -888,10 +886,9 @@ fn print_current_local_state(
888
886
}
889
887
890
888
for & child in children. iter ( ) {
891
- let mut text = q_child. get_mut ( child) . unwrap ( ) ;
892
- text. sections [ 0 ] . value = format ! (
893
- "{current_action}\n Gold: {gold_amount}\n Hunger: {hunger:.0}\n Energy: {energy:.0}\n Has Ore? {has_ore}\n Has Metal? {has_metal}"
894
- ) ;
889
+ let text = q_child. get ( child) . unwrap ( ) ;
890
+ * text_writer. text ( text, 0 ) =
891
+ format ! ( "{current_action}\n Gold: {gold_amount}\n Hunger: {hunger:.0}\n Energy: {energy:.0}\n Has Ore? {has_ore}\n Has Metal? {has_metal}" ) ;
895
892
}
896
893
}
897
894
}
@@ -909,7 +906,6 @@ fn draw_gizmos(
909
906
gizmos
910
907
. grid_2d (
911
908
Vec2 :: ZERO ,
912
- 0.0 ,
913
909
UVec2 :: new ( 16 , 9 ) ,
914
910
Vec2 :: new ( 80. , 80. ) ,
915
911
// Dark gray
@@ -923,14 +919,12 @@ fn draw_gizmos(
923
919
924
920
gizmos. rect_2d (
925
921
q_house. get_single ( ) . unwrap ( ) . translation . truncate ( ) ,
926
- 0.0 ,
927
922
Vec2 :: new ( 40.0 , 80.0 ) ,
928
923
AQUAMARINE ,
929
924
) ;
930
925
931
926
gizmos. rect_2d (
932
927
q_smelter. get_single ( ) . unwrap ( ) . translation . truncate ( ) ,
933
- 0.0 ,
934
928
Vec2 :: new ( 30.0 , 30.0 ) ,
935
929
YELLOW_GREEN ,
936
930
) ;
0 commit comments