mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: roads generation - fix route segment detection
This commit is contained in:
parent
1dd185354b
commit
fc3e3b844d
2 changed files with 52 additions and 35 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import * as d3 from "d3";
|
||||
import {drawPoint} from "utils/debugUtils";
|
||||
|
||||
import {round} from "utils/stringUtils";
|
||||
|
||||
|
|
@ -22,11 +23,21 @@ export function drawRoutes() {
|
|||
return cells.p[cellId];
|
||||
});
|
||||
|
||||
const normalizePoints = (points: TPoints): TPoints =>
|
||||
points.map(([x, y], index) => {
|
||||
return [x, y];
|
||||
|
||||
if (i === 17) {
|
||||
cells.forEach(cellId => drawPoint(pack.cells.p[cellId]));
|
||||
}
|
||||
});
|
||||
|
||||
const routePaths: Dict<string[]> = {};
|
||||
|
||||
for (const {i, type, cells} of pack.routes) {
|
||||
const points = getPathPoints(cells);
|
||||
const path = round(lineGen(points)!, 1);
|
||||
const normalizedPoints = normalizePoints(points);
|
||||
const path = round(lineGen(normalizedPoints)!, 1);
|
||||
|
||||
if (!routePaths[type]) routePaths[type] = [];
|
||||
routePaths[type].push(`<path id="${type}${i}" d="${path}"/>`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue