improve error handling

This commit is contained in:
Chance 2025-04-01 18:05:17 -04:00 committed by BitSyndicate
parent ff7ff5fb79
commit 2dd2398809
Signed by untrusted user: bitsyndicate
GPG key ID: 443E4198D6BBA6DE
5 changed files with 112 additions and 54 deletions

View file

@ -81,7 +81,8 @@ impl Entity for EntityImpl {
fn get_component<C: Component>(&self) -> Option<&C> {
let type_id = TypeId::of::<C>();
if let Some(&bit) = COMPONENT_REGISTRY.lock().unwrap().get(&type_id) {
self.components.get(&bit)
self.components
.get(&bit)
.and_then(|boxed| boxed.as_any().downcast_ref::<C>())
} else {
None
@ -107,7 +108,6 @@ impl Entity for EntityImpl {
components: HashMap::new(),
}
}
}
pub struct ECS {
@ -167,4 +167,4 @@ impl ECS {
}
self.next_entity_id = count;
}
}
}