mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-21 19:41:23 +01:00
feat: routes - auto-update part 1
This commit is contained in:
parent
da2d6fc584
commit
126393fea3
3 changed files with 41 additions and 7 deletions
3
main.js
3
main.js
|
|
@ -1176,7 +1176,6 @@ function reGraph() {
|
|||
for (const i of gridCells.i) {
|
||||
const height = gridCells.h[i];
|
||||
const type = gridCells.t[i];
|
||||
const isOnBorder = gridCells.b[i];
|
||||
|
||||
// exclude most of ocean points
|
||||
if (height < 20) {
|
||||
|
|
@ -1195,7 +1194,7 @@ function reGraph() {
|
|||
|
||||
// add additional points for cells along coast
|
||||
if (type === 1 || type === -1) {
|
||||
if (isOnBorder) continue; // not for near-border cells
|
||||
if (gridCells.b[i]) continue; // not for near-border cells
|
||||
gridCells.c[i].forEach(function (e) {
|
||||
if (i > e) return;
|
||||
if (gridCells.t[e] === type) {
|
||||
|
|
|
|||
|
|
@ -863,10 +863,44 @@ export function resolveVersionConflicts(version) {
|
|||
|
||||
if (version < 1.99) {
|
||||
// v1.99.00 changed routes generation algorithm and data format
|
||||
// 1. cells.road => cells.routes and now it an object of objects {i1: {i2: routeId, i3: routeId}}
|
||||
// 2. cells.crossroad is removed
|
||||
// 3. pack.routes is added as an array of objects
|
||||
// 4. rendering is changed
|
||||
// v1.98.00 changed compass layer and rose element id
|
||||
delete cells.road;
|
||||
delete cells.crossroad;
|
||||
|
||||
pack.routes = [];
|
||||
pack.cells.routes = {};
|
||||
|
||||
const POINT_DISTANCE = 10;
|
||||
|
||||
routes.selectAll("g").each(function () {
|
||||
const group = this.id;
|
||||
if (!group) return;
|
||||
|
||||
for (const node of this.querySelectorAll("path")) {
|
||||
const totalLength = node.getTotalLength();
|
||||
if (!totalLength) debugger;
|
||||
const increment = totalLength / Math.ceil(totalLength / POINT_DISTANCE);
|
||||
const points = [];
|
||||
|
||||
for (let i = 0; i <= totalLength; i += increment) {
|
||||
const point = node.getPointAtLength(i);
|
||||
const x = rn(point.x, 2);
|
||||
const y = rn(point.y, 2);
|
||||
const cellId = findCell(x, y);
|
||||
points.push([x, y, cellId]);
|
||||
}
|
||||
|
||||
if (points.length < 2) return;
|
||||
|
||||
const secondCellId = points[1][2];
|
||||
const feature = pack.cells.f[secondCellId];
|
||||
|
||||
pack.routes.push({i: pack.routes.length, group, feature, points});
|
||||
}
|
||||
});
|
||||
|
||||
console.log(pack.routes);
|
||||
|
||||
routes.selectAll("path").remove();
|
||||
if (layerIsOn("toggleRoutes")) drawRoutes();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ const version = "1.99.00"; // generator version, update each time
|
|||
<ul>
|
||||
<strong>Latest changes:</strong>
|
||||
<li>New routes generatation algorithm</li>
|
||||
<li>Routes overview tool</li>
|
||||
<li>Configurable longitude</li>
|
||||
<li>Preview villages map</li>
|
||||
<li>Ability to render ocean heightmap</li>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue