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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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