mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
feat(religions editor): debouce center dragging
This commit is contained in:
parent
3ce0481a49
commit
218887b435
2 changed files with 28 additions and 9 deletions
|
|
@ -590,16 +590,23 @@ function drawCultureCenters() {
|
|||
}
|
||||
|
||||
function cultureCenterDrag() {
|
||||
const $el = d3.select(this);
|
||||
const cultureId = +this.id.slice(13);
|
||||
d3.event.on("drag", () => {
|
||||
const tr = parseTransform(this.getAttribute("transform"));
|
||||
const x0 = +tr[0] - d3.event.x;
|
||||
const y0 = +tr[1] - d3.event.y;
|
||||
|
||||
function handleDrag() {
|
||||
const {x, y} = d3.event;
|
||||
$el.attr("cx", x).attr("cy", y);
|
||||
this.setAttribute("transform", `translate(${x0 + x},${y0 + y})`);
|
||||
const cell = findCell(x, y);
|
||||
if (pack.cells.h[cell] < 20) return; // ignore dragging on water
|
||||
|
||||
pack.cultures[cultureId].center = cell;
|
||||
recalculateCultures();
|
||||
});
|
||||
}
|
||||
|
||||
const dragDebounced = debounce(handleDrag, 50);
|
||||
d3.event.on("drag", dragDebounced);
|
||||
}
|
||||
|
||||
function toggleLegend() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue