mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
heightmap selection - refactor, make generation immutable to get predictable result
This commit is contained in:
parent
8ea89111fc
commit
b6a1012753
4 changed files with 18 additions and 4 deletions
|
|
@ -323,14 +323,14 @@ async function drawPrecreatedHeightmap(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawTemplatePreview(id) {
|
function drawTemplatePreview(id) {
|
||||||
const heights = generateHeightmap(id);
|
const heights = HeightmapGenerator.fromTemplate(graph, id);
|
||||||
const dataUrl = drawHeights(heights);
|
const dataUrl = drawHeights(heights);
|
||||||
const article = byId("heightmapSelection").querySelector(`[data-id="${id}"]`);
|
const article = byId("heightmapSelection").querySelector(`[data-id="${id}"]`);
|
||||||
article.querySelector("img").src = dataUrl;
|
article.querySelector("img").src = dataUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function drawPrecreatedHeightmap(id) {
|
async function drawPrecreatedHeightmap(id) {
|
||||||
const heights = await HeightmapGenerator.fromPrecreated(id);
|
const heights = await HeightmapGenerator.fromPrecreated(graph, id);
|
||||||
const dataUrl = drawHeights(heights);
|
const dataUrl = drawHeights(heights);
|
||||||
const article = byId("heightmapSelection").querySelector(`[data-id="${id}"]`);
|
const article = byId("heightmapSelection").querySelector(`[data-id="${id}"]`);
|
||||||
article.querySelector("img").src = dataUrl;
|
article.querySelector("img").src = dataUrl;
|
||||||
|
|
|
||||||
|
|
@ -510,7 +510,6 @@ window.HeightmapGenerator = (function () {
|
||||||
const powered = lightness < 0.2 ? lightness : 0.2 + (lightness - 0.2) ** 0.8;
|
const powered = lightness < 0.2 ? lightness : 0.2 + (lightness - 0.2) ** 0.8;
|
||||||
heights[i] = minmax(Math.floor(powered * 100), 0, 100);
|
heights[i] = minmax(Math.floor(powered * 100), 0, 100);
|
||||||
}
|
}
|
||||||
return heights;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ window.Submap = (function () {
|
||||||
// create new grid
|
// create new grid
|
||||||
applyMapSize();
|
applyMapSize();
|
||||||
grid = generateGrid();
|
grid = generateGrid();
|
||||||
|
|
||||||
drawScaleBar(scale);
|
drawScaleBar(scale);
|
||||||
|
|
||||||
const resampler = (points, qtree, f) => {
|
const resampler = (points, qtree, f) => {
|
||||||
|
|
|
||||||
|
|
@ -96,3 +96,19 @@ function deepCopy(obj) {
|
||||||
|
|
||||||
return dcAny(obj);
|
return dcAny(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTypedArray(maxValue) {
|
||||||
|
console.assert(
|
||||||
|
Number.isInteger(maxValue) && maxValue >= 0 && maxValue <= 4294967295,
|
||||||
|
`Array maxValue must be an integer between 0 and 4294967295, got ${maxValue}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (maxValue <= 255) return Uint8Array;
|
||||||
|
if (maxValue <= 65535) return Uint16Array;
|
||||||
|
if (maxValue <= 4294967295) return Uint32Array;
|
||||||
|
return Uint32Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createTypedArray({maxValue, length}) {
|
||||||
|
return new (getTypedArray(maxValue))(length);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue