diff options
| author | HampusM <hampus@hampusmat.com> | 2026-07-08 23:30:50 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-07-08 23:30:50 +0200 |
| commit | 0b78c7da4980c90c2feca1ef7e0ee898db084486 (patch) | |
| tree | ba2f033b004e44b73737e502274117357e022d24 /engine-ecs/src/actions.rs | |
| parent | a34ad021ab4d3330e28e5489b24be7dd23c89808 (diff) | |
feat(engine-ecs): add fns for spawning named entities
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) { |
