Track longest chain records per scene
This commit is contained in:
33
src/main.js
33
src/main.js
@@ -138,6 +138,7 @@
|
|||||||
let spawnCount = 0;
|
let spawnCount = 0;
|
||||||
let score = 0;
|
let score = 0;
|
||||||
let highScore = 0;
|
let highScore = 0;
|
||||||
|
let longestChainRecord = 0;
|
||||||
let clearedCount = 0;
|
let clearedCount = 0;
|
||||||
let clearedByColor = {};
|
let clearedByColor = {};
|
||||||
let gameOver = false;
|
let gameOver = false;
|
||||||
@@ -148,6 +149,7 @@
|
|||||||
let dragConstraint = null;
|
let dragConstraint = null;
|
||||||
|
|
||||||
const makeStorageKey = (sceneId) => `physilinks-highscore-${sceneId}`;
|
const makeStorageKey = (sceneId) => `physilinks-highscore-${sceneId}`;
|
||||||
|
const makeChainKey = (sceneId) => `physilinks-longestchain-${sceneId}`;
|
||||||
|
|
||||||
const loadHighScore = (sceneId) => {
|
const loadHighScore = (sceneId) => {
|
||||||
try {
|
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 = () => {
|
const saveHighScore = () => {
|
||||||
try {
|
try {
|
||||||
localStorage.setItem(makeStorageKey(currentScene.id), String(highScore));
|
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 applyScene = (sceneId) => {
|
||||||
const next = getSceneById(sceneId) || scenes[0];
|
const next = getSceneById(sceneId) || scenes[0];
|
||||||
if (!next) return;
|
if (!next) return;
|
||||||
@@ -215,6 +238,7 @@
|
|||||||
levelWon = false;
|
levelWon = false;
|
||||||
clearedByColor = {};
|
clearedByColor = {};
|
||||||
highScore = loadHighScore(next.id);
|
highScore = loadHighScore(next.id);
|
||||||
|
longestChainRecord = loadLongestChain(next.id);
|
||||||
rebuildSceneBodies();
|
rebuildSceneBodies();
|
||||||
buildLegend();
|
buildLegend();
|
||||||
restartGame();
|
restartGame();
|
||||||
@@ -623,6 +647,15 @@
|
|||||||
const finishChain = (releasePoint) => {
|
const finishChain = (releasePoint) => {
|
||||||
if (!chain.active || gameOver || isPaused) return;
|
if (!chain.active || gameOver || isPaused) return;
|
||||||
if (chain.bodies.length >= config.minChain) {
|
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 baseGain = 10 * Math.pow(chain.bodies.length, 2);
|
||||||
const negativeColors = (
|
const negativeColors = (
|
||||||
currentScene?.config?.negativeScoreColors || []
|
currentScene?.config?.negativeScoreColors || []
|
||||||
|
|||||||
Reference in New Issue
Block a user