Add component access for entity
This commit is contained in:
parent
8e717b4974
commit
855c5ac59b
3 changed files with 34 additions and 1 deletions
|
@ -43,6 +43,10 @@ impl ActivationState {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait EntityComponentDisjointMut<'a, T: 'a> {
|
||||
fn get_components_mut(&'a mut self) -> std::result::Result<T, ComponentNotFoundError>;
|
||||
}
|
||||
|
||||
pub struct EntityObject {
|
||||
#[cfg(debug_assertions)]
|
||||
pub debug_name: Option<String>,
|
||||
|
@ -239,6 +243,31 @@ impl EntityObject {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_get_components_mut {
|
||||
($($t:ident$(,)?)+) => {
|
||||
impl<'a, $($t,)+> EntityComponentDisjointMut<'a, ($(&'a mut $t,)+)> for EntityObject
|
||||
where
|
||||
$(
|
||||
$t: EntityComponent + ComponentDebug + 'static,
|
||||
)+
|
||||
{
|
||||
fn get_components_mut(&'a mut self) -> std::result::Result<($(&'a mut $t,)+), ComponentNotFoundError> {
|
||||
crate::get_disjoint_mut::GetDisjointMut::<'a, ($(&'a mut $t,)+)>::get_mut(&mut self.components)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl_get_components_mut!(T, U);
|
||||
impl_get_components_mut!(T, U, V);
|
||||
impl_get_components_mut!(T, U, V, W);
|
||||
impl_get_components_mut!(T, U, V, W, X);
|
||||
impl_get_components_mut!(T, U, V, W, X, Y);
|
||||
impl_get_components_mut!(T, U, V, W, X, Y, Z);
|
||||
impl_get_components_mut!(T, U, V, W, X, Y, Z, A);
|
||||
impl_get_components_mut!(T, U, V, W, X, Y, Z, A, B);
|
||||
impl_get_components_mut!(T, U, V, W, X, Y, Z, A, B, C);
|
||||
|
||||
#[allow(clippy::derive_hash_xor_eq)]
|
||||
#[derive(Debug, Clone, Copy, Hash, Eq, Serialize, Deserialize)]
|
||||
pub struct Entity {
|
||||
|
|
|
@ -8,7 +8,9 @@ mod unsafe_component_store;
|
|||
mod updates;
|
||||
mod world;
|
||||
|
||||
pub use crate::entity::{Entity, EntityMultiMut, EntityNotFoundError, EntityObject};
|
||||
pub use crate::entity::{
|
||||
Entity, EntityComponentDisjointMut, EntityMultiMut, EntityNotFoundError, EntityObject,
|
||||
};
|
||||
pub use crate::events::Events;
|
||||
pub use crate::resources::Resources;
|
||||
pub use crate::type_map::{
|
||||
|
|
|
@ -201,6 +201,8 @@ impl_get_disjoint_mut!(TypeMap < T, U, V, W, X, Y, Z > { ComponentNotFoundError
|
|||
impl_get_disjoint_mut!(TypeMap < T, U, V, W, X, Y, Z, A > { ComponentNotFoundError });
|
||||
#[rustfmt::skip]
|
||||
impl_get_disjoint_mut!(TypeMap < T, U, V, W, X, Y, Z, A, B > { ComponentNotFoundError });
|
||||
#[rustfmt::skip]
|
||||
impl_get_disjoint_mut!(TypeMap < T, U, V, W, X, Y, Z, A, B, C > { ComponentNotFoundError });
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ComponentRequestType {
|
||||
|
|
Loading…
Reference in a new issue