mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
ensure marker id is unique
This commit is contained in:
parent
d07e43cde8
commit
dbb3d6e91a
2 changed files with 41 additions and 0 deletions
|
|
@ -967,6 +967,31 @@ function parseLoadedData(data) {
|
|||
ERROR && console.error('Data Integrity Check. Province', p.i, 'is linked to removed state', p.state);
|
||||
p.removed = true; // remove incorrect province
|
||||
});
|
||||
|
||||
{
|
||||
const markerIds = [];
|
||||
let nextId = last(pack.markers)?.i + 1 || 0;
|
||||
|
||||
pack.markers.forEach(marker => {
|
||||
if (markerIds[marker.i]) {
|
||||
ERROR && console.error("Data Integrity Check. Marker", marker.i, "has non-unique id. Changing to", nextId);
|
||||
|
||||
const domElements = document.querySelectorAll("#marker" + marker.i);
|
||||
if (domElements[1]) domElements[1].id = "marker" + nextId; // rename 2nd dom element
|
||||
|
||||
const noteElements = notes.filter(note => note.id === "marker" + marker.i);
|
||||
if (noteElements[1]) noteElements[1].id = "marker" + nextId; // rename 2nd note
|
||||
|
||||
marker.i = nextId;
|
||||
nextId += 1;
|
||||
} else {
|
||||
markerIds[marker.i] = true;
|
||||
}
|
||||
});
|
||||
|
||||
// sort markers by index
|
||||
pack.markers.sort((a, b) => a.i - b.i);
|
||||
}
|
||||
})();
|
||||
|
||||
changeMapSize();
|
||||
|
|
|
|||
|
|
@ -126,7 +126,23 @@ window.Markers = (function () {
|
|||
return cells.p[cell];
|
||||
};
|
||||
|
||||
<<<<<<< HEAD
|
||||
function addVolcanoes() {
|
||||
=======
|
||||
function addMarker({cell, type, icon, dx, dy, px}) {
|
||||
const i = last(pack.markers)?.i + 1 || 0;
|
||||
const [x, y] = getMarkerCoordinates(cell);
|
||||
const marker = {i, icon, type, x, y, cell};
|
||||
if (dx) marker.dx = dx;
|
||||
if (dy) marker.dy = dy;
|
||||
if (px) marker.px = px;
|
||||
pack.markers.push(marker);
|
||||
occupied[cell] = true;
|
||||
return "marker" + i;
|
||||
}
|
||||
|
||||
function addVolcanoes(type, icon, multiplier) {
|
||||
>>>>>>> c152c2ed (ensure marker id is unique)
|
||||
const {cells} = pack;
|
||||
|
||||
let mountains = Array.from(cells.i.filter(i => cells.h[i] >= 70).sort((a, b) => cells.h[b] - cells.h[a]));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue