package com.zombie.game.systems;

import com.zombie.game.ecs.ECSWorld;
import com.zombie.game.ecs.System;
import com.zombie.game.ecs.components.Position;
import com.zombie.game.model.GameMap;

import java.util.ArrayList;
import java.util.List;

/** Updates flow field each frame based on player positions / 每帧根据玩家位置更新流场 */
public class FlowFieldUpdateSystem implements System {

    @Override
    public void update(float dt, ECSWorld world) {
        GameMap map = world.getMap();

        List<float[]> playerPositions = new ArrayList<>();
        for (int entityId : world.getPlayers()) {
            Position pos = world.getPositions().get(entityId);
            if (pos != null) {
                playerPositions.add(new float[]{pos.getX(), pos.getY()});
            }
        }

        if (!playerPositions.isEmpty()) {
            map.updateFlowField(playerPositions);
        }
    }
}
