import { normalizeInputPreferences, type InputPreferences } from "./keybinds"; // Kept independent of React, account storage and gameplay stores. The profile store // publishes changes here so shell menus, native input and the simulation agree. let preferences = normalizeInputPreferences(null); let capturing = false; const listeners = new Set<() => void>(); export function getInputPreferences(): InputPreferences { return preferences; } export function publishInputPreferences(next: InputPreferences): void { if (preferences === next) return; preferences = next; for (const listener of listeners) listener(); } export function subscribeInputPreferences(listener: () => void): () => void { listeners.add(listener); return () => { listeners.delete(listener); }; } export function isCapturingInput(): boolean { return capturing; } export function setCapturingInput(value: boolean): void { capturing = value; } export function controllerModifierTokens(): Set { return new Set(Object.values(preferences.controller).flatMap((key) => key?.split("&").slice(0, -1) ?? [])); }