Align scene ids with names and order

This commit is contained in:
Daddy32
2025-12-13 19:59:39 +01:00
parent f57e993964
commit ebd61a7979
5 changed files with 49 additions and 24 deletions

22
main.js
View File

@@ -143,10 +143,24 @@
};
const getNextSceneId = () => {
const winCond = currentScene?.config?.winCondition;
if (winCond?.nextSceneId) return winCond.nextSceneId;
const idx = scenes.findIndex((s) => s.id === currentScene?.id);
if (idx >= 0 && idx < scenes.length - 1) return scenes[idx + 1].id;
const order = window.PhysilinksScenes?.order || [];
const currentId = currentScene?.id;
const orderedExisting = order.filter((id) =>
scenes.some((s) => s.id === id),
);
if (orderedExisting.length > 0 && currentId) {
const idx = orderedExisting.indexOf(currentId);
if (idx >= 0 && idx < orderedExisting.length - 1) {
return orderedExisting[idx + 1];
}
if (idx === orderedExisting.length - 1) {
return orderedExisting[0];
}
}
const fallbackIdx = scenes.findIndex((s) => s.id === currentId);
if (fallbackIdx >= 0 && fallbackIdx < scenes.length - 1) {
return scenes[fallbackIdx + 1].id;
}
return scenes[0]?.id || defaultSceneId;
};