@@ -73,7 +73,7 @@ pub struct Fatigue {
73
73
/// Increases an entity's fatigue over time
74
74
pub fn fatigue_system ( time : Res < Time > , mut fatigues : Query < & mut Fatigue > ) {
75
75
for mut fatigue in & mut fatigues {
76
- fatigue. level += fatigue. per_second * time. delta_seconds ( ) ;
76
+ fatigue. level += fatigue. per_second * time. delta_secs ( ) ;
77
77
if fatigue. level >= 100.0 {
78
78
fatigue. level = 100.0 ;
79
79
}
@@ -111,7 +111,7 @@ pub struct Sleep {
111
111
// the Sleep component's parameters.
112
112
fn sleep_action_system (
113
113
time : Res < Time > ,
114
- mut fatigues : Query < ( & mut Fatigue , & Handle < StandardMaterial > ) > ,
114
+ mut fatigues : Query < ( & mut Fatigue , & MeshMaterial3d < StandardMaterial > ) > ,
115
115
// Resource used to modify the appearance of the farmer.
116
116
mut materials : ResMut < Assets < StandardMaterial > > ,
117
117
// We execute actions by querying for their associated Action Component
@@ -133,7 +133,7 @@ fn sleep_action_system(
133
133
}
134
134
ActionState :: Executing => {
135
135
trace ! ( "Sleeping..." ) ;
136
- fatigue. level -= sleep. per_second * time. delta_seconds ( ) ;
136
+ fatigue. level -= sleep. per_second * time. delta_secs ( ) ;
137
137
materials. get_mut ( material) . unwrap ( ) . base_color = SLEEP_COLOR ;
138
138
139
139
if fatigue. level <= sleep. until {
@@ -208,7 +208,7 @@ pub struct Farm {
208
208
// Farm component's parameters and changes the entity's appearance to indicate the farming action.
209
209
fn farm_action_system (
210
210
time : Res < Time > ,
211
- mut actors : Query < ( & mut Inventory , & Handle < StandardMaterial > ) > ,
211
+ mut actors : Query < ( & mut Inventory , & MeshMaterial3d < StandardMaterial > ) > ,
212
212
// Resource used to modify the appearance of the farmer.
213
213
mut materials : ResMut < Assets < StandardMaterial > > ,
214
214
// Query to manage the state of the farming action.
@@ -225,7 +225,7 @@ fn farm_action_system(
225
225
}
226
226
ActionState :: Executing => {
227
227
trace ! ( "Farming..." ) ;
228
- inventory. items += farm. per_second * time. delta_seconds ( ) ;
228
+ inventory. items += farm. per_second * time. delta_secs ( ) ;
229
229
materials. get_mut ( material) . unwrap ( ) . base_color = FARM_COLOR ;
230
230
231
231
if inventory. items >= MAX_INVENTORY_ITEMS {
@@ -398,7 +398,7 @@ pub fn move_to_nearest_system<T: Component + std::fmt::Debug + Clone>(
398
398
if distance > MAX_DISTANCE {
399
399
trace ! ( "Stepping closer." ) ;
400
400
401
- let step_size = time. delta_seconds ( ) * move_to. speed ;
401
+ let step_size = time. delta_secs ( ) * move_to. speed ;
402
402
let step = delta. normalize ( ) * step_size. min ( distance) ;
403
403
404
404
// We only care about moving in the XZ plane.
@@ -455,15 +455,15 @@ fn update_ui(
455
455
) {
456
456
for ( inventory, fatigue) in & mut actor_query. iter ( ) {
457
457
for mut text in & mut money_query {
458
- text. sections [ 0 ] . value = format ! ( "Money: {}" , inventory. money) ;
458
+ text. 0 = format ! ( "Money: {}" , inventory. money) ;
459
459
}
460
460
461
461
for mut text in & mut fatigue_query {
462
- text. sections [ 0 ] . value = format ! ( "Fatigue: {}" , fatigue. level as u32 ) ;
462
+ text. 0 = format ! ( "Fatigue: {}" , fatigue. level as u32 ) ;
463
463
}
464
464
465
465
for mut text in & mut inventory_query {
466
- text. sections [ 0 ] . value = format ! ( "Inventory: {}" , inventory. items as u32 ) ;
466
+ text. 0 = format ! ( "Inventory: {}" , inventory. items as u32 ) ;
467
467
}
468
468
}
469
469
}
@@ -475,11 +475,10 @@ fn init_entities(
475
475
mut meshes : ResMut < Assets < Mesh > > ,
476
476
mut materials : ResMut < Assets < StandardMaterial > > ,
477
477
) {
478
- commands. spawn ( Camera3dBundle {
479
- transform : Transform :: from_xyz ( 6.0 , 6.0 , 4.0 )
480
- . looking_at ( Vec3 :: new ( 0.0 , -1.0 , 0.0 ) , Vec3 :: Y ) ,
481
- ..default ( )
482
- } ) ;
478
+ commands. spawn ( (
479
+ Camera3d :: default ( ) ,
480
+ Transform :: from_xyz ( 6.0 , 6.0 , 4.0 ) . looking_at ( Vec3 :: new ( 0.0 , -1.0 , 0.0 ) , Vec3 :: Y ) ,
481
+ ) ) ;
483
482
484
483
commands. insert_resource ( AmbientLight {
485
484
color : Color :: WHITE ,
@@ -488,26 +487,20 @@ fn init_entities(
488
487
489
488
commands. spawn ( (
490
489
Name :: new ( "Light" ) ,
491
- SpotLightBundle {
492
- spot_light : SpotLight {
493
- shadows_enabled : true ,
494
- intensity : 500_000.0 ,
495
- range : 100.0 ,
496
- ..default ( )
497
- } ,
498
- transform : Transform :: from_xyz ( 2.0 , 10.0 , 0.0 ) . looking_at ( Vec3 :: ZERO , Vec3 :: Y ) ,
490
+ SpotLight {
491
+ shadows_enabled : true ,
492
+ intensity : 500_000.0 ,
493
+ range : 100.0 ,
499
494
..default ( )
500
495
} ,
496
+ Transform :: from_xyz ( 2.0 , 10.0 , 0.0 ) . looking_at ( Vec3 :: ZERO , Vec3 :: Y ) ,
501
497
) ) ;
502
498
503
499
// Loading our scene here. Note we'll still need to add components to different parts
504
500
// of the gltf in order to query their positions. We do this through an observer further below.
505
501
commands. spawn ( (
506
502
Name :: new ( "Town" ) ,
507
- SceneBundle {
508
- scene : asset_server. load ( "models/town.glb#Scene0" ) ,
509
- ..default ( )
510
- } ,
503
+ SceneRoot ( asset_server. load ( "models/town.glb#Scene0" ) ) ,
511
504
) ) ;
512
505
513
506
// We'll use `Steps` to execute a sequence of actions.
@@ -538,16 +531,13 @@ fn init_entities(
538
531
539
532
commands. spawn ( (
540
533
Name :: new ( "Farmer" ) ,
541
- PbrBundle {
542
- mesh : meshes. add ( Mesh :: from ( Capsule3d {
543
- half_length : 0.15 ,
544
- radius : 0.1 ,
545
- ..default ( )
546
- } ) ) ,
547
- material : materials. add ( DEFAULT_COLOR ) ,
548
- transform : Transform :: from_xyz ( 0.0 , 0.5 , 0.0 ) ,
534
+ Mesh3d ( meshes. add ( Mesh :: from ( Capsule3d {
535
+ half_length : 0.15 ,
536
+ radius : 0.1 ,
549
537
..default ( )
550
- } ,
538
+ } ) ) ) ,
539
+ MeshMaterial3d ( materials. add ( DEFAULT_COLOR ) ) ,
540
+ Transform :: from_xyz ( 0.0 , 0.5 , 0.0 ) ,
551
541
Fatigue {
552
542
is_sleeping : false ,
553
543
per_second : 4.0 ,
@@ -566,29 +556,26 @@ fn init_entities(
566
556
. when ( SellNeedScorer , move_and_sell) ,
567
557
) ) ;
568
558
569
- let style = TextStyle {
559
+ let font = TextFont {
570
560
font_size : 40.0 ,
571
561
..default ( )
572
562
} ;
573
563
574
564
// Our scoreboard.
575
565
commands
576
- . spawn ( NodeBundle {
577
- style : Style {
578
- width : Val :: Percent ( 100.0 ) ,
579
- height : Val :: Percent ( 100.0 ) ,
580
- flex_direction : FlexDirection :: Column ,
581
- justify_content : JustifyContent :: End ,
582
- align_items : AlignItems :: FlexStart ,
583
- padding : UiRect :: all ( Val :: Px ( 20.0 ) ) ,
584
- ..default ( )
585
- } ,
566
+ . spawn ( Node {
567
+ width : Val :: Percent ( 100.0 ) ,
568
+ height : Val :: Percent ( 100.0 ) ,
569
+ flex_direction : FlexDirection :: Column ,
570
+ justify_content : JustifyContent :: End ,
571
+ align_items : AlignItems :: FlexStart ,
572
+ padding : UiRect :: all ( Val :: Px ( 20.0 ) ) ,
586
573
..default ( )
587
574
} )
588
575
. with_children ( |builder| {
589
- builder. spawn ( ( TextBundle :: from_section ( "" , style . clone ( ) ) , MoneyText ) ) ;
590
- builder. spawn ( ( TextBundle :: from_section ( "" , style . clone ( ) ) , FatigueText ) ) ;
591
- builder. spawn ( ( TextBundle :: from_section ( "" , style . clone ( ) ) , InventoryText ) ) ;
576
+ builder. spawn ( ( Text :: new ( "" ) , font . clone ( ) , MoneyText ) ) ;
577
+ builder. spawn ( ( Text :: new ( "" ) , font . clone ( ) , FatigueText ) ) ;
578
+ builder. spawn ( ( Text :: new ( "" ) , font . clone ( ) , InventoryText ) ) ;
592
579
} ) ;
593
580
}
594
581
@@ -640,7 +627,7 @@ fn main() {
640
627
. add_event :: < SceneLoaded > ( )
641
628
. add_systems ( Update , check_scene_loaded)
642
629
// This observer will attach components to entities in the scene based on their names.
643
- . observe (
630
+ . add_observer (
644
631
|trigger : Trigger < SceneLoaded > ,
645
632
query : Query < ( Entity , & Name ) > ,
646
633
mut commands : Commands | {
0 commit comments