mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
refactor: improve getNextId function to fill gaps in ice element IDs(optional commit)
This commit is contained in:
parent
f2d98e5bc7
commit
95a06dfb4b
1 changed files with 7 additions and 2 deletions
|
|
@ -3,10 +3,15 @@
|
||||||
// Ice layer data model - separates ice data from SVG rendering
|
// Ice layer data model - separates ice data from SVG rendering
|
||||||
window.Ice = (function () {
|
window.Ice = (function () {
|
||||||
|
|
||||||
// Find next available id for new ice element
|
// Find next available id for new ice element idealy filling gaps
|
||||||
function getNextId() {
|
function getNextId() {
|
||||||
if (pack.ice.length === 0) return 0;
|
if (pack.ice.length === 0) return 0;
|
||||||
return Math.max(...pack.ice.map(element => element.i)) + 1;
|
// find gaps in existing ids
|
||||||
|
const existingIds = pack.ice.map(e => e.i).sort((a, b) => a - b);
|
||||||
|
for (let id = 0; id < existingIds[existingIds.length - 1]; id++) {
|
||||||
|
if (!existingIds.includes(id)) return id;
|
||||||
|
}
|
||||||
|
return existingIds[existingIds.length - 1] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate glaciers and icebergs based on temperature and height
|
// Generate glaciers and icebergs based on temperature and height
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue