mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
refactor(maps): separate source factories and scene coordination
This commit is contained in:
1 parent
561a781099
commit
e59282dc9c
22 files changed
+1807
-798
No files matched your search
@@ -0,0 +1,21 @@
|
||||
/** Catch invalid source graphs before a cached fallback can wait on itself. */
|
||||
export function indexMapSources(sources) {
|
||||
const index = new Map();
|
||||
for (const source of sources) {
|
||||
const id = source?.descriptor?.id;
|
||||
if (typeof id !== 'string' || !id || index.has(id))
|
||||
throw new TypeError('Map source IDs must be nonempty and unique');
|
||||
index.set(id, source);
|
||||
}
|
||||
for (const id of index.keys()) {
|
||||
const seen = new Set();
|
||||
let next = id;
|
||||
while (next) {
|
||||
if (seen.has(next)) throw new TypeError('Map source fallback cycle');
|
||||
if (!index.has(next)) throw new TypeError('Unknown map fallback source');
|
||||
seen.add(next);
|
||||
next = index.get(next).constructionFallback?.id;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
Reference in new issue
Block a user