Upgrade to Bevy 0.13.

This commit is contained in:
Nolan Darilek 2024-03-14 13:37:46 -05:00
parent 4e0a36c4a5
commit d0c4f5b29b
8 changed files with 96 additions and 101 deletions

View File

@ -13,7 +13,7 @@ speech_dispatcher_0_10 = ["bevy_tts/speech_dispatcher_0_10"]
speech_dispatcher_0_11 = ["bevy_tts/speech_dispatcher_0_11"] speech_dispatcher_0_11 = ["bevy_tts/speech_dispatcher_0_11"]
[dependencies.bevy] [dependencies.bevy]
version = "0.12" version = "0.13"
default-features = false default-features = false
features = [ features = [
"bevy_gilrs", "bevy_gilrs",
@ -25,13 +25,12 @@ features = [
] ]
[dependencies] [dependencies]
bevy_rapier2d = "0.24" bevy_rapier2d = "0.25"
bevy_synthizer = "0.5" bevy_synthizer = "0.6"
bevy_tts = { version = "0.7", default-features = false, features = ["tolk"] } bevy_tts = { version = "0.8", default-features = false, features = ["tolk"] }
coord_2d = "0.3" coord_2d = "0.3"
futures-lite = "1"
here_be_dragons = { version = "0.3", features = ["serde"] } here_be_dragons = { version = "0.3", features = ["serde"] }
leafwing-input-manager = "0.11" leafwing-input-manager = "0.13"
maze_generator = "2" maze_generator = "2"
once_cell = "1" once_cell = "1"
pathfinding = "4" pathfinding = "4"

View File

@ -630,7 +630,7 @@ where
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
let mut rng = thread_rng(); let mut rng = thread_rng();
self.0.shuffle(&mut rng); self.0.shuffle(&mut rng);
self.0.get(0).cloned() self.0.first().cloned()
} }
} }

View File

