Store high scores per scene and add README
This commit is contained in:
12
main.js
12
main.js
@@ -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);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user