diff --git a/index.html b/index.html index 733d2513..131ea67f 100644 --- a/index.html +++ b/index.html @@ -2996,6 +2996,7 @@ class="icon-chart-area" > + - + + diff --git a/modules/routes-generator.js b/modules/routes-generator.js index 0926a6c3..c5a88988 100644 --- a/modules/routes-generator.js +++ b/modules/routes-generator.js @@ -2,15 +2,17 @@ const ROUTES_SHARP_ANGLE = 135; const ROUTES_VERY_SHARP_ANGLE = 115; window.Routes = (function () { - function generate() { + function generate(lockedRoutes = []) { const {capitalsByFeature, burgsByFeature, portsByFeature} = sortBurgsByFeature(pack.burgs); + const connections = new Map(); + lockedRoutes.forEach(route => addConnections(route.points.map(p => p[2]))); const mainRoads = generateMainRoads(); const trails = generateTrails(); const seaRoutes = generateSeaRoutes(); - pack.routes = createRoutesData(); + pack.routes = createRoutesData(lockedRoutes); pack.cells.routes = buildLinks(pack.routes); function sortBurgsByFeature(burgs) { @@ -124,8 +126,7 @@ window.Routes = (function () { return segments; } - function createRoutesData() { - const routes = []; + function createRoutesData(routes) { const pointsArray = preparePointsArray(); for (const {feature, cells, merged} of mergeRoutes(mainRoads)) { diff --git a/modules/ui/burgs-overview.js b/modules/ui/burgs-overview.js index 8f68cbee..b4dd8639 100644 --- a/modules/ui/burgs-overview.js +++ b/modules/ui/burgs-overview.js @@ -36,7 +36,6 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) { }); byId("burgsLockAll").addEventListener("click", toggleLockAll); byId("burgsRemoveAll").addEventListener("click", triggerAllBurgsRemove); - byId("burgsInvertLock").addEventListener("click", invertLock); function refreshBurgsEditor() { updateFilter(); @@ -604,11 +603,6 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) { burgsOverviewAddLines(); } - function invertLock() { - pack.burgs = pack.burgs.map(burg => ({...burg, lock: !burg.lock})); - burgsOverviewAddLines(); - } - function toggleLockAll() { const activeBurgs = pack.burgs.filter(b => b.i && !b.removed); const allLocked = activeBurgs.every(burg => burg.lock); diff --git a/modules/ui/general.js b/modules/ui/general.js index 8ac87374..f665902d 100644 --- a/modules/ui/general.js +++ b/modules/ui/general.js @@ -67,9 +67,9 @@ function showDataTip(event) { function showElementLockTip(event) { const locked = event?.target?.classList?.contains("icon-lock"); if (locked) { - tip("Click to unlock the element and allow it to be changed by regeneration tools"); + tip("Locked. Click to unlock the element and allow it to be changed by regeneration tools"); } else { - tip("Click to lock the element and prevent changes to it by regeneration tools"); + tip("Unlocked. Click to lock the element and prevent changes to it by regeneration tools"); } } diff --git a/modules/ui/routes-editor.js b/modules/ui/routes-editor.js index 067213e8..82411544 100644 --- a/modules/ui/routes-editor.js +++ b/modules/ui/routes-editor.js @@ -23,6 +23,7 @@ function editRoute(id) { updateRouteData(route); drawControlPoints(route.points); drawCells(route.points); + updateLockIcon(); } $("#routeEditor").dialog({ @@ -41,6 +42,7 @@ function editRoute(id) { byId("routeJoin").on("click", openJoinRoutesDialog); byId("routeElevationProfile").on("click", showRouteElevationProfile); byId("routeLegend").on("click", editRouteLegend); + byId("routeLock").on("click", toggleLockButton); byId("routeRemove").on("click", removeRoute); byId("routeName").on("input", changeName); byId("routeGroup").on("input", changeGroup); @@ -371,6 +373,23 @@ function editRoute(id) { editStyle("routes", group); } + function toggleLockButton() { + const route = getRoute(); + route.lock = !route.lock; + updateLockIcon(); + } + + function updateLockIcon() { + const route = getRoute(); + if (route.lock) { + byId("routeLock").classList.remove("icon-lock-open"); + byId("routeLock").classList.add("icon-lock"); + } else { + byId("routeLock").classList.remove("icon-lock"); + byId("routeLock").classList.add("icon-lock-open"); + } + } + function removeRoute() { alertMessage.innerHTML = "Are you sure you want to remove the route"; $("#alert").dialog({ diff --git a/modules/ui/routes-overview.js b/modules/ui/routes-overview.js index 49a63cac..d9817dc3 100644 --- a/modules/ui/routes-overview.js +++ b/modules/ui/routes-overview.js @@ -21,8 +21,9 @@ function overviewRoutes() { // add listeners byId("routesOverviewRefresh").on("click", routesOverviewAddLines); - byId("routeCreateNew").on("click", createRoute); + byId("routesCreateNew").on("click", createRoute); byId("routesExport").on("click", downloadRoutesData); + byId("routesLockAll").on("click", toggleLockAll); byId("routesRemoveAll").on("click", triggerAllRoutesRemove); // add line for each route @@ -47,6 +48,9 @@ function overviewRoutes() {
${route.group}
${length}
+ `; } @@ -62,6 +66,7 @@ function overviewRoutes() { body.querySelectorAll("div.states").forEach(el => el.on("mouseleave", routeHighlightOff)); body.querySelectorAll("div > span.icon-dot-circled").forEach(el => el.on("click", zoomToRoute)); body.querySelectorAll("div > span.icon-pencil").forEach(el => el.on("click", openRouteEditor)); + body.querySelectorAll("div > span.locks").forEach(el => el.addEventListener("click", toggleLockStatus)); body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.on("click", triggerRouteRemove)); applySorting(routesHeader); @@ -110,6 +115,33 @@ function overviewRoutes() { editRoute(id); } + function toggleLockStatus() { + const routeId = +this.parentNode.dataset.id; + const route = pack.routes[routeId]; + route.lock = !route.lock; + + if (this.classList.contains("icon-lock")) { + this.classList.remove("icon-lock"); + this.classList.add("icon-lock-open"); + this.classList.add("inactive"); + } else { + this.classList.remove("icon-lock-open"); + this.classList.add("icon-lock"); + this.classList.remove("inactive"); + } + } + + function toggleLockAll() { + const allLocked = pack.routes.every(route => route.lock); + + pack.routes.forEach(route => { + route.lock = !allLocked; + }); + + routesOverviewAddLines(); + byId("routesLockAll").className = allLocked ? "icon-lock" : "icon-lock-open"; + } + function triggerRouteRemove() { const routeId = +this.parentNode.dataset.id; diff --git a/modules/ui/tools.js b/modules/ui/tools.js index 3fb98a3a..65ffb29c 100644 --- a/modules/ui/tools.js +++ b/modules/ui/tools.js @@ -117,10 +117,10 @@ async function openEmblemEditor() { } function regenerateRoutes() { - pack.routes = []; - pack.cells.routes = {}; + const locked = pack.routes.filter(route => route.lock).map((route, index) => ({...route, i: index})); + Routes.generate(locked); + routes.selectAll("path").remove(); - Routes.generate(); if (layerIsOn("toggleRoutes")) drawRoutes(); }