From 89724815230c4fcab81111f626bd4bb8b12db7bd Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 31 Oct 2026 14:46:39 +0100 Subject: feat(engine-ecs): add Actions fn to create sole --- engine-ecs/src/actions.rs | 12 ++++++++++++ engine-ecs/src/lib.rs | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) 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(&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); } -- cgit v1.2.3-18-g5258