diff options
author | HampusM <hampus@hampusmat.com> | 2024-08-11 21:48:31 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-08-12 19:23:10 +0200 |
commit | ee69aa92802ba9f5becd533465ca1639cb670ace (patch) | |
tree | e99102b0e8a29126cd8ff8b12389a5f3b42c083a /ecs/src/lib.rs | |
parent | 93f764e1003bb6f35b56b7b91a73ae0ca80282c9 (diff) |
feat(ecs): add action to add component(s) to entity
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r-- | ecs/src/lib.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs index 34d6b7b..df65cb3 100644 --- a/ecs/src/lib.rs +++ b/ecs/src/lib.rs @@ -71,7 +71,7 @@ impl World .component_storage .write_nonblock() .expect("Failed to acquire read-write component storage lock") - .push_entity(components.into_vec()); + .push_entity(EntityUid::new_unique(), components.into_vec()); entity_uid } @@ -158,7 +158,17 @@ impl World "Failed to acquire read-write component storage lock", ); - component_storage_lock.push_entity(components); + component_storage_lock + .push_entity(EntityUid::new_unique(), components); + } + Action::AddComponents(entity_uid, components) => { + let mut component_storage_lock = + self.data.component_storage.write_nonblock().expect( + "Failed to acquire read-write component storage lock", + ); + + component_storage_lock + .add_components_to_entity(entity_uid, components); } Action::Stop => { self.stop.store(true, Ordering::Relaxed); @@ -226,6 +236,18 @@ pub struct EntityComponent pub component: Lock<Box<dyn Component>>, } +impl From<Box<dyn Component>> for EntityComponent +{ + fn from(component: Box<dyn Component>) -> Self + { + Self { + id: component.id(), + name: component.type_name(), + component: Lock::new(component), + } + } +} + #[derive(Debug, Default)] struct ActionQueue { |