summaryrefslogtreecommitdiff
path: root/engine-ecs/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-10-31 14:46:39 +0100
committerHampusM <hampus@hampusmat.com>2026-10-31 14:46:39 +0100
commit89724815230c4fcab81111f626bd4bb8b12db7bd (patch)
tree31e3f90eb35850afb991320bd0cab6f6c75e987d /engine-ecs/src
parent2d977a7b3089193080365c66219914081a9347ae (diff)
feat(engine-ecs): add Actions fn to create sole
Diffstat (limited to 'engine-ecs/src')
-rw-r--r--engine-ecs/src/actions.rs12
-rw-r--r--engine-ecs/src/lib.rs21
2 files changed, 33 insertions, 0 deletions
diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs
index cef51cc..f1a1541 100644
--- a/engine-ecs/src/actions.rs
+++ b/engine-ecs/src/actions.rs
@@ -10,6 +10,7 @@ use crate::component::{
use crate::entity::Name as EntityName;
use crate::event::component::Removed;
use crate::pair::Pair;
+use crate::sole::Sole;
use crate::system::{Metadata as SystemMetadata, Param as SystemParam};
use crate::uid::Uid;
use crate::{ActionQueue, World};
@@ -304,6 +305,16 @@ impl Actions<'_>
});
}
+ /// Queues up a entity to spawn at the end of the current tick, returning the [`Uid`]
+ /// that the entity will have.
+ pub fn create_sole<SoleT: Sole>(&mut self, sole: SoleT) -> Uid
+ {
+ self.action_queue
+ .push(Action::CreateSole(sole.into_parts()));
+
+ SoleT::id()
+ }
+
/// Stops the [`World`]. The world will finish the current tick and that tick will be
/// the last.
pub fn stop(&mut self)
@@ -339,5 +350,6 @@ pub(crate) enum Action
pair_id: Uid,
new_pair: ComponentParts,
},
+ CreateSole(ComponentParts),
Stop,
}
diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs
index 6028cf7..188ca7a 100644
--- a/engine-ecs/src/lib.rs
+++ b/engine-ecs/src/lib.rs
@@ -667,6 +667,27 @@ impl World
&ComponentAddingFlags { allow_soles: false },
);
}
+ Action::CreateSole(sole_parts) => {
+ if let Err(EntityAlreadyExistsError) =
+ self.data.component_storage.create_entity(sole_parts.id)
+ {
+ tracing::error!(
+ name = sole_parts.name,
+ "Can not create sole that already exists"
+ );
+ continue;
+ }
+
+ let name = sole_parts.name;
+
+ Self::add_entity_components(
+ sole_parts.id,
+ [sole_parts, EntityName { name: name.into() }.into_parts()],
+ &mut self.data.component_storage,
+ &EventSubmitter::new(&self.data.new_events),
+ &ComponentAddingFlags { allow_soles: true },
+ );
+ }
Action::Stop => {
self.stop.store(true, Ordering::Relaxed);
}