1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use bevy_ecs::{
component::Component,
entity::{Entity, EntityMap, MapEntities, MapEntitiesError},
reflect::{ReflectComponent, ReflectMapEntities},
world::{FromWorld, World},
};
use bevy_reflect::Reflect;
use std::ops::Deref;
#[derive(Component, Debug, Eq, PartialEq, Reflect)]
#[reflect(Component, MapEntities, PartialEq)]
pub struct Parent(pub(crate) Entity);
impl Parent {
pub fn get(&self) -> Entity {
self.0
}
}
impl FromWorld for Parent {
fn from_world(_world: &mut World) -> Self {
Parent(Entity::from_raw(u32::MAX))
}
}
impl MapEntities for Parent {
fn map_entities(&mut self, entity_map: &EntityMap) -> Result<(), MapEntitiesError> {
if let Ok(mapped_entity) = entity_map.get(self.0) {
self.0 = mapped_entity;
}
Ok(())
}
}
impl Deref for Parent {
type Target = Entity;
fn deref(&self) -> &Self::Target {
&self.0
}
}