summaryrefslogtreecommitdiff
path: root/ecs/src/actions.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-08-12 19:43:47 +0200
committerHampusM <hampus@hampusmat.com>2024-08-12 19:44:06 +0200
commit28438c40c09bb52f8bd444b6f5cf9b34bdf71fee (patch)
treeae6d506f9a9fc30a332deb0f51b098be87f8d78b /ecs/src/actions.rs
parentee69aa92802ba9f5becd533465ca1639cb670ace (diff)
feat(ecs): add action for removing components(s) from entity
Diffstat (limited to 'ecs/src/actions.rs')
-rw-r--r--ecs/src/actions.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/ecs/src/actions.rs b/ecs/src/actions.rs
index 038f617..7698b45 100644
--- a/ecs/src/actions.rs
+++ b/ecs/src/actions.rs
@@ -2,7 +2,11 @@ use std::any::Any;
use std::marker::PhantomData;
use std::sync::{Arc, Weak};
-use crate::component::{Component, Sequence as ComponentSequence};
+use crate::component::{
+ Component,
+ Metadata as ComponentMetadata,
+ Sequence as ComponentSequence,
+};
use crate::entity::Uid as EntityUid;
use crate::lock::{Lock, WriteGuard};
use crate::system::{NoInitParamFlag, Param as SystemParam, System};
@@ -33,6 +37,15 @@ impl<'world> Actions<'world>
.push(Action::AddComponents(entity_uid, components.into_vec()));
}
+ /// Removes component(s) from a entity.
+ pub fn remove_components<Comps>(&mut self, entity_uid: EntityUid)
+ where
+ Comps: ComponentSequence,
+ {
+ self.action_queue
+ .push(Action::RemoveComponents(entity_uid, Comps::metadata()));
+ }
+
/// Adds stopping the loop in [`Engine::event_loop`] at the next opportune time to the
/// action queue.
pub fn stop(&mut self)
@@ -140,6 +153,7 @@ pub(crate) enum Action
{
Spawn(Vec<Box<dyn Component>>),
AddComponents(EntityUid, Vec<Box<dyn Component>>),
+ RemoveComponents(EntityUid, Vec<ComponentMetadata>),
Stop,
}