fix ice selection(hopefully)

This commit is contained in:
StempunkDev 2026-01-13 19:50:00 +01:00
parent f726c911b8
commit 959e49b255

View file

@ -23,7 +23,7 @@ function editIce() {
}); });
if (modules.editIce) return; if (modules.editIce) return;
modules.editIce = true; modules.editIce = { currentIndex: index };
// add listeners // add listeners
document.getElementById("iceEditStyle").addEventListener("click", () => editStyle("ice")); document.getElementById("iceEditStyle").addEventListener("click", () => editStyle("ice"));
@ -33,17 +33,19 @@ function editIce() {
document.getElementById("iceRemove").addEventListener("click", removeIce); document.getElementById("iceRemove").addEventListener("click", removeIce);
function randomizeShape() { function randomizeShape() {
Ice.randomizeIcebergShape(index); const idx = modules.editIce.currentIndex;
Ice.randomizeIcebergShape(idx);
redrawIce(); redrawIce();
elSelected = ice.selectAll(`[data-index="${index}"]`).node(); elSelected = ice.selectAll(`[data-index="${idx}"]`).node();
elSelected = d3.select(elSelected); elSelected = d3.select(elSelected);
} }
function changeSize() { function changeSize() {
const newSize = +this.value; const newSize = +this.value;
Ice.changeIcebergSize(index, newSize); const idx = modules.editIce.currentIndex;
Ice.changeIcebergSize(idx, newSize);
redrawIce(); redrawIce();
elSelected = ice.selectAll(`[data-index="${index}"]`).node(); elSelected = ice.selectAll(`[data-index="${idx}"]`).node();
elSelected = d3.select(elSelected); elSelected = d3.select(elSelected);
} }
@ -117,6 +119,10 @@ function editIce() {
clearMainTip(); clearMainTip();
iceNew.classList.remove("pressed"); iceNew.classList.remove("pressed");
unselect(); unselect();
// Clean up handlers
if (modules.editIce && typeof modules.editIce === "object") {
modules.editIce = false;
}
} }
} }