use glam::Quat;

use crate::components::RotateComponent;
use crate::utility::transform::Transform;
use crate::world::Storage;

pub fn rotate_system(
    rotates: &Storage<RotateComponent>,
    transforms: &mut Storage<Transform>,
    delta: f32,
)
{
    let entities = rotates.all();

    for entity in entities
    {
        if let Some(rotate) = rotates.get(entity)
        {
            let rotation_delta = Quat::from_axis_angle(rotate.axis, rotate.speed * delta);

            transforms.with_mut(entity, |transform| {
                transform.rotation = rotation_delta * transform.rotation;
            });
        }
    }
}
