use crate::physics::PhysicsManager;
use crate::utility::transform::Transform;
use crate::world::World;

pub fn physics_sync_system(world: &mut World)
{
    let all_entities = world.entities.all_entities();

    for entity in all_entities
    {
        if let Some(physics) = world.physics.get(entity)
        {
            if let Some(rigidbody_position) =
                PhysicsManager::get_rigidbody_position(physics.rigidbody)
            {
                let transform = Transform::from(rigidbody_position);

                world.transforms.with_mut(entity, |t| {
                    *t = transform;
                });
            }
        }
    }
}
