Skip to content

Commit 23b87f2

Browse files
authored
Merge pull request #4 from splashdust/bevy-15
Upgrade to Bevy 0.15
2 parents b6da5e5 + 8e7b36d commit 23b87f2

File tree

9 files changed

+943
-510
lines changed

9 files changed

+943
-510
lines changed

Cargo.lock

+862-402
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bevy_dogoap/Cargo.toml

+12-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ default = ["compute-pool"]
1111
compute-pool = []
1212

1313
[dependencies]
14-
bevy = { version = "0.14.0", default-features = false, optional = false, features = ["wayland", "bevy_gizmos", "bevy_text", "multi_threaded", "default_font", "webgl2"]}
15-
bevy-trait-query-0-14-0 = { version = "0.6.2" }
16-
dogoap = { path = "../dogoap", version = "0.3.0"}
17-
dogoap_macros = { path = "../dogoap_macros", version = "0.3.0"}
14+
bevy = { version = "0.15", default-features = false, optional = false, features = [
15+
"wayland",
16+
"bevy_gizmos",
17+
"bevy_text",
18+
"multi_threaded",
19+
"default_font",
20+
"webgl2",
21+
"bevy_window",
22+
] }
23+
bevy-trait-query = { version = "0.7.0" }
24+
dogoap = { path = "../dogoap", version = "0.3.0" }
25+
dogoap_macros = { path = "../dogoap_macros", version = "0.3.0" }
1826
rand = "0.8.5"

