Skip to content

Commit 868ebdb

Browse files
authored
feat(bevy): Upgrade to bevy 0.15 (#106)
1 parent ab0385d commit 868ebdb

7 files changed

+54
-67
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ homepage = "https://github.com/zkat/big-brain"
1515
[workspace]
1616

1717
[dependencies]
18-
bevy = { version = "0.14.0", default-features = false }
18+
bevy = { version = "0.15.0", default-features = false }
1919
big-brain-derive = { version = "=0.21.1", path = "./derive" }
2020

2121
[dev-dependencies]
22-
bevy = { version = "0.14.0", default-features = true }
22+
bevy = { version = "0.15.0", default-features = true }
2323
rand = { version = "0.8.5", features = ["small_rng"] }
2424

2525
[features]

examples/custom_measure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Pancakes(pub f32);
3434
pub struct Waffles(pub f32);
3535

3636
pub fn eat_dessert(time: Res<Time>, mut pancakes: Query<(&mut Pancakes, &mut Waffles)>) {
37-
let delta_t = time.delta_seconds();
37+
let delta_t = time.delta_secs();
3838

3939
for (mut pancake, mut waffle) in pancakes.iter_mut() {
4040
pancake.0 = (pancake.0 - delta_t).max(0.0);
@@ -101,7 +101,7 @@ fn eat_thing_action<
101101
ActionState::Executing => {
102102
debug!("You should {:?}", action_marker);
103103

104-
item.eat(time.delta_seconds() * 5.0);
104+
item.eat(time.delta_secs() * 5.0);
105105

106106
// we should stop at some eating pancakes at some point, unfortunately
107107
if item.get() > 80.0 {

examples/farming_sim.rs

+37-50
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub struct Fatigue {
7373
/// Increases an entity's fatigue over time
7474
pub fn fatigue_system(time: Res<Time>, mut fatigues: Query<&mut Fatigue>) {
7575
for mut fatigue in &mut fatigues {
76-
fatigue.level += fatigue.per_second * time.delta_seconds();
76+
fatigue.level += fatigue.per_second * time.delta_secs();
7777
if fatigue.level >= 100.0 {
7878
fatigue.level = 100.0;
7979
}
@@ -111,7 +111,7 @@ pub struct Sleep {
111111
// the Sleep component's parameters.
112112
fn sleep_action_system(
113113
time: Res<Time>,
114-
mut fatigues: Query<(&mut Fatigue, &Handle<StandardMaterial>)>,
114+
mut fatigues: Query<(&mut Fatigue, &MeshMaterial3d<StandardMaterial>)>,
115115
// Resource used to modify the appearance of the farmer.
116116
mut materials: ResMut<Assets<StandardMaterial>>,
117117
// We execute actions by querying for their associated Action Component
@@ -133,7 +133,7 @@ fn sleep_action_system(
133133
}
134134
ActionState::Executing => {
135135
trace!("Sleeping...");
136-
fatigue.level -= sleep.per_second * time.delta_seconds();
136+
fatigue.level -= sleep.per_second * time.delta_secs();
137137
materials.get_mut(material).unwrap().base_color = SLEEP_COLOR;
138138

139139
if fatigue.level <= sleep.until {
@@ -208,7 +208,7 @@ pub struct Farm {
208208
// Farm component's parameters and changes the entity's appearance to indicate the farming action.
209209
fn farm_action_system(
210210
time: Res<Time>,
211-
mut actors: Query<(&mut Inventory, &Handle<StandardMaterial>)>,
211+
mut actors: Query<(&mut Inventory, &MeshMaterial3d<StandardMaterial>)>,
212212
// Resource used to modify the appearance of the farmer.
213213
mut materials: ResMut<Assets<StandardMaterial>>,
214214
// Query to manage the state of the farming action.
@@ -225,7 +225,7 @@ fn farm_action_system(
225225
}
226226
ActionState::Executing => {
227227
trace!("Farming...");
228-
inventory.items += farm.per_second * time.delta_seconds();
228+
inventory.items += farm.per_second * time.delta_secs();
229229
materials.get_mut(material).unwrap().base_color = FARM_COLOR;
230230

231231
if inventory.items >= MAX_INVENTORY_ITEMS {
@@ -398,7 +398,7 @@ pub fn move_to_nearest_system<T: Component + std::fmt::Debug + Clone>(
398398
if distance > MAX_DISTANCE {
399399
trace!("Stepping closer.");
400400

401-
let step_size = time.delta_seconds() * move_to.speed;
401+
let step_size = time.delta_secs() * move_to.speed;
402402
let step = delta.normalize() * step_size.min(distance);
403403

404404
// We only care about moving in the XZ plane.
@@ -455,15 +455,15 @@ fn update_ui(
455455
) {
456456
for (inventory, fatigue) in &mut actor_query.iter() {
457457
for mut text in &mut money_query {
458-
text.sections[0].value = format!("Money: {}", inventory.money);
458+
text.0 = format!("Money: {}", inventory.money);
459459
}
460460

461461
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);
463463
}
464464

465465
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);
467467
}
468468
}
469469
}
@@ -475,11 +475,10 @@ fn init_entities(
475475
mut meshes: ResMut<Assets<Mesh>>,
476476
mut materials: ResMut<Assets<StandardMaterial>>,
477477
) {
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+
));
483482

484483
commands.insert_resource(AmbientLight {
485484
color: Color::WHITE,
@@ -488,26 +487,20 @@ fn init_entities(
488487

489488
commands.spawn((
490489
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,
499494
..default()
500495
},
496+
Transform::from_xyz(2.0, 10.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
501497
));
502498

503499
// Loading our scene here. Note we'll still need to add components to different parts
504500
// of the gltf in order to query their positions. We do this through an observer further below.
505501
commands.spawn((
506502
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")),
511504
));
512505

513506
// We'll use `Steps` to execute a sequence of actions.
@@ -538,16 +531,13 @@ fn init_entities(
538531

539532
commands.spawn((
540533
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,
549537
..default()
550-
},
538+
}))),
539+
MeshMaterial3d(materials.add(DEFAULT_COLOR)),
540+
Transform::from_xyz(0.0, 0.5, 0.0),
551541
Fatigue {
552542
is_sleeping: false,
553543
per_second: 4.0,
@@ -566,29 +556,26 @@ fn init_entities(
566556
.when(SellNeedScorer, move_and_sell),
567557
));
568558

569-
let style = TextStyle {
559+
let font = TextFont {
570560
font_size: 40.0,
571561
..default()
572562
};
573563

574564
// Our scoreboard.
575565
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)),
586573
..default()
587574
})
588575
.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));
592579
});
593580
}
594581

@@ -640,7 +627,7 @@ fn main() {
640627
.add_event::<SceneLoaded>()
641628
.add_systems(Update, check_scene_loaded)
642629
// This observer will attach components to entities in the scene based on their names.
643-
.observe(
630+
.add_observer(
644631
|trigger: Trigger<SceneLoaded>,
645632
query: Query<(Entity, &Name)>,
646633
mut commands: Commands| {

examples/sequence.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Thirst {
4040
/// Just a plain old Bevy system, big-brain is not involved yet.
4141
pub fn thirst_system(time: Res<Time>, mut thirsts: Query<&mut Thirst>) {
4242
for mut thirst in &mut thirsts {
43-
thirst.thirst += thirst.per_second * time.delta_seconds();
43+
thirst.thirst += thirst.per_second * time.delta_secs();
4444

4545
// Thirst is capped at 100.0
4646
if thirst.thirst >= 100.0 {
@@ -104,7 +104,7 @@ fn move_to_water_source_action_system(
104104
trace!("Stepping closer.");
105105

106106
// How far can we travel during this frame?
107-
let step_size = time.delta_seconds() * move_to.speed;
107+
let step_size = time.delta_secs() * move_to.speed;
108108
// Travel towards the water-source position, but make sure to not overstep it.
109109
let step = delta.normalize() * step_size.min(distance);
110110

@@ -191,7 +191,7 @@ fn drink_action_system(
191191

192192
// Start reducing the thirst. Alternatively, you could send out some kind of
193193
// DrinkFromSource event that indirectly decreases thirst.
194-
thirst.thirst -= drink.per_second * time.delta_seconds();
194+
thirst.thirst -= drink.per_second * time.delta_secs();
195195

196196
// Once we hit 0 thirst, we stop drinking and report success.
197197
if thirst.thirst <= 0.0 {

src/actions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl ActionBuilder for StepsBuilder {
194194
steps: self.steps.clone(),
195195
steps_labels: self.steps_labels.clone(),
196196
})
197-
.push_children(&[child_action]);
197+
.add_children(&[child_action]);
198198
}
199199
}
200200
}
@@ -315,7 +315,7 @@ pub fn steps_system(
315315
let step_ent = spawn_action(step_builder.as_ref(), &mut cmd, *actor);
316316
#[cfg(feature = "trace")]
317317
trace!("Spawned next step: {:?}", step_ent);
318-
cmd.entity(seq_ent).push_children(&[step_ent]);
318+
cmd.entity(seq_ent).add_children(&[step_ent]);
319319
steps_action.active_ent = Action(step_ent);
320320
}
321321
}
@@ -396,7 +396,7 @@ impl ActionBuilder for ConcurrentlyBuilder {
396396
.collect();
397397
cmd.entity(action)
398398
.insert(Name::new("Concurrent Action"))
399-
.push_children(&children[..])
399+
.add_children(&children[..])
400400
.insert(Concurrently {
401401
actions: children.into_iter().map(Action).collect(),
402402
action_labels: self.action_labels.clone(),

src/choices.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl ChoiceBuilder {
5050

5151
pub fn build(&self, cmd: &mut Commands, actor: Entity, parent: Entity) -> Choice {
5252
let scorer_ent = scorers::spawn_scorer(&*self.when, cmd, actor);
53-
cmd.entity(parent).push_children(&[scorer_ent]);
53+
cmd.entity(parent).add_children(&[scorer_ent]);
5454
Choice {
5555
scorer: Scorer(scorer_ent),
5656
action_label: self.then.label().map(|s| s.into()),

src/scorers.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl ScorerBuilder for AllOrNothingBuilder {
279279
.collect();
280280
cmd.entity(scorer)
281281
.insert(Score::default())
282-
.push_children(&scorers[..])
282+
.add_children(&scorers[..])
283283
.insert(Name::new("Scorer"))
284284
.insert(AllOrNothing {
285285
threshold: self.threshold,
@@ -406,7 +406,7 @@ impl ScorerBuilder for SumOfScorersBuilder {
406406
.map(|scorer| spawn_scorer(&**scorer, cmd, actor))
407407
.collect();
408408
cmd.entity(scorer)
409-
.push_children(&scorers[..])
409+
.add_children(&scorers[..])
410410
.insert(SumOfScorers {
411411
threshold: self.threshold,
412412
scorers: scorers.into_iter().map(Scorer).collect(),
@@ -565,7 +565,7 @@ impl ScorerBuilder for ProductOfScorersBuilder {
565565
.map(|scorer| spawn_scorer(&**scorer, cmd, actor))
566566
.collect();
567567
cmd.entity(scorer)
568-
.push_children(&scorers[..])
568+
.add_children(&scorers[..])
569569
.insert(ProductOfScorers {
570570
threshold: self.threshold,
571571
use_compensation: self.use_compensation,
@@ -696,7 +696,7 @@ impl ScorerBuilder for WinningScorerBuilder {
696696
.map(|scorer| spawn_scorer(&**scorer, cmd, actor))
697697
.collect();
698698
cmd.entity(scorer)
699-
.push_children(&scorers[..])
699+
.add_children(&scorers[..])
700700
.insert(WinningScorer {
701701
threshold: self.threshold,
702702
scorers: scorers.into_iter().map(Scorer).collect(),
@@ -805,7 +805,7 @@ impl ScorerBuilder for EvaluatingScorerBuilder {
805805
let inner_scorer = spawn_scorer(&*self.scorer, cmd, actor);
806806
let scorers = [inner_scorer];
807807
cmd.entity(scorer)
808-
.push_children(&scorers[..])
808+
.add_children(&scorers[..])
809809
.insert(EvaluatingScorer {
810810
evaluator: self.evaluator.clone(),
811811
scorer: Scorer(inner_scorer),
@@ -978,7 +978,7 @@ impl ScorerBuilder for MeasuredScorerBuilder {
978978
.map(|(scorer, _)| spawn_scorer(&**scorer, cmd, actor))
979979
.collect();
980980
cmd.entity(scorer)
981-
.push_children(&scorers[..])
981+
.add_children(&scorers[..])
982982
.insert(MeasuredScorer {
983983
threshold: self.threshold,
984984
measure: self.measure.clone(),

0 commit comments

Comments
 (0)