diff options
| -rw-r--r-- | engine-ecs/src/actions.rs | 51 | ||||
| -rw-r--r-- | engine-ecs/src/lib.rs | 37 |
2 files changed, 75 insertions, 13 deletions
diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs index 8387acc..9ca9198 100644 --- a/engine-ecs/src/actions.rs +++ b/engine-ecs/src/actions.rs @@ -29,10 +29,21 @@ impl Actions<'_> { let new_entity_uid = Uid::new_unique(); - self.action_queue.push(Action::Spawn( - new_entity_uid, - components.into_parts_array().into(), - )); + let components_parts = components.into_parts_array(); + + if let Some(comp_parts) = components_parts + .as_ref() + .iter() + .find(|comp_parts| comp_parts.is_sole) + { + panic!( + "Cannot spawn entity with sole component {}", + comp_parts.name + ); + } + + self.action_queue + .push(Action::Spawn(new_entity_uid, components_parts.into())); new_entity_uid } @@ -50,10 +61,22 @@ impl Actions<'_> { let new_entity_uid = Uid::new_unique(); + let components_parts = components.into_parts_array(); + + if let Some(comp_parts) = components_parts + .as_ref() + .iter() + .find(|comp_parts| comp_parts.is_sole) + { + panic!( + "Cannot spawn entity with sole component {}", + comp_parts.name + ); + } + self.action_queue.push(Action::Spawn( new_entity_uid, - components - .into_parts_array() + components_parts .into_iter() .chain([EntityName { name: name.into() }.into_parts()]) .collect(), @@ -106,10 +129,18 @@ impl Actions<'_> return; } - self.action_queue.push(Action::AddComponents( - entity_uid, - components.into_parts_array().into(), - )); + let components_parts = components.into_parts_array(); + + if let Some(comp_parts) = components_parts + .as_ref() + .iter() + .find(|comp_parts| comp_parts.is_sole) + { + panic!("Cannot add sole component {} to an entity", comp_parts.name); + } + + self.action_queue + .push(Action::AddComponents(entity_uid, components_parts.into())); } /// Queues up removing component(s) from a entity at the end of the current tick. diff --git a/engine-ecs/src/lib.rs b/engine-ecs/src/lib.rs index 8e8cc69..450940a 100644 --- a/engine-ecs/src/lib.rs +++ b/engine-ecs/src/lib.rs @@ -175,7 +175,20 @@ impl World where Comps: ComponentSequence, { - self.create_ent(entity_uid, components.into_parts_array()); + let components_parts = components.into_parts_array(); + + if let Some(comp_parts) = components_parts + .as_ref() + .iter() + .find(|comp_parts| comp_parts.is_sole) + { + panic!( + "Cannot spawn entity with sole component {}", + comp_parts.name + ); + } + + self.create_ent(entity_uid, components_parts); } /// Creates a entity with the given components. The entity will have the specified @@ -192,10 +205,22 @@ impl World ) where Comps: ComponentSequence, { + let components_parts = components.into_parts_array(); + + if let Some(comp_parts) = components_parts + .as_ref() + .iter() + .find(|comp_parts| comp_parts.is_sole) + { + panic!( + "Cannot spawn entity with sole component {}", + comp_parts.name + ); + } + self.create_ent( entity_uid, - components - .into_parts_array() + components_parts .into_iter() .chain([EntityName { name: name.into() }.into_parts()]), ); @@ -203,6 +228,12 @@ impl World pub fn add_component(&mut self, entity_id: Uid, component_parts: ComponentParts) { + assert!( + !component_parts.is_sole, + "Cannot add sole component {} to an entity", + component_parts.name + ); + Self::add_entity_components( entity_id, [component_parts], |
