From ee69aa92802ba9f5becd533465ca1639cb670ace Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 11 Aug 2024 21:48:31 +0200 Subject: feat(ecs): add action to add component(s) to entity --- ecs/src/actions.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ecs/src/actions.rs') 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(&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>), + AddComponents(EntityUid, Vec>), Stop, } -- cgit v1.2.3-18-g5258