This commit is contained in:
parent
cbad1648e8
commit
865bdc333c
|
@ -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
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
use bevy::{
|
||||
ecs::{system::Command, world::EntityMut},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
struct RunIfExistsCommand<F>(Entity, F);
|
||||
|
||||
impl<F: FnOnce(EntityMut) + Send + Sync + 'static> Command for RunIfExistsCommand<F> {
|
||||
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));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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::<CardinalDirection>();
|
||||
});
|
||||
commands.entity(entity).remove::<CardinalDirection>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<Path>();
|
||||
entity.remove::<NoPath>();
|
||||
});
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(Calculating(task))
|
||||
.remove::<Path>()
|
||||
.remove::<NoPath>();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Footstep>>) {
|
||||
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()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SoundI
|
|||
let gain = icon.gain;
|
||||
let pitch = icon.pitch;
|
||||
let looping = icon.interval.is_none();
|
||||
commands.run_if_exists(entity, move |mut entity| {
|
||||
entity.insert(Sound {
|
||||
audio: buffer.into(),
|
||||
gain,
|
||||
pitch,
|
||||
looping,
|
||||
paused: true,
|
||||
..default()
|
||||
});
|
||||
commands.entity(entity).insert(Sound {
|
||||
audio: buffer.into(),
|
||||
gain,
|
||||
pitch,
|
||||
looping,
|
||||
paused: true,
|
||||
..default()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ use bevy::prelude::*;
|
|||
|
||||
use crate::{
|
||||
bevy_synthizer::{Listener, Sound},
|
||||
commands::RunIfExistsExt,
|
||||
sound::SoundIcon,
|
||||
};
|
||||
|
||||
|
@ -30,21 +29,15 @@ fn tag_behind(
|
|||
let dot = v.dot(listener_forward);
|
||||
let is_behind = dot <= 0.;
|
||||
if is_behind {
|
||||
commands.run_if_exists(entity, |mut entity| {
|
||||
entity.insert(Behind);
|
||||
});
|
||||
commands.entity(entity).insert(Behind);
|
||||
} else if !is_behind {
|
||||
commands.run_if_exists(entity, |mut entity| {
|
||||
entity.remove::<Behind>();
|
||||
});
|
||||
commands.entity(entity).remove::<Behind>();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for entity in &behind {
|
||||
commands.run_if_exists(entity, |mut entity| {
|
||||
entity.remove::<Behind>();
|
||||
});
|
||||
commands.entity(entity).remove::<Behind>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Volumetric>) {
|
||||
for entity in &mut removed {
|
||||
commands.run_if_exists(entity, |mut entity| {
|
||||
entity.insert(TransformBundle::default());
|
||||
});
|
||||
commands.entity(entity).insert(TransformBundle::default());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user