Created
December 12, 2020 23:31
-
-
Save smokku/b19fbce0a312b2a2e22d5cef4450fcd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mut registry = TypeRegistryInternal::default(); | |
registry.register::<f32>(); | |
registry.register::<bool>(); | |
registry.register::<Vec2>(); | |
registry.register::<components::Position>(); | |
registry.register::<components::KineticBody>(); | |
... | |
for entity in entities.iter() { | |
if let Some(location) = world.get_entity_location(*entity) { | |
let archetype = &world.archetypes[location.archetype as usize]; | |
for type_info in archetype.types() { | |
if let Some(registration) = registry.get(type_info.id()) { | |
if let Some(reflect_component) = | |
registration.data::<ReflectComponent>() | |
{ | |
let serializer = unsafe { | |
let component = reflect_component | |
.reflect_component(&archetype, location.index); | |
ReflectSerializer::new(component, ®istry) | |
}; | |
let json = serde_json::to_string(&serializer).unwrap(); | |
// This allows to introspect and serialize components tagged with: | |
#[derive(Debug, Reflect, Copy, Clone)] | |
#[reflect(Component)] | |
pub struct SomeComponent { | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment