river edit - allow to move river to occupied cells

This commit is contained in:
Azgaar 2021-08-02 20:51:54 +03:00
parent 9c68c2b09e
commit ca5aefaf15
2 changed files with 9 additions and 20 deletions

View file

@ -991,12 +991,6 @@ body button.noicon {
stroke-width: 0.4;
}
#controlCells > .occupied {
fill: #ff828240;
stroke: #ff8282;
stroke-width: 0.4;
}
#vertices > circle {
fill: #ff0000;
stroke: #841f1f;

View file

@ -124,18 +124,13 @@ function editRiver(id) {
const initCell = +this.dataset.cell;
const index = +this.dataset.i;
const occupiedCells = i.filter(i => r[i] && !river.cells.includes(i));
drawCells(occupiedCells, "occupied");
let movedToCell = null;
d3.event.on("drag", function () {
const {x, y} = d3.event;
const currentCell = findCell(x, y);
if (initCell !== currentCell) {
if (occupiedCells.includes(currentCell)) return;
movedToCell = currentCell;
} else movedToCell = null;
movedToCell = initCell !== currentCell ? currentCell : null;
this.setAttribute("cx", x);
this.setAttribute("cy", y);
@ -149,6 +144,7 @@ function editRiver(id) {
river.cells[index] = movedToCell;
drawCells(river.cells, "current");
if (!r[movedToCell]) {
// swap river data
r[initCell] = 0;
r[movedToCell] = river.i;
@ -156,8 +152,7 @@ function editRiver(id) {
fl[initCell] = fl[movedToCell];
fl[movedToCell] = sourceFlux;
}
debug.select("#controlCells").selectAll("polygon.available, polygon.occupied").remove();
}
});
}