refactor: submap - UI update

This commit is contained in:
Azgaar 2024-10-20 02:29:10 +02:00
parent 431a5aa3e9
commit 6e38c93841
4 changed files with 22 additions and 48 deletions

View file

@ -38,37 +38,22 @@ function openSubmapTool() {
populationRate = populationRateInput.value = rn(populationRate / scale, 2);
const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)};
const options = {
smoothHeightmap: byId("submapSmoothHeightmap").checked,
depressRivers: byId("submapDepressRivers").checked,
projection: (x, y) => [(x - x0) * scale, (y - y0) * scale],
inverse: (x, y) => [x / scale + x0, y / scale + y0],
scale
};
const smoothHeightmap = byId("submapSmoothHeightmap").checked;
const depressRivers = byId("submapDepressRivers").checked;
const projection = (x, y) => [(x - x0) * scale, (y - y0) * scale];
const inverse = (x, y) => [x / scale + x0, y / scale + y0];
const options = {smoothHeightmap, depressRivers, projection, inverse, scale};
resetZoom(0);
undraw();
const oldScale = scale;
await Submap.resample(parentMap, options);
if (byId("submapPromoteTowns").checked) {
const groupName = "largetowns";
moveAllBurgsToGroup("towns", groupName);
changeRadius(rn(oldScale * 0.8, 2), groupName);
changeFontSize(svg.select(`#labels #${groupName}`), rn(oldScale * 2, 2));
invokeActiveZooming();
}
if (byId("submapRescaleStyles").checked) changeStyles(oldScale);
rescaleBurgStyles(scale);
drawLayers();
INFO && console.groupEnd("generateSubmap");
}
function changeStyles(scale) {
// resize burgIcons
function rescaleBurgStyles(scale) {
const burgIcons = [...byId("burgIcons").querySelectorAll("g")];
for (const bi of burgIcons) {
const newRadius = rn(minmax(bi.getAttribute("size") * scale, 0.2, 10), 2);
@ -77,13 +62,10 @@ function openSubmapTool() {
swAttr.value = +swAttr.value * scale;
}
// burglabels
const burgLabels = [...byId("burgLabels").querySelectorAll("g")];
for (const bl of burgLabels) {
const size = +bl.dataset["size"];
bl.dataset["size"] = Math.max(rn((size + size / scale) / 2, 2), 1) * scale;
}
drawEmblems();
}
}

View file

@ -123,13 +123,13 @@ async function openTransformTool() {
async function transformMap() {
INFO && console.group("transformMap");
const cellsNumber = +byId("transformPointsInput").value;
changeCellsDensity(cellsNumber);
const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)};
const [projection, inverse] = getProjection();
const options = {depressRivers: false, smoothHeightmap: false, scale: 1, inverse, projection};
const cellsNumber = +byId("transformPointsInput").value;
changeCellsDensity(cellsNumber);
resetZoom(0);
undraw();
await Submap.resample(parentMap, options);