summaryrefslogtreecommitdiff
path: root/engine-ecs/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine-ecs/src/lib.rs')
-rw-r--r--engine-ecs/src/lib.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index 190eab7..b682906 100644
--- a/engine-ecs/src/lib.rs
+++ b/engine-ecs/src/lib.rs
@@ -1,6 +1,7 @@
#![deny(clippy::all, clippy::pedantic)]
use std::any::{Any, TypeId};
+use std::borrow::Cow;
use std::fmt::Debug;
use std::hint::cold_path;
use std::rc::Rc;
@@ -138,6 +139,26 @@ impl World
entity_uid
}
+ /// Creates a entity with the given components. A new unique [`Uid`] will be generated
+ /// for this entity.
+ ///
+ /// In addition to the given components, the entity will have a [`EntityName`]
+ /// component containing `name`.
+ pub fn spawn_named<Comps>(
+ &mut self,
+ name: impl Into<Cow<'static, str>>,
+ components: Comps,
+ ) -> Uid
+ where
+ Comps: ComponentSequence,
+ {
+ let entity_uid = Uid::new_unique();
+
+ self.spawn_named_with_uid(entity_uid, name, components);
+
+ entity_uid
+ }
+
/// Creates a entity with the given components. The entity will have the specified
/// [`Uid`].
#[tracing::instrument(skip_all)]
@@ -148,6 +169,29 @@ impl World
self.create_ent(entity_uid, components.into_parts_array());
}
+ /// Creates a entity with the given components. The entity will have the specified
+ /// [`Uid`].
+ ///
+ /// In addition to the given components, the entity will have a [`EntityName`]
+ /// component containing `name`.
+ #[tracing::instrument(skip_all)]
+ pub fn spawn_named_with_uid<Comps>(
+ &mut self,
+ entity_uid: Uid,
+ name: impl Into<Cow<'static, str>>,
+ components: Comps,
+ ) where
+ Comps: ComponentSequence,
+ {
+ self.create_ent(
+ entity_uid,
+ components
+ .into_parts_array()
+ .into_iter()
+ .chain([EntityName { name: name.into() }.into_parts()]),
+ );
+ }
+
pub fn add_component(&mut self, entity_id: Uid, component_parts: ComponentParts)
{
Self::add_entity_components(