diff options
| author | HampusM <hampus@hampusmat.com> | 2026-08-31 06:04:44 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-08-31 06:04:44 +0200 |
| commit | 4988e8aeee39a8ec35d338b3ffdb0d26c89ff6ab (patch) | |
| tree | a56e317b5bba755a31a5ad85837df9bccd3fadab /engine-ecs/src/actions.rs | |
| parent | 6c0db8d03888edddcd811166b1297ae185f2bfbe (diff) | |
fix(engine-ecs): add checks against adding sole components to entities
Diffstat (limited to 'engine-ecs/src/actions.rs')
| -rw-r--r-- | engine-ecs/src/actions.rs | 51 |
1 files changed, 41 insertions, 10 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. |