@ -72,7 +72,7 @@ where
types.dedup(); types.dedup();
if types.is_empty() { if types.is_empty() {
tts.speak("Nothing visible.", true)?; tts.speak("Nothing visible.", true)?;
} else if actions.just_pressed(ExplorationAction::SelectPrevType) { } else if actions.just_pressed(&ExplorationAction::SelectPrevType) {
if let Some(t) = &focused.0 { if let Some(t) = &focused.0 {
if let Some(i) = types.iter().position(|v| *v == *t) { if let Some(i) = types.iter().position(|v| *v == *t) {
if i == 0 { if i == 0 {
@ -89,7 +89,7 @@ where
let t = types.last().unwrap(); let t = types.last().unwrap();
focused.0 = Some(*t); focused.0 = Some(*t);
} }
} else if actions.just_pressed(ExplorationAction::SelectNextType) { } else if actions.just_pressed(&ExplorationAction::SelectNextType) {
if let Some(t) = &focused.0 { if let Some(t) = &focused.0 {
if let Some(i) = types.iter().position(|v| *v == *t) { if let Some(i) = types.iter().position(|v| *v == *t) {
if i == types.len() - 1 { if i == types.len() - 1 {
@ -141,7 +141,7 @@ where
features.retain(|(_, t)| **t == *focused); features.retain(|(_, t)| **t == *focused);
} }
let mut target: Option<&((f32, f32), &ExplorationType)> = None; let mut target: Option<&((f32, f32), &ExplorationType)> = None;
if actions.just_pressed(ExplorationAction::FocusNext) { if actions.just_pressed(&ExplorationAction::FocusNext) {
if let Some(exploring) = exploring { if let Some(exploring) = exploring {
target = features.iter().find(|(c, _)| *c > **exploring); target = features.iter().find(|(c, _)| *c > **exploring);
if target.is_none() { if target.is_none() {
@ -150,7 +150,7 @@ where
} else { } else {
target = features.first(); target = features.first();
} }
} else if actions.just_pressed(ExplorationAction::FocusPrev) { } else if actions.just_pressed(&ExplorationAction::FocusPrev) {
if let Some(exploring) = exploring { if let Some(exploring) = exploring {
features.reverse(); features.reverse();
target = features.iter().find(|(c, _)| *c < **exploring); target = features.iter().find(|(c, _)| *c < **exploring);
@ -224,13 +224,13 @@ fn exploration_focus<MapData>(
(floor.x, floor.y) (floor.x, floor.y)
}; };
let orig = exploring; let orig = exploring;
if actions.just_pressed(ExplorationAction::Forward) { if actions.just_pressed(&ExplorationAction::Forward) {
exploring.1 += 1.; exploring.1 += 1.;
} else if actions.just_pressed(ExplorationAction::Backward) { } else if actions.just_pressed(&ExplorationAction::Backward) {
exploring.1 -= 1.; exploring.1 -= 1.;
} else if actions.just_pressed(ExplorationAction::Left) { } else if actions.just_pressed(&ExplorationAction::Left) {
exploring.0 -= 1.; exploring.0 -= 1.;
} else if actions.just_pressed(ExplorationAction::Right) { } else if actions.just_pressed(&ExplorationAction::Right) {
exploring.0 += 1.; exploring.0 += 1.;
} }
let dimensions = if let Ok(map) = map.get_single() { let dimensions = if let Ok(map) = map.get_single() {
@ -261,7 +261,7 @@ fn navigate_to_explored<MapData>(
let point = **exploring; let point = **exploring;
let idx = point.to_index(map.width); let idx = point.to_index(map.width);
let known = revealed_tiles[idx]; let known = revealed_tiles[idx];
if actions.just_pressed(ExplorationAction::NavigateTo) && known { if actions.just_pressed(&ExplorationAction::NavigateTo) && known {
commands commands
.entity(entity) .entity(entity)
.insert(Destination((point.x_i32(), point.y_i32()))); .insert(Destination((point.x_i32(), point.y_i32())));

View File

@ -11,7 +11,6 @@ pub use coord_2d;
pub mod core; pub mod core;
pub mod error; pub mod error;
pub mod exploration; pub mod exploration;
pub use futures_lite;
pub use here_be_dragons as mapgen; pub use here_be_dragons as mapgen;
pub use leafwing_input_manager; pub use leafwing_input_manager;
pub mod log; pub mod log;

View File

@ -98,7 +98,7 @@ fn snap(
for (entity, actions, mut transform, direction) in &mut query { for (entity, actions, mut transform, direction) in &mut query {
if snap_timers.contains_key(&entity) { if snap_timers.contains_key(&entity) {
continue; continue;
} else if actions.just_pressed(NavigationAction::SnapLeft) { } else if actions.just_pressed(&NavigationAction::SnapLeft) {
snap_timers.insert(entity, SnapTimer::default()); snap_timers.insert(entity, SnapTimer::default());
transform.rotation = Quat::from_rotation_z(match direction { transform.rotation = Quat::from_rotation_z(match direction {
CardinalDirection::North => PI, CardinalDirection::North => PI,
@ -106,7 +106,7 @@ fn snap(
CardinalDirection::South => 0., CardinalDirection::South => 0.,
CardinalDirection::West => -PI / 2., CardinalDirection::West => -PI / 2.,
}); });
} else if actions.just_pressed(NavigationAction::SnapRight) { } else if actions.just_pressed(&NavigationAction::SnapRight) {
snap_timers.insert(entity, SnapTimer::default()); snap_timers.insert(entity, SnapTimer::default());
transform.rotation = Quat::from_rotation_z(match direction { transform.rotation = Quat::from_rotation_z(match direction {
CardinalDirection::North => 0., CardinalDirection::North => 0.,
@ -114,10 +114,10 @@ fn snap(
CardinalDirection::South => PI, CardinalDirection::South => PI,
CardinalDirection::West => PI / 2., CardinalDirection::West => PI / 2.,
}); });
} else if actions.just_pressed(NavigationAction::SnapReverse) { } else if actions.just_pressed(&NavigationAction::SnapReverse) {
snap_timers.insert(entity, SnapTimer::default()); snap_timers.insert(entity, SnapTimer::default());
transform.rotate(Quat::from_rotation_z(PI)); transform.rotate(Quat::from_rotation_z(PI));
} else if actions.just_pressed(NavigationAction::SnapCardinal) { } else if actions.just_pressed(&NavigationAction::SnapCardinal) {
let yaw: Angle = direction.into(); let yaw: Angle = direction.into();
let yaw = yaw.radians(); let yaw = yaw.radians();
transform.rotation = Quat::from_rotation_z(yaw); transform.rotation = Quat::from_rotation_z(yaw);
@ -166,8 +166,8 @@ fn controls(
) in &mut query ) in &mut query
{ {
let mut cleanup = false; let mut cleanup = false;
if actions.pressed(NavigationAction::Move) { if actions.pressed(&NavigationAction::Move) {
if let Some(pair) = actions.clamped_axis_pair(NavigationAction::Move) { if let Some(pair) = actions.clamped_axis_pair(&NavigationAction::Move) {
cleanup = true; cleanup = true;
let mut direction = pair.xy(); let mut direction = pair.xy();
let forward_movement_factor = let forward_movement_factor =
@ -201,77 +201,84 @@ fn controls(
let velocity = direction * speed; let velocity = direction * speed;
if character_controller.is_some() { if character_controller.is_some() {
let translation = velocity * time.delta_seconds(); let translation = velocity * time.delta_seconds();
actions.press(NavigationAction::Translate); actions.press(&NavigationAction::Translate);
actions if let Some(data) = actions.action_data_mut(&NavigationAction::Translate) {
.action_data_mut(NavigationAction::Translate) data.axis_pair = Some(DualAxisData::from_xy(translation));
.axis_pair = Some(DualAxisData::from_xy(translation)); }
} else { } else {
// println!("{entity:?}: SetLinearVelocity: {velocity:?}"); // println!("{entity:?}: SetLinearVelocity: {velocity:?}");
actions.press(NavigationAction::SetLinearVelocity); actions.press(&NavigationAction::SetLinearVelocity);
actions if let Some(data) =
.action_data_mut(NavigationAction::SetLinearVelocity) actions.action_data_mut(&NavigationAction::SetLinearVelocity)
.axis_pair = Some(DualAxisData::from_xy(velocity)); {
data.axis_pair = Some(DualAxisData::from_xy(velocity));
} }
} }
} else if actions.just_released(NavigationAction::Move) { }
} else if actions.just_released(&NavigationAction::Move) {
trace!("{entity:?}: Stopped moving"); trace!("{entity:?}: Stopped moving");
actions.release(NavigationAction::SetLinearVelocity); actions.release(&NavigationAction::SetLinearVelocity);
actions.release(NavigationAction::Translate); actions.release(&NavigationAction::Translate);
actions.action_data_mut(NavigationAction::Move).axis_pair = if let Some(data) = actions.action_data_mut(&NavigationAction::Move) {
Some(DualAxisData::from_xy(Vec2::ZERO)); data.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
} }
if actions.pressed(NavigationAction::SetLinearVelocity) { }
if let Some(pair) = actions.axis_pair(NavigationAction::SetLinearVelocity) { if actions.pressed(&NavigationAction::SetLinearVelocity) {
if let Some(pair) = actions.axis_pair(&NavigationAction::SetLinearVelocity) {
// println!("{entity:?}: SetLinearVelocity: {pair:?}"); // println!("{entity:?}: SetLinearVelocity: {pair:?}");
velocity.linvel = pair.into(); velocity.linvel = pair.into();
} else { } else {
// println!("{entity:?}: SetLinearVelocity: 0"); // println!("{entity:?}: SetLinearVelocity: 0");
velocity.linvel = Vec2::ZERO; velocity.linvel = Vec2::ZERO;
} }
} else if actions.just_released(NavigationAction::SetLinearVelocity) { } else if actions.just_released(&NavigationAction::SetLinearVelocity) {
// println!("{entity:?}: Released velocity"); // println!("{entity:?}: Released velocity");
velocity.linvel = Vec2::ZERO; velocity.linvel = Vec2::ZERO;
actions if let Some(data) = actions.action_data_mut(&NavigationAction::SetLinearVelocity) {
.action_data_mut(NavigationAction::SetLinearVelocity) data.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
} }
if actions.pressed(NavigationAction::Translate) { }
if let Some(pair) = actions.axis_pair(NavigationAction::Translate) { if actions.pressed(&NavigationAction::Translate) {
if let Some(pair) = actions.axis_pair(&NavigationAction::Translate) {
if let Some(mut character_controller) = character_controller { if let Some(mut character_controller) = character_controller {
character_controller.translation = Some(pair.xy()); character_controller.translation = Some(pair.xy());
} }
} }
} else if actions.just_released(NavigationAction::Translate) { } else if actions.just_released(&NavigationAction::Translate) {
if let Some(mut character_controller) = character_controller { if let Some(mut character_controller) = character_controller {
character_controller.translation = None; character_controller.translation = None;
} }
actions if let Some(data) = actions.action_data_mut(&NavigationAction::Translate) {
.action_data_mut(NavigationAction::Translate) data.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO)); }
} }
if !snap_timers.contains_key(&entity) { if !snap_timers.contains_key(&entity) {
if let Some(rotation_speed) = rotation_speed { if let Some(rotation_speed) = rotation_speed {
if actions.pressed(NavigationAction::Rotate) { if actions.pressed(&NavigationAction::Rotate) {
cleanup = true; cleanup = true;
let delta = let delta = -rotation_speed.radians()
-rotation_speed.radians() * actions.clamped_value(NavigationAction::Rotate); * actions.clamped_value(&NavigationAction::Rotate);
actions.press(NavigationAction::SetAngularVelocity); actions.press(&NavigationAction::SetAngularVelocity);
actions if let Some(data) =
.action_data_mut(NavigationAction::SetAngularVelocity) actions.action_data_mut(&NavigationAction::SetAngularVelocity)
.value = delta; {
data.value = delta;
} }
} }
} }
if actions.just_released(NavigationAction::Rotate) {
actions.release(NavigationAction::SetAngularVelocity);
actions.action_data_mut(NavigationAction::Rotate).value = 0.;
} }
if actions.pressed(NavigationAction::SetAngularVelocity) { if actions.just_released(&NavigationAction::Rotate) {
velocity.angvel = actions.value(NavigationAction::SetAngularVelocity); actions.release(&NavigationAction::SetAngularVelocity);
} else if actions.just_released(NavigationAction::SetAngularVelocity) { if let Some(data) = actions.action_data_mut(&NavigationAction::Rotate) {
actions data.value = 0.;
.action_data_mut(NavigationAction::SetAngularVelocity) }
.value = 0.; }
if actions.pressed(&NavigationAction::SetAngularVelocity) {
velocity.angvel = actions.value(&NavigationAction::SetAngularVelocity);
} else if actions.just_released(&NavigationAction::SetAngularVelocity) {
if let Some(data) = actions.action_data_mut(&NavigationAction::SetAngularVelocity) {
data.value = 0.;
}
velocity.angvel = 0.; velocity.angvel = 0.;
} }
if cleanup { if cleanup {

View File

@ -1,7 +1,7 @@
use bevy::{ use bevy::{
ecs::entity::Entities, ecs::entity::Entities,
prelude::*, prelude::*,
tasks::{prelude::*, Task}, tasks::{futures_lite::future, prelude::*, Task},
utils::HashMap, utils::HashMap,
}; };
use bevy_rapier2d::{ use bevy_rapier2d::{
@ -9,7 +9,6 @@ use bevy_rapier2d::{
prelude::*, prelude::*,
rapier::prelude::{ColliderHandle, ColliderSet, QueryPipeline, RigidBodySet}, rapier::prelude::{ColliderHandle, ColliderSet, QueryPipeline, RigidBodySet},
}; };
use futures_lite::future;
use leafwing_input_manager::{axislike::DualAxisData, plugin::InputManagerSystem, prelude::*}; use leafwing_input_manager::{axislike::DualAxisData, plugin::InputManagerSystem, prelude::*};
use pathfinding::prelude::*; use pathfinding::prelude::*;
@ -22,23 +21,7 @@ use crate::{
#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)] #[derive(PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)]
pub struct NegotiatePathAction; pub struct NegotiatePathAction;
impl Actionlike for NegotiatePathAction { impl Actionlike for NegotiatePathAction {}
fn n_variants() -> usize {
1
}
fn get_at(index: usize) -> Option<Self> {
if index == 0 {
Some(Self)
} else {
None
}
}
fn index(&self) -> usize {
0
}
}
#[derive(Component, Debug, Deref, DerefMut)] #[derive(Component, Debug, Deref, DerefMut)]
struct Calculating(Task<Option<Path>>); struct Calculating(Task<Option<Path>>);
@ -338,9 +321,10 @@ fn negotiate_path(
continue; continue;
} }
trace!("{entity:?}: path: direction: {direction:?}"); trace!("{entity:?}: path: direction: {direction:?}");
actions.press(NavigationAction::Move); actions.press(&NavigationAction::Move);
actions.action_data_mut(NavigationAction::Move).axis_pair = if let Some(data) = actions.action_data_mut(&NavigationAction::Move) {
Some(DualAxisData::from_xy(Vec2::new(-direction.y, direction.x))); data.axis_pair = Some(DualAxisData::from_xy(Vec2::new(-direction.y, direction.x)));
}
if rotation_speed.is_some() { if rotation_speed.is_some() {
let angle = direction.y.atan2(direction.x); let angle = direction.y.atan2(direction.x);
transform.rotation = Quat::from_rotation_z(angle); transform.rotation = Quat::from_rotation_z(angle);
@ -352,7 +336,7 @@ fn negotiate_path(
.remove::<Path>() .remove::<Path>()
.remove::<NoPath>() .remove::<NoPath>()
.remove::<Destination>(); .remove::<Destination>();
actions.release(NavigationAction::Move); actions.release(&NavigationAction::Move);
trace!("{entity:?}: pathfinding: cleaned up"); trace!("{entity:?}: pathfinding: cleaned up");
} }
} }
@ -368,25 +352,29 @@ fn actions(
)>, )>,
) { ) {
for (entity, mut actions, mut navigation_action, destination) in &mut query { for (entity, mut actions, mut navigation_action, destination) in &mut query {
if actions.pressed(NegotiatePathAction) { if actions.pressed(&NegotiatePathAction) {
if let Some(pair) = actions.axis_pair(NegotiatePathAction) { if let Some(pair) = actions.axis_pair(&NegotiatePathAction) {
trace!("Negotiating path to {pair:?}"); trace!("Negotiating path to {pair:?}");
let dest = Destination((pair.x() as i32, pair.y() as i32)); let dest = Destination((pair.x() as i32, pair.y() as i32));
if let Some(mut current_dest) = destination { if let Some(mut current_dest) = destination {
if *current_dest != dest { if *current_dest != dest {
trace!("{entity:?}: New destination, zeroing velocity"); trace!("{entity:?}: New destination, zeroing velocity");
navigation_action.press(NavigationAction::SetLinearVelocity); navigation_action.press(&NavigationAction::SetLinearVelocity);
navigation_action if let Some(data) =
.action_data_mut(NavigationAction::SetLinearVelocity) navigation_action.action_data_mut(&NavigationAction::SetLinearVelocity)
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO)); {
data.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
}
*current_dest = dest; *current_dest = dest;
} }
} else { } else {
trace!("{entity:?}: Adding destination, zeroing velocity"); trace!("{entity:?}: Adding destination, zeroing velocity");
navigation_action.press(NavigationAction::SetLinearVelocity); navigation_action.press(&NavigationAction::SetLinearVelocity);
navigation_action if let Some(data) =
.action_data_mut(NavigationAction::SetLinearVelocity) navigation_action.action_data_mut(&NavigationAction::SetLinearVelocity)
.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO)); {
data.axis_pair = Some(DualAxisData::from_xy(Vec2::ZERO));
}
commands.entity(entity).insert(dest); commands.entity(entity).insert(dest);
} }
} else if destination.is_some() { } else if destination.is_some() {
@ -395,8 +383,10 @@ fn actions(
.remove::<Destination>() .remove::<Destination>()
.remove::<NoPath>(); .remove::<NoPath>();
} }
actions.release(NegotiatePathAction); actions.release(&NegotiatePathAction);
actions.action_data_mut(NegotiatePathAction).axis_pair = None; if let Some(data) = actions.action_data_mut(&NegotiatePathAction) {
data.axis_pair = None;
}
} }
} }
} }

View File

@ -79,7 +79,7 @@ fn update<S>(
if interval.finished() { if interval.finished() {
interval.reset(); interval.reset();
continue; continue;
} else if interval.percent() == 0. { } else if interval.fraction() == 0. {
sound.generator = None; sound.generator = None;
} }
interval.tick(time.delta()); interval.tick(time.delta());

View File

@ -273,7 +273,7 @@ fn viewshed_removed(
events.send(VisibilityChanged::Lost { events.send(VisibilityChanged::Lost {
viewer: entity, viewer: entity,
viewed: *e, viewed: *e,
}) });
} }
} }
} }