fix(settings): persist pause menu preferences

This commit is contained in:
Tom Boullay
2026-06-01 01:32:36 +02:00
parent 597ebcfbd4
commit bc862960a7
3 changed files with 129 additions and 86 deletions
+12 -3
View File
@@ -9,6 +9,7 @@ const DEBUG_CONTROLS_STORAGE_KEY = "la-fabrik-debug-controls";
interface StoredDebugControls {
cameraMode: CameraMode;
handTrackingSource: HandTrackingSource;
sceneMode: SceneMode;
}
@@ -39,6 +40,10 @@ function isSceneMode(value: unknown): value is SceneMode {
return value === "game" || value === "physics";
}
function isHandTrackingSource(value: unknown): value is HandTrackingSource {
return value === "browser" || value === "backend";
}
function getStoredDebugControls(): Partial<StoredDebugControls> {
try {
const rawValue = window.localStorage.getItem(DEBUG_CONTROLS_STORAGE_KEY);
@@ -51,6 +56,9 @@ function getStoredDebugControls(): Partial<StoredDebugControls> {
...(isCameraMode(parsedValue.cameraMode)
? { cameraMode: parsedValue.cameraMode }
: {}),
...(isHandTrackingSource(parsedValue.handTrackingSource)
? { handTrackingSource: parsedValue.handTrackingSource }
: {}),
...(isSceneMode(parsedValue.sceneMode)
? { sceneMode: parsedValue.sceneMode }
: {}),
@@ -94,7 +102,7 @@ export class Debug {
this.controls = {
cameraMode: storedControls.cameraMode ?? "player",
fogEnabled: FOG_CONFIG.enabled,
handTrackingSource: "browser",
handTrackingSource: storedControls.handTrackingSource ?? "browser",
showDebugOverlay: true,
showHandTrackingSvg: false,
showInteractionSpheres: false,
@@ -159,7 +167,7 @@ export class Debug {
.name("Source")
.onChange((value: HandTrackingSource) => {
this.controls.handTrackingSource = value;
this.emit();
this.saveAndEmit();
});
}
}
@@ -246,7 +254,7 @@ export class Debug {
setHandTrackingSource(value: HandTrackingSource): void {
this.controls.handTrackingSource = value;
this.emit();
this.saveAndEmit();
}
getFogEnabled(): boolean {
@@ -285,6 +293,7 @@ export class Debug {
DEBUG_CONTROLS_STORAGE_KEY,
JSON.stringify({
cameraMode: this.controls.cameraMode,
handTrackingSource: this.controls.handTrackingSource,
sceneMode: this.controls.sceneMode,
}),
);