refactor: drawCells

This commit is contained in:
Azgaar 2024-09-05 01:10:35 +02:00
parent bfc83e8f7b
commit 289620615f

View file

@ -364,22 +364,17 @@ function toggleCells(event) {
drawCells(); drawCells();
if (event && isCtrlClick(event)) editStyle("cells"); if (event && isCtrlClick(event)) editStyle("cells");
} else { } else {
if (event && isCtrlClick(event)) { if (event && isCtrlClick(event)) return editStyle("cells");
editStyle("cells");
return;
}
cells.selectAll("path").remove(); cells.selectAll("path").remove();
turnButtonOff("toggleCells"); turnButtonOff("toggleCells");
} }
} }
function drawCells() { function drawCells() {
cells.selectAll("path").remove(); const cells = customization === 1 ? grid.cells.i : pack.cells.i;
const data = customization === 1 ? grid.cells.i : pack.cells.i;
const polygon = customization === 1 ? getGridPolygon : getPackPolygon; const polygon = customization === 1 ? getGridPolygon : getPackPolygon;
let path = ""; const paths = Array.from(cells).map(i => "M" + polygon(i));
data.forEach(i => (path += "M" + polygon(i))); byId("cells").innerHTML = `<path d="${paths.join("")}" />`;
cells.append("path").attr("d", path);
} }
function toggleIce(event) { function toggleIce(event) {