Store high scores per scene and add README

This commit is contained in:
Daddy32
2025-12-12 13:17:52 +01:00
parent f482cafb2f
commit de28fa0cdd
2 changed files with 32 additions and 6 deletions

12
main.js
View File

@@ -24,7 +24,7 @@
id: "scene1",
name: "Balanced (default)",
config: {
gravity: 0.78,
gravity: 0.88,
spawnIntervalMs: 720,
minChain: 3,
palette: ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"],
@@ -175,11 +175,11 @@
let gameOver = false;
let isPaused = false;
const STORAGE_KEY = "physilinks-highscore";
const makeStorageKey = (sceneId) => `physilinks-highscore-${sceneId}`;
const loadHighScore = () => {
const loadHighScore = (sceneId) => {
try {
const raw = localStorage.getItem(STORAGE_KEY);
const raw = localStorage.getItem(makeStorageKey(sceneId));
const parsed = parseInt(raw, 10);
return Number.isFinite(parsed) ? parsed : 0;
} catch (err) {
@@ -189,7 +189,7 @@
const saveHighScore = () => {
try {
localStorage.setItem(STORAGE_KEY, String(highScore));
localStorage.setItem(makeStorageKey(currentScene.id), String(highScore));
} catch (err) {
// ignore write failures (private mode or blocked storage)
}
@@ -212,6 +212,7 @@
if (sceneSelectEl) sceneSelectEl.value = next.id;
Object.assign(config, next.config);
engine.gravity.y = config.gravity;
highScore = loadHighScore(next.id);
rebuildSceneBodies();
buildLegend();
restartGame();
@@ -583,7 +584,6 @@
if (sceneSelectEl) {
sceneSelectEl.addEventListener("change", (e) => applyScene(e.target.value));
}
highScore = loadHighScore();
populateSceneSelect();
applyScene(currentScene.id);
})();