summaryrefslogtreecommitdiff
path: root/ecs/src
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src')
-rw-r--r--ecs/src/component/storage.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/ecs/src/component/storage.rs b/ecs/src/component/storage.rs
index 05ede9b..944beb3 100644
--- a/ecs/src/component/storage.rs
+++ b/ecs/src/component/storage.rs
@@ -149,7 +149,7 @@ impl Storage
pub fn add_components_to_entity(
&mut self,
entity_uid: EntityUid,
- components: impl IntoIterator<Item = Box<dyn Component>>,
+ components: Vec<Box<dyn Component>>,
) -> Option<()>
{
let archetype_id = self.entity_archetype_lookup.get(&entity_uid)?;
@@ -159,6 +159,29 @@ impl Storage
let archetype = self.archetypes.get_mut(archetype_index)?;
+ let contains_component_already = components
+ .iter()
+ .find(|component| archetype.component_ids.contains_key(&component.id()))
+ .is_some();
+
+ if contains_component_already {
+ let component_cnt = components.len();
+
+ // TODO: return error
+ panic!(
+ "Entity with UID {:?} already contains one or more component(s) ({})",
+ entity_uid,
+ components
+ .iter()
+ .map(|component| [component.type_name(), ", "])
+ .flatten()
+ .enumerate()
+ .take_while(|(index, _)| { *index < (component_cnt * 2) - 1 })
+ .map(|(_, component)| component)
+ .collect::<String>()
+ );
+ }
+
let entity = archetype.take_entity(entity_uid)?;
self.push_entity(