mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
Generate a legend for manually added markers (#753)
Markers added by procedural generation have custom notes depending on the type of marker (e.g. dungeons have a procedurally generated map); however, the notes for markers manually added by the user are empty. This patch separates the cell selection logic from the legend and name generation logic in markers-generator.js, so that the latter can be shared with manually added markers. There is some additional simplifications such as storing the dx/dy/px/min/each values directly in the markers table to simplify the writing of the generic "list and add" loop in `generateTypes()`. Currently, the legend is only generated when adding a marker of the same type as an existing marker, and only when a legend generation function is available for that type. To generate a marker of a type that is not currently present on the map, one must first change the type field of an existing marker (which will not get a procedural note), then use "Add additional marker of that type". The UI for this can be improved later. Co-authored-by: Basile Clement <basile-github@clement.pm>
This commit is contained in:
parent
3ac075319f
commit
edfcad4e8c
2 changed files with 306 additions and 389 deletions
|
|
@ -706,14 +706,16 @@ function addMarkerOnClick() {
|
|||
const point = d3.mouse(this);
|
||||
const x = rn(point[0], 2);
|
||||
const y = rn(point[1], 2);
|
||||
const i = markers.length ? last(markers).i + 1 : 0;
|
||||
|
||||
// Find the current cell
|
||||
const cell = findCell(point[0], point[1]);
|
||||
|
||||
// Find the currently selected marker to use as a base
|
||||
const isMarkerSelected = markers.length && elSelected?.node()?.parentElement?.id === "markers";
|
||||
const selectedMarker = isMarkerSelected ? markers.find(marker => marker.i === +elSelected.attr("id").slice(6)) : null;
|
||||
const baseMarker = selectedMarker || {icon: "❓"};
|
||||
const marker = {...baseMarker, i, x, y};
|
||||
const marker = Markers.add({...baseMarker, x, y, cell});
|
||||
|
||||
markers.push(marker);
|
||||
const markersElement = document.getElementById("markers");
|
||||
const rescale = +markersElement.getAttribute("rescale");
|
||||
markersElement.insertAdjacentHTML("beforeend", drawMarker(marker, rescale));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue