export let buildingGrid = [];
export function createBuildingGrid(severity, width = 30, height = 20) {
const styles = [
"default", "cabin", "skyscraper", "pillars", "roman",
"stripes", "windows", "battlements", "zigzag", "tower",
"step-pyramid", "arch", "roof", "blocky", "industrial",
"grid", "frame", "modern", "lighthouse", "castle",
"barn", "hut", "crenellations", "glass", "hex"
];
const style = styles[Math.floor(Math.random() * styles.length)];
const grid = Array.from({ length: height }, () =>
Array.from({ length: width }, () => 0)
);
const fillPoints = [];
// Helper to queue fill points based on style logic
function draw(fx) {
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
if (fx(x, y)) {
fillPoints.push([y, x]);
}
}
}
}
const stylesMap = {
default: () => draw(() => true),
cabin: () => draw((x, y) => x > 5 && x < 24 && y > 10 && y < 18),
skyscraper: () => draw((x, y) => x === 14 || x === 15 || y % 2 === 0),
pillars: () => draw((x, y) => x % 3 === 0),
roman: () => draw((x, y) => y === 0 || y === height - 1 || x % 4 === 0),
stripes: () => draw((x, y) => y % 2 === 0),
windows: () => draw((x, y) => x % 3 === 1 && y % 2 === 1),
battlements: () => draw((x, y) => y === 0 || (y === 1 && x % 2 === 0)),
zigzag: () => draw((x, y) => (x + y) % 5 === 0),
tower: () => draw((x, y) => x === 14 || x === 15),
"step-pyramid": () => draw((x, y) => x >= y && x < width - y),
arch: () => draw((x, y) => y === height - 1 || (y < 3 && x % 4 === 0)),
roof: () => draw((x, y) => y >= 18 || y === Math.abs(15 - x)),
blocky: () => draw((x, y) => x % 2 === 0 && y % 2 === 0),
industrial: () => draw((x, y) => x % 4 === 0 && y % 3 === 0),
grid: () => draw((x, y) => x % 2 === 0 || y % 2 === 0),
frame: () => draw((x, y) => x === 0 || x === width - 1 || y === 0 || y === height - 1),
modern: () => draw((x, y) => (x + y) % 3 === 0),
lighthouse: () => draw((x, y) => x === Math.floor(width / 2)),
castle: () => draw((x, y) => y === height - 1 || (y === 0 && x % 3 !== 1)),
barn: () => draw((x, y) => y > 12 && y < 18 && x > 10 && x < 20),
hut: () => draw((x, y) => y > 14 && x === Math.floor(width / 2)),
crenellations: () => draw((x, y) => y === height - 1 || (y === 0 && x % 2 === 0)),
glass: () => draw((x, y) => (x + y) % 2 === 0),
hex: () => draw((x, y) => (x + y) % 6 === 0 || (x - y + width) % 6 === 0)
};
if (stylesMap[style]) stylesMap[style]();
// Shuffle and limit the fill points to match severity
fillPoints.sort(() => Math.random() - 0.5);
const limitedPoints = fillPoints.slice(0, severity);
for (const [y, x] of limitedPoints) {
grid[y][x] = 1;
}
buildingGrid = grid;
console.log(`Generated style: ${style}, 1s placed: ${limitedPoints.length}`);
//Replace items chars in grid string until its in correct format
var grid_Out
grid_Out = '{"c2array":true,"size":[30,20,1],"data":' + (JSON.stringify(grid)) +"}";
console.log(grid_Out);
return (grid_Out);
}