An experimental, status effects-as-entities system for Bevy.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Final cleanup.

+22 -6
+1 -1
Cargo.toml
··· 24 24 bevy_time = { version = "0.18", default-features = false, features = [ 25 25 "bevy_reflect", 26 26 ] } 27 - bevy_utils = { version = "0.18.1", default-features = false } 27 + bevy_utils = { version = "0.18", default-features = false } 28 28 29 29 [dev-dependencies] 30 30 bevy = "0.18"
+21 -5
src/bundle_inspector.rs
··· 87 87 /// 88 88 /// # Errors 89 89 /// Will return an error if: 90 + /// - The component is not registered in `dst_world`. 90 91 /// - The component cannot be cloned ([`ComponentCloneBehavior::Ignore`]). 91 92 /// - The stashed bundle doesn't contain the component. 92 93 /// - The destination entity doesn't exist in `dst_world`. 94 + /// - The resource AppTypeRegistry doesn't exist in `dst_world`. 93 95 /// 94 96 /// # Safety 95 97 /// `src_component_id` must be for the same component as `type_id`. ··· 100 102 type_id: TypeId, 101 103 src_component_id: ComponentId, 102 104 ) -> Result<&Self, MultiWorldCopyError> { 103 - // 104 - let dst_component_id = dst_world.components().get_id(type_id).unwrap(); 105 + let Some(dst_component_id) = dst_world.components().get_id(type_id) else { 106 + return Err(MultiWorldCopyError::Unregistered(type_id)); 107 + }; 105 108 let component_info = dst_world.components().get_info(dst_component_id).unwrap(); 106 109 107 110 match component_info.clone_behavior() { ··· 124 127 let dst = alloc(component_info.layout()); 125 128 126 129 // SAFETY: `dst` is allocated from the component's layout. 127 - // Both IDs provided by the caller must match, and `src` and `dst` obtained using the IDs. 130 + // Both IDs provided by the caller must match, and `src` and `dst` are obtained using those IDs. 128 131 // `src` and `dst` are from different worlds, so cannot overlap. 129 132 copy_nonoverlapping(src.as_ptr(), dst, component_info.layout().size()); 130 133 134 + // SAFETY: Both IDs provided by the caller must match, and `dst` was created from `src`. 131 135 let owning = OwningPtr::new(NonNull::new(dst).unwrap()); 132 136 133 137 // SAFETY: `existing_component_id` is extracted from `dst_world`. 134 - // Both IDs provided by the caller must match, `owning` was obtained using `src_component_id`. 138 + // Both IDs provided by the caller must match, and `owning` was obtained using `src_component_id`. 135 139 dst_world 136 140 .get_entity_mut(dst_entity) 137 141 .map_err(|_| MultiWorldCopyError::MissingDstEntity(dst_entity))? 138 142 .insert_by_id(dst_component_id, owning); 139 143 } 140 144 } else { 141 - let registry = dst_world.resource::<AppTypeRegistry>().clone(); 145 + let Some(registry) = dst_world.get_resource::<AppTypeRegistry>().cloned() else { 146 + return Err(MultiWorldCopyError::MissingTypeRegistry); 147 + }; 142 148 let registry = registry.read(); 143 149 144 150 let reflect_component = registry ··· 160 166 161 167 #[derive(Debug, Eq, PartialEq, Clone)] 162 168 pub enum MultiWorldCopyError { 169 + Unregistered(TypeId), 163 170 Uncloneable(DebugName), 164 171 MissingDstEntity(Entity), 165 172 MissingSrcComponent(DebugName, Entity), 173 + MissingTypeRegistry, 166 174 } 167 175 168 176 impl std::fmt::Display for MultiWorldCopyError { 169 177 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 170 178 match self { 179 + MultiWorldCopyError::Unregistered(type_id) => write!( 180 + f, 181 + "Component with {type_id:?} is not registered in the destination world, and therefor cannot be inserted using merge mode.", 182 + ), 171 183 MultiWorldCopyError::Uncloneable(name) => write!( 172 184 f, 173 185 "Component {name} cannot be cloned, and therefor cannot be inserted using merge mode.", ··· 179 191 MultiWorldCopyError::MissingSrcComponent(name, entity) => write!( 180 192 f, 181 193 "Component {name} does not exist on the scratch entity {entity}, and therefor cannot be cloned.", 194 + ), 195 + MultiWorldCopyError::MissingTypeRegistry => write!( 196 + f, 197 + "Resource AppTypeRegistry does not exist in the destination world, and therefor no components can be cloned.", 182 198 ), 183 199 } 184 200 }