diff --git a/index.html b/index.html
index 621428ac..a448ac30 100644
--- a/index.html
+++ b/index.html
@@ -7824,7 +7824,7 @@
-
+
@@ -7858,8 +7858,8 @@
-
-
+
+
diff --git a/main.js b/main.js
index 36a59cae..69323e92 100644
--- a/main.js
+++ b/main.js
@@ -692,7 +692,7 @@ async function generate(options) {
applyMapSize();
randomizeOptions();
- if (shouldRegenerateGrid(grid)) grid = precreatedGraph || generateGrid();
+ if (shouldRegenerateGrid(grid, precreatedSeed)) grid = precreatedGraph || generateGrid();
else delete grid.cells.h;
grid.cells.h = await HeightmapGenerator.generate(grid);
@@ -774,12 +774,10 @@ async function generate(options) {
function setSeed(precreatedSeed) {
if (!precreatedSeed) {
const first = !mapHistory[0];
- const url = new URL(window.location.href);
- const params = url.searchParams;
- const urlSeed = url.searchParams.get("seed");
+ const params = new URL(window.location.href).searchParams;
+ const urlSeed = params.get("seed");
if (first && params.get("from") === "MFCG" && urlSeed.length === 13) seed = urlSeed.slice(0, -4);
else if (first && urlSeed) seed = urlSeed;
- else if (optionsSeed.value && optionsSeed.value != seed) seed = optionsSeed.value;
else seed = generateSeed();
} else {
seed = precreatedSeed;
diff --git a/modules/dynamic/heightmap-selection.js b/modules/dynamic/heightmap-selection.js
index 9b78d118..2fb3ba7c 100644
--- a/modules/dynamic/heightmap-selection.js
+++ b/modules/dynamic/heightmap-selection.js
@@ -262,7 +262,7 @@ function getName(id) {
}
function getGraph(currentGraph) {
- const newGraph = shouldRegenerateGrid(currentGraph) ? generateGrid() : deepCopy(currentGraph);
+ const newGraph = shouldRegenerateGrid(currentGraph, seed) ? generateGrid() : deepCopy(currentGraph);
delete newGraph.cells.h;
return newGraph;
}
diff --git a/modules/ui/options.js b/modules/ui/options.js
index c072d1cb..f8ccfb38 100644
--- a/modules/ui/options.js
+++ b/modules/ui/options.js
@@ -257,8 +257,8 @@ function testSpeaker() {
}
function generateMapWithSeed() {
- if (optionsSeed.value == seed) return tip("The current map already has this seed", false, "error");
- regeneratePrompt();
+ if (optionsSeed.value === seed) return tip("The current map already has this seed", false, "error");
+ regeneratePrompt({seed: optionsSeed.value});
}
function showSeedHistoryDialog() {
@@ -288,7 +288,7 @@ function restoreSeed(id) {
if (locked("template")) unlock("template");
- regeneratePrompt();
+ regeneratePrompt({seed});
}
function restoreDefaultZoomExtent() {
diff --git a/utils/graphUtils.js b/utils/graphUtils.js
index 75b64253..c6315088 100644
--- a/utils/graphUtils.js
+++ b/utils/graphUtils.js
@@ -2,7 +2,9 @@
// FMG utils related to graph
// check if new grid graph should be generated or we can use the existing one
-function shouldRegenerateGrid(grid) {
+function shouldRegenerateGrid(grid, expectedSeed) {
+ if (expectedSeed && expectedSeed !== grid.seed) return true;
+
const cellsDesired = +byId("pointsInput").dataset.cells;
if (cellsDesired !== grid.cellsDesired) return true;
@@ -17,7 +19,7 @@ function generateGrid() {
Math.random = aleaPRNG(seed); // reset PRNG
const {spacing, cellsDesired, boundary, points, cellsX, cellsY} = placePoints();
const {cells, vertices} = calculateVoronoi(points, boundary);
- return {spacing, cellsDesired, boundary, points, cellsX, cellsY, cells, vertices};
+ return {spacing, cellsDesired, boundary, points, cellsX, cellsY, cells, vertices, seed};
}
// place random points to calculate Voronoi diagram
@@ -96,7 +98,10 @@ function getJitteredGrid(width, height, spacing) {
// return cell index on a regular square grid
function findGridCell(x, y, grid) {
- return Math.floor(Math.min(y / grid.spacing, grid.cellsY - 1)) * grid.cellsX + Math.floor(Math.min(x / grid.spacing, grid.cellsX - 1));
+ return (
+ Math.floor(Math.min(y / grid.spacing, grid.cellsY - 1)) * grid.cellsX +
+ Math.floor(Math.min(x / grid.spacing, grid.cellsX - 1))
+ );
}
// return array of cell indexes in radius on a regular square grid
@@ -246,7 +251,14 @@ void (function addFindAll() {
i++;
// Stop searching if this quadrant can’t contain a closer node.
- if (!(t.node = t.q.node) || (t.x1 = t.q.x0) > t.x3 || (t.y1 = t.q.y0) > t.y3 || (t.x2 = t.q.x1) < t.x0 || (t.y2 = t.q.y1) < t.y0) continue;
+ if (
+ !(t.node = t.q.node) ||
+ (t.x1 = t.q.x0) > t.x3 ||
+ (t.y1 = t.q.y0) > t.y3 ||
+ (t.x2 = t.q.x1) < t.x0 ||
+ (t.y2 = t.q.y1) < t.y0
+ )
+ continue;
// Bisect the current quadrant.
if (t.node.length) {
diff --git a/versioning.js b/versioning.js
index 9467d1b5..ee613a00 100644
--- a/versioning.js
+++ b/versioning.js
@@ -1,7 +1,7 @@
"use strict";
// version and caching control
-const version = "1.88.01"; // generator version, update each time
+const version = "1.88.02"; // generator version, update each time
{
document.title += " v" + version;