Skip to content

Commit

Permalink
Rename "AddChild" to "PushChild" (bevyengine#11194)
Browse files Browse the repository at this point in the history
# Objective

- Fixes bevyengine#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`.
  • Loading branch information
garychia authored Jan 4, 2024
1 parent 5511483 commit 93c7e7c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions crates/bevy_hierarchy/src/child_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_scene/src/dynamic_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
}
Expand All @@ -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,
}
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_scene/src/scene_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -348,7 +348,7 @@ impl SceneSpawner {
// this case shouldn't happen anyway
.unwrap_or(true)
{
AddChild {
PushChild {
parent,
child: entity,
}
Expand Down
12 changes: 6 additions & 6 deletions crates/bevy_transform/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 93c7e7c

Please sign in to comment.