Rename bevy_core::name::DebugName to bevy_core::name::NameOrEntity (#14211)
# Objective - Fixes #14039 ## Solution - Rename. ## Testing - CI --- ## Migration Guide - Rename usages of `bevy_core::name::DebugName` to `bevy_core::name::NameOrEntity`
This commit is contained in:
parent
bc72cedfe3
commit
e79f91fc45
@ -20,7 +20,8 @@ pub mod prelude {
|
|||||||
//! The Bevy Core Prelude.
|
//! The Bevy Core Prelude.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
DebugName, FrameCountPlugin, Name, TaskPoolOptions, TaskPoolPlugin, TypeRegistrationPlugin,
|
FrameCountPlugin, Name, NameOrEntity, TaskPoolOptions, TaskPoolPlugin,
|
||||||
|
TypeRegistrationPlugin,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -107,7 +107,7 @@ impl std::fmt::Debug for Name {
|
|||||||
/// # use bevy_core::prelude::*;
|
/// # use bevy_core::prelude::*;
|
||||||
/// # use bevy_ecs::prelude::*;
|
/// # use bevy_ecs::prelude::*;
|
||||||
/// # #[derive(Component)] pub struct Score(f32);
|
/// # #[derive(Component)] pub struct Score(f32);
|
||||||
/// fn increment_score(mut scores: Query<(DebugName, &mut Score)>) {
|
/// fn increment_score(mut scores: Query<(NameOrEntity, &mut Score)>) {
|
||||||
/// for (name, mut score) in &mut scores {
|
/// for (name, mut score) in &mut scores {
|
||||||
/// score.0 += 1.0;
|
/// score.0 += 1.0;
|
||||||
/// if score.0.is_nan() {
|
/// if score.0.is_nan() {
|
||||||
@ -120,18 +120,18 @@ impl std::fmt::Debug for Name {
|
|||||||
///
|
///
|
||||||
/// # Implementation
|
/// # Implementation
|
||||||
///
|
///
|
||||||
/// The `Display` impl for `DebugName` returns the `Name` where there is one
|
/// The `Display` impl for `NameOrEntity` returns the `Name` where there is one
|
||||||
/// or {index}v{generation} for entities without one.
|
/// or {index}v{generation} for entities without one.
|
||||||
#[derive(QueryData)]
|
#[derive(QueryData)]
|
||||||
#[query_data(derive(Debug))]
|
#[query_data(derive(Debug))]
|
||||||
pub struct DebugName {
|
pub struct NameOrEntity {
|
||||||
/// A [`Name`] that the entity might have that is displayed if available.
|
/// A [`Name`] that the entity might have that is displayed if available.
|
||||||
pub name: Option<&'static Name>,
|
pub name: Option<&'static Name>,
|
||||||
/// The unique identifier of the entity as a fallback.
|
/// The unique identifier of the entity as a fallback.
|
||||||
pub entity: Entity,
|
pub entity: Entity,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> std::fmt::Display for DebugNameItem<'a> {
|
impl<'a> std::fmt::Display for NameOrEntityItem<'a> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
match self.name {
|
match self.name {
|
||||||
@ -227,12 +227,12 @@ mod tests {
|
|||||||
let e1 = world.spawn_empty().id();
|
let e1 = world.spawn_empty().id();
|
||||||
let name = Name::new("MyName");
|
let name = Name::new("MyName");
|
||||||
let e2 = world.spawn(name.clone()).id();
|
let e2 = world.spawn(name.clone()).id();
|
||||||
let mut query = world.query::<DebugName>();
|
let mut query = world.query::<NameOrEntity>();
|
||||||
let d1 = query.get(&world, e1).unwrap();
|
let d1 = query.get(&world, e1).unwrap();
|
||||||
let d2 = query.get(&world, e2).unwrap();
|
let d2 = query.get(&world, e2).unwrap();
|
||||||
// DebugName Display for entities without a Name should be {index}v{generation}
|
// NameOrEntity Display for entities without a Name should be {index}v{generation}
|
||||||
assert_eq!(d1.to_string(), "0v1");
|
assert_eq!(d1.to_string(), "0v1");
|
||||||
// DebugName Display for entities with a Name should be the Name
|
// NameOrEntity Display for entities with a Name should be the Name
|
||||||
assert_eq!(d2.to_string(), "MyName");
|
assert_eq!(d2.to_string(), "MyName");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user