use crate::world::World;

pub fn state_machine_system(world: &mut World, delta: f32)
{
    let entities: Vec<_> = world.state_machines.all();

    for entity in entities
    {
        if let Some(mut state_machine) = world.state_machines.components.remove(&entity)
        {
            state_machine.update(world, delta);
            world
                .state_machines
                .components
                .insert(entity, state_machine);
        }
    }
}

pub fn state_machine_physics_system(world: &mut World, delta: f32)
{
    let entities: Vec<_> = world.state_machines.all();

    for entity in entities
    {
        if let Some(mut state_machine) = world.state_machines.components.remove(&entity)
        {
            if let Some(current_state) = state_machine.get_current_state_mut()
            {
                current_state.on_state_physics_update(world, delta);
            }
            world
                .state_machines
                .components
                .insert(entity, state_machine);
        }
    }
}
