mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-16 17:31:24 +01:00
fix: regenerate grid if seed is manually changed (1.88.02)
This commit is contained in:
parent
0b1a2048a7
commit
425325888e
6 changed files with 27 additions and 17 deletions
|
|
@ -7824,7 +7824,7 @@
|
|||
<script src="utils/commonUtils.js"></script>
|
||||
<script src="utils/arrayUtils.js"></script>
|
||||
<script src="utils/colorUtils.js"></script>
|
||||
<script src="utils/graphUtils.js"></script>
|
||||
<script src="utils/graphUtils.js?v=1.88.02"></script>
|
||||
<script src="utils/nodeUtils.js"></script>
|
||||
<script src="utils/numberUtils.js"></script>
|
||||
<script src="utils/polyfills.js"></script>
|
||||
|
|
@ -7858,8 +7858,8 @@
|
|||
<script src="modules/ui/stylePresets.js"></script>
|
||||
|
||||
<script src="modules/ui/general.js?v=1.87.00"></script>
|
||||
<script src="modules/ui/options.js?v=1.87.15"></script>
|
||||
<script src="main.js?v=1.87.15"></script>
|
||||
<script src="modules/ui/options.js?v=1.88.02"></script>
|
||||
<script src="main.js?v=1.88.02"></script>
|
||||
|
||||
<script defer src="modules/relief-icons.js"></script>
|
||||
<script defer src="modules/ui/style.js"></script>
|
||||
|
|
|
|||
8
main.js
8
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue