use crate::ecs::world::World;

pub fn update_particle_emitters(world: &mut World, delta_time: f32) {
    let emitter_entities: Vec<_> = world.query_entities(crate::ecs::PARTICLE_EMITTER).collect();

    for entity in emitter_entities {
        if let Some(emitter) = world.get_particle_emitter_mut(entity) {
            if !emitter.enabled {
                continue;
            }

            if emitter.one_shot && emitter.has_fired {
                continue;
            }

            if emitter.burst_count > 0 && !emitter.has_fired {
                emitter.accumulated_spawn = emitter.burst_count as f32;
                emitter.has_fired = true;
            } else if emitter.spawn_rate > 0.0 {
                emitter.accumulated_spawn += emitter.spawn_rate * delta_time;
            }
        }
    }
}