crates/bevy_dogoap/examples/cells.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn spawn_cell(commands: &mut Commands, position: Vec3, speed: f32) {
9292
planner.always_plan = true; // Re-calculate our plan whenever we can
9393
planner.current_goal = Some(goal.clone());
9494

95-
let text_style = TextStyle {
95+
let text_style = TextFont {
9696
font_size: 12.0,
9797
..default()
9898
};
@@ -109,13 +109,10 @@ fn spawn_cell(commands: &mut Commands, position: Vec3, speed: f32) {
109109
))
110110
.with_children(|subcommands| {
111111
subcommands.spawn((
112-
Text2dBundle {
113-
transform: Transform::from_translation(Vec3::new(10.0, -10.0, 10.0)),
114-
text: Text::from_section("", text_style.clone())
115-
.with_justify(JustifyText::Left),
116-
text_anchor: bevy::sprite::Anchor::TopLeft,
117-
..default()
118-
},
112+
Transform::from_translation(Vec3::new(10.0, -10.0, 10.0)),
113+
Text2d("".into()),
114+
text_style,
115+
bevy::sprite::Anchor::TopLeft,
119116
StateDebugText,
120117
));
121118
});
@@ -183,7 +180,7 @@ fn handle_move_to(
183180
Some(_) => {
184181
if transform.translation.distance(destination) > 5.0 {
185182
let direction = (destination - transform.translation).normalize();
186-
transform.translation += direction * cell.speed * time.delta_seconds();
183+
transform.translation += direction * cell.speed * time.delta_secs();
187184
} else {
188185
commands.entity(entity).remove::<MoveTo>();
189186
// commands.entity(destination_entity).remove::<BusyObject>();
@@ -293,7 +290,7 @@ fn handle_replicate_action(
293290
timers.remove(&entity);
294291
planner.always_plan = true;
295292
} else {
296-
hunger.0 += 6.0 * time.delta_seconds_f64();
293+
hunger.0 += 6.0 * time.delta_secs_f64();
297294
}
298295
}
299296
None => {
@@ -364,7 +361,7 @@ fn over_time_needs_change(
364361
for (entity, mut hunger, transform) in query.iter_mut() {
365362
// Increase hunger
366363
let r = rng.gen_range(10.0..20.0);
367-
let val: f64 = r * time.delta_seconds_f64();
364+
let val: f64 = r * time.delta_secs_f64();
368365
hunger.0 += val;
369366
if hunger.0 > 100.0 {
370367
// hunger.0 = 100.0;
@@ -388,7 +385,8 @@ fn print_current_local_state(
388385
Option<&GoToFoodAction>,
389386
Option<&ReplicateAction>,
390387
)>,
391-
mut q_child: Query<&mut Text, With<StateDebugText>>,
388+
q_child: Query<Entity, With<StateDebugText>>,
389+
mut text_writer: Text2dWriter,
392390
) {
393391
// let planner = query.get_single().unwrap();
394392
for (entity, cell, hunger, children) in query.iter() {
@@ -416,8 +414,8 @@ fn print_current_local_state(
416414
}
417415

418416
for &child in children.iter() {
419-
let mut text = q_child.get_mut(child).unwrap();
420-
text.sections[0].value =
417+
let text = q_child.get(child).unwrap();
418+
*text_writer.text(text, 0) =
421419
format!("{current_action}\nAge: {age}\nHunger: {hunger:.0}\nEntity: {entity}");
422420
}
423421
}
@@ -433,7 +431,6 @@ fn draw_gizmos(
433431
gizmos
434432
.grid_2d(
435433
Vec2::ZERO,
436-
0.0,
437434
UVec2::new(16, 9),
438435
Vec2::new(80., 80.),
439436
// Dark gray

crates/bevy_dogoap/examples/miner.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn startup(mut commands: Commands, windows: Query<&Window>) {
204204
// Set current goal to be to acquire gold
205205
planner.current_goal = Some(gold_goal.clone());
206206

207-
let text_style = TextStyle {
207+
let text_style = TextFont {
208208
font_size: 18.0,
209209
..default()
210210
};
@@ -220,13 +220,10 @@ fn startup(mut commands: Commands, windows: Query<&Window>) {
220220
))
221221
.with_children(|subcommands| {
222222
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,
230227
NeedsText,
231228
));
232229
});
@@ -364,7 +361,7 @@ fn handle_go_to_house_action(
364361

365362
go_to_location::<GoToHouseAction>(
366363
&mut at_location,
367-
time.delta_seconds(),
364+
time.delta_secs(),
368365
&mut t_entity,
369366
t_house.translation,
370367
Location::House,
@@ -390,7 +387,7 @@ fn handle_go_to_smelter_action(
390387

391388
go_to_location::<GoToSmelterAction>(
392389
&mut at_location,
393-
time.delta_seconds(),
390+
time.delta_secs(),
394391
&mut t_entity,
395392
t_smelter.translation,
396393
Location::Smelter,
@@ -417,7 +414,7 @@ fn handle_go_to_outside_action(
417414

418415
go_to_location::<GoToOutsideAction>(
419416
&mut at_location,
420-
time.delta_seconds(),
417+
time.delta_secs(),
421418
&mut t_entity,
422419
new_pos,
423420
Location::Outside,
@@ -443,7 +440,7 @@ fn handle_go_to_merchant_action(
443440

444441
go_to_location::<GoToMerchantAction>(
445442
&mut at_location,
446-
time.delta_seconds(),
443+
time.delta_secs(),
447444
&mut t_entity,
448445
t_destination.translation,
449446
Location::Merchant,
@@ -474,7 +471,7 @@ fn handle_go_to_mushroom_action(
474471

475472
go_to_location::<GoToMushroomAction>(
476473
&mut at_location,
477-
time.delta_seconds(),
474+
time.delta_secs(),
478475
&mut t_entity,
479476
mushroom.1,
480477
Location::Mushroom,
@@ -503,7 +500,7 @@ fn handle_go_to_ore_action(
503500

504501
go_to_location::<GoToOreAction>(
505502
&mut at_location,
506-
time.delta_seconds(),
503+
time.delta_secs(),
507504
&mut t_entity,
508505
closest.1,
509506
Location::Ore,
@@ -581,7 +578,7 @@ fn handle_sleep_action(
581578
planner.always_plan = false;
582579

583580
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();
585582
energy.0 += val;
586583
if energy.0 >= 100.0 {
587584
commands.entity(entity).remove::<SleepAction>();
@@ -670,7 +667,7 @@ fn handle_mine_ore_action(
670667

671668
// Mining consumes energy!
672669
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();
674671
energy.0 -= val;
675672
// If we're running out of energy before finishing, stop mining for now
676673
if energy.0 <= 0.0 {
@@ -726,7 +723,7 @@ fn handle_smelt_ore_action(
726723
let mut rng = rand::thread_rng();
727724
// Smelting consumes even more energy!
728725
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();
730727
energy.0 -= val;
731728
if energy.0 <= 0.0 {
732729
commands.entity(entity).remove::<SmeltOreAction>();
@@ -778,15 +775,15 @@ fn over_time_needs_change(time: Res<Time>, mut query: Query<(&mut Hunger, &mut E
778775
for (mut hunger, mut energy) in query.iter_mut() {
779776
// Increase hunger
780777
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();
782779
hunger.0 += val;
783780
if hunger.0 > 100.0 {
784781
hunger.0 = 100.0;
785782
}
786783

787784
// Decrease energy
788785
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();
790787
energy.0 -= val;
791788
if energy.0 < 0.0 {
792789
energy.0 = 0.0;
@@ -818,7 +815,8 @@ fn print_current_local_state(
818815
Option<&GoToMerchantAction>,
819816
)>,
820817
// 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,
822820
) {
823821
for (entity, hunger, energy, has_ore, has_metal, gold_amount, children) in query.iter() {
824822
let hunger = hunger.0;
@@ -888,10 +886,9 @@ fn print_current_local_state(
888886
}
889887

890888
for &child in children.iter() {
891-
let mut text = q_child.get_mut(child).unwrap();
892-
text.sections[0].value = format!(
893-
"{current_action}\nGold: {gold_amount}\nHunger: {hunger:.0}\nEnergy: {energy:.0}\nHas Ore? {has_ore}\nHas Metal? {has_metal}"
894-
);
889+
let text = q_child.get(child).unwrap();
890+
*text_writer.text(text, 0) =
891+
format!("{current_action}\nGold: {gold_amount}\nHunger: {hunger:.0}\nEnergy: {energy:.0}\nHas Ore? {has_ore}\nHas Metal? {has_metal}");
895892
}
896893
}
897894
}
@@ -909,7 +906,6 @@ fn draw_gizmos(
909906
gizmos
910907
.grid_2d(
911908
Vec2::ZERO,
912-
0.0,
913909
UVec2::new(16, 9),
914910
Vec2::new(80., 80.),
915911
// Dark gray
@@ -923,14 +919,12 @@ fn draw_gizmos(
923919

924920
gizmos.rect_2d(
925921
q_house.get_single().unwrap().translation.truncate(),
926-
0.0,
927922
Vec2::new(40.0, 80.0),
928923
AQUAMARINE,
929924
);
930925

931926
gizmos.rect_2d(
932927
q_smelter.get_single().unwrap().translation.truncate(),
933-
0.0,
934928
Vec2::new(30.0, 30.0),
935929
YELLOW_GREEN,
936930
);

0 commit comments

Comments
 (0)