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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use super::*;
/// Component mixin implementation
impl World {
/// Find or register component.
///
/// # Type Parameters
///
/// * `T` - The component type.
///
/// # Returns
///
/// The found or registered component.
pub fn component<T: ComponentId>(&self) -> Component<'_, T::UnderlyingType> {
Component::<T::UnderlyingType>::new(self)
}
/// Find or register component.
///
/// # Type Parameters
///
/// * `T` - The component type.
///
/// # Arguments
///
/// * `name` - The name of the component.
///
/// # Returns
///
/// The found or registered component.
pub fn component_named<'a, T: ComponentId>(
&'a self,
name: &str,
) -> Component<'a, T::UnderlyingType> {
Component::<T::UnderlyingType>::new_named(self, name)
}
/// Create new untyped component.
pub fn component_untyped(&self) -> UntypedComponent<'_> {
UntypedComponent::new(self)
}
/// Create new named untyped component.
pub fn component_untyped_named(&self, name: &str) -> UntypedComponent<'_> {
UntypedComponent::new_named(self, name)
}
/// Find or register untyped component.
///
/// # Arguments
///
/// * `id` - The component id.
///
/// # Returns
///
/// The found or registered untyped component.
pub fn component_untyped_from(&self, id: impl IntoEntity) -> UntypedComponent<'_> {
UntypedComponent::new_from(self, id)
}
/// Convert enum constant to entity
///
/// # Type Parameters
///
/// * `T` - The enum type.
///
/// # Arguments
///
/// * `enum_value` - The enum value to convert.
pub fn to_entity<T: ComponentId + ComponentType<Enum> + EnumComponentInfo>(
&self,
enum_value: T,
) -> EntityView<'_> {
EntityView::new_from(self, enum_value.id_variant(self))
}
}