Skip to content

Instantly share code, notes, and snippets.

@smokku
Created December 12, 2020 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smokku/b19fbce0a312b2a2e22d5cef4450fcd8 to your computer and use it in GitHub Desktop.
Save smokku/b19fbce0a312b2a2e22d5cef4450fcd8 to your computer and use it in GitHub Desktop.
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, &registry)
};
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