mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
refactor: fix burgId issue
This commit is contained in:
parent
ec6285a7a4
commit
bc98757b96
8 changed files with 62 additions and 41 deletions
|
|
@ -5,13 +5,28 @@ import {round} from "utils/stringUtils";
|
|||
export function drawRoutes() {
|
||||
routes.selectAll("path").remove();
|
||||
|
||||
const {cells, burgs} = pack;
|
||||
const lineGen = d3.line().curve(d3.curveBasis);
|
||||
|
||||
const getBurgCoords = (burgId: number): TPoint => {
|
||||
if (!burgId) throw new Error("burgId must be positive");
|
||||
const burg = burgs[burgId] as IBurg;
|
||||
return [burg.x, burg.y];
|
||||
};
|
||||
|
||||
const getPathPoints = (cellIds: number[]): TPoints =>
|
||||
cellIds.map(cellId => {
|
||||
const burgId = cells.burg[cellId];
|
||||
if (burgId) return getBurgCoords(burgId);
|
||||
|
||||
return cells.p[cellId];
|
||||
});
|
||||
|
||||
const routePaths: Dict<string[]> = {};
|
||||
|
||||
for (const {i, type, cells: routeCells} of pack.routes) {
|
||||
const points = routeCells.map(cellId => pack.cells.p[cellId]);
|
||||
const path = round(lineGen(points)!);
|
||||
const points = getPathPoints(routeCells);
|
||||
const path = round(lineGen(points)!, 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