Struct shipyard::EntitiesViewMut [−][src]
pub struct EntitiesViewMut<'a> { /* fields omitted */ }
Expand description
Exclusive view over Entities
storage.
Methods from Deref<Target = Entities>
Returns true if entity
matches a living entity.
pub fn try_add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
) -> Result<(), AddComponent>
pub fn try_add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
) -> Result<(), AddComponent>
Adds component
to entity
, multiple components can be added at the same time using a tuple.
Entities
is only borrowed immutably.
Example
use shipyard::{World, EntitiesViewMut, EntitiesView, ViewMut};
let world = World::new();
let entity = world.borrow::<EntitiesViewMut>().add_entity((), ());
world.run(|entities: EntitiesView, mut u32s: ViewMut<u32>| {
entities.try_add_component(&mut u32s, 0, entity).unwrap();
});
pub fn add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
)
pub fn add_component<C, S: AddComponent<C>>(
&self,
storages: S,
component: C,
entity: EntityId
)
Adds component
to entity
, multiple components can be added at the same time using a tuple.
Entities
is only borrowed immutably.
Unwraps errors.
Example
use shipyard::{World, EntitiesViewMut, EntitiesView, ViewMut};
let world = World::new();
let entity = world.borrow::<EntitiesViewMut>().add_entity((), ());
world.run(|entities: EntitiesView, mut u32s: ViewMut<u32>| {
entities.add_component(&mut u32s, 0, entity);
});
Delete an entity, returns true if the entity was alive.
If the entity has components, they will not be deleted and still be accessible using this id.
pub fn add_entity<T: ViewAddEntity>(
&mut self,
storages: T,
component: T::Component
) -> EntityId
pub fn add_entity<T: ViewAddEntity>(
&mut self,
storages: T,
component: T::Component
) -> EntityId
Stores component
in a new entity, the EntityId
to this entity is returned.
Multiple components can be added at the same time using a tuple.
Example:
use shipyard::{EntitiesViewMut, Get, ViewMut, World};
let world = World::new();
world.run(
|mut entities: EntitiesViewMut, mut usizes: ViewMut<usize>, mut u32s: ViewMut<u32>| {
let entity = entities.add_entity((&mut usizes, &mut u32s), (0, 1));
assert_eq!(usizes.try_get(entity), Ok(&0));
assert_eq!(u32s.try_get(entity), Ok(&1));
},
);
Trait Implementations
type Error = GetStorage
type Error = GetStorage
The type returned in the event of a conversion error.
Performs the conversion.