feat(state): localStorage player prefs for story and action display

This commit is contained in:
ginnoir
2026-06-11 18:52:39 -05:00
parent 9196c77e25
commit b88399ac14
2 changed files with 58 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
const PREFS_KEY = 'idlegame:prefs:v1';
export type StoryOpenMode = 'auto' | 'choices-only' | 'manual';
export type ActionDetailMode = 'inline' | 'hover' | 'info-button';
export interface GamePrefs {
storyOpenMode: StoryOpenMode;
actionDetailMode: ActionDetailMode;
}
const DEFAULTS: GamePrefs = {
storyOpenMode: 'auto',
actionDetailMode: 'inline',
};
export function getPrefs(): GamePrefs {
if (typeof localStorage === 'undefined') return { ...DEFAULTS };
try {
const raw = localStorage.getItem(PREFS_KEY);
if (!raw) return { ...DEFAULTS };
return { ...DEFAULTS, ...JSON.parse(raw) };
} catch {
return { ...DEFAULTS };
}
}
export function setPrefs(partial: Partial<GamePrefs>): GamePrefs {
const next = { ...getPrefs(), ...partial };
if (typeof localStorage !== 'undefined') {
localStorage.setItem(PREFS_KEY, JSON.stringify(next));
}
return next;
}