Skip to content

Commit eca6ecf

Browse files
committed
Fix elapsed timer restore when resuming saved games
1 parent 3c52847 commit eca6ecf

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

script.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,15 @@
182182
(Math.floor(selected.r/3)===Math.floor(r/3) && Math.floor(selected.c/3)===Math.floor(c/3));
183183
}
184184

185+
function normalizeElapsed(value){
186+
const parsed=Number(value);
187+
if(!Number.isFinite(parsed) || parsed<0) return 0;
188+
return Math.floor(parsed);
189+
}
190+
185191
function formatTime(t){
186-
return `${String(Math.floor(t/60)).padStart(2,'0')}:${String(t%60).padStart(2,'0')}`;
192+
const normalized=normalizeElapsed(t);
193+
return `${String(Math.floor(normalized/60)).padStart(2,'0')}:${String(normalized%60).padStart(2,'0')}`;
187194
}
188195

189196
// ── Notes ────────────────────────────────────────────────────────────────
@@ -566,7 +573,7 @@
566573
startingGrid=data.startingGrid||data.grid.map(row=>row.slice());
567574
notes=data.notes.map(row=>row.map(arr=>new Set(arr)));
568575
selected=data.selected;
569-
elapsed=data.elapsed||0;
576+
elapsed=normalizeElapsed(data.elapsed ?? data.timeElapsed ?? data.timer ?? data.timeSeconds);
570577
notesMode=!!data.notesMode;
571578
autoCleanup=data.autoCleanup!==false;
572579
difficultyEl.value=data.difficulty||'medium';
@@ -946,7 +953,7 @@
946953
try{
947954
const saved=JSON.parse(raw);
948955
const modal=document.getElementById('resumeModal');
949-
timeStat.textContent=formatTime(Number(saved.elapsed) || 0);
956+
timeStat.textContent=formatTime(saved.elapsed ?? saved.timeElapsed ?? saved.timer ?? saved.timeSeconds);
950957
modal.hidden=false;
951958
document.getElementById('resumeYesBtn').onclick=()=>{ modal.hidden=true; applyLoadedData(saved); };
952959
document.getElementById('resumeNoBtn').onclick=()=>{ modal.hidden=true; newGame(); };

0 commit comments

Comments
 (0)