summaryrefslogtreecommitdiff
path: root/ecs/src/actions.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-11 21:48:31 +0200
committerHampusM <hampus@hampusmat.com>2024-08-12 19:23:10 +0200
commitee69aa92802ba9f5becd533465ca1639cb670ace (patch)
treee99102b0e8a29126cd8ff8b12389a5f3b42c083a /ecs/src/actions.rs
parent93f764e1003bb6f35b56b7b91a73ae0ca80282c9 (diff)
feat(ecs): add action to add component(s) to entity
Diffstat (limited to 'ecs/src/actions.rs')
-rw-r--r--ecs/src/actions.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs
index 2ee5518..038f617 100644
--- a/ecs/src/actions.rs
+++ b/ecs/src/actions.rs
@@ -3,6 +3,7 @@ use std::marker::PhantomData;
use std::sync::{Arc, Weak};
use crate::component::{Component, Sequence as ComponentSequence};
+use crate::entity::Uid as EntityUid;
use crate::lock::{Lock, WriteGuard};
use crate::system::{NoInitParamFlag, Param as SystemParam, System};
use crate::{ActionQueue, World};
@@ -23,6 +24,15 @@ impl<'world> Actions<'world>
self.action_queue.push(Action::Spawn(components.into_vec()));
}
+ /// Adds component(s) to a entity.
+ pub fn add_components<Comps>(&mut self, entity_uid: EntityUid, components: Comps)
+ where
+ Comps: ComponentSequence,
+ {
+ self.action_queue
+ .push(Action::AddComponents(entity_uid, components.into_vec()));
+ }
+
/// Adds stopping the loop in [`Engine::event_loop`] at the next opportune time to the
/// action queue.
pub fn stop(&mut self)
@@ -129,6 +139,7 @@ impl<'weak_ref> Ref<'weak_ref>
pub(crate) enum Action
{
Spawn(Vec<Box<dyn Component>>),
+ AddComponents(EntityUid, Vec<Box<dyn Component>>),
Stop,
}