diff options
Diffstat (limited to 'engine-ecs/src/actions.rs')
| -rw-r--r-- | engine-ecs/src/actions.rs | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/engine-ecs/src/actions.rs b/engine-ecs/src/actions.rs index c367f6e..5eaa24e 100644 --- a/engine-ecs/src/actions.rs +++ b/engine-ecs/src/actions.rs @@ -25,21 +25,17 @@ impl Actions<'_> { let new_entity_uid = Uid::new_unique(); - let components_parts = bundle.into_parts_array(); + let components_parts = bundle.iter_component_parts().collect::<Vec<_>>(); - if let Some(comp_parts) = components_parts - .as_ref() + if let Some(ComponentParts { name: sole_name, .. }) = components_parts .iter() .find(|comp_parts| comp_parts.is_sole) { - panic!( - "Cannot spawn entity with sole component {}", - comp_parts.name - ); + panic!("Cannot spawn entity with sole component '{sole_name}'"); } self.action_queue - .push(Action::Spawn(new_entity_uid, components_parts.into())); + .push(Action::Spawn(new_entity_uid, components_parts)); new_entity_uid } @@ -57,26 +53,20 @@ impl Actions<'_> { let new_entity_uid = Uid::new_unique(); - let components_parts = bundle.into_parts_array(); + let components_parts = bundle + .iter_component_parts() + .chain([EntityName { name: name.into() }.into_parts()]) + .collect::<Vec<_>>(); - if let Some(comp_parts) = components_parts - .as_ref() + if let Some(ComponentParts { name: sole_name, .. }) = components_parts .iter() .find(|comp_parts| comp_parts.is_sole) { - panic!( - "Cannot spawn entity with sole component {}", - comp_parts.name - ); + panic!("Cannot spawn entity with sole component '{sole_name}'"); } - self.action_queue.push(Action::Spawn( - new_entity_uid, - components_parts - .into_iter() - .chain([EntityName { name: name.into() }.into_parts()]) - .collect(), - )); + self.action_queue + .push(Action::Spawn(new_entity_uid, components_parts)); new_entity_uid } @@ -119,22 +109,21 @@ impl Actions<'_> { debug_assert!(!entity_uid.is_pair()); - if bundle.cnt() == 0 { + let components_parts = bundle.iter_component_parts().collect::<Vec<_>>(); + + if components_parts.is_empty() { return; } - let components_parts = bundle.into_parts_array(); - - if let Some(comp_parts) = components_parts - .as_ref() + if let Some(ComponentParts { name: sole_name, .. }) = components_parts .iter() .find(|comp_parts| comp_parts.is_sole) { - panic!("Cannot add sole component {} to an entity", comp_parts.name); + panic!("Cannot spawn entity with sole component '{sole_name}'"); } self.action_queue - .push(Action::AddComponents(entity_uid, components_parts.into())); + .push(Action::AddComponents(entity_uid, components_parts)); } /// Queues up removing component(s) from a entity at the end of the current tick. |
