diff options
Diffstat (limited to 'ecs/src/relationship.rs')
-rw-r--r-- | ecs/src/relationship.rs | 72 |
1 files changed, 40 insertions, 32 deletions
diff --git a/ecs/src/relationship.rs b/ecs/src/relationship.rs index 45fa265..c5399e4 100644 --- a/ecs/src/relationship.rs +++ b/ecs/src/relationship.rs @@ -6,13 +6,14 @@ use ecs_macros::Component; use crate::component::storage::Storage as ComponentStorage; use crate::component::{ Component, - FromLockedOptional as FromLockedOptionalComponent, Handle as ComponentHandle, + HandleError as ComponentHandleError, + HandleFromEntityComponentRef, HandleMut as ComponentHandleMut, }; -use crate::lock::{Error as LockError, Lock, ReadGuard}; +use crate::lock::ReadGuard; use crate::uid::{Kind as UidKind, Uid}; -use crate::World; +use crate::{EntityComponentRef, World}; /// A relationship to one or more targets. #[derive(Debug, Component)] @@ -70,22 +71,24 @@ where relationship_comp: ComponentHandleMut<'rel_comp, Relationship<Kind, ComponentT>>, } -impl<'rel_comp, Kind, ComponentT> FromLockedOptionalComponent<'rel_comp> +impl<'rel_comp, Kind, ComponentT> HandleFromEntityComponentRef<'rel_comp> for RelationMut<'rel_comp, Kind, ComponentT> where ComponentT: Component, { - fn from_locked_optional_component( - optional_component: Option<&'rel_comp crate::lock::Lock<Box<dyn Component>>>, + type Error = ComponentHandleError; + + fn from_entity_component_ref( + entity_component_ref: Option<EntityComponentRef<'rel_comp>>, world: &'rel_comp World, - ) -> Result<Self, LockError> + ) -> Result<Self, Self::Error> { - let relationship_comp_handle_from_locked_opt_comp = ComponentHandleMut::< + let relationship_comp_handle_from_ent_comp_ref = ComponentHandleMut::< Relationship<Kind, ComponentT>, - >::from_locked_optional_component; + >::from_entity_component_ref; let relationship_comp = - relationship_comp_handle_from_locked_opt_comp(optional_component, world)?; + relationship_comp_handle_from_ent_comp_ref(entity_component_ref, world)?; let component_storage_lock = world .data @@ -100,19 +103,21 @@ where } } -impl<'rel_comp, Kind, ComponentT> FromLockedOptionalComponent<'rel_comp> +impl<'rel_comp, Kind, ComponentT> HandleFromEntityComponentRef<'rel_comp> for Option<RelationMut<'rel_comp, Kind, ComponentT>> where ComponentT: Component, { - fn from_locked_optional_component( - optional_component: Option<&'rel_comp Lock<Box<dyn Component>>>, + type Error = ComponentHandleError; + + fn from_entity_component_ref( + entity_component_ref: Option<EntityComponentRef<'rel_comp>>, world: &'rel_comp World, - ) -> Result<Self, crate::lock::Error> + ) -> Result<Self, Self::Error> { - optional_component - .map(|component| { - RelationMut::from_locked_optional_component(Some(component), world) + entity_component_ref + .map(|entity_comp| { + RelationMut::from_entity_component_ref(Some(entity_comp), world) }) .transpose() } @@ -292,22 +297,23 @@ where relationship_comp: ComponentHandle<'rel_comp, Relationship<Kind, ComponentT>>, } -impl<'rel_comp, Kind, ComponentT> FromLockedOptionalComponent<'rel_comp> +impl<'rel_comp, Kind, ComponentT> HandleFromEntityComponentRef<'rel_comp> for Relation<'rel_comp, Kind, ComponentT> where ComponentT: Component, { - fn from_locked_optional_component( - optional_component: Option<&'rel_comp Lock<Box<dyn Component>>>, + type Error = ComponentHandleError; + + fn from_entity_component_ref( + entity_component_ref: Option<EntityComponentRef<'rel_comp>>, world: &'rel_comp World, - ) -> Result<Self, LockError> + ) -> Result<Self, Self::Error> { - let relationship_comp_handle_from_locked_opt_comp = ComponentHandle::< - Relationship<Kind, ComponentT>, - >::from_locked_optional_component; + let relationship_comp_handle_from_ent_comp_ref = + ComponentHandle::<Relationship<Kind, ComponentT>>::from_entity_component_ref; let relationship_comp = - relationship_comp_handle_from_locked_opt_comp(optional_component, world)?; + relationship_comp_handle_from_ent_comp_ref(entity_component_ref, world)?; let component_storage_lock = world .data @@ -322,19 +328,21 @@ where } } -impl<'rel_comp, Kind, ComponentT> FromLockedOptionalComponent<'rel_comp> +impl<'rel_comp, Kind, ComponentT> HandleFromEntityComponentRef<'rel_comp> for Option<Relation<'rel_comp, Kind, ComponentT>> where ComponentT: Component, { - fn from_locked_optional_component( - optional_component: Option<&'rel_comp Lock<Box<dyn Component>>>, + type Error = ComponentHandleError; + + fn from_entity_component_ref( + entity_component_ref: Option<EntityComponentRef<'rel_comp>>, world: &'rel_comp World, - ) -> Result<Self, crate::lock::Error> + ) -> Result<Self, ComponentHandleError> { - optional_component - .map(|component| { - Relation::from_locked_optional_component(Some(component), world) + entity_component_ref + .map(|entity_comp| { + Relation::from_entity_component_ref(Some(entity_comp), world) }) .transpose() } |