A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): settings window + declarative settings architecture
esengine72599f6f0c42
diff --git a/desktop/src/App.tsx b/desktop/src/App.tsxindex c54de63ea..92487e05c 100644--- a/desktop/src/App.tsx+++ b/desktop/src/App.tsx@@ -9,6 +9,7 @@ import '@/engine/EditorSession'; // side effect: constructs defaultSession → wimport { Launcher } from '@/launcher/Launcher';import { Toaster } from '@/components/Toaster';import { BuildDialog } from '@/components/BuildDialog';+import { SettingsDialog } from '@/components/SettingsDialog';import { useEditorStore } from '@/store/editorStore';import { commands } from '@/commands';import { PlayRealm } from '@/engine/PlayRealm';@@ -80,6 +81,7 @@ export function App() {// only once a project is opened. (Logic wiring lands with the recents IPC.)const showLauncher = useEditorStore((s) => s.showLauncher);const buildOpen = useEditorStore((s) => s.buildOpen);+ const settingsOpen = useEditorStore((s) => s.settingsOpen);if (showLauncher) return <Launcher />;return (@@ -93,6 +95,7 @@ export function App() {<StatusBar /><ContentDrawer />{buildOpen && <BuildDialog />}+ {settingsOpen && <SettingsDialog />}<Toaster /></div>);diff --git a/desktop/src/commands/editorCommands.ts b/desktop/src/commands/editorCommands.tsindex 3a7d5613d..ed0603350 100644--- a/desktop/src/commands/editorCommands.ts+++ b/desktop/src/commands/editorCommands.ts@@ -157,6 +157,15 @@ commands.register({run: () => editor().toggleSnapping(),});+// — Editor —+commands.register({+ id: 'settings.open',+ label: 'Settings…',+ category: 'Editor',+ keybinding: 'mod+,',+ run: () => editor().setSettingsOpen(true),+});+// — Play —commands.register({id: 'play.toggle',diff --git a/desktop/src/components/SettingsDialog.tsx b/desktop/src/components/SettingsDialog.tsxnew file mode 100644index 000000000..65fdc07e9--- /dev/null+++ b/desktop/src/components/SettingsDialog.tsx@@ -0,0 +1,291 @@+/**+ * @file SettingsDialog.tsx — the settings window (the design's `.set-*`), driven+ * entirely by the settings registry + store. The dialog knows nothing about+ * individual settings: it renders nav from registered sections and rows from+ * registered descriptors, picking a control by `type`. Search filters across+ * sections; a reset arrow shows when a value differs from its default.+ */+import { useEffect, useRef, useState } from 'react';+import type { PointerEvent as ReactPointerEvent } from 'react';+import { createPortal } from 'react-dom';+import { Settings as SettingsIcon, Search, X, RotateCcw } from 'lucide-react';+import { useEditorStore } from '@/store/editorStore';+import { useSettings } from '@/store/settingsStore';+import { settingsRegistry } from '@/settings/registry';+import type { Setting, NumberSetting } from '@/settings/types';++const CATEGORY_LABEL: Record<string, string> = {+ editor: 'Editor',+ project: 'Project',+ plugin: 'Plugins',+};++const clamp = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(hi, v));++function Slider({+ value, min, max, step, onChange,+}: {+ value: number; min: number; max: number; step: number; onChange: (v: number) => void;+}) {+ const ref = useRef<HTMLSpanElement>(null);+ const pct = max > min ? clamp(((value - min) / (max - min)) * 100, 0, 100) : 0;+ const fromClient = (clientX: number) => {+ const el = ref.current;+ if (!el) return;+ const r = el.getBoundingClientRect();+ const t = clamp((clientX - r.left) / r.width, 0, 1);+ const raw = min + t * (max - min);+ onChange(clamp(Math.round(raw / step) * step, min, max));+ };+ return (+ <span+ ref={ref}+ className="slider set-slider"+ onPointerDown={(e: ReactPointerEvent) => {+ (e.target as HTMLElement).setPointerCapture(e.pointerId);+ fromClient(e.clientX);+ }}+ onPointerMove={(e: ReactPointerEvent) => {+ if (e.buttons & 1) fromClient(e.clientX);+ }}+ >+ <span className="fill" style={{ width: `${pct}%` }} />+ <span className="thumb" style={{ left: `${pct}%` }} />+ </span>+ );+}++function NumberControl({ setting }: { setting: NumberSetting }) {+ const setValue = useSettings((s) => s.setValue);+ const value = Number(useSettings((s) => s.getValue<number>(setting.id)));+ const { min = 0, max = 100, step = 1, slider, suffix } = setting;+ return (+ <>+ {slider && (+ <Slider value={value} min={min} max={max} step={step} onChange={(v) => setValue(setting.id, v)} />+ )}+ <input+ className="set-num"+ defaultValue={`${value}${suffix ?? ''}`}+ key={value}+ onBlur={(e) => {+ const n = parseFloat(e.target.value);+ if (!Number.isNaN(n)) setValue(setting.id, clamp(n, min, max));+ }}+ onKeyDown={(e) => {+ if (e.key === 'Enter') (e.target as HTMLInputElement).blur();+ }}+ />+ </>+ );+}++function Control({ setting }: { setting: Setting }) {+ const setValue = useSettings((s) => s.setValue);+ const value = useSettings((s) => s.getValue(setting.id));+ switch (setting.type) {+ case 'boolean':+ return (+ <span+ className={`toggle${value ? ' on' : ''}`}+ role="switch"+ aria-checked={Boolean(value)}+ tabIndex={0}+ onClick={() => setValue(setting.id, !value)}+ />+ );+ case 'enum':+ if (setting.segmented) {+ return (+ <div className="set-seg">+ {setting.options.map((o) => (+ <button+ key={o.value}+ type="button"+ className={value === o.value ? 'on' : ''}+ onClick={() => setValue(setting.id, o.value)}+ >+ {o.label}+ </button>+ ))}+ </div>+ );+ }+ return (+ <select className="set-sel" value={String(value)} onChange={(e) => setValue(setting.id, e.target.value)}>+ {setting.options.map((o) => (+ <option key={o.value} value={o.value}>{o.label}</option>+ ))}+ </select>+ );+ case 'number':+ return <NumberControl setting={setting} />;+ case 'color':+ return (+ <div className="set-swatches">+ {setting.swatches.map((c) => (+ <span+ key={c}+ className={`set-swatch${value === c ? ' on' : ''}`}+ style={{ background: c }}+ title={c}+ onClick={() => setValue(setting.id, c)}+ />+ ))}+ </div>+ );+ case 'keybinding':+ return <span className="set-key">{setting.default}</span>;+ }+}++function Row({ setting }: { setting: Setting }) {+ const isChanged = useSettings((s) => s.isChanged(setting.id));+ const reset = useSettings((s) => s.reset);+ const resettable = setting.type !== 'keybinding';+ return (+ <div className={`set-row${isChanged && resettable ? ' changed' : ''}`}>+ <div>+ <div className="sn">{setting.label}</div>+ {setting.description && <div className="sd">{setting.description}</div>}+ </div>+ <div className="set-ctrl">+ <Control setting={setting} />+ </div>+ {resettable ? (+ <span+ className={`set-reset${isChanged ? ' show' : ''}`}+ title="Reset to default"+ onClick={() => isChanged && reset(setting.id)}+ >+ {isChanged && <RotateCcw size={11} strokeWidth={2} />}+ </span>+ ) : (+ <span className="set-reset" />+ )}+ </div>+ );+}++// A content group: a header + its rows.+function Group({ label, settings }: { label: string; settings: Setting[] }) {+ return (+ <>+ <div className="set-group">{label}</div>+ {settings.map((s) => (+ <Row key={s.id} setting={s} />+ ))}+ </>+ );+}++export function SettingsDialog() {+ const close = () => useEditorStore.getState().setSettingsOpen(false);+ const [open, setOpen] = useState(false);+ const [query, setQuery] = useState('');+ const sections = settingsRegistry.allSections();+ const [active, setActive] = useState(() => sections[0]?.id ?? '');++ // Subscribe so rows reflect live changes of bound (editorStore) settings too.+ useEditorStore((s) => `${s.showGrid}|${s.showGizmos}|${s.snapping}|${s.snapStep}`);++ useEffect(() => {+ const raf = requestAnimationFrame(() => setOpen(true));+ const onKey = (e: KeyboardEvent) => {+ if (e.key === 'Escape') close();+ };+ window.addEventListener('keydown', onKey);+ return () => {+ cancelAnimationFrame(raf);+ window.removeEventListener('keydown', onKey);+ };+ }, []);++ const q = query.trim().toLowerCase();+ const matches = (s: Setting) =>+ !q ||+ s.label.toLowerCase().includes(q) ||+ (s.description?.toLowerCase().includes(q) ?? false) ||+ s.id.toLowerCase().includes(q);++ // When searching, show matching rows across all sections (grouped by section);+ // otherwise show the active section grouped by each setting's `group`.+ const content = q+ ? sections+ .map((sec) => ({ label: sec.label, settings: settingsRegistry.settingsForSection(sec.id).filter(matches) }))+ .filter((g) => g.settings.length > 0)+ : groupByGroup(settingsRegistry.settingsForSection(active));++ return createPortal(+ <div className={`set-scrim${open ? ' open' : ''}`} onMouseDown={close}>+ <div className="set-win" role="dialog" aria-label="Settings" onMouseDown={(e) => e.stopPropagation()}>+ <div className="set-head">+ <span className="set-title">+ <span className="ic"><SettingsIcon size={16} strokeWidth={1.8} /></span>+ Settings+ </span>+ <span className="set-head-sp" />+ <label className="set-search">+ <Search size={12} strokeWidth={2} />+ <input+ placeholder="Search settings…"+ value={query}+ onChange={(e) => setQuery(e.target.value)}+ autoFocus+ />+ </label>+ <button type="button" className="set-x" title="Close (Esc)" onClick={close}>+ <X size={14} strokeWidth={2} />+ </button>+ </div>++ <div className="set-body">+ <nav className="set-nav">+ {settingsRegistry.sectionsByCategory().map((cat) => (+ <div key={cat.category}>+ <div className="set-nav-sec">{CATEGORY_LABEL[cat.category] ?? cat.category}</div>+ {cat.sections.map((sec) => (+ <button+ key={sec.id}+ type="button"+ className={`set-nav-item${!q && sec.id === active ? ' active' : ''}`}+ onClick={() => {+ setQuery('');+ setActive(sec.id);+ }}+ >+ {sec.label}+ </button>+ ))}+ </div>+ ))}+ </nav>++ <div className="set-content">+ {content.length === 0 ? (+ <div className="set-empty">No settings match “{query}”.</div>+ ) : (+ content.map((g) => <Group key={g.label} label={g.label} settings={g.settings} />)+ )}+ </div>+ </div>+ </div>+ </div>,+ document.body,+ );+}++// Group a section's settings by their `group` field, preserving first-seen order.+function groupByGroup(settings: Setting[]): { label: string; settings: Setting[] }[] {+ const order: string[] = [];+ const map = new Map<string, Setting[]>();+ for (const s of settings) {+ const g = s.group ?? '';+ if (!map.has(g)) {+ map.set(g, []);+ order.push(g);+ }+ map.get(g)!.push(s);+ }+ return order.map((label) => ({ label, settings: map.get(label)! }));+}diff --git a/desktop/src/layout/ActivityBar.tsx b/desktop/src/layout/ActivityBar.tsxindex 0b7be9e93..9cfc341e6 100644--- a/desktop/src/layout/ActivityBar.tsx+++ b/desktop/src/layout/ActivityBar.tsx@@ -3,7 +3,7 @@import { ListTree, SlidersHorizontal, FolderOpen, Terminal, Settings } from 'lucide-react';import { useEditorStore } from '@/store/editorStore';import { dockApi } from '@/layout/dockApi';-import { Toasts } from '@/store/Toasts';+import { commands } from '@/commands';export function ActivityBar() {const contentDrawer = useEditorStore((s) => s.contentDrawer);@@ -39,8 +39,8 @@ export function ActivityBar() {<buttontype="button"className="act"- title="Settings"- onClick={() => Toasts.push('Settings — coming soon', 'info', 1600)}+ title="Settings (Ctrl+,)"+ onClick={() => commands.run('settings.open')}><Settings size={19} strokeWidth={1.7} /></button>diff --git a/desktop/src/main.tsx b/desktop/src/main.tsxindex 0872c9651..59f101909 100644--- a/desktop/src/main.tsx+++ b/desktop/src/main.tsx@@ -21,13 +21,19 @@ import './theme/viewport.css';import './theme/content.css';import './theme/chrome.css';import './theme/menus.css';+import './theme/settings.css';import './theme/launcher.css';import { App } from './App';import { LogStore } from './store/LogStore';import { initFsWatch } from './project/fsWatch';+// Register the built-in settings (side effect) and replay persisted ones.+import './settings';+import { applySettings } from './store/settingsStore';// Capture console (editor + SDK + wasm) into the Output Log panel from startup.LogStore.install();+// Apply persisted editor settings (accent, UI scale, log cap) before first paint.+applySettings();// Live-sync the asset registry + Content Browser with on-disk changes (incl.// edits made outside the editor) via the main-process project watcher.initFsWatch();diff --git a/desktop/src/settings/editorSettings.ts b/desktop/src/settings/editorSettings.tsnew file mode 100644index 000000000..9610c8877--- /dev/null+++ b/desktop/src/settings/editorSettings.ts@@ -0,0 +1,143 @@+/**+ * @file editorSettings.ts — the editor's built-in settings, registered as a side+ * effect (import this once at boot). Each is wired to a REAL backing: a CSS+ * variable, a live store (editorStore), or a subsystem (LogStore). Adding a+ * setting here makes it appear in SettingsDialog with no UI change.+ *+ * Project- and plugin-scoped sections (physics / render / asset pipeline) plug in+ * the same way once their persistence + backing land — that's the architecture's+ * extension point, not a special case.+ */+import { settingsRegistry } from './registry';+import { useEditorStore } from '@/store/editorStore';+import { LogStore } from '@/store/LogStore';+import { commands } from '@/commands';+import { formatKeybinding } from '@/commands/keybinding';++const root = () => document.documentElement.style;++// ── Sections (editor category) ──────────────────────────────────────────────+settingsRegistry.registerSection({ id: 'appearance', label: 'Appearance', category: 'editor', order: 1 });+settingsRegistry.registerSection({ id: 'viewport', label: 'Viewport', category: 'editor', order: 2 });+settingsRegistry.registerSection({ id: 'shortcuts', label: 'Keyboard Shortcuts', category: 'editor', order: 3 });+settingsRegistry.registerSection({ id: 'console', label: 'Console', category: 'editor', order: 4 });++// ── Appearance (store-owned, applied via CSS) ───────────────────────────────+settingsRegistry.register({+ id: 'appearance.accent',+ type: 'color',+ scope: 'editor',+ section: 'appearance',+ group: 'Appearance',+ label: 'Accent color',+ description: 'Used for selection, active controls, and focus.',+ default: '#2f88d6',+ swatches: ['#2f88d6', '#46b08c', '#b272d6', '#e08c43', '#c75d6e'],+ effect: (v) => {+ root().setProperty('--star', v);+ root().setProperty('--acc', v);+ },+});++settingsRegistry.register({+ id: 'appearance.uiScale',+ type: 'number',+ scope: 'editor',+ section: 'appearance',+ group: 'Appearance',+ label: 'UI scale',+ description: 'Scales every panel — fonts and controls.',+ default: 100,+ min: 80,+ max: 150,+ step: 5,+ slider: true,+ suffix: '%',+ effect: (v) => {+ document.body.style.setProperty('zoom', String(v / 100));+ },+});++// ── Viewport (bound to editorStore — one source with the viewport toolbar) ───+const ed = () => useEditorStore.getState();++settingsRegistry.register({+ id: 'viewport.showGrid',+ type: 'boolean',+ scope: 'editor',+ section: 'viewport',+ group: 'Grid',+ label: 'Show grid',+ default: true,+ bind: { get: () => ed().showGrid, set: (v) => useEditorStore.setState({ showGrid: v }) },+});++settingsRegistry.register({+ id: 'viewport.gridSize',+ type: 'number',+ scope: 'editor',+ section: 'viewport',+ group: 'Grid',+ label: 'Grid size',+ description: 'World-unit spacing of the scene grid (and Move snap).',+ default: 32,+ min: 8,+ max: 128,+ step: 1,+ bind: { get: () => ed().snapStep, set: (v) => useEditorStore.setState({ snapStep: v }) },+});++settingsRegistry.register({+ id: 'viewport.snapping',+ type: 'boolean',+ scope: 'editor',+ section: 'viewport',+ group: 'Grid',+ label: 'Snap to grid',+ default: false,+ bind: { get: () => ed().snapping, set: (v) => useEditorStore.setState({ snapping: v }) },+});++settingsRegistry.register({+ id: 'viewport.showGizmos',+ type: 'boolean',+ scope: 'editor',+ section: 'viewport',+ group: 'Gizmos',+ label: 'Show gizmos',+ default: true,+ bind: { get: () => ed().showGizmos, set: (v) => useEditorStore.setState({ showGizmos: v }) },+});++// ── Console (store-owned, applied to the log ring buffer) ────────────────────+settingsRegistry.register({+ id: 'console.maxLines',+ type: 'number',+ scope: 'editor',+ section: 'console',+ group: 'Console',+ label: 'Max retained lines',+ description: 'Output Log keeps at most this many entries.',+ default: 2000,+ min: 100,+ max: 10000,+ step: 100,+ effect: (v) => LogStore.setCap(v),+});++// ── Keyboard Shortcuts (read-only, generated from the command registry) ──────+// Editing is a later feature; here we surface the live bindings so they're+// discoverable in one place (the design's "快捷键" section).+for (const cmd of commands.all()) {+ if (!cmd.keybinding) continue;+ settingsRegistry.register({+ id: `shortcut.${cmd.id}`,+ type: 'keybinding',+ scope: 'editor',+ section: 'shortcuts',+ group: cmd.category ?? 'General',+ label: cmd.label,+ commandId: cmd.id,+ default: formatKeybinding(cmd.keybinding),+ });+}diff --git a/desktop/src/settings/index.ts b/desktop/src/settings/index.tsnew file mode 100644index 000000000..3ea1b5ab9--- /dev/null+++ b/desktop/src/settings/index.ts@@ -0,0 +1,14 @@+/**+ * @file index.ts — settings barrel. Importing this registers the built-in+ * settings (./editorSettings side effect) and exposes the registry + types.+ */+import './editorSettings';++export { settingsRegistry } from './registry';+export type {+ Setting,+ SettingsSection,+ SettingScope,+ SettingCategory,+ SettingValue,+} from './types';diff --git a/desktop/src/settings/registry.ts b/desktop/src/settings/registry.tsnew file mode 100644index 000000000..725c949ee--- /dev/null+++ b/desktop/src/settings/registry.ts@@ -0,0 +1,55 @@+/**+ * @file registry.ts — the editor settings registry, the declarative sibling of+ * the command registry (commands/registry.ts). Features and plugins register+ * sections + settings; the store holds values, SettingsDialog renders from+ * here. Holds no reactive state — the single source of ids, defaults, and+ * schema. One place to add a setting; the UI follows automatically.+ */+import type { Setting, SettingsSection, SettingCategory } from './types';++class SettingsRegistry {+ private readonly settings = new Map<string, Setting>();+ private readonly sections = new Map<string, SettingsSection>();++ registerSection(section: SettingsSection): void {+ this.sections.set(section.id, section);+ }++ register(setting: Setting): void {+ this.settings.set(setting.id, setting);+ }++ get(id: string): Setting | undefined {+ return this.settings.get(id);+ }++ all(): Setting[] {+ return [...this.settings.values()];+ }++ getSection(id: string): SettingsSection | undefined {+ return this.sections.get(id);+ }++ allSections(): SettingsSection[] {+ return [...this.sections.values()].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));+ }++ /** Sections grouped by nav category, in declared order. */+ sectionsByCategory(): { category: SettingCategory; sections: SettingsSection[] }[] {+ const order: SettingCategory[] = ['editor', 'project', 'plugin'];+ return order+ .map((category) => ({+ category,+ sections: this.allSections().filter((s) => s.category === category),+ }))+ .filter((g) => g.sections.length > 0);+ }++ /** Settings in a section, in declared registration order. */+ settingsForSection(sectionId: string): Setting[] {+ return this.all().filter((s) => s.section === sectionId);+ }+}++export const settingsRegistry = new SettingsRegistry();diff --git a/desktop/src/settings/types.ts b/desktop/src/settings/types.tsnew file mode 100644index 000000000..aeadb9796--- /dev/null+++ b/desktop/src/settings/types.ts@@ -0,0 +1,84 @@+/**+ * @file types.ts — settings schema. A setting is a declarative descriptor; the+ * registry holds them, the store holds their values, and SettingsDialog+ * renders from them. New setting = new descriptor; the UI needs no change.+ *+ * Two ways a setting reaches runtime:+ * - `bind` — delegate get/set to an existing store (e.g. editorStore.showGrid),+ * so the setting and the live control share ONE source (no dupe).+ * - `effect` — for store-owned settings, push the value to runtime on set + on+ * hydrate (CSS variable, engine resource, …). Persisted by the store.+ */++/** Where a setting lives / persists. editor → per-user (localStorage). */+export type SettingScope = 'editor' | 'project';++/** Nav grouping in the dialog's left rail. */+export type SettingCategory = 'editor' | 'project' | 'plugin';++export interface SettingsSection {+ id: string;+ label: string;+ category: SettingCategory;+ order?: number;+}++interface BaseSetting<T> {+ /** Dot-namespaced, stable id, e.g. 'appearance.accent'. */+ id: string;+ scope: SettingScope;+ /** Section id (a nav item) this row appears under. */+ section: string;+ /** Group header within the section content. */+ group?: string;+ label: string;+ description?: string;+ default: T;+ /** Two-way delegation to a live store; when present the store owns the value. */+ bind?: { get: () => T; set: (value: T) => void };+ /** One-way push to runtime for store-owned settings (on set + on hydrate). */+ effect?: (value: T) => void;+}++export interface BooleanSetting extends BaseSetting<boolean> {+ type: 'boolean';+}++export interface NumberSetting extends BaseSetting<number> {+ type: 'number';+ min?: number;+ max?: number;+ step?: number;+ /** Render a slider alongside the numeric field. */+ slider?: boolean;+ /** Suffix shown in the numeric field (e.g. '%', 's'). */+ suffix?: string;+}++export interface EnumSetting extends BaseSetting<string> {+ type: 'enum';+ options: { value: string; label: string }[];+ /** Render as a segmented control instead of a dropdown. */+ segmented?: boolean;+}++export interface ColorSetting extends BaseSetting<string> {+ type: 'color';+ /** Preset swatches (hex). */+ swatches: string[];+}++/** Read-only display of a command's keybinding (editing is a later feature). */+export interface KeybindingSetting extends BaseSetting<string> {+ type: 'keybinding';+ commandId: string;+}++export type Setting =+ | BooleanSetting+ | NumberSetting+ | EnumSetting+ | ColorSetting+ | KeybindingSetting;++export type SettingValue = boolean | number | string;diff --git a/desktop/src/store/LogStore.ts b/desktop/src/store/LogStore.tsindex c2731cc3b..f5b93e806 100644--- a/desktop/src/store/LogStore.ts+++ b/desktop/src/store/LogStore.ts@@ -18,7 +18,7 @@ export interface LogEntry {message: string;}-const CAP = 2000; // ring-buffer cap — long sessions can't grow the log unbounded+const DEFAULT_CAP = 2000; // ring-buffer cap — long sessions can't grow unboundedconst pad = (n: number) => (n < 10 ? `0${n}` : `${n}`);function stamp(): string {@@ -57,14 +57,29 @@ class LogStoreImpl {private seq = 0;private installed = false;private capturing = false;+ private cap = DEFAULT_CAP;subscribe = (fn: () => void): (() => void) => this.store.subscribe(fn);getSnapshot = (): LogEntry[] => this.store.getState().entries;+ getCap(): number {+ return this.cap;+ }++ /** Set the ring-buffer cap (the console "max lines" setting); trims overflow. */+ setCap(cap: number): void {+ this.cap = Math.max(100, Math.floor(cap));+ const cur = this.store.getState().entries;+ if (cur.length > this.cap) {+ this.store.setState({ entries: cur.slice(cur.length - this.cap) });+ }+ }+push(level: LogLevel, source: string, message: string): void {const entry: LogEntry = { id: ++this.seq, level, time: stamp(), source, message };const cur = this.store.getState().entries;- const next = cur.length >= CAP ? [...cur.slice(cur.length - CAP + 1), entry] : [...cur, entry];+ const next =+ cur.length >= this.cap ? [...cur.slice(cur.length - this.cap + 1), entry] : [...cur, entry];this.store.setState({ entries: next });}diff --git a/desktop/src/store/editorStore.ts b/desktop/src/store/editorStore.tsindex 6c9252ed6..d7f2cbae7 100644--- a/desktop/src/store/editorStore.ts+++ b/desktop/src/store/editorStore.ts@@ -56,6 +56,10 @@ interface EditorState {// Package/Build dialog (File → Build) — the UE5-style export modal.buildOpen: boolean;setBuildOpen: (open: boolean) => void;++ // Settings window (the registry-driven preferences dialog).+ settingsOpen: boolean;+ setSettingsOpen: (open: boolean) => void;}export const useEditorStore = create<EditorState>((set) => ({@@ -108,4 +112,7 @@ export const useEditorStore = create<EditorState>((set) => ({buildOpen: false,setBuildOpen: (buildOpen) => set({ buildOpen }),++ settingsOpen: false,+ setSettingsOpen: (settingsOpen) => set({ settingsOpen }),}));diff --git a/desktop/src/store/settingsStore.ts b/desktop/src/store/settingsStore.tsnew file mode 100644index 000000000..41d2afb5a--- /dev/null+++ b/desktop/src/store/settingsStore.ts@@ -0,0 +1,94 @@+/**+ * @file settingsStore.ts — reactive values for the settings registry, with+ * per-user persistence. Store-owned settings live here (persisted to+ * localStorage, pushed to runtime via the descriptor's `effect`); bound+ * settings delegate to their live store, so there's a single source.+ *+ * Read with useSettings((s) => s.getValue(id)) or the snapshot for non-reactive+ * reads. `applySettings()` (called once at boot) replays persisted effects.+ */+import { create } from 'zustand';+import { settingsRegistry } from '@/settings/registry';+import type { SettingValue } from '@/settings/types';++const LS_KEY = 'estella.settings';++function loadPersisted(): Record<string, SettingValue> {+ if (typeof localStorage === 'undefined') return {};+ try {+ const raw = localStorage.getItem(LS_KEY);+ return raw ? (JSON.parse(raw) as Record<string, SettingValue>) : {};+ } catch {+ return {};+ }+}++function persist(values: Record<string, SettingValue>): void {+ if (typeof localStorage === 'undefined') return;+ try {+ localStorage.setItem(LS_KEY, JSON.stringify(values));+ } catch {+ /* quota / private mode — settings just won't persist this session */+ }+}++interface SettingsState {+ // Owned (non-bound) setting values; bumped on every set so consumers re-render.+ values: Record<string, SettingValue>;+ getValue: <T extends SettingValue>(id: string) => T;+ setValue: (id: string, value: SettingValue) => void;+ reset: (id: string) => void;+ isChanged: (id: string) => boolean;+}++export const useSettings = create<SettingsState>((set, get) => ({+ values: loadPersisted(),++ getValue: <T extends SettingValue>(id: string): T => {+ const desc = settingsRegistry.get(id);+ if (desc?.bind) return desc.bind.get() as T;+ const v = get().values[id];+ return (v !== undefined ? v : desc?.default) as T;+ },++ setValue: (id, value) => {+ const desc = settingsRegistry.get(id);+ if (!desc) return;+ if (desc.bind) {+ (desc.bind.set as (v: SettingValue) => void)(value);+ // Bump a new object so dialog rows reading bound values re-render too.+ set((s) => ({ values: { ...s.values } }));+ return;+ }+ set((s) => {+ const values = { ...s.values, [id]: value };+ persist(values);+ return { values };+ });+ (desc.effect as ((v: SettingValue) => void) | undefined)?.(value);+ },++ reset: (id) => {+ const desc = settingsRegistry.get(id);+ if (desc) get().setValue(id, desc.default as SettingValue);+ },++ isChanged: (id) => {+ const desc = settingsRegistry.get(id);+ if (!desc) return false;+ return get().getValue(id) !== desc.default;+ },+}));++/**+ * Replay persisted store-owned effects once the registry is populated (call from+ * boot, after registering settings). Bound settings already reflect their store.+ */+export function applySettings(): void {+ const { getValue } = useSettings.getState();+ for (const desc of settingsRegistry.all()) {+ if (!desc.bind && desc.effect) {+ (desc.effect as (v: SettingValue) => void)(getValue(desc.id));+ }+ }+}diff --git a/desktop/src/theme/settings.css b/desktop/src/theme/settings.cssnew file mode 100644index 000000000..6eedfa5d8--- /dev/null+++ b/desktop/src/theme/settings.css@@ -0,0 +1,233 @@+/* =============================================================================+ @file settings.css+ @brief Settings dialog — adopted from the design's authored stylesheet+ (ue5/shell.css `.set-*`): a centered window with a left nav + scrollable+ content of typed setting rows. `.slider`/`.fill`/`.thumb` reuse the inspector's.+ ========================================================================== */++.set-scrim {+ position: fixed;+ inset: 0;+ z-index: 124;+ background: var(--overlay);+ display: grid;+ place-items: center;+ opacity: 0;+ pointer-events: none;+ transition: opacity var(--t) var(--e-out);+}+.set-scrim.open { opacity: 1; pointer-events: auto; }+.set-win {+ width: 880px;+ max-width: 94vw;+ height: 600px;+ max-height: 88vh;+ display: flex;+ flex-direction: column;+ background: var(--srf-2);+ border: 1px solid var(--border-line);+ border-radius: var(--r-lg);+ box-shadow: var(--shadow-3);+ overflow: hidden;+ transform: scale(0.97);+ opacity: 0.5;+ transition: transform var(--t) var(--e-spring), opacity var(--t);+}+.set-scrim.open .set-win { transform: scale(1); opacity: 1; }++.set-head {+ height: 46px;+ flex-shrink: 0;+ display: flex;+ align-items: center;+ gap: 12px;+ padding: 0 14px;+ border-bottom: 1px solid var(--border);+ background: var(--srf-3);+}+.set-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: var(--fs-lg); }+.set-title .ic { color: var(--text-dim); display: inline-flex; }+.set-head-sp { flex: 1; }+.set-search {+ display: inline-flex;+ align-items: center;+ gap: 6px;+ width: 220px;+ height: 28px;+ padding: 0 9px;+ background: var(--inset);+ border: 1px solid var(--border);+ border-radius: var(--r-sm);+ color: var(--text-mute);+ transition: border-color var(--t-fast), box-shadow var(--t-fast);+}+.set-search:focus-within { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }+.set-search input { flex: 1; min-width: 0; background: none; border: none; outline: none; font-size: var(--fs-sm); color: var(--text); }+.set-search input::placeholder { color: var(--text-mute); }+.set-x { width: 28px; height: 28px; display: grid; place-items: center; color: var(--text-mute); border-radius: var(--r-sm); }+.set-x:hover { color: var(--text); background: var(--srf-4); }++.set-body { flex: 1; min-height: 0; display: flex; }+.set-nav {+ width: 212px;+ flex-shrink: 0;+ background: var(--srf-1);+ border-right: 1px solid var(--border);+ overflow-y: auto;+ padding: 8px 6px;+}+.set-nav-sec {+ font-size: var(--fs-2xs);+ text-transform: uppercase;+ letter-spacing: 0.6px;+ color: var(--text-mute);+ font-weight: 700;+ padding: 10px 10px 4px;+}+.set-nav-item {+ width: 100%;+ display: flex;+ align-items: center;+ gap: 8px;+ height: 30px;+ padding: 0 10px;+ border-radius: var(--r-sm);+ color: var(--text-dim);+ font-size: var(--fs-sm);+ text-align: left;+ position: relative;+ transition: color var(--t-fast), background var(--t-fast);+}+.set-nav-item:hover { color: var(--text); background: var(--srf-3); }+.set-nav-item.active { color: var(--text); background: var(--acc-soft); }+.set-nav-item.active::before {+ content: '';+ position: absolute;+ left: 0;+ top: 6px;+ bottom: 6px;+ width: 2px;+ border-radius: var(--r-pill);+ background: var(--acc);+}++.set-content { flex: 1; min-width: 0; overflow-y: auto; padding: 16px 22px 28px; }+.set-section { animation: setfade var(--t) var(--e-out); }+@keyframes setfade {+ from { opacity: 0; transform: translateY(8px); }+ to { opacity: 1; transform: translateY(0); }+}+.set-group {+ font-size: var(--fs-md);+ font-weight: 700;+ color: var(--text);+ padding-bottom: 7px;+ margin: 6px 0 8px;+ border-bottom: 1px solid var(--border);+}+.set-group:not(:first-child) { margin-top: 26px; }+.set-empty { color: var(--text-mute); font-size: var(--fs-sm); padding: 20px 2px; }++.set-row {+ display: grid;+ grid-template-columns: 1fr 230px 18px;+ gap: 16px;+ align-items: center;+ padding: 9px 0;+ border-bottom: 1px solid var(--border-soft);+}+.set-row .sn { font-size: var(--fs-sm); color: var(--text); }+.set-row .sd { font-size: var(--fs-xs); color: var(--text-mute); margin-top: 2px; line-height: 1.4; }+.set-row.changed .sn::after {+ content: '';+ display: inline-block;+ width: 6px;+ height: 6px;+ border-radius: 50%;+ background: var(--warn);+ margin-left: 7px;+ vertical-align: middle;+}+.set-ctrl { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }+.set-reset { width: 16px; height: 16px; display: grid; place-items: center; color: var(--warn); opacity: 0; }+.set-row:hover .set-reset.show, .set-row.changed .set-reset.show { opacity: 0.85; }+.set-reset.show { cursor: pointer; }++.set-sel {+ height: 27px;+ min-width: 130px;+ background: var(--inset);+ border: 1px solid var(--border);+ border-radius: var(--r-sm);+ color: var(--text);+ padding: 0 8px;+ outline: none;+ font-size: var(--fs-sm);+}+.set-num {+ width: 92px;+ height: 27px;+ background: var(--inset);+ border: 1px solid var(--border);+ border-radius: var(--r-sm);+ color: var(--text);+ padding: 0 8px;+ outline: none;+ font-family: var(--mono);+ font-size: var(--fs-xs);+ text-align: right;+}+.set-sel:focus, .set-num:focus { border-color: var(--acc); box-shadow: 0 0 0 2px var(--acc-soft); }+.set-slider { flex: 1; max-width: 130px; }++.set-key {+ height: 24px;+ display: inline-flex;+ align-items: center;+ gap: 4px;+ padding: 0 9px;+ background: var(--inset);+ border: 1px solid var(--border);+ border-radius: var(--r-sm);+ font-family: var(--mono);+ font-size: var(--fs-xs);+ color: var(--text);+}+.set-swatches { display: flex; gap: 6px; }+.set-swatch {+ width: 22px;+ height: 22px;+ border-radius: var(--r-sm);+ border: 1px solid var(--border-line);+ cursor: pointer;+ transition: box-shadow var(--t-fast);+}+.set-swatch.on { box-shadow: 0 0 0 2px var(--srf-2), 0 0 0 4px var(--acc); }+.set-seg { display: flex; background: var(--inset); border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }+.set-seg button { padding: 4px 11px; font-size: var(--fs-xs); color: var(--text-dim); transition: color var(--t-fast), background var(--t-fast); }+.set-seg button.on { background: var(--acc); color: #fff; }++/* Pill toggle (the design's `.toggle`; not yet in the shared theme). */+.toggle {+ width: 30px;+ height: 17px;+ border-radius: var(--r-pill);+ background: var(--srf-5);+ position: relative;+ cursor: pointer;+ flex-shrink: 0;+ transition: background var(--t-fast);+}+.toggle::after {+ content: '';+ position: absolute;+ top: 2px;+ left: 2px;+ width: 13px;+ height: 13px;+ border-radius: 50%;+ background: var(--text-dim);+ transition: left var(--t-fast) var(--e-out), background var(--t-fast);+}+.toggle.on { background: var(--acc); }+.toggle.on::after { left: 15px; background: #fff; }diff --git a/desktop/tests/settings.test.ts b/desktop/tests/settings.test.tsnew file mode 100644index 000000000..401b228fa--- /dev/null+++ b/desktop/tests/settings.test.ts@@ -0,0 +1,57 @@+/**+ * @file Settings registry + store. Importing '@/settings' registers the built-in+ * sections/settings (side effect); the store resolves defaults, persists+ * owned values (here: console cap → LogStore), and delegates bound settings+ * to their live store (editorStore). DOM-effect settings (accent / UI scale)+ * aren't exercised — the suite runs in a node environment.+ */+import { describe, it, expect } from 'vitest';+import '@/settings';+import { settingsRegistry } from '@/settings/registry';+import { useSettings } from '@/store/settingsStore';+import { useEditorStore } from '@/store/editorStore';+import { LogStore } from '@/store/LogStore';++describe('settings registry', () => {+ it('registers the editor sections', () => {+ const ids = settingsRegistry.allSections().map((s) => s.id);+ expect(ids).toEqual(expect.arrayContaining(['appearance', 'viewport', 'shortcuts', 'console']));+ });++ it('groups sections by category for the nav', () => {+ const editor = settingsRegistry.sectionsByCategory().find((c) => c.category === 'editor');+ expect(editor?.sections.length).toBeGreaterThan(0);+ });++ it('generates read-only keybinding rows from the command registry', () => {+ const rows = settingsRegistry.settingsForSection('shortcuts');+ expect(rows.length).toBeGreaterThan(0);+ expect(rows.every((s) => s.type === 'keybinding')).toBe(true);+ });+});++describe('settings store', () => {+ it('getValue returns the registered default', () => {+ expect(useSettings.getState().getValue('console.maxLines')).toBe(2000);+ });++ it('an owned setting persists its value, pushes its effect, and resets', () => {+ const s = useSettings.getState();+ s.setValue('console.maxLines', 500);+ expect(s.getValue('console.maxLines')).toBe(500);+ expect(s.isChanged('console.maxLines')).toBe(true);+ expect(LogStore.getCap()).toBe(500); // effect ran+ s.reset('console.maxLines');+ expect(s.getValue('console.maxLines')).toBe(2000);+ expect(s.isChanged('console.maxLines')).toBe(false);+ });++ it('a bound setting delegates get/set to its live store', () => {+ const s = useSettings.getState();+ useEditorStore.setState({ showGrid: true });+ expect(s.getValue('viewport.showGrid')).toBe(true);+ s.setValue('viewport.showGrid', false);+ expect(useEditorStore.getState().showGrid).toBe(false);+ expect(s.getValue('viewport.showGrid')).toBe(false);+ });+});