import { getGroup, getPrefab, addTo } from '.';
/**
 * Returns a group with grass_plane_01/terrain_plane_01 placed in a grid that makes up the getGround.
 * @param  opt.hilly optional, should the getGround be hilly or not? If set to 0 the getGround is flat. 0.1 creates a slightly hilly plane, 10 makes it very hilly. Default = 0
 * @param opt.repeatX, optional, number of objects should be repeated on the x axis in the grid creating the getGround. Default = 3
 * @param opt.repeatY, optional, number of objects should be repeated on the y axis in the grid creating the getGround.  Default = 3
 * @param opt.material, optional, material to put on the getGround. Default = t_grass_01
 * @example
 * ```
 * const grd = getGround({ hilly: 0.1 });
 * addTo(rootObject, grd);
 * ```
 */
export const getGround = (opt = {}) => {
    const val = {
        p: [0, 0, 0],
        s: [1, 1, 1],
        r: [0, 0, 0],
        children: [],
        hilly: 0,
        prefabId: undefined,
        width: 50,
        repeatX: 4,
        repeatZ: 4,
        material: 't_grass_01',
        water: false,
        waterOffset: 0,
        ...opt,
    };
    const wrapper = getGroup({ p: val.p, s: val.s, r: val.r });
    let id = (val.hilly === 0 ? 'grass_plane_01' : 'terrain_plane_01'); // plane_terrain_01
    if (val.prefabId) {
        id = val.prefabId;
    }
    const hilly = opt.hilly || 0;
    const scale = opt.hilly === 0 ? 1 : 1 + hilly;
    const yPos = val.hilly === 0 ? -2 : scale * -1;
    const width = val.width;
    const depth = width;
    const offsetX = width * (val.repeatX - 1) * 0.5;
    const offsetZ = depth * (val.repeatZ - 1) * 0.5;
    const waterScale = (6.25 * val.width) / 50;
    const waterY = val.hilly === 0 ? yPos + 0.1 : -2.8 - hilly * 2.3;
    for (let indexX = 0; indexX < val.repeatX; indexX++) {
        for (let indexZ = 0; indexZ < val.repeatZ; indexZ++) {
            const obj = getPrefab({
                id: id,
                p: [indexX * width - offsetX, yPos, indexZ * depth - offsetZ],
                s: [1, scale, 1],
                material: val.material,
            });
            addTo(wrapper, obj);
            if (val.water) {
                const water = getPrefab({
                    id: 'water_plane_01',
                    p: [indexX * width - offsetX, waterY + val.waterOffset, indexZ * depth - offsetZ],
                    s: [waterScale, scale, waterScale],
                });
                addTo(wrapper, water);
            }
        }
    }
    return wrapper;
};
//# sourceMappingURL=getGround.js.map