From 8dad1a3bac0059d163a4cb1a05dd9318f163d126 Mon Sep 17 00:00:00 2001 From: Azgaar Date: Thu, 17 Apr 2025 13:11:23 +0200 Subject: [PATCH] fix(routes): connect new burg to land route only --- modules/burgs-generator.js | 9 +-------- modules/routes-generator.js | 3 ++- modules/ui/layers.js | 8 ++++++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/burgs-generator.js b/modules/burgs-generator.js index 4cb36481..3769972b 100644 --- a/modules/burgs-generator.js +++ b/modules/burgs-generator.js @@ -547,14 +547,7 @@ window.Burgs = (() => { cells.burg[cellId] = burgId; const newRoute = Routes.connect(cellId); - if (newRoute && layerIsOn("toggleRoutes")) { - const path = Routes.getPath(newRoute); - routes - .select("#" + newRoute.group) - .append("path") - .attr("d", path) - .attr("id", "route" + newRoute.i); - } + if (newRoute && layerIsOn("toggleRoutes")) drawRoute(newRoute); drawBurgIcon(burg); drawBurgLabel(burg); diff --git a/modules/routes-generator.js b/modules/routes-generator.js index 562eed14..4454b8ff 100644 --- a/modules/routes-generator.js +++ b/modules/routes-generator.js @@ -360,7 +360,8 @@ window.Routes = (function () { // connect cell with routes system by land function connect(cellId) { const getCost = createCostEvaluator({isWater: false, connections: new Map()}); - const pathCells = findPath(cellId, isConnected, getCost); + const isExit = cellId => isLand(cellId) && isConnected(cellId); + const pathCells = findPath(cellId, isExit, getCost); if (!pathCells) return; const pointsArray = preparePointsArray(); diff --git a/modules/ui/layers.js b/modules/ui/layers.js index a1e3b503..5037a5ee 100644 --- a/modules/ui/layers.js +++ b/modules/ui/layers.js @@ -845,6 +845,14 @@ function drawRoutes() { TIME && console.timeEnd("drawRoutes"); } +function drawRoute(route) { + routes + .select("#" + route.group) + .append("path") + .attr("d", Routes.getPath(route)) + .attr("id", "route" + route.i); +} + function toggleMilitary(event) { if (!layerIsOn("toggleMilitary")) { turnButtonOn("toggleMilitary");