mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-21 19:41:23 +01:00
feat: routes - lock routes
This commit is contained in:
parent
a83d7bab85
commit
b4653c1aff
7 changed files with 69 additions and 23 deletions
14
index.html
14
index.html
|
|
@ -2996,6 +2996,7 @@
|
||||||
class="icon-chart-area"
|
class="icon-chart-area"
|
||||||
></button>
|
></button>
|
||||||
<button id="routeLegend" data-tip="Edit free text notes (legend) for the route" class="icon-edit"></button>
|
<button id="routeLegend" data-tip="Edit free text notes (legend) for the route" class="icon-edit"></button>
|
||||||
|
<button id="routeLock" class="icon-lock-open" onmouseover="showElementLockTip(event)"></button>
|
||||||
<button
|
<button
|
||||||
id="routeRemove"
|
id="routeRemove"
|
||||||
data-tip="Remove route"
|
data-tip="Remove route"
|
||||||
|
|
@ -5458,12 +5459,6 @@
|
||||||
Population
|
Population
|
||||||
</div>
|
</div>
|
||||||
<div data-tip="Click to sort by burg type" class="sortable alphabetically" data-sortby="type">Type </div>
|
<div data-tip="Click to sort by burg type" class="sortable alphabetically" data-sortby="type">Type </div>
|
||||||
<div
|
|
||||||
id="burgsInvertLock"
|
|
||||||
style="color: #6e5e66"
|
|
||||||
data-tip="Click to invert lock for all burgs"
|
|
||||||
class="icon-lock pointer"
|
|
||||||
></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="burgsBody" class="table"></div>
|
<div id="burgsBody" class="table"></div>
|
||||||
|
|
@ -5536,12 +5531,17 @@
|
||||||
|
|
||||||
<div id="routesBottom">
|
<div id="routesBottom">
|
||||||
<button id="routesOverviewRefresh" data-tip="Refresh the Editor" class="icon-cw"></button>
|
<button id="routesOverviewRefresh" data-tip="Refresh the Editor" class="icon-cw"></button>
|
||||||
<button id="routeCreateNew" data-tip="Create a new route selecting route cells" class="icon-map-pin"></button>
|
<button
|
||||||
|
id="routesCreateNew"
|
||||||
|
data-tip="Create a new route selecting route cells"
|
||||||
|
class="icon-map-pin"
|
||||||
|
></button>
|
||||||
<button
|
<button
|
||||||
id="routesExport"
|
id="routesExport"
|
||||||
data-tip="Save routes-related data as a text file (.csv)"
|
data-tip="Save routes-related data as a text file (.csv)"
|
||||||
class="icon-download"
|
class="icon-download"
|
||||||
></button>
|
></button>
|
||||||
|
<button id="routesLockAll" data-tip="Lock or unlock all routes" class="icon-lock"></button>
|
||||||
<button id="routesRemoveAll" data-tip="Remove all routes" class="icon-trash"></button>
|
<button id="routesRemoveAll" data-tip="Remove all routes" class="icon-trash"></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,17 @@ const ROUTES_SHARP_ANGLE = 135;
|
||||||
const ROUTES_VERY_SHARP_ANGLE = 115;
|
const ROUTES_VERY_SHARP_ANGLE = 115;
|
||||||
|
|
||||||
window.Routes = (function () {
|
window.Routes = (function () {
|
||||||
function generate() {
|
function generate(lockedRoutes = []) {
|
||||||
const {capitalsByFeature, burgsByFeature, portsByFeature} = sortBurgsByFeature(pack.burgs);
|
const {capitalsByFeature, burgsByFeature, portsByFeature} = sortBurgsByFeature(pack.burgs);
|
||||||
|
|
||||||
const connections = new Map();
|
const connections = new Map();
|
||||||
|
lockedRoutes.forEach(route => addConnections(route.points.map(p => p[2])));
|
||||||
|
|
||||||
const mainRoads = generateMainRoads();
|
const mainRoads = generateMainRoads();
|
||||||
const trails = generateTrails();
|
const trails = generateTrails();
|
||||||
const seaRoutes = generateSeaRoutes();
|
const seaRoutes = generateSeaRoutes();
|
||||||
|
|
||||||
pack.routes = createRoutesData();
|
pack.routes = createRoutesData(lockedRoutes);
|
||||||
pack.cells.routes = buildLinks(pack.routes);
|
pack.cells.routes = buildLinks(pack.routes);
|
||||||
|
|
||||||
function sortBurgsByFeature(burgs) {
|
function sortBurgsByFeature(burgs) {
|
||||||
|
|
@ -124,8 +126,7 @@ window.Routes = (function () {
|
||||||
return segments;
|
return segments;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRoutesData() {
|
function createRoutesData(routes) {
|
||||||
const routes = [];
|
|
||||||
const pointsArray = preparePointsArray();
|
const pointsArray = preparePointsArray();
|
||||||
|
|
||||||
for (const {feature, cells, merged} of mergeRoutes(mainRoads)) {
|
for (const {feature, cells, merged} of mergeRoutes(mainRoads)) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
||||||
});
|
});
|
||||||
byId("burgsLockAll").addEventListener("click", toggleLockAll);
|
byId("burgsLockAll").addEventListener("click", toggleLockAll);
|
||||||
byId("burgsRemoveAll").addEventListener("click", triggerAllBurgsRemove);
|
byId("burgsRemoveAll").addEventListener("click", triggerAllBurgsRemove);
|
||||||
byId("burgsInvertLock").addEventListener("click", invertLock);
|
|
||||||
|
|
||||||
function refreshBurgsEditor() {
|
function refreshBurgsEditor() {
|
||||||
updateFilter();
|
updateFilter();
|
||||||
|
|
@ -604,11 +603,6 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
||||||
burgsOverviewAddLines();
|
burgsOverviewAddLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
function invertLock() {
|
|
||||||
pack.burgs = pack.burgs.map(burg => ({...burg, lock: !burg.lock}));
|
|
||||||
burgsOverviewAddLines();
|
|
||||||
}
|
|
||||||
|
|
||||||
function toggleLockAll() {
|
function toggleLockAll() {
|
||||||
const activeBurgs = pack.burgs.filter(b => b.i && !b.removed);
|
const activeBurgs = pack.burgs.filter(b => b.i && !b.removed);
|
||||||
const allLocked = activeBurgs.every(burg => burg.lock);
|
const allLocked = activeBurgs.every(burg => burg.lock);
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,9 @@ function showDataTip(event) {
|
||||||
function showElementLockTip(event) {
|
function showElementLockTip(event) {
|
||||||
const locked = event?.target?.classList?.contains("icon-lock");
|
const locked = event?.target?.classList?.contains("icon-lock");
|
||||||
if (locked) {
|
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 {
|
} 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ function editRoute(id) {
|
||||||
updateRouteData(route);
|
updateRouteData(route);
|
||||||
drawControlPoints(route.points);
|
drawControlPoints(route.points);
|
||||||
drawCells(route.points);
|
drawCells(route.points);
|
||||||
|
updateLockIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#routeEditor").dialog({
|
$("#routeEditor").dialog({
|
||||||
|
|
@ -41,6 +42,7 @@ function editRoute(id) {
|
||||||
byId("routeJoin").on("click", openJoinRoutesDialog);
|
byId("routeJoin").on("click", openJoinRoutesDialog);
|
||||||
byId("routeElevationProfile").on("click", showRouteElevationProfile);
|
byId("routeElevationProfile").on("click", showRouteElevationProfile);
|
||||||
byId("routeLegend").on("click", editRouteLegend);
|
byId("routeLegend").on("click", editRouteLegend);
|
||||||
|
byId("routeLock").on("click", toggleLockButton);
|
||||||
byId("routeRemove").on("click", removeRoute);
|
byId("routeRemove").on("click", removeRoute);
|
||||||
byId("routeName").on("input", changeName);
|
byId("routeName").on("input", changeName);
|
||||||
byId("routeGroup").on("input", changeGroup);
|
byId("routeGroup").on("input", changeGroup);
|
||||||
|
|
@ -371,6 +373,23 @@ function editRoute(id) {
|
||||||
editStyle("routes", group);
|
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() {
|
function removeRoute() {
|
||||||
alertMessage.innerHTML = "Are you sure you want to remove the route";
|
alertMessage.innerHTML = "Are you sure you want to remove the route";
|
||||||
$("#alert").dialog({
|
$("#alert").dialog({
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,9 @@ function overviewRoutes() {
|
||||||
|
|
||||||
// add listeners
|
// add listeners
|
||||||
byId("routesOverviewRefresh").on("click", routesOverviewAddLines);
|
byId("routesOverviewRefresh").on("click", routesOverviewAddLines);
|
||||||
byId("routeCreateNew").on("click", createRoute);
|
byId("routesCreateNew").on("click", createRoute);
|
||||||
byId("routesExport").on("click", downloadRoutesData);
|
byId("routesExport").on("click", downloadRoutesData);
|
||||||
|
byId("routesLockAll").on("click", toggleLockAll);
|
||||||
byId("routesRemoveAll").on("click", triggerAllRoutesRemove);
|
byId("routesRemoveAll").on("click", triggerAllRoutesRemove);
|
||||||
|
|
||||||
// add line for each route
|
// add line for each route
|
||||||
|
|
@ -47,6 +48,9 @@ function overviewRoutes() {
|
||||||
<div data-tip="Route group" style="width: 8em;">${route.group}</div>
|
<div data-tip="Route group" style="width: 8em;">${route.group}</div>
|
||||||
<div data-tip="Route length" style="width: 6em;">${length}</div>
|
<div data-tip="Route length" style="width: 6em;">${length}</div>
|
||||||
<span data-tip="Edit route" class="icon-pencil"></span>
|
<span data-tip="Edit route" class="icon-pencil"></span>
|
||||||
|
<span class="locks pointer ${
|
||||||
|
route.lock ? "icon-lock" : "icon-lock-open inactive"
|
||||||
|
}" onmouseover="showElementLockTip(event)"></span>
|
||||||
<span data-tip="Remove route" class="icon-trash-empty"></span>
|
<span data-tip="Remove route" class="icon-trash-empty"></span>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
@ -62,6 +66,7 @@ function overviewRoutes() {
|
||||||
body.querySelectorAll("div.states").forEach(el => el.on("mouseleave", routeHighlightOff));
|
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-dot-circled").forEach(el => el.on("click", zoomToRoute));
|
||||||
body.querySelectorAll("div > span.icon-pencil").forEach(el => el.on("click", openRouteEditor));
|
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));
|
body.querySelectorAll("div > span.icon-trash-empty").forEach(el => el.on("click", triggerRouteRemove));
|
||||||
|
|
||||||
applySorting(routesHeader);
|
applySorting(routesHeader);
|
||||||
|
|
@ -110,6 +115,33 @@ function overviewRoutes() {
|
||||||
editRoute(id);
|
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() {
|
function triggerRouteRemove() {
|
||||||
const routeId = +this.parentNode.dataset.id;
|
const routeId = +this.parentNode.dataset.id;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,10 +117,10 @@ async function openEmblemEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function regenerateRoutes() {
|
function regenerateRoutes() {
|
||||||
pack.routes = [];
|
const locked = pack.routes.filter(route => route.lock).map((route, index) => ({...route, i: index}));
|
||||||
pack.cells.routes = {};
|
Routes.generate(locked);
|
||||||
|
|
||||||
routes.selectAll("path").remove();
|
routes.selectAll("path").remove();
|
||||||
Routes.generate();
|
|
||||||
if (layerIsOn("toggleRoutes")) drawRoutes();
|
if (layerIsOn("toggleRoutes")) drawRoutes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue