import { assert } from "../../../../core/assert.js";
import { noop } from "../../../../core/function/noop.js";
import Terrain from "../ecs/Terrain.js";

/**
 *
 * @param {EntityComponentDataset} ecd
 * @param {function(terrain:Terrain,entity:number)} [callback]
 * @returns {Terrain|null}
 */
export function obtainTerrain(ecd, callback=noop) {
    assert.notEqual(ecd, null, 'ecd is null');
    assert.notEqual(ecd, undefined, 'ecd is undefined');

    const object = ecd.getAnyComponent(Terrain);

    const terrain = object.component;

        callback(terrain, object.entity);

    return terrain;
}
