mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix: features - define first cell
This commit is contained in:
parent
6d3b88b36f
commit
97e504d2aa
3 changed files with 27 additions and 11 deletions
|
|
@ -8115,7 +8115,7 @@
|
||||||
<script defer src="modules/io/cloud.js?v=1.99.00"></script>
|
<script defer src="modules/io/cloud.js?v=1.99.00"></script>
|
||||||
<script defer src="modules/io/export.js?v=1.100.00"></script>
|
<script defer src="modules/io/export.js?v=1.100.00"></script>
|
||||||
|
|
||||||
<script defer src="modules/renderers/draw-features.js?v=1.104.0"></script>
|
<script defer src="modules/renderers/draw-features.js?v=1.104.15"></script>
|
||||||
<script defer src="modules/renderers/draw-borders.js?v=1.104.0"></script>
|
<script defer src="modules/renderers/draw-borders.js?v=1.104.0"></script>
|
||||||
<script defer src="modules/renderers/draw-heightmap.js?v=1.104.0"></script>
|
<script defer src="modules/renderers/draw-heightmap.js?v=1.104.0"></script>
|
||||||
<script defer src="modules/renderers/draw-markers.js?v=1.104.0"></script>
|
<script defer src="modules/renderers/draw-markers.js?v=1.104.0"></script>
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,6 @@ window.Features = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
features.push(addFeature({firstCell, land, border, featureId, totalCells}));
|
features.push(addFeature({firstCell, land, border, featureId, totalCells}));
|
||||||
|
|
||||||
queue[0] = featureIds.findIndex(f => f === UNMARKED); // find unmarked cell
|
queue[0] = featureIds.findIndex(f => f === UNMARKED); // find unmarked cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,7 +154,7 @@ window.Features = (function () {
|
||||||
|
|
||||||
function addFeature({firstCell, land, border, featureId, totalCells}) {
|
function addFeature({firstCell, land, border, featureId, totalCells}) {
|
||||||
const type = land ? "island" : border ? "ocean" : "lake";
|
const type = land ? "island" : border ? "ocean" : "lake";
|
||||||
const featureVertices = type === "ocean" ? [] : getFeatureVertices(firstCell);
|
const [startCell, featureVertices] = getCellsData(type, firstCell);
|
||||||
const points = clipPoly(featureVertices.map(vertex => vertices.p[vertex]));
|
const points = clipPoly(featureVertices.map(vertex => vertices.p[vertex]));
|
||||||
const area = d3.polygonArea(points); // feature perimiter area
|
const area = d3.polygonArea(points); // feature perimiter area
|
||||||
const absArea = Math.abs(rn(area));
|
const absArea = Math.abs(rn(area));
|
||||||
|
|
@ -165,8 +164,8 @@ window.Features = (function () {
|
||||||
type,
|
type,
|
||||||
land,
|
land,
|
||||||
border,
|
border,
|
||||||
firstCell,
|
|
||||||
cells: totalCells,
|
cells: totalCells,
|
||||||
|
firstCell: startCell,
|
||||||
vertices: featureVertices,
|
vertices: featureVertices,
|
||||||
area: absArea
|
area: absArea
|
||||||
};
|
};
|
||||||
|
|
@ -179,22 +178,39 @@ window.Features = (function () {
|
||||||
|
|
||||||
return feature;
|
return feature;
|
||||||
|
|
||||||
function getFeatureVertices(firstCell) {
|
function getCellsData(featureType, firstCell) {
|
||||||
|
if (featureType === "ocean") return [firstCell, []];
|
||||||
|
|
||||||
const getType = cellId => featureIds[cellId];
|
const getType = cellId => featureIds[cellId];
|
||||||
const type = getType(firstCell);
|
const type = getType(firstCell);
|
||||||
const ofSameType = cellId => getType(cellId) === type;
|
const ofSameType = cellId => getType(cellId) === type;
|
||||||
const ofDifferentType = cellId => getType(cellId) !== type;
|
const ofDifferentType = cellId => getType(cellId) !== type;
|
||||||
|
|
||||||
const isOnBorder = borderCells[firstCell] || neighbors[firstCell].some(ofDifferentType);
|
const startCell = findOnBorderCell(firstCell);
|
||||||
if (!isOnBorder) throw new Error(`Markup: firstCell ${firstCell} is not on the feature or map border`);
|
const featureVertices = getFeatureVertices(startCell);
|
||||||
|
return [startCell, featureVertices];
|
||||||
|
|
||||||
const startingVertex = cells.v[firstCell].find(v => vertices.c[v].some(ofDifferentType));
|
function findOnBorderCell(firstCell) {
|
||||||
if (startingVertex === undefined) throw new Error(`Markup: startingVertex for cell ${firstCell} is not found`);
|
const isOnBorder = cellId => borderCells[cellId] || neighbors[cellId].some(ofDifferentType);
|
||||||
|
if (isOnBorder(firstCell)) return firstCell;
|
||||||
|
|
||||||
|
const startCell = cells.i.filter(ofSameType).find(isOnBorder);
|
||||||
|
if (startCell === undefined)
|
||||||
|
throw new Error(`Markup: firstCell ${firstCell} is not on the feature or map border`);
|
||||||
|
|
||||||
|
return startCell;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFeatureVertices(startCell) {
|
||||||
|
const startingVertex = cells.v[startCell].find(v => vertices.c[v].some(ofDifferentType));
|
||||||
|
if (startingVertex === undefined)
|
||||||
|
throw new Error(`Markup: startingVertex for cell ${startCell} is not found`);
|
||||||
|
|
||||||
return connectVertices({vertices, startingVertex, ofSameType, closeRing: false});
|
return connectVertices({vertices, startingVertex, ofSameType, closeRing: false});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add properties to pack features
|
// add properties to pack features
|
||||||
function specify() {
|
function specify() {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
*
|
*
|
||||||
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
|
* Example: 1.102.2 -> Major version 1, Minor version 102, Patch version 2
|
||||||
*/
|
*/
|
||||||
const VERSION = "1.104.14";
|
const VERSION = "1.104.15";
|
||||||
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
|
if (parseMapVersion(VERSION) !== VERSION) alert("versioning.js: Invalid format or parsing function");
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue