[−][src]Trait akashi::Entity
Represents an Entity within Akashi's Entity-Component-System architecture.
Entities, on their own, are essentially just a unique ID and a collection of attached Components.
The two main Entity types that Akashi provides are Players
and
Cards
.
Errors
Many of the methods provided by this trait wrap similar methods on
ComponentManager
objects, which in turn wrap a
number of Component
storage objects.
Errors reported by those will bubble up through these methods.
Additionally, attempts to perform operations with Component
types for which no backing store has been registered with
ComponentManager::register_component
will return TypeNotFoundError
.
Required methods
fn new(
id: Snowflake,
component_manager: Arc<ComponentManager<Self>>,
components_attached: HashSet<TypeId>
) -> Self
id: Snowflake,
component_manager: Arc<ComponentManager<Self>>,
components_attached: HashSet<TypeId>
) -> Self
fn id(&self) -> Snowflake
Gets the unique ID used to identify this Entity and its Components.
fn dirty(&self) -> bool
Checks whether any Components
have been modified
on this Entity.
fn dirty_mut(&mut self) -> &mut bool
Get this entity's 'dirty' flag.
fn component_manager(&self) -> &ComponentManager<Self>
Gets a reference to the ComponentManager
used to perform operations on this Entity.
fn components_attached(&self) -> &HashSet<TypeId>
Gets a reference to a HashSet
containing the TypeId
s of each
Component
attached to this Entity.
fn components_attached_mut(&mut self) -> &mut HashSet<TypeId>
Gets a mutable reference to the HashSet
of attached component
TypeId
s.
Provided methods
fn get_component<T: Component<Self> + 'static>(
&self
) -> Result<Option<T>, Error>
&self
) -> Result<Option<T>, Error>
Gets a Component
attached to this Entity.
fn set_component<T: Component<Self> + 'static>(
&mut self,
component: T
) -> Result<(), Error>
&mut self,
component: T
) -> Result<(), Error>
fn has_component<T: Component<Self> + 'static>(&self) -> bool
Checks to see if the given Component
type has
been attached to this Entity.
Unlike most of the other Entity
trait methods, this doesn't
return a TypeNotFoundError
for Components
without an associated backing store. Instead, it will just return
false
.
fn delete_component<T: Component<Self> + 'static>(
&mut self
) -> Result<(), Error>
&mut self
) -> Result<(), Error>
Deletes an attached Component
from this Entity.
fn clear_components(&mut self) -> Result<(), ClearComponentsError>
Delete all Components
attached to this Entity.
Errors
Any errors reported by the backing storage objects for
Components
attached to this Entity will be
collected into a ClearComponentsError
.
Implementors
impl Entity for Card
[src]
fn new(
id: Snowflake,
cm: Arc<ComponentManager<Card>>,
components: HashSet<TypeId>
) -> Card
[src]
id: Snowflake,
cm: Arc<ComponentManager<Card>>,
components: HashSet<TypeId>
) -> Card
fn id(&self) -> Snowflake
[src]
fn component_manager(&self) -> &ComponentManager<Card>
[src]
fn components_attached(&self) -> &HashSet<TypeId>
[src]
fn components_attached_mut(&mut self) -> &mut HashSet<TypeId>
[src]
fn dirty(&self) -> bool
[src]
fn dirty_mut(&mut self) -> &mut bool
[src]
impl Entity for CardType
[src]
fn new(
id: Snowflake,
cm: Arc<ComponentManager<Self>>,
components: HashSet<TypeId>
) -> Self
[src]
id: Snowflake,
cm: Arc<ComponentManager<Self>>,
components: HashSet<TypeId>
) -> Self
fn id(&self) -> Snowflake
[src]
fn component_manager(&self) -> &ComponentManager<CardType>
[src]
fn components_attached(&self) -> &HashSet<TypeId>
[src]
fn components_attached_mut(&mut self) -> &mut HashSet<TypeId>
[src]
fn dirty(&self) -> bool
[src]
fn dirty_mut(&mut self) -> &mut bool
[src]
impl Entity for Player
[src]
fn new(
id: Snowflake,
cm: Arc<ComponentManager<Self>>,
components: HashSet<TypeId>
) -> Self
[src]
id: Snowflake,
cm: Arc<ComponentManager<Self>>,
components: HashSet<TypeId>
) -> Self