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 getNextSceneId = () => {
const winCond = currentScene?.config?.winCondition; const order = window.PhysilinksScenes?.order || [];
if (winCond?.nextSceneId) return winCond.nextSceneId; const currentId = currentScene?.id;
const idx = scenes.findIndex((s) => s.id === currentScene?.id); const orderedExisting = order.filter((id) =>
if (idx >= 0 && idx < scenes.length - 1) return scenes[idx + 1].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; return scenes[0]?.id || defaultSceneId;
}; };

View File

@@ -1,10 +1,27 @@
(() => { (() => {
const scenes = window.PhysilinksSceneDefs || []; const scenes = window.PhysilinksSceneDefs || [];
const gridDefault = scenes.find((s) => s.id === "scene-grid"); const desiredOrder = [
const defaultSceneId = gridDefault?.id || scenes[0]?.id || "scene-grid"; "scene-grid",
"low-g-terraces",
"fast-drop-maze",
"balanced",
"scene-lava",
];
const orderedScenes = desiredOrder
.map((id) => scenes.find((s) => s.id === id))
.filter(Boolean);
const unordered = scenes.filter(
(s) => !orderedScenes.find((o) => o.id === s.id),
);
const finalScenes = [...orderedScenes, ...unordered];
const defaultSceneId =
desiredOrder.find((id) => finalScenes.some((s) => s.id === id)) ||
finalScenes[0]?.id ||
"scene-grid";
window.PhysilinksScenes = { window.PhysilinksScenes = {
scenes, scenes: finalScenes,
defaultSceneId, defaultSceneId,
order: desiredOrder,
}; };
})(); })();

View File

@@ -4,7 +4,7 @@
window.PhysilinksSceneDefs || []); window.PhysilinksSceneDefs || []);
scenes.push({ scenes.push({
id: "scene1", id: "balanced",
name: "Balanced", name: "Balanced",
config: { config: {
gravity: 0.88, gravity: 0.88,
@@ -16,7 +16,7 @@
type: "score", type: "score",
target: 10000, target: 10000,
onWin: { shoveBalls: true }, onWin: { shoveBalls: true },
nextSceneId: "scene2", nextSceneId: "low-g-terraces",
}, },
link: { link: {
stiffness: 0.85, stiffness: 0.85,

View File

@@ -1,10 +1,10 @@
(() => { (() => {
const { Bodies } = Matter; const { Bodies } = Matter;
const scenes = const scenes = (window.PhysilinksSceneDefs =
(window.PhysilinksSceneDefs = window.PhysilinksSceneDefs || []); window.PhysilinksSceneDefs || []);
scenes.push({ scenes.push({
id: "scene3", id: "fast-drop-maze",
name: "Fast drop maze", name: "Fast drop maze",
config: { config: {
gravity: 1.25, gravity: 1.25,
@@ -42,16 +42,10 @@
render: { fillStyle: "#14b8a6", strokeStyle: "#14b8a6" }, render: { fillStyle: "#14b8a6", strokeStyle: "#14b8a6" },
}, },
), ),
Bodies.rectangle( Bodies.rectangle(-wallThickness / 2, h / 2, wallThickness, wallHeight, {
-wallThickness / 2, isStatic: true,
h / 2, render: { fillStyle: "#f472b6", strokeStyle: "#f472b6" },
wallThickness, }),
wallHeight,
{
isStatic: true,
render: { fillStyle: "#f472b6", strokeStyle: "#f472b6" },
},
),
Bodies.rectangle( Bodies.rectangle(
w + wallThickness / 2, w + wallThickness / 2,
h / 2, h / 2,

View File

@@ -4,7 +4,7 @@
window.PhysilinksSceneDefs || []); window.PhysilinksSceneDefs || []);
scenes.push({ scenes.push({
id: "scene2", id: "low-g-terraces",
name: "Low-G terraces", name: "Low-G terraces",
config: { config: {
gravity: 0.65, gravity: 0.65,
@@ -15,7 +15,7 @@
winCondition: { winCondition: {
type: "score", type: "score",
target: 50000, target: 50000,
nextSceneId: "scene3", nextSceneId: "fast-drop-maze",
onWin: { shoveBalls: true }, onWin: { shoveBalls: true },
}, },
link: { link: {