Skip to content

Commit 5abd7f4

Browse files
committed
Fix notes toggle state normalization and reset defaults
1 parent 8506b50 commit 5abd7f4

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

script.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@
201201
return Math.floor(parsed);
202202
}
203203

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+
204215
function formatTime(t){
205216
const normalized=normalizeElapsed(t);
206217
return `${String(Math.floor(normalized/60)).padStart(2,'0')}:${String(normalized%60).padStart(2,'0')}`;
@@ -633,8 +644,8 @@
633644
notes=data.notes.map(row=>row.map(arr=>new Set(arr)));
634645
selected=data.selected;
635646
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);
638649
difficultyEl.value=data.difficulty||'medium';
639650
history=[]; future=[];
640651
boardShellEl.classList.remove('victory-glow');
@@ -741,7 +752,7 @@
741752
startingGrid=cloneGrid(grid);
742753
notes=Array.from({length:GRID_SIZE},()=>Array.from({length:GRID_SIZE},()=>new Set()));
743754
fillNotesAll();
744-
selected=null; elapsed=0; history=[]; future=[];
755+
selected=null; elapsed=0; notesMode=false; autoCleanup=true; history=[]; future=[];
745756
boardShellEl.classList.remove('victory-glow');
746757
clearRiftVisualState();
747758
resetRiftState();
@@ -927,8 +938,8 @@
927938
?{r:Math.max(0,Math.min(8,payload.selected.r)),c:Math.max(0,Math.min(8,payload.selected.c))}
928939
:null;
929940
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);
932943
history=[]; future=[];
933944
boardShellEl.classList.remove('victory-glow');
934945
clearRiftVisualState();
@@ -1046,7 +1057,11 @@
10461057
document.getElementById('undoBtn').onclick=undo;
10471058
document.getElementById('redoBtn').onclick=redo;
10481059

1049-
notesModeBtn.onclick=()=>{ notesMode=!notesMode; render(); saveGame(); };
1060+
notesModeBtn.onclick=()=>{
1061+
notesMode=!normalizeBoolean(notesMode,false);
1062+
render();
1063+
saveGame();
1064+
};
10501065
autoNotesBtn.onclick=()=>{ autoCleanup=!autoCleanup; render(); saveGame(); };
10511066

10521067
document.getElementById('fillNotesBtn').onclick=()=>{ fillNotesAll(); render(); saveGame(); setStatus('Filled notes for all empty cells.'); };

0 commit comments

Comments
 (0)