This commit is contained in:
Reimar 2024-08-16 23:45:52 +02:00
parent 8caff387a7
commit 1225f8da24

View File

@ -164,15 +164,35 @@ window.addEventListener("mousedown", event => {
draw();
});
window.addEventListener("wheel", event => {
if (event.shiftKey) {
scrollX += event.deltaY;
} else {
scrollX += event.deltaX;
scrollY += event.deltaY;
function columnContainsOnlyUnrevealed(column) {
return column.every(cell => !cell.isRevealed);
}
// TODO create new rows/columns on scroll
window.addEventListener("wheel", event => {
let deltaX = 0, deltaY = 0;
if (event.shiftKey) {
deltaX = event.deltaY;
} else {
deltaX = event.deltaX;
deltaY = event.deltaY;
}
console.log(scrollY + deltaY + window.innerHeight, board.length * CELL_SIZE);
if (scrollY + deltaY + window.innerHeight > board.length * CELL_SIZE) {
if (board.slice(-20).every(columnContainsOnlyUnrevealed)) {
console.log("ignoring");
return;
}
const diff = scrollY + window.innerHeight - board.length * CELL_SIZE;
for (let i = 0; i < diff + CELL_SIZE; i += CELL_SIZE)
createRowAtBottom();
}
scrollX += deltaX;
scrollY += deltaY;
draw();
});