From 865bdc333c03cd414b2428652632ad358f05abf2 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sat, 1 Apr 2023 07:20:59 -0500 Subject: [PATCH] Remove commands hack. --- README.md | 4 +--- src/commands.rs | 22 ---------------------- src/lib.rs | 1 - src/navigation.rs | 5 +---- src/pathfinding.rs | 11 +++++------ src/sound/footstep.rs | 12 +++++------- src/sound/icon.rs | 17 +++++++---------- src/sound/pitch_shift.rs | 13 +++---------- src/sound/volumetric.rs | 6 ++---- 9 files changed, 24 insertions(+), 67 deletions(-) delete mode 100644 src/commands.rs diff --git a/README.md b/README.md index 46fde7c..6ab6996 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ _Blackout_ uses a few other libraries for its magic: It provides, including but not limited to: -* commands - * `RunIfExists` extension for only running a given command if its entity exists * core * `PointLike` trait for distance and other calculations between `Coordinates` and `Coordinates`-like things (I.e. `(f32, f32)`, `(i32, i32)`, ...) * `Angle` type for handling angles in degrees/radians @@ -49,4 +47,4 @@ It provides, including but not limited to: * utils * Poorly-named `target_and_other` function for taking 2 entities, a predecate, and returning `Some((match, other))` if one matches or `None` if neither do. Good for, say, taking in a collision pair and returning a bullet entity first * error - * Logger for logging errors in systems + * Logger for logging piped errors in systems diff --git a/src/commands.rs b/src/commands.rs deleted file mode 100644 index 129f4c6..0000000 --- a/src/commands.rs +++ /dev/null @@ -1,22 +0,0 @@ -use bevy::{ - ecs::{system::Command, world::EntityMut}, - prelude::*, -}; - -struct RunIfExistsCommand(Entity, F); - -impl Command for RunIfExistsCommand { - fn write(self, world: &mut World) { - world.get_entity_mut(self.0).map(self.1); - } -} - -pub trait RunIfExistsExt { - fn run_if_exists(&mut self, entity: Entity, f: impl FnOnce(EntityMut) + Send + Sync + 'static); -} - -impl RunIfExistsExt for Commands<'_, '_> { - fn run_if_exists(&mut self, entity: Entity, f: impl FnOnce(EntityMut) + Send + Sync + 'static) { - self.add(RunIfExistsCommand(entity, f)); - } -} diff --git a/src/lib.rs b/src/lib.rs index 60271ca..b84203a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,6 @@ pub use bevy; pub use bevy_rapier2d; pub use bevy_synthizer; pub use bevy_tts; -pub mod commands; pub use coord_2d; #[macro_use] pub mod core; diff --git a/src/navigation.rs b/src/navigation.rs index 293f9dd..10f349e 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -6,7 +6,6 @@ use bevy_tts::Tts; use leafwing_input_manager::{axislike::DualAxisData, prelude::*}; use crate::{ - commands::RunIfExistsExt, core::{Angle, Area, CardinalDirection, GlobalTransformExt, Player}, error::error_handler, exploration::{ExplorationFocused, Exploring}, @@ -309,9 +308,7 @@ fn remove_direction( ) { for entity in &mut removed { if directions.contains(entity) { - commands.run_if_exists(entity, |mut entity| { - entity.remove::(); - }); + commands.entity(entity).remove::(); } } } diff --git a/src/pathfinding.rs b/src/pathfinding.rs index f324451..3b666db 100644 --- a/src/pathfinding.rs +++ b/src/pathfinding.rs @@ -14,7 +14,6 @@ use leafwing_input_manager::{axislike::DualAxisData, plugin::InputManagerSystem, use pathfinding::prelude::*; use crate::{ - commands::RunIfExistsExt, core::{PointLike, TransformExt}, map::{Map, MapObstruction}, navigation::{NavigationAction, RotationSpeed}, @@ -235,11 +234,11 @@ fn calculate_path( shape_clone, ) }); - commands.run_if_exists(entity, |mut entity| { - entity.insert(Calculating(task)); - entity.remove::(); - entity.remove::(); - }); + commands + .entity(entity) + .insert(Calculating(task)) + .remove::() + .remove::(); } } diff --git a/src/sound/footstep.rs b/src/sound/footstep.rs index b105ac6..605eea6 100644 --- a/src/sound/footstep.rs +++ b/src/sound/footstep.rs @@ -4,7 +4,7 @@ use bevy::{prelude::*, transform::TransformSystem}; use bevy_synthizer::{Buffer, Sound}; use rand::random; -use crate::{commands::RunIfExistsExt, core::PointLike}; +use crate::core::PointLike; #[derive(Component, Clone, Debug, Reflect)] #[reflect(Component)] @@ -31,12 +31,10 @@ impl Default for Footstep { fn added(mut commands: Commands, footsteps: Query<(Entity, &Footstep), Added>) { for (entity, footstep) in &footsteps { let buffer = footstep.buffer.clone(); - commands.run_if_exists(entity, move |mut entity| { - entity.insert(Sound { - audio: buffer.into(), - paused: true, - ..default() - }); + commands.entity(entity).insert(Sound { + audio: buffer.into(), + paused: true, + ..default() }); } } diff --git a/src/sound/icon.rs b/src/sound/icon.rs index 88fdcde..96355d7 100644 --- a/src/sound/icon.rs +++ b/src/sound/icon.rs @@ -6,7 +6,6 @@ use bevy_synthizer::{Audio, Buffer, Sound}; use rand::random; use crate::{ - commands::RunIfExistsExt, core::Player, exploration::ExplorationFocused, visibility::{VisibilityChanged, Visible, VisibleEntities}, @@ -44,15 +43,13 @@ fn added(mut commands: Commands, icons: Query<(Entity, &SoundIcon), Added(); - }); + commands.entity(entity).remove::(); } } } } else { for entity in &behind { - commands.run_if_exists(entity, |mut entity| { - entity.remove::(); - }); + commands.entity(entity).remove::(); } } } diff --git a/src/sound/volumetric.rs b/src/sound/volumetric.rs index 35361d5..b979cbe 100644 --- a/src/sound/volumetric.rs +++ b/src/sound/volumetric.rs @@ -2,7 +2,7 @@ use bevy::{prelude::*, transform::TransformSystem}; use bevy_rapier2d::{parry::query::ClosestPoints, prelude::*}; use bevy_synthizer::{Listener, Sound}; -use crate::{commands::RunIfExistsExt, core::GlobalTransformExt}; +use crate::core::GlobalTransformExt; #[derive(Component, Default, Reflect, Clone, Copy, Debug)] #[reflect(Component)] @@ -41,9 +41,7 @@ fn update( fn removed(mut commands: Commands, mut removed: RemovedComponents) { for entity in &mut removed { - commands.run_if_exists(entity, |mut entity| { - entity.insert(TransformBundle::default()); - }); + commands.entity(entity).insert(TransformBundle::default()); } }