Track longest chain records per scene

This commit is contained in:
Daddy32
2025-12-14 13:13:41 +01:00
parent 0ef5644d1d
commit 19c8489553

View File

@@ -138,6 +138,7 @@
let spawnCount = 0;
let score = 0;
let highScore = 0;
let longestChainRecord = 0;
let clearedCount = 0;
let clearedByColor = {};
let gameOver = false;
@@ -148,6 +149,7 @@
let dragConstraint = null;
const makeStorageKey = (sceneId) => `physilinks-highscore-${sceneId}`;
const makeChainKey = (sceneId) => `physilinks-longestchain-${sceneId}`;
const loadHighScore = (sceneId) => {
try {
@@ -159,6 +161,16 @@
}
};
const loadLongestChain = (sceneId) => {
try {
const raw = localStorage.getItem(makeChainKey(sceneId));
const parsed = parseInt(raw, 10);
return Number.isFinite(parsed) ? parsed : 0;
} catch (err) {
return 0;
}
};
const saveHighScore = () => {
try {
localStorage.setItem(makeStorageKey(currentScene.id), String(highScore));
@@ -167,6 +179,17 @@
}
};
const saveLongestChain = () => {
try {
localStorage.setItem(
makeChainKey(currentScene.id),
String(longestChainRecord),
);
} catch (err) {
// ignore write failures
}
};
const applyScene = (sceneId) => {
const next = getSceneById(sceneId) || scenes[0];
if (!next) return;
@@ -215,6 +238,7 @@
levelWon = false;
clearedByColor = {};
highScore = loadHighScore(next.id);
longestChainRecord = loadLongestChain(next.id);
rebuildSceneBodies();
buildLegend();
restartGame();
@@ -623,6 +647,15 @@
const finishChain = (releasePoint) => {
if (!chain.active || gameOver || isPaused) return;
if (chain.bodies.length >= config.minChain) {
const chainLength = chain.bodies.length;
if (chainLength > longestChainRecord) {
longestChainRecord = chainLength;
saveLongestChain();
ui.showFloatingMessage(`New chain record: ${chainLength}`, {
durationMs: 3600,
position: config.messages.position,
});
}
const baseGain = 10 * Math.pow(chain.bodies.length, 2);
const negativeColors = (
currentScene?.config?.negativeScoreColors || []