Rename "AddChild" to "PushChild" (#11194)
# Objective - Fixes #11187 ## Solution - Rename the `AddChild` struct to `PushChild` - Rename the `AddChildInPlace` struct to `PushChildInPlace` ## Migration Guide The struct `AddChild` has been renamed to `PushChild`, and the struct `AddChildInPlace` has been renamed to `PushChildInPlace`.
This commit is contained in:
parent
5511483408
commit
93c7e7cf4d
@ -161,14 +161,14 @@ fn clear_children(parent: Entity, world: &mut World) {
|
|||||||
|
|
||||||
/// Command that adds a child to an entity.
|
/// Command that adds a child to an entity.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AddChild {
|
pub struct PushChild {
|
||||||
/// Parent entity to add the child to.
|
/// Parent entity to add the child to.
|
||||||
pub parent: Entity,
|
pub parent: Entity,
|
||||||
/// Child entity to add.
|
/// Child entity to add.
|
||||||
pub child: Entity,
|
pub child: Entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Command for AddChild {
|
impl Command for PushChild {
|
||||||
fn apply(self, world: &mut World) {
|
fn apply(self, world: &mut World) {
|
||||||
world.entity_mut(self.parent).add_child(self.child);
|
world.entity_mut(self.parent).add_child(self.child);
|
||||||
}
|
}
|
||||||
@ -433,7 +433,7 @@ impl<'w, 's, 'a> BuildChildren for EntityCommands<'w, 's, 'a> {
|
|||||||
if child == parent {
|
if child == parent {
|
||||||
panic!("Cannot add entity as a child of itself.");
|
panic!("Cannot add entity as a child of itself.");
|
||||||
}
|
}
|
||||||
self.commands().add(AddChild { child, parent });
|
self.commands().add(PushChild { child, parent });
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,7 +460,7 @@ impl<'w, 's, 'a> BuildChildren for EntityCommands<'w, 's, 'a> {
|
|||||||
if child == parent {
|
if child == parent {
|
||||||
panic!("Cannot set parent to itself");
|
panic!("Cannot set parent to itself");
|
||||||
}
|
}
|
||||||
self.commands().add(AddChild { child, parent });
|
self.commands().add(PushChild { child, parent });
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use bevy_ecs::{reflect::AppTypeRegistry, system::Command, world::World};
|
use bevy_ecs::{reflect::AppTypeRegistry, system::Command, world::World};
|
||||||
use bevy_hierarchy::{AddChild, Parent};
|
use bevy_hierarchy::{Parent, PushChild};
|
||||||
use bevy_utils::EntityHashMap;
|
use bevy_utils::EntityHashMap;
|
||||||
|
|
||||||
use crate::dynamic_scene_builder::DynamicSceneBuilder;
|
use crate::dynamic_scene_builder::DynamicSceneBuilder;
|
||||||
@ -211,7 +211,7 @@ mod tests {
|
|||||||
.register::<Parent>();
|
.register::<Parent>();
|
||||||
let original_parent_entity = world.spawn_empty().id();
|
let original_parent_entity = world.spawn_empty().id();
|
||||||
let original_child_entity = world.spawn_empty().id();
|
let original_child_entity = world.spawn_empty().id();
|
||||||
AddChild {
|
PushChild {
|
||||||
parent: original_parent_entity,
|
parent: original_parent_entity,
|
||||||
child: original_child_entity,
|
child: original_child_entity,
|
||||||
}
|
}
|
||||||
@ -232,7 +232,7 @@ mod tests {
|
|||||||
// We then add the parent from the scene as a child of the original child
|
// We then add the parent from the scene as a child of the original child
|
||||||
// Hierarchy should look like:
|
// Hierarchy should look like:
|
||||||
// Original Parent <- Original Child <- Scene Parent <- Scene Child
|
// Original Parent <- Original Child <- Scene Parent <- Scene Child
|
||||||
AddChild {
|
PushChild {
|
||||||
parent: original_child_entity,
|
parent: original_child_entity,
|
||||||
child: from_scene_parent_entity,
|
child: from_scene_parent_entity,
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use bevy_ecs::{
|
|||||||
system::{Command, Resource},
|
system::{Command, Resource},
|
||||||
world::{Mut, World},
|
world::{Mut, World},
|
||||||
};
|
};
|
||||||
use bevy_hierarchy::{AddChild, Parent};
|
use bevy_hierarchy::{Parent, PushChild};
|
||||||
use bevy_utils::{tracing::error, EntityHashMap, HashMap, HashSet};
|
use bevy_utils::{tracing::error, EntityHashMap, HashMap, HashSet};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@ -348,7 +348,7 @@ impl SceneSpawner {
|
|||||||
// this case shouldn't happen anyway
|
// this case shouldn't happen anyway
|
||||||
.unwrap_or(true)
|
.unwrap_or(true)
|
||||||
{
|
{
|
||||||
AddChild {
|
PushChild {
|
||||||
parent,
|
parent,
|
||||||
child: entity,
|
child: entity,
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,24 @@
|
|||||||
//! while preserving [`GlobalTransform`].
|
//! while preserving [`GlobalTransform`].
|
||||||
|
|
||||||
use bevy_ecs::{prelude::Entity, system::Command, system::EntityCommands, world::World};
|
use bevy_ecs::{prelude::Entity, system::Command, system::EntityCommands, world::World};
|
||||||
use bevy_hierarchy::{AddChild, RemoveParent};
|
use bevy_hierarchy::{PushChild, RemoveParent};
|
||||||
|
|
||||||
use crate::{GlobalTransform, Transform};
|
use crate::{GlobalTransform, Transform};
|
||||||
|
|
||||||
/// Command similar to [`AddChild`], but updating the child transform to keep
|
/// Command similar to [`PushChild`], but updating the child transform to keep
|
||||||
/// it at the same [`GlobalTransform`].
|
/// it at the same [`GlobalTransform`].
|
||||||
///
|
///
|
||||||
/// You most likely want to use [`BuildChildrenTransformExt::set_parent_in_place`]
|
/// You most likely want to use [`BuildChildrenTransformExt::set_parent_in_place`]
|
||||||
/// method on [`EntityCommands`] instead.
|
/// method on [`EntityCommands`] instead.
|
||||||
pub struct AddChildInPlace {
|
pub struct PushChildInPlace {
|
||||||
/// Parent entity to add the child to.
|
/// Parent entity to add the child to.
|
||||||
pub parent: Entity,
|
pub parent: Entity,
|
||||||
/// Child entity to add.
|
/// Child entity to add.
|
||||||
pub child: Entity,
|
pub child: Entity,
|
||||||
}
|
}
|
||||||
impl Command for AddChildInPlace {
|
impl Command for PushChildInPlace {
|
||||||
fn apply(self, world: &mut World) {
|
fn apply(self, world: &mut World) {
|
||||||
let hierarchy_command = AddChild {
|
let hierarchy_command = PushChild {
|
||||||
child: self.child,
|
child: self.child,
|
||||||
parent: self.parent,
|
parent: self.parent,
|
||||||
};
|
};
|
||||||
@ -88,7 +88,7 @@ pub trait BuildChildrenTransformExt {
|
|||||||
impl<'w, 's, 'a> BuildChildrenTransformExt for EntityCommands<'w, 's, 'a> {
|
impl<'w, 's, 'a> BuildChildrenTransformExt for EntityCommands<'w, 's, 'a> {
|
||||||
fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self {
|
fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self {
|
||||||
let child = self.id();
|
let child = self.id();
|
||||||
self.commands().add(AddChildInPlace { child, parent });
|
self.commands().add(PushChildInPlace { child, parent });
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user