mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
prettify
This commit is contained in:
parent
5703e62177
commit
ae0979fc68
3 changed files with 6211 additions and 4539 deletions
|
|
@ -15,7 +15,9 @@ function openSubmapOptions() {
|
|||
$(this).dialog("close");
|
||||
generateSubmap();
|
||||
},
|
||||
Cancel: function () { $(this).dialog("close"); },
|
||||
Cancel: function () {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -29,18 +31,20 @@ function openRemapOptions() {
|
|||
position: {my: "right top", at: "right-10 top+10", of: "svg", collision: "fit"},
|
||||
buttons: {
|
||||
Resample: function () {
|
||||
const cellNumId = Number(document.getElementById('submapPointsInput').value);
|
||||
const cellNumId = Number(document.getElementById("submapPointsInput").value);
|
||||
const cells = cellsDensityConstants[cellNumId];
|
||||
$(this).dialog("close");
|
||||
if (!cells) {
|
||||
console.error('Unknown cell number!');
|
||||
console.error("Unknown cell number!");
|
||||
return;
|
||||
}
|
||||
changeCellsDensity(cellNumId);
|
||||
resampleCurrentMap();
|
||||
},
|
||||
Cancel: function () { $(this).dialog("close"); },
|
||||
},
|
||||
Cancel: function () {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -56,21 +60,20 @@ const resampleCurrentMap = debounce(function () {
|
|||
addLakesInDepressions: false,
|
||||
promoteTowns: false,
|
||||
smoothHeightMap: false,
|
||||
projection: (x,y) => [x, y],
|
||||
inverse: (x,y) => [x, y],
|
||||
}
|
||||
projection: (x, y) => [x, y],
|
||||
inverse: (x, y) => [x, y]
|
||||
};
|
||||
|
||||
startResample(options);
|
||||
}, 1000);
|
||||
|
||||
|
||||
const generateSubmap = debounce(function () {
|
||||
// Create submap from the current map
|
||||
// submap limits defined by the current window size (canvas viewport)
|
||||
|
||||
WARN && console.warn("Resampling current map");
|
||||
closeDialogs("#worldConfigurator, #options3d");
|
||||
const checked = id => Boolean(document.getElementById(id).checked)
|
||||
const checked = id => Boolean(document.getElementById(id).checked);
|
||||
// Create projection func from current zoom extents
|
||||
const [[x0, y0], [x1, y1]] = getViewBoxExtent();
|
||||
|
||||
|
|
@ -82,28 +85,27 @@ const generateSubmap = debounce(function () {
|
|||
addLakesInDepressions: checked("submapAddLakeInDepression"),
|
||||
promoteTowns: checked("submapPromoteTowns"),
|
||||
smoothHeightMap: scale > 2,
|
||||
inverse: (x,y) => [x * (x1-x0) / graphWidth + x0, y * (y1-y0) / graphHeight + y0],
|
||||
projection: (x, y) => [(x-x0) * graphWidth / (x1-x0), (y-y0) * graphHeight / (y1-y0)],
|
||||
}
|
||||
inverse: (x, y) => [(x * (x1 - x0)) / graphWidth + x0, (y * (y1 - y0)) / graphHeight + y0],
|
||||
projection: (x, y) => [((x - x0) * graphWidth) / (x1 - x0), ((y - y0) * graphHeight) / (y1 - y0)]
|
||||
};
|
||||
|
||||
// converting map position on the planet
|
||||
const mapSizeOutput = document.getElementById("mapSizeOutput");
|
||||
const latitudeOutput = document.getElementById("latitudeOutput");
|
||||
const latN = 90 - (180 - mapSizeInput.value / 100 * 180) * latitudeOutput.value / 100;
|
||||
const newLatN = latN - y0 / graphHeight * mapSizeOutput.value * 180 / 100;
|
||||
const latN = 90 - ((180 - (mapSizeInput.value / 100) * 180) * latitudeOutput.value) / 100;
|
||||
const newLatN = latN - ((y0 / graphHeight) * mapSizeOutput.value * 180) / 100;
|
||||
mapSizeOutput.value /= scale;
|
||||
latitudeOutput.value = (90 - newLatN) / (180 - mapSizeOutput.value / 100 * 180) * 100;
|
||||
latitudeOutput.value = ((90 - newLatN) / (180 - (mapSizeOutput.value / 100) * 180)) * 100;
|
||||
document.getElementById("mapSizeInput").value = mapSizeOutput.value;
|
||||
document.getElementById("latitudeInput").value = latitudeOutput.value;
|
||||
|
||||
// fix scale
|
||||
distanceScaleInput.value = distanceScaleOutput.value = rn(distanceScale = distanceScaleOutput.value / scale, 2);
|
||||
populationRateInput.value = populationRateOutput.value = rn(populationRate = populationRateOutput.value / scale, 2);
|
||||
distanceScaleInput.value = distanceScaleOutput.value = rn((distanceScale = distanceScaleOutput.value / scale), 2);
|
||||
populationRateInput.value = populationRateOutput.value = rn((populationRate = populationRateOutput.value / scale), 2);
|
||||
customization = 0;
|
||||
startResample(options);
|
||||
}, 1000);
|
||||
|
||||
|
||||
async function startResample(options) {
|
||||
undraw();
|
||||
resetZoom(0);
|
||||
|
|
@ -112,17 +114,17 @@ async function startResample(options) {
|
|||
pack: deepCopy(pack),
|
||||
seed,
|
||||
graphWidth,
|
||||
graphHeight,
|
||||
graphHeight
|
||||
};
|
||||
|
||||
try {
|
||||
const oldScale = scale;
|
||||
await Submap.resample(oldstate, options);
|
||||
if (options.promoteTowns) {
|
||||
const groupName = 'largetowns';
|
||||
moveAllBurgsToGroup('towns', groupName);
|
||||
changeRadius(rn(oldScale * 0.8,2), groupName);
|
||||
changeFontSize(svg.select(`#labels #${groupName}`), rn(oldScale*2, 2));
|
||||
const groupName = "largetowns";
|
||||
moveAllBurgsToGroup("towns", groupName);
|
||||
changeRadius(rn(oldScale * 0.8, 2), groupName);
|
||||
changeFontSize(svg.select(`#labels #${groupName}`), rn(oldScale * 2, 2));
|
||||
invokeActiveZooming();
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
@ -132,7 +134,7 @@ async function startResample(options) {
|
|||
oldstate = null; // destroy old state to free memory
|
||||
|
||||
restoreLayers();
|
||||
turnButtonOn('toggleMarkers');
|
||||
turnButtonOn("toggleMarkers");
|
||||
if (ThreeD.options.isOn) ThreeD.redraw();
|
||||
if ($("#worldConfigurator").is(":visible")) editWorld();
|
||||
}
|
||||
|
|
@ -149,7 +151,9 @@ function showSubmapErrorHandler(error) {
|
|||
title: "Generation error",
|
||||
width: "32em",
|
||||
buttons: {
|
||||
Ok: function () { $(this).dialog("close"); }
|
||||
Ok: function () {
|
||||
$(this).dialog("close");
|
||||
}
|
||||
},
|
||||
position: {my: "center", at: "center", of: "svg"}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue