fix for ice-editor types

data will be seperated later
This commit is contained in:
kruschen 2024-08-26 21:05:25 +00:00
parent 509fc8ca0b
commit 09591a180b

View file

@ -16,7 +16,7 @@ export function open() {
closeDialogs(".stable");
if (!layerIsOn("toggleIce")) toggleLayer("toggleIce");
elSelected = d3.select(d3.event.target);
const elSelected = d3.select<SVGPolygonElement, any>(d3.event.target);
const type = elSelected.attr("type") ? "Glacier" : "Iceberg";
if (byId("iceRandomize")) byId("iceRandomize")!.style.display = type === "Glacier" ? "none" : "inline-block";
@ -26,7 +26,7 @@ export function open() {
$iceSize.style.display = type === "Glacier" ? "none" : "inline-block";
if (type === "Iceberg") $iceSize.value = elSelected.attr("size");
}
ice.selectAll("*").classed("draggable", true).call(d3.drag().on("drag", dragElement));
ice.selectAll<SVGPolygonElement, any>("*").classed("draggable", true).on("drag", dragElement);
$("#iceEditor").dialog({
title: "Edit " + type,
@ -53,7 +53,7 @@ export function open() {
const cn = grid.points[i];
const poly = getGridPolygon(i).map(p => [p[0] - cn[0], p[1] - cn[1]]);
const points = poly.map(p => [rn(c[0] + p[0] * s, 2), rn(c[1] + p[1] * s, 2)]);
elSelected.attr("points", points);
elSelected.attr("points", points.flat().toString());
}
function changeSize(this: HTMLInputElement) {
@ -69,13 +69,13 @@ export function open() {
const poly = pairs.map(p => [(p[0] - c[0]) / s, (p[1] - c[1]) / s]);
const size = +this.value;
const points = poly.map(p => [rn(c[0] + p[0] * size, 2), rn(c[1] + p[1] * size, 2)]);
elSelected.attr("points", points).attr("size", size);
elSelected.attr("points", points.toString()).attr("size", size);
}
function toggleAdd() {
byId("iceNew")?.classList.toggle("pressed");
if (byId("iceNew")?.classList.contains("pressed")) {
viewbox.style("cursor", "crosshair").on("click", addIcebergOnClick);
viewbox.style("cursor", "crosshair").on("click",() => addIcebergOnClick);
tip("Click on map to create an iceberg. Hold Shift to add multiple", true);
} else {
clearMainTip();
@ -90,8 +90,8 @@ export function open() {
const s = getInputNumber("iceSize");
const points = getGridPolygon(i).map(p => [(p[0] + (c[0] - p[0]) / s) | 0, (p[1] + (c[1] - p[1]) / s) | 0]);
const iceberg = ice.append("polygon").attr("points", points).attr("cell", i).attr("size", s);
iceberg.call(d3.drag().on("drag", dragElement));
const iceberg = ice.append("polygon").attr("points", points.flat().toString()).attr("cell", i).attr("size", s);
iceberg.on("drag", dragElement);
if (d3.event.shiftKey === false) toggleAdd();
}
@ -114,7 +114,7 @@ export function open() {
});
}
function dragElement(this: Element) {
function dragElement(this: SVGPolygonElement) {
const tr = parseTransform(this.getAttribute("transform"));
const dx = +tr[0] - d3.event.x;
const dy = +tr[1] - d3.event.y;
@ -126,7 +126,7 @@ export function open() {
}
function closeEditor() {
ice.selectAll("*").classed("draggable", false).call(d3.drag().on("drag", null));
ice.selectAll("*").classed("draggable", false).on("drag", null);
clearMainTip();
byId("iceNew")?.classList.remove("pressed");
unselect();