import { addTo } from './addTo';
import { getGroup } from './getGroup';
import { getPrefab } from './getPrefab';
import { random90Deg } from './utils/random90Deg';
import { rsd } from './utils/randomSeed';
/**
 * Constructs a skyscraper using randomly assembled building blocks.
 * If needed, alter building by setting seed value
 * @example
 * ```ts
  addTo(root, getSkyScraper({ p: [0, 0, 50], seed: 42 }));
 * ```
  Or define building blocks
 * @example
 * ```
  addTo(root, getSkyScraper({ p: [0, 0, 50], bottom: 0, middle: 1, top: 2 }));
 * ```
 */
export const getSkyScraper = (opt = {}) => {
    opt = { ...opt };
    let bottoms = [
        {
            id: 'en_m_hiberpunk_building_01_bottom',
            height: 20,
        },
        {
            id: 'en_m_hiberpunk_building_02_bottom',
            height: 20,
        },
        {
            id: 'en_m_hiberpunk_building_03_bottom',
            height: 20,
        },
    ];
    let middles = [
        {
            id: 'en_m_hiberpunk_building_01_middle',
            height: 50,
        },
        {
            id: 'en_m_hiberpunk_building_02_middle',
            height: 50,
        },
        {
            id: 'en_m_hiberpunk_building_02_middle_02',
            height: 50,
        },
        {
            id: 'en_m_hiberpunk_building_01_middle_02',
            height: 50,
        },
        {
            id: 'en_m_hiberpunk_building_03_middle',
            height: 50,
        },
    ];
    let tops = [
        {
            id: 'en_m_hiberpunk_building_01_top',
            height: 20,
        },
        {
            id: 'en_m_hiberpunk_building_02_top',
            height: 20,
        },
        {
            id: 'en_m_hiberpunk_building_03_top',
            height: 20,
        },
    ];
    const angles = [0, 90, 180, 270];
    const skyScraper = getGroup(opt);
    const seed = opt.seed || undefined;
    let height = 0;
    let bottomPart = opt.bottom !== undefined ? bottoms[opt.bottom] : rsd(seed).randomFromArray(bottoms);
    const bottom = getPrefab({ id: bottomPart.id, p: [0, height, 0], r: [0, random90Deg(seed), 0] });
    addTo(skyScraper, bottom);
    height += bottomPart.height;
    if (opt.middle !== undefined) {
        let middlePart = middles[opt.middle];
        const middle = getPrefab({ id: middlePart.id, p: [0, height, 0], r: [0, random90Deg(seed), 0] });
        addTo(skyScraper, middle);
        height += middlePart.height;
    }
    else {
        let noMiddleFloors = rsd(seed).randomFromArray([0, 1, 1, 1, 2, 2, 3]);
        for (let index = 0; index < noMiddleFloors; index++) {
            let middlePart = rsd(seed).randomFromArray(middles);
            const middle = getPrefab({ id: middlePart.id, p: [0, height, 0], r: [0, random90Deg(seed), 0] });
            addTo(skyScraper, middle);
            height += middlePart.height;
        }
    }
    let topPart = opt.top !== undefined ? tops[opt.top] : rsd(seed).randomFromArray(tops);
    const top = getPrefab({ id: topPart.id, p: [0, height, 0], r: [0, random90Deg(seed), 0] });
    addTo(skyScraper, top);
    height += topPart.height;
    return skyScraper;
};
//# sourceMappingURL=getSkyScraper.js.map