|
182 | 182 | (Math.floor(selected.r/3)===Math.floor(r/3) && Math.floor(selected.c/3)===Math.floor(c/3)); |
183 | 183 | } |
184 | 184 |
|
| 185 | + function getPersistedElapsedTime(data){ |
| 186 | + return data?.elapsed ?? data?.timeElapsed ?? data?.timer ?? data?.timeSeconds; |
| 187 | + } |
| 188 | + |
| 189 | + function normalizeElapsed(value){ |
| 190 | + const parsed=Number(value); |
| 191 | + if(!Number.isFinite(parsed) || parsed<0) return 0; |
| 192 | + return Math.floor(parsed); |
| 193 | + } |
| 194 | + |
185 | 195 | function formatTime(t){ |
186 | | - return `${String(Math.floor(t/60)).padStart(2,'0')}:${String(t%60).padStart(2,'0')}`; |
| 196 | + const normalized=normalizeElapsed(t); |
| 197 | + return `${String(Math.floor(normalized/60)).padStart(2,'0')}:${String(normalized%60).padStart(2,'0')}`; |
187 | 198 | } |
188 | 199 |
|
189 | 200 | // ── Notes ──────────────────────────────────────────────────────────────── |
|
566 | 577 | startingGrid=data.startingGrid||data.grid.map(row=>row.slice()); |
567 | 578 | notes=data.notes.map(row=>row.map(arr=>new Set(arr))); |
568 | 579 | selected=data.selected; |
569 | | - elapsed=data.elapsed||0; |
| 580 | + elapsed=normalizeElapsed(getPersistedElapsedTime(data)); |
570 | 581 | notesMode=!!data.notesMode; |
571 | 582 | autoCleanup=data.autoCleanup!==false; |
572 | 583 | difficultyEl.value=data.difficulty||'medium'; |
|
946 | 957 | try{ |
947 | 958 | const saved=JSON.parse(raw); |
948 | 959 | const modal=document.getElementById('resumeModal'); |
949 | | - timeStat.textContent=formatTime(Number(saved.elapsed) || 0); |
| 960 | + timeStat.textContent=formatTime(getPersistedElapsedTime(saved)); |
950 | 961 | modal.hidden=false; |
951 | 962 | document.getElementById('resumeYesBtn').onclick=()=>{ modal.hidden=true; applyLoadedData(saved); }; |
952 | 963 | document.getElementById('resumeNoBtn').onclick=()=>{ modal.hidden=true; newGame(); }; |
|
0 commit comments