Skip to content

Commit 9bae80f

Browse files
committed
Remove EntityPath & NameLookup
1 parent f50514a commit 9bae80f

File tree

1 file changed

+0
-88
lines changed

1 file changed

+0
-88
lines changed

crates/bevy_core/src/name.rs

-88
Original file line numberDiff line numberDiff line change
@@ -158,91 +158,3 @@ impl Deref for Name {
158158
}
159159
}
160160

161-
/// Path to an entity, with [`Name`]s. Each entity in a path must have a name.
162-
#[derive(Clone, Debug, Hash, PartialEq, Eq, Default)]
163-
pub struct EntityPath {
164-
/// Parts of the path
165-
pub parts: Vec<Name>,
166-
}
167-
168-
/// System param to enable entity lookup of an entity via EntityPath
169-
#[derive(SystemParam)]
170-
pub struct NameLookup<'w, 's> {
171-
named: Query<'w, 's, (Entity, &'static Name)>,
172-
children: Query<'w, 's, &'static Children>,
173-
}
174-
175-
/// Errors when looking up an entity by name
176-
pub enum LookupError {
177-
/// An entity could not be found, this either means the entity has been
178-
/// despawned, or the entity doesn't have the required components
179-
Query(QueryEntityError),
180-
/// The root node does not have the corrent name
181-
// TODO: add expected / found name
182-
RootNotFound,
183-
/// A child was not found
184-
// TODO: add expected name
185-
ChildNotFound,
186-
/// The name does not uniquely identify an entity
187-
// TODO: add name
188-
NameNotUnique,
189-
}
190-
191-
impl From<QueryEntityError> for LookupError {
192-
fn from(q: QueryEntityError) -> Self {
193-
Self::Query(q)
194-
}
195-
}
196-
197-
impl<'w, 's> NameLookup<'w, 's> {
198-
/// Find an entity by entity path, may return an error if the root name isn't unique
199-
pub fn lookup_any(&self, path: &EntityPath) -> Result<Entity, LookupError> {
200-
let mut path = path.parts.iter();
201-
let root_name = path.next().unwrap();
202-
let mut root = None;
203-
for (entity, name) in self.named.iter() {
204-
if root_name == name {
205-
if root.is_some() {
206-
return Err(LookupError::NameNotUnique);
207-
}
208-
root = Some(entity);
209-
}
210-
}
211-
let mut current_node = root.ok_or(LookupError::RootNotFound)?;
212-
for part in path {
213-
current_node = self.find_child(current_node, part)?;
214-
}
215-
Ok(current_node)
216-
}
217-
218-
/// Find an entity by the root & entity path
219-
pub fn lookup(&self, root: Entity, path: &EntityPath) -> Result<Entity, LookupError> {
220-
let mut path = path.parts.iter();
221-
let (_, root_name) = self.named.get(root)?;
222-
if root_name != path.next().unwrap() {
223-
return Err(LookupError::RootNotFound);
224-
}
225-
let mut current_node = root;
226-
for part in path {
227-
current_node = self.find_child(current_node, part)?;
228-
}
229-
Ok(current_node)
230-
}
231-
232-
/// Internal function to get the child of `current_node` that has the name `part`
233-
fn find_child(&self, current_node: Entity, part: &Name) -> Result<Entity, LookupError> {
234-
let children = self.children.get(current_node)?;
235-
let mut ret = Err(LookupError::ChildNotFound);
236-
for child in children {
237-
if let Ok((_, name)) = self.named.get(*child) {
238-
if name == part {
239-
if ret.is_ok() {
240-
return Err(LookupError::NameNotUnique);
241-
}
242-
ret = Ok(*child);
243-
}
244-
}
245-
}
246-
ret
247-
}
248-
}

0 commit comments

Comments
 (0)