pub struct EntitiesAndComponents { /* private fields */ }Expand description
This struct holds all the entities and components in the game engine It is the main way to interact with the game engine, it is seperate from systems for safety reasons
Implementations§
Source§impl EntitiesAndComponents
impl EntitiesAndComponents
Sourcepub fn add_entity(&mut self) -> Entity
pub fn add_entity(&mut self) -> Entity
Adds an entity to the game engine Returns the entity
Sourcepub fn add_entity_with<T: OwnedComponents<Input = T>>(
&mut self,
components: T,
) -> Entity
pub fn add_entity_with<T: OwnedComponents<Input = T>>( &mut self, components: T, ) -> Entity
Adds an entity to the game engine with components
Sourcepub fn remove_entity(&mut self, entity: Entity)
pub fn remove_entity(&mut self, entity: Entity)
Removes an entity from the game engine This will also remove all children of the entity
Sourcepub fn get_entities(&self) -> Vec<Entity>
pub fn get_entities(&self) -> Vec<Entity>
Gets a reference to all the entities in the game engine Should rarely if ever be used
Sourcepub fn get_nth_entity(&self, index: usize) -> Option<Entity>
pub fn get_nth_entity(&self, index: usize) -> Option<Entity>
Gets a copy of an entity at a certain index
Sourcepub fn get_entity_count(&self) -> usize
pub fn get_entity_count(&self) -> usize
Gets the number of entities in the game engine
Sourcepub fn get_all_components(&self, entity: Entity) -> &Map<dyn Any + 'static>
pub fn get_all_components(&self, entity: Entity) -> &Map<dyn Any + 'static>
Gets a reference to all the components on an entity Returns an AnyMap, which can be used to get a reference to a component This should rarely if ever be used
Sourcepub fn get_all_components_mut(
&mut self,
entity: Entity,
) -> &mut Map<dyn Any + 'static>
pub fn get_all_components_mut( &mut self, entity: Entity, ) -> &mut Map<dyn Any + 'static>
Gets a mutable reference to the components on an entity If the entity does not exist, it will panic This should rarely if ever be used
Sourcepub fn try_get_component<T: Component>(&self, entity: Entity) -> Option<&Box<T>>
pub fn try_get_component<T: Component>(&self, entity: Entity) -> Option<&Box<T>>
Gets a reference to a component on an entity If the component does not exist on the entity, it will return None panics if the entity does not exist
Sourcepub fn try_get_component_mut<T: Component>(
&mut self,
entity: Entity,
) -> Option<&mut Box<T>>
pub fn try_get_component_mut<T: Component>( &mut self, entity: Entity, ) -> Option<&mut Box<T>>
Gets a mutable reference to a component on an entity If the component does not exist on the entity, it will return None panics if the entity does not exist
Sourcepub fn get_components<'a, T: ComponentsRef<'a> + 'static>(
&'a self,
entity: Entity,
) -> T::Result
pub fn get_components<'a, T: ComponentsRef<'a> + 'static>( &'a self, entity: Entity, ) -> T::Result
Gets a tuple of references to components on an entity If the component does not exist on the entity, it will panic panics if the entity does not exist
Sourcepub fn get_components_mut<'a, T: ComponentsMut<'a> + 'static>(
&'a mut self,
entity: Entity,
) -> T::Result
pub fn get_components_mut<'a, T: ComponentsMut<'a> + 'static>( &'a mut self, entity: Entity, ) -> T::Result
Gets a mutable reference to a component on an entity If the component does not exist on the entity, it will panic panics if the entity does not exist
Sourcepub fn try_get_components<'a, T: TryComponentsRef<'a> + 'static>(
&'a self,
entity: Entity,
) -> T::Result
pub fn try_get_components<'a, T: TryComponentsRef<'a> + 'static>( &'a self, entity: Entity, ) -> T::Result
Gets a tuple of references to components on an entity If the component does not exist on the entity it will return None panics if the entity does not exist
Sourcepub fn try_get_components_mut<'a, T: TryComponentsMut<'a> + 'static>(
&'a mut self,
entity: Entity,
) -> T::Result
pub fn try_get_components_mut<'a, T: TryComponentsMut<'a> + 'static>( &'a mut self, entity: Entity, ) -> T::Result
Gets a mutable reference to a component on an entity If the component does not exist on the entity it will return None panics if the entity does not exist
Sourcepub fn add_component_to<T: Component>(&mut self, entity: Entity, component: T)
pub fn add_component_to<T: Component>(&mut self, entity: Entity, component: T)
Adds a component to an entity If the component already exists on the entity, it will be overwritten panics if the entity does not exist
Sourcepub fn remove_component_from<T: Component>(&mut self, entity: Entity)
pub fn remove_component_from<T: Component>(&mut self, entity: Entity)
Removes a component from an entity If the component does not exist on the entity, it will do nothing panics if the entity does not exist
Sourcepub fn get_entities_with_component<T: Component>(
&self,
) -> Flatten<IntoIter<Values<'_, DefaultKey, Entity>>>
pub fn get_entities_with_component<T: Component>( &self, ) -> Flatten<IntoIter<Values<'_, DefaultKey, Entity>>>
returns an iterator over all entities with a certain component
Sourcepub fn get_entity_count_with_component<T: Component>(&self) -> usize
pub fn get_entity_count_with_component<T: Component>(&self) -> usize
gets the number of entities with a certain component
Sourcepub fn get_entity_with_component<T: Component>(
&self,
index: usize,
) -> Option<Entity>
pub fn get_entity_with_component<T: Component>( &self, index: usize, ) -> Option<Entity>
gets the nth entity with a certain component O(n) use get_entities_with_component if you need to iterate over all entities with a certain component
Sourcepub fn get_resource<T: Resource>(&self) -> Option<&T>
pub fn get_resource<T: Resource>(&self) -> Option<&T>
Gets a resource from the game engine
Sourcepub fn add_resource<T: Resource>(&mut self, resource: T)
pub fn add_resource<T: Resource>(&mut self, resource: T)
Adds a resource to the game engine
Sourcepub fn remove_resource<T: Resource>(&mut self)
pub fn remove_resource<T: Resource>(&mut self)
Removes a resource from the game engine
Sourcepub fn get_resource_mut<T: Resource>(&mut self) -> Option<&mut T>
pub fn get_resource_mut<T: Resource>(&mut self) -> Option<&mut T>
Gets a resource from the game engine mutably, panics if the resource does not exist
Sourcepub fn does_entity_exist(&self, entity: Entity) -> bool
pub fn does_entity_exist(&self, entity: Entity) -> bool
Checks if an entity exists in the world
Sourcepub fn print_tree(&self)
pub fn print_tree(&self)
This function is used to help debug entities and components It will print out all the entities and components in the game engine it prints the type id of the components, not the actual type because that is not possible
Sourcepub fn get_children(&self, entity: Entity) -> Vec<Entity>
pub fn get_children(&self, entity: Entity) -> Vec<Entity>
gets the children of an entity
Sourcepub fn get_parent(&self, entity: Entity) -> Option<Entity>
pub fn get_parent(&self, entity: Entity) -> Option<Entity>
gets the parent of an entity returns None if the entity is a root entity
Sourcepub fn set_parent(
&mut self,
child_entity: Entity,
parent_entity: Entity,
) -> bool
pub fn set_parent( &mut self, child_entity: Entity, parent_entity: Entity, ) -> bool
sets the parent of an entity if the entity already has a parent it will be changed returns true if the parent was set, false if the parent was not set (inverse relationship detected)
Sourcepub fn remove_parent(&mut self, child_entity: Entity)
pub fn remove_parent(&mut self, child_entity: Entity)
this function removes the link between a parent and a child making the child a root entity
Sourcepub fn get_entities_with_children(
&self,
) -> Flatten<IntoIter<Values<'_, DefaultKey, Entity>>>
pub fn get_entities_with_children( &self, ) -> Flatten<IntoIter<Values<'_, DefaultKey, Entity>>>
gets the entities with children
Sourcepub fn get_entities_with_parent(
&self,
) -> Flatten<IntoIter<Values<'_, DefaultKey, Entity>>>
pub fn get_entities_with_parent( &self, ) -> Flatten<IntoIter<Values<'_, DefaultKey, Entity>>>
gets the entities with parents
Auto Trait Implementations§
impl Freeze for EntitiesAndComponents
impl !RefUnwindSafe for EntitiesAndComponents
impl !Send for EntitiesAndComponents
impl !Sync for EntitiesAndComponents
impl Unpin for EntitiesAndComponents
impl !UnwindSafe for EntitiesAndComponents
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more