Add methods to add single entity relationships (#18038)
# Objective Closes #17572 ## Solution Add the `add_one_related` methods to `EntityCommands` and `EntityWorldMut`. ## Testing Clippy --- ## Showcase The `EntityWorldMut` and `FilteredResourcesMut` now include the `add_one_related` method if you just want to relate 2 entities.
This commit is contained in:
parent
5961df7c89
commit
b43c8f8c4f
@ -21,7 +21,9 @@ impl<'w> EntityWorldMut<'w> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Relates the given entities to this entity with the relation `R`
|
||||
/// Relates the given entities to this entity with the relation `R`.
|
||||
///
|
||||
/// See [`add_one_related`](Self::add_one_related) if you want relate only one entity.
|
||||
pub fn add_related<R: Relationship>(&mut self, related: &[Entity]) -> &mut Self {
|
||||
let id = self.id();
|
||||
self.world_scope(|world| {
|
||||
@ -32,6 +34,13 @@ impl<'w> EntityWorldMut<'w> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Relates the given entity to this with the relation `R`.
|
||||
///
|
||||
/// See [`add_related`](Self::add_related) if you want to relate more than one entity.
|
||||
pub fn add_one_related<R: Relationship>(&mut self, entity: Entity) -> &mut Self {
|
||||
self.add_related::<R>(&[entity])
|
||||
}
|
||||
|
||||
/// Despawns entities that relate to this one via the given [`RelationshipTarget`].
|
||||
/// This entity will not be despawned.
|
||||
pub fn despawn_related<S: RelationshipTarget>(&mut self) -> &mut Self {
|
||||
@ -108,7 +117,9 @@ impl<'a> EntityCommands<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Relates the given entities to this entity with the relation `R`
|
||||
/// Relates the given entities to this entity with the relation `R`.
|
||||
///
|
||||
/// See [`add_one_related`](Self::add_one_related) if you want relate only one entity.
|
||||
pub fn add_related<R: Relationship>(&mut self, related: &[Entity]) -> &mut Self {
|
||||
let id = self.id();
|
||||
let related = related.to_vec();
|
||||
@ -120,6 +131,13 @@ impl<'a> EntityCommands<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Relates the given entity to this with the relation `R`.
|
||||
///
|
||||
/// See [`add_related`](Self::add_related) if you want to relate more than one entity.
|
||||
pub fn add_one_related<R: Relationship>(&mut self, entity: Entity) -> &mut Self {
|
||||
self.add_related::<R>(&[entity])
|
||||
}
|
||||
|
||||
/// Despawns entities that relate to this one via the given [`RelationshipTarget`].
|
||||
/// This entity will not be despawned.
|
||||
pub fn despawn_related<S: RelationshipTarget>(&mut self) -> &mut Self {
|
||||
|
Loading…
Reference in New Issue
Block a user