Skip to content

Commit

Permalink
Merge pull request #4 from splashdust/bevy-15
Browse files Browse the repository at this point in the history
Upgrade to Bevy 0.15
  • Loading branch information
victorb authored Dec 23, 2024
2 parents b6da5e5 + 8e7b36d commit 23b87f2
Show file tree
Hide file tree
Showing 9 changed files with 943 additions and 510 deletions.
1,264 changes: 862 additions & 402 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions crates/bevy_dogoap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ default = ["compute-pool"]
compute-pool = []

[dependencies]
bevy = { version = "0.14.0", default-features = false, optional = false, features = ["wayland", "bevy_gizmos", "bevy_text", "multi_threaded", "default_font", "webgl2"]}
bevy-trait-query-0-14-0 = { version = "0.6.2" }
dogoap = { path = "../dogoap", version = "0.3.0"}
dogoap_macros = { path = "../dogoap_macros", version = "0.3.0"}
bevy = { version = "0.15", default-features = false, optional = false, features = [
"wayland",
"bevy_gizmos",
"bevy_text",
"multi_threaded",
"default_font",
"webgl2",
"bevy_window",
] }
bevy-trait-query = { version = "0.7.0" }
dogoap = { path = "../dogoap", version = "0.3.0" }
dogoap_macros = { path = "../dogoap_macros", version = "0.3.0" }
rand = "0.8.5"
27 changes: 12 additions & 15 deletions crates/bevy_dogoap/examples/cells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn spawn_cell(commands: &mut Commands, position: Vec3, speed: f32) {
planner.always_plan = true; // Re-calculate our plan whenever we can
planner.current_goal = Some(goal.clone());

let text_style = TextStyle {
let text_style = TextFont {
font_size: 12.0,
..default()
};
Expand All @@ -109,13 +109,10 @@ fn spawn_cell(commands: &mut Commands, position: Vec3, speed: f32) {
))
.with_children(|subcommands| {
subcommands.spawn((
Text2dBundle {
transform: Transform::from_translation(Vec3::new(10.0, -10.0, 10.0)),
text: Text::from_section("", text_style.clone())
.with_justify(JustifyText::Left),
text_anchor: bevy::sprite::Anchor::TopLeft,
..default()
},
Transform::from_translation(Vec3::new(10.0, -10.0, 10.0)),
Text2d("".into()),
text_style,
bevy::sprite::Anchor::TopLeft,
StateDebugText,
));
});
Expand Down Expand Up @@ -183,7 +180,7 @@ fn handle_move_to(
Some(_) => {
if transform.translation.distance(destination) > 5.0 {
let direction = (destination - transform.translation).normalize();
transform.translation += direction * cell.speed * time.delta_seconds();
transform.translation += direction * cell.speed * time.delta_secs();
} else {
commands.entity(entity).remove::<MoveTo>();
// commands.entity(destination_entity).remove::<BusyObject>();
Expand Down Expand Up @@ -293,7 +290,7 @@ fn handle_replicate_action(
timers.remove(&entity);
planner.always_plan = true;
} else {
hunger.0 += 6.0 * time.delta_seconds_f64();
hunger.0 += 6.0 * time.delta_secs_f64();
}
}
None => {
Expand Down Expand Up @@ -364,7 +361,7 @@ fn over_time_needs_change(
for (entity, mut hunger, transform) in query.iter_mut() {
// Increase hunger
let r = rng.gen_range(10.0..20.0);
let val: f64 = r * time.delta_seconds_f64();
let val: f64 = r * time.delta_secs_f64();
hunger.0 += val;
if hunger.0 > 100.0 {
// hunger.0 = 100.0;
Expand All @@ -388,7 +385,8 @@ fn print_current_local_state(
Option<&GoToFoodAction>,
Option<&ReplicateAction>,
)>,
mut q_child: Query<&mut Text, With<StateDebugText>>,
q_child: Query<Entity, With<StateDebugText>>,
mut text_writer: Text2dWriter,
) {
// let planner = query.get_single().unwrap();
for (entity, cell, hunger, children) in query.iter() {
Expand Down Expand Up @@ -416,8 +414,8 @@ fn print_current_local_state(
}

for &child in children.iter() {
let mut text = q_child.get_mut(child).unwrap();
text.sections[0].value =
let text = q_child.get(child).unwrap();
*text_writer.text(text, 0) =
format!("{current_action}\nAge: {age}\nHunger: {hunger:.0}\nEntity: {entity}");
}
}
Expand All @@ -433,7 +431,6 @@ fn draw_gizmos(
gizmos
.grid_2d(
Vec2::ZERO,
0.0,
UVec2::new(16, 9),
Vec2::new(80., 80.),
// Dark gray
Expand Down
48 changes: 21 additions & 27 deletions crates/bevy_dogoap/examples/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn startup(mut commands: Commands, windows: Query<&Window>) {
// Set current goal to be to acquire gold
planner.current_goal = Some(gold_goal.clone());

let text_style = TextStyle {
let text_style = TextFont {
font_size: 18.0,
..default()
};
Expand All @@ -220,13 +220,10 @@ fn startup(mut commands: Commands, windows: Query<&Window>) {
))
.with_children(|subcommands| {
subcommands.spawn((
Text2dBundle {
transform: Transform::from_translation(Vec3::new(10.0, -10.0, 10.0)),
text: Text::from_section("", text_style.clone())
.with_justify(JustifyText::Left),
text_anchor: bevy::sprite::Anchor::TopLeft,
..default()
},
Transform::from_translation(Vec3::new(10.0, -10.0, 10.0)),
Text2d("".into()),
text_style,
bevy::sprite::Anchor::TopLeft,
NeedsText,
));
});
Expand Down Expand Up @@ -364,7 +361,7 @@ fn handle_go_to_house_action(

go_to_location::<GoToHouseAction>(
&mut at_location,
time.delta_seconds(),
time.delta_secs(),
&mut t_entity,
t_house.translation,
Location::House,
Expand All @@ -390,7 +387,7 @@ fn handle_go_to_smelter_action(

go_to_location::<GoToSmelterAction>(
&mut at_location,
time.delta_seconds(),
time.delta_secs(),
&mut t_entity,
t_smelter.translation,
Location::Smelter,
Expand All @@ -417,7 +414,7 @@ fn handle_go_to_outside_action(

go_to_location::<GoToOutsideAction>(
&mut at_location,
time.delta_seconds(),
time.delta_secs(),
&mut t_entity,
new_pos,
Location::Outside,
Expand All @@ -443,7 +440,7 @@ fn handle_go_to_merchant_action(

go_to_location::<GoToMerchantAction>(
&mut at_location,
time.delta_seconds(),
time.delta_secs(),
&mut t_entity,
t_destination.translation,
Location::Merchant,
Expand Down Expand Up @@ -474,7 +471,7 @@ fn handle_go_to_mushroom_action(

go_to_location::<GoToMushroomAction>(
&mut at_location,
time.delta_seconds(),
time.delta_secs(),
&mut t_entity,
mushroom.1,
Location::Mushroom,
Expand Down Expand Up @@ -503,7 +500,7 @@ fn handle_go_to_ore_action(

go_to_location::<GoToOreAction>(
&mut at_location,
time.delta_seconds(),
time.delta_secs(),
&mut t_entity,
closest.1,
Location::Ore,
Expand Down Expand Up @@ -581,7 +578,7 @@ fn handle_sleep_action(
planner.always_plan = false;

let r = rng.gen_range(5.0..20.0);
let val: f64 = r * time.delta_seconds_f64();
let val: f64 = r * time.delta_secs_f64();
energy.0 += val;
if energy.0 >= 100.0 {
commands.entity(entity).remove::<SleepAction>();
Expand Down Expand Up @@ -670,7 +667,7 @@ fn handle_mine_ore_action(

// Mining consumes energy!
let r = rng.gen_range(5.0..10.0);
let val: f64 = r * time.delta_seconds_f64();
let val: f64 = r * time.delta_secs_f64();
energy.0 -= val;
// If we're running out of energy before finishing, stop mining for now
if energy.0 <= 0.0 {
Expand Down Expand Up @@ -726,7 +723,7 @@ fn handle_smelt_ore_action(
let mut rng = rand::thread_rng();
// Smelting consumes even more energy!
let r = rng.gen_range(10.0..15.0);
let val: f64 = r * time.delta_seconds_f64();
let val: f64 = r * time.delta_secs_f64();
energy.0 -= val;
if energy.0 <= 0.0 {
commands.entity(entity).remove::<SmeltOreAction>();
Expand Down Expand Up @@ -778,15 +775,15 @@ fn over_time_needs_change(time: Res<Time>, mut query: Query<(&mut Hunger, &mut E
for (mut hunger, mut energy) in query.iter_mut() {
// Increase hunger
let r = rng.gen_range(10.0..20.0);
let val: f64 = r * time.delta_seconds_f64();
let val: f64 = r * time.delta_secs_f64();
hunger.0 += val;
if hunger.0 > 100.0 {
hunger.0 = 100.0;
}

// Decrease energy
let r = rng.gen_range(1.0..10.0);
let val: f64 = r * time.delta_seconds_f64();
let val: f64 = r * time.delta_secs_f64();
energy.0 -= val;
if energy.0 < 0.0 {
energy.0 = 0.0;
Expand Down Expand Up @@ -818,7 +815,8 @@ fn print_current_local_state(
Option<&GoToMerchantAction>,
)>,
// action_query: Query<&dyn ActionComponent>,
mut q_child: Query<&mut Text, With<NeedsText>>,
q_child: Query<Entity, With<NeedsText>>,
mut text_writer: Text2dWriter,
) {
for (entity, hunger, energy, has_ore, has_metal, gold_amount, children) in query.iter() {
let hunger = hunger.0;
Expand Down Expand Up @@ -888,10 +886,9 @@ fn print_current_local_state(
}

for &child in children.iter() {
let mut text = q_child.get_mut(child).unwrap();
text.sections[0].value = format!(
"{current_action}\nGold: {gold_amount}\nHunger: {hunger:.0}\nEnergy: {energy:.0}\nHas Ore? {has_ore}\nHas Metal? {has_metal}"
);
let text = q_child.get(child).unwrap();
*text_writer.text(text, 0) =
format!("{current_action}\nGold: {gold_amount}\nHunger: {hunger:.0}\nEnergy: {energy:.0}\nHas Ore? {has_ore}\nHas Metal? {has_metal}");
}
}
}
Expand All @@ -909,7 +906,6 @@ fn draw_gizmos(
gizmos
.grid_2d(
Vec2::ZERO,
0.0,
UVec2::new(16, 9),
Vec2::new(80., 80.),
// Dark gray
Expand All @@ -923,14 +919,12 @@ fn draw_gizmos(

gizmos.rect_2d(
q_house.get_single().unwrap().translation.truncate(),
0.0,
Vec2::new(40.0, 80.0),
AQUAMARINE,
);

gizmos.rect_2d(
q_smelter.get_single().unwrap().translation.truncate(),
0.0,
Vec2::new(30.0, 30.0),
YELLOW_GREEN,
);
Expand Down
Loading

0 comments on commit 23b87f2

Please sign in to comment.