mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix: routes id after removing all
This commit is contained in:
parent
106d5edc78
commit
9c97711a99
6 changed files with 15 additions and 10 deletions
|
|
@ -434,7 +434,7 @@ window.Routes = (function () {
|
|||
const points = getPoints("trails", pathCells, pointsArray);
|
||||
const feature = cells.f[cellId];
|
||||
|
||||
const routeId = Math.max(...routes.map(route => route.i)) + 1;
|
||||
const routeId = getNextId();
|
||||
const newRoute = {i: routeId, group: "trails", feature, points};
|
||||
routes.push(newRoute);
|
||||
|
||||
|
|
@ -706,6 +706,10 @@ window.Routes = (function () {
|
|||
return path.getTotalLength();
|
||||
}
|
||||
|
||||
function getNextId() {
|
||||
return pack.routes.length ? Math.max(...pack.routes.map(r => r.i)) + 1 : 0;
|
||||
}
|
||||
|
||||
function remove(route) {
|
||||
const routes = pack.cells.routes;
|
||||
|
||||
|
|
@ -738,6 +742,7 @@ window.Routes = (function () {
|
|||
generateName,
|
||||
getPath,
|
||||
getLength,
|
||||
getNextId,
|
||||
remove
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ function createRoute(defaultGroup) {
|
|||
const points = createRoute.points;
|
||||
if (points.length < 2) return tip("Add at least 2 points", false, "error");
|
||||
|
||||
const routeId = Math.max(...pack.routes.map(route => route.i)) + 1;
|
||||
const routeId = Routes.getNextId();
|
||||
const group = byId("routeCreatorGroupSelect").value;
|
||||
const feature = pack.cells.f[points[0][2]];
|
||||
const route = {points, group, feature, i: routeId};
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ function editRoute(id) {
|
|||
|
||||
// create new route
|
||||
const newRoute = {
|
||||
i: Math.max(...pack.routes.map(route => route.i)) + 1,
|
||||
i: Routes.getNextId(),
|
||||
group: route.group,
|
||||
feature: route.feature,
|
||||
name: route.name,
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ function overviewRoutes() {
|
|||
|
||||
// update footer
|
||||
routesFooterNumber.innerHTML = pack.routes.length;
|
||||
const averageLength = rn(d3.mean(pack.routes.map(r => r.length)));
|
||||
const averageLength = rn(d3.mean(pack.routes.map(r => r.length)) || 0);
|
||||
routesFooterLength.innerHTML = averageLength * distanceScale + " " + distanceUnitInput.value;
|
||||
|
||||
// add listeners
|
||||
|
|
@ -175,8 +175,8 @@ function overviewRoutes() {
|
|||
pack.routes = [];
|
||||
routes.selectAll("path").remove();
|
||||
|
||||
routesOverviewAddLines();
|
||||
$(this).dialog("close");
|
||||
$("#routesOverview").dialog("close");
|
||||
},
|
||||
Cancel: function () {
|
||||
$(this).dialog("close");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue