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

@ -5772,15 +5772,7 @@
Don't forget to save the .map file to your machine first! Don't forget to save the .map file to your machine first!
</p> </p>
<p>Settings to be changed: population rate, map pixel size</p> <p>Options:</p>
<p>
Data to be copied: heightmap, biomes, religions, population, precipitation, cultures, states, provinces,
military regiments
</p>
<p>Data to be regenerated: zones, routes, rivers</p>
<p>Burgs may be remapped incorrectly, manual change is required</p>
<p>Experimental features:</p>
<div data-tip="Smooth heightmap to get more natural terrain"> <div data-tip="Smooth heightmap to get more natural terrain">
<input id="submapSmoothHeightmap" class="checkbox" type="checkbox" checked /> <input id="submapSmoothHeightmap" class="checkbox" type="checkbox" checked />
<label for="submapSmoothHeightmap" class="checkbox-label">Smooth heightmap</label> <label for="submapSmoothHeightmap" class="checkbox-label">Smooth heightmap</label>
@ -5789,14 +5781,6 @@
<input id="submapDepressRivers" class="checkbox" type="checkbox" checked /> <input id="submapDepressRivers" class="checkbox" type="checkbox" checked />
<label for="submapDepressRivers" class="checkbox-label">Erode riverbeds</label> <label for="submapDepressRivers" class="checkbox-label">Erode riverbeds</label>
</div> </div>
<div data-tip="Rescale styles (burg labels, emblem size) to match the new scale">
<input id="submapRescaleStyles" class="checkbox" type="checkbox" checked />
<label for="submapRescaleStyles" class="checkbox-label">Rescale styles</label>
</div>
<div data-tip="Move all existing towns to the 'largetown' burg group">
<input id="submapPromoteTowns" class="checkbox" type="checkbox" />
<label for="submapPromoteTowns" class="checkbox-label">Promote towns to largetowns</label>
</div>
</div> </div>
<div id="transformTool" style="display: none" class="dialog"> <div id="transformTool" style="display: none" class="dialog">

View file

@ -45,11 +45,10 @@ window.Submap = (function () {
restoreRoutes(parentMap, projection); restoreRoutes(parentMap, projection);
restoreReligions(parentMap, projection); restoreReligions(parentMap, projection);
restoreProvinces(parentMap); restoreProvinces(parentMap);
restoreRiverDetails(parentMap, inverse);
restoreFeatureDetails(parentMap, inverse);
restoreMarkers(parentMap, projection); restoreMarkers(parentMap, projection);
restoreZones(parentMap, projection, options); restoreZones(parentMap, projection, options);
restoreFeatureDetails(parentMap, inverse);
Rivers.specify();
showStatistics(); showStatistics();
} }
@ -277,6 +276,15 @@ window.Submap = (function () {
}); });
} }
// TODO: actually restore rivers
function restoreRiverDetails(parentMap, inverse) {
pack.rivers.forEach(river => {
river.basin = Rivers.getBasin(river.i);
river.name = Rivers.getName(river.mouth);
river.type = Rivers.getType(river);
});
}
function restoreFeatureDetails(parentMap, inverse) { function restoreFeatureDetails(parentMap, inverse) {
pack.features.forEach(feature => { pack.features.forEach(feature => {
if (!feature) return; if (!feature) return;

View file

@ -38,37 +38,22 @@ function openSubmapTool() {
populationRate = populationRateInput.value = rn(populationRate / scale, 2); populationRate = populationRateInput.value = rn(populationRate / scale, 2);
const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)}; const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)};
const options = { const smoothHeightmap = byId("submapSmoothHeightmap").checked;
smoothHeightmap: byId("submapSmoothHeightmap").checked, const depressRivers = byId("submapDepressRivers").checked;
depressRivers: byId("submapDepressRivers").checked, const projection = (x, y) => [(x - x0) * scale, (y - y0) * scale];
projection: (x, y) => [(x - x0) * scale, (y - y0) * scale], const inverse = (x, y) => [x / scale + x0, y / scale + y0];
inverse: (x, y) => [x / scale + x0, y / scale + y0], const options = {smoothHeightmap, depressRivers, projection, inverse, scale};
scale
};
resetZoom(0); resetZoom(0);
undraw(); undraw();
const oldScale = scale;
await Submap.resample(parentMap, options); await Submap.resample(parentMap, options);
rescaleBurgStyles(scale);
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);
drawLayers(); drawLayers();
INFO && console.groupEnd("generateSubmap"); INFO && console.groupEnd("generateSubmap");
} }
function changeStyles(scale) { function rescaleBurgStyles(scale) {
// resize burgIcons
const burgIcons = [...byId("burgIcons").querySelectorAll("g")]; const burgIcons = [...byId("burgIcons").querySelectorAll("g")];
for (const bi of burgIcons) { for (const bi of burgIcons) {
const newRadius = rn(minmax(bi.getAttribute("size") * scale, 0.2, 10), 2); const newRadius = rn(minmax(bi.getAttribute("size") * scale, 0.2, 10), 2);
@ -77,13 +62,10 @@ function openSubmapTool() {
swAttr.value = +swAttr.value * scale; swAttr.value = +swAttr.value * scale;
} }
// burglabels
const burgLabels = [...byId("burgLabels").querySelectorAll("g")]; const burgLabels = [...byId("burgLabels").querySelectorAll("g")];
for (const bl of burgLabels) { for (const bl of burgLabels) {
const size = +bl.dataset["size"]; const size = +bl.dataset["size"];
bl.dataset["size"] = Math.max(rn((size + size / scale) / 2, 2), 1) * scale; 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() { async function transformMap() {
INFO && console.group("transformMap"); INFO && console.group("transformMap");
const cellsNumber = +byId("transformPointsInput").value;
changeCellsDensity(cellsNumber);
const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)}; const parentMap = {grid: deepCopy(grid), pack: deepCopy(pack), notes: deepCopy(notes)};
const [projection, inverse] = getProjection(); const [projection, inverse] = getProjection();
const options = {depressRivers: false, smoothHeightmap: false, scale: 1, inverse, projection}; const options = {depressRivers: false, smoothHeightmap: false, scale: 1, inverse, projection};
const cellsNumber = +byId("transformPointsInput").value;
changeCellsDensity(cellsNumber);
resetZoom(0); resetZoom(0);
undraw(); undraw();
await Submap.resample(parentMap, options); await Submap.resample(parentMap, options);