diff options
Diffstat (limited to 'engine-ecs/src/actions.rs')
| -rw-r--r-- | engine-ecs/src/actions.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs index 9e88011..411a5d5 100644 --- a/engine-ecs/src/actions.rs +++ b/engine-ecs/src/actions.rs @@ -1,4 +1,11 @@ -use crate::component::{Parts as ComponentParts, Sequence as ComponentSequence}; +use std::borrow::Cow; + +use crate::component::{ + IntoParts, + Parts as ComponentParts, + Sequence as ComponentSequence, +}; +use crate::entity::Name as EntityName; use crate::event::component::Removed; use crate::pair::Pair; use crate::system::{Metadata as SystemMetadata, Param as SystemParam}; @@ -29,6 +36,31 @@ impl Actions<'_> new_entity_uid } + /// Queues up a entity to spawn at the end of the current tick, returning the [`Uid`] + /// that the entity will have. + /// + /// In addition to the given components, the entity will have a [`EntityName`] + /// component containing `name`. + pub fn spawn_named<Comps: ComponentSequence>( + &mut self, + name: impl Into<Cow<'static, str>>, + components: Comps, + ) -> Uid + { + let new_entity_uid = Uid::new_unique(); + + self.action_queue.push(Action::Spawn( + new_entity_uid, + components + .into_parts_array() + .into_iter() + .chain([EntityName { name: name.into() }.into_parts()]) + .collect(), + )); + + new_entity_uid + } + /// Queues up despawning a entity at the end of the current tick. pub fn despawn(&mut self, entity_uid: Uid) { |
