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:
Chia-Hsiang Cheng 2024-01-05 00:06:14 +08:00 committed by GitHub
parent 5511483408
commit 93c7e7cf4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 15 deletions

View File

@ -161,14 +161,14 @@ fn clear_children(parent: Entity, world: &mut World) {
/// Command that adds a child to an entity.
#[derive(Debug)]
pub struct AddChild {
pub struct PushChild {
/// Parent entity to add the child to.
pub parent: Entity,
/// Child entity to add.
pub child: Entity,
}
impl Command for AddChild {
impl Command for PushChild {
fn apply(self, world: &mut World) {
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 {
panic!("Cannot add entity as a child of itself.");
}
self.commands().add(AddChild { child, parent });
self.commands().add(PushChild { child, parent });
self
}
@ -460,7 +460,7 @@ impl<'w, 's, 'a> BuildChildren for EntityCommands<'w, 's, 'a> {
if child == parent {
panic!("Cannot set parent to itself");
}
self.commands().add(AddChild { child, parent });
self.commands().add(PushChild { child, parent });
self
}

View File

@ -193,7 +193,7 @@ where
#[cfg(test)]
mod tests {
use bevy_ecs::{reflect::AppTypeRegistry, system::Command, world::World};
use bevy_hierarchy::{AddChild, Parent};
use bevy_hierarchy::{Parent, PushChild};
use bevy_utils::EntityHashMap;
use crate::dynamic_scene_builder::DynamicSceneBuilder;
@ -211,7 +211,7 @@ mod tests {
.register::<Parent>();
let original_parent_entity = world.spawn_empty().id();
let original_child_entity = world.spawn_empty().id();
AddChild {
PushChild {
parent: original_parent_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
// Hierarchy should look like:
// Original Parent <- Original Child <- Scene Parent <- Scene Child
AddChild {
PushChild {
parent: original_child_entity,
child: from_scene_parent_entity,
}

View File

@ -7,7 +7,7 @@ use bevy_ecs::{
system::{Command, Resource},
world::{Mut, World},
};
use bevy_hierarchy::{AddChild, Parent};
use bevy_hierarchy::{Parent, PushChild};
use bevy_utils::{tracing::error, EntityHashMap, HashMap, HashSet};
use thiserror::Error;
use uuid::Uuid;
@ -348,7 +348,7 @@ impl SceneSpawner {
// this case shouldn't happen anyway
.unwrap_or(true)
{
AddChild {
PushChild {
parent,
child: entity,
}

View File

@ -2,24 +2,24 @@
//! while preserving [`GlobalTransform`].
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};
/// 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`].
///
/// You most likely want to use [`BuildChildrenTransformExt::set_parent_in_place`]
/// method on [`EntityCommands`] instead.
pub struct AddChildInPlace {
pub struct PushChildInPlace {
/// Parent entity to add the child to.
pub parent: Entity,
/// Child entity to add.
pub child: Entity,
}
impl Command for AddChildInPlace {
impl Command for PushChildInPlace {
fn apply(self, world: &mut World) {
let hierarchy_command = AddChild {
let hierarchy_command = PushChild {
child: self.child,
parent: self.parent,
};
@ -88,7 +88,7 @@ pub trait BuildChildrenTransformExt {
impl<'w, 's, 'a> BuildChildrenTransformExt for EntityCommands<'w, 's, 'a> {
fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self {
let child = self.id();
self.commands().add(AddChildInPlace { child, parent });
self.commands().add(PushChildInPlace { child, parent });
self
}