import { Effect } from "../components/effect";
import { Component, System, type Entity, type World } from "../core/world";

export class EffectSystem extends System {
    override update(world: World, dt: number) {
        const expired: [Entity, Component<any>][] = [];

        for (const [entity, , effect] of world.query(Effect)) {
            effect.update(dt);
            if (effect.state.remaining !== null && effect.state.remaining <= 0) {
                expired.push([entity, effect]);
            }
        }

        for (const [entity, key] of expired) {
            entity.remove(key);
        }
    }
}
