|
201 | 201 | return Math.floor(parsed); |
202 | 202 | } |
203 | 203 |
|
| 204 | + function normalizeBoolean(value, fallback=false){ |
| 205 | + if(typeof value === 'boolean') return value; |
| 206 | + if(typeof value === 'string'){ |
| 207 | + const normalized=value.trim().toLowerCase(); |
| 208 | + if(normalized==='true') return true; |
| 209 | + if(normalized==='false') return false; |
| 210 | + } |
| 211 | + if(value==null) return fallback; |
| 212 | + return Boolean(value); |
| 213 | + } |
| 214 | + |
204 | 215 | function formatTime(t){ |
205 | 216 | const normalized=normalizeElapsed(t); |
206 | 217 | return `${String(Math.floor(normalized/60)).padStart(2,'0')}:${String(normalized%60).padStart(2,'0')}`; |
|
633 | 644 | notes=data.notes.map(row=>row.map(arr=>new Set(arr))); |
634 | 645 | selected=data.selected; |
635 | 646 | elapsed=normalizeElapsed(getPersistedElapsedTime(data)); |
636 | | - notesMode=!!data.notesMode; |
637 | | - autoCleanup=data.autoCleanup!==false; |
| 647 | + notesMode=normalizeBoolean(data.notesMode,false); |
| 648 | + autoCleanup=normalizeBoolean(data.autoCleanup,true); |
638 | 649 | difficultyEl.value=data.difficulty||'medium'; |
639 | 650 | history=[]; future=[]; |
640 | 651 | boardShellEl.classList.remove('victory-glow'); |
|
741 | 752 | startingGrid=cloneGrid(grid); |
742 | 753 | notes=Array.from({length:GRID_SIZE},()=>Array.from({length:GRID_SIZE},()=>new Set())); |
743 | 754 | fillNotesAll(); |
744 | | - selected=null; elapsed=0; history=[]; future=[]; |
| 755 | + selected=null; elapsed=0; notesMode=false; autoCleanup=true; history=[]; future=[]; |
745 | 756 | boardShellEl.classList.remove('victory-glow'); |
746 | 757 | clearRiftVisualState(); |
747 | 758 | resetRiftState(); |
|
927 | 938 | ?{r:Math.max(0,Math.min(8,payload.selected.r)),c:Math.max(0,Math.min(8,payload.selected.c))} |
928 | 939 | :null; |
929 | 940 | elapsed=normalizeElapsed(payload.elapsed); |
930 | | - notesMode=!!payload.notesMode; |
931 | | - autoCleanup=payload.autoCleanup!==false; |
| 941 | + notesMode=normalizeBoolean(payload.notesMode,false); |
| 942 | + autoCleanup=normalizeBoolean(payload.autoCleanup,true); |
932 | 943 | history=[]; future=[]; |
933 | 944 | boardShellEl.classList.remove('victory-glow'); |
934 | 945 | clearRiftVisualState(); |
|
1046 | 1057 | document.getElementById('undoBtn').onclick=undo; |
1047 | 1058 | document.getElementById('redoBtn').onclick=redo; |
1048 | 1059 |
|
1049 | | - notesModeBtn.onclick=()=>{ notesMode=!notesMode; render(); saveGame(); }; |
| 1060 | + notesModeBtn.onclick=()=>{ |
| 1061 | + notesMode=!normalizeBoolean(notesMode,false); |
| 1062 | + render(); |
| 1063 | + saveGame(); |
| 1064 | + }; |
1050 | 1065 | autoNotesBtn.onclick=()=>{ autoCleanup=!autoCleanup; render(); saveGame(); }; |
1051 | 1066 |
|
1052 | 1067 | document.getElementById('fillNotesBtn').onclick=()=>{ fillNotesAll(); render(); saveGame(); setStatus('Filled notes for all empty cells.'); }; |
|
0 commit comments