 ffc572728f
			
		
	
	
		ffc572728f
		
			
		
	
	
	
	
		
			
			# Objective
Fix typos throughout the project.
## Solution
[`typos`](https://github.com/crate-ci/typos) project was used for
scanning, but no automatic corrections were applied. I checked
everything by hand before fixing.
Most of the changes are documentation/comments corrections. Also, there
are few trivial changes to code (variable name, pub(crate) function name
and a few error/panic messages).
## Unsolved
`bevy_reflect_derive` has
[typo](1b51053f19/crates/bevy_reflect/bevy_reflect_derive/src/type_path.rs (L76))
in enum variant name that I didn't fix. Enum is `pub(crate)`, so there
shouldn't be any trouble if fixed. However, code is tightly coupled with
macro usage, so I decided to leave it for more experienced contributor
just in case.
		
	
			
		
			
				
	
	
		
			67 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use crate::{
 | |
|     component::Component,
 | |
|     entity::{Entity, EntityMap, EntityMapper, MapEntities},
 | |
|     world::World,
 | |
| };
 | |
| use bevy_reflect::FromType;
 | |
| 
 | |
| /// For a specific type of component, this maps any fields with values of type [`Entity`] to a new world.
 | |
| /// Since a given `Entity` ID is only valid for the world it came from, when performing deserialization
 | |
| /// any stored IDs need to be re-allocated in the destination world.
 | |
| ///
 | |
| /// See [`MapEntities`] for more information.
 | |
| #[derive(Clone)]
 | |
| pub struct ReflectMapEntities {
 | |
|     map_all_entities: fn(&mut World, &mut EntityMapper),
 | |
|     map_entities: fn(&mut World, &mut EntityMapper, &[Entity]),
 | |
| }
 | |
| 
 | |
| impl ReflectMapEntities {
 | |
|     /// A general method for applying [`MapEntities`] behavior to all elements in an [`EntityMap`].
 | |
|     ///
 | |
|     /// Be mindful in its usage: Works best in situations where the entities in the [`EntityMap`] are newly
 | |
|     /// created, before systems have a chance to add new components. If some of the entities referred to
 | |
|     /// by the [`EntityMap`] might already contain valid entity references, you should use [`map_entities`](Self::map_entities).
 | |
|     ///
 | |
|     /// An example of this: A scene can be loaded with `Parent` components, but then a `Parent` component can be added
 | |
|     /// to these entities after they have been loaded. If you reload the scene using [`map_all_entities`](Self::map_all_entities), those `Parent`
 | |
|     /// components with already valid entity references could be updated to point at something else entirely.
 | |
|     pub fn map_all_entities(&self, world: &mut World, entity_map: &mut EntityMap) {
 | |
|         entity_map.world_scope(world, self.map_all_entities);
 | |
|     }
 | |
| 
 | |
|     /// A general method for applying [`MapEntities`] behavior to elements in an [`EntityMap`]. Unlike
 | |
|     /// [`map_all_entities`](Self::map_all_entities), this is applied to specific entities, not all values
 | |
|     /// in the [`EntityMap`].
 | |
|     ///
 | |
|     /// This is useful mostly for when you need to be careful not to update components that already contain valid entity
 | |
|     /// values. See [`map_all_entities`](Self::map_all_entities) for more details.
 | |
|     pub fn map_entities(&self, world: &mut World, entity_map: &mut EntityMap, entities: &[Entity]) {
 | |
|         entity_map.world_scope(world, |world, mapper| {
 | |
|             (self.map_entities)(world, mapper, entities);
 | |
|         });
 | |
|     }
 | |
| }
 | |
| 
 | |
| impl<C: Component + MapEntities> FromType<C> for ReflectMapEntities {
 | |
|     fn from_type() -> Self {
 | |
|         ReflectMapEntities {
 | |
|             map_entities: |world, entity_mapper, entities| {
 | |
|                 for &entity in entities {
 | |
|                     if let Some(mut component) = world.get_mut::<C>(entity) {
 | |
|                         component.map_entities(entity_mapper);
 | |
|                     }
 | |
|                 }
 | |
|             },
 | |
|             map_all_entities: |world, entity_mapper| {
 | |
|                 let entities = entity_mapper.get_map().values().collect::<Vec<Entity>>();
 | |
|                 for entity in &entities {
 | |
|                     if let Some(mut component) = world.get_mut::<C>(*entity) {
 | |
|                         component.map_entities(entity_mapper);
 | |
|                     }
 | |
|                 }
 | |
|             },
 | |
|         }
 | |
|     }
 | |
| }
 |