From da5484987f47924883417e25791d394f306ecd5b Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Thu, 26 Nov 2026 19:47:19 +0900 Subject: [PATCH 1/9] feat(editor): adopt Spec design tokens, geometry/motion constants, and zero-literal enforcement (#1002) --- .../2026-11-26-editor-spec-design-tokens.md | 30 ++ .github/PULL_REQUEST_TEMPLATE.md | 11 + changelog.d/editor-spec-design-tokens.md | 7 + docs/en/editor.md | 21 +- docs/zh/editor.md | 21 +- packages/game/editor/asset_drawer_ui.go | 4 +- packages/game/editor/asset_gen.go | 8 +- packages/game/editor/asset_gen_ui.go | 27 +- packages/game/editor/asset_import_model.go | 15 +- packages/game/editor/asset_import_pivot.go | 33 +- packages/game/editor/browser.go | 2 +- packages/game/editor/build_release_ui.go | 6 +- packages/game/editor/changes_ui.go | 12 +- packages/game/editor/collider3d_gizmo.go | 13 +- packages/game/editor/cutscene_ui.go | 14 +- .../game/editor/editormcp/viewport_text.go | 3 +- packages/game/editor/files.go | 2 +- packages/game/editor/focus_regions.go | 2 +- packages/game/editor/gizmo2d.go | 16 +- packages/game/editor/gizmo3d.go | 11 +- packages/game/editor/gridmap.go | 43 +-- packages/game/editor/gridmap_palette.go | 9 +- packages/game/editor/handles3d.go | 79 ++--- packages/game/editor/hud_layout_ui.go | 30 +- packages/game/editor/input_map_panel.go | 23 +- packages/game/editor/inspector.go | 102 +++--- packages/game/editor/inspector_edit.go | 27 +- packages/game/editor/inspector_scrub.go | 115 ++----- packages/game/editor/inspector_sections.go | 18 +- packages/game/editor/layers_panel.go | 4 +- packages/game/editor/library.go | 2 +- packages/game/editor/lights2d_editor.go | 10 +- packages/game/editor/materials.go | 2 +- packages/game/editor/materials_ui.go | 17 +- packages/game/editor/merge_conflict_ui.go | 20 +- packages/game/editor/model_thumbs.go | 2 +- packages/game/editor/navmesh3d.go | 7 +- packages/game/editor/navmesh3d_panel.go | 2 +- packages/game/editor/navmesh3d_test.go | 4 +- packages/game/editor/navregion2d_editor.go | 26 +- packages/game/editor/parallax_test.go | 5 +- packages/game/editor/particles.go | 5 +- packages/game/editor/particles_ui.go | 29 +- packages/game/editor/physics_debug.go | 9 +- packages/game/editor/play_marks_ui.go | 20 +- packages/game/editor/playtest_report_ui.go | 24 +- packages/game/editor/profiler_ui.go | 46 +-- packages/game/editor/rig_handles.go | 43 +-- packages/game/editor/rooms.go | 21 +- packages/game/editor/scenetree.go | 2 +- packages/game/editor/shapes2d.go | 28 +- packages/game/editor/spec_panel_ui.go | 45 +-- packages/game/editor/spec_theme.go | 181 ++++++++-- packages/game/editor/spec_theme.yaml | 12 + packages/game/editor/spec_theme_test.go | 310 ++++++++++++++++++ packages/game/editor/start_screen_ui.go | 67 ++-- packages/game/editor/states_ui.go | 14 +- packages/game/editor/terrain.go | 37 ++- packages/game/editor/tile_review.go | 19 +- packages/game/editor/tile_review_ui.go | 14 +- packages/game/editor/tilebrush.go | 18 +- packages/game/editor/tilebrush_test.go | 4 +- packages/game/editor/tilestroke.go | 21 +- packages/game/editor/tilestroke_test.go | 17 +- packages/game/editor/ui.go | 6 +- packages/game/editor/usages_ui.go | 12 +- packages/game/editor/viewport.go | 2 +- packages/game/editor/viewport3d.go | 34 +- .../game/editor/viewport3d_lod_occluder.go | 24 +- 69 files changed, 1181 insertions(+), 688 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-11-26-editor-spec-design-tokens.md create mode 100644 changelog.d/editor-spec-design-tokens.md diff --git a/.agents/notes/implemented/feature/2026-11-26-editor-spec-design-tokens.md b/.agents/notes/implemented/feature/2026-11-26-editor-spec-design-tokens.md new file mode 100644 index 000000000..8370e2372 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-11-26-editor-spec-design-tokens.md @@ -0,0 +1,30 @@ +# Agent Note: Editor Spec design tokens, geometry and motion constants, and zero-literal enforcement + +Status: implemented + +## Problem + +While [the Spec light/dark theme note](./2026-11-26-editor-spec-light-theme.md) established the embedded `spec_theme.yaml` file and WCAG 2.2 contrast table for `SpecPalette`, dozens of editor views, 2D/3D viewport overlays, gizmos, handles, and debug layers still hardcoded `core.RGB`/`core.RGBA` and hex color literals (including Tailwind slate/sky/emerald hues and duplicate local token tables). There was also no exported single source of truth for the Spec's typography, spacing, corner radius, height, and reduced-motion constants, no 3D axis tokens in `spec_theme.yaml`, and no automated test preventing new hardcoded UI color literals from creeping back into `packages/game/editor`. + +## Decision + +`packages/game/editor/spec_theme.yaml` and `packages/game/editor/spec_theme.go` are the sole source of UI color, type, spacing, shape, height, and motion tokens across the editor, enforced by both WCAG contrast tests and an AST-based zero-literal test. + +### Key design choices + +- **3D axis and interaction tokens in `spec_theme.yaml`**: Added `specAxisX` (`#FF6B6B` dark / `#C92A2A` light), `specAxisY` (`#4FD38A` dark / `#0D7A43` light), `specAxisZ` (`#3B7BFF` dark / `#1D5CE6` light) from `docs/design/editor/Viewport3D.dc.html`, plus `specPrimaryHover`, `specViewport3DGround`, and `specViewport3DGrid`, and exposed `HoverOverlay`/`ActiveOverlay` from `core.Palette.SurfaceHover`/`SurfacePressed`. All three 3D axis tokens are checked at `>= 3.0:1` against `Viewport` in `SpecContrastTable` for both dark and light appearances. +- **Exported Spec geometry, type, and motion constants**: Defined `SpecFont*` (Inter title `14/600`, body `12.5/400`, section `11/600` at `+6%` tracking, JetBrains Mono `11.5`), `SpecSpace4`–`SpecSpace24` (`4, 8, 12, 16, 24`), `SpecRadiusControl`/`Button`/`Card`/`Dialog` (`6, 8, 12, 18`), `SpecRowHeight`/`SpecMinHitSize`/`SpecButtonHeight`/`SpecButtonTallHeight`/`SpecHeaderHeight` (`28, 28, 30, 32, 44`), `SpecBorderWidth` (`1`), `SpecIconSize`/`SpecIconStrokeWidth` (`15, 1.8`), and `SpecMotionHover`/`Panel`/`Overlay`/`AgentPulse` (`120 ms, 180 ms, 240 ms, 1.6 s`). `SpecMotionDuration` and `SpecAgentPulseOpacity` turn off all motion (`0` duration, solid `1.0` opacity) under `Env.ReduceMotion()`. +- **Var-time theme loading**: `parsedSpecTheme`, `darkSpecPalette`, and `lightSpecPalette` are loaded by a package-level variable initializer (`loadSpecTheme()`) rather than `init()`, guaranteeing deterministic initialization order for package-level derived color variables across other files in `editor`. +- **Zero hardcoded UI color literals outside `spec_theme.go`**: Every non-test `.go` file in `packages/game/editor` (including `editormcp/`) replaces `core.RGB`/`core.RGBA` and UI hex literals with `SpecPalette` tokens, `specAlpha`, `CompositeOver`, or `colorFromRGBA8` (for dynamic raster asset pixels and heightmap layer RGB data). Scene content defaults (such as `BackgroundColor`, default 3D light/sky/fog colors, and hex text-field placeholders) remain scene data, not UI chrome. Side panels (`SceneTreeView`, `LayersView`, `AssetBrowserView`, `FilesView`, `LibraryView`) render in `panel` (`colors.Surface()`) with `line` dividers, and `InspectorView` inherits the root `SpecTheme()` / `Editor.SpecPalette(cx)` directly instead of overriding a dark-only subtree theme. +- **AST-enforced guardrail and WCAG mutation test**: `TestSpecNoHardcodedColorLiteralsInEditor` parses every non-test `.go` file under `packages/game/editor` (excluding `spec_theme.go`) with `go/parser` and fails on any `core.RGB`/`core.RGBA` call or hardcoded UI hex color literal. `TestSpecContrastTableRejectsRetiredMutedColor` verifies that mutating dark `textMuted`/`specTextFaint` back to `#6F7684` causes the contrast check to fail. +- **PR checklist and synchronized docs**: Added the Spec's "Acceptance for every editor PR" checklist to `.github/PULL_REQUEST_TEMPLATE.md` and documented the full design-token contract in both `docs/en/editor.md` and `docs/zh/editor.md`. + +## Alternatives considered + +- **Regex-only grep test instead of `go/parser` AST scanning**: rejected because regex scans produce false positives on non-color 64-bit PRNG constants (`splitmix64` in `tilebrush.go`) and scene content YAML defaults (`BackgroundColor`, sky/fog placeholders), whereas AST inspection accurately targets `core.RGB`/`core.RGBA` calls and color-typed expressions while keeping exemptions minimal and explicit. +- **Keeping separate Tailwind hues for 2D/3D debug overlays (physics, navmesh, rig, terrain, LOD)**: rejected because the Spec explicitly forbids off-board UI color literals in `packages/game/editor`, and mapping debug overlays onto `SpecPalette` roles (`Accent`, `Agent`, `Added`, `Changed`, `Removed`, `Warning`, `AxisX`/`Y`/`Z`) ensures visual consistency and WCAG-checked contrast in both dark and light modes. + +## Consequences + +- **Benefits**: Every editor chrome region, gizmo, overlay, and debug canvas now draws strictly from `spec_theme.yaml` with dark/light parity; CI automatically blocks accidental re-introduction of `core.RGB`/`core.RGBA` or retired contrast-failing colors; typography, spacing, radii, heights, and reduced-motion rules are codified as reusable exported constants. +- **Costs**: Adding any new semantic color to the editor requires adding a named token to both `dark` and `light` in `spec_theme.yaml`, wiring it into `SpecPalette`, and verifying it in `SpecContrastTable` rather than writing an inline hex literal. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6e6264aea..0805c07e3 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -18,3 +18,14 @@ Fixes # ## Screenshots + +## Acceptance for every editor PR + + + +- [ ] Real screenshots from `nsgotest` on macOS, before and after, beside the matching artboard. +- [ ] Uses only the tokens in `packages/game/editor/spec_theme.yaml` (`SpecPalette`), and every text pair is in the WCAG 2.2 contrast table. +- [ ] Every control shows the focus ring and is reachable with `Tab`, `F6`, or arrow keys. +- [ ] Every action has a shortcut row with a scope and a matching MCP tool (when applicable). +- [ ] Overlays follow the Spec line-style legend; nothing is told apart by hue alone. +- [ ] Reviewed by a person looking at the screenshots, not only by tests. diff --git a/changelog.d/editor-spec-design-tokens.md b/changelog.d/editor-spec-design-tokens.md new file mode 100644 index 000000000..05ec1478f --- /dev/null +++ b/changelog.d/editor-spec-design-tokens.md @@ -0,0 +1,7 @@ +### Added + +- `game/editor`: added Spec typography, spacing, radius, height, border, and reduced-motion constants (`SpecFont*`, `SpecSpace*`, `SpecRadius*`, `SpecRowHeight`, `SpecButtonHeight`, `SpecHeaderHeight`, `SpecMotion*`, `SpecMotionDuration`, `SpecAgentPulseOpacity`), 3D axis tokens (`AxisX`, `AxisY`, `AxisZ`) from `Viewport3D.dc.html` in `spec_theme.yaml`, an AST test refusing `core.RGB`/`core.RGBA` and hardcoded UI hex color literals outside `spec_theme.go`, a Design tokens section in `docs/en/editor.md` and `docs/zh/editor.md`, and the Spec editor PR acceptance checklist in `.github/PULL_REQUEST_TEMPLATE.md` (#1002). + +### Changed + +- `game/editor`: replaced all hardcoded UI `core.RGB`/`core.RGBA` and hex color literals across the editor's panels, 2D/3D viewports, gizmos, handles, and debug overlays with `SpecPalette` tokens from `spec_theme.yaml`, and updated the toolbar scene title to Spec `14 / 600` (`SpecFontTitleSize`, `SpecFontTitleWeight`) (#1002). diff --git a/docs/en/editor.md b/docs/en/editor.md index 48861a116..9e2bfdf5a 100644 --- a/docs/en/editor.md +++ b/docs/en/editor.md @@ -1561,7 +1561,6 @@ Every edit an agent makes through the editor's MCP server between the start and - **Right-panel Agent tab & Summary Card (`RightRailView` / `AgentPanelView`)**: switch between **Agent** (`mod+1` / `CmdAgentTab`) and **Inspector** (`mod+2` / `CmdInspectorTab`) in the right panel header (showing a live pending indicator dot and MCP connection status). Styled exclusively with `Spec.dc.html` tokens matching `Main.dc.html` (localized in English and Chinese), the Agent panel displays the request bubble, progress steps, working **Stop (`⌘.`)** control, completion summary, the small summary card (`"6 changes · 1 file · +38 −0"`, grouped changes with per-change and per-file Revert/Restore, **Keep**, **Review**, **Revert**), Kept/Reverted notes (`"one undo step (⌘Z)"`), and the composer with `"Edits stay unsaved until you keep them"`. - **Navigation, close, and boundary protection**: opening another scene (`RequestOpenScene`), switching scene tabs (`RequestSelectTab`), switching projects (`RequestOpenProject`), closing the window, or quitting with a pending turn prompts **Keep**, **Revert**, or **Cancel** (`pendingTurnDialog`), matching unsaved-changes behavior. Every staged file enforces project-root symlink containment, refuses `.git/**` and You-only files, enforces a 2 MiB per-file limit, and resets cleanly on `OpenProject` and `OpenDemo`. - **MCP surface (`editormcp`)**: `turn_start`, `turn_end`, `turn_status` (read-only, reporting reverted changes), and `file_edit` (validating `game.yaml`, data tables, clips, prefabs, and scenes in memory) work alongside `scene_edit` and `object_set_field`'s `why` support. By design there is no MCP tool that keeps or reverts a turn. - ## Agent panel failure, recovery, and offline states (#1024) When an agent request does not simply succeed, `AgentPanelView` renders dedicated `docs/design/editor/AgentStates.dc.html` cards using exclusively `SpecPalette` tokens (both Dark and Light themes) while keeping every manual editing tool (Select, Move, Inspector, `CheckProblems`, and Play) working in every state: @@ -1572,7 +1571,6 @@ When an agent request does not simply succeed, `AgentPanelView` renders dedicate - **Stopped (`AgentStoppedState`)**: stopping a running turn records `DONE` and `NOT DONE` step sections, **Resume** (`ResumeAgentTurn`, which starts strictly at the first not-done step and skips steps already done), and **Review N changes**; completed changes stay unkept until explicitly reviewed and kept. - **Mismatch (`AgentMismatchReport`)**: the editor automatically checks every turn summary against the actual diff (`CheckAgentSummaryAgainstDiff`) and displays a `WHAT · SUMMARY · REVIEW` table when they disagree, including the auto-derived reason when known (for example, an object added at step 3 and removed at step 5), **Ask why** (`AskAgentWhyMismatch`), and **Open review** (`OpenAgentTurnReview`). **Keep** always applies the actual review diff, never the prose summary. - **Offline (`AgentStatusOffline`, `SetAgentOffline`)**: displays `"You're offline"` and queues submitted requests with timestamps (`AgentQueuedRequests`, `QueueAgentRequest`, `RemoveQueuedAgentRequest`) while Select, Move, the Inspector, game check, and Play keep working. Returning online never runs queued requests on its own; each queued request waits for an explicit **Send** (`SendQueuedAgentRequest`). - ## Spec viewport overlays and toggle legend (#1006) Every semantic overlay drawn over the 2D and 3D viewports passes through one shared helper (`DrawObjectOverlay`) using exclusively `SpecPalette` tokens (`docs/design/editor/Spec.dc.html`, "Overlay legend"), with a non-color second cue (corner handles, pill glyph/prefix, ghost fill, strikethrough, or filled alert badge) so every kind remains distinguishable in greyscale: @@ -1647,7 +1645,6 @@ Rewind an agent conversation to before any earlier sent message (`docs/design/ed - **Files only (`AgentRewindFilesOnly`)**: restores the files from the turns' checkpoints while keeping the conversation thread and session unchanged. - **Conversation only (`AgentRewindConversationOnly`)**: drops the target and later turns and restores the session ID while leaving all files on disk untouched. - **Post-rewind banner, Redo, and composer return**: after rewinding, the rewound message returns to the composer highlighted with the Spec accent ring (`AgentComposerRewound`) so you can edit and ask it differently, and a status banner above the composer (`AgentRewindBanner`) summarizes what was rewound with a **Redo** button (`RedoAgentRewind` / `CanRedoAgentRewind`) that restores the files, conversation turns, session ID, and prior composer draft. - ## Agent plans with clarifying questions and planned ghosts (#1035) For larger changes—such as edits touching Go code, creating files, or spanning multiple files under the project's `permissions.yaml` rules (`EvaluatePlanPermissions`, `PlanNeededForEdit`)—an agent proposes a structured plan before modifying any scene or file (`docs/design/editor/Plan.dc.html`, styled strictly with `Spec.dc.html` Dark and Light tokens): @@ -1664,3 +1661,21 @@ For larger changes—such as edits touching Go code, creating files, or spanning - While `PlanPhaseRunning`, the top header pill shows `"Agent is working · step k of N · manual edits to planned objects are paused"`, the active step's ghost switches from dashed to solid, and manual edits to planned objects (`IsObjectPausedByPlan`) are paused until completion or stop. - Pressing **Stop**, `Esc`, or `⌘.` before step 1 writes anything (`StopAgentPlan`) leaves every file unchanged (`NothingWritten: true`) and shows `"Stopped before step 1. Nothing was written."` with **Edit plan** (`EditStoppedPlan`) and **Run again** (`RunStoppedPlanAgain`). - Once completed (`CompleteAgentPlan` / `plan_step_update` with `complete: true`), the turn's review (`AgentTurn.Plan`, `agentTurnPlanReviewView`) lists every plan step and marks which were done or skipped. Small edits started with `⌘L` continue to set `SkipPlan: true`. + +## Design tokens (#1002) + +Every color, type size, spacing step, corner radius, height, and motion duration in the editor comes from the embedded YAML theme and constants defined in `packages/game/editor/spec_theme.yaml` and `packages/game/editor/spec_theme.go`, matching `docs/design/editor/Spec.dc.html` and `docs/design/editor/Viewport3D.dc.html`: + +- **Embedded YAML theme (`spec_theme.yaml`, `SpecTheme`, `SpecPalette`)**: loaded with `core.ParseTheme` and attached on `EditorView`'s root scope via `cx.SetTheme(SpecTheme())`. Every NSGo `core.Palette` and `ui.ColorsOf` role (`Background`, `Surface`, `Raised`, `Line`, `Border`, `Text`, `TextMuted`, `Accent`, `AccentText`, `Success`, `Warning`, `Danger`, `Focus`) maps directly onto the Spec palette in both dark and light appearances, while `Editor.SpecPalette(cx)` (`DarkSpecPalette()`, `LightSpecPalette()`, `SpecPaletteFor(dark)`) exposes the additional Spec roles (`TextPrimary` / text strong, `TextSecondary` / text, `TextMuted` / text secondary, `TextFaint` / text muted, `OnTextPrimary`, `Viewport`, `ViewportDot`, `PillBg`, `HoverOverlay`, `ActiveOverlay`, `PrimaryHover`, `Viewport3DGround`, `Viewport3DGrid`, `Accent`, `Agent`, `Added`, `Changed`, `Removed`/`Problem`, `Warning` with dedicated `Fill` and `Edge`, and 3D axis tokens `AxisX`, `AxisY`, `AxisZ`). +- **Dark palette tokens (`Spec.dc.html` & `Viewport3D.dc.html`)**: + - Surfaces & borders: `bg #101216`, `panel #12141A`, `raised #171A21`, `line #1F232A`, `line raised #262B35`, `viewport #15181D`, `viewportDot #2A2F38`. + - Text ladder: `text strong #FFFFFF`, `text #D9DDE5`, `text secondary #B4BAC6`, `text muted #8B92A0`. The retired `#6F7684`, `#5D6472`, and `#4A505C` are never used for text. + - Semantic roles: `accent #3B7BFF` (on-fill ink `#101216` at weight 600; `#FFFFFF` on dark accent or agent is never used), `agent #9B7BFF`, `added #4FD38A`, `changed #E9A84A`, `removed · problem #FF6B6B`, `warning #F2C14E` (on fill `#2A2414`, edge `#4A3F1F`). + - 3D axes (`Viewport3D.dc.html`): `axisX #FF6B6B`, `axisY #4FD38A`, `axisZ #3B7BFF` (with WCAG-passing light equivalents `#C92A2A`, `#0D7A43`, `#1D5CE6`). +- **Measured WCAG 2.2 contrast table (`SpecContrastTable`, `ContrastRatio`)**: `TestSpecContrastTableDarkAndLight` computes the WCAG 2.2 luminance contrast ratio of every foreground/background, on-fill, warning-card, pill, overlay, and 3D axis pair directly from `spec_theme.yaml` for both dark and light palettes, failing below `4.5:1` for text/on-fill or `3.0:1` for UI/overlay edges. A dedicated regression test verifies that reverting dark `text_muted` to `#6F7684` fails the check. +- **Type, spacing, shape, heights, and motion constants**: + - Type scale: Inter title `14 / 600` (`SpecFontTitleSize`, `SpecFontTitleWeight`), body `12.5 / 400` (`SpecFontBodySize`, `SpecFontBodyWeight`), section `11 / 600` at `+6%` tracking (`SpecFontSectionSize`, `SpecFontSectionWeight`, `SpecFontSectionTrack`), JetBrains Mono `11.5` (`SpecFontCodeSize`, `SpecFontFamilyMono`). + - Spacing: `4`, `8`, `12`, `16`, `24` px only (`SpecSpace4`–`SpecSpace24`). + - Radii & geometry: `6` controls (`SpecRadiusControl`), `8` buttons (`SpecRadiusButton`), `12` cards and toasts (`SpecRadiusCard`), `18` dialogs (`SpecRadiusDialog`); heights `28` rows/tool buttons (`SpecRowHeight`, minimum hit area `SpecMinHitSize = 28`), `30`–`32` buttons (`SpecButtonHeight`, `SpecButtonTallHeight`), `44` header (`SpecHeaderHeight`); `1` px inner borders (`SpecBorderWidth`). + - Motion: `120 ms` hover/press (`SpecMotionHover`), `180 ms` panels/popovers/toasts (`SpecMotionPanel`), `240 ms` agent overlays (`SpecMotionOverlay`), `1.6 s` agent pulse (`SpecMotionAgentPulse`, `100%` ↔ `45%` opacity). `SpecMotionDuration` and `SpecAgentPulseOpacity` disable all motion (`0` duration, solid `1.0` opacity) whenever `Env.ReduceMotion` is enabled. +- **No hardcoded UI color literals**: every non-test `.go` file in `packages/game/editor` outside `spec_theme.go` draws UI chrome, gizmos, overlays, and debug views exclusively from `SpecPalette` tokens (scene content data such as `scene.BackgroundColor` stays scene data). `TestSpecNoHardcodedColorLiteralsInEditor` scans the package AST and fails on any `core.RGB`/`core.RGBA` call or hardcoded UI hex color literal outside `spec_theme.go`. diff --git a/docs/zh/editor.md b/docs/zh/editor.md index 26d9be606..b9185a26d 100644 --- a/docs/zh/editor.md +++ b/docs/zh/editor.md @@ -1561,7 +1561,6 @@ func main() { - **右侧 Agent 标签页与摘要卡片(`RightRailView` / `AgentPanelView`)**:右侧栏顶部支持在 **Agent**(`mod+1` / `CmdAgentTab`)与 **Inspector**(`mod+2` / `CmdInspectorTab`)之间切换,并显示待确认状态点与 MCP 连接状态。界面严格使用 `Spec.dc.html` 令牌并对应 `Main.dc.html` 布局(完整支持中英文界面),展示请求气泡、进度步骤、工作中的 **Stop(`⌘.`)** 按钮、完成摘要、精简摘要卡片(`"6 changes · 1 file · +38 −0"`、按类型展示的变更列表与单条/按文件还原恢复按钮、**Keep** / **Review** / **Revert**)、已保留/已还原状态(`"one undo step (⌘Z)"`)以及带 `"Edits stay unsaved until you keep them"` 提示的输入框。 - **切换场景/标签页/项目、关闭与安全边界保护**:存在待确认回合时,打开其他场景(`RequestOpenScene`)、切换场景标签页(`RequestSelectTab`)、切换项目(`RequestOpenProject`)、关闭窗口或退出应用都会弹出 **Keep / Revert / Cancel** 确认框(`pendingTurnDialog`),与未保存修改的行为保持一致。所有暂存文件均强制校验项目根目录符号链接包含性、拒绝 `.git/**` 与“仅限本人”配置文件、限制单文件 2 MiB 上限,并在 `OpenProject` 与 `OpenDemo` 时彻底重置状态。 - **MCP 工具(`editormcp`)**:提供 `turn_start`、`turn_end`、`turn_status`(只读,如实报告已还原的变更)和 `file_edit`(在内存中校验并编辑 `game.yaml`、数据表、动画片段、预制体与场景),并为 `scene_edit` 与 `object_set_field` 增加 `why` 参数;按设计不提供可由智能体调用的保留或还原回合工具。 - ## 智能体面板的失败、恢复与离线状态(#1024) 当智能体请求未能直接成功完成时,`AgentPanelView` 会严格使用 `SpecPalette` 设计 Token(支持深浅外观)渲染 `docs/design/editor/AgentStates.dc.html` 定义的六种状态卡片,并且在所有状态下保持选择、移动、检视器、`CheckProblems` 与 Play 等手动编辑工具正常工作: @@ -1572,7 +1571,6 @@ func main() { - **已停止(`AgentStoppedState`)**:停止运行中的请求后,卡片分区列出 `DONE` 与 `NOT DONE` 步骤,提供 **Resume**(`ResumeAgentTurn`,从首个未完成步骤开始继续,跳过已完成步骤不重复执行)与 **Review N changes**;已生成的改动在审查采纳前保持未保留状态。 - **摘要与差异不一致(`AgentMismatchReport`)**:编辑器会自动将每条智能体摘要与实际 diff 比对(`CheckAgentSummaryAgainstDiff`),当两者不一致时展示 `WHAT · SUMMARY · REVIEW` 对比表与已知原因(例如某对象在第 3 步被添加、第 5 步被移除),并提供 **Ask why**(`AskAgentWhyMismatch`)与 **Open review**(`OpenAgentTurnReview`)。点击 **Keep** 始终仅采纳实际审查差异,绝不采纳摘要中的虚构数量。 - **离线队列(`AgentStatusOffline`、`SetAgentOffline`)**:展示 `"You're offline"`,并在保持选择、移动、检视器、游戏检查与 Play 全部可用的同时,将提交的请求连同时间戳加入队列(`AgentQueuedRequests`、`QueueAgentRequest`、`RemoveQueuedAgentRequest`)。恢复联网后队列中的请求不会自动执行,而是逐条等待用户手动点击 **Send**(`SendQueuedAgentRequest`)发送。 - ## 规范视口叠加层与可切换图例(#1006) 2D 与 3D 视口中的所有语义叠加层都通过统一绘制辅助函数 `DrawObjectOverlay` 绘制,完全使用 `SpecPalette` 令牌(对应 `docs/design/editor/Spec.dc.html` 中的 “Overlay legend”),且每一种类型都配备非颜色的第二视觉线索(角点手柄、胶囊图标/前缀、灰色幽灵填充、删除线或实心警告徽章),在灰度下依然彼此可辨: @@ -1647,7 +1645,6 @@ func main() { - **仅文件(`AgentRewindFilesOnly`)**:从回合检查点还原文件,同时保持对话记录与会话不变。 - **仅对话(`AgentRewindConversationOnly`)**:移除目标及后续回合与会话推进,同时保持磁盘文件现状不变。 - **回退横幅、重做与消息回到输入框**:回退完成后,被回退的消息会重新填入输入框并以规范强调色边框高亮(`AgentComposerRewound`),方便修改后重新发送;输入框上方会显示状态横幅(`AgentRewindBanner`)说明已回退的范围,并提供 **Redo** / **重做** 按钮(`RedoAgentRewind` / `CanRedoAgentRewind`)一键恢复文件、对话回合、会话 ID 与原有输入框草稿。 - ## 智能体执行前提出计划、澄清问题与规划虚影(#1035) 对于较大规模的修改(例如依据项目 `permissions.yaml` 规则会修改 Go 代码、新建文件或跨多个文件的操作,`EvaluatePlanPermissions`、`PlanNeededForEdit`),智能体会在修改任何场景或文件前先提出结构化计划(对应 `docs/design/editor/Plan.dc.html`,严格遵循 `Spec.dc.html` 深色与浅色令牌): @@ -1664,3 +1661,21 @@ func main() { - 进入执行态(`PlanPhaseRunning`)后,顶部标题栏显示状态胶囊(`"Agent is working · step k of N · manual edits to planned objects are paused"`),当前活动步骤的虚影变为实线,并暂停对被规划对象的手动修改(`IsObjectPausedByPlan`)。 - 在第 1 步写入任何内容前点击**停止**、按 `Esc` 或 `⌘.`(`StopAgentPlan`),所有文件保持原样(`NothingWritten: true`),底部显示“已在第 1 步前停止,未写入任何内容”并提供**编辑计划**(`EditStoppedPlan`)与**重新运行**(`RunStoppedPlanAgain`)。 - 计划完成后(`CompleteAgentPlan` 或 `plan_step_update` 传入 `complete: true`),该回合的审查视图(`AgentTurn.Plan`、`agentTurnPlanReviewView`)会列出计划的全部步骤并标明已完成或已跳过的条目。使用 `⌘L` 发起的小修改仍通过 `SkipPlan: true` 跳过计划。 + +## 设计令牌(#1002) + +编辑器中的每一处色彩、字号、间距阶梯、圆角、高度与动效时长都统一来自嵌入的 YAML 主题文件与常量定义(`packages/game/editor/spec_theme.yaml` 与 `packages/game/editor/spec_theme.go`),与 `docs/design/editor/Spec.dc.html` 及 `docs/design/editor/Viewport3D.dc.html` 保持一致: + +- **嵌入 YAML 主题(`spec_theme.yaml`、`SpecTheme`、`SpecPalette`)**:通过 `core.ParseTheme` 解析并在 `EditorView` 根作用域通过 `cx.SetTheme(SpecTheme())` 生效。NSGo 的所有 `core.Palette` 与 `ui.ColorsOf` 角色(`Background`、`Surface`、`Raised`、`Line`、`Border`、`Text`、`TextMuted`、`Accent`、`AccentText`、`Success`、`Warning`、`Danger`、`Focus`)均在深色与浅色外观下直接映射到规范调色板;`Editor.SpecPalette(cx)`(以及 `DarkSpecPalette()`、`LightSpecPalette()`、`SpecPaletteFor(dark)`)同时提供 NSGo 未命名的规范角色(`TextPrimary` / 强文本、`TextSecondary` / 正文、`TextMuted` / 次级文本、`TextFaint` / 弱化文本、`OnTextPrimary`、`Viewport`、`ViewportDot`、`PillBg`、`HoverOverlay`、`ActiveOverlay`、`PrimaryHover`、`Viewport3DGround`、`Viewport3DGrid`、`Accent`、`Agent`、`Added`、`Changed`、`Removed`/`Problem`、含专用 `Fill` 与 `Edge` 的 `Warning`,以及 3D 坐标轴令牌 `AxisX`、`AxisY`、`AxisZ`)。 +- **深色模式色彩令牌(`Spec.dc.html` 与 `Viewport3D.dc.html`)**: + - 表面与边框:`bg #101216`、`panel #12141A`、`raised #171A21`、`line #1F232A`、`line raised #262B35`、`viewport #15181D`、`viewportDot #2A2F38`。 + - 四级文本:`text strong #FFFFFF`、`text #D9DDE5`、`text secondary #B4BAC6`、`text muted #8B92A0`。已退役的 `#6F7684`、`#5D6472` 与 `#4A505C` 不再用于文本。 + - 语义角色:`accent #3B7BFF`(填充上的文字使用 `#101216` 且字重 600,绝不在深色强调色或智能体色填充上使用 `#FFFFFF`)、`agent #9B7BFF`、`added #4FD38A`、`changed #E9A84A`、`removed · problem #FF6B6B`、`warning #F2C14E`(填充 `#2A2414`、描边 `#4A3F1F`)。 + - 3D 坐标轴(`Viewport3D.dc.html`):`axisX #FF6B6B`、`axisY #4FD38A`、`axisZ #3B7BFF`(浅色模式对应通过 WCAG 校验的 `#C92A2A`、`#0D7A43`、`#1D5CE6`)。 +- **实测 WCAG 2.2 对比度表(`SpecContrastTable`、`ContrastRatio`)**:`TestSpecContrastTableDarkAndLight` 直接从 `spec_theme.yaml` 计算深色与浅色两套主题中每一组前景/背景、实心填充文字、警告卡片、胶囊标签、视口叠加层与 3D 坐标轴的 WCAG 2.2 亮度对比度;常规文本及填充文字低于 `4.5:1`、UI 边界与叠加层低于 `3.0:1` 即报错,并包含回归测试验证将深色 `text_muted` 退回 `#6F7684` 时测试必然失败。 +- **排版、间距、圆角、高度与动效常量**: + - 排版:Inter 标题 `14 / 600`(`SpecFontTitleSize`、`SpecFontTitleWeight`)、正文 `12.5 / 400`(`SpecFontBodySize`、`SpecFontBodyWeight`)、分区标题 `11 / 600` 加 `+6%` 字距(`SpecFontSectionSize`、`SpecFontSectionWeight`、`SpecFontSectionTrack`)、代码 JetBrains Mono `11.5`(`SpecFontCodeSize`、`SpecFontFamilyMono`)。 + - 间距:仅使用 `4`、`8`、`12`、`16`、`24` px(`SpecSpace4`–`SpecSpace24`)。 + - 圆角与几何:控件 `6`(`SpecRadiusControl`)、按钮 `8`(`SpecRadiusButton`)、卡片与轻提示 `12`(`SpecRadiusCard`)、对话框 `18`(`SpecRadiusDialog`);行与工具按钮高 `28`(`SpecRowHeight`,最小命中热区 `SpecMinHitSize = 28`)、按钮高 `30`–`32`(`SpecButtonHeight`、`SpecButtonTallHeight`)、顶栏高 `44`(`SpecHeaderHeight`);`1` px 内描边(`SpecBorderWidth`)。 + - 动效:悬停与按压 `120 ms`(`SpecMotionHover`)、面板/浮层/轻提示 `180 ms`(`SpecMotionPanel`)、智能体叠加层淡入 `240 ms`(`SpecMotionOverlay`)、智能体脉冲 `1.6 s`(`SpecMotionAgentPulse`,透明度 `100%` ↔ `45%`)。开启 `Env.ReduceMotion` 时,`SpecMotionDuration` 返回 `0`,`SpecAgentPulseOpacity` 保持 `1.0` 不闪烁。 +- **禁止硬编码 UI 颜色字面量**:`packages/game/editor` 中除 `spec_theme.go` 外的所有非测试 `.go` 文件在绘制界面元素、操纵杆、叠加层与调试视图时仅使用 `SpecPalette` 令牌(场景内容数据如 `scene.BackgroundColor` 保留为场景数据)。`TestSpecNoHardcodedColorLiteralsInEditor` 通过 AST 静态扫描整个编辑器包,一旦在 `spec_theme.go` 之外出现任何 `core.RGB`/`core.RGBA` 调用或硬编码 UI 十六进制颜色即令测试失败。 diff --git a/packages/game/editor/asset_drawer_ui.go b/packages/game/editor/asset_drawer_ui.go index 9286be436..e98a3e8e0 100644 --- a/packages/game/editor/asset_drawer_ui.go +++ b/packages/game/editor/asset_drawer_ui.go @@ -11,8 +11,8 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Spec-derived checker tint using exclusively Spec.dc.html base tokens. -var specCheckerAlt = core.RGBA(0x262B35, 0.36) +// Spec-derived checker tint using exclusively spec_theme.yaml base tokens. +var specCheckerAlt = specAlpha(darkSpecPalette.LineRaised, 0.36) type versionedAssetSnap struct { key assetDrawerRailKey diff --git a/packages/game/editor/asset_gen.go b/packages/game/editor/asset_gen.go index 7f01d0ce4..946bf02dd 100644 --- a/packages/game/editor/asset_gen.go +++ b/packages/game/editor/asset_gen.go @@ -131,9 +131,9 @@ func DefaultAssetStyleBrief() AssetStyleBrief { MaxPeakDB: -0.5, LoudnessTolDB: 3.0, Backgrounds: []AssetPreviewBackground{ - {ID: "floor3", Label: "Floor 3", Color: core.RGB(0x1A2130)}, - {ID: "floor1", Label: "Floor 1", Color: core.RGB(0x231D1C)}, - {ID: "checker", Label: "Checker", Color: core.RGB(0x171A21), Checker: true}, + {ID: "floor3", Label: "Floor 3", Color: CompositeOver(specAlpha(darkSpecPalette.Accent.Fg, 0.12), darkSpecPalette.Raised)}, + {ID: "floor1", Label: "Floor 1", Color: CompositeOver(specAlpha(darkSpecPalette.Changed.Fg, 0.08), darkSpecPalette.Raised)}, + {ID: "checker", Label: "Checker", Color: darkSpecPalette.Raised, Checker: true}, }, } } @@ -592,7 +592,7 @@ func parseBriefStyleYAML(data []byte, base AssetStyleBrief) AssetStyleBrief { if strings.TrimSpace(bg.ID) == "" { continue } - c := core.RGB(0x1A2130) + c := CompositeOver(specAlpha(darkSpecPalette.Accent.Fg, 0.12), darkSpecPalette.Raised) if parsedCol, err := core.ParseColor(strings.TrimSpace(bg.Color)); err == nil { c = parsedCol } diff --git a/packages/game/editor/asset_gen_ui.go b/packages/game/editor/asset_gen_ui.go index 54df9b231..71a313063 100644 --- a/packages/game/editor/asset_gen_ui.go +++ b/packages/game/editor/asset_gen_ui.go @@ -15,19 +15,19 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Spec-derived alpha tints strictly from docs/design/editor/Spec.dc.html color tokens (never introducing off-spec hex values). +// Spec-derived alpha tints strictly from spec_theme.yaml color tokens. var ( - specAssetGenSelectedBg = core.RGBA(0x3B7BFF, 0.14) - specAssetGenPillBg = core.RGBA(0x9B7BFF, 0.14) - specAssetGenPillBorder = core.RGBA(0x9B7BFF, 0.42) - specAssetGenBtnSec = core.RGBA(0xD9DDE5, 0.08) - specAssetGenCheckerTile = core.RGBA(0xD9DDE5, 0.05) - specAssetGenFloorTile = core.RGBA(0xD9DDE5, 0.09) - specAssetGenTorchGlow = core.RGBA(0xE9A84A, 0.18) - specAssetGenWavePass = core.RGBA(0x3B7BFF, 0.72) - specAssetGenWaveFail = core.RGBA(0xFF6B6B, 0.85) - specAssetGenApprovedRow = core.RGBA(0x4FD38A, 0.10) - specAssetGenProblemText = core.RGB(0xFF6B6B) + specAssetGenSelectedBg = specAlpha(darkSpecPalette.Accent.Fg, 0.14) + specAssetGenPillBg = specAlpha(darkSpecPalette.Agent.Fg, 0.14) + specAssetGenPillBorder = specAlpha(darkSpecPalette.Agent.Fg, 0.42) + specAssetGenBtnSec = specAlpha(darkSpecPalette.TextSecondary, 0.08) + specAssetGenCheckerTile = specAlpha(darkSpecPalette.TextSecondary, 0.05) + specAssetGenFloorTile = specAlpha(darkSpecPalette.TextSecondary, 0.09) + specAssetGenTorchGlow = specAlpha(darkSpecPalette.Changed.Fg, 0.18) + specAssetGenWavePass = specAlpha(darkSpecPalette.Accent.Fg, 0.72) + specAssetGenWaveFail = specAlpha(darkSpecPalette.Removed.Fg, 0.85) + specAssetGenApprovedRow = specAlpha(darkSpecPalette.Added.Fg, 0.10) + specAssetGenProblemText = darkSpecPalette.Removed.Fg ) // AssetGeneratorView renders the full-window Generated Assets screen matching docs/design/editor/Assets.dc.html @@ -1976,8 +1976,7 @@ func drawCrispPixels(d *core.Drawing, rgba *image.RGBA, x, y, maxW, maxH float32 if c.A == 0 { continue } - rgb := uint32(c.R)<<16 | uint32(c.G)<<8 | uint32(c.B) - col := core.RGBA(rgb, float32(c.A)/255.0) + col := colorFromRGBA8(c.R, c.G, c.B, c.A) d.SetFillColor(col).FillRect(ox+float32(px)*scale, oy+float32(py)*scale, scale, scale) } } diff --git a/packages/game/editor/asset_import_model.go b/packages/game/editor/asset_import_model.go index 96fb9b5e9..ce33bddb9 100644 --- a/packages/game/editor/asset_import_model.go +++ b/packages/game/editor/asset_import_model.go @@ -875,7 +875,7 @@ func (e *Editor) RenderModelPreview(relPath string, width, height int) (*image.R ColorAttachments: []gpu.ColorAttachment{{ LoadOp: gpu.LoadClear, StoreOp: gpu.StoreStore, - ClearColor: core.RGB(0x1E293B), + ClearColor: e.activeSpecPalette().Viewport, }}, DepthStencil: &gpu.DepthStencilAttachment{ DepthLoadOp: gpu.LoadClear, @@ -912,7 +912,8 @@ func (e *Editor) DrawModelPreview(d *core.Drawing, size core.Size, relPath strin if !isFiniteFloat32(cw) || !isFiniteFloat32(ch) || cw <= 0 || ch <= 0 { return } - d.SetFillColor(core.RGB(0x1E293B)).FillRect(0, 0, cw, ch) + spec := e.activeSpecPalette() + d.SetFillColor(spec.Viewport).FillRect(0, 0, cw, ch) if e == nil { return } @@ -928,10 +929,10 @@ func (e *Editor) DrawModelPreview(d *core.Drawing, size core.Size, relPath strin Version: ver, }, 0, 0, iw, ih, 0, 0, cw, ch) - drawModelPreviewTriad(d, e.ModelPreviewCamera(), cw, ch) + drawModelPreviewTriad(d, e.ModelPreviewCamera(), cw, ch, spec) } -func drawModelPreviewTriad(d *core.Drawing, cam OrbitCamera3D, cw, ch float32) { +func drawModelPreviewTriad(d *core.Drawing, cam OrbitCamera3D, cw, ch float32, spec SpecPalette) { if cw < 48 || ch < 48 { return } @@ -942,9 +943,9 @@ func drawModelPreviewTriad(d *core.Drawing, cam OrbitCamera3D, cw, ch float32) { dir [3]float32 color core.Color }{ - {[3]float32{1, 0, 0}, core.RGB(0xEF4444)}, - {[3]float32{0, 1, 0}, core.RGB(0x22C55E)}, - {[3]float32{0, 0, 1}, core.RGB(0x3B82F6)}, + {[3]float32{1, 0, 0}, spec.AxisX}, + {[3]float32{0, 1, 0}, spec.AxisY}, + {[3]float32{0, 0, 1}, spec.AxisZ}, } for _, a := range axes { px := a.dir[0]*right[0] + a.dir[1]*right[1] + a.dir[2]*right[2] diff --git a/packages/game/editor/asset_import_pivot.go b/packages/game/editor/asset_import_pivot.go index 6eb5c66fa..ff7cc37fc 100644 --- a/packages/game/editor/asset_import_pivot.go +++ b/packages/game/editor/asset_import_pivot.go @@ -510,10 +510,11 @@ func (e *Editor) DrawImageImportPreview(d *core.Drawing, size core.Size, relPath return } + spec := e.activeSpecPalette() // Draw alpha checkerboard background. - d.SetFillColor(core.RGB(0x1E293B)).FillRect(0, 0, cw, ch) + d.SetFillColor(spec.Viewport).FillRect(0, 0, cw, ch) const tile float32 = 8 - d.SetFillColor(core.RGB(0x273449)) + d.SetFillColor(spec.LineRaised) for y := float32(0); y < ch; y += tile { row := int(y / tile) for x := float32(0); x < cw; x += tile { @@ -537,7 +538,7 @@ func (e *Editor) DrawImageImportPreview(d *core.Drawing, size core.Size, relPath } dw, dh := float32(imgW)*scale, float32(imgH)*scale d.DrawImageFrom(core.ImageSource{Pixels: rgba}, 0, 0, float32(imgW), float32(imgH), ox, oy, dw, dh) - d.SetStrokeColor(core.RGBA(0x94A3B8, 0.5)).SetLineWidth(1).StrokeRect(ox, oy, dw, dh) + d.SetStrokeColor(specAlpha(spec.TextFaint, 0.5)).SetLineWidth(1).StrokeRect(ox, oy, dw, dh) info, err := e.InspectAssetImport(relPath) if err != nil { @@ -559,7 +560,7 @@ func (e *Editor) DrawImageImportPreview(d *core.Drawing, size core.Size, relPath if n > maxImportPreviewCells { // Dense grids skip drawing millions of cell outlines/markers and show only the selected cell. if sr, ok := s.CellRect(bounds, cols, sel); ok { - d.SetStrokeColor(core.RGBA(0x38BDF8, 1)).SetLineWidth(1.5).StrokeRect( + d.SetStrokeColor(spec.Accent.Edge).SetLineWidth(1.5).StrokeRect( ox+float32(sr.Min.X)*scale, oy+float32(sr.Min.Y)*scale, float32(sr.Dx())*scale, @@ -571,7 +572,7 @@ func (e *Editor) DrawImageImportPreview(d *core.Drawing, size core.Size, relPath pt = drag.livePivot } mx, my := previewPivotCanvasPos(ox, oy, scale, sr, pt) - drawPivotMarker(d, mx, my, overridden, true, draggingCell) + drawPivotMarker(d, spec, mx, my, overridden, true, draggingCell) } return } @@ -588,10 +589,10 @@ func (e *Editor) DrawImageImportPreview(d *core.Drawing, size core.Size, relPath if i == sel { continue } - d.SetStrokeColor(core.RGBA(0x38BDF8, 0.65)).SetLineWidth(1).StrokeRect(rx, ry, rw, rh) + d.SetStrokeColor(specAlpha(spec.Accent.Edge, 0.65)).SetLineWidth(1).StrokeRect(rx, ry, rw, rh) } sr := rects[sel] - d.SetStrokeColor(core.RGBA(0x38BDF8, 1)).SetLineWidth(1.5).StrokeRect( + d.SetStrokeColor(spec.Accent.Edge).SetLineWidth(1.5).StrokeRect( ox+float32(sr.Min.X)*scale, oy+float32(sr.Min.Y)*scale, float32(sr.Dx())*scale, @@ -606,7 +607,7 @@ func (e *Editor) DrawImageImportPreview(d *core.Drawing, size core.Size, relPath pt = drag.livePivot } mx, my := previewPivotCanvasPos(ox, oy, scale, r, pt) - drawPivotMarker(d, mx, my, overridden, i == sel, draggingCell) + drawPivotMarker(d, spec, mx, my, overridden, i == sel, draggingCell) } return } @@ -618,16 +619,16 @@ func (e *Editor) DrawImageImportPreview(d *core.Drawing, size core.Size, relPath pt = drag.livePivot } mx, my := previewPivotCanvasPos(ox, oy, scale, bounds, pt) - drawPivotMarker(d, mx, my, explicit, true, draggingDefault) + drawPivotMarker(d, spec, mx, my, explicit, true, draggingDefault) } -func drawPivotMarker(d *core.Drawing, x, y float32, overridden, selected, dragging bool) { - fill := core.RGB(0xF59E0B) // amber for inherited/default pivot +func drawPivotMarker(d *core.Drawing, spec SpecPalette, x, y float32, overridden, selected, dragging bool) { + fill := spec.Warning.Fg // amber for inherited/default pivot if overridden { - fill = core.RGB(0x22D3EE) // cyan for per-cell override or explicit default + fill = spec.Accent.Fg // accent for per-cell override or explicit default } if dragging { - fill = core.RGB(0xF43F5E) // rose while dragging + fill = spec.Removed.Fg // red while dragging } r := importPivotMarkRadius cross := importPivotCrossRadius @@ -637,16 +638,16 @@ func drawPivotMarker(d *core.Drawing, x, y float32, overridden, selected, draggi } // Contrast dark crosshair halo then colored crosshair lines. - d.SetStrokeColor(core.RGBA(0x0F172A, 0.9)).SetLineWidth(2.5) + d.SetStrokeColor(specAlpha(spec.Bg, 0.9)).SetLineWidth(2.5) d.BeginPath().MoveTo(x-cross, y).LineTo(x+cross, y).MoveTo(x, y-cross).LineTo(x, y+cross).Stroke() d.SetStrokeColor(fill).SetLineWidth(1.25) d.BeginPath().MoveTo(x-cross, y).LineTo(x+cross, y).MoveTo(x, y-cross).LineTo(x, y+cross).Stroke() // Circle marker with dark outline and colored center. d.SetFillColor(fill).BeginPath().Arc(x, y, r, 0, float32(2*math.Pi), false).Fill() - stroke := core.RGB(0x0F172A) + stroke := spec.Bg if selected || dragging { - stroke = core.RGB(0xFFFFFF) + stroke = spec.TextPrimary } d.SetStrokeColor(stroke).SetLineWidth(1.25).BeginPath().Arc(x, y, r, 0, float32(2*math.Pi), false).Stroke() } diff --git a/packages/game/editor/browser.go b/packages/game/editor/browser.go index 75edfa1cc..e2eda4432 100644 --- a/packages/game/editor/browser.go +++ b/packages/game/editor/browser.go @@ -263,7 +263,7 @@ func AssetBrowserView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core TestID: "asset-browser", Style: dockedStyle(cx, core.Style{ Width: core.Pt(224), - Background: colors.Inset(), + Background: colors.Surface(), Borders: core.Edges{Right: 1}, BorderColor: colors.Line(), Padding: core.All(10), diff --git a/packages/game/editor/build_release_ui.go b/packages/game/editor/build_release_ui.go index e2cf6a5f4..9582a2e8e 100644 --- a/packages/game/editor/build_release_ui.go +++ b/packages/game/editor/build_release_ui.go @@ -2124,7 +2124,7 @@ func buildWebQRCardView(ed *Editor, spec SpecPalette, ws WebBuildServerSnapshot, Width: core.Pt(160), Height: core.Pt(160), CornerRadius: 8, - Background: core.RGB(0xFFFFFF), + Background: lightSpecPalette.Raised, BorderWidth: qrBorderW, BorderColor: qrBorderCol, Overflow: core.Hidden, @@ -2256,7 +2256,7 @@ func drawQRCode(d *core.Drawing, sz core.Size, code *qrcode.Code) { if d == nil || code == nil || code.Size <= 0 || math.IsNaN(w) || math.IsInf(w, 0) || math.IsNaN(h) || math.IsInf(h, 0) || w <= 0 || h <= 0 { return } - d.SetFillColor(core.RGB(0xFFFFFF)).FillRect(0, 0, float32(w), float32(h)) + d.SetFillColor(lightSpecPalette.Raised).FillRect(0, 0, float32(w), float32(h)) qz := code.QuietZone() totalModules := code.Size + 2*qz @@ -2269,7 +2269,7 @@ func drawQRCode(d *core.Drawing, sz core.Size, code *qrcode.Code) { ox := math.Floor((w - gridSide) / 2) oy := math.Floor((h - gridSide) / 2) - d.SetFillColor(core.RGB(0x101216)) + d.SetFillColor(darkSpecPalette.Bg) cellF := float32(cell) for y := range code.Size { py := float32(oy + float64(qz+y)*cell) diff --git a/packages/game/editor/changes_ui.go b/packages/game/editor/changes_ui.go index 43a996a1c..2d8f85f13 100644 --- a/packages/game/editor/changes_ui.go +++ b/packages/game/editor/changes_ui.go @@ -10,13 +10,13 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Spec-derived alpha tints for diff lines and status badges (base colors are Spec.dc.html `added` #4FD38A, `changed` #E9A84A, `problem` #FF6B6B). +// Spec-derived alpha tints for diff lines and status badges from spec_theme.yaml. var ( - specDiffAddBg = core.RGBA(0x4FD38A, 0.08) - specDiffDelBg = core.RGBA(0xFF6B6B, 0.08) - specBadgeAddBg = core.RGBA(0x4FD38A, 0.14) - specBadgeModBg = core.RGBA(0xE9A84A, 0.16) - specBadgeDelBg = core.RGBA(0xFF6B6B, 0.14) + specDiffAddBg = specAlpha(darkSpecPalette.Added.Fg, 0.08) + specDiffDelBg = specAlpha(darkSpecPalette.Removed.Fg, 0.08) + specBadgeAddBg = specAlpha(darkSpecPalette.Added.Fg, 0.14) + specBadgeModBg = specAlpha(darkSpecPalette.Changed.Fg, 0.16) + specBadgeDelBg = specAlpha(darkSpecPalette.Removed.Fg, 0.14) ) // ChangesPanelView renders the full-window Changes & Commit screen matching diff --git a/packages/game/editor/collider3d_gizmo.go b/packages/game/editor/collider3d_gizmo.go index c70d23f92..cf0c8c483 100644 --- a/packages/game/editor/collider3d_gizmo.go +++ b/packages/game/editor/collider3d_gizmo.go @@ -480,16 +480,17 @@ func (e *Editor) drawColliderGizmo3D(d *core.Drawing, obj *sceneformat.ObjectDoc activeSign = e.drag3D.colliderSign } + spec := e.activeSpecPalette() axisColor := func(ax GizmoAxis3D) core.Color { switch ax { case Axis3DX: - return core.RGBA(0xEF4444, 1) + return spec.AxisX case Axis3DY: - return core.RGBA(0x22C55E, 1) + return spec.AxisY case Axis3DZ: - return core.RGBA(0x3B82F6, 1) + return spec.AxisZ default: - return core.RGBA(0xFACC15, 1) + return spec.Warning.Fg } } @@ -498,14 +499,14 @@ func (e *Editor) drawColliderGizmo3D(d *core.Drawing, obj *sceneformat.ObjectDoc half := colliderHandleHalfSize active := hh.Axis == activeAxis && (activeSign == 0 || hh.Sign == activeSign) if active { - col = core.RGBA(0xFACC15, 1) + col = spec.Warning.Fg half += 1.5 } if x0, y0, x1, y1, vis := e.Camera3D.projectSegment(center, hh.Pos, w, h); vis { d.Save().SetStrokeColor(col.Faded(0.55)).SetLineWidth(1.25).BeginPath().MoveTo(x0, y0).LineTo(x1, y1).Stroke().Restore() } if px, py, _, vis := e.Camera3D.Project(hh.Pos, w, h); vis { - d.Save().SetFillColor(col).SetStrokeColor(core.RGBA(0x0F172A, 0.95)).SetLineWidth(1.25). + d.Save().SetFillColor(col).SetStrokeColor(specAlpha(spec.Bg, 0.95)).SetLineWidth(1.25). BeginPath(). MoveTo(px, py-half). LineTo(px+half, py). diff --git a/packages/game/editor/cutscene_ui.go b/packages/game/editor/cutscene_ui.go index 56628f3c4..aed0d3e80 100644 --- a/packages/game/editor/cutscene_ui.go +++ b/packages/game/editor/cutscene_ui.go @@ -21,14 +21,14 @@ const ( cutscenePreviewH float32 = 324 ) -// Spec-derived translucent fills using exclusively Spec.dc.html token hues. +// Spec-derived translucent fills from spec_theme.yaml. var ( - specChangedFill = core.RGBA(0xE9A84A, 0.14) - specRemovedFill = core.RGBA(0xFF6B6B, 0.14) - specAccentFill = core.RGBA(0x3B7BFF, 0.16) - specDialogueFill = core.RGBA(0x3B7BFF, 0.10) - specAudioFill = core.RGBA(0x4FD38A, 0.10) - specSubtitleBg = core.RGBA(0x101216, 0.88) + specChangedFill = specAlpha(darkSpecPalette.Changed.Fg, 0.14) + specRemovedFill = specAlpha(darkSpecPalette.Removed.Fg, 0.14) + specAccentFill = specAlpha(darkSpecPalette.Accent.Fg, 0.16) + specDialogueFill = specAlpha(darkSpecPalette.Accent.Fg, 0.10) + specAudioFill = specAlpha(darkSpecPalette.Added.Fg, 0.10) + specSubtitleBg = specAlpha(darkSpecPalette.Bg, 0.88) ) // CutscenePanelView renders the full-workspace cutscene timeline and agent review screen (matching docs/design/editor/Animation.dc.html Screen 2 and Spec.dc.html tokens) whenever a cutscene is open and Play mode is not active. diff --git a/packages/game/editor/editormcp/viewport_text.go b/packages/game/editor/editormcp/viewport_text.go index ab3b2e6f4..c6a24005b 100644 --- a/packages/game/editor/editormcp/viewport_text.go +++ b/packages/game/editor/editormcp/viewport_text.go @@ -7,6 +7,7 @@ import ( "image/png" "math" + "github.com/nsgo-dev/game/packages/game/editor" "github.com/nsgo-dev/nsgo/core" ) @@ -149,7 +150,7 @@ func renderOverlayTextPNG(pngBytes []byte, ops []core.DrawOp) ([]byte, bool) { } cur := state{ m: textAffine{a: 1, d: 1}, - color: core.RGB(0xFFFFFF), + color: editor.DarkSpecPalette().TextPrimary, alpha: 1, } var stack []state diff --git a/packages/game/editor/files.go b/packages/game/editor/files.go index 15bb4d9bd..bb1e8d8e8 100644 --- a/packages/game/editor/files.go +++ b/packages/game/editor/files.go @@ -211,7 +211,7 @@ func FilesView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.Node { Style: dockedStyle(cx, core.Style{ FlexGrow: 1, FlexBasis: core.Pt(0), - Background: colors.Inset(), + Background: colors.Surface(), Borders: core.Edges{Top: 1}, BorderColor: colors.Line(), Padding: core.All(6), diff --git a/packages/game/editor/focus_regions.go b/packages/game/editor/focus_regions.go index d8d6727cc..8817d73bf 100644 --- a/packages/game/editor/focus_regions.go +++ b/packages/game/editor/focus_regions.go @@ -982,7 +982,7 @@ func (s SpecSwitch) Render(cx *core.Scope) core.Node { } knob := colors.Knob() if knob == 0 { - knob = core.RGB(0xFFFFFF) + knob = lightSpecPalette.Raised } return core.Style{ Width: core.Pt(14), diff --git a/packages/game/editor/gizmo2d.go b/packages/game/editor/gizmo2d.go index 37fc5ad3b..e90b02916 100644 --- a/packages/game/editor/gizmo2d.go +++ b/packages/game/editor/gizmo2d.go @@ -1337,13 +1337,13 @@ func (c *transform2DCmd) Undo() { } } -// Gizmo colors derived from Spec palette tokens. +// Spec token gizmo colors shared with 2D lighting and nav-region handle overlays. var ( - gizmoColorX = specRemoved - gizmoColorY = specAdded - gizmoColorRing = ui.Alpha(specAccent, 0.8) - gizmoColorCenter = specTextStrong - gizmoColorActive = specWarning + gizmoColorX = darkSpecPalette.AxisX + gizmoColorY = darkSpecPalette.AxisY + gizmoColorRing = specAlpha(darkSpecPalette.Accent.Edge, 0.8) + gizmoColorCenter = darkSpecPalette.TextPrimary + gizmoColorActive = darkSpecPalette.Warning.Fg ) // drawGizmo2D draws the selected object's transform gizmo: the rotation ring, the X and Y arrows, the move square and, on an outline large enough, the scale handles. The handle a drag holds is drawn highlighted. @@ -1353,8 +1353,8 @@ func (e *Editor) drawGizmo2D(d *core.Drawing) { } g, _ := e.gizmo2D() spec := e.SpecPalette(nil) - colX := spec.Problem().Fg - colY := spec.Added.Fg + colX := spec.AxisX + colY := spec.AxisY colRing := ui.Alpha(spec.Accent.Edge, 0.8) colCenter := specHandleFill(spec) colActive := spec.Warning.Fg diff --git a/packages/game/editor/gizmo3d.go b/packages/game/editor/gizmo3d.go index 745b806ec..b5ebb3352 100644 --- a/packages/game/editor/gizmo3d.go +++ b/packages/game/editor/gizmo3d.go @@ -264,13 +264,13 @@ func (h GizmoHandle3D) referencePoint() math3d.Vec3 { func (h GizmoHandle3D) effectiveColor(active bool) core.Color { if active { - return core.RGBA(0xFACC15, 1) + return darkSpecPalette.Warning.Fg } var zero core.Color if h.Color != zero { return h.Color } - return core.RGBA(0x38BDF8, 1) + return darkSpecPalette.Accent.Fg } // ComponentGizmo3D registers 3D viewport handles and drag editing for one component type. @@ -578,7 +578,7 @@ func drawGizmoHandle3D(d *core.Drawing, proj Projection3D, mat math3d.Mat4, h Gi } d.Save() d.SetFillColor(col).BeginPath().Arc(sx, sy, r, 0, float32(2*math.Pi), false).Fill() - d.SetStrokeColor(core.RGBA(0x0F172A, 0.9)).SetLineWidth(1.25).BeginPath().Arc(sx, sy, r, 0, float32(2*math.Pi), false).Stroke() + d.SetStrokeColor(specAlpha(darkSpecPalette.Bg, 0.9)).SetLineWidth(1.25).BeginPath().Arc(sx, sy, r, 0, float32(2*math.Pi), false).Stroke() if active && h.Label != "" { d.SetFillColor(col).FillText(h.Label, sx+r+4, sy+3, core.Font{Size: 10}) } @@ -682,9 +682,10 @@ func newPhysicsCollider3DGizmo(component string, alwaysTrigger bool) *ComponentG cy := float32(readFloat(ed, objectID, "offsetY", 0)) cz := float32(readFloat(ed, objectID, "offsetZ", 0)) center := math3d.Vec3{X: cx, Y: cy, Z: cz} - col := core.RGBA(0x38BDF8, 1) + spec := ed.activeSpecPalette() + col := spec.Accent.Fg if isTrigger(ed, objectID) { - col = core.RGBA(0xF59E0B, 1) + col = spec.Warning.Fg } switch shape { diff --git a/packages/game/editor/gridmap.go b/packages/game/editor/gridmap.go index 47f58654b..c1b66926e 100644 --- a/packages/game/editor/gridmap.go +++ b/packages/game/editor/gridmap.go @@ -1427,28 +1427,29 @@ func (e *Editor) drawGridMap3D(d *core.Drawing, w, h float32) { return } + spec := e.activeSpecPalette() // 3. Box Fill drag preview, or hovered cell preview under the pointer. if minC, maxC, ok := e.GridMapBoxPreview(); ok { bmin := gm.CellBounds(minC).Min bmax := gm.CellBounds(maxC).Max - e.drawAABBWireframe3D(d, bmin, bmax, toWorld, hoverPaintColor, 2.2, w, h) - e.fillCellFloorQuad3D(d, bmin, bmax, toWorld, core.RGBA(0x38BDF8, 0.22), w, h) + e.drawAABBWireframe3D(d, bmin, bmax, toWorld, spec.Accent.Fg, 2.2, w, h) + e.fillCellFloorQuad3D(d, bmin, bmax, toWorld, specAlpha(spec.Accent.Fg, 0.22), w, h) return } if hc, ok := e.HoveredGridMapCell(); ok { - col := hoverPaintColor - fill := core.RGBA(0x38BDF8, 0.22) + col := spec.Accent.Fg + fill := specAlpha(spec.Accent.Fg, 0.22) mode := e.gridMap.tool if e.gridMap.hover.picking { mode = GridMapToolPick } switch mode { case GridMapToolErase: - col = hoverEraseColor - fill = core.RGBA(0xF87171, 0.25) + col = spec.Removed.Fg + fill = specAlpha(spec.Removed.Fg, 0.25) case GridMapToolPick: - col = hoverPickColor - fill = core.RGBA(0xFBBF24, 0.22) + col = spec.Warning.Fg + fill = specAlpha(spec.Warning.Fg, 0.22) } cb := gm.CellBounds(hc) e.fillCellFloorQuad3D(d, cb.Min, cb.Max, toWorld, fill, w, h) @@ -1472,7 +1473,7 @@ func (e *Editor) drawGridMapFloor3D(d *core.Drawing, gm *world3d.GridMap, toWorl zMin := gm.Origin.Z + float32(centerZ-half)*gm.CellSize.Z zMax := gm.Origin.Z + float32(centerZ+half)*gm.CellSize.Z - d.Save().SetStrokeColor(core.RGBA(0x38BDF8, 0.32)).SetLineWidth(1).BeginPath() + d.Save().SetStrokeColor(specAlpha(e.activeSpecPalette().Accent.Fg, 0.32)).SetLineWidth(1).BeginPath() hasSeg := false for i := centerX - half; i <= centerX+half; i++ { x := gm.Origin.X + float32(i)*gm.CellSize.X @@ -1596,23 +1597,23 @@ func (e *Editor) fillCellFloorQuad3D(d *core.Drawing, bmin, bmax math3d.Vec3, to ClosePath().Fill().Restore() } -var gridMapPaletteSwatches = []uint32{ - 0x60A5FA, // blue - 0x34D399, // emerald - 0xFBBF24, // amber - 0xF472B6, // pink - 0xA78BFA, // violet - 0xFB923C, // orange - 0x2DD4BF, // teal - 0xE879F9, // fuchsia +var gridMapPaletteSwatches = []core.Color{ + darkSpecPalette.Accent.Fg, + darkSpecPalette.Added.Fg, + darkSpecPalette.Warning.Fg, + darkSpecPalette.Removed.Fg, + darkSpecPalette.Agent.Fg, + darkSpecPalette.Changed.Fg, + darkSpecPalette.TextMuted, + darkSpecPalette.TextSecondary, } func gridMapTileColor(tileID uint16, alpha float32) core.Color { if tileID == 0 { - return core.RGBA(0x94A3B8, alpha) + return specAlpha(darkSpecPalette.TextFaint, alpha) } - rgb := gridMapPaletteSwatches[int(tileID-1)%len(gridMapPaletteSwatches)] - return core.RGBA(rgb, alpha) + base := gridMapPaletteSwatches[int(tileID-1)%len(gridMapPaletteSwatches)] + return specAlpha(base, alpha) } // --- Scene Object GridMap setter --- diff --git a/packages/game/editor/gridmap_palette.go b/packages/game/editor/gridmap_palette.go index d273f720a..b7232358c 100644 --- a/packages/game/editor/gridmap_palette.go +++ b/packages/game/editor/gridmap_palette.go @@ -110,17 +110,16 @@ func buildGridMapThumbnail(doc *gltf.Document, def world3d.MeshTileDef) []gridMa } func rgbColor(r, g, b float64) core.Color { - clamp := func(v float64) uint32 { + clamp := func(v float64) uint8 { if v <= 0 { return 0 } if v >= 1 { return 255 } - return uint32(math.Round(v * 255)) + return uint8(math.Round(v * 255)) } - hex := (clamp(r) << 16) | (clamp(g) << 8) | clamp(b) - return core.RGBA(hex, 1) + return colorFromRGBA8(clamp(r), clamp(g), clamp(b), 255) } func extractGLTFThumbTris(doc *gltf.Document, meshIdx int, tileID uint16) []gridMapThumbTri { @@ -302,7 +301,7 @@ func drawGridMapThumbnail(d *core.Drawing, item GridMapPaletteItem, orient uint8 ClosePath().Fill() } // Subtle wireframe accent on top of shaded thumbnail for crisp legibility at small sizes. - d.SetStrokeColor(core.RGBA(0x0F172A, 0.35)).SetLineWidth(0.75) + d.SetStrokeColor(specAlpha(darkSpecPalette.Bg, 0.35)).SetLineWidth(0.75) for _, pt := range projected { d.BeginPath().MoveTo(pt.x0, pt.y0).LineTo(pt.x1, pt.y1).LineTo(pt.x2, pt.y2).ClosePath().Stroke() } diff --git a/packages/game/editor/handles3d.go b/packages/game/editor/handles3d.go index 146fe2dce..2bdebe883 100644 --- a/packages/game/editor/handles3d.go +++ b/packages/game/editor/handles3d.go @@ -1037,17 +1037,18 @@ func lightIconColor(l *sceneformat.LightDoc) core.Color { return c } } - return core.RGBA(0xFDE047, 1) + return darkSpecPalette.Warning.Fg } func drawLightIcon2D(d *core.Drawing, x, y float32, l *sceneformat.LightDoc, selected bool) { + pal := darkSpecPalette col := lightIconColor(l) - ring := core.RGBA(0x0F172A, 0.85) + ring := specAlpha(pal.Bg, 0.85) if selected { - ring = core.RGBA(0x38BDF8, 1) + ring = pal.Accent.Edge } // Backing disc for contrast over any sky or geometry. - d.Save().SetFillColor(core.RGBA(0x0F172A, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() + d.Save().SetFillColor(specAlpha(pal.Bg, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() d.Save().SetStrokeColor(ring).SetLineWidth(1.75).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Stroke().Restore() switch l.Kind { @@ -1080,15 +1081,16 @@ func drawLightIcon2D(d *core.Drawing, x, y float32, l *sceneformat.LightDoc, sel } func drawCameraIcon2D(d *core.Drawing, x, y float32, c *sceneformat.Camera3DDoc, selected bool) { - col := core.RGBA(0xE2E8F0, 1) + pal := darkSpecPalette + col := pal.TextSecondary if c != nil && c.Current { - col = core.RGBA(0x38BDF8, 1) + col = pal.Accent.Fg } - ring := core.RGBA(0x0F172A, 0.85) + ring := specAlpha(pal.Bg, 0.85) if selected { - ring = core.RGBA(0x38BDF8, 1) + ring = pal.Accent.Edge } - d.Save().SetFillColor(core.RGBA(0x0F172A, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() + d.Save().SetFillColor(specAlpha(pal.Bg, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() d.Save().SetStrokeColor(ring).SetLineWidth(1.75).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Stroke().Restore() // Camera body + lens trapezoid. @@ -1103,31 +1105,33 @@ func drawCameraIcon2D(d *core.Drawing, x, y float32, c *sceneformat.Camera3DDoc, } func drawReflectionProbeIcon2D(d *core.Drawing, x, y float32, p *sceneformat.ReflectionProbeDoc, selected bool) { - col := core.RGBA(0x22D3EE, 1) + pal := darkSpecPalette + col := pal.Accent.Fg if p != nil && p.Cubemap == "" { - col = core.RGBA(0x94A3B8, 1) + col = pal.TextFaint } - ring := core.RGBA(0x0F172A, 0.85) + ring := specAlpha(pal.Bg, 0.85) if selected { - ring = core.RGBA(0x38BDF8, 1) + ring = pal.Accent.Edge } - d.Save().SetFillColor(core.RGBA(0x0F172A, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() + d.Save().SetFillColor(specAlpha(pal.Bg, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() d.Save().SetStrokeColor(ring).SetLineWidth(1.75).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Stroke().Restore() // Chrome sphere badge with specular highlight dot. d.Save().SetFillColor(col).BeginPath().Arc(x, y, 5.5, 0, float32(2*math.Pi), false).Fill().Restore() - d.Save().SetFillColor(core.RGBA(0xFFFFFF, 0.9)).BeginPath().Arc(x-1.8, y-1.8, 1.8, 0, float32(2*math.Pi), false).Fill().Restore() + d.Save().SetFillColor(specAlpha(pal.TextPrimary, 0.9)).BeginPath().Arc(x-1.8, y-1.8, 1.8, 0, float32(2*math.Pi), false).Fill().Restore() } func drawLightProbeGridIcon2D(d *core.Drawing, x, y float32, g *sceneformat.LightProbeGridDoc, selected bool) { - col := core.RGBA(0xF59E0B, 1) + pal := darkSpecPalette + col := pal.Warning.Fg if g != nil && g.Data == "" { - col = core.RGBA(0xCBD5E1, 1) + col = pal.TextMuted } - ring := core.RGBA(0x0F172A, 0.85) + ring := specAlpha(pal.Bg, 0.85) if selected { - ring = core.RGBA(0x38BDF8, 1) + ring = pal.Accent.Edge } - d.Save().SetFillColor(core.RGBA(0x0F172A, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() + d.Save().SetFillColor(specAlpha(pal.Bg, 0.72)).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Fill().Restore() d.Save().SetStrokeColor(ring).SetLineWidth(1.75).BeginPath().Arc(x, y, 10, 0, float32(2*math.Pi), false).Stroke().Restore() // 2x2 warm probe dot grid. for _, ox := range [2]float32{-3.2, 3.2} { @@ -1151,6 +1155,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { if obj.Light == nil && obj.Camera == nil && obj.ReflectionProbe == nil && obj.LightProbeGrid == nil { return } + spec := e.activeSpecPalette() vc := e.activeView3DCam(w, h) activeHandle := e.ActiveHandle3D() pos64, right, up, fwd := e.objectWorldFrame3D(obj) @@ -1165,10 +1170,10 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { fill := col if activeHandle == kind { radius = 7 - fill = core.RGBA(0xFACC15, 1) + fill = spec.Warning.Fg } d.Save().SetFillColor(fill).BeginPath().Arc(px, py, radius, 0, float32(2*math.Pi), false).Fill().Restore() - d.Save().SetStrokeColor(core.RGBA(0x0F172A, 0.9)).SetLineWidth(1.5).BeginPath().Arc(px, py, radius, 0, float32(2*math.Pi), false).Stroke().Restore() + d.Save().SetStrokeColor(specAlpha(spec.Bg, 0.9)).SetLineWidth(1.5).BeginPath().Arc(px, py, radius, 0, float32(2*math.Pi), false).Stroke().Restore() } drawCircle3D := func(center, uAxis, vAxis [3]float64, radius float64, col core.Color, lw float32) { @@ -1248,7 +1253,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { // Inner cone ring. if innerRad > 1e-3 { - drawCircle3D(center, right, up, innerRad, core.RGBA(0xFDE68A, 0.75), 1.25) + drawCircle3D(center, right, up, innerRad, specAlpha(spec.Warning.Fg, 0.75), 1.25) } // Direction axis shaft. if dirTip, ok := e.HandlePosition3D(Handle3DLightDirection); ok { @@ -1261,10 +1266,10 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { drawHandleKnob(Handle3DLightRange, rangeTip, col) } if outerTip, ok := e.HandlePosition3D(Handle3DLightOuterCone); ok { - drawHandleKnob(Handle3DLightOuterCone, outerTip, core.RGBA(0x38BDF8, 1)) + drawHandleKnob(Handle3DLightOuterCone, outerTip, spec.Accent.Fg) } if innerTip, ok := e.HandlePosition3D(Handle3DLightInnerCone); ok { - drawHandleKnob(Handle3DLightInnerCone, innerTip, core.RGBA(0xFDE68A, 1)) + drawHandleKnob(Handle3DLightInnerCone, innerTip, spec.Warning.Fg) } } } @@ -1302,7 +1307,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { nearR := planeRect(near) prevR := planeRect(previewDist) - col := core.RGBA(0x38BDF8, 0.95) + col := specAlpha(spec.Accent.Fg, 0.95) d.Save().SetStrokeColor(col).SetLineWidth(1.5).BeginPath() hasSeg := false seg := func(a, b [3]float32) { @@ -1355,7 +1360,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { drawHandleKnob(Handle3DCameraFOV, fovTip, col) } if farTip, ok := e.HandlePosition3D(Handle3DCameraFar); ok { - drawHandleKnob(Handle3DCameraFar, farTip, core.RGBA(0xA855F7, 1)) + drawHandleKnob(Handle3DCameraFar, farTip, spec.Agent.Fg) } } @@ -1396,7 +1401,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { sz := obj.ReflectionProbe.EffectiveSize() c64 := [3]float64{float64(c[0]), float64(c[1]), float64(c[2])} s64 := [3]float64{float64(sz[0]), float64(sz[1]), float64(sz[2])} - drawWireBox(c64, s64, core.RGBA(0x22D3EE, 0.95), 1.6) + drawWireBox(c64, s64, specAlpha(spec.Accent.Fg, 0.95), 1.6) if b := float64(obj.ReflectionProbe.BlendDistance); b > 0 { inner := [3]float64{ math.Max(0, s64[0]-2*b), @@ -1404,7 +1409,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { math.Max(0, s64[2]-2*b), } if inner[0] > 0 && inner[1] > 0 && inner[2] > 0 { - drawWireBox(c64, inner, core.RGBA(0x22D3EE, 0.4), 1) + drawWireBox(c64, inner, specAlpha(spec.Accent.Fg, 0.4), 1) } } } @@ -1415,7 +1420,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { cnt := obj.LightProbeGrid.EffectiveCounts() c64 := [3]float64{float64(c[0]), float64(c[1]), float64(c[2])} s64 := [3]float64{float64(sz[0]), float64(sz[1]), float64(sz[2])} - drawWireBox(c64, s64, core.RGBA(0xF59E0B, 0.95), 1.6) + drawWireBox(c64, s64, specAlpha(spec.Warning.Fg, 0.95), 1.6) if cnt[0]*cnt[1]*cnt[2] <= 512 { sampleCoord := func(i, n int, mid, span float64) float64 { if n <= 1 { @@ -1423,7 +1428,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { } return (mid - span*0.5) + span*(float64(i)/float64(n-1)) } - dotCol := core.RGBA(0xFBBF24, 0.85) + dotCol := specAlpha(spec.Changed.Fg, 0.85) for iz := range cnt[2] { pz := sampleCoord(iz, cnt[2], c64[2], s64[2]) for iy := range cnt[1] { @@ -1444,12 +1449,12 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { kind Handle3DKind col core.Color }{ - {Handle3DProbeBoundsPosX, core.RGBA(0xEF4444, 1)}, - {Handle3DProbeBoundsNegX, core.RGBA(0xEF4444, 1)}, - {Handle3DProbeBoundsPosY, core.RGBA(0x22C55E, 1)}, - {Handle3DProbeBoundsNegY, core.RGBA(0x22C55E, 1)}, - {Handle3DProbeBoundsPosZ, core.RGBA(0x3B82F6, 1)}, - {Handle3DProbeBoundsNegZ, core.RGBA(0x3B82F6, 1)}, + {Handle3DProbeBoundsPosX, spec.AxisX}, + {Handle3DProbeBoundsNegX, spec.AxisX}, + {Handle3DProbeBoundsPosY, spec.AxisY}, + {Handle3DProbeBoundsNegY, spec.AxisY}, + {Handle3DProbeBoundsPosZ, spec.AxisZ}, + {Handle3DProbeBoundsNegZ, spec.AxisZ}, } { if hp, ok := e.HandlePosition3D(hspec.kind); ok { drawHandleKnob(hspec.kind, hp, hspec.col) diff --git a/packages/game/editor/hud_layout_ui.go b/packages/game/editor/hud_layout_ui.go index 85566f771..aa5821e5e 100644 --- a/packages/game/editor/hud_layout_ui.go +++ b/packages/game/editor/hud_layout_ui.go @@ -11,21 +11,21 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Additional alpha derivatives strictly from Spec color tokens (docs/design/editor/Spec.dc.html). +// Additional alpha derivatives strictly from spec_theme.yaml color tokens. var ( - specSelectedRowFill = core.RGBA(0x3B7BFF, 0.14) - specSafeStripFill = core.RGBA(0xF2C14E, 0.10) - specSafeDashStroke = core.RGBA(0xF2C14E, 0.72) - specTouchDashStroke = core.RGBA(0x3B7BFF, 0.80) - specProblemHatch = core.RGBA(0xFF6B6B, 0.35) - specTouchFill = core.RGBA(0xFFFFFF, 0.14) - specTouchBase = core.RGBA(0xFFFFFF, 0.08) - specTouchKnob = core.RGBA(0xFFFFFF, 0.28) - specTouchBorder = core.RGBA(0xFFFFFF, 0.30) - specHintFill = core.RGBA(0x101216, 0.80) - specMenuBtnFill = core.RGBA(0xFFFFFF, 0.08) - specDimOverlay = core.RGBA(0x101216, 0.62) - specPanelBackdrop = core.RGBA(0x171A21, 0.96) + specSelectedRowFill = specAlpha(darkSpecPalette.Accent.Fg, 0.14) + specSafeStripFill = specAlpha(darkSpecPalette.Warning.Fg, 0.10) + specSafeDashStroke = specAlpha(darkSpecPalette.Warning.Fg, 0.72) + specTouchDashStroke = specAlpha(darkSpecPalette.Accent.Fg, 0.80) + specProblemHatch = specAlpha(darkSpecPalette.Removed.Fg, 0.35) + specTouchFill = specAlpha(darkSpecPalette.TextPrimary, 0.14) + specTouchBase = specAlpha(darkSpecPalette.TextPrimary, 0.08) + specTouchKnob = specAlpha(darkSpecPalette.TextPrimary, 0.28) + specTouchBorder = specAlpha(darkSpecPalette.TextPrimary, 0.30) + specHintFill = specAlpha(darkSpecPalette.Bg, 0.80) + specMenuBtnFill = specAlpha(darkSpecPalette.TextPrimary, 0.08) + specDimOverlay = specAlpha(darkSpecPalette.Bg, 0.62) + specPanelBackdrop = specAlpha(darkSpecPalette.Raised, 0.96) ) // HUDLayoutView renders the full-window HUD and menu layout screen matching docs/design/editor/HUDLayout.dc.html @@ -2609,7 +2609,7 @@ func drawHUDZoomOverflow(d *core.Drawing, size core.Size, n *gameui.ScreenNodeDo if sw > 0 { d.Save() d.BeginPath().Rect(bx+bw, by, sw, boxH).Clip() - d.SetFillColor(core.RGBA(0xFF6B6B, 0.14)).FillRect(bx+bw, by, sw, boxH) + d.SetFillColor(specAlpha(darkSpecPalette.Removed.Fg, 0.14)).FillRect(bx+bw, by, sw, boxH) d.SetStrokeColor(specProblemHatch).SetLineWidth(2) for hx := bx + bw - boxH; hx < bx+bw+sw+boxH; hx += 8 { d.BeginPath().MoveTo(hx, by+boxH).LineTo(hx+boxH, by).Stroke() diff --git a/packages/game/editor/input_map_panel.go b/packages/game/editor/input_map_panel.go index 048193af7..890e550b2 100644 --- a/packages/game/editor/input_map_panel.go +++ b/packages/game/editor/input_map_panel.go @@ -931,9 +931,10 @@ func (e *Editor) DrawInputRegionCanvas(d *core.Drawing, size core.Size) { sx := cw / dw sy := ch / dh + spec := e.activeSpecPalette() // Background and display bounds border. - d.SetFillColor(core.RGB(0x0F172A)).FillRect(0, 0, cw, ch) - d.SetStrokeColor(core.RGBA(0x94A3B8, 0.25)).SetLineWidth(1) + d.SetFillColor(spec.Viewport).FillRect(0, 0, cw, ch) + d.SetStrokeColor(specAlpha(spec.TextFaint, 0.25)).SetLineWidth(1) d.BeginPath() d.MoveTo(cw/2, 0).LineTo(cw/2, ch) d.MoveTo(0, ch/2).LineTo(cw, ch/2) @@ -954,26 +955,26 @@ func (e *Editor) DrawInputRegionCanvas(d *core.Drawing, size core.Size) { r = e.inputMap.dragPreview } selected := act.Name == selAct && bi == selBind - drawInputRegionBox(d, r, sx, sy, b.Kind, selected) + drawInputRegionBox(d, spec, r, sx, sy, b.Kind, selected) } } } if e.inputMap.dragMode == regionDragCreate && e.inputMap.dragChanged { - drawInputRegionBox(d, e.inputMap.dragPreview, sx, sy, e.InputMapRegionDrawKind(), true) + drawInputRegionBox(d, spec, e.inputMap.dragPreview, sx, sy, e.InputMapRegionDrawKind(), true) } - d.SetStrokeColor(core.RGBA(0xCBD5E1, 0.6)).SetLineWidth(1).StrokeRect(0.5, 0.5, cw-1, ch-1) + d.SetStrokeColor(spec.LineRaised).SetLineWidth(1).StrokeRect(0.5, 0.5, cw-1, ch-1) } -func drawInputRegionBox(d *core.Drawing, r project.Rect, sx, sy float32, kind string, selected bool) { +func drawInputRegionBox(d *core.Drawing, spec SpecPalette, r project.Rect, sx, sy float32, kind string, selected bool) { rx := r.X * sx ry := r.Y * sy rw := r.Width * sx rh := r.Height * sy - baseHex := uint32(0x38BDF8) // touchRegion: sky blue + base := spec.Accent.Fg // touchRegion: Spec accent if kind == project.KindMouseRegion { - baseHex = 0xF59E0B // mouseRegion: amber + base = spec.Warning.Fg // mouseRegion: Spec warning } fillAlpha := float32(0.18) strokeWidth := float32(1) @@ -981,11 +982,11 @@ func drawInputRegionBox(d *core.Drawing, r project.Rect, sx, sy float32, kind st fillAlpha = 0.34 strokeWidth = 2 } - d.SetFillColor(core.RGBA(baseHex, fillAlpha)).FillRect(rx, ry, rw, rh) - d.SetStrokeColor(core.RGBA(baseHex, 0.95)).SetLineWidth(strokeWidth).StrokeRect(rx, ry, rw, rh) + d.SetFillColor(specAlpha(base, fillAlpha)).FillRect(rx, ry, rw, rh) + d.SetStrokeColor(specAlpha(base, 0.95)).SetLineWidth(strokeWidth).StrokeRect(rx, ry, rw, rh) if selected { const hs float32 = 6 - d.SetFillColor(core.RGB(baseHex)).FillRect(rx+rw-hs, ry+rh-hs, hs, hs) + d.SetFillColor(base).FillRect(rx+rw-hs, ry+rh-hs, hs, hs) } } diff --git a/packages/game/editor/inspector.go b/packages/game/editor/inspector.go index 958b5d155..cb065df2c 100644 --- a/packages/game/editor/inspector.go +++ b/packages/game/editor/inspector.go @@ -564,14 +564,11 @@ func valueKindTag(v any) string { // nothing else is selected. A component that a plugin which is on has an Inspector for is // drawn by that inspector instead of the generic fields. func InspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.Node { - return inspectorThemeScope{ - build: func(cx *core.Scope) core.Node { - return renderInspectorView(cx, ed, rev) - }, - } + return renderInspectorView(cx, ed, rev) } func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.Node { + spec := ed.SpecPalette(cx) schema := core.NewMemo(cx, func() string { _ = rev.Get() return inspectorSchemaKey(ed) @@ -596,6 +593,7 @@ func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c return !shouldShowRemoteInspector(ed) && ed.Doc != nil }, Then: func(cx *core.Scope) core.Node { + btnSpec := ed.SpecPalette(cx) return core.View{ TestID: "inspector-open-yaml", Role: core.RoleButton, @@ -607,20 +605,20 @@ func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c Padding: core.Symmetric(0, 8), CornerRadius: 6, Gap: 5, - Hover: &core.Style{Background: specRaised}, - FocusVisible: specFocusRingStyle, + Hover: &core.Style{Background: btnSpec.Raised}, + FocusVisible: btnSpec.FocusRing(2), }, OnPress: func(core.PressEvent) { ed.report(ed.OpenSelectedObjectYAML()) }, Children: []core.Node{ - ui.Icon(lucide.FileCode, 13, func() core.Color { return specTextSecondary }), + ui.Icon(lucide.FileCode, 13, func() core.Color { return btnSpec.TextMuted }), core.Text{ Content: ed.T("inspector.openYAML"), MaxLines: 1, Style: core.Style{ FontSize: 11.5, - Color: specTextSecondary, + Color: btnSpec.TextMuted, }, }, }, @@ -634,9 +632,9 @@ func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c Width: core.Pt(272), FlexGrow: 1, FlexBasis: core.Pt(0), - Background: specPanel, + Background: spec.Panel, Borders: core.Edges{Left: 1}, - BorderColor: specLine, + BorderColor: spec.Line, Gap: 0, }), Children: []core.Node{ @@ -650,6 +648,7 @@ func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c return playInspectorTabBarView(cx, ed, rev) }, Else: func(cx *core.Scope) core.Node { + hdrSpec := ed.SpecPalette(cx) return core.View{ Style: core.Style{ Direction: core.Row, @@ -658,7 +657,7 @@ func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c Height: core.Pt(38), Padding: core.Symmetric(0, 12), Borders: core.Edges{Bottom: 1}, - BorderColor: specLine, + BorderColor: hdrSpec.Line, Gap: 8, FlexShrink: 0, }, @@ -675,7 +674,7 @@ func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c Style: core.Style{ FontSize: 13, FontWeight: core.FontWeightSemibold, - Color: specTextStrong, + Color: hdrSpec.TextPrimary, }, }, openYAMLBtn, @@ -714,7 +713,7 @@ func renderInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c Content: ed.T("inspector.empty"), Style: core.Style{ FontSize: 12, - Color: specTextMuted, + Color: ed.SpecPalette(cx).TextFaint, }, } } @@ -1166,6 +1165,7 @@ func layerInspectorView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], la func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], objID, layerName string) core.Node { colors := ui.ColorsOf(cx) + spec := ed.SpecPalette(cx) info := ed.ObjectOverrideInfo(objID) isLocal := info.Origin == ObjectLocal disabled := func() bool { @@ -1180,7 +1180,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o FontSize: 11, FontWeight: core.FontWeightSemibold, LetterSpacing: 0.7, - Color: specTextMuted, + Color: spec.TextFaint, }, } } @@ -1255,7 +1255,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Width: core.Pt(68), FlexShrink: 0, FontSize: 12, - Color: specTextSecondary, + Color: spec.TextMuted, }, }, tip) } @@ -1308,7 +1308,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Style: core.Style{ FlexShrink: 1, FontSize: 12, - Color: specTextSecondary, + Color: spec.TextMuted, }, }, tip) var labelCell core.Node @@ -1350,7 +1350,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Style: core.Style{ FlexShrink: 1, FontSize: 12, - Color: specTextSecondary, + Color: spec.TextMuted, }, }, "")), controlWithRevert(overrideKey, label, control), @@ -1386,7 +1386,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o MaxLines: 1, Style: core.Style{ FontSize: 12, - Color: specTextSecondary, + Color: spec.TextMuted, }, }, ) @@ -1463,7 +1463,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o overrideDot(key), core.Text{ Content: axisName, - Style: core.Style{FontSize: 10.5, Color: specTextMuted}, + Style: core.Style{FontSize: 10.5, Color: spec.TextFaint}, }, overrideRevertBtn(key, axisName), }, @@ -1534,7 +1534,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Height: core.Pt(28), CornerRadius: 7, FlexShrink: 0, - Background: objectSwatchColor(objInit), + Background: objectSwatchColor(spec, objInit), }, }, core.View{ @@ -1552,7 +1552,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Style: core.Style{ FontSize: 13.5, FontWeight: core.FontWeightSemibold, - Color: specTextStrong, + Color: spec.TextPrimary, }, }, core.Text{ @@ -1568,7 +1568,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o MaxLines: 1, Style: core.Style{ FontSize: 11.5, - Color: specTextMuted, + Color: spec.TextFaint, }, }, }, @@ -1598,13 +1598,13 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Height: core.Pt(28), Padding: core.Symmetric(0, 8), CornerRadius: 6, - Background: specRaised, + Background: spec.Raised, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: spec.LineRaised, Gap: 6, }, Children: []core.Node{ - ui.Icon(lucide.Search, 12, func() core.Color { return specTextMuted }), + ui.Icon(lucide.Search, 12, func() core.Color { return spec.TextFaint }), core.Input{ TestID: "inspector-field-filter", Label: ed.T("inspector.filterFields"), @@ -1623,9 +1623,9 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o MinWidth: core.Pt(0), Height: core.Pt(26), FontSize: 12, - Color: specTextStrong, - PlaceholderColor: specTextMuted, - CaretColor: specAccent, + Color: spec.TextPrimary, + PlaceholderColor: spec.TextFaint, + CaretColor: spec.Accent.Fg, }, }, core.Show{ @@ -1673,7 +1673,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Style: core.Style{ FlexShrink: 1, FontSize: 12, - Color: specTextSecondary, + Color: spec.TextMuted, }, }, "")), controlWithRevert("name", ed.T("inspector.name"), specInputField(cx, ed, ui.Input{ @@ -1781,9 +1781,9 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Gap: 6, Padding: core.All(8), CornerRadius: 6, - Background: specRaised, + Background: spec.Raised, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: spec.LineRaised, }, Children: []core.Node{ core.View{ @@ -1794,7 +1794,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-object-scene", Content: info.SourceScene, MaxLines: 1, - Style: core.Style{FontSize: 11, Color: specText, FlexGrow: 1, FlexShrink: 1}, + Style: core.Style{FontSize: 11, Color: spec.TextSecondary, FlexGrow: 1, FlexShrink: 1}, }, }, }, @@ -1809,7 +1809,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o } return ed.T("overrides.overrideCount", l10n.Param("count", ovCount)) }, - Style: core.Style{FontSize: 11, Color: specTextMuted}, + Style: core.Style{FontSize: 11, Color: spec.TextFaint}, }, ui.Wrap{Children: actionBtns}, }, @@ -1834,7 +1834,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-x", Label: "X", AxisLabel: "X", - AxisColor: specProblem, + AxisColor: spec.AxisX, Step: 1, Scrub: InspectorScrubField{ObjectID: objID, Field: "x", Step: 1}, Disabled: disabled, @@ -1855,7 +1855,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-y", Label: "Y", AxisLabel: "Y", - AxisColor: specAdded, + AxisColor: spec.AxisY, Step: 1, Scrub: InspectorScrubField{ObjectID: objID, Field: "y", Step: 1}, Disabled: disabled, @@ -1879,7 +1879,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-pos-z", Label: ed.T("inspector.posZ"), AxisLabel: "Z", - AxisColor: specAccent, + AxisColor: spec.AxisZ, Step: 1, Scrub: InspectorScrubField{ObjectID: objID, Field: "posZ", Step: 1}, Disabled: disabled, @@ -1909,7 +1909,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-rot-x", Label: ed.T("inspector.rotX"), AxisLabel: "X", - AxisColor: specProblem, + AxisColor: spec.AxisX, Step: 0.1, Scrub: InspectorScrubField{ObjectID: objID, Field: "rotX", Step: 0.1}, Disabled: disabled, @@ -1930,7 +1930,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-rot-y", Label: ed.T("inspector.rotY"), AxisLabel: "Y", - AxisColor: specAdded, + AxisColor: spec.AxisY, Step: 0.1, Scrub: InspectorScrubField{ObjectID: objID, Field: "rotY", Step: 0.1}, Disabled: disabled, @@ -1951,7 +1951,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-rot-z", Label: ed.T("inspector.rotZ"), AxisLabel: "Z", - AxisColor: specAccent, + AxisColor: spec.AxisZ, Step: 0.1, Scrub: InspectorScrubField{ObjectID: objID, Field: "rotZ", Step: 0.1}, Disabled: disabled, @@ -2002,7 +2002,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-scale-x", Label: ed.T("inspector.scaleX"), AxisLabel: "X", - AxisColor: specProblem, + AxisColor: spec.AxisX, Step: 0.1, Scrub: InspectorScrubField{ObjectID: objID, Field: "scaleX", Step: 0.1}, Disabled: disabled, @@ -2023,7 +2023,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-scale-y", Label: ed.T("inspector.scaleY"), AxisLabel: "Y", - AxisColor: specAdded, + AxisColor: spec.AxisY, Step: 0.1, Scrub: InspectorScrubField{ObjectID: objID, Field: "scaleY", Step: 0.1}, Disabled: disabled, @@ -2047,7 +2047,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: "inspector-scale-z", Label: ed.T("inspector.scaleZ"), AxisLabel: "Z", - AxisColor: specAccent, + AxisColor: spec.AxisZ, Step: 0.1, Scrub: InspectorScrubField{ObjectID: objID, Field: "scaleZ", Step: 0.1}, Disabled: disabled, @@ -2129,7 +2129,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Content: ed.T("inspector.scrubHint3D"), Style: core.Style{ FontSize: 11, - Color: specTextMuted, + Color: spec.TextFaint, }, }) } @@ -2296,7 +2296,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o } return fmt.Sprintf("Culled (%d levels)", count) }, - Style: core.Style{FontSize: 12, Color: specText}, + Style: core.Style{FontSize: 12, Color: spec.TextSecondary}, }) }, }, @@ -2523,7 +2523,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o lblInner := inspectorScrubHandle( ed, cfg.TestID+"-scrub", "", cfg.Scrub, disabled, core.Style{Height: core.Pt(28), FlexGrow: 1, FlexShrink: 1, MinWidth: core.Pt(0)}, - core.Text{Content: key, MaxLines: 1, Style: core.Style{FontSize: 12, Color: specTextSecondary}}, + core.Text{Content: key, MaxLines: 1, Style: core.Style{FontSize: 12, Color: spec.TextMuted}}, ) lbl := labelWithOverride(ovKey, lblInner) if isLocal { @@ -2561,7 +2561,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o lblInner := inspectorScrubHandle( ed, cfg.TestID+"-scrub", "", cfg.Scrub, disabled, core.Style{Height: core.Pt(28), FlexGrow: 1, FlexShrink: 1, MinWidth: core.Pt(0)}, - core.Text{Content: key, MaxLines: 1, Style: core.Style{FontSize: 12, Color: specTextSecondary}}, + core.Text{Content: key, MaxLines: 1, Style: core.Style{FontSize: 12, Color: spec.TextMuted}}, ) lbl := labelWithOverride(ovKey, lblInner) if isLocal { @@ -2591,7 +2591,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o lbl := labelWithOverride(ovKey, withTooltip(core.Text{ Content: key, MaxLines: 1, - Style: core.Style{FlexShrink: 1, FontSize: 12, Color: specTextSecondary}, + Style: core.Style{FlexShrink: 1, FontSize: 12, Color: spec.TextMuted}, }, "")) if isLocal { lbl = plainLabel(key, "", "") @@ -2740,7 +2740,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: labelID, Content: field.Name, MaxLines: 1, - Style: core.Style{FlexShrink: 1, FontSize: 12, Color: specTextSecondary}, + Style: core.Style{FlexShrink: 1, FontSize: 12, Color: spec.TextMuted}, }, tip)) if isLocal { lbl = plainLabel(field.Name, labelID, tip) @@ -2912,7 +2912,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o TestID: labelID, Content: fk, MaxLines: 1, - Style: core.Style{FlexShrink: 1, FontSize: 12, Color: specTextSecondary}, + Style: core.Style{FlexShrink: 1, FontSize: 12, Color: spec.TextMuted}, }, "")) if isLocal { lbl = plainLabel(fk, labelID, "") @@ -2965,7 +2965,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Style: core.Style{ FontSize: 11.5, LineHeight: 16.5, - Color: specTextMuted, + Color: spec.TextFaint, Padding: core.Edges{Top: 6}, }, } diff --git a/packages/game/editor/inspector_edit.go b/packages/game/editor/inspector_edit.go index 417007884..4322faca0 100644 --- a/packages/game/editor/inspector_edit.go +++ b/packages/game/editor/inspector_edit.go @@ -129,13 +129,14 @@ func spriteFieldsFiltered( }, } } + spec := ed.SpecPalette(cx) rows = append(rows, multiAxisRow( "Origin", []string{"originX", "originY"}, "inspector-origin", []inspectorNumberFieldCfg{ - originCfg("inspector-origin-x", ed.T("inspector.originX"), "X", "originX", specProblem, false), - originCfg("inspector-origin-y", ed.T("inspector.originY"), "Y", "originY", specAdded, true), + originCfg("inspector-origin-x", ed.T("inspector.originX"), "X", "originX", spec.AxisX, false), + originCfg("inspector-origin-y", ed.T("inspector.originY"), "Y", "originY", spec.AxisY, true), }, )) } @@ -481,6 +482,7 @@ func addComponentControl(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o } } + spec := ed.SpecPalette(cx) askBtn := core.View{ TestID: "inspector-ask-to-add", Role: core.RoleButton, @@ -492,13 +494,13 @@ func addComponentControl(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Height: core.Pt(30), Padding: core.Symmetric(0, 10), CornerRadius: 8, - Background: specAgentTint, + Background: spec.Agent.Fill, BorderWidth: 1, - BorderColor: specAgentEdge, + BorderColor: spec.Agent.Edge, Gap: 5, FlexShrink: 0, - Hover: &core.Style{Background: specRaised}, - FocusVisible: specFocusRingStyle, + Hover: &core.Style{Background: spec.Raised}, + FocusVisible: spec.FocusRing(2), }, OnPress: func(core.PressEvent) { if disabled != nil && disabled() { @@ -507,13 +509,13 @@ func addComponentControl(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o ed.AskToAddComponent(objID) }, Children: []core.Node{ - ui.Icon(lucide.Sparkles, 12, func() core.Color { return specAgent }), + ui.Icon(lucide.Sparkles, 12, func() core.Color { return spec.Agent.Fg }), core.Text{ Content: ed.T("inspector.askToAdd"), MaxLines: 1, Style: core.Style{ FontSize: 11.5, - Color: specText, + Color: spec.TextSecondary, }, }, }, @@ -524,7 +526,7 @@ func addComponentControl(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Gap: 8, Padding: core.Edges{Top: 8}, Borders: core.Edges{Top: 1}, - BorderColor: specLine, + BorderColor: spec.Line, }, Children: []core.Node{ core.View{ @@ -553,6 +555,7 @@ func addComponentControl(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o }, core.Dynamic(func(cx *core.Scope) core.Node { _ = rev.Get() + dynSpec := ed.SpecPalette(cx) groups := ed.AddableComponentGroups(objID, query.Get()) if len(groups) == 0 { return nil @@ -586,7 +589,7 @@ func addComponentControl(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o FontSize: 10.5, FontWeight: core.FontWeightSemibold, LetterSpacing: 0.7, - Color: specTextMuted, + Color: dynSpec.TextFaint, }, }, ui.Wrap{Children: buttons}, @@ -598,9 +601,9 @@ func addComponentControl(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Gap: 8, Padding: core.All(8), CornerRadius: 8, - Background: specRaised, + Background: dynSpec.Raised, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: dynSpec.LineRaised, }, Children: children, } diff --git a/packages/game/editor/inspector_scrub.go b/packages/game/editor/inspector_scrub.go index ac1a3ee8c..d4716685c 100644 --- a/packages/game/editor/inspector_scrub.go +++ b/packages/game/editor/inspector_scrub.go @@ -17,62 +17,6 @@ const ( inspectorDragTip3D = "Drag a label to scrub · Shift for 0.01 steps · ↑↓ steps, ⇧ ×10 · ↵ commits, Esc restores" ) -// specInspectorTheme scopes Spec dark-surface tokens to the Inspector subtree so every standard -// ui.Button, ui.Input, ui.Select, ui.Checkbox, and plugin view inherits readable Spec dark colors -// regardless of the host OS's light/dark appearance. -var specInspectorTheme = newSpecInspectorTheme() - -func newSpecInspectorTheme() *core.Theme { - t := core.DefaultTheme().Clone() - p := t.Dark - p.Background = specBg - p.Surface = specPanel - p.SurfaceHover = specRaised - p.SurfacePressed = specLineRaised - p.Border = specLineRaised - p.Text = specText - p.TextMuted = specTextMuted - p.Accent = specAccent - p.AccentHover = specAccent - p.AccentPressed = specAccent - p.AccentText = specBg - p.Danger = specProblem - p.Warning = specChanged - p.Success = specAdded - p.Selection = core.RGBA(0x3B7BFF, 0.24) - p.Focus = core.RGBA(0x3B7BFF, 0.85) - p.Scrollbar = specTextMuted - p.SetColor("inset", specRaised) - p.SetColor("raised", specRaised) - p.SetColor("field", specBg) - p.SetColor("fieldBorder", specLineRaised) - p.SetColor("line", specLine) - p.SetColor("faint", specTextMuted) - p.SetColor("accentFill", specAccent) - p.SetColor("light", specTextStrong) - p.SetColor("onLight", specBg) - p.SetColor("track", specLineRaised) - p.SetColor("knob", specTextStrong) - p.SetColor("code", specText) - p.SetColor("info", specAccent) - p.SetColor("down", specProblem) - t.Dark = p - t.Light = p - return t.Clone() -} - -// inspectorThemeScope establishes a child scope with Spec dark appearance and palette for the -// Inspector subtree without affecting sibling editor panels. -type inspectorThemeScope struct { - build func(*core.Scope) core.Node -} - -func (s inspectorThemeScope) Render(cx *core.Scope) core.Node { - cx.SetSubtreeAppearance(core.AppearanceDark) - cx.SetTheme(specInspectorTheme) - return s.build(cx) -} - // inspectorNumberFieldCfg configures a Spec-styled scrubbable numeric input in the inspector. type inspectorNumberFieldCfg struct { TestID string @@ -234,11 +178,12 @@ func inspectorNumberBox(cx *core.Scope, ed *Editor, cfg inspectorNumberFieldCfg) } } + spec := ed.SpecPalette(cx) var prefix core.Node if cfg.AxisLabel != "" { axisColor := cfg.AxisColor if axisColor == 0 { - axisColor = specTextMuted + axisColor = spec.TextFaint } prefix = inspectorScrubHandle( ed, @@ -279,7 +224,7 @@ func inspectorNumberBox(cx *core.Scope, ed *Editor, cfg inspectorNumberFieldCfg) MaxLines: 1, Style: core.Style{ FontSize: 10.5, - Color: specTextMuted, + Color: spec.TextFaint, }, }, }, @@ -341,15 +286,15 @@ func inspectorNumberBox(cx *core.Scope, ed *Editor, cfg inspectorNumberFieldCfg) Overflow: core.Hidden, }, StyleFunc: func() core.Style { - border := specLineRaised + border := spec.LineRaised width := core.Points(1) if cfg.Invalid != nil && cfg.Invalid() { - border = specProblem + border = spec.Removed.Fg width = 1.5 } else if focused.Get() { - border = specAccent + border = spec.Accent.Fg } - bg := specRaised + bg := spec.Raised op := core.Alpha(1) if cfg.Disabled != nil && cfg.Disabled() { op = core.Alpha(0.55) @@ -368,7 +313,7 @@ func inspectorNumberBox(cx *core.Scope, ed *Editor, cfg inspectorNumberFieldCfg) Height: core.Pt(26), FontFamily: core.FontMonospace, FontSize: 11.5, - Color: specTextStrong, + Color: spec.TextPrimary, Padding: core.Symmetric(0, 6), }, InputStyleFunc: func() core.Style { @@ -377,9 +322,9 @@ func inspectorNumberBox(cx *core.Scope, ed *Editor, cfg inspectorNumberFieldCfg) padLeft = 2 } return core.Style{ - Color: specTextStrong, - PlaceholderColor: specTextMuted, - CaretColor: specAccent, + Color: spec.TextPrimary, + PlaceholderColor: spec.TextFaint, + CaretColor: spec.Accent.Fg, Padding: core.Edges{Left: padLeft, Right: 6}, } }, @@ -488,6 +433,7 @@ func inspectorTitledSection( return ed.T("inspector.fieldCountOther", l10n.Param("count", fieldCount)) } + spec := ed.SpecPalette(cx) var titleNode core.Node = core.Text{ TestID: titleTestID, Content: title, @@ -496,7 +442,7 @@ func inspectorTitledSection( FontSize: 11, FontWeight: core.FontWeightSemibold, LetterSpacing: 0.7, - Color: specTextMuted, + Color: spec.TextFaint, }, } if titleTip != "" { @@ -506,6 +452,7 @@ func inspectorTitledSection( metaBadge := core.Dynamic(func(cx *core.Scope) core.Node { m := metaMemo.Get() probs, reviews := m.probs, m.reviews + dynSpec := ed.SpecPalette(cx) if probs > 0 { label := ed.T("inspector.problemCountOther", l10n.Param("count", probs)) if probs == 1 { @@ -517,9 +464,9 @@ func inspectorTitledSection( Height: core.Pt(18), Padding: core.Symmetric(0, 6), CornerRadius: 9, - Background: specProblemTint, + Background: dynSpec.Removed.Fill, BorderWidth: 1, - BorderColor: specProblemEdge, + BorderColor: dynSpec.Removed.Edge, AlignItems: core.AlignCenter, JustifyContent: core.JustifyCenter, }, @@ -530,7 +477,7 @@ func inspectorTitledSection( Style: core.Style{ FontSize: 10.5, FontWeight: core.FontWeightMedium, - Color: specProblem, + Color: dynSpec.Removed.Fg, }, }, }, @@ -543,7 +490,7 @@ func inspectorTitledSection( MaxLines: 1, Style: core.Style{ FontSize: 11, - Color: specChanged, + Color: dynSpec.Changed.Fg, }, } } @@ -553,7 +500,7 @@ func inspectorTitledSection( MaxLines: 1, Style: core.Style{ FontSize: 11, - Color: specTextMuted, + Color: dynSpec.TextFaint, }, } }) @@ -575,8 +522,8 @@ func inspectorTitledSection( Padding: core.Symmetric(0, 4), CornerRadius: 6, Gap: 5, - Hover: &core.Style{Background: specRaised}, - FocusVisible: specRowFocusRingStyle, + Hover: &core.Style{Background: spec.Raised}, + FocusVisible: spec.FocusRing(-2), }, OnPress: func(core.PressEvent) { if !forceExpanded { @@ -589,7 +536,7 @@ func inspectorTitledSection( if !isOpen() { icon = lucide.ChevronRight } - return ui.Icon(icon, 12, func() core.Color { return specTextMuted }) + return ui.Icon(icon, 12, func() core.Color { return ed.SpecPalette(cx).TextFaint }) }), core.View{ Style: core.Style{FlexGrow: 1, FlexShrink: 1, MinWidth: core.Pt(0)}, @@ -616,7 +563,7 @@ func inspectorTitledSection( Gap: 6, Padding: core.Edges{Top: 6}, Borders: core.Edges{Top: 1}, - BorderColor: specLine, + BorderColor: spec.Line, }, Children: []core.Node{ headerRow, @@ -711,7 +658,7 @@ func inspectorFieldRowKeys( if _, ok := reviewsText(); ok { return core.Style{ Borders: core.Edges{Left: 2}, - BorderColor: specChanged, + BorderColor: ed.activeSpecPalette().Changed.Fg, Padding: core.Edges{Left: 6}, } } @@ -732,6 +679,7 @@ func inspectorFieldRowKeys( return ok }, Then: func(cx *core.Scope) core.Node { + spec := ed.SpecPalette(cx) return core.View{ TestID: fieldTestID + "-review", Style: core.Style{ @@ -746,7 +694,7 @@ func inspectorFieldRowKeys( Width: core.Pt(6), Height: core.Pt(6), CornerRadius: 3, - Background: specChanged, + Background: spec.Changed.Fg, }, }, core.Text{ @@ -756,7 +704,7 @@ func inspectorFieldRowKeys( }, Style: core.Style{ FontSize: 11, - Color: specTextMuted, + Color: spec.TextFaint, }, }, }, @@ -770,6 +718,7 @@ func inspectorFieldRowKeys( return ok }, Then: func(cx *core.Scope) core.Node { + spec := ed.SpecPalette(cx) return core.View{ Style: core.Style{ Direction: core.Row, @@ -785,12 +734,12 @@ func inspectorFieldRowKeys( Gap: 5, Padding: core.Symmetric(2, 8), CornerRadius: 9, - Background: specProblemTint, + Background: spec.Removed.Fill, BorderWidth: 1, - BorderColor: specProblemEdge, + BorderColor: spec.Removed.Edge, }, Children: []core.Node{ - ui.Icon(lucide.CircleAlert, 11, func() core.Color { return specProblem }), + ui.Icon(lucide.CircleAlert, 11, func() core.Color { return spec.Removed.Fg }), core.Text{ ContentFunc: func() string { msg, _ := problemsText() @@ -798,7 +747,7 @@ func inspectorFieldRowKeys( }, Style: core.Style{ FontSize: 11, - Color: specProblem, + Color: spec.Removed.Fg, }, }, }, diff --git a/packages/game/editor/inspector_sections.go b/packages/game/editor/inspector_sections.go index a9cb72291..f500c8902 100644 --- a/packages/game/editor/inspector_sections.go +++ b/packages/game/editor/inspector_sections.go @@ -1165,25 +1165,25 @@ func inspectorObjectKindLabel(obj *sceneformat.ObjectDoc) string { // objectSwatchColor returns a Spec token swatch color identifying the object's kind in the // inspector header. -func objectSwatchColor(obj *sceneformat.ObjectDoc) core.Color { +func objectSwatchColor(spec SpecPalette, obj *sceneformat.ObjectDoc) core.Color { if obj == nil { - return specTextMuted + return spec.TextFaint } switch { case obj.Prefab != "" || obj.Scene != "": - return specAgent + return spec.Agent.Fg case obj.Light != nil: - return specWarning + return spec.Warning.Fg case obj.Camera != nil: - return specAccent + return spec.Accent.Fg case obj.ReflectionProbe != nil || obj.LightProbeGrid != nil: - return specAccent + return spec.Accent.Fg case obj.Model != "" || obj.Mesh != "" || obj.GridMap != "": - return specAdded + return spec.Added.Fg case obj.Sprite != nil: - return specChanged + return spec.Changed.Fg default: - return specTextMuted + return spec.TextFaint } } diff --git a/packages/game/editor/layers_panel.go b/packages/game/editor/layers_panel.go index e3d4ccbd9..24079cff2 100644 --- a/packages/game/editor/layers_panel.go +++ b/packages/game/editor/layers_panel.go @@ -101,7 +101,7 @@ func LayersView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.Node Style: dockedStyle(cx, core.Style{ Height: core.Pt(200), FlexShrink: 0, - Background: colors.Inset(), + Background: colors.Surface(), Borders: core.Edges{Top: 1, Right: 1}, BorderColor: colors.Line(), Padding: core.All(8), @@ -285,7 +285,7 @@ func layerPanelRow(cx *core.Scope, ed *Editor, layers func() []LayerInfo, name s Style: core.Style{Direction: core.Row, AlignItems: core.AlignCenter, FlexGrow: 1, MinWidth: core.Pt(0), Gap: 2}, StyleFunc: func() core.Style { h := hint.Get() - s := core.Style{Borders: core.Edges{Top: 2, Bottom: 2}, BorderColor: colors.Inset()} + s := core.Style{Borders: core.Edges{Top: 2, Bottom: 2}, BorderColor: colors.Surface()} if h.on && h.name == name { if h.before { s.BorderColors = core.EdgeColors{Top: colors.Accent()} diff --git a/packages/game/editor/library.go b/packages/game/editor/library.go index 978982486..8ad46816e 100644 --- a/packages/game/editor/library.go +++ b/packages/game/editor/library.go @@ -282,7 +282,7 @@ func LibraryView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.Node TestID: "library-panel", Style: dockedStyle(cx, core.Style{ Width: core.Pt(224), - Background: colors.Inset(), + Background: colors.Surface(), Borders: core.Edges{Right: 1}, BorderColor: colors.Line(), Padding: core.All(10), diff --git a/packages/game/editor/lights2d_editor.go b/packages/game/editor/lights2d_editor.go index 4a1f99c0e..433b5d48a 100644 --- a/packages/game/editor/lights2d_editor.go +++ b/packages/game/editor/lights2d_editor.go @@ -786,11 +786,11 @@ func (e *Editor) cancelLightingDrag2D() bool { } var ( - lightOverlayColor = core.RGBA(0xFBBF24, 0.85) - lightOverlaySubtleColor = core.RGBA(0xFBBF24, 0.45) - occluderOverlayColor = core.RGBA(0xC084FC, 0.9) - occluderOverlaySubtle = core.RGBA(0xC084FC, 0.45) - occluderEdgeMidFillColor = core.RGBA(0xE9D5FF, 0.95) + lightOverlayColor = specAlpha(darkSpecPalette.Warning.Fg, 0.85) + lightOverlaySubtleColor = specAlpha(darkSpecPalette.Warning.Fg, 0.45) + occluderOverlayColor = specAlpha(darkSpecPalette.Agent.Fg, 0.9) + occluderOverlaySubtle = specAlpha(darkSpecPalette.Agent.Fg, 0.45) + occluderEdgeMidFillColor = CompositeOver(specAlpha(darkSpecPalette.TextPrimary, 0.65), darkSpecPalette.Agent.Fg) ) // drawLightingOverlays2D draws light origin markers and occluder outlines for all visible objects in edit mode so lights and occluders without sprites remain easy to locate and select. diff --git a/packages/game/editor/materials.go b/packages/game/editor/materials.go index a3baea716..e840585dd 100644 --- a/packages/game/editor/materials.go +++ b/packages/game/editor/materials.go @@ -1205,7 +1205,7 @@ func (e *Editor) renderMaterialPreview3D(mat resource.Material, shape MaterialPr enc := dev.BeginEncoder() pass := enc.BeginRenderPass(gpu.RenderPassDesc{ Label: "editor.material.preview", - ColorAttachments: []gpu.ColorAttachment{{LoadOp: gpu.LoadClear, StoreOp: gpu.StoreStore, ClearColor: core.RGBA(0x000000, 0)}}, + ColorAttachments: []gpu.ColorAttachment{{LoadOp: gpu.LoadClear, StoreOp: gpu.StoreStore, ClearColor: core.Color(0)}}, DepthStencil: &gpu.DepthStencilAttachment{DepthLoadOp: gpu.LoadClear, DepthStoreOp: gpu.StoreDiscard, ClearDepth: 1}, }) r.Draw(pass) diff --git a/packages/game/editor/materials_ui.go b/packages/game/editor/materials_ui.go index 2a984ba8d..01d980b83 100644 --- a/packages/game/editor/materials_ui.go +++ b/packages/game/editor/materials_ui.go @@ -137,7 +137,7 @@ func materialEditorPanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c Style: core.Style{ Width: core.Pt(232), Height: core.Pt(156), - Background: core.RGB(0x141824), + Background: ed.SpecPalette(cx).Viewport, CornerRadius: 6, BorderWidth: 1, BorderColor: colors.Line(), @@ -430,7 +430,7 @@ func materialEditorPanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c ed.T("material.field.baseColor"), "#ffffff", false, - core.RGB(0xffffff), + colorFromRGBA8(255, 255, 255, 255), func() string { return currentMat().BaseColor }, ed.SetMaterialBaseColor, )), @@ -439,7 +439,7 @@ func materialEditorPanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c ed.T("material.field.emissiveLabel"), "#000000", true, - core.RGB(0x000000), + colorFromRGBA8(0, 0, 0, 255), func() string { return currentMat().Emissive }, ed.SetMaterialEmissive, )), @@ -536,13 +536,14 @@ func drawMaterialPreviewCanvas(d *core.Drawing, size core.Size, ed *Editor) { if w <= 0 || h <= 0 { return } + spec := ed.activeSpecPalette() // Draw transparency checkerboard so opacity and blend modes are legible. const cell float32 = 12 for y := float32(0); y < h; y += cell { for x := float32(0); x < w; x += cell { - col := core.RGB(0x1e2433) + col := spec.Viewport if (int(x/cell)+int(y/cell))%2 == 1 { - col = core.RGB(0x283044) + col = spec.LineRaised } d.SetFillColor(col).FillRect(x, y, min(cell, w-x), min(cell, h-y)) } @@ -552,7 +553,7 @@ func drawMaterialPreviewCanvas(d *core.Drawing, size core.Size, ed *Editor) { if shape != MaterialPreviewSprite { img, err := ed.MaterialPreviewImage(MaterialPreviewSize) if err != nil { - d.SetFillColor(core.RGB(0xf87171)).FillText("Preview error", 8, 20, core.Font{Size: 11}) + d.SetFillColor(spec.Removed.Fg).FillText("Preview error", 8, 20, core.Font{Size: 11}) return } if img != nil { @@ -609,7 +610,7 @@ func drawMaterialPreviewCanvas(d *core.Drawing, size core.Size, ed *Editor) { label = path.Base(ed.material.relPath) } d.Save() - d.SetFillColor(core.RGBA(0x0f172a, 0.72)).FillRect(4, h-18, w-8, 14) - d.SetFillColor(core.RGB(0xe2e8f0)).FillText(label, 8, h-7, core.Font{Size: 10}) + d.SetFillColor(specAlpha(spec.PillBg, 0.85)).FillRect(4, h-18, w-8, 14) + d.SetFillColor(spec.TextSecondary).FillText(label, 8, h-7, core.Font{Size: 10}) d.Restore() } diff --git a/packages/game/editor/merge_conflict_ui.go b/packages/game/editor/merge_conflict_ui.go index 4fd91a3a5..2e7eedb65 100644 --- a/packages/game/editor/merge_conflict_ui.go +++ b/packages/game/editor/merge_conflict_ui.go @@ -11,14 +11,14 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Spec-derived alpha tints for agent-accented cards and buttons (base color is Spec.dc.html `agent` #9B7BFF). +// Spec-derived alpha tints for agent-accented cards and buttons from spec_theme.yaml. var ( - specAgentTint = core.RGBA(0x9B7BFF, 0.12) - specAgentCardTint = core.RGBA(0x9B7BFF, 0.06) - specAgentEdge = core.RGBA(0x9B7BFF, 0.45) - specAccentEdge = core.RGBA(0x3B7BFF, 0.55) - specChangedTint = core.RGBA(0xE9A84A, 0.18) - specProblemTint = core.RGBA(0xFF6B6B, 0.14) + specAgentTint = specAlpha(darkSpecPalette.Agent.Fg, 0.12) + specAgentCardTint = specAlpha(darkSpecPalette.Agent.Fg, 0.06) + specAgentEdge = specAlpha(darkSpecPalette.Agent.Fg, 0.45) + specAccentEdge = specAlpha(darkSpecPalette.Accent.Fg, 0.55) + specChangedTint = specAlpha(darkSpecPalette.Changed.Fg, 0.18) + specProblemTint = specAlpha(darkSpecPalette.Removed.Fg, 0.14) ) // MergeConflictView renders the full-window Scene Merge Conflict screen matching @@ -1613,10 +1613,10 @@ func drawMergeObjectBlock(d *core.Drawing, o *sceneformat.ObjectDoc, wx, wy floa fill = specChanged radius = 5 case strings.Contains(lower, "slime") || strings.Contains(lower, "enemy"): - fill = core.RGBA(0x4FD38A, 0.55) + fill = specAlpha(darkSpecPalette.Added.Fg, 0.55) radius = 6 case strings.Contains(lower, "coin") || strings.Contains(lower, "pickup"): - fill = core.RGBA(0xF2C14E, 0.80) + fill = specAlpha(darkSpecPalette.Warning.Fg, 0.80) radius = 5 case strings.Contains(lower, "door"): fill = specTextMuted @@ -1626,7 +1626,7 @@ func drawMergeObjectBlock(d *core.Drawing, o *sceneformat.ObjectDoc, wx, wy floa radius = 2 } if ghost { - fill = core.RGBA(0x8B92A0, 0.18) + fill = specAlpha(darkSpecPalette.TextFaint, 0.18) } d.Save() d.SetFillColor(fill) diff --git a/packages/game/editor/model_thumbs.go b/packages/game/editor/model_thumbs.go index ae89432ec..02c2b18e7 100644 --- a/packages/game/editor/model_thumbs.go +++ b/packages/game/editor/model_thumbs.go @@ -220,7 +220,7 @@ func renderModelThumbnail(built *scenemodel.Built, bounds math3d.AABB) (*image.R enc := dev.BeginEncoder() pass := enc.BeginRenderPass(gpu.RenderPassDesc{ Label: "editor.thumbnail", - ColorAttachments: []gpu.ColorAttachment{{LoadOp: gpu.LoadClear, StoreOp: gpu.StoreStore, ClearColor: core.RGBA(0x000000, 0)}}, + ColorAttachments: []gpu.ColorAttachment{{LoadOp: gpu.LoadClear, StoreOp: gpu.StoreStore, ClearColor: core.Color(0)}}, DepthStencil: &gpu.DepthStencilAttachment{DepthLoadOp: gpu.LoadClear, DepthStoreOp: gpu.StoreDiscard, ClearDepth: 1}, }) r.Draw(pass) diff --git a/packages/game/editor/navmesh3d.go b/packages/game/editor/navmesh3d.go index 75fb95c0d..eb54d07a0 100644 --- a/packages/game/editor/navmesh3d.go +++ b/packages/game/editor/navmesh3d.go @@ -610,8 +610,9 @@ func (e *Editor) drawNavMeshOverlay3D(d *core.Drawing, w, h float32) { const lift float32 = 0.05 + spec := e.activeSpecPalette() // 1. Translucent walkable fill for each detail triangle (clipped against camera near plane). - d.Save().SetFillColor(core.RGBA(0x22D3EE, 0.24)).BeginPath() + d.Save().SetFillColor(specAlpha(spec.Accent.Fg, 0.24)).BeginPath() hasFill := false var tri [3][3]float32 for pi := range mesh.Polygons { @@ -668,10 +669,10 @@ func (e *Editor) drawNavMeshOverlay3D(d *core.Drawing, w, h float32) { } if outlines < len(allLines) { - drawLines(allLines[outlines:], core.RGBA(0x0E7490, 0.55), 1.0) + drawLines(allLines[outlines:], specAlpha(spec.Accent.Edge, 0.55), 1.0) } if outlines > 0 { - drawLines(allLines[:outlines], core.RGBA(0x22D3EE, 0.95), 1.75) + drawLines(allLines[:outlines], specAlpha(spec.Accent.Edge, 0.95), 1.75) } } diff --git a/packages/game/editor/navmesh3d_panel.go b/packages/game/editor/navmesh3d_panel.go index ccd2b9484..312cf569c 100644 --- a/packages/game/editor/navmesh3d_panel.go +++ b/packages/game/editor/navmesh3d_panel.go @@ -298,7 +298,7 @@ func NavMeshPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core }, Style: core.Style{ FontSize: 11, - Color: core.RGBA(0xF87171, 1), + Color: ed.SpecPalette(cx).Removed.Fg, }, } }, diff --git a/packages/game/editor/navmesh3d_test.go b/packages/game/editor/navmesh3d_test.go index 58d82eefe..df876f3dd 100644 --- a/packages/game/editor/navmesh3d_test.go +++ b/packages/game/editor/navmesh3d_test.go @@ -16,6 +16,7 @@ import ( "github.com/nsgo-dev/game/packages/game/world3d" "github.com/nsgo-dev/nsgo/core" "github.com/nsgo-dev/nsgo/nsgotest" + "github.com/nsgo-dev/nsgo/ui" ) const navMeshTestProjectYAML = `version: 1 @@ -507,8 +508,9 @@ func TestEditorNavMesh3DOrthographicOverlayAlignment(t *testing.T) { ops := app.Find("id:nav-ortho-canvas").Ops var fillPts [][2]float32 inNavFill := false + wantNavFill := ui.Alpha(ed.SpecPalette(nil).Accent.Fg, 0.24) for _, op := range ops { - if op.Kind == core.DrawFillColor && op.Color == core.RGBA(0x22D3EE, 0.24) { + if op.Kind == core.DrawFillColor && op.Color == wantNavFill { inNavFill = true continue } diff --git a/packages/game/editor/navregion2d_editor.go b/packages/game/editor/navregion2d_editor.go index d1f2217ba..a4b9fa4f4 100644 --- a/packages/game/editor/navregion2d_editor.go +++ b/packages/game/editor/navregion2d_editor.go @@ -559,19 +559,19 @@ func (e *Editor) updateNavRegionDrag2D(x, y float32) { } var ( - navMesh2DFillColor = core.RGBA(0x22D3EE, 0.2) - navMesh2DEdgeColor = core.RGBA(0x06B6D4, 0.78) - navMesh2DPortalColor = core.RGBA(0x38BDF8, 0.45) - navRegionWalkableColor = core.RGBA(0x14B8A6, 0.92) - navRegionWalkableSubtle = core.RGBA(0x14B8A6, 0.5) - navRegionObstacleColor = core.RGBA(0xFB7185, 0.92) - navRegionObstacleSubtle = core.RGBA(0xFB7185, 0.5) - navRegionEdgeMidFillColor = core.RGBA(0x99F6E4, 0.95) - navRegionObstacleMidFill = core.RGBA(0xFECDD3, 0.95) - navPathLineColor = core.RGBA(0xFACC15, 0.95) - navPathBlockedColor = core.RGBA(0xEF4444, 0.85) - navPathStartColor = core.RGBA(0x22C55E, 1) - navPathEndColor = core.RGBA(0xF97316, 1) + navMesh2DFillColor = specAlpha(darkSpecPalette.Accent.Fg, 0.2) + navMesh2DEdgeColor = specAlpha(darkSpecPalette.Accent.Edge, 0.78) + navMesh2DPortalColor = specAlpha(darkSpecPalette.Agent.Fg, 0.45) + navRegionWalkableColor = specAlpha(darkSpecPalette.Added.Fg, 0.92) + navRegionWalkableSubtle = specAlpha(darkSpecPalette.Added.Fg, 0.5) + navRegionObstacleColor = specAlpha(darkSpecPalette.Removed.Fg, 0.92) + navRegionObstacleSubtle = specAlpha(darkSpecPalette.Removed.Fg, 0.5) + navRegionEdgeMidFillColor = CompositeOver(specAlpha(darkSpecPalette.TextPrimary, 0.6), darkSpecPalette.Added.Fg) + navRegionObstacleMidFill = CompositeOver(specAlpha(darkSpecPalette.TextPrimary, 0.6), darkSpecPalette.Removed.Fg) + navPathLineColor = specAlpha(darkSpecPalette.Warning.Fg, 0.95) + navPathBlockedColor = specAlpha(darkSpecPalette.Removed.Fg, 0.85) + navPathStartColor = darkSpecPalette.Added.Fg + navPathEndColor = darkSpecPalette.Changed.Fg ) // drawNavMesh2DOverlay draws the baked 2D navigation mesh polygons and portals, authored navregion2d outlines, and the active test-path preview in the 2D edit viewport. diff --git a/packages/game/editor/parallax_test.go b/packages/game/editor/parallax_test.go index 1e26779ae..c47ac7462 100644 --- a/packages/game/editor/parallax_test.go +++ b/packages/game/editor/parallax_test.go @@ -9,6 +9,7 @@ import ( "github.com/nsgo-dev/game/packages/game/gametest" "github.com/nsgo-dev/game/packages/game/sceneformat" "github.com/nsgo-dev/nsgo/core" + "github.com/nsgo-dev/nsgo/ui" ) func parallaxSceneDoc() *sceneformat.SceneDoc { @@ -304,7 +305,7 @@ func TestEditorParallaxAlignsGizmoTileHoverAndPhysicsDebug(t *testing.T) { defer ed.SetShowPhysicsDebug(false) d := &core.Drawing{} ed.DrawViewport(d, size) - x, y, ok := findStrokedRectCanvasPos(d.Ops, core.RGBA(0x60A5FA, 0.9), 16, 16) + x, y, ok := findStrokedRectCanvasPos(d.Ops, ui.Alpha(editor.DarkSpecPalette().Accent.Fg, 0.9), 16, 16) if !ok { t.Fatal("physics debug StrokeRect not found") } @@ -357,7 +358,7 @@ func TestEditorParallaxAlignsGizmoTileHoverAndPhysicsDebug(t *testing.T) { } d := &core.Drawing{} ed.DrawViewport(d, size) - hx, hy, foundHover := findStrokedRectCanvasPos(d.Ops, core.RGBA(0x38BDF8, 1), 16, 16) + hx, hy, foundHover := findStrokedRectCanvasPos(d.Ops, ed.SpecPalette(nil).Accent.Fg, 16, 16) if !foundHover { t.Fatal("tile hover StrokeRect not found") } diff --git a/packages/game/editor/particles.go b/packages/game/editor/particles.go index 2ae5bb73b..13787f9a3 100644 --- a/packages/game/editor/particles.go +++ b/packages/game/editor/particles.go @@ -1816,8 +1816,9 @@ func (e *Editor) drawParticleEmitterOverlays(d *core.Drawing, scene *sceneformat } p := m.TransformPoint(math2d.Vec2{X: bo.Emitter.X, Y: bo.Emitter.Y}) cx, cy := p.X, p.Y + spec := e.activeSpecPalette() d.Save() - d.SetStrokeColor(core.RGBA(0xF59E0B, 0.9)).SetLineWidth(1.5) + d.SetStrokeColor(specAlpha(spec.Warning.Fg, 0.9)).SetLineWidth(1.5) // Draw small diamond origin marker. const r float32 = 6 d.BeginPath(). @@ -1829,7 +1830,7 @@ func (e *Editor) drawParticleEmitterOverlays(d *core.Drawing, scene *sceneformat // Draw spawn shape preview scaled by view zoom. zoom := strokeScale(m) sh := bo.Emitter.Shape - d.SetStrokeColor(core.RGBA(0xF59E0B, 0.45)).SetLineDash(4, 3).SetLineWidth(1) + d.SetStrokeColor(specAlpha(spec.Warning.Fg, 0.45)).SetLineDash(4, 3).SetLineWidth(1) switch sh.Kind() { case "circle", "ring": if rad := sh.Radius() * zoom; rad > 1 { diff --git a/packages/game/editor/particles_ui.go b/packages/game/editor/particles_ui.go index bd92798ed..721f612f2 100644 --- a/packages/game/editor/particles_ui.go +++ b/packages/game/editor/particles_ui.go @@ -204,7 +204,7 @@ func particleEditorPanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c Style: core.Style{ Width: core.Pt(244), Height: core.Pt(170), - Background: core.RGB(0x0f172a), + Background: ed.SpecPalette(cx).Viewport, CornerRadius: 6, BorderWidth: 1, BorderColor: colors.Line(), @@ -316,9 +316,10 @@ func drawParticlePreviewCanvas(d *core.Drawing, size core.Size, ed *Editor) { } cx, cy := w/2, h/2 + spec := ed.activeSpecPalette() // Subtle grid & origin crosshair. d.Save() - d.SetStrokeColor(core.RGBA(0x94A3B8, 0.16)).SetLineWidth(1) + d.SetStrokeColor(specAlpha(spec.TextFaint, 0.16)).SetLineWidth(1) d.BeginPath().MoveTo(cx, 0).LineTo(cx, h).MoveTo(0, cy).LineTo(w, cy).Stroke() em := ed.ParticlePreview() @@ -331,7 +332,7 @@ func drawParticlePreviewCanvas(d *core.Drawing, size core.Size, ed *Editor) { d.Translate(cx-em.X, cy-em.Y) // Draw spawn shape guide. - d.SetStrokeColor(core.RGBA(0x38BDF8, 0.45)).SetLineDash(4, 3).SetLineWidth(1) + d.SetStrokeColor(specAlpha(spec.Accent.Fg, 0.45)).SetLineDash(4, 3).SetLineWidth(1) sh := em.Shape switch sh.Kind() { case "circle", "ring": @@ -348,7 +349,7 @@ func drawParticlePreviewCanvas(d *core.Drawing, size core.Size, ed *Editor) { // Draw preview floor collider when enabled. if ed.ParticlePreviewFloor() { fy := em.Y + 60 - d.SetStrokeColor(core.RGBA(0xF59E0B, 0.7)).SetLineWidth(1.5) + d.SetStrokeColor(specAlpha(spec.Warning.Fg, 0.7)).SetLineWidth(1.5) d.BeginPath().MoveTo(em.X-w, fy).LineTo(em.X+w, fy).Stroke() } @@ -1251,7 +1252,7 @@ func particleCurveWidgetView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 Style: core.Style{ Width: core.Pt(graphW), Height: core.Pt(graphH), - Background: core.RGB(0x0f172a), + Background: ed.SpecPalette(cx).Viewport, CornerRadius: 6, BorderWidth: 1, BorderColor: colors.Line(), @@ -1262,9 +1263,10 @@ func particleCurveWidgetView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 minY, maxY := curveYBounds(kind, curve) sel := ed.ParticleSelectedStop() + spec := ed.activeSpecPalette() // Grid lines at t = 0, 0.25, 0.5, 0.75, 1 and mid Y. d.Save() - d.SetStrokeColor(core.RGBA(0x94A3B8, 0.2)).SetLineWidth(1) + d.SetStrokeColor(specAlpha(spec.TextFaint, 0.2)).SetLineWidth(1) d.BeginPath() for g := range 5 { gx := padX + (float32(g)/4)*(graphW-2*padX) @@ -1277,7 +1279,7 @@ func particleCurveWidgetView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 d.Stroke() // Evaluated curve polyline. - d.SetStrokeColor(core.RGB(0x38BDF8)).SetLineWidth(2) + d.SetStrokeColor(spec.Accent.Fg).SetLineWidth(2) d.BeginPath() const samples = 40 for i := 0; i <= samples; i++ { @@ -1299,14 +1301,14 @@ func particleCurveWidgetView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 for i, s := range curve { sx, sy := tvToPoint(s.T, s.Value, minY, maxY) r := float32(4.5) - fill := core.RGB(0xF8FAFC) + fill := spec.TextPrimary if i == sel { r = 6 - fill = core.RGB(0xF59E0B) + fill = spec.Warning.Fg } d.SetFillColor(fill) d.BeginPath().Arc(sx, sy, r, 0, 2*math.Pi, false).Fill() - d.SetStrokeColor(core.RGB(0x0f172a)).SetLineWidth(1.5) + d.SetStrokeColor(spec.Bg).SetLineWidth(1.5) d.BeginPath().Arc(sx, sy, r, 0, 2*math.Pi, false).Stroke() } d.Restore() @@ -1354,7 +1356,7 @@ func particleCurveWidgetView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 Style: core.Style{ Width: core.Pt(graphW), Height: core.Pt(barH), - Background: core.RGB(0x0f172a), + Background: ed.SpecPalette(cx).Viewport, CornerRadius: 6, BorderWidth: 1, BorderColor: colors.Line(), @@ -1372,11 +1374,12 @@ func particleCurveWidgetView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 d.SetFillColor(curve.At(t)) d.FillRect(padX+float32(i)*(innerW/steps), 6, segW, barH-16) } + spec := ed.activeSpecPalette() for i, s := range curve { sx := padX + clamp01f32(s.T)*innerW - stroke := core.RGB(0xF8FAFC) + stroke := spec.TextPrimary if i == sel { - stroke = core.RGB(0xF59E0B) + stroke = spec.Warning.Fg } d.SetFillColor(s.Color | 0xff) d.BeginPath().Arc(sx, barH-7, 5, 0, 2*math.Pi, false).Fill() diff --git a/packages/game/editor/physics_debug.go b/packages/game/editor/physics_debug.go index d5f74b97d..142d2a20b 100644 --- a/packages/game/editor/physics_debug.go +++ b/packages/game/editor/physics_debug.go @@ -11,16 +11,17 @@ import ( ) func physicsDebugColor(isTrigger bool, bodyKind string) core.Color { + pal := darkSpecPalette if isTrigger { - return core.RGBA(0xF59E0B, 0.95) + return specAlpha(pal.Warning.Fg, 0.95) } switch bodyKind { case "dynamic": - return core.RGBA(0x22C55E, 0.95) + return specAlpha(pal.Added.Fg, 0.95) case "kinematic": - return core.RGBA(0x38BDF8, 0.95) + return specAlpha(pal.Agent.Fg, 0.95) default: - return core.RGBA(0x60A5FA, 0.9) + return specAlpha(pal.Accent.Fg, 0.9) } } diff --git a/packages/game/editor/play_marks_ui.go b/packages/game/editor/play_marks_ui.go index 6e0eb56b4..cc277228b 100644 --- a/packages/game/editor/play_marks_ui.go +++ b/packages/game/editor/play_marks_ui.go @@ -10,14 +10,14 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Spec-derived composite tints for Play mode header and panic card (all derived strictly from Spec.dc.html tokens). +// Spec-derived composite tints for Play mode header and panic card (all derived strictly from spec_theme.yaml tokens). var ( - specPlayRunBg = core.RGB(0x16221F) // #101216 + 6% #4FD38A - specPlayRunBorder = core.RGBA(0x4FD38A, 0.35) - specPlayPauseBg = core.RGB(0x1E1D19) // #101216 + 5% #F2C14E - specPanicCardBg = core.RGB(0x211A21) // #171A21 + 6% #FF6B6B - specAgentBubbleBg = core.RGB(0x1C2130) - specAgentStepDoneB = core.RGB(0x1F3A2B) + specPlayRunBg = CompositeOver(specAlpha(darkSpecPalette.Added.Fg, 0.06), darkSpecPalette.Bg) + specPlayRunBorder = specAlpha(darkSpecPalette.Added.Fg, 0.35) + specPlayPauseBg = CompositeOver(specAlpha(darkSpecPalette.Warning.Fg, 0.05), darkSpecPalette.Bg) + specPanicCardBg = CompositeOver(specAlpha(darkSpecPalette.Removed.Fg, 0.06), darkSpecPalette.Raised) + specAgentBubbleBg = CompositeOver(specAlpha(darkSpecPalette.Accent.Fg, 0.08), darkSpecPalette.Raised) + specAgentStepDoneB = darkSpecPalette.Added.Fill ) // playModeBarView renders the Play Mode control bar below the main toolbar while local Play mode is active @@ -42,7 +42,7 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. if math.Abs(ed.PlayTimeScale()-scale) < 1e-6 { return specLineRaised } - return core.RGBA(0, 0) + return core.Color(0) }, TextStyle: core.Style{ FontSize: 11, @@ -777,7 +777,7 @@ func playInspectorTabBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 if ed.PlayInspectorTab() == target { return specAgentBubbleBg } - return core.RGBA(0, 0) + return core.Color(0) }, TextStyle: core.Style{ FontSize: 12, @@ -932,7 +932,7 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co }) } for i, st := range steps { - dotFill := core.RGBA(0, 0) + dotFill := core.Color(0) dotBorder := specLineRaised textColor := specTextMuted switch st.Status { diff --git a/packages/game/editor/playtest_report_ui.go b/packages/game/editor/playtest_report_ui.go index d139f3baa..a3c855887 100644 --- a/packages/game/editor/playtest_report_ui.go +++ b/packages/game/editor/playtest_report_ui.go @@ -12,19 +12,19 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Spec-derived alpha tints strictly from Spec.dc.html color tokens (never introducing off-spec hex values). +// Spec-derived alpha tints strictly from spec_theme.yaml color tokens. var ( - specPlaytestMissedFill = core.RGBA(0xFF6B6B, 0.08) - specPlaytestHeatRedHigh = core.RGBA(0xFF6B6B, 0.56) - specPlaytestHeatRedMid = core.RGBA(0xFF6B6B, 0.28) - specPlaytestHeatRedSoft = core.RGBA(0xFF6B6B, 0.12) - specPlaytestHeatAmberHi = core.RGBA(0xE9A84A, 0.48) - specPlaytestHeatAmberMid = core.RGBA(0xE9A84A, 0.22) - specPlaytestHeatAmberLow = core.RGBA(0xE9A84A, 0.10) - specPlaytestLineArea = core.RGBA(0x3B7BFF, 0.14) - specPlaytestGridLine = core.RGBA(0x8B92A0, 0.16) - specPlaytestAgentBanner = core.RGBA(0x9B7BFF, 0.10) - specPlaytestAgentBorder = core.RGBA(0x9B7BFF, 0.50) + specPlaytestMissedFill = specAlpha(darkSpecPalette.Removed.Fg, 0.08) + specPlaytestHeatRedHigh = specAlpha(darkSpecPalette.Removed.Fg, 0.56) + specPlaytestHeatRedMid = specAlpha(darkSpecPalette.Removed.Fg, 0.28) + specPlaytestHeatRedSoft = specAlpha(darkSpecPalette.Removed.Fg, 0.12) + specPlaytestHeatAmberHi = specAlpha(darkSpecPalette.Changed.Fg, 0.48) + specPlaytestHeatAmberMid = specAlpha(darkSpecPalette.Changed.Fg, 0.22) + specPlaytestHeatAmberLow = specAlpha(darkSpecPalette.Changed.Fg, 0.10) + specPlaytestLineArea = specAlpha(darkSpecPalette.Accent.Fg, 0.14) + specPlaytestGridLine = specAlpha(darkSpecPalette.TextFaint, 0.16) + specPlaytestAgentBanner = specAlpha(darkSpecPalette.Agent.Fg, 0.10) + specPlaytestAgentBorder = specAlpha(darkSpecPalette.Agent.Fg, 0.50) ) // PlaytestReportView renders the full-window Playtest Report screen matching docs/design/editor/Playtest.dc.html diff --git a/packages/game/editor/profiler_ui.go b/packages/game/editor/profiler_ui.go index 0fbb970aa..cbcc01362 100644 --- a/packages/game/editor/profiler_ui.go +++ b/packages/game/editor/profiler_ui.go @@ -12,30 +12,30 @@ import ( ) // Spec color tokens from docs/design/editor/Spec.dc.html and docs/design/editor/PlayMode.dc.html. -// Every color used by the Play-mode frame time strip and the full Profiler panel comes exclusively from this table. +// Every color used by the Play-mode frame time strip and the full Profiler panel comes exclusively from spec_theme.yaml. var ( - specBg = core.RGB(0x101216) - specBgOverlay = core.RGBA(0x101216, 0.92) - specPanel = core.RGB(0x12141A) - specRaised = core.RGB(0x171A21) - specLine = core.RGB(0x1F232A) - specLineRaised = core.RGB(0x262B35) - specTextStrong = core.RGB(0xFFFFFF) - specText = core.RGB(0xD9DDE5) - specTextSecondary = core.RGB(0xB4BAC6) - specTextMuted = core.RGB(0x8B92A0) - specBarNormal = core.RGBA(0x8B92A0, 0.45) - specAccent = core.RGB(0x3B7BFF) - specAgent = core.RGB(0x9B7BFF) - specAdded = core.RGB(0x4FD38A) - specAddedFill = core.RGBA(0x4FD38A, 0.12) - specAddedEdge = core.RGBA(0x4FD38A, 0.45) - specChanged = core.RGB(0xE9A84A) - specProblem = core.RGB(0xFF6B6B) - specProblemEdge = core.RGBA(0xFF6B6B, 0.50) - specWarning = core.RGB(0xF2C14E) - specWarningFill = core.RGB(0x2A2414) - specWarningEdge = core.RGB(0x4A3F1F) + specBg = darkSpecPalette.Bg + specBgOverlay = specAlpha(darkSpecPalette.Bg, 0.92) + specPanel = darkSpecPalette.Panel + specRaised = darkSpecPalette.Raised + specLine = darkSpecPalette.Line + specLineRaised = darkSpecPalette.LineRaised + specTextStrong = darkSpecPalette.TextPrimary + specText = darkSpecPalette.TextSecondary + specTextSecondary = darkSpecPalette.TextMuted + specTextMuted = darkSpecPalette.TextFaint + specBarNormal = specAlpha(darkSpecPalette.TextFaint, 0.45) + specAccent = darkSpecPalette.Accent.Fg + specAgent = darkSpecPalette.Agent.Fg + specAdded = darkSpecPalette.Added.Fg + specAddedFill = specAlpha(darkSpecPalette.Added.Fg, 0.12) + specAddedEdge = specAlpha(darkSpecPalette.Added.Fg, 0.45) + specChanged = darkSpecPalette.Changed.Fg + specProblem = darkSpecPalette.Removed.Fg + specProblemEdge = specAlpha(darkSpecPalette.Removed.Fg, 0.50) + specWarning = darkSpecPalette.Warning.Fg + specWarningFill = darkSpecPalette.Warning.Fill + specWarningEdge = darkSpecPalette.Warning.Edge ) // ProfilerStripView renders the Play-mode "FRAME TIME · LAST 60 S" strip directly below the game view while Play mode is active or a running game is connected to the profiler, matching docs/design/editor/PlayMode.dc.html. Pressing the strip's Profiler button opens the full Profiler panel. diff --git a/packages/game/editor/rig_handles.go b/packages/game/editor/rig_handles.go index 2f7a8f863..1150052e1 100644 --- a/packages/game/editor/rig_handles.go +++ b/packages/game/editor/rig_handles.go @@ -656,9 +656,10 @@ func (e *Editor) DrawRigViewport(d *core.Drawing, size core.Size) { cw, ch := float32(size.Width), float32(size.Height) e.SetRigCanvasSize(cw, ch) + spec := e.activeSpecPalette() // Background and subtle grid. d.Save() - d.SetFillColor(core.RGBA(0x111827, 1)).FillRect(0, 0, cw, ch) + d.SetFillColor(spec.Viewport).FillRect(0, 0, cw, ch) ox, oy := e.RigWorldToCanvas(0, 0) z := e.rigZoom() @@ -666,7 +667,7 @@ func (e *Editor) DrawRigViewport(d *core.Drawing, size core.Size) { if step < 8 { step = 8 } - d.SetStrokeColor(core.RGBA(0xFFFFFF, 0.06)).SetLineWidth(1) + d.SetStrokeColor(spec.HoverOverlay).SetLineWidth(1) d.BeginPath() for x := ox - float32(math.Ceil(float64(ox/step)))*step; x <= cw; x += step { d.MoveTo(x, 0).LineTo(x, ch) @@ -677,9 +678,9 @@ func (e *Editor) DrawRigViewport(d *core.Drawing, size core.Size) { d.Stroke() // Origin axes. - d.SetStrokeColor(core.RGBA(0xEF4444, 0.35)).SetLineWidth(1) + d.SetStrokeColor(specAlpha(spec.AxisX, 0.35)).SetLineWidth(1) d.BeginPath().MoveTo(0, oy).LineTo(cw, oy).Stroke() - d.SetStrokeColor(core.RGBA(0x22C55E, 0.35)).SetLineWidth(1) + d.SetStrokeColor(specAlpha(spec.AxisY, 0.35)).SetLineWidth(1) d.BeginPath().MoveTo(ox, 0).LineTo(ox, ch).Stroke() // Draw live runtime skeletal attachments. @@ -703,18 +704,18 @@ func (e *Editor) DrawRigViewport(d *core.Drawing, size core.Size) { if b.Parent != "" { if pw, pok := e.rig.skel.WorldBone(b.Parent); pok { px, py := e.RigWorldToCanvas(pw.X, pw.Y) - d.SetStrokeColor(core.RGBA(0x94A3B8, 0.45)).SetLineWidth(1).SetLineDash(3, 3) + d.SetStrokeColor(specAlpha(spec.TextFaint, 0.45)).SetLineWidth(1).SetLineDash(3, 3) d.BeginPath().MoveTo(px, py).LineTo(bx, by).Stroke() d.SetLineDash() } } selected := b.Name == e.rig.selectedBone - fill := core.RGBA(0x38BDF8, 0.25) - stroke := core.RGBA(0x38BDF8, 0.85) + fill := specAlpha(spec.Accent.Fg, 0.25) + stroke := specAlpha(spec.Accent.Fg, 0.85) if selected { - fill = core.RGBA(0xFBBF24, 0.35) - stroke = core.RGBA(0xFBBF24, 1) + fill = specAlpha(spec.Warning.Fg, 0.35) + stroke = spec.Warning.Fg } origin, tip, _, _ := e.RigBoneHandlePos(b.Name) @@ -740,7 +741,7 @@ func (e *Editor) DrawRigViewport(d *core.Drawing, size core.Size) { d.BeginPath().MoveTo(origin.X, origin.Y).LineTo(tip.X, tip.Y).Stroke() } // Joint circle. - d.SetFillColor(core.RGBA(0x0F172A, 1)).SetStrokeColor(stroke).SetLineWidth(1.5) + d.SetFillColor(spec.Bg).SetStrokeColor(stroke).SetLineWidth(1.5) d.BeginPath().Ellipse(origin.X, origin.Y, 4.5, 4.5).Fill().Stroke() } @@ -748,26 +749,26 @@ func (e *Editor) DrawRigViewport(d *core.Drawing, size core.Size) { if e.rig.selectedBone != "" { if origin, tip, ring, ok := e.RigBoneHandlePos(e.rig.selectedBone); ok { active := e.rig.drag.handle - ringCol := core.RGBA(0x38BDF8, 0.75) + ringCol := specAlpha(spec.Accent.Fg, 0.75) if active == RigHandleBoneRotate { - ringCol = core.RGBA(0xFBBF24, 1) + ringCol = spec.Warning.Fg } d.SetStrokeColor(ringCol).SetLineWidth(1.5) d.BeginPath().Arc(origin.X, origin.Y, ring, 0, 2*math.Pi, false).Stroke() - moveCol := core.RGBA(0xF8FAFC, 1) + moveCol := spec.TextPrimary if active == RigHandleBoneMove { - moveCol = core.RGBA(0xFBBF24, 1) + moveCol = spec.Warning.Fg } - d.SetFillColor(moveCol).SetStrokeColor(core.RGBA(0x0F172A, 1)).SetLineWidth(1.5) + d.SetFillColor(moveCol).SetStrokeColor(spec.Bg).SetLineWidth(1.5) d.BeginPath().Ellipse(origin.X, origin.Y, 5.5, 5.5).Fill().Stroke() - tipCol := core.RGBA(0x22C55E, 1) + tipCol := spec.Added.Fg if active == RigHandleBoneLength { - tipCol = core.RGBA(0xFBBF24, 1) + tipCol = spec.Warning.Fg } const r float32 = 5 - d.SetFillColor(tipCol).SetStrokeColor(core.RGBA(0x0F172A, 1)).SetLineWidth(1.5) + d.SetFillColor(tipCol).SetStrokeColor(spec.Bg).SetLineWidth(1.5) d.BeginPath(). MoveTo(tip.X, tip.Y-r). LineTo(tip.X+r, tip.Y). @@ -795,15 +796,15 @@ func (e *Editor) DrawRigViewport(d *core.Drawing, size core.Size) { px, py := e.RigWorldToCanvas(pt.X, pt.Y) pts[i] = math2d.Vec2{X: px, Y: py} } - d.SetStrokeColor(core.RGBA(0xA855F7, 0.85)).SetLineWidth(1).SetLineDash(4, 3) + d.SetStrokeColor(specAlpha(spec.Agent.Fg, 0.85)).SetLineWidth(1).SetLineDash(4, 3) strokePolygon(d, pts) d.SetLineDash() } } px, py := e.RigWorldToCanvas(wt.X, wt.Y) - origCol := core.RGBA(0xE879F9, 1) + origCol := spec.Agent.Fg if e.rig.drag.handle == RigHandleAttachmentOrigin { - origCol = core.RGBA(0xFBBF24, 1) + origCol = spec.Warning.Fg } const arm float32 = 8 d.SetStrokeColor(origCol).SetLineWidth(1.5) diff --git a/packages/game/editor/rooms.go b/packages/game/editor/rooms.go index e10ea012a..e5fea86ee 100644 --- a/packages/game/editor/rooms.go +++ b/packages/game/editor/rooms.go @@ -1190,6 +1190,7 @@ func (e *Editor) drawRoomsOverlay(d *core.Drawing) { } } + spec := e.activeSpecPalette() for i := range e.rooms.doc.Rooms { r := &e.rooms.doc.Rooms[i] selected := r.ID == e.rooms.selectedRoomID @@ -1197,9 +1198,9 @@ func (e *Editor) drawRoomsOverlay(d *core.Drawing) { // Fill room rectangle. if selected { - d.SetFillColor(core.RGBA(0x14B8A6, 0.20)) + d.SetFillColor(specAlpha(spec.Added.Fg, 0.20)) } else { - d.SetFillColor(core.RGBA(0x14B8A6, 0.10)) + d.SetFillColor(specAlpha(spec.Added.Fg, 0.10)) } d.BeginPath().MoveTo(pts[0].X, pts[0].Y) for _, p := range pts[1:] { @@ -1209,9 +1210,9 @@ func (e *Editor) drawRoomsOverlay(d *core.Drawing) { // Stroke room border. if selected { - d.SetStrokeColor(core.RGBA(0x5EEAD4, 1)).SetLineWidth(2) + d.SetStrokeColor(spec.Added.Edge).SetLineWidth(2) } else { - d.SetStrokeColor(core.RGBA(0x2DD4BF, 0.85)).SetLineWidth(1.5) + d.SetStrokeColor(specAlpha(spec.Added.Edge, 0.85)).SetLineWidth(1.5) } strokePolygon(d, pts) @@ -1227,30 +1228,30 @@ func (e *Editor) drawRoomsOverlay(d *core.Drawing) { label += " (" + string(tr.Kind) + ")" } lx, ly := e.WorldToCanvas(r.X, r.Y) - d.SetFillColor(core.RGBA(0x0F172A, 0.78)) + d.SetFillColor(specAlpha(spec.PillBg, 0.88)) badgeW := float32(len(label))*6.5 + 10 d.FillRect(lx+4, ly+4, badgeW, 18) - d.SetFillColor(core.RGBA(0xCCFBF1, 1)). + d.SetFillColor(spec.Added.Fg). SetTextAlign(core.TextAlignLeft). SetTextBaseline(core.BaselineTop). FillText(label, lx+9, ly+7, font) // Draw 8 resize handles on the selected room. if selected && (e.Tool == ToolSelect || e.Tool == ToolMove) && !e.rooms.createMode { - drawWorldRectHandles(e, d, r.X, r.Y, r.Width, r.Height, e.roomDrag.handle, core.RGBA(0xFFFFFF, 1), core.RGBA(0x14B8A6, 1), core.RGBA(0x5EEAD4, 1)) + drawWorldRectHandles(e, d, r.X, r.Y, r.Width, r.Height, e.roomDrag.handle, spec.TextPrimary, spec.Added.Edge, spec.Added.Fg) } } // Draw live creation preview rectangle while dragging in Draw Room mode. if e.roomDrag.active && e.roomDrag.creating && e.roomDrag.moved { pts := worldRectCanvasCorners(e, e.roomDrag.previewX, e.roomDrag.previewY, e.roomDrag.previewW, e.roomDrag.previewH) - d.SetFillColor(core.RGBA(0x14B8A6, 0.22)) + d.SetFillColor(specAlpha(spec.Added.Fg, 0.22)) d.BeginPath().MoveTo(pts[0].X, pts[0].Y) for _, p := range pts[1:] { d.LineTo(p.X, p.Y) } d.ClosePath().Fill() - d.SetStrokeColor(core.RGBA(0x5EEAD4, 1)).SetLineWidth(1.5).SetLineDash(5, 3) + d.SetStrokeColor(spec.Added.Edge).SetLineWidth(1.5).SetLineDash(5, 3) strokePolygon(d, pts) d.SetLineDash() } @@ -1295,7 +1296,7 @@ func (e *Editor) drawRoomSnapGrid(d *core.Drawing, gw, gh float32) { return } d.Save() - d.SetStrokeColor(core.RGBA(0x5EEAD4, 0.16)).SetLineWidth(1) + d.SetStrokeColor(specAlpha(e.activeSpecPalette().Added.Edge, 0.16)).SetLineWidth(1) d.BeginPath() for x, n := startX, 0; x <= maxX && n <= 258; x, n = x+gw, n+1 { x0, y0 := e.WorldToCanvas(x, minY) diff --git a/packages/game/editor/scenetree.go b/packages/game/editor/scenetree.go index d84cdace0..4666037cd 100644 --- a/packages/game/editor/scenetree.go +++ b/packages/game/editor/scenetree.go @@ -563,7 +563,7 @@ func shownRow(roots []any, children func(sceneTreeKey) []any, expanded func(scen func dropStyle(cx *core.Scope, hint *core.Signal[treeHint], k sceneTreeKey) core.Style { colors := ui.ColorsOf(cx) h := hint.Get() - s := core.Style{Borders: core.Edges{Top: 2, Bottom: 2}, BorderColor: colors.Inset()} + s := core.Style{Borders: core.Edges{Top: 2, Bottom: 2}, BorderColor: colors.Surface()} if !h.on || h.key != k { return s } diff --git a/packages/game/editor/shapes2d.go b/packages/game/editor/shapes2d.go index bc34b99ed..7081fa9a2 100644 --- a/packages/game/editor/shapes2d.go +++ b/packages/game/editor/shapes2d.go @@ -945,17 +945,17 @@ func normZero(v float64) float64 { // --- 2D Viewport Drawing --- -func shapeBaseRGB(compName string) uint32 { +func shapeBaseColor(p SpecPalette, compName string) core.Color { lc := strings.ToLower(compName) switch { case strings.Contains(lc, "trigger"), strings.Contains(lc, "sensor"), strings.Contains(lc, "area"): - return 0xF59E0B // amber + return p.Warning.Fg case strings.Contains(lc, "nav"), strings.Contains(lc, "path"), strings.Contains(lc, "spawn"): - return 0x10B981 // emerald + return p.Added.Fg case strings.Contains(lc, "light"), strings.Contains(lc, "occlud"), strings.Contains(lc, "shadow"): - return 0xA855F7 // violet + return p.Agent.Fg default: - return 0x22D3EE // cyan + return p.Accent.Fg } } @@ -1013,7 +1013,7 @@ func (e *Editor) drawComponentShapes2D(d *core.Drawing, scene *sceneformat.Built d.Save() saved = true } - rgb := shapeBaseRGB(s.Component) + base := shapeBaseColor(e.activeSpecPalette(), s.Component) strokeAlpha := float32(0.55) fillAlpha := float32(0.07) lineW := float32(1.25) @@ -1022,8 +1022,8 @@ func (e *Editor) drawComponentShapes2D(d *core.Drawing, scene *sceneformat.Built fillAlpha = 0.15 lineW = 1.75 } - stroke := core.RGBA(rgb, strokeAlpha) - fill := core.RGBA(rgb, fillAlpha) + stroke := specAlpha(base, strokeAlpha) + fill := specAlpha(base, fillAlpha) d.SetLineWidth(lineW) switch s.Kind { case sceneformat.FieldPoint: @@ -1058,6 +1058,7 @@ func (e *Editor) drawComponentShapeHandles2D(d *core.Drawing) { active, hasActive := e.ActiveShapeHandle2D() d.Save() d.SetLineWidth(1.5) + spec := e.activeSpecPalette() for _, h := range handles { isActive := hasActive && h.ObjectID == active.ObjectID && @@ -1065,17 +1066,16 @@ func (e *Editor) drawComponentShapeHandles2D(d *core.Drawing) { h.Field == active.Field && h.Kind == active.Kind && h.Index == active.Index - rgb := shapeBaseRGB(h.Component) - stroke := core.RGBA(rgb, 1) - fill := core.RGBA(0xF8FAFC, 1) + stroke := shapeBaseColor(spec, h.Component) + fill := spec.TextPrimary if isActive { - fill = gizmoColorActive - stroke = core.RGBA(0x0F172A, 1) + fill = spec.Warning.Fg + stroke = spec.Bg } p := h.Pos switch h.Kind { case ShapeHandlePolygonMidpoint: - d.SetFillColor(core.RGBA(0x0F172A, 0.75)) + d.SetFillColor(specAlpha(spec.Bg, 0.75)) d.SetStrokeColor(stroke) d.BeginPath().Ellipse(p.X, p.Y, shapeMidHalf, shapeMidHalf).Fill().Stroke() case ShapeHandlePolygonVertex, ShapeHandlePoint, ShapeHandleCircleRadius, ShapeHandleCircleCenter: diff --git a/packages/game/editor/spec_panel_ui.go b/packages/game/editor/spec_panel_ui.go index ff609c36e..64b7f19f4 100644 --- a/packages/game/editor/spec_panel_ui.go +++ b/packages/game/editor/spec_panel_ui.go @@ -8,20 +8,20 @@ import ( ) const ( - specSpace4 core.Points = 4 - specSpace8 core.Points = 8 - specSpace12 core.Points = 12 - specSpace16 core.Points = 16 - specSpace24 core.Points = 24 - - specRadiusControl core.Points = 6 - specRadiusButton core.Points = 8 - specRadiusCard core.Points = 12 - - specRowHeight core.Points = 28 - specButtonHeight core.Points = 30 - specHeaderHeight core.Points = 44 - specIconSize core.Points = 15 + specSpace4 = SpecSpace4 + specSpace8 = SpecSpace8 + specSpace12 = SpecSpace12 + specSpace16 = SpecSpace16 + specSpace24 = SpecSpace24 + + specRadiusControl = SpecRadiusControl + specRadiusButton = SpecRadiusButton + specRadiusCard = SpecRadiusCard + + specRowHeight = SpecRowHeight + specButtonHeight = SpecButtonHeight + specHeaderHeight = SpecHeaderHeight + specIconSize = SpecIconSize ) type specButtonVariant uint8 @@ -79,24 +79,15 @@ type specPanelRowButtonSpec struct { } func specHoverOverlay(p SpecPalette) core.Color { - if p.Dark { - return core.RGBA(0xFFFFFF, 0.06) - } - return core.RGBA(0x000000, 0.05) + return p.HoverOverlay } func specActiveOverlay(p SpecPalette) core.Color { - if p.Dark { - return core.RGBA(0xFFFFFF, 0.10) - } - return core.RGBA(0x000000, 0.09) + return p.ActiveOverlay } func specPrimaryHover(p SpecPalette) core.Color { - if p.Dark { - return core.RGB(0xD9DDE5) - } - return core.RGB(0x2B303B) + return p.PrimaryHover } // specShortcutTip formats a Spec tooltip string ("Name · shortcut") when shortcut is non-empty. @@ -381,7 +372,7 @@ func specPanelButton(p SpecPalette, b specPanelButtonSpec) core.Node { func specButtonColors(p SpecPalette, v specButtonVariant) (bg, hover, active, fg, border core.Color) { hov := specHoverOverlay(p) act := specActiveOverlay(p) - transparent := core.RGBA(0x000000, 0) + transparent := core.Color(0) switch v { case specBtnPrimary: // Spec contrast table: 18.75:1 AAA in Dark (#101216 on #FFFFFF) and Light (#FFFFFF on #101216). diff --git a/packages/game/editor/spec_theme.go b/packages/game/editor/spec_theme.go index 23bb3cc19..903928015 100644 --- a/packages/game/editor/spec_theme.go +++ b/packages/game/editor/spec_theme.go @@ -4,29 +4,109 @@ import ( _ "embed" "fmt" "math" + "time" "github.com/nsgo-dev/nsgo/core" + "github.com/nsgo-dev/nsgo/ui" ) //go:embed spec_theme.yaml var specThemeYAML []byte +// Typography tokens from docs/design/editor/Spec.dc.html ("Type, space, shape"). +const ( + SpecFontFamilySans = "Inter" + SpecFontFamilyMono = "JetBrains Mono" + + SpecFontTitleSize core.Points = 14 + SpecFontTitleWeight core.FontWeight = core.FontWeightSemibold // 600 + SpecFontBodySize core.Points = 12.5 + SpecFontBodyWeight core.FontWeight = core.FontWeightNormal // 400 + SpecFontSectionSize core.Points = 11 + SpecFontSectionWeight core.FontWeight = core.FontWeightSemibold // 600 + SpecFontSectionTrack core.Points = 0.66 // +6% tracking on 11 px + SpecFontCodeSize core.Points = 11.5 + SpecFontCodeWeight core.FontWeight = core.FontWeightNormal // 400 +) + +// Spacing scale tokens from docs/design/editor/Spec.dc.html: 4, 8, 12, 16, 24 px only. +const ( + SpecSpace4 core.Points = 4 + SpecSpace8 core.Points = 8 + SpecSpace12 core.Points = 12 + SpecSpace16 core.Points = 16 + SpecSpace24 core.Points = 24 +) + +// Corner radius tokens from docs/design/editor/Spec.dc.html. +const ( + SpecRadiusControl core.Points = 6 // Controls, inputs, tree rows, pills + SpecRadiusButton core.Points = 8 // Buttons + SpecRadiusCard core.Points = 12 // Cards, popovers, toasts + SpecRadiusDialog core.Points = 18 // Dialogs +) + +// Height, border, and icon geometry tokens from docs/design/editor/Spec.dc.html. +const ( + SpecRowHeight core.Points = 28 // Rows and tool buttons + SpecMinHitSize core.Points = 28 // Minimum interactive hit area (28 x 28) + SpecButtonHeight core.Points = 30 // Standard button height (30-32 px) + SpecButtonTallHeight core.Points = 32 // Tall button height (30-32 px) + SpecHeaderHeight core.Points = 44 // Header / toolbar height + SpecBorderWidth core.Points = 1 // 1 px inner borders in Line or LineRaised + SpecIconSize core.Points = 15 // Inline stroke icon size + SpecIconStrokeWidth float32 = 1.8 +) + +// Motion tokens from docs/design/editor/Spec.dc.html ("Motion"). +// All durations drop to 0 under Env.ReduceMotion (see SpecMotionDuration). +const ( + SpecMotionHover = 120 * time.Millisecond // Hover and press transitions + SpecMotionPanel = 180 * time.Millisecond // Panels, popovers, and toasts + SpecMotionOverlay = 240 * time.Millisecond // Agent change overlays fading in + SpecMotionAgentPulse = 1600 * time.Millisecond // Agent outline pulse (100% <-> 45% opacity) + + SpecAgentPulseMinOpacity float32 = 0.45 + SpecAgentPulseMaxOpacity float32 = 1.0 +) + +// SpecMotionDuration returns d when motion is enabled, or 0 when cx is non-nil and +// cx.Env().ReduceMotion() is true. +func SpecMotionDuration(cx *core.Scope, d time.Duration) time.Duration { + if cx != nil && cx.Env().ReduceMotion() { + return 0 + } + return d +} + +// SpecAgentPulseOpacity returns the Spec agent-working outline opacity in [0.45, 1.0] +// for elapsed time since the pulse began. Under Env.ReduceMotion it stays solid at 1.0. +func SpecAgentPulseOpacity(cx *core.Scope, elapsed time.Duration) float32 { + if cx != nil && cx.Env().ReduceMotion() { + return SpecAgentPulseMaxOpacity + } + if SpecMotionAgentPulse <= 0 { + return SpecAgentPulseMaxOpacity + } + phase := float64(elapsed%SpecMotionAgentPulse) / float64(SpecMotionAgentPulse) + t := 0.5 * (1 + math.Cos(2*math.Pi*phase)) + return SpecAgentPulseMinOpacity + float32(t)*(SpecAgentPulseMaxOpacity-SpecAgentPulseMinOpacity) +} + var ( - parsedSpecTheme *core.Theme - darkSpecPalette SpecPalette - lightSpecPalette SpecPalette + parsedSpecTheme, darkSpecPalette, lightSpecPalette = loadSpecTheme() ) -func init() { +func loadSpecTheme() (*core.Theme, SpecPalette, SpecPalette) { th, err := core.ParseTheme(specThemeYAML) if err != nil { panic(fmt.Sprintf("editor: parse embedded spec_theme.yaml: %v", err)) } - parsedSpecTheme = th - darkSpecPalette = extractSpecPalette(&th.Dark, true) - lightSpecPalette = extractSpecPalette(&th.Light, false) - th.Dark.SetColor("ring", darkSpecPalette.Accent.Edge) - th.Light.SetColor("ring", lightSpecPalette.Accent.Edge) + dark := extractSpecPalette(&th.Dark, true) + light := extractSpecPalette(&th.Light, false) + th.Dark.SetColor("ring", dark.Accent.Edge) + th.Light.SetColor("ring", light.Accent.Edge) + return th, dark, light } // SpecRole holds the coordinated colors for a semantic Spec token role @@ -76,6 +156,16 @@ type SpecPalette struct { Changed SpecRole // Edited objects and values; dashed. Removed SpecRole // Deleted objects and problems/errors; solid. Warning SpecRole // Permission asks, waiting, warning toasts (with dedicated Fill and Edge). + + // Surface interaction overlays and 3D viewport / axis tokens (docs/design/editor/Viewport3D.dc.html). + HoverOverlay core.Color // Subtle hover wash over surfaces (`surfaceHover`). + ActiveOverlay core.Color // Subtle pressed wash over surfaces (`surfacePressed`). + PrimaryHover core.Color // Hover fill for solid TextPrimary buttons (`specPrimaryHover`). + Viewport3DGround core.Color // 3D viewport ground plane (`specViewport3DGround`). + Viewport3DGrid core.Color // 3D viewport grid line (`specViewport3DGrid`). + AxisX core.Color // 3D X axis token (`specAxisX`, #FF6B6B dark / #C92A2A light). + AxisY core.Color // 3D Y axis token (`specAxisY`, #4FD38A dark / #0D7A43 light). + AxisZ core.Color // 3D Z axis token (`specAxisZ`, #3B7BFF dark / #1D5CE6 light). } // Problem returns the semantic role shared by removed objects and problems/errors (Spec `removed · problem`). @@ -125,9 +215,27 @@ func (e *Editor) SpecPalette(cx *core.Scope) SpecPalette { if cx != nil { return SpecPaletteFor(cx.Dark()) } + return e.activeSpecPalette() +} + +// activeSpecPalette returns the active SpecPalette for e, defaulting to dark when e is nil. +func (e *Editor) activeSpecPalette() SpecPalette { + if e == nil { + return darkSpecPalette + } return SpecPaletteFor(e.Dark()) } +// specAlpha returns c with opacity a clamped to [0, 1]. +func specAlpha(c core.Color, a float32) core.Color { + return ui.Alpha(c, a) +} + +// colorFromRGBA8 packs dynamic raster pixel or computed data channels into a core.Color. +func colorFromRGBA8(r, g, b, a uint8) core.Color { + return core.Color(uint32(r)<<24 | uint32(g)<<16 | uint32(b)<<8 | uint32(a)) +} + func mustPaletteColor(p *core.Palette, name string) core.Color { c, ok := p.Color(name) if !ok || c == 0 { @@ -146,27 +254,35 @@ func extractSpecPalette(p *core.Palette, dark bool) SpecPalette { } } return SpecPalette{ - Dark: dark, - Bg: mustPaletteColor(p, "specBg"), - Panel: mustPaletteColor(p, "specPanel"), - Raised: mustPaletteColor(p, "specRaised"), - Inset: mustPaletteColor(p, "specInset"), - Viewport: mustPaletteColor(p, "specViewport"), - ViewportDot: mustPaletteColor(p, "specViewportDot"), - PillBg: mustPaletteColor(p, "specPillBg"), - Line: mustPaletteColor(p, "specLine"), - LineRaised: mustPaletteColor(p, "specLineRaised"), - TextPrimary: mustPaletteColor(p, "specTextPrimary"), - TextSecondary: mustPaletteColor(p, "specTextSecondary"), - TextMuted: mustPaletteColor(p, "specTextMuted"), - TextFaint: mustPaletteColor(p, "specTextFaint"), - OnTextPrimary: mustPaletteColor(p, "specOnTextPrimary"), - Accent: role("specAccent"), - Agent: role("specAgent"), - Added: role("specAdded"), - Changed: role("specChanged"), - Removed: role("specRemoved"), - Warning: role("specWarning"), + Dark: dark, + Bg: mustPaletteColor(p, "specBg"), + Panel: mustPaletteColor(p, "specPanel"), + Raised: mustPaletteColor(p, "specRaised"), + Inset: mustPaletteColor(p, "specInset"), + Viewport: mustPaletteColor(p, "specViewport"), + ViewportDot: mustPaletteColor(p, "specViewportDot"), + PillBg: mustPaletteColor(p, "specPillBg"), + Line: mustPaletteColor(p, "specLine"), + LineRaised: mustPaletteColor(p, "specLineRaised"), + TextPrimary: mustPaletteColor(p, "specTextPrimary"), + TextSecondary: mustPaletteColor(p, "specTextSecondary"), + TextMuted: mustPaletteColor(p, "specTextMuted"), + TextFaint: mustPaletteColor(p, "specTextFaint"), + OnTextPrimary: mustPaletteColor(p, "specOnTextPrimary"), + Accent: role("specAccent"), + Agent: role("specAgent"), + Added: role("specAdded"), + Changed: role("specChanged"), + Removed: role("specRemoved"), + Warning: role("specWarning"), + HoverOverlay: p.SurfaceHover, + ActiveOverlay: p.SurfacePressed, + PrimaryHover: mustPaletteColor(p, "specPrimaryHover"), + Viewport3DGround: mustPaletteColor(p, "specViewport3DGround"), + Viewport3DGrid: mustPaletteColor(p, "specViewport3DGrid"), + AxisX: mustPaletteColor(p, "specAxisX"), + AxisY: mustPaletteColor(p, "specAxisY"), + AxisZ: mustPaletteColor(p, "specAxisZ"), } } @@ -289,5 +405,10 @@ func SpecContrastTable(p SpecPalette) []SpecContrastPair { {Name: "added edge on viewport", Foreground: p.Added.Edge, Background: p.Viewport, MinRatio: 3.0, Usage: "Added dashed outline on viewport surround"}, {Name: "changed edge on viewport", Foreground: p.Changed.Edge, Background: p.Viewport, MinRatio: 3.0, Usage: "Changed dashed outline on viewport surround"}, {Name: "removed edge on viewport", Foreground: p.Removed.Edge, Background: p.Viewport, MinRatio: 3.0, Usage: "Removed/problem outline on viewport surround"}, + + // 3D viewport axis tokens from docs/design/editor/Viewport3D.dc.html (WCAG 2.2 3:1). + {Name: "3D axis X on viewport", Foreground: p.AxisX, Background: p.Viewport, MinRatio: 3.0, Usage: "3D X gizmo, axis widget, and transform X label"}, + {Name: "3D axis Y on viewport", Foreground: p.AxisY, Background: p.Viewport, MinRatio: 3.0, Usage: "3D Y gizmo, axis widget, and transform Y label"}, + {Name: "3D axis Z on viewport", Foreground: p.AxisZ, Background: p.Viewport, MinRatio: 3.0, Usage: "3D Z gizmo, axis widget, and transform Z label"}, } } diff --git a/packages/game/editor/spec_theme.yaml b/packages/game/editor/spec_theme.yaml index 35bdc49d5..8cf4eb0c9 100644 --- a/packages/game/editor/spec_theme.yaml +++ b/packages/game/editor/spec_theme.yaml @@ -69,6 +69,12 @@ dark: specWarningFill: "#2A2414" specWarningEdge: "#4A3F1F" specWarningOnFill: "#101216" + specPrimaryHover: "#D9DDE5" + specViewport3DGround: "#1D2129" + specViewport3DGrid: "#2B313B" + specAxisX: "#FF6B6B" + specAxisY: "#4FD38A" + specAxisZ: "#3B7BFF" light: background: "#EEF1F6" surface: "#F6F7FA" @@ -139,3 +145,9 @@ light: specWarningFill: "#FDF4DC" specWarningEdge: "#C99A2E" specWarningOnFill: "#FFFFFF" + specPrimaryHover: "#2B303B" + specViewport3DGround: "#DCE2EC" + specViewport3DGrid: "#C4CCD9" + specAxisX: "#C92A2A" + specAxisY: "#0D7A43" + specAxisZ: "#1D5CE6" diff --git a/packages/game/editor/spec_theme_test.go b/packages/game/editor/spec_theme_test.go index a63f7fa98..98069df46 100644 --- a/packages/game/editor/spec_theme_test.go +++ b/packages/game/editor/spec_theme_test.go @@ -1,9 +1,17 @@ package editor_test import ( + "go/ast" + "go/parser" + "go/token" + "io/fs" "math" + "path/filepath" + "regexp" + "strconv" "strings" "testing" + "time" "github.com/nsgo-dev/game/packages/game/editor" "github.com/nsgo-dev/nsgo/core" @@ -83,6 +91,15 @@ func TestSpecThemeParsesAndMapsAllRoles(t *testing.T) { if tc.p.Surface != tc.spec.Panel { t.Errorf("%s Palette.Surface = #%08X, want #%08X", tc.name, uint32(tc.p.Surface), uint32(tc.spec.Panel)) } + if raised, ok := tc.p.Color("raised"); !ok || raised != tc.spec.Raised { + t.Errorf("%s Palette.Color(raised) = #%08X (ok=%v), want #%08X", tc.name, uint32(raised), ok, uint32(tc.spec.Raised)) + } + if line, ok := tc.p.Color("line"); !ok || line != tc.spec.Line { + t.Errorf("%s Palette.Color(line) = #%08X (ok=%v), want #%08X", tc.name, uint32(line), ok, uint32(tc.spec.Line)) + } + if tc.p.Border != tc.spec.LineRaised { + t.Errorf("%s Palette.Border = #%08X, want #%08X", tc.name, uint32(tc.p.Border), uint32(tc.spec.LineRaised)) + } if tc.p.Text != tc.spec.TextSecondary { t.Errorf("%s Palette.Text = #%08X, want #%08X", tc.name, uint32(tc.p.Text), uint32(tc.spec.TextSecondary)) } @@ -594,3 +611,296 @@ func TestSpecLightChromeOverlaysAndMarqueeContrast(t *testing.T) { } } } + +func TestSpecDesignTokenConstantsAndReducedMotion(t *testing.T) { + if editor.SpecFontFamilySans != "Inter" || editor.SpecFontFamilyMono != "JetBrains Mono" { + t.Fatalf("font families = (%q, %q), want (Inter, JetBrains Mono)", editor.SpecFontFamilySans, editor.SpecFontFamilyMono) + } + if editor.SpecFontTitleSize != 14 || editor.SpecFontTitleWeight != core.FontWeightSemibold { + t.Fatalf("title type = %v/%v, want 14/600", editor.SpecFontTitleSize, editor.SpecFontTitleWeight) + } + if editor.SpecFontBodySize != 12.5 || editor.SpecFontBodyWeight != core.FontWeightNormal { + t.Fatalf("body type = %v/%v, want 12.5/400", editor.SpecFontBodySize, editor.SpecFontBodyWeight) + } + if editor.SpecFontSectionSize != 11 || editor.SpecFontSectionWeight != core.FontWeightSemibold || math.Abs(float64(editor.SpecFontSectionTrack)-0.66) > 1e-6 { + t.Fatalf("section type = %v/%v/+%v, want 11/600/+0.66 (+6%%)", editor.SpecFontSectionSize, editor.SpecFontSectionWeight, editor.SpecFontSectionTrack) + } + if editor.SpecFontCodeSize != 11.5 || editor.SpecFontCodeWeight != core.FontWeightNormal { + t.Fatalf("code type = %v/%v, want 11.5/400", editor.SpecFontCodeSize, editor.SpecFontCodeWeight) + } + if editor.SpecSpace4 != 4 || editor.SpecSpace8 != 8 || editor.SpecSpace12 != 12 || editor.SpecSpace16 != 16 || editor.SpecSpace24 != 24 { + t.Fatalf("spacing scale = %v,%v,%v,%v,%v, want 4,8,12,16,24", + editor.SpecSpace4, editor.SpecSpace8, editor.SpecSpace12, editor.SpecSpace16, editor.SpecSpace24) + } + if editor.SpecRadiusControl != 6 || editor.SpecRadiusButton != 8 || editor.SpecRadiusCard != 12 || editor.SpecRadiusDialog != 18 { + t.Fatalf("radii = %v,%v,%v,%v, want 6,8,12,18", + editor.SpecRadiusControl, editor.SpecRadiusButton, editor.SpecRadiusCard, editor.SpecRadiusDialog) + } + if editor.SpecRowHeight != 28 || editor.SpecMinHitSize != 28 || editor.SpecButtonHeight != 30 || editor.SpecButtonTallHeight != 32 || editor.SpecHeaderHeight != 44 { + t.Fatalf("heights = row:%v hit:%v btn:%v btnTall:%v header:%v", + editor.SpecRowHeight, editor.SpecMinHitSize, editor.SpecButtonHeight, editor.SpecButtonTallHeight, editor.SpecHeaderHeight) + } + if editor.SpecBorderWidth != 1 || editor.SpecIconSize != 15 || math.Abs(float64(editor.SpecIconStrokeWidth)-1.8) > 1e-6 { + t.Fatalf("border/icon = border:%v icon:%v stroke:%v", editor.SpecBorderWidth, editor.SpecIconSize, editor.SpecIconStrokeWidth) + } + if editor.SpecMotionHover != 120*time.Millisecond || + editor.SpecMotionPanel != 180*time.Millisecond || + editor.SpecMotionOverlay != 240*time.Millisecond || + editor.SpecMotionAgentPulse != 1600*time.Millisecond { + t.Fatalf("motion = hover:%v panel:%v overlay:%v pulse:%v", + editor.SpecMotionHover, editor.SpecMotionPanel, editor.SpecMotionOverlay, editor.SpecMotionAgentPulse) + } + + // Verify 3D axis tokens match docs/design/editor/Viewport3D.dc.html. + dark := editor.DarkSpecPalette() + if dark.AxisX != core.RGB(0xFF6B6B) || dark.AxisY != core.RGB(0x4FD38A) || dark.AxisZ != core.RGB(0x3B7BFF) { + t.Fatalf("dark 3D axes = (#%06X, #%06X, #%06X), want (#FF6B6B, #4FD38A, #3B7BFF)", + uint32(dark.AxisX)>>8, uint32(dark.AxisY)>>8, uint32(dark.AxisZ)>>8) + } + + // Verify motion disables cleanly under Env.ReduceMotion. + var normalHover, reducedHover time.Duration + var normalMidPulse, reducedMidPulse float32 + app := nsgotest.Start(t, func(cx *core.Scope) core.Node { + cx.Effect(func() { + if cx.Env().ReduceMotion() { + reducedHover = editor.SpecMotionDuration(cx, editor.SpecMotionHover) + reducedMidPulse = editor.SpecAgentPulseOpacity(cx, editor.SpecMotionAgentPulse/2) + } else { + normalHover = editor.SpecMotionDuration(cx, editor.SpecMotionHover) + normalMidPulse = editor.SpecAgentPulseOpacity(cx, editor.SpecMotionAgentPulse/2) + } + }) + return core.View{} + }, nsgotest.Environment(core.Environment{OS: core.OSMacOS, Idiom: core.IdiomDesktop, Dark: true, ReduceMotion: false})) + + if normalHover != 120*time.Millisecond { + t.Fatalf("normal SpecMotionDuration(Hover) = %v, want 120ms", normalHover) + } + if math.Abs(float64(normalMidPulse-0.45)) > 0.01 { + t.Fatalf("normal SpecAgentPulseOpacity(800ms) = %v, want 0.45", normalMidPulse) + } + + app.SetEnvironment(core.Environment{OS: core.OSMacOS, Idiom: core.IdiomDesktop, Dark: true, ReduceMotion: true}) + if reducedHover != 0 { + t.Fatalf("ReduceMotion SpecMotionDuration(Hover) = %v, want 0", reducedHover) + } + if reducedMidPulse != 1.0 { + t.Fatalf("ReduceMotion SpecAgentPulseOpacity(800ms) = %v, want 1.0", reducedMidPulse) + } +} + +// #1002 Acceptance 1: Setting dark text_muted back to the retired #6F7684 causes the +// theme-file WCAG 2.2 contrast table check to fail below 4.5:1. +func TestSpecContrastTableRejectsRetiredMutedColor(t *testing.T) { + raw := string(editor.SpecThemeYAML()) + mutated := strings.Replace(raw, `specTextFaint: "#8B92A0"`, `specTextFaint: "#6F7684"`, 1) + if mutated == raw { + t.Fatal("failed to locate dark specTextFaint in spec_theme.yaml") + } + th, err := core.ParseTheme([]byte(mutated)) + if err != nil { + t.Fatalf("core.ParseTheme(mutated): %v", err) + } + retired, ok := th.Dark.Color("specTextFaint") + if !ok || retired != core.RGB(0x6F7684) { + t.Fatalf("mutated specTextFaint = #%06X (ok=%v), want #6F7684", uint32(retired)>>8, ok) + } + + pal := editor.DarkSpecPalette() + pal.TextFaint = retired + + failed := 0 + for _, row := range editor.SpecContrastTable(pal) { + if row.Ratio() < row.MinRatio { + failed++ + } + } + if failed == 0 { + t.Fatal("expected SpecContrastTable to fail when dark text_muted is reverted to #6F7684") + } +} + +// #1002 Acceptance 2: Every non-test Go file in packages/game/editor outside spec_theme.go +// must use Spec theme tokens instead of core.RGB, core.RGBA, or hardcoded UI hex color literals. +// Scene content defaults (such as scene.BackgroundColor, sky/fog/light defaults, and hex input +// placeholders) stay scene data and are explicitly allowlisted below. +func TestSpecNoHardcodedColorLiteralsInEditor(t *testing.T) { + hexStringRe := regexp.MustCompile(`^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$`) + + // Explicit minimal allowlist for scene-content data defaults & hex input placeholders (never UI chrome). + allowedHexStringFiles := map[string]bool{ + "demo.go": true, // default demo scene BackgroundColor + "environment_panel.go": true, // default 3D sky/fog/directional-light scene data and hex placeholders + "first_run.go": true, // first-run starter scene BackgroundColor + "inspector_room.go": true, // room transition tint hex field placeholder + "inspector_scene.go": true, // scene BackgroundColor hex field placeholder + "materials_ui.go": true, // material albedo/emissive hex field placeholders + "scene3d_edit.go": true, // default 3D light scene data colors + "state.go": true, // default new scene BackgroundColor + } + allowedCoreColorHexFiles := map[string]bool{ + "particles.go": true, // default particle emitter ramp stop data + "particles_ui.go": true, // default new particle color stop data + } + + fset := token.NewFileSet() + var violations []string + + err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + if d.IsDir() { + if d.Name() == "testdata" { + return filepath.SkipDir + } + return nil + } + name := d.Name() + if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") { + return nil + } + if filepath.Clean(path) == "spec_theme.go" { + return nil + } + + file, parseErr := parser.ParseFile(fset, path, nil, 0) + if parseErr != nil { + t.Errorf("parse %s: %v", path, parseErr) + return nil + } + + ast.Inspect(file, func(n ast.Node) bool { + switch node := n.(type) { + case *ast.CallExpr: + if sel, ok := node.Fun.(*ast.SelectorExpr); ok { + if ident, ok := sel.X.(*ast.Ident); ok && ident.Name == "core" { + switch sel.Sel.Name { + case "RGB", "RGBA": + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden core."+sel.Sel.Name+" call outside spec_theme.go") + case "ParseColor": + if len(node.Args) == 1 { + if lit, ok := node.Args[0].(*ast.BasicLit); ok && lit.Kind == token.STRING { + if s, err := strconv.Unquote(lit.Value); err == nil && hexStringRe.MatchString(s) { + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden core.ParseColor("+lit.Value+") literal outside spec_theme.go") + } + } + } + case "Color": + if !allowedCoreColorHexFiles[filepath.ToSlash(path)] && len(node.Args) == 1 { + if lit, ok := node.Args[0].(*ast.BasicLit); ok && lit.Kind == token.INT && strings.HasPrefix(strings.ToLower(lit.Value), "0x") && lit.Value != "0x0" { + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden core.Color("+lit.Value+") literal outside spec_theme.go") + } + } + } + } + } + case *ast.BasicLit: + if node.Kind == token.STRING && !allowedHexStringFiles[filepath.ToSlash(path)] { + if s, err := strconv.Unquote(node.Value); err == nil && hexStringRe.MatchString(s) { + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden hex color literal "+node.Value+" outside spec_theme.go") + } + } + } + return true + }) + return nil + }) + if err != nil { + t.Fatalf("WalkDir: %v", err) + } + if len(violations) > 0 { + t.Fatalf("found %d hardcoded color literal(s) outside spec_theme.go:\n%s", len(violations), strings.Join(violations, "\n")) + } +} + +// #1002 Acceptance 3: Toolbar, panels, inspector, viewport surround, and status bar render in +// Spec bg, panel, raised, and line tokens, toolbar title is 14/600, and the selection outline is accent. +func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { + ed := newTestEditor(t) + ed.SelectObject("hero") + + app := nsgotest.Start(t, func(cx *core.Scope) core.Node { + return editor.EditorView(cx, ed) + }, nsgotest.Size(1280, 800), nsgotest.Environment(core.Environment{ + OS: core.OSMacOS, + Idiom: core.IdiomDesktop, + Dark: true, + Locale: "en-US", + })) + + verifyMode := func(label string, want editor.SpecPalette) { + t.Helper() + if got := app.Find("id:scene-editor").Style.Background; got != want.Bg { + t.Errorf("%s: root bg = #%06X, want Bg #%06X", label, uint32(got)>>8, uint32(want.Bg)>>8) + } + tb := app.Find("id:editor-toolbar").Style + if tb.Background != want.Raised || tb.BorderColors.Bottom != want.Line { + t.Errorf("%s: toolbar bg=#%06X bottomBorder=#%06X, want Raised=#%06X Line=#%06X", + label, uint32(tb.Background)>>8, uint32(tb.BorderColors.Bottom)>>8, uint32(want.Raised)>>8, uint32(want.Line)>>8) + } + title := app.Find("id:toolbar-scene-name").TextStyle + if title.Font.Size != editor.SpecFontTitleSize || title.Font.Weight != editor.SpecFontTitleWeight || title.Color != want.TextPrimary { + t.Errorf("%s: toolbar title = %v/%v/#%06X, want 14/600/#%06X", + label, title.Font.Size, title.Font.Weight, uint32(title.Color)>>8, uint32(want.TextPrimary)>>8) + } + if got := app.Find("id:editor-viewport-container").Style.Background; got != want.Viewport { + t.Errorf("%s: viewport surround = #%06X, want Viewport #%06X", label, uint32(got)>>8, uint32(want.Viewport)>>8) + } + st := app.Find("id:scene-tree-panel").Style + if st.Background != want.Panel || st.BorderColors.Right != want.Line { + t.Errorf("%s: scene-tree-panel bg=#%06X rightBorder=#%06X, want Panel=#%06X Line=#%06X", + label, uint32(st.Background)>>8, uint32(st.BorderColors.Right)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + } + lp := app.Find("id:layers-panel").Style + if lp.Background != want.Panel || lp.BorderColors.Top != want.Line || lp.BorderColors.Right != want.Line { + t.Errorf("%s: layers-panel bg=#%06X topBorder=#%06X rightBorder=#%06X, want Panel=#%06X Line=#%06X", + label, uint32(lp.Background)>>8, uint32(lp.BorderColors.Top)>>8, uint32(lp.BorderColors.Right)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + } + ab := app.Find("id:asset-browser").Style + if ab.Background != want.Panel || ab.BorderColors.Right != want.Line { + t.Errorf("%s: asset-browser bg=#%06X rightBorder=#%06X, want Panel=#%06X Line=#%06X", + label, uint32(ab.Background)>>8, uint32(ab.BorderColors.Right)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + } + insp := app.Find("id:editor-inspector").Style + if insp.Background != want.Panel || insp.BorderColors.Left != want.Line { + t.Errorf("%s: editor-inspector bg=#%06X leftBorder=#%06X, want Panel=#%06X Line=#%06X", + label, uint32(insp.Background)>>8, uint32(insp.BorderColors.Left)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + } + sb := app.Find("id:editor-status").Style + if sb.Background != want.Raised || sb.BorderColors.Top != want.Line { + t.Errorf("%s: status bar bg=#%06X topBorder=#%06X, want Raised=#%06X Line=#%06X", + label, uint32(sb.Background)>>8, uint32(sb.BorderColors.Top)>>8, uint32(want.Raised)>>8, uint32(want.Line)>>8) + } + + // Verify the 2D selection outline strokes in Spec Accent.Edge. + cw, ch := ed.CanvasSize() + d := &core.Drawing{} + ed.DrawViewport(d, core.Size{Width: core.Points(cw), Height: core.Points(ch)}) + foundAccentStroke := false + for _, op := range d.Ops { + if op.Kind == core.DrawStrokeColor && op.Color == want.Accent.Edge { + foundAccentStroke = true + break + } + } + if !foundAccentStroke { + t.Errorf("%s: 2D viewport selection did not stroke with Accent.Edge #%06X", label, uint32(want.Accent.Edge)>>8) + } + } + + verifyMode("dark", editor.DarkSpecPalette()) + + app.SetEnvironment(core.Environment{ + OS: core.OSMacOS, + Idiom: core.IdiomDesktop, + Dark: false, + Locale: "en-US", + }) + verifyMode("light", editor.LightSpecPalette()) +} diff --git a/packages/game/editor/start_screen_ui.go b/packages/game/editor/start_screen_ui.go index 57d918728..02c821141 100644 --- a/packages/game/editor/start_screen_ui.go +++ b/packages/game/editor/start_screen_ui.go @@ -12,47 +12,50 @@ import ( // Additional Spec.dc.html color tokens used by the Start Screen (shared tokens live in profiler_ui.go). var ( - specAccentTint = core.RGBA(0x3B7BFF, 0.18) - specRemoved = mustSpecColor("#FF6B6B") + specAccentTint = specAlpha(darkSpecPalette.Accent.Fg, 0.18) + specRemoved = darkSpecPalette.Removed.Fg ) -func mustSpecColor(hex string) core.Color { - c, err := core.ParseColor(hex) - if err != nil { - panic(err) - } - return c -} - -// templateSwatchColor returns a restrained, dark-theme card preview tint derived from the template name. +// templateSwatchColor returns a restrained, dark-theme card preview tint composed strictly from Spec tokens. func templateSwatchColor(name string) core.Color { - swatches := map[string]string{ - "starter": "#262B35", - "platformer2d": "#253856", - "rpg2d": "#2D4533", - "shmup2d": "#482A3E", - "fighting2d": "#543329", - "racing3d": "#294156", - "fps3d": "#3D334D", - "action3d": "#31423F", - "puzzle2d": "#4A432D", - "cards2d": "#422E2E", - "rts2d": "#2B3F34", - "roguelike2d": "#342D45", - "towerdefense2d": "#423F29", - "idle": "#284242", - "visualnovel": "#4A3342", - "rhythm": "#2D384B", + base := darkSpecPalette.Raised + swatch := func(role core.Color, alpha float32) core.Color { + return CompositeOver(specAlpha(role, alpha), base) + } + swatches := map[string]core.Color{ + "starter": darkSpecPalette.LineRaised, + "platformer2d": swatch(darkSpecPalette.Accent.Fg, 0.24), + "rpg2d": swatch(darkSpecPalette.Added.Fg, 0.22), + "shmup2d": swatch(darkSpecPalette.Removed.Fg, 0.22), + "fighting2d": swatch(darkSpecPalette.Changed.Fg, 0.24), + "racing3d": swatch(darkSpecPalette.Accent.Fg, 0.20), + "fps3d": swatch(darkSpecPalette.Agent.Fg, 0.22), + "action3d": swatch(darkSpecPalette.Added.Fg, 0.18), + "puzzle2d": swatch(darkSpecPalette.Warning.Fg, 0.20), + "cards2d": swatch(darkSpecPalette.Removed.Fg, 0.18), + "rts2d": swatch(darkSpecPalette.Added.Fg, 0.20), + "roguelike2d": swatch(darkSpecPalette.Agent.Fg, 0.18), + "towerdefense2d": swatch(darkSpecPalette.Warning.Fg, 0.18), + "idle": swatch(darkSpecPalette.Added.Fg, 0.16), + "visualnovel": swatch(darkSpecPalette.Agent.Fg, 0.24), + "rhythm": swatch(darkSpecPalette.Accent.Fg, 0.18), + } + if col, ok := swatches[strings.ToLower(name)]; ok { + return col } - if hex, ok := swatches[strings.ToLower(name)]; ok { - return mustSpecColor(hex) + palette := []core.Color{ + darkSpecPalette.LineRaised, + swatch(darkSpecPalette.Accent.Fg, 0.24), + swatch(darkSpecPalette.Added.Fg, 0.22), + swatch(darkSpecPalette.Agent.Fg, 0.22), + swatch(darkSpecPalette.Changed.Fg, 0.20), + swatch(darkSpecPalette.Warning.Fg, 0.20), } - palette := []string{"#262B35", "#253856", "#2D4533", "#3D334D", "#31423F", "#4A432D"} sum := 0 for i := range len(name) { sum += int(name[i]) } - return mustSpecColor(palette[sum%len(palette)]) + return palette[sum%len(palette)] } // StartScreenView renders the editor's Start Screen matching Start.dc.html, step 1 of FirstRun.dc.html, diff --git a/packages/game/editor/states_ui.go b/packages/game/editor/states_ui.go index 7cf930dec..078138757 100644 --- a/packages/game/editor/states_ui.go +++ b/packages/game/editor/states_ui.go @@ -13,13 +13,13 @@ import ( // Additional Spec color tokens for docs/design/editor/Animation.dc.html (shared specPanel/specRaised/etc. live in profiler_ui.go). var ( - specBG = core.RGBA(0x101216, 1) - specActiveNode = core.RGBA(0x1A2030, 1) - specViewportBG = core.RGBA(0x15181D, 1) - specViewportDot = core.RGBA(0x2A2F38, 1) - specEdgeLine = core.RGBA(0x4A5262, 1) - specAccentText = core.RGBA(0xB9CFFF, 1) - specFloorFill = core.RGBA(0x2A2F3A, 1) + specBG = darkSpecPalette.Bg + specActiveNode = CompositeOver(specAlpha(darkSpecPalette.Accent.Fg, 0.12), darkSpecPalette.Raised) + specViewportBG = darkSpecPalette.Viewport + specViewportDot = darkSpecPalette.ViewportDot + specEdgeLine = CompositeOver(specAlpha(darkSpecPalette.TextFaint, 0.45), darkSpecPalette.Viewport) + specAccentText = CompositeOver(specAlpha(darkSpecPalette.TextPrimary, 0.62), darkSpecPalette.Accent.Fg) + specFloorFill = darkSpecPalette.LineRaised ) const ( diff --git a/packages/game/editor/terrain.go b/packages/game/editor/terrain.go index 1eb4efcbc..779167eef 100644 --- a/packages/game/editor/terrain.go +++ b/packages/game/editor/terrain.go @@ -1582,23 +1582,24 @@ func (e *Editor) ClearTerrainHover() { e.notify() } -// terrainLayerPreviewColors gives distinct visual tints for up to 8 terrain layers +// terrainLayerPreviewColors gives distinct visual tints from spec_theme.yaml for up to 8 terrain layers // in the 3D viewport wireframe when a layer has no explicit RGB tint. var terrainLayerPreviewColors = [8]core.Color{ - core.RGBA(0x4ADE80, 0.85), // grass green - core.RGBA(0xB45309, 0.85), // dirt brown - core.RGBA(0x94A3B8, 0.85), // rock slate - core.RGBA(0xF8FAFC, 0.90), // snow white - core.RGBA(0xFBBF24, 0.85), // sand amber - core.RGBA(0x78716C, 0.85), // mud warm gray - core.RGBA(0xA8A29E, 0.85), // gravel - core.RGBA(0x38BDF8, 0.85), // ice sky + specAlpha(darkSpecPalette.Added.Fg, 0.85), + specAlpha(darkSpecPalette.Changed.Fg, 0.85), + specAlpha(darkSpecPalette.TextFaint, 0.85), + specAlpha(darkSpecPalette.TextPrimary, 0.90), + specAlpha(darkSpecPalette.Warning.Fg, 0.85), + specAlpha(darkSpecPalette.TextMuted, 0.85), + specAlpha(darkSpecPalette.Agent.Fg, 0.85), + specAlpha(darkSpecPalette.Accent.Fg, 0.85), } func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { if !e.TerrainOpen() { return } + spec := e.activeSpecPalette() t := e.terrain hm := t.hm if hm.Cols < 2 || hm.Rows < 2 { @@ -1612,10 +1613,10 @@ func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { layerColors := make([]core.Color, len(t.doc.Layers)) for i, l := range t.doc.Layers { if l.Color != nil { - r := uint32(clamp01f32(l.Color[0]) * 255) - g := uint32(clamp01f32(l.Color[1]) * 255) - b := uint32(clamp01f32(l.Color[2]) * 255) - layerColors[i] = core.RGBA(r<<16|g<<8|b, 0.85) + r := uint8(clamp01f32(l.Color[0]) * 255) + g := uint8(clamp01f32(l.Color[1]) * 255) + b := uint8(clamp01f32(l.Color[2]) * 255) + layerColors[i] = specAlpha(colorFromRGBA8(r, g, b, 255), 0.85) } else { layerColors[i] = terrainLayerPreviewColors[i%len(terrainLayerPreviewColors)] } @@ -1675,7 +1676,7 @@ func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { if dens, ok := hm.FoliageDensityAt(flName, p[0], p[2]); ok && dens > 0.05 { if sx, sy, _, vis := e.Camera3D.Project(p, w, h); vis { rad := float32(1.5 + 2.5*dens) - d.Save().SetFillColor(core.RGBA(0x22C55E, float32(0.35+0.6*dens))). + d.Save().SetFillColor(specAlpha(spec.Added.Fg, float32(0.35+0.6*dens))). BeginPath().Arc(sx, sy, rad, 0, float32(2*math.Pi), false).Fill().Restore() } } @@ -1689,14 +1690,14 @@ func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { const ringSteps = 32 radius := e.terrainBrush.effectiveRadius() center := t.hoverPos - ringColor := core.RGBA(0x38BDF8, 0.95) + ringColor := specAlpha(spec.Accent.Fg, 0.95) switch e.terrainBrush.Mode { case TerrainBrushLower: - ringColor = core.RGBA(0xF87171, 0.95) + ringColor = specAlpha(spec.Removed.Fg, 0.95) case TerrainBrushPaintFoliage: - ringColor = core.RGBA(0x22C55E, 0.95) + ringColor = specAlpha(spec.Added.Fg, 0.95) case TerrainBrushPaintLayer: - ringColor = core.RGBA(0xFBBF24, 0.95) + ringColor = specAlpha(spec.Warning.Fg, 0.95) } ringPt := func(i int) [3]float32 { a := (2 * math.Pi * float64(i)) / ringSteps diff --git a/packages/game/editor/tile_review.go b/packages/game/editor/tile_review.go index 91b192173..eb213fafd 100644 --- a/packages/game/editor/tile_review.go +++ b/packages/game/editor/tile_review.go @@ -2325,20 +2325,21 @@ func (e *Editor) drawTileReviewOverlay(d *core.Drawing) { } var lineColor, fillColor core.Color dashed := true + pal := e.activeSpecPalette() switch r.Kind { case TileReviewPainted: - lineColor = specAdded - fillColor = core.RGBA(0x4FD38A, 0.16) + lineColor = pal.Added.Fg + fillColor = specAlpha(pal.Added.Fg, 0.16) case TileReviewReplaced: - lineColor = specChanged - fillColor = core.RGBA(0xE9A84A, 0.16) + lineColor = pal.Changed.Fg + fillColor = specAlpha(pal.Changed.Fg, 0.16) case TileReviewErased: - lineColor = specProblem - fillColor = core.RGBA(0xFF6B6B, 0.18) + lineColor = pal.Removed.Fg + fillColor = specAlpha(pal.Removed.Fg, 0.18) dashed = false default: - lineColor = specAccent - fillColor = core.RGBA(0x3B7BFF, 0.16) + lineColor = pal.Accent.Fg + fillColor = specAlpha(pal.Accent.Fg, 0.16) } for _, c := range r.Cells { @@ -2354,7 +2355,7 @@ func (e *Editor) drawTileReviewOverlay(d *core.Drawing) { if r.ID == rev.focusedID && len(perimeter) > 0 { d.SetLineDash() - d.SetStrokeColor(core.RGBA(0x3B7BFF, 0.45)).SetLineWidth(4 / scale) + d.SetStrokeColor(specAlpha(pal.Accent.Fg, 0.45)).SetLineWidth(4 / scale) d.BeginPath() for _, s := range perimeter { d.MoveTo(ox+float32(s.c0)*tw, oy+float32(s.r0)*th). diff --git a/packages/game/editor/tile_review_ui.go b/packages/game/editor/tile_review_ui.go index 069f7dd6a..c4f8ae782 100644 --- a/packages/game/editor/tile_review_ui.go +++ b/packages/game/editor/tile_review_ui.go @@ -9,13 +9,13 @@ import ( ) var ( - tileReviewOverlayBg = core.RGBA(0x171A21, 0.92) - tileReviewCardFocusBg = core.RGB(0x1A2030) - tileReviewFocusEdge = core.RGB(0x2A3A5C) - tileReviewKeycapBg = core.RGB(0x20252F) - tileReviewKeycapEdge = core.RGB(0x2C3240) - tileReviewSegActiveBg = core.RGB(0x2A2F3A) - tileReviewStepDotBg = core.RGB(0x1F3A2B) + tileReviewOverlayBg = specAlpha(darkSpecPalette.Raised, 0.92) + tileReviewCardFocusBg = CompositeOver(specAlpha(darkSpecPalette.Accent.Fg, 0.12), darkSpecPalette.Raised) + tileReviewFocusEdge = CompositeOver(specAlpha(darkSpecPalette.Accent.Fg, 0.35), darkSpecPalette.LineRaised) + tileReviewKeycapBg = CompositeOver(specAlpha(darkSpecPalette.TextFaint, 0.08), darkSpecPalette.Raised) + tileReviewKeycapEdge = darkSpecPalette.LineRaised + tileReviewSegActiveBg = darkSpecPalette.LineRaised + tileReviewStepDotBg = darkSpecPalette.Added.Fill ) // viewportTileOverlays returns the 2D viewport floating overlays: diff --git a/packages/game/editor/tilebrush.go b/packages/game/editor/tilebrush.go index 91b2cbea5..999ca2de8 100644 --- a/packages/game/editor/tilebrush.go +++ b/packages/game/editor/tilebrush.go @@ -950,8 +950,8 @@ func (e *Editor) TilePreview() []TilePreviewCell { // Spec token colors for brush preview and selection overlays. var ( - previewAccentColor = core.RGBA(0x3B7BFF, 1) - previewEraseColor = core.RGBA(0xFF6B6B, 1) + previewAccentColor = darkSpecPalette.Accent.Fg + previewEraseColor = darkSpecPalette.Removed.Fg ) // drawTileSelectionOverlay draws a dashed marquee around the active TileSelection (or in-progress region select stroke). @@ -984,10 +984,11 @@ func (e *Editor) drawTileSelectionOverlay(d *core.Drawing) { y := float32(rect.Row0 * tm.TileHeight) w := float32(rect.Width() * tm.TileWidth) h := float32(rect.Height() * tm.TileHeight) + spec := e.activeSpecPalette() d.Save() applyAffine(d, m) - d.SetFillColor(core.RGBA(0x3B7BFF, 0.14)).FillRect(x, y, w, h) - d.SetStrokeColor(previewAccentColor).SetLineWidth(1.5/strokeScale(m)).SetLineDash(4/strokeScale(m), 3/strokeScale(m)).StrokeRect(x, y, w, h) + d.SetFillColor(specAlpha(spec.Accent.Fg, 0.14)).FillRect(x, y, w, h) + d.SetStrokeColor(spec.Accent.Edge).SetLineWidth(1.5/strokeScale(m)).SetLineDash(4/strokeScale(m), 3/strokeScale(m)).StrokeRect(x, y, w, h) d.Restore() } @@ -1016,16 +1017,17 @@ func (e *Editor) drawTilePreviewOverlay(d *core.Drawing) bool { p := e.TilePalette() pal = &p } + spec := e.activeSpecPalette() d.Save() applyAffine(d, m) for _, cell := range s.preview { x, y := float32(cell.Col)*tw, float32(cell.Row)*th if cell.Erase || cell.Tile == 0 { - d.SetFillColor(core.RGBA(0xFF6B6B, 0.25)).FillRect(x, y, tw, th) - d.SetStrokeColor(previewEraseColor).SetLineWidth(lw).StrokeRect(x, y, tw, th) + d.SetFillColor(specAlpha(spec.Removed.Fg, 0.25)).FillRect(x, y, tw, th) + d.SetStrokeColor(spec.Removed.Edge).SetLineWidth(lw).StrokeRect(x, y, tw, th) } else { e.drawGhostTileID(d, tm, cell.Tile, cell.Flip, x, y, pal) - d.SetStrokeColor(previewAccentColor).SetLineWidth(lw).StrokeRect(x, y, tw, th) + d.SetStrokeColor(spec.Accent.Edge).SetLineWidth(lw).StrokeRect(x, y, tw, th) } } d.Restore() @@ -1061,7 +1063,7 @@ func (e *Editor) drawStampHoverOverlay(d *core.Drawing, tm *sceneformat.TilemapD } x, y := float32(mc)*tw, float32(mr)*th if tid == 0 { - d.SetFillColor(core.RGBA(0xFF6B6B, 0.18)).FillRect(x, y, tw, th) + d.SetFillColor(specAlpha(e.activeSpecPalette().Removed.Fg, 0.18)).FillRect(x, y, tw, th) } else { e.drawGhostTileID(d, tm, tid, flip, x, y, pal) } diff --git a/packages/game/editor/tilebrush_test.go b/packages/game/editor/tilebrush_test.go index e019153f5..cef31a07b 100644 --- a/packages/game/editor/tilebrush_test.go +++ b/packages/game/editor/tilebrush_test.go @@ -91,7 +91,7 @@ func TestTileBrushRectangleFillErasePreviewAndUndo(t *testing.T) { if !slices.Equal(gridData(ed), before) || ed.History.Len() != 0 { t.Fatalf("rect preview mutated map or history before release: hist=%d", ed.History.Len()) } - if _, ok := hoverRect(drawn(ed).Ops, core.RGBA(0x3B7BFF, 1)); !ok { + if _, ok := hoverRect(drawn(ed).Ops, ed.SpecPalette(nil).Accent.Edge); !ok { t.Fatal("rect preview did not draw accent outline in viewport") } @@ -126,7 +126,7 @@ func TestTileBrushRectangleFillErasePreviewAndUndo(t *testing.T) { if got := ed.TilePreview(); len(got) != 4 || !got[0].Erase { t.Fatalf("rect erase preview = %+v, want 4 erase cells", got) } - if _, ok := hoverRect(drawn(ed).Ops, core.RGBA(0xFF6B6B, 1)); !ok { + if _, ok := hoverRect(drawn(ed).Ops, ed.SpecPalette(nil).Removed.Edge); !ok { t.Fatal("rect erase preview did not draw red outline in viewport") } ed.EndTileStroke() diff --git a/packages/game/editor/tilestroke.go b/packages/game/editor/tilestroke.go index 65d45dd66..4b1cccb9e 100644 --- a/packages/game/editor/tilestroke.go +++ b/packages/game/editor/tilestroke.go @@ -892,12 +892,12 @@ func (e *Editor) toolStrokeMode(secondary, alt bool) (TileStrokeMode, bool) { return 0, false } -// The hover outline's colors: sky for painting and filling, emerald for terrain, red for erasing, amber for picking. +// The hover outline's colors from spec_theme.yaml: accent for painting and filling, added for terrain, removed for erasing, warning for picking. var ( - hoverPaintColor = core.RGBA(0x38BDF8, 1) - hoverTerrainColor = core.RGBA(0x34D399, 1) - hoverEraseColor = core.RGBA(0xF87171, 1) - hoverPickColor = core.RGBA(0xFBBF24, 1) + hoverPaintColor = darkSpecPalette.Accent.Fg + hoverTerrainColor = darkSpecPalette.Added.Fg + hoverEraseColor = darkSpecPalette.Removed.Fg + hoverPickColor = darkSpecPalette.Warning.Fg ) // drawTileHoverOverlay draws the active tile selection marquee, any live brush preview under way, @@ -928,7 +928,8 @@ func (e *Editor) drawTileHoverOverlay(d *core.Drawing) { d.Restore() return } - color := hoverPaintColor + spec := e.activeSpecPalette() + color := spec.Accent.Fg switch mode { case TileStrokePaint: if e.Tool == ToolRandomTile { @@ -939,13 +940,13 @@ func (e *Editor) drawTileHoverOverlay(d *core.Drawing) { e.drawGhostTile(d, tm, x, y) } case TileStrokeTerrain: - color = hoverTerrainColor + color = spec.Added.Fg e.drawGhostTerrainTile(d, layer, col, row, x, y) case TileStrokeErase, TileStrokeEraseTerrain: - color = hoverEraseColor - d.SetFillColor(core.RGBA(0xF87171, 0.25)).FillRect(x, y, w, h) + color = spec.Removed.Fg + d.SetFillColor(specAlpha(spec.Removed.Fg, 0.25)).FillRect(x, y, w, h) case TileStrokePick: - color = hoverPickColor + color = spec.Warning.Fg } d.SetStrokeColor(color).SetLineWidth(lw).StrokeRect(x, y, w, h) d.Restore() diff --git a/packages/game/editor/tilestroke_test.go b/packages/game/editor/tilestroke_test.go index 07bde9048..4bdc38c38 100644 --- a/packages/game/editor/tilestroke_test.go +++ b/packages/game/editor/tilestroke_test.go @@ -284,21 +284,16 @@ func drawn(ed *editor.Editor) *core.Drawing { return d } -var ( - skyOutline = core.RGBA(0x38BDF8, 1) - redOutline = core.RGBA(0xF87171, 1) - amberOutline = core.RGBA(0xFBBF24, 1) -) - // The viewport outlines the hovered cell on its grid lines, wherever in the cell the mouse is, in the color of what a press would do, and draws the tile Paint would write faded inside it. func TestHoverOutlineIsDrawnOnTheCell(t *testing.T) { ed := floorEditor(t) + pal := ed.SpecPalette(nil) ed.SetTool(editor.ToolPaintTile) ed.SetActiveTileID(2) for _, at := range [][2]float32{{33, 17}, {47, 31}} { x, y := ed.WorldToCanvas(at[0], at[1]) ed.SetTileHover(x, y, false) - r, ok := hoverRect(drawn(ed).Ops, skyOutline) + r, ok := hoverRect(drawn(ed).Ops, pal.Accent.Fg) if !ok || r.X != 32 || r.Y != 16 || r.W != 16 || r.H != 16 { t.Fatalf("hover at world %v outlines %+v (%v), want the cell (2,1) at 32,16 16x16", at, r, ok) } @@ -307,16 +302,16 @@ func TestHoverOutlineIsDrawnOnTheCell(t *testing.T) { t.Fatal("no faded tile is drawn in the hovered cell") } ed.SetTool(editor.ToolEraseTile) - if _, ok := hoverRect(drawn(ed).Ops, redOutline); !ok { + if _, ok := hoverRect(drawn(ed).Ops, pal.Removed.Fg); !ok { t.Fatal("Erase does not outline the hovered cell in red") } x, y := ed.WorldToCanvas(33, 17) ed.SetTileHover(x, y, true) - if _, ok := hoverRect(drawn(ed).Ops, amberOutline); !ok { + if _, ok := hoverRect(drawn(ed).Ops, pal.Warning.Fg); !ok { t.Fatal("Alt does not outline the hovered cell in amber") } ed.ClearTileHover() - if _, ok := hoverRect(drawn(ed).Ops, amberOutline); ok { + if _, ok := hoverRect(drawn(ed).Ops, pal.Warning.Fg); ok { t.Fatal("a cell is outlined after the mouse left") } } @@ -430,7 +425,7 @@ func TestHoverOutlineFollowsTheMouse(t *testing.T) { if col, row, ok := ed.HoveredTile(); !ok || col != 3 || row != 0 { t.Fatalf("HoveredTile = (%d, %d, %v), want (3, 0)", col, row, ok) } - r, ok := hoverRect(app.Find("id:editor-viewport").Ops, skyOutline) + r, ok := hoverRect(app.Find("id:editor-viewport").Ops, ed.SpecPalette(nil).Accent.Fg) if !ok || r.X != 48 || r.Y != 0 || r.W != 16 || r.H != 16 { t.Fatalf("the canvas outlines %+v (%v), want the cell (3,0)", r, ok) } diff --git a/packages/game/editor/ui.go b/packages/game/editor/ui.go index 569de62ab..caeac6e47 100644 --- a/packages/game/editor/ui.go +++ b/packages/game/editor/ui.go @@ -807,9 +807,9 @@ func toolbarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], fileButto return ed.T("scene.untitledScene") }, Style: core.Style{ - FontSize: 14, - FontWeight: 700, - Color: colors.Text(), + FontSize: SpecFontTitleSize, + FontWeight: SpecFontTitleWeight, + Color: ed.SpecPalette(cx).TextPrimary, }, }, ui.HStack{Gap: 6, Children: fileButtons}, diff --git a/packages/game/editor/usages_ui.go b/packages/game/editor/usages_ui.go index 26145a7af..b4cfde4c8 100644 --- a/packages/game/editor/usages_ui.go +++ b/packages/game/editor/usages_ui.go @@ -12,13 +12,13 @@ import ( "github.com/nsgo-dev/nsgo/ui" ) -// Spec-derived alpha tints for ReferencesScreenView (every base color comes from Spec.dc.html). +// Spec-derived alpha tints for ReferencesScreenView from spec_theme.yaml. var ( - specRefRowActiveBg = core.RGBA(0x3B7BFF, 0.16) - specRefHitBg = core.RGBA(0x3B7BFF, 0.18) - specRefHitDimBg = core.RGBA(0x3B7BFF, 0.08) - specRefDelBg = core.RGBA(0xFF6B6B, 0.10) - specRefAddBg = core.RGBA(0x4FD38A, 0.10) + specRefRowActiveBg = specAlpha(darkSpecPalette.Accent.Fg, 0.16) + specRefHitBg = specAlpha(darkSpecPalette.Accent.Fg, 0.18) + specRefHitDimBg = specAlpha(darkSpecPalette.Accent.Fg, 0.08) + specRefDelBg = specAlpha(darkSpecPalette.Removed.Fg, 0.10) + specRefAddBg = specAlpha(darkSpecPalette.Added.Fg, 0.10) specRefMonoFamily = "JetBrains Mono, Menlo, monospace" ) diff --git a/packages/game/editor/viewport.go b/packages/game/editor/viewport.go index e72cd064b..fa2824f5c 100644 --- a/packages/game/editor/viewport.go +++ b/packages/game/editor/viewport.go @@ -583,7 +583,7 @@ func drawWorldRectHandles(e *Editor, d *core.Drawing, x, y, w, h float32, active if handle == active { half = rectHandleHalf + 1 f = activeFill - s = core.RGBA(0xFFFFFF, 1) + s = e.activeSpecPalette().TextPrimary } d.SetFillColor(f).FillRect(cx-half, cy-half, 2*half, 2*half) d.SetStrokeColor(s).StrokeRect(cx-half, cy-half, 2*half, 2*half) diff --git a/packages/game/editor/viewport3d.go b/packages/game/editor/viewport3d.go index 209a2d1ea..d6028c70c 100644 --- a/packages/game/editor/viewport3d.go +++ b/packages/game/editor/viewport3d.go @@ -2283,9 +2283,9 @@ func (e *Editor) DrawViewport3D(d *core.Drawing, size core.Size) { } } -// background3D returns the scene's background color, or the editor's dark default when it sets none or one that does not parse. +// background3D returns the scene's background color, or the Spec viewport surround token when none is set. func (e *Editor) background3D() core.Color { - bg := core.RGBA(0x141824, 1) + bg := e.activeSpecPalette().Viewport if e.Doc != nil && e.Doc.BackgroundColor != "" { if parsed, err := core.ParseColor(e.Doc.BackgroundColor); err == nil { bg = parsed @@ -2352,8 +2352,7 @@ func (e *Editor) drawGrid3D(d *core.Drawing, w, h float32) { extent := step * float32(half) vc := e.activeView3DCam(w, h) - spec := e.SpecPalette(nil) - d.Save().SetStrokeColor(ui.Alpha(spec.TextFaint, 0.24)).SetLineWidth(1).BeginPath() + d.Save().SetStrokeColor(specAlpha(e.activeSpecPalette().TextFaint, 0.25)).SetLineWidth(1).BeginPath() hasSegments := false for i := -half; i <= half; i++ { coord := float32(i) * step @@ -2391,9 +2390,9 @@ func (e *Editor) drawOriginAxes3D(d *core.Drawing, w, h float32) { end [3]float32 color core.Color }{ - {[3]float32{axisLen, 0, 0}, ui.Alpha(spec.Problem().Fg, 0.9)}, - {[3]float32{0, axisLen, 0}, ui.Alpha(spec.Added.Fg, 0.9)}, - {[3]float32{0, 0, axisLen}, ui.Alpha(spec.Accent.Fg, 0.9)}, + {[3]float32{axisLen, 0, 0}, specAlpha(spec.AxisX, 0.9)}, + {[3]float32{0, axisLen, 0}, specAlpha(spec.AxisY, 0.9)}, + {[3]float32{0, 0, axisLen}, specAlpha(spec.AxisZ, 0.9)}, } for _, ax := range axes { x0, y0, x1, y1, vis := vc.projectSegment(origin, ax.end, w, h) @@ -2501,7 +2500,7 @@ func (e *Editor) drawSceneObjects3D(d *core.Drawing, w, h float32, overlay bool) if occluded { color = ui.Alpha(spec.TextFaint, 0.35) } else if e.ShowLODOverlay && hasLOD { - color = lodColor3D(lod) + color = lodColor3D(spec, lod) } if item.selected && selVisible { color = spec.Accent.Edge @@ -2610,6 +2609,14 @@ func (e *Editor) drawGizmo3D(d *core.Drawing, w, h float32) { continue } col := seg.Color + switch seg.Axis { + case render3d.AxisX: + col = spec.AxisX + case render3d.AxisY: + col = spec.AxisY + case render3d.AxisZ: + col = spec.AxisZ + } lw := float32(2.0) if isActive { col = activeCol @@ -2659,14 +2666,9 @@ func drawTranslatePlaneFills3D(d *core.Drawing, proj Projection3D, gizmoMat math u, v math3d.Vec3 color core.Color }{ - {Axis3DXY, math3d.Vec3UnitX(), math3d.Vec3UnitY(), core.RGBA(0xB45309, fillAlpha)}, - {Axis3DXZ, math3d.Vec3UnitX(), math3d.Vec3UnitZ(), core.RGBA(0xA21CAF, fillAlpha)}, - {Axis3DYZ, math3d.Vec3UnitY(), math3d.Vec3UnitZ(), core.RGBA(0x0E7490, fillAlpha)}, - } - if spec.Dark { - planes[0].color = core.RGBA(0xEAB308, fillAlpha) - planes[1].color = core.RGBA(0xD946EF, fillAlpha) - planes[2].color = core.RGBA(0x06B6D4, fillAlpha) + {Axis3DXY, math3d.Vec3UnitX(), math3d.Vec3UnitY(), specAlpha(spec.Warning.Fg, fillAlpha)}, + {Axis3DXZ, math3d.Vec3UnitX(), math3d.Vec3UnitZ(), specAlpha(spec.Agent.Fg, fillAlpha)}, + {Axis3DYZ, math3d.Vec3UnitY(), math3d.Vec3UnitZ(), specAlpha(spec.Accent.Fg, fillAlpha)}, } for _, pl := range planes { corner := func(a, b float32) (float32, float32, bool) { diff --git a/packages/game/editor/viewport3d_lod_occluder.go b/packages/game/editor/viewport3d_lod_occluder.go index 41de220d7..72b236e89 100644 --- a/packages/game/editor/viewport3d_lod_occluder.go +++ b/packages/game/editor/viewport3d_lod_occluder.go @@ -430,18 +430,18 @@ func hasOccluder(o *sceneformat.ObjectDoc) bool { return false } -// lodColor3D returns a distinct color for each LOD index so level transitions +// lodColor3D returns a distinct Spec token color for each LOD index so level transitions // stand out clearly in the 3D viewport. -func lodColor3D(level int) core.Color { +func lodColor3D(spec SpecPalette, level int) core.Color { switch level { case 0: - return core.RGBA(0x22C55E, 0.95) // green: LOD0 (finest) + return specAlpha(spec.Added.Fg, 0.95) // green: LOD0 (finest) case 1: - return core.RGBA(0xF59E0B, 0.95) // amber: LOD1 + return specAlpha(spec.Warning.Fg, 0.95) // warning: LOD1 case 2: - return core.RGBA(0xF97316, 0.95) // orange: LOD2 + return specAlpha(spec.Changed.Fg, 0.95) // amber: LOD2 default: - return core.RGBA(0xEF4444, 0.95) // red: LOD3+ + return specAlpha(spec.Removed.Fg, 0.95) // red: LOD3+ } } @@ -457,10 +457,11 @@ func (e *Editor) drawObjectLODBadge3D(d *core.Drawing, obj *sceneformat.ObjectDo if !vis { return } + spec := e.activeSpecPalette() label := fmt.Sprintf("LOD%d", lod) - col := lodColor3D(lod) + col := lodColor3D(spec, lod) d.Save(). - SetFillColor(core.RGBA(0x0F172A, 0.78)). + SetFillColor(specAlpha(spec.PillBg, 0.88)). FillRect(sx-18, sy-15, 36, 14). SetFillColor(col). FillText(label, sx-14, sy-4, core.Font{Size: 10}). @@ -468,13 +469,14 @@ func (e *Editor) drawObjectLODBadge3D(d *core.Drawing, obj *sceneformat.ObjectDo } // drawOccluders3D draws visible occluder volumes (boxes and model occluder -// triangle wireframes) in magenta so authors can inspect occlusion walls. +// triangle wireframes) in the Spec agent violet token so authors can inspect occlusion walls. func (e *Editor) drawOccluders3D(d *core.Drawing, w, h float32) { if !e.ShowOccluders || d == nil || e.Doc == nil { return } - occColor := core.RGBA(0xD946EF, 0.95) - occLabelBg := core.RGBA(0x2E1065, 0.78) + spec := e.activeSpecPalette() + occColor := specAlpha(spec.Agent.Fg, 0.95) + occLabelBg := specAlpha(spec.Agent.Fill, 0.90) // Track which object IDs were drawn from built scenemodel.Occluders so // fallback doc walking does not double-draw them. From cd68d8e1a0dc7af19744ccbcc518d228716b42ae Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Thu, 26 Nov 2026 20:30:28 +0900 Subject: [PATCH 2/9] fix(editor): align 3D wireframe background test with Spec viewport token and keep problem rows mounted across live rechecks --- packages/game/editor/viewport3d_gpu_test.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/game/editor/viewport3d_gpu_test.go b/packages/game/editor/viewport3d_gpu_test.go index 7003e162c..1a0e25f54 100644 --- a/packages/game/editor/viewport3d_gpu_test.go +++ b/packages/game/editor/viewport3d_gpu_test.go @@ -137,8 +137,8 @@ func TestViewport3DDrawsTheSceneOnTheGPUView(t *testing.T) { cw, ch := ed.CanvasSize() overlay := &core.Drawing{} ed.DrawViewport(overlay, core.Size{Width: core.Points(cw), Height: core.Points(ch)}) - bg, _ := core.ParseColor("#141824") - if canvasBackgroundFilled(overlay, cw, ch, bg) || canvasBackgroundFilled(overlay, cw, ch, core.RGBA(0x141824, 1)) { + bg := editor.SpecPaletteFor(ed.Dark()).Viewport + if canvasBackgroundFilled(overlay, cw, ch, bg) { t.Fatal("the canvas over the GPU view paints a background over the scene") } if got := fmt.Sprint(app.Find("id:editor-viewport").Ops); got != fmt.Sprint(overlay.Ops) { @@ -203,11 +203,8 @@ func TestViewport3DWithoutAGPUDrawsTheWireframeView(t *testing.T) { cw, ch := ed.CanvasSize() d := &core.Drawing{} ed.DrawViewport(d, core.Size{Width: core.Points(cw), Height: core.Points(ch)}) - if !canvasBackgroundFilled(d, cw, ch, core.RGBA(0x141824, 1)) { - bg, _ := core.ParseColor("#141824") - if !canvasBackgroundFilled(d, cw, ch, bg) { - t.Fatal("the wireframe view does not fill the scene's background") - } + if !canvasBackgroundFilled(d, cw, ch, editor.SpecPaletteFor(ed.Dark()).Viewport) { + t.Fatal("the wireframe view does not fill the scene's background") } if got := fmt.Sprint(app.Find("id:editor-viewport").Ops); got != fmt.Sprint(d.Ops) { t.Fatal("the mounted canvas does not draw the wireframe view") From ea6c4e059b28e36d6668961c7e0131968abbeb25 Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 02:37:45 +0900 Subject: [PATCH 3/9] fix(editor): replace core.RGBA(0, 0) in datatable review UI and align live agent inspector theme test --- packages/game/editor/agent_live_test.go | 7 +++---- packages/game/editor/datatable_review_ui.go | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/game/editor/agent_live_test.go b/packages/game/editor/agent_live_test.go index c73b12c02..1b2ac9f4c 100644 --- a/packages/game/editor/agent_live_test.go +++ b/packages/game/editor/agent_live_test.go @@ -534,10 +534,9 @@ func TestAgentLiveHardeningLifecycleLocksThemeAndPulse(t *testing.T) { if got := app.Find("id:header-agent-pill").Style.Background; got != wantLight.Agent.Fill { t.Fatalf("header agent pill background after live Dark->Light switch = %v, want %v", got, wantLight.Agent.Fill) } - // Inspector lives inside inspectorThemeScope (Spec Dark subtree), so its banner stays in dark contrast tokens. - wantDark := editor.DarkSpecPalette() - if got := app.Find("id:inspector-agent-working-banner").Style.Background; got != wantDark.Agent.Fill { - t.Fatalf("inspector banner background = %v, want dark subtree token %v", got, wantDark.Agent.Fill) + // Inspector inherits the root SpecTheme() and adapts live to Spec Light tokens too. + if got := app.Find("id:inspector-agent-working-banner").Style.Background; got != wantLight.Agent.Fill { + t.Fatalf("inspector banner background after live Dark->Light switch = %v, want %v", got, wantLight.Agent.Fill) } // Switching to a second tab isolates pending turn, working lock, review changes, and state; switching back restores them. diff --git a/packages/game/editor/datatable_review_ui.go b/packages/game/editor/datatable_review_ui.go index a957bd8c1..4d925253d 100644 --- a/packages/game/editor/datatable_review_ui.go +++ b/packages/game/editor/datatable_review_ui.go @@ -285,7 +285,7 @@ func dtReviewLeftSidebar(cx *core.Scope, p SpecPalette, ed *Editor, reviewRev *c for i, f := range files { idx := i selected := i == activeIdx - bg := core.RGBA(0, 0) + bg := core.Color(0) if selected { bg = p.Accent.Fill } @@ -534,7 +534,7 @@ func dtReviewCenterPane(cx *core.Scope, p SpecPalette, ed *Editor, reviewRev *co FontSize: 12.5, Color: p.TextPrimary, PlaceholderColor: p.TextFaint, - Background: core.RGBA(0, 0), + Background: core.Color(0), BorderWidth: 0, CaretColor: p.Accent.Edge, }, @@ -629,7 +629,7 @@ func dtReviewToolbar(cx *core.Scope, p SpecPalette, ed *Editor, reviewRev *core. for _, c := range defs { cd := c on := active == cd.id - bg := core.RGBA(0, 0) + bg := core.Color(0) border := p.Line fg := p.TextMuted countFg := p.TextFaint @@ -1178,7 +1178,7 @@ func dtReviewDataRow( Role: core.RoleRow, StyleFunc: func() core.Style { h := dropHint.Get() - bg := core.RGBA(0, 0) + bg := core.Color(0) leftW := core.Points(0) leftCol := p.Line if focused { @@ -1447,7 +1447,7 @@ func dtReviewInlineCellEditor(cx *core.Scope, p SpecPalette, ed *Editor, recKey FontFamily: core.FontMonospace, FontSize: 11.5, Color: p.TextPrimary, - Background: core.RGBA(0, 0), + Background: core.Color(0), BorderWidth: 0, CaretColor: p.Accent.Edge, }, @@ -1537,7 +1537,7 @@ func dtReviewRightYAML(cx *core.Scope, p SpecPalette, ed *Editor, reviewRev *cor lineNodes := make([]core.Node, 0, len(lines)) for i, ln := range lines { - bg := core.RGBA(0, 0) + bg := core.Color(0) fg := p.TextFaint switch ln.Sign { case "+": From 848c65eee6e05b47f108b3b1cec0c2e184ff01d5 Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 03:18:46 +0900 Subject: [PATCH 4/9] fix(editor): replace sketch hardcoded colors with Spec tokens and keep HUD inspector mounted across unrelated notifications --- packages/game/editor/hud_layout.go | 54 +++++++++++++++++++++++++++ packages/game/editor/hud_layout_ui.go | 17 +++++---- packages/game/editor/sketch.go | 2 +- packages/game/editor/sketch_png.go | 2 +- 4 files changed, 65 insertions(+), 10 deletions(-) diff --git a/packages/game/editor/hud_layout.go b/packages/game/editor/hud_layout.go index 3099b7b54..35fd25645 100644 --- a/packages/game/editor/hud_layout.go +++ b/packages/game/editor/hud_layout.go @@ -3,8 +3,10 @@ package editor import ( "bytes" "cmp" + "encoding/binary" "errors" "fmt" + "hash/fnv" "io/fs" "maps" "math" @@ -149,6 +151,7 @@ type hudLayoutState struct { open bool rev uint64 session uint64 + localeRev uint64 screens []hudScreenRecord activePath string selectedNodeID string @@ -554,6 +557,7 @@ func (e *Editor) loadHUDLocalesFromDir(dir string, enforceProjectRoot bool) { e.hud.locales = locales e.hud.localeStrings = stringsMap e.hud.localePlurals = pluralsMap + e.hud.localeRev++ if e.hud.locale == "" || !slices.Contains(locales, e.hud.locale) { e.hud.locale = locales[0] } @@ -725,6 +729,7 @@ func (e *Editor) OpenHUDScreenDoc(name string, doc *gameui.ScreenDoc, locales ma e.hud.locales = locs e.hud.localeStrings = sm e.hud.localePlurals = pm + e.hud.localeRev++ } e.hud.activePath = relPath e.hud.open = true @@ -1017,10 +1022,59 @@ func (e *Editor) syncHUDAfterMutate() { e.hud.localePlurals[loc] = maps.Clone(e.l10n.plurals[loc]) } slices.Sort(e.hud.locales) + e.hud.localeRev++ } e.ensureHUDSelection() } +// hudStableFingerprint summarizes the HUD layout state rendered by the left rail, +// text-width table, and inspector so unrelated editor notifications (such as async +// project-wide problem rechecks or overlay toggles) do not needlessly remount those +// subtrees and drop in-flight pointer presses. +func (e *Editor) hudStableFingerprint() uint64 { + if e == nil { + return 0 + } + h := fnv.New64a() + var buf [8]byte + writeU64 := func(v uint64) { + binary.LittleEndian.PutUint64(buf[:], v) + _, _ = h.Write(buf[:]) + } + writeStr := func(s string) { + writeU64(uint64(len(s))) + _, _ = h.Write([]byte(s)) + } + writeU64(e.hud.rev) + writeU64(e.hud.session) + writeU64(e.hud.localeRev) + writeStr(e.hud.activePath) + writeStr(e.hud.selectedNodeID) + writeStr(e.hud.locale) + writeU64(uint64(len(e.hud.locales))) + for _, loc := range e.hud.locales { + writeStr(loc) + } + writeU64(uint64(len(e.hud.screens))) + for i := range e.hud.screens { + rec := &e.hud.screens[i] + writeStr(rec.path) + writeU64(uint64(len(rec.raw))) + _, _ = h.Write(rec.raw) + if rec.doc != nil { + writeU64(1) + } else { + writeU64(0) + } + if rec.loadErr != nil { + writeStr(rec.loadErr.Error()) + } else { + writeU64(0) + } + } + return h.Sum64() +} + // HUDTree returns the flattened node tree for the active screen's NODES rail. func (e *Editor) HUDTree() []HUDTreeRow { rec := e.activeHUDScreenRecord() diff --git a/packages/game/editor/hud_layout_ui.go b/packages/game/editor/hud_layout_ui.go index aa5821e5e..a9685b5e3 100644 --- a/packages/game/editor/hud_layout_ui.go +++ b/packages/game/editor/hud_layout_ui.go @@ -36,20 +36,21 @@ func HUDLayoutView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.No canvasH := core.NewSignal(cx, float32(812)) // Pause heavy left-rail / text-width-table / inspector rebuilds (which run gameui.CheckScreen - // across project screens) while a touch drag streams mouse moves, and gate rebuilds on HUD - // state revisions so unrelated background editor notifications (such as async CheckProblems - // completions or disk-watch ticks) never remount HUD inspector buttons mid-press. + // across project screens) while a touch drag streams mouse moves, and keep those subtrees + // stably mounted across unrelated editor notifications (such as async project-wide problem + // rechecks, disk-watch ticks, or overlay toggles) so in-flight pointer presses and focus + // are never dropped. type hudStableKey struct { - rev uint64 - sel string + fp uint64 + dark bool } - var lastNonDragRev uint64 + var lastNonDragFP uint64 stableRev := core.NewMemo(cx, func() hudStableKey { _ = rev.Get() if !ed.HUDTouchDragActive() { - lastNonDragRev = ed.hud.rev + lastNonDragFP = ed.hudStableFingerprint() } - return hudStableKey{rev: lastNonDragRev, sel: ed.HUDSelectedNodeID()} + return hudStableKey{fp: lastNonDragFP, dark: cx.Dark()} }) stableTick := func() { _ = stableRev.Get() } diff --git a/packages/game/editor/sketch.go b/packages/game/editor/sketch.go index 10620038d..b478dffb1 100644 --- a/packages/game/editor/sketch.go +++ b/packages/game/editor/sketch.go @@ -1843,7 +1843,7 @@ func (e *Editor) drawSketchDraft(d *core.Drawing, spec SpecPalette, dr *sketchDr } func (e *Editor) drawSketchMark(d *core.Drawing, spec SpecPalette, m SketchMark, selected, reviewDotted bool, alpha float32) { - haloColor := core.RGBA(0x000000, 0.55*alpha) + haloColor := ui.Alpha(spec.Bg, 0.65*alpha) if !spec.Dark { haloColor = ui.Alpha(spec.Bg, 0.72*alpha) } diff --git a/packages/game/editor/sketch_png.go b/packages/game/editor/sketch_png.go index a6b6668af..0dedf9932 100644 --- a/packages/game/editor/sketch_png.go +++ b/packages/game/editor/sketch_png.go @@ -147,7 +147,7 @@ func renderSketchOverlayTextPNG(pngBytes []byte, ops []core.DrawOp) ([]byte, boo } cur := state{ m: sketchTextAffine{a: 1, d: 1}, - color: core.RGB(0xFFFFFF), + color: darkSpecPalette.TextPrimary, alpha: 1, } var stack []state From 6462ad140ef621464227f8ced90d2dff9db2b67a Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 03:35:42 +0900 Subject: [PATCH 5/9] test(game): wait for MCP initialized client identity in TestGameMCPInstallConnectReconnectAndComposer --- packages/game/cmd/game/mcp_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/game/cmd/game/mcp_test.go b/packages/game/cmd/game/mcp_test.go index 15d28265c..044f80317 100644 --- a/packages/game/cmd/game/mcp_test.go +++ b/packages/game/cmd/game/mcp_test.go @@ -376,8 +376,10 @@ func TestGameMCPInstallConnectReconnectAndComposer(t *testing.T) { } // Connecting via the installed config transitions the Connect dialog and status chip to Connected. + // Wait for the MCP initialized handshake to populate the proxy client identity ("Claude Code over stdio"), + // since serveConn registers the raw unix transport before notifications/initialized arrives. app.WaitUntil(10*time.Second, func() bool { - return ed.AgentStatus() == editor.AgentStatusConnected + return ed.AgentStatus() == editor.AgentStatusConnected && ed.AgentStatusTooltip() == "Claude Code over stdio" }) if tip := ed.AgentStatusTooltip(); tip != "Claude Code over stdio" { t.Fatalf("tooltip = %q, want Claude Code over stdio", tip) From 50eff49461a5823a98046ace1d09925f2f128eea Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 04:14:54 +0900 Subject: [PATCH 6/9] fix(editor): harden Spec theme light-mode contrast, gizmo palettes, token wiring, and AST guardrails --- docs/en/editor.md | 2 +- docs/zh/editor.md | 2 +- packages/game/editor/agent_live.go | 10 +- packages/game/editor/focus_regions.go | 6 +- packages/game/editor/gizmo2d.go | 9 - packages/game/editor/gizmo3d.go | 20 +- packages/game/editor/gridmap.go | 35 +- packages/game/editor/gridmap_palette.go | 23 +- packages/game/editor/handles3d.go | 29 +- packages/game/editor/inspector.go | 17 +- packages/game/editor/inspector_scrub.go | 6 +- packages/game/editor/lights2d_editor.go | 22 +- packages/game/editor/materials_ui.go | 5 +- packages/game/editor/navregion2d_editor.go | 41 +- packages/game/editor/physics_debug.go | 12 +- packages/game/editor/play_marks_ui.go | 381 +++++++----- packages/game/editor/spec_panel_ui.go | 4 +- packages/game/editor/spec_theme.go | 14 +- packages/game/editor/spec_theme.yaml | 2 + packages/game/editor/spec_theme_test.go | 666 +++++++++++++++++++-- packages/game/editor/terrain.go | 25 +- packages/game/editor/tilebrush.go | 11 +- packages/game/editor/tilepalette.go | 24 +- packages/game/editor/tilestroke.go | 8 - packages/game/editor/viewport3d.go | 30 +- 25 files changed, 1021 insertions(+), 383 deletions(-) diff --git a/docs/en/editor.md b/docs/en/editor.md index 9e2bfdf5a..9ba898328 100644 --- a/docs/en/editor.md +++ b/docs/en/editor.md @@ -1666,7 +1666,7 @@ For larger changes—such as edits touching Go code, creating files, or spanning Every color, type size, spacing step, corner radius, height, and motion duration in the editor comes from the embedded YAML theme and constants defined in `packages/game/editor/spec_theme.yaml` and `packages/game/editor/spec_theme.go`, matching `docs/design/editor/Spec.dc.html` and `docs/design/editor/Viewport3D.dc.html`: -- **Embedded YAML theme (`spec_theme.yaml`, `SpecTheme`, `SpecPalette`)**: loaded with `core.ParseTheme` and attached on `EditorView`'s root scope via `cx.SetTheme(SpecTheme())`. Every NSGo `core.Palette` and `ui.ColorsOf` role (`Background`, `Surface`, `Raised`, `Line`, `Border`, `Text`, `TextMuted`, `Accent`, `AccentText`, `Success`, `Warning`, `Danger`, `Focus`) maps directly onto the Spec palette in both dark and light appearances, while `Editor.SpecPalette(cx)` (`DarkSpecPalette()`, `LightSpecPalette()`, `SpecPaletteFor(dark)`) exposes the additional Spec roles (`TextPrimary` / text strong, `TextSecondary` / text, `TextMuted` / text secondary, `TextFaint` / text muted, `OnTextPrimary`, `Viewport`, `ViewportDot`, `PillBg`, `HoverOverlay`, `ActiveOverlay`, `PrimaryHover`, `Viewport3DGround`, `Viewport3DGrid`, `Accent`, `Agent`, `Added`, `Changed`, `Removed`/`Problem`, `Warning` with dedicated `Fill` and `Edge`, and 3D axis tokens `AxisX`, `AxisY`, `AxisZ`). +- **Embedded YAML theme (`spec_theme.yaml`, `SpecTheme`, `SpecPalette`)**: loaded with `core.ParseTheme` and attached on `EditorView`'s root scope via `cx.SetTheme(SpecTheme())`. Every NSGo `core.Palette` and `ui.ColorsOf` role (`Background`, `Surface`, `Raised`, `Line`, `Border`, `Text`, `TextMuted`, `Accent`, `AccentText`, `Success`, `Warning`, `Danger`, `Focus`) maps directly onto the Spec palette in both dark and light appearances, while `Editor.SpecPalette(cx)` (`DarkSpecPalette()`, `LightSpecPalette()`, `SpecPaletteFor(dark)`) exposes the additional Spec roles (`TextPrimary` / text strong, `TextSecondary` / text, `TextMuted` / text secondary, `TextFaint` / text muted, `OnTextPrimary`, `Viewport`, `ViewportDot`, `PillBg`, `HoverOverlay`, `ActiveOverlay`, `PrimaryHover`, `AccentHover`, `AccentPressed`, `Viewport3DGround`, `Viewport3DGrid`, `Accent`, `Agent`, `Added`, `Changed`, `Removed`/`Problem`, `Warning` with dedicated `Fill` and `Edge`, and 3D axis tokens `AxisX`, `AxisY`, `AxisZ`). - **Dark palette tokens (`Spec.dc.html` & `Viewport3D.dc.html`)**: - Surfaces & borders: `bg #101216`, `panel #12141A`, `raised #171A21`, `line #1F232A`, `line raised #262B35`, `viewport #15181D`, `viewportDot #2A2F38`. - Text ladder: `text strong #FFFFFF`, `text #D9DDE5`, `text secondary #B4BAC6`, `text muted #8B92A0`. The retired `#6F7684`, `#5D6472`, and `#4A505C` are never used for text. diff --git a/docs/zh/editor.md b/docs/zh/editor.md index b9185a26d..b392874c1 100644 --- a/docs/zh/editor.md +++ b/docs/zh/editor.md @@ -1666,7 +1666,7 @@ func main() { 编辑器中的每一处色彩、字号、间距阶梯、圆角、高度与动效时长都统一来自嵌入的 YAML 主题文件与常量定义(`packages/game/editor/spec_theme.yaml` 与 `packages/game/editor/spec_theme.go`),与 `docs/design/editor/Spec.dc.html` 及 `docs/design/editor/Viewport3D.dc.html` 保持一致: -- **嵌入 YAML 主题(`spec_theme.yaml`、`SpecTheme`、`SpecPalette`)**:通过 `core.ParseTheme` 解析并在 `EditorView` 根作用域通过 `cx.SetTheme(SpecTheme())` 生效。NSGo 的所有 `core.Palette` 与 `ui.ColorsOf` 角色(`Background`、`Surface`、`Raised`、`Line`、`Border`、`Text`、`TextMuted`、`Accent`、`AccentText`、`Success`、`Warning`、`Danger`、`Focus`)均在深色与浅色外观下直接映射到规范调色板;`Editor.SpecPalette(cx)`(以及 `DarkSpecPalette()`、`LightSpecPalette()`、`SpecPaletteFor(dark)`)同时提供 NSGo 未命名的规范角色(`TextPrimary` / 强文本、`TextSecondary` / 正文、`TextMuted` / 次级文本、`TextFaint` / 弱化文本、`OnTextPrimary`、`Viewport`、`ViewportDot`、`PillBg`、`HoverOverlay`、`ActiveOverlay`、`PrimaryHover`、`Viewport3DGround`、`Viewport3DGrid`、`Accent`、`Agent`、`Added`、`Changed`、`Removed`/`Problem`、含专用 `Fill` 与 `Edge` 的 `Warning`,以及 3D 坐标轴令牌 `AxisX`、`AxisY`、`AxisZ`)。 +- **嵌入 YAML 主题(`spec_theme.yaml`、`SpecTheme`、`SpecPalette`)**:通过 `core.ParseTheme` 解析并在 `EditorView` 根作用域通过 `cx.SetTheme(SpecTheme())` 生效。NSGo 的所有 `core.Palette` 与 `ui.ColorsOf` 角色(`Background`、`Surface`、`Raised`、`Line`、`Border`、`Text`、`TextMuted`、`Accent`、`AccentText`、`Success`、`Warning`、`Danger`、`Focus`)均在深色与浅色外观下直接映射到规范调色板;`Editor.SpecPalette(cx)`(以及 `DarkSpecPalette()`、`LightSpecPalette()`、`SpecPaletteFor(dark)`)同时提供 NSGo 未命名的规范角色(`TextPrimary` / 强文本、`TextSecondary` / 正文、`TextMuted` / 次级文本、`TextFaint` / 弱化文本、`OnTextPrimary`、`Viewport`、`ViewportDot`、`PillBg`、`HoverOverlay`、`ActiveOverlay`、`PrimaryHover`、`AccentHover`、`AccentPressed`、`Viewport3DGround`、`Viewport3DGrid`、`Accent`、`Agent`、`Added`、`Changed`、`Removed`/`Problem`、含专用 `Fill` 与 `Edge` 的 `Warning`,以及 3D 坐标轴令牌 `AxisX`、`AxisY`、`AxisZ`)。 - **深色模式色彩令牌(`Spec.dc.html` 与 `Viewport3D.dc.html`)**: - 表面与边框:`bg #101216`、`panel #12141A`、`raised #171A21`、`line #1F232A`、`line raised #262B35`、`viewport #15181D`、`viewportDot #2A2F38`。 - 四级文本:`text strong #FFFFFF`、`text #D9DDE5`、`text secondary #B4BAC6`、`text muted #8B92A0`。已退役的 `#6F7684`、`#5D6472` 与 `#4A505C` 不再用于文本。 diff --git a/packages/game/editor/agent_live.go b/packages/game/editor/agent_live.go index a0b83e038..8ce284afa 100644 --- a/packages/game/editor/agent_live.go +++ b/packages/game/editor/agent_live.go @@ -160,9 +160,9 @@ type agentLiveState struct { } const ( - agentPulsePeriod = 1600 * time.Millisecond - agentPulseMinAlpha = 0.45 - agentPulseMaxAlpha = 1.0 + agentPulsePeriod = SpecMotionAgentPulse + agentPulseMinAlpha = SpecAgentPulseMinOpacity + agentPulseMaxAlpha = SpecAgentPulseMaxOpacity ) // RunAsAgent executes fn while marking edits as originating from the agent rather than manual UI input, @@ -678,8 +678,8 @@ func (e *Editor) AgentPulseOpacity() float32 { return agentPulseMaxAlpha } // Smooth cosine oscillation between 1.0 and 0.45 over 1.6 s. - mid := (agentPulseMaxAlpha + agentPulseMinAlpha) * 0.5 - amp := (agentPulseMaxAlpha - agentPulseMinAlpha) * 0.5 + mid := (float64(agentPulseMaxAlpha) + float64(agentPulseMinAlpha)) * 0.5 + amp := (float64(agentPulseMaxAlpha) - float64(agentPulseMinAlpha)) * 0.5 return float32(mid + amp*math.Cos(2*math.Pi*e.agentLive.pulsePhase)) } diff --git a/packages/game/editor/focus_regions.go b/packages/game/editor/focus_regions.go index 8817d73bf..727c5e926 100644 --- a/packages/game/editor/focus_regions.go +++ b/packages/game/editor/focus_regions.go @@ -980,15 +980,11 @@ func (s SpecSwitch) Render(cx *core.Scope) core.Node { if checked() { tx = 14 } - knob := colors.Knob() - if knob == 0 { - knob = lightSpecPalette.Raised - } return core.Style{ Width: core.Pt(14), Height: core.Pt(14), CornerRadius: 7, - Background: knob, + Background: colors.Knob(), Transform: core.Transform{TranslateX: tx}, } }, diff --git a/packages/game/editor/gizmo2d.go b/packages/game/editor/gizmo2d.go index e90b02916..a5ee18c04 100644 --- a/packages/game/editor/gizmo2d.go +++ b/packages/game/editor/gizmo2d.go @@ -1337,15 +1337,6 @@ func (c *transform2DCmd) Undo() { } } -// Spec token gizmo colors shared with 2D lighting and nav-region handle overlays. -var ( - gizmoColorX = darkSpecPalette.AxisX - gizmoColorY = darkSpecPalette.AxisY - gizmoColorRing = specAlpha(darkSpecPalette.Accent.Edge, 0.8) - gizmoColorCenter = darkSpecPalette.TextPrimary - gizmoColorActive = darkSpecPalette.Warning.Fg -) - // drawGizmo2D draws the selected object's transform gizmo: the rotation ring, the X and Y arrows, the move square and, on an outline large enough, the scale handles. The handle a drag holds is drawn highlighted. func (e *Editor) drawGizmo2D(d *core.Drawing) { if !e.Gizmo2DShown() || !e.OverlayKindVisible(OverlayKindSelection) { diff --git a/packages/game/editor/gizmo3d.go b/packages/game/editor/gizmo3d.go index b5ebb3352..4870683ca 100644 --- a/packages/game/editor/gizmo3d.go +++ b/packages/game/editor/gizmo3d.go @@ -262,15 +262,15 @@ func (h GizmoHandle3D) referencePoint() math3d.Vec3 { } } -func (h GizmoHandle3D) effectiveColor(active bool) core.Color { +func (h GizmoHandle3D) effectiveColor(pal SpecPalette, active bool) core.Color { if active { - return darkSpecPalette.Warning.Fg + return pal.Warning.Fg } var zero core.Color if h.Color != zero { return h.Color } - return darkSpecPalette.Accent.Fg + return pal.Accent.Fg } // ComponentGizmo3D registers 3D viewport handles and drag editing for one component type. @@ -557,11 +557,11 @@ func pickGizmoHandles3D(proj Projection3D, mat math3d.Mat4, handles []GizmoHandl } // drawGizmoHandle3D renders a single 3D gizmo handle transformed by mat onto d through proj. -func drawGizmoHandle3D(d *core.Drawing, proj Projection3D, mat math3d.Mat4, h GizmoHandle3D, active bool) { +func drawGizmoHandle3D(d *core.Drawing, pal SpecPalette, proj Projection3D, mat math3d.Mat4, h GizmoHandle3D, active bool) { if d == nil { return } - col := h.effectiveColor(active) + col := h.effectiveColor(pal, active) switch h.Kind { case GizmoHandlePoint3D: wp := mat.TransformPoint(h.Position) @@ -578,7 +578,7 @@ func drawGizmoHandle3D(d *core.Drawing, proj Projection3D, mat math3d.Mat4, h Gi } d.Save() d.SetFillColor(col).BeginPath().Arc(sx, sy, r, 0, float32(2*math.Pi), false).Fill() - d.SetStrokeColor(specAlpha(darkSpecPalette.Bg, 0.9)).SetLineWidth(1.25).BeginPath().Arc(sx, sy, r, 0, float32(2*math.Pi), false).Stroke() + d.SetStrokeColor(specAlpha(pal.Bg, 0.9)).SetLineWidth(1.25).BeginPath().Arc(sx, sy, r, 0, float32(2*math.Pi), false).Stroke() if active && h.Label != "" { d.SetFillColor(col).FillText(h.Label, sx+r+4, sy+3, core.Font{Size: 10}) } @@ -613,15 +613,15 @@ func drawGizmoHandle3D(d *core.Drawing, proj Projection3D, mat math3d.Mat4, h Gi } // drawGizmoHandles3D draws visual primitives (boxes and lines) first and point handles on top. -func drawGizmoHandles3D(d *core.Drawing, proj Projection3D, mat math3d.Mat4, handles []GizmoHandle3D, activeID string) { +func drawGizmoHandles3D(d *core.Drawing, pal SpecPalette, proj Projection3D, mat math3d.Mat4, handles []GizmoHandle3D, activeID string) { for _, h := range handles { if h.Kind != GizmoHandlePoint3D { - drawGizmoHandle3D(d, proj, mat, h, activeID != "" && h.ID == activeID) + drawGizmoHandle3D(d, pal, proj, mat, h, activeID != "" && h.ID == activeID) } } for _, h := range handles { if h.Kind == GizmoHandlePoint3D { - drawGizmoHandle3D(d, proj, mat, h, activeID != "" && h.ID == activeID) + drawGizmoHandle3D(d, pal, proj, mat, h, activeID != "" && h.ID == activeID) } } } @@ -1186,7 +1186,7 @@ func (e *Editor) drawComponentGizmos3D(d *core.Drawing, proj Projection3D) { if selected && e.compGizmoDrag.active && e.compGizmoDrag.objectID == obj.ID && e.compGizmoDrag.component == compName { activeID = e.compGizmoDrag.handle.ID } - drawGizmoHandles3D(d, proj, worldMat, handles, activeID) + drawGizmoHandles3D(d, e.activeSpecPalette(), proj, worldMat, handles, activeID) } } diff --git a/packages/game/editor/gridmap.go b/packages/game/editor/gridmap.go index c1b66926e..eb3209ecd 100644 --- a/packages/game/editor/gridmap.go +++ b/packages/game/editor/gridmap.go @@ -1413,11 +1413,12 @@ func (e *Editor) drawGridMap3D(d *core.Drawing, w, h float32) { cmp.Compare(a.coord.X, b.coord.X), ) }) + spec := e.activeSpecPalette() for _, item := range cells { - col := gridMapTileColor(item.cell.TileID, 0.9) + col := gridMapTileColor(spec, item.cell.TileID, 0.9) lw := float32(1.4) if e.gridMap.tool != GridMapToolNone && item.coord.Y != e.gridMap.floor { - col = gridMapTileColor(item.cell.TileID, 0.45) + col = gridMapTileColor(spec, item.cell.TileID, 0.45) lw = 1.0 } e.drawGridMapCellBox3D(d, gm, item.coord, item.cell.TileID, item.cell.Orientation, toWorld, col, lw, w, h) @@ -1427,7 +1428,6 @@ func (e *Editor) drawGridMap3D(d *core.Drawing, w, h float32) { return } - spec := e.activeSpecPalette() // 3. Box Fill drag preview, or hovered cell preview under the pointer. if minC, maxC, ok := e.GridMapBoxPreview(); ok { bmin := gm.CellBounds(minC).Min @@ -1597,22 +1597,21 @@ func (e *Editor) fillCellFloorQuad3D(d *core.Drawing, bmin, bmax math3d.Vec3, to ClosePath().Fill().Restore() } -var gridMapPaletteSwatches = []core.Color{ - darkSpecPalette.Accent.Fg, - darkSpecPalette.Added.Fg, - darkSpecPalette.Warning.Fg, - darkSpecPalette.Removed.Fg, - darkSpecPalette.Agent.Fg, - darkSpecPalette.Changed.Fg, - darkSpecPalette.TextMuted, - darkSpecPalette.TextSecondary, -} - -func gridMapTileColor(tileID uint16, alpha float32) core.Color { +func gridMapTileColor(pal SpecPalette, tileID uint16, alpha float32) core.Color { if tileID == 0 { - return specAlpha(darkSpecPalette.TextFaint, alpha) - } - base := gridMapPaletteSwatches[int(tileID-1)%len(gridMapPaletteSwatches)] + return specAlpha(pal.TextFaint, alpha) + } + swatches := [8]core.Color{ + pal.Accent.Fg, + pal.Added.Fg, + pal.Warning.Fg, + pal.Removed.Fg, + pal.Agent.Fg, + pal.Changed.Fg, + pal.TextMuted, + pal.TextSecondary, + } + base := swatches[int(tileID-1)%len(swatches)] return specAlpha(base, alpha) } diff --git a/packages/game/editor/gridmap_palette.go b/packages/game/editor/gridmap_palette.go index b7232358c..0ef298cfc 100644 --- a/packages/game/editor/gridmap_palette.go +++ b/packages/game/editor/gridmap_palette.go @@ -77,6 +77,7 @@ func (e *Editor) GridMapPalette() GridMapPalette { p.Message = fmt.Sprintf("Mesh library %q has no items", e.gridMap.meshLibrary) return p } + pal := e.activeSpecPalette() p.Items = make([]GridMapPaletteItem, 0, len(defs)) for _, def := range defs { name := def.Name @@ -88,7 +89,7 @@ func (e *Editor) GridMapPalette() GridMapPalette { Name: name, MeshID: def.MeshID, LocalBounds: def.LocalBounds, - Thumbnail: buildGridMapThumbnail(e.gridMap.gltfDoc, def), + Thumbnail: buildGridMapThumbnail(pal, e.gridMap.gltfDoc, def), }) } return p @@ -100,13 +101,13 @@ type gridMapThumbTri struct { color core.Color } -func buildGridMapThumbnail(doc *gltf.Document, def world3d.MeshTileDef) []gridMapThumbTri { +func buildGridMapThumbnail(pal SpecPalette, doc *gltf.Document, def world3d.MeshTileDef) []gridMapThumbTri { if doc != nil && int(def.MeshID) < len(doc.Meshes) { - if tris := extractGLTFThumbTris(doc, int(def.MeshID), def.ID); len(tris) > 0 { + if tris := extractGLTFThumbTris(pal, doc, int(def.MeshID), def.ID); len(tris) > 0 { return tris } } - return boxThumbTris(def.LocalBounds, def.ID) + return boxThumbTris(pal, def.LocalBounds, def.ID) } func rgbColor(r, g, b float64) core.Color { @@ -122,7 +123,7 @@ func rgbColor(r, g, b float64) core.Color { return colorFromRGBA8(clamp(r), clamp(g), clamp(b), 255) } -func extractGLTFThumbTris(doc *gltf.Document, meshIdx int, tileID uint16) []gridMapThumbTri { +func extractGLTFThumbTris(pal SpecPalette, doc *gltf.Document, meshIdx int, tileID uint16) []gridMapThumbTri { mesh := &doc.Meshes[meshIdx] bounds := math3d.AABBEmpty() var raw [][3]math3d.Vec3 @@ -134,7 +135,7 @@ func extractGLTFThumbTris(doc *gltf.Document, meshIdx int, tileID uint16) []grid if len(prim.Positions) < 3 { continue } - baseCol := gridMapTileColor(tileID, 1) + baseCol := gridMapTileColor(pal, tileID, 1) if prim.Material >= 0 && prim.Material < len(doc.Materials) { bc := doc.Materials[prim.Material].BaseColorFactor if bc.X+bc.Y+bc.Z > 0.05 { @@ -190,7 +191,7 @@ func extractGLTFThumbTris(doc *gltf.Document, meshIdx int, tileID uint16) []grid return out } -func boxThumbTris(bounds math3d.AABB, tileID uint16) []gridMapThumbTri { +func boxThumbTris(pal SpecPalette, bounds math3d.AABB, tileID uint16) []gridMapThumbTri { hx, hy, hz := float32(0.65), float32(0.65), float32(0.65) if !bounds.Empty() { s := bounds.Size() @@ -202,7 +203,7 @@ func boxThumbTris(bounds math3d.AABB, tileID uint16) []gridMapThumbTri { hz = max(s.Z*0.5*scale, 0.14) } } - col := gridMapTileColor(tileID, 1) + col := gridMapTileColor(pal, tileID, 1) v := [8]math3d.Vec3{ {X: -hx, Y: -hy, Z: -hz}, {X: +hx, Y: -hy, Z: -hz}, @@ -232,7 +233,7 @@ func boxThumbTris(bounds math3d.AABB, tileID uint16) []gridMapThumbTri { } // drawGridMapThumbnail renders an isometric 3D shaded thumbnail of item rotated by orient onto d. -func drawGridMapThumbnail(d *core.Drawing, item GridMapPaletteItem, orient uint8, w, h float32) { +func drawGridMapThumbnail(d *core.Drawing, pal SpecPalette, item GridMapPaletteItem, orient uint8, w, h float32) { if d == nil || w <= 0 || h <= 0 || len(item.Thumbnail) == 0 { return } @@ -301,7 +302,7 @@ func drawGridMapThumbnail(d *core.Drawing, item GridMapPaletteItem, orient uint8 ClosePath().Fill() } // Subtle wireframe accent on top of shaded thumbnail for crisp legibility at small sizes. - d.SetStrokeColor(specAlpha(darkSpecPalette.Bg, 0.35)).SetLineWidth(0.75) + d.SetStrokeColor(specAlpha(pal.Bg, 0.35)).SetLineWidth(0.75) for _, pt := range projected { d.BeginPath().MoveTo(pt.x0, pt.y0).LineTo(pt.x1, pt.y1).LineTo(pt.x2, pt.y2).ClosePath().Stroke() } @@ -406,7 +407,7 @@ func gridMapPalettePanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c }, Draw: func(d *core.Drawing, size core.Size) { o := orient.Get() - drawGridMapThumbnail(d, item, o, float32(size.Width), float32(size.Height)) + drawGridMapThumbnail(d, ed.SpecPalette(cx), item, o, float32(size.Width), float32(size.Height)) }, }, core.Text{ diff --git a/packages/game/editor/handles3d.go b/packages/game/editor/handles3d.go index 2bdebe883..386a75a73 100644 --- a/packages/game/editor/handles3d.go +++ b/packages/game/editor/handles3d.go @@ -985,6 +985,7 @@ func (e *Editor) drawSceneLightAndCameraIcons3D(d *core.Drawing, w, h float32) { if e.LookThroughCamera3D() { _, activeCamID, _ = e.ActiveSceneCamera3D(w, h) } + pal := e.activeSpecPalette() for li := range doc.Layers { layer := &doc.Layers[li] if !layer.IsVisible() || layer.EffectiveSpace() == sceneformat.SpaceScreen { @@ -1003,25 +1004,25 @@ func (e *Editor) drawSceneLightAndCameraIcons3D(d *core.Drawing, w, h float32) { if posed.Light != nil { pos := vec32(world.point([3]float64{0, 0, 0})) if px, py, _, vis := vc.project(pos, w, h); vis { - drawLightIcon2D(d, px, py, posed.Light, selected) + drawLightIcon2D(d, pal, px, py, posed.Light, selected) } } if posed.Camera != nil && o.ID != activeCamID { pos := vec32(world.point([3]float64{0, 0, 0})) if px, py, _, vis := vc.project(pos, w, h); vis { - drawCameraIcon2D(d, px, py, posed.Camera, selected) + drawCameraIcon2D(d, pal, px, py, posed.Camera, selected) } } if posed.ReflectionProbe != nil { pos := vec32(world.point([3]float64{0, 0, 0})) if px, py, _, vis := vc.project(pos, w, h); vis { - drawReflectionProbeIcon2D(d, px, py, posed.ReflectionProbe, selected) + drawReflectionProbeIcon2D(d, pal, px, py, posed.ReflectionProbe, selected) } } if posed.LightProbeGrid != nil { pos := vec32(world.point([3]float64{0, 0, 0})) if px, py, _, vis := vc.project(pos, w, h); vis { - drawLightProbeGridIcon2D(d, px, py, posed.LightProbeGrid, selected) + drawLightProbeGridIcon2D(d, pal, px, py, posed.LightProbeGrid, selected) } } walk(o.Children, world) @@ -1031,18 +1032,17 @@ func (e *Editor) drawSceneLightAndCameraIcons3D(d *core.Drawing, w, h float32) { } } -func lightIconColor(l *sceneformat.LightDoc) core.Color { +func lightIconColor(pal SpecPalette, l *sceneformat.LightDoc) core.Color { if l != nil && l.Color != "" { if c, err := core.ParseColor(l.Color); err == nil { return c } } - return darkSpecPalette.Warning.Fg + return pal.Warning.Fg } -func drawLightIcon2D(d *core.Drawing, x, y float32, l *sceneformat.LightDoc, selected bool) { - pal := darkSpecPalette - col := lightIconColor(l) +func drawLightIcon2D(d *core.Drawing, pal SpecPalette, x, y float32, l *sceneformat.LightDoc, selected bool) { + col := lightIconColor(pal, l) ring := specAlpha(pal.Bg, 0.85) if selected { ring = pal.Accent.Edge @@ -1080,8 +1080,7 @@ func drawLightIcon2D(d *core.Drawing, x, y float32, l *sceneformat.LightDoc, sel } } -func drawCameraIcon2D(d *core.Drawing, x, y float32, c *sceneformat.Camera3DDoc, selected bool) { - pal := darkSpecPalette +func drawCameraIcon2D(d *core.Drawing, pal SpecPalette, x, y float32, c *sceneformat.Camera3DDoc, selected bool) { col := pal.TextSecondary if c != nil && c.Current { col = pal.Accent.Fg @@ -1104,8 +1103,7 @@ func drawCameraIcon2D(d *core.Drawing, x, y float32, c *sceneformat.Camera3DDoc, Fill().Restore() } -func drawReflectionProbeIcon2D(d *core.Drawing, x, y float32, p *sceneformat.ReflectionProbeDoc, selected bool) { - pal := darkSpecPalette +func drawReflectionProbeIcon2D(d *core.Drawing, pal SpecPalette, x, y float32, p *sceneformat.ReflectionProbeDoc, selected bool) { col := pal.Accent.Fg if p != nil && p.Cubemap == "" { col = pal.TextFaint @@ -1121,8 +1119,7 @@ func drawReflectionProbeIcon2D(d *core.Drawing, x, y float32, p *sceneformat.Ref d.Save().SetFillColor(specAlpha(pal.TextPrimary, 0.9)).BeginPath().Arc(x-1.8, y-1.8, 1.8, 0, float32(2*math.Pi), false).Fill().Restore() } -func drawLightProbeGridIcon2D(d *core.Drawing, x, y float32, g *sceneformat.LightProbeGridDoc, selected bool) { - pal := darkSpecPalette +func drawLightProbeGridIcon2D(d *core.Drawing, pal SpecPalette, x, y float32, g *sceneformat.LightProbeGridDoc, selected bool) { col := pal.Warning.Fg if g != nil && g.Data == "" { col = pal.TextMuted @@ -1203,7 +1200,7 @@ func (e *Editor) drawSceneHandles3D(d *core.Drawing, w, h float32) { } if obj.Light != nil { - col := lightIconColor(obj.Light) + col := lightIconColor(spec, obj.Light) soft := col.Faded(0.65) switch obj.Light.Kind { case sceneformat.LightDirectional: diff --git a/packages/game/editor/inspector.go b/packages/game/editor/inspector.go index cb065df2c..c1e152b9d 100644 --- a/packages/game/editor/inspector.go +++ b/packages/game/editor/inspector.go @@ -1343,7 +1343,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o return fieldRow(label, control) } return inspectorFieldRow( - ed, rev, objID, "", overrideKey, "inspector-"+overrideKey, + cx, ed, rev, objID, "", overrideKey, "inspector-"+overrideKey, labelWithOverride(overrideKey, withTooltip(core.Text{ Content: label, MaxLines: 1, @@ -1405,7 +1405,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o } } ctrl := controlWithRevert(overrideKey, label, inspectorNumberBox(cx, ed, cfg)) - return inspectorFieldRow(ed, rev, objID, component, fieldKey, cfg.TestID, lbl, ctrl) + return inspectorFieldRow(cx, ed, rev, objID, component, fieldKey, cfg.TestID, lbl, ctrl) } // multiAxisRow renders a compact X Y (or X Y Z in 3D) row with inline scrubbable axis labels, @@ -1496,6 +1496,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o } } return inspectorFieldRowKeys( + cx, ed, rev, objID, @@ -1666,7 +1667,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o }) } nodes = append(nodes, inspectorFieldRow( - ed, rev, objID, "", "name", "inspector-name", + cx, ed, rev, objID, "", "name", "inspector-name", labelWithOverride("name", withTooltip(core.Text{ Content: ed.T("inspector.name"), MaxLines: 1, @@ -2532,7 +2533,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Children: []core.Node{lblInner}, } } - propRows = append(propRows, inspectorFieldRow(ed, rev, objID, "", "prop:"+key, cfg.TestID, lbl, controlWithRevert(ovKey, key, withTrailing(inspectorNumberBox(cx, ed, cfg), del)))) + propRows = append(propRows, inspectorFieldRow(cx, ed, rev, objID, "", "prop:"+key, cfg.TestID, lbl, controlWithRevert(ovKey, key, withTrailing(inspectorNumberBox(cx, ed, cfg), del)))) case float64, float32: cfg := inspectorNumberFieldCfg{ TestID: "inspector-prop-" + key, @@ -2570,7 +2571,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o Children: []core.Node{lblInner}, } } - propRows = append(propRows, inspectorFieldRow(ed, rev, objID, "", "prop:"+key, cfg.TestID, lbl, controlWithRevert(ovKey, key, withTrailing(inspectorNumberBox(cx, ed, cfg), del)))) + propRows = append(propRows, inspectorFieldRow(cx, ed, rev, objID, "", "prop:"+key, cfg.TestID, lbl, controlWithRevert(ovKey, key, withTrailing(inspectorNumberBox(cx, ed, cfg), del)))) default: ctrl := typedFieldControl( "inspector-prop-"+key, @@ -2596,7 +2597,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o if isLocal { lbl = plainLabel(key, "", "") } - propRows = append(propRows, inspectorFieldRow(ed, rev, objID, "", "prop:"+key, "inspector-prop-"+key, lbl, controlWithRevert(ovKey, key, withTrailing(ctrl, del)))) + propRows = append(propRows, inspectorFieldRow(cx, ed, rev, objID, "", "prop:"+key, "inspector-prop-"+key, lbl, controlWithRevert(ovKey, key, withTrailing(ctrl, del)))) } } } @@ -2745,7 +2746,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o if isLocal { lbl = plainLabel(field.Name, labelID, tip) } - compRows = append(compRows, inspectorFieldRow(ed, rev, objID, cn, field.Name, testID, lbl, controlWithRevert(ovKey, field.Name, ctrl))) + compRows = append(compRows, inspectorFieldRow(cx, ed, rev, objID, cn, field.Name, testID, lbl, controlWithRevert(ovKey, field.Name, ctrl))) } matchedFields := len(compRows) if matchedFields > 0 { @@ -2917,7 +2918,7 @@ func inspectorFieldsView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], o if isLocal { lbl = plainLabel(fk, labelID, "") } - compRows = append(compRows, inspectorFieldRow(ed, rev, objID, cn, fk, testID, lbl, controlWithRevert(ovKey, fk, ctrl))) + compRows = append(compRows, inspectorFieldRow(cx, ed, rev, objID, cn, fk, testID, lbl, controlWithRevert(ovKey, fk, ctrl))) } } if len(compRows) > 0 || (!filtering && len(m) == 0) || (filtering && matchesInspectorFilter(q, compTitle, cn)) { diff --git a/packages/game/editor/inspector_scrub.go b/packages/game/editor/inspector_scrub.go index d4716685c..55b3bb5df 100644 --- a/packages/game/editor/inspector_scrub.go +++ b/packages/game/editor/inspector_scrub.go @@ -583,6 +583,7 @@ func inspectorTitledSection( // inspectorFieldRow wraps one inspector row with Spec label styling, optional review amber bar // ("was · in review"), and optional problem pill beneath the control. func inspectorFieldRow( + cx *core.Scope, ed *Editor, rev *core.Signal[uint64], objID, component, fieldKey, fieldTestID string, @@ -593,12 +594,13 @@ func inspectorFieldRow( if fieldKey != "" { keys = []string{fieldKey} } - return inspectorFieldRowKeys(ed, rev, objID, component, keys, fieldTestID, labelNode, control) + return inspectorFieldRowKeys(cx, ed, rev, objID, component, keys, fieldTestID, labelNode, control) } // inspectorFieldRowKeys wraps an inspector row whose controls edit one or more field keys // (such as compact X/Y/Z rows), surfacing review changes and field problems for every key. func inspectorFieldRowKeys( + cx *core.Scope, ed *Editor, rev *core.Signal[uint64], objID, component string, @@ -658,7 +660,7 @@ func inspectorFieldRowKeys( if _, ok := reviewsText(); ok { return core.Style{ Borders: core.Edges{Left: 2}, - BorderColor: ed.activeSpecPalette().Changed.Fg, + BorderColor: ed.SpecPalette(cx).Changed.Fg, Padding: core.Edges{Left: 6}, } } diff --git a/packages/game/editor/lights2d_editor.go b/packages/game/editor/lights2d_editor.go index 433b5d48a..32dbd9563 100644 --- a/packages/game/editor/lights2d_editor.go +++ b/packages/game/editor/lights2d_editor.go @@ -785,19 +785,16 @@ func (e *Editor) cancelLightingDrag2D() bool { return true } -var ( - lightOverlayColor = specAlpha(darkSpecPalette.Warning.Fg, 0.85) - lightOverlaySubtleColor = specAlpha(darkSpecPalette.Warning.Fg, 0.45) - occluderOverlayColor = specAlpha(darkSpecPalette.Agent.Fg, 0.9) - occluderOverlaySubtle = specAlpha(darkSpecPalette.Agent.Fg, 0.45) - occluderEdgeMidFillColor = CompositeOver(specAlpha(darkSpecPalette.TextPrimary, 0.65), darkSpecPalette.Agent.Fg) -) - // drawLightingOverlays2D draws light origin markers and occluder outlines for all visible objects in edit mode so lights and occluders without sprites remain easy to locate and select. func (e *Editor) drawLightingOverlays2D(d *core.Drawing, scene *sceneformat.BuiltScene) { if d == nil || scene == nil || e.playing { return } + pal := e.activeSpecPalette() + lightOverlayColor := specAlpha(pal.Warning.Fg, 0.85) + lightOverlaySubtleColor := specAlpha(pal.Warning.Fg, 0.45) + occluderOverlayColor := specAlpha(pal.Agent.Fg, 0.9) + occluderOverlaySubtle := specAlpha(pal.Agent.Fg, 0.45) for _, layer := range scene.Layers { if !layer.Visible || layer.Space != sceneformat.SpaceWorld { continue @@ -858,6 +855,15 @@ func (e *Editor) drawLightingOverlays2D(d *core.Drawing, scene *sceneformat.Buil // drawSelectedLightingHandles2D draws the interactive light radius/spot-angle handles and occluder rect/polygon shape handles for the currently selected object. func (e *Editor) drawSelectedLightingHandles2D(d *core.Drawing) { + pal := e.activeSpecPalette() + lightOverlayColor := specAlpha(pal.Warning.Fg, 0.85) + lightOverlaySubtleColor := specAlpha(pal.Warning.Fg, 0.45) + occluderOverlayColor := specAlpha(pal.Agent.Fg, 0.9) + occluderEdgeMidFillColor := CompositeOver(specAlpha(pal.TextPrimary, 0.65), pal.Agent.Fg) + gizmoColorRing := specAlpha(pal.Accent.Edge, 0.8) + gizmoColorCenter := pal.TextPrimary + gizmoColorActive := pal.Warning.Fg + active := e.drag2D.handle pick := func(h GizmoHandle2D, c core.Color) core.Color { if h == active { diff --git a/packages/game/editor/materials_ui.go b/packages/game/editor/materials_ui.go index 01d980b83..791b14474 100644 --- a/packages/game/editor/materials_ui.go +++ b/packages/game/editor/materials_ui.go @@ -183,7 +183,8 @@ func materialEditorPanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c } // Base color and emissive color controls: ColorWell + ColorPicker + text Input + Clear button. - colorControl := func(testPrefix, label, placeholder string, emissive bool, fallback core.Color, getStr func() string, setStr func(string) error) core.Node { + colorControl := func(testPrefix, label, placeholder string, emissive bool, getStr func() string, setStr func(string) error) core.Node { + fallback, _ := core.ParseColor(placeholder) pickerOpen := core.NewSignal(cx, false) cx.Effect(func() { if disabled() { @@ -430,7 +431,6 @@ func materialEditorPanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c ed.T("material.field.baseColor"), "#ffffff", false, - colorFromRGBA8(255, 255, 255, 255), func() string { return currentMat().BaseColor }, ed.SetMaterialBaseColor, )), @@ -439,7 +439,6 @@ func materialEditorPanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) c ed.T("material.field.emissiveLabel"), "#000000", true, - colorFromRGBA8(0, 0, 0, 255), func() string { return currentMat().Emissive }, ed.SetMaterialEmissive, )), diff --git a/packages/game/editor/navregion2d_editor.go b/packages/game/editor/navregion2d_editor.go index a4b9fa4f4..4cf902f9f 100644 --- a/packages/game/editor/navregion2d_editor.go +++ b/packages/game/editor/navregion2d_editor.go @@ -558,22 +558,6 @@ func (e *Editor) updateNavRegionDrag2D(x, y float32) { e.notify() } -var ( - navMesh2DFillColor = specAlpha(darkSpecPalette.Accent.Fg, 0.2) - navMesh2DEdgeColor = specAlpha(darkSpecPalette.Accent.Edge, 0.78) - navMesh2DPortalColor = specAlpha(darkSpecPalette.Agent.Fg, 0.45) - navRegionWalkableColor = specAlpha(darkSpecPalette.Added.Fg, 0.92) - navRegionWalkableSubtle = specAlpha(darkSpecPalette.Added.Fg, 0.5) - navRegionObstacleColor = specAlpha(darkSpecPalette.Removed.Fg, 0.92) - navRegionObstacleSubtle = specAlpha(darkSpecPalette.Removed.Fg, 0.5) - navRegionEdgeMidFillColor = CompositeOver(specAlpha(darkSpecPalette.TextPrimary, 0.6), darkSpecPalette.Added.Fg) - navRegionObstacleMidFill = CompositeOver(specAlpha(darkSpecPalette.TextPrimary, 0.6), darkSpecPalette.Removed.Fg) - navPathLineColor = specAlpha(darkSpecPalette.Warning.Fg, 0.95) - navPathBlockedColor = specAlpha(darkSpecPalette.Removed.Fg, 0.85) - navPathStartColor = darkSpecPalette.Added.Fg - navPathEndColor = darkSpecPalette.Changed.Fg -) - // drawNavMesh2DOverlay draws the baked 2D navigation mesh polygons and portals, authored navregion2d outlines, and the active test-path preview in the 2D edit viewport. func (e *Editor) drawNavMesh2DOverlay(d *core.Drawing, scene *sceneformat.BuiltScene) { if d == nil || scene == nil || e.playing { @@ -584,6 +568,14 @@ func (e *Editor) drawNavMesh2DOverlay(d *core.Drawing, scene *sceneformat.BuiltS if !showMesh && !showTool { return } + pal := e.activeSpecPalette() + navMesh2DFillColor := specAlpha(pal.Accent.Fg, 0.2) + navMesh2DEdgeColor := specAlpha(pal.Accent.Edge, 0.78) + navMesh2DPortalColor := specAlpha(pal.Agent.Fg, 0.45) + navRegionWalkableColor := specAlpha(pal.Added.Fg, 0.92) + navRegionWalkableSubtle := specAlpha(pal.Added.Fg, 0.5) + navRegionObstacleColor := specAlpha(pal.Removed.Fg, 0.92) + navRegionObstacleSubtle := specAlpha(pal.Removed.Fg, 0.5) // 1. Built convex navigation mesh overlay (filled polygons, outer edges, shared portals). if showMesh && scene.NavBake2D != nil && len(scene.NavBake2D.Polygons) > 0 { @@ -658,6 +650,12 @@ func (e *Editor) drawNavPathPreview2D(d *core.Drawing) { if !p.HasStart && !p.HasEnd { return } + pal := e.activeSpecPalette() + navPathLineColor := specAlpha(pal.Warning.Fg, 0.95) + navPathBlockedColor := specAlpha(pal.Removed.Fg, 0.85) + navPathStartColor := pal.Added.Fg + navPathEndColor := pal.Changed.Fg + gizmoColorCenter := pal.TextPrimary d.Save() if p.HasStart && p.HasEnd { if p.Found && len(p.Path) >= 2 { @@ -701,12 +699,15 @@ func (e *Editor) drawSelectedNavRegionHandles2D(d *core.Drawing) { if !ok { return } + pal := e.activeSpecPalette() + gizmoColorCenter := pal.TextPrimary + gizmoColorActive := pal.Warning.Fg active := e.drag2D.handle - stroke := navRegionWalkableColor - midFill := navRegionEdgeMidFillColor + stroke := specAlpha(pal.Added.Fg, 0.92) + midFill := CompositeOver(specAlpha(pal.TextPrimary, 0.6), pal.Added.Fg) if ng.dbg.Mode == "obstacle" { - stroke = navRegionObstacleColor - midFill = navRegionObstacleMidFill + stroke = specAlpha(pal.Removed.Fg, 0.92) + midFill = CompositeOver(specAlpha(pal.TextPrimary, 0.6), pal.Removed.Fg) } d.Save() for i, mid := range ng.edgeMids { diff --git a/packages/game/editor/physics_debug.go b/packages/game/editor/physics_debug.go index 142d2a20b..ab25cf199 100644 --- a/packages/game/editor/physics_debug.go +++ b/packages/game/editor/physics_debug.go @@ -10,8 +10,7 @@ import ( "github.com/nsgo-dev/nsgo/core" ) -func physicsDebugColor(isTrigger bool, bodyKind string) core.Color { - pal := darkSpecPalette +func physicsDebugColor(pal SpecPalette, isTrigger bool, bodyKind string) core.Color { if isTrigger { return specAlpha(pal.Warning.Fg, 0.95) } @@ -73,18 +72,19 @@ func (e *Editor) drawPhysicsDebug2D(d *core.Drawing, scene *sceneformat.BuiltSce } else { applyAffine(d, e.layerAffineFor(layer.Space, layer.ParallaxX, layer.ParallaxY)) } + pal := e.activeSpecPalette() for _, item := range shapes { - drawPhysicsShape2D(d, item) + drawPhysicsShape2D(d, pal, item) } d.Restore() } } -func drawPhysicsShape2D(d *core.Drawing, item sceneformat.PhysicsDebugShape2D) { +func drawPhysicsShape2D(d *core.Drawing, pal SpecPalette, item sceneformat.PhysicsDebugShape2D) { if item.Shape.Empty() { return } - col := physicsDebugColor(item.IsTrigger, item.BodyKind) + col := physicsDebugColor(pal, item.IsTrigger, item.BodyKind) d.Save() d.SetStrokeColor(col).SetLineWidth(1.5) switch item.Shape.Kind { @@ -186,7 +186,7 @@ func (e *Editor) drawPhysicsShape3D(d *core.Drawing, item sceneformat.PhysicsDeb if len(edges) == 0 { return } - col := physicsDebugColor(item.IsTrigger, item.BodyKind) + col := physicsDebugColor(e.activeSpecPalette(), item.IsTrigger, item.BodyKind) d.Save().SetStrokeColor(col).SetLineWidth(1.5).BeginPath() hasSeg := false for _, seg := range edges { diff --git a/packages/game/editor/play_marks_ui.go b/packages/game/editor/play_marks_ui.go index cc277228b..fbff61496 100644 --- a/packages/game/editor/play_marks_ui.go +++ b/packages/game/editor/play_marks_ui.go @@ -5,20 +5,32 @@ import ( "math" "strings" + "github.com/nsgo-dev/nsgo/base" "github.com/nsgo-dev/nsgo/core" "github.com/nsgo-dev/nsgo/icons/lucide" "github.com/nsgo-dev/nsgo/ui" ) // Spec-derived composite tints for Play mode header and panic card (all derived strictly from spec_theme.yaml tokens). -var ( - specPlayRunBg = CompositeOver(specAlpha(darkSpecPalette.Added.Fg, 0.06), darkSpecPalette.Bg) - specPlayRunBorder = specAlpha(darkSpecPalette.Added.Fg, 0.35) - specPlayPauseBg = CompositeOver(specAlpha(darkSpecPalette.Warning.Fg, 0.05), darkSpecPalette.Bg) - specPanicCardBg = CompositeOver(specAlpha(darkSpecPalette.Removed.Fg, 0.06), darkSpecPalette.Raised) - specAgentBubbleBg = CompositeOver(specAlpha(darkSpecPalette.Accent.Fg, 0.08), darkSpecPalette.Raised) - specAgentStepDoneB = darkSpecPalette.Added.Fill -) +func playRunBg(p SpecPalette) core.Color { + return CompositeOver(specAlpha(p.Added.Fg, 0.06), p.Bg) +} + +func playRunBorder(p SpecPalette) core.Color { + return specAlpha(p.Added.Fg, 0.35) +} + +func playPauseBg(p SpecPalette) core.Color { + return CompositeOver(specAlpha(p.Warning.Fg, 0.05), p.Bg) +} + +func playPanicCardBg(p SpecPalette) core.Color { + return CompositeOver(specAlpha(p.Removed.Fg, 0.06), p.Raised) +} + +func playAgentBubbleBg(p SpecPalette) core.Color { + return CompositeOver(specAlpha(p.Accent.Fg, 0.08), p.Raised) +} // playModeBarView renders the Play Mode control bar below the main toolbar while local Play mode is active // (and not already showing the Remote Play bar), styled strictly with Spec.dc.html tokens matching PlayMode.dc.html. @@ -29,34 +41,44 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. return ed.Playing() && !ed.RemoteConnected() && !ed.RemoteConnecting() }, Then: func(cx *core.Scope) core.Node { + pal := ed.SpecPalette(cx) scaleBtn := func(scale float64, label string) core.Node { id := fmt.Sprintf("play-timescale-%g", scale) - return ui.Button{ - TestID: id, - Text: label, - Label: fmt.Sprintf("Set play time scale to %s", label), - Size: ui.SizeSmall, - Variant: ui.ButtonGhost, - Color: func() core.Color { + return base.Button{ + TestID: id, + Label: fmt.Sprintf("Set play time scale to %s", label), + StyleFunc: func() core.Style { _ = rev.Get() + bg := core.Color(0) if math.Abs(ed.PlayTimeScale()-scale) < 1e-6 { - return specLineRaised + bg = pal.LineRaised + } + return core.Style{ + Height: core.Pt(26), + Padding: core.Symmetric(0, 8), + CornerRadius: 6, + Direction: core.Row, + AlignItems: core.AlignCenter, + JustifyContent: core.JustifyCenter, + Background: bg, + Cursor: core.CursorPointer, + Hover: &core.Style{Background: pal.LineRaised}, + FocusVisible: pal.FocusRing(-2), } - return core.Color(0) - }, - TextStyle: core.Style{ - FontSize: 11, - FontWeight: 500, - Color: specText, - }, - Style: core.Style{ - Height: core.Pt(26), - Padding: core.Symmetric(0, 8), - CornerRadius: 6, }, - OnPress: func() { + OnPress: func(core.PressEvent) { ed.SetPlayTimeScale(scale) }, + Children: []core.Node{ + core.Text{ + Content: label, + Style: core.Style{ + FontSize: 11, + FontWeight: 500, + Color: pal.TextSecondary, + }, + }, + }, } } @@ -77,13 +99,13 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. _ = rev.Get() if ed.PlayPaused() { return core.Style{ - Background: specPlayPauseBg, - BorderColor: specWarningEdge, + Background: playPauseBg(pal), + BorderColor: pal.Warning.Edge, } } return core.Style{ - Background: specPlayRunBg, - BorderColor: specPlayRunBorder, + Background: playRunBg(pal), + BorderColor: playRunBorder(pal), } }, Children: []core.Node{ @@ -103,13 +125,13 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. _ = rev.Get() if ed.PlayPaused() { return core.Style{ - Background: specWarningFill, - BorderColor: specWarningEdge, + Background: pal.Warning.Fill, + BorderColor: pal.Warning.Edge, } } return core.Style{ - Background: specAddedFill, - BorderColor: specAddedEdge, + Background: pal.Added.Fill, + BorderColor: specAlpha(pal.Added.Edge, 0.45), } }, Children: []core.Node{ @@ -118,9 +140,9 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. StyleFunc: func() core.Style { _ = rev.Get() if ed.PlayPaused() { - return core.Style{Background: specWarning} + return core.Style{Background: pal.Warning.Fg} } - return core.Style{Background: specAdded} + return core.Style{Background: pal.Added.Fg} }, }, core.Text{ @@ -144,9 +166,9 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. StyleFunc: func() core.Style { _ = rev.Get() if ed.PlayPaused() { - return core.Style{Color: specWarning} + return core.Style{Color: pal.Warning.Fg} } - return core.Style{Color: specText} + return core.Style{Color: pal.TextSecondary} }, }, }, @@ -160,9 +182,9 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. Gap: 2, Padding: core.All(3), CornerRadius: 8, - Background: specRaised, + Background: pal.Raised, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: pal.LineRaised, }, Children: []core.Node{ ui.Button{ @@ -183,7 +205,7 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. }, Size: ui.SizeSmall, Variant: ui.ButtonGhost, - Tint: func() core.Color { return specTextStrong }, + Tint: func() core.Color { return pal.TextPrimary }, Style: core.Style{Width: core.Pt(30), Height: core.Pt(26), CornerRadius: 6}, OnPress: func() { ed.SetPlayPaused(!ed.PlayPaused()) }, }, @@ -197,7 +219,7 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. _ = rev.Get() return !ed.PlayPaused() }, - Tint: func() core.Color { return specTextStrong }, + Tint: func() core.Color { return pal.TextPrimary }, Style: core.Style{Width: core.Pt(30), Height: core.Pt(26), CornerRadius: 6}, OnPress: func() { ed.StepPlay(1) @@ -207,7 +229,7 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. Style: core.Style{ Width: core.Pt(1), Height: core.Pt(16), - Background: specLineRaised, + Background: pal.LineRaised, Margin: core.Symmetric(0, 4), }, }, @@ -236,17 +258,21 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. } return fmt.Sprintf("Mark %s", key) }, - Color: func() core.Color { return specRaised }, - Tint: func() core.Color { return specText }, + Color: func() core.Color { return pal.Raised }, + Tint: func() core.Color { return pal.TextSecondary }, TextStyle: core.Style{ FontSize: 12, FontWeight: 500, - Color: specText, + Color: pal.TextSecondary, }, Style: core.Style{ Height: core.Pt(30), Padding: core.Symmetric(0, 10), CornerRadius: 8, + Background: pal.Raised, + BorderWidth: 1, + BorderColor: pal.LineRaised, + Hover: &core.Style{Background: pal.LineRaised}, }, OnPress: func() { _, err := ed.AddPlayMark() @@ -260,17 +286,21 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. Label: "Pause and ask the agent about this frame (" + cx.KeyLabel("mod+l") + ")", Size: ui.SizeSmall, Variant: ui.ButtonGhost, - Color: func() core.Color { return specRaised }, - Tint: func() core.Color { return specAgent }, + Color: func() core.Color { return pal.Raised }, + Tint: func() core.Color { return pal.Agent.Fg }, TextStyle: core.Style{ FontSize: 12, FontWeight: 500, - Color: specText, + Color: pal.TextSecondary, }, Style: core.Style{ Height: core.Pt(30), Padding: core.Symmetric(0, 10), CornerRadius: 8, + Background: pal.Raised, + BorderWidth: 1, + BorderColor: pal.LineRaised, + Hover: &core.Style{Background: pal.LineRaised}, }, OnPress: func() { ed.report(ed.OpenAskFrozenFrame()) @@ -283,17 +313,19 @@ func playModeBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core. Label: "Stop Play mode", Size: ui.SizeSmall, Variant: ui.ButtonGhost, - Color: func() core.Color { return specTextStrong }, - Tint: func() core.Color { return specBg }, + Color: func() core.Color { return pal.TextPrimary }, + Tint: func() core.Color { return pal.OnTextPrimary }, TextStyle: core.Style{ FontSize: 12, FontWeight: 600, - Color: specBg, + Color: pal.OnTextPrimary, }, Style: core.Style{ Height: core.Pt(30), Padding: core.Symmetric(0, 12), CornerRadius: 8, + Background: pal.TextPrimary, + Hover: &core.Style{Background: pal.PrimaryHover}, }, OnPress: func() { ed.report(ed.Stop()) @@ -316,15 +348,16 @@ func playReplayFooterView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) return ed.Playing() || ed.RemoteConnected() }, Then: func(cx *core.Scope) core.Node { + pal := ed.SpecPalette(cx) return core.View{ TestID: "play-replay-footer", Style: core.Style{ FlexShrink: 0, Padding: core.Symmetric(10, 8), Gap: 4, - Background: specBg, + Background: pal.Bg, Borders: core.Edges{Top: 1}, - BorderColor: specLine, + BorderColor: pal.Line, }, Children: []core.Node{ core.Text{ @@ -332,7 +365,7 @@ func playReplayFooterView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) Style: core.Style{ FontSize: 11, FontWeight: core.FontWeightSemibold, - Color: specTextMuted, + Color: pal.TextFaint, }, }, core.Text{ @@ -344,14 +377,14 @@ func playReplayFooterView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) Style: core.Style{ FontSize: 12, FontVariant: core.FontTabularNums, - Color: specText, + Color: pal.TextSecondary, }, }, core.Text{ Content: "Saved as an input recording when you mark or ask", Style: core.Style{ FontSize: 11, - Color: specTextMuted, + Color: pal.TextFaint, }, }, core.Show{ @@ -360,6 +393,7 @@ func playReplayFooterView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) return ed.PlayLastReplayPath() != "" }, Then: func(cx *core.Scope) core.Node { + p := ed.SpecPalette(cx) return core.Text{ TestID: "play-replay-last-path", ContentFunc: func() string { @@ -368,7 +402,7 @@ func playReplayFooterView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) }, Style: core.Style{ FontSize: 10.5, - Color: specTextSecondary, + Color: p.TextMuted, }, } }, @@ -406,6 +440,7 @@ func playViewportOverlaysView(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 return ed.PlayAgentPill() != "" }, Then: func(cx *core.Scope) core.Node { + pal := ed.SpecPalette(cx) return core.View{ TestID: "play-agent-pill", PointerEvents: core.PointerEventsNone, @@ -419,9 +454,9 @@ func playViewportOverlaysView(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Gap: 6, Padding: core.Symmetric(0, 10), CornerRadius: 12, - Background: specBgOverlay, + Background: specAlpha(pal.PillBg, 0.92), BorderWidth: 1, - BorderColor: specAgentEdge, + BorderColor: pal.Agent.Edge, }, Children: []core.Node{ core.View{ @@ -429,7 +464,7 @@ func playViewportOverlaysView(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Width: core.Pt(6), Height: core.Pt(6), CornerRadius: 3, - Background: specAgent, + Background: pal.Agent.Fg, }, }, core.Text{ @@ -441,7 +476,7 @@ func playViewportOverlaysView(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Style: core.Style{ FontSize: 11.5, FontVariant: core.FontTabularNums, - Color: specText, + Color: pal.TextSecondary, }, }, }, @@ -455,6 +490,7 @@ func playViewportOverlaysView(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 return ed.Playing() && ed.PlayPaused() }, Then: func(cx *core.Scope) core.Node { + pal := ed.SpecPalette(cx) return core.View{ TestID: "play-paused-hint", PointerEvents: core.PointerEventsNone, @@ -467,9 +503,9 @@ func playViewportOverlaysView(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 AlignItems: core.AlignCenter, Padding: core.Symmetric(0, 12), CornerRadius: 13, - Background: specWarningFill, + Background: pal.Warning.Fill, BorderWidth: 1, - BorderColor: specWarningEdge, + BorderColor: pal.Warning.Edge, }, Children: []core.Node{ core.Text{ @@ -480,7 +516,7 @@ func playViewportOverlaysView(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Style: core.Style{ FontSize: 11.5, FontVariant: core.FontTabularNums, - Color: specWarning, + Color: pal.Warning.Fg, }, }, }, @@ -500,13 +536,14 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 return ed.AskFrozenFrameOpen() }, Then: func(cx *core.Scope) core.Node { + pal := ed.SpecPalette(cx) cx.OnKeyWith("escape", core.KeyOptions{When: core.KeyAlways}, func() { if ed.AskFrozenFrameOpen() { ed.CloseAskFrozenFrame() } }) - chip := func(text string, dot core.Color) core.Node { + chip := func(p SpecPalette, text string, dot core.Color) core.Node { return core.View{ Style: core.Style{ Direction: core.Row, @@ -515,9 +552,9 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Height: core.Pt(22), Padding: core.Symmetric(0, 8), CornerRadius: 6, - Background: specPanel, + Background: p.Panel, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: p.LineRaised, }, Children: []core.Node{ core.View{ @@ -532,7 +569,7 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Content: text, Style: core.Style{ FontSize: 11, - Color: specTextSecondary, + Color: p.TextMuted, }, }, }, @@ -556,9 +593,9 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Padding: core.All(12), Gap: 10, CornerRadius: 12, - Background: specRaised, + Background: pal.Raised, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: pal.LineRaised, }, Children: []core.Node{ // Header: "Ask about frame N" + "game frozen" @@ -579,14 +616,14 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Style: core.Style{ FontSize: 14, FontWeight: core.FontWeightSemibold, - Color: specTextStrong, + Color: pal.TextPrimary, }, }, core.Text{ Content: "game frozen", Style: core.Style{ FontSize: 11.5, - Color: specTextMuted, + Color: pal.TextFaint, }, }, }, @@ -598,9 +635,9 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Height: core.Pt(110), CornerRadius: 8, Overflow: core.Hidden, - Background: specBg, + Background: pal.Bg, BorderWidth: 1, - BorderColor: specWarningEdge, + BorderColor: pal.Warning.Edge, }, Children: []core.Node{ core.Canvas{ @@ -610,7 +647,7 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Draw: func(d *core.Drawing, size core.Size) { _ = rev.Get() d.Save() - d.SetFillColor(specBg).FillRect(0, 0, float32(size.Width), float32(size.Height)) + d.SetFillColor(ed.activeSpecPalette().Bg).FillRect(0, 0, float32(size.Width), float32(size.Height)) // Preserve the main viewport's canvas size so drawing the thumbnail // does not overwrite Editor.canvasW/canvasH. prevW, prevH := ed.canvasW, ed.canvasH @@ -641,6 +678,7 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 } }) return core.Dynamic(func(cx *core.Scope) core.Node { + p := ed.SpecPalette(cx) k := chipsMemo.Get() sec := float64(k.rollingFrames) / float64(k.rate) replayLabel := fmt.Sprintf("Replay · %s frames", formatPlayFrameNumber(k.rollingFrames)) @@ -648,20 +686,20 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 replayLabel = fmt.Sprintf("Replay · last %.0f s", math.Round(sec)) } chips := []core.Node{ - chip("Frame "+formatPlayFrameNumber(k.frame), specTextSecondary), - chip(replayLabel, specTextSecondary), + chip(p, "Frame "+formatPlayFrameNumber(k.frame), p.TextMuted), + chip(p, replayLabel, p.TextMuted), } if k.selectedID != "" { - chips = append(chips, chip(k.selectedID+" · live state", specChanged)) + chips = append(chips, chip(p, k.selectedID+" · live state", p.Changed.Fg)) } else { - chips = append(chips, chip("Live state", specAdded)) + chips = append(chips, chip(p, "Live state", p.Added.Fg)) } if k.liveChanges > 0 { unit := "live changes" if k.liveChanges == 1 { unit = "live change" } - chips = append(chips, chip(fmt.Sprintf("%d %s", k.liveChanges, unit), specChanged)) + chips = append(chips, chip(p, fmt.Sprintf("%d %s", k.liveChanges, unit), p.Changed.Fg)) } return core.View{ Style: core.Style{Direction: core.Row, Wrap: core.Wrap, Gap: 4}, @@ -688,11 +726,11 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 }, Style: core.Style{ MinHeight: core.Pt(56), - Background: specPanel, - Color: specTextStrong, + Background: pal.Panel, + Color: pal.TextPrimary, CornerRadius: 8, BorderWidth: 1, - BorderColor: specAccent, + BorderColor: pal.Accent.Edge, }, }, // Footer: "A fix comes back as a review", Cancel, Ask @@ -708,7 +746,7 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Content: "A fix comes back as a review", Style: core.Style{ FontSize: 11.5, - Color: specTextMuted, + Color: pal.TextFaint, FlexGrow: 1, }, }, @@ -719,7 +757,7 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Variant: ui.ButtonGhost, TextStyle: core.Style{ FontSize: 12, - Color: specTextSecondary, + Color: pal.TextMuted, }, Style: core.Style{ Height: core.Pt(30), @@ -735,16 +773,19 @@ func playAskFrozenFrameDialog(cx *core.Scope, ed *Editor, rev *core.Signal[uint6 Text: "Ask", Size: ui.SizeSmall, Variant: ui.ButtonGhost, - Color: func() core.Color { return specAccent }, + Color: func() core.Color { return pal.Accent.Fg }, TextStyle: core.Style{ FontSize: 12, FontWeight: core.FontWeightSemibold, - Color: specBg, // Spec contrast table: #101216 on #3B7BFF (4.88:1 AA) + Color: pal.Accent.OnFill, }, Style: core.Style{ Height: core.Pt(30), Padding: core.Symmetric(0, 14), CornerRadius: 8, + Background: pal.Accent.Fg, + Hover: &core.Style{Background: pal.AccentHover}, + Active: &core.Style{Background: pal.AccentPressed}, }, OnPress: submit, }, @@ -766,32 +807,43 @@ func shouldShowPlayInspectorTabs(ed *Editor) bool { // playInspectorTabBarView renders the Play-mode Inspector | Agent tab strip + MCP status chip at the top of InspectorView. func playInspectorTabBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.Node { + pal := ed.SpecPalette(cx) tabBtn := func(testID, label string, target PlayInspectorTab) core.Node { - return ui.Button{ - TestID: testID, - Text: label, - Size: ui.SizeSmall, - Variant: ui.ButtonGhost, - Color: func() core.Color { + return base.Button{ + TestID: testID, + Label: label, + StyleFunc: func() core.Style { _ = rev.Get() + bg := core.Color(0) if ed.PlayInspectorTab() == target { - return specAgentBubbleBg + bg = playAgentBubbleBg(pal) + } + return core.Style{ + Height: core.Pt(26), + Padding: core.Symmetric(0, 8), + CornerRadius: 6, + Direction: core.Row, + AlignItems: core.AlignCenter, + JustifyContent: core.JustifyCenter, + Background: bg, + Cursor: core.CursorPointer, + Hover: &core.Style{Background: pal.LineRaised}, + FocusVisible: pal.FocusRing(-2), } - return core.Color(0) - }, - TextStyle: core.Style{ - FontSize: 12, - FontWeight: 500, - Color: specTextStrong, - }, - Style: core.Style{ - Height: core.Pt(26), - Padding: core.Symmetric(0, 8), - CornerRadius: 6, }, - OnPress: func() { + OnPress: func(core.PressEvent) { ed.SetPlayInspectorTab(target) }, + Children: []core.Node{ + core.Text{ + Content: label, + Style: core.Style{ + FontSize: 12, + FontWeight: 500, + Color: pal.TextPrimary, + }, + }, + }, } } @@ -804,9 +856,9 @@ func playInspectorTabBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 Gap: 4, Padding: core.All(4), CornerRadius: 8, - Background: specPanel, + Background: pal.Panel, BorderWidth: 1, - BorderColor: specLine, + BorderColor: pal.Line, }, Children: []core.Node{ ui.HStack{ @@ -832,13 +884,13 @@ func playInspectorTabBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 _ = rev.Get() if ed.PlayAgentActive() { return core.Style{ - Background: specAgentTint, - BorderColor: specAgentEdge, + Background: pal.Agent.Fill, + BorderColor: pal.Agent.Edge, } } return core.Style{ - Background: specRaised, - BorderColor: specLineRaised, + Background: pal.Raised, + BorderColor: pal.LineRaised, } }, Children: []core.Node{ @@ -847,9 +899,9 @@ func playInspectorTabBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 StyleFunc: func() core.Style { _ = rev.Get() if ed.PlayAgentActive() { - return core.Style{Background: specAgent} + return core.Style{Background: pal.Agent.Fg} } - return core.Style{Background: specAdded} + return core.Style{Background: pal.Added.Fg} }, }, core.Text{ @@ -866,7 +918,7 @@ func playInspectorTabBarView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64 } return "MCP" }, - Style: core.Style{FontSize: 10.5, Color: specTextSecondary}, + Style: core.Style{FontSize: 10.5, Color: pal.TextMuted}, }, }, }, @@ -898,6 +950,7 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co }) return core.Dynamic(func(cx *core.Scope) core.Node { _ = panelKey.Get() + pal := ed.SpecPalette(cx) marks := ed.PlayMarks() unsentCount := len(ed.UnsentPlayMarks()) steps := ed.PlayAgentSteps() @@ -915,35 +968,35 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co Padding: core.Symmetric(8, 10), Gap: 4, CornerRadius: 10, - Background: specAgentBubbleBg, + Background: playAgentBubbleBg(pal), BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: pal.LineRaised, }, Children: []core.Node{ core.Text{ Content: question, - Style: core.Style{FontSize: 12, Color: specTextStrong}, + Style: core.Style{FontSize: 12, Color: pal.TextPrimary}, }, core.Text{ Content: questionMeta, - Style: core.Style{FontSize: 11, Color: specTextSecondary}, + Style: core.Style{FontSize: 11, Color: pal.TextMuted}, }, }, }) } for i, st := range steps { dotFill := core.Color(0) - dotBorder := specLineRaised - textColor := specTextMuted + dotBorder := pal.LineRaised + textColor := pal.TextFaint switch st.Status { case "done": - dotFill = specAgentStepDoneB - dotBorder = specAdded - textColor = specTextSecondary + dotFill = pal.Added.Fill + dotBorder = pal.Added.Fg + textColor = pal.TextMuted case "active": - dotFill = specAgentTint - dotBorder = specAgent - textColor = specTextStrong + dotFill = pal.Agent.Fill + dotBorder = pal.Agent.Fg + textColor = pal.TextPrimary } children = append(children, core.View{ TestID: fmt.Sprintf("play-agent-step-%d", i), @@ -980,12 +1033,12 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co children = append(children, core.Text{ TestID: "play-agent-pause-note", Content: "The game stays paused while the agent steps through the replay. Resume whenever you like; its fix comes back as a review.", - Style: core.Style{FontSize: 11, Color: specTextMuted}, + Style: core.Style{FontSize: 11, Color: pal.TextFaint}, }) } else { children = append(children, core.Text{ Content: "The agent sees the running game through the editor's MCP server: live entities, the last 60 s of replay and your marks. Ask with " + cx.KeyLabel("mod+l") + " to freeze the frame first.", - Style: core.Style{FontSize: 11.5, Color: specTextSecondary}, + Style: core.Style{FontSize: 11.5, Color: pal.TextMuted}, }) } @@ -996,7 +1049,7 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co Style: core.Style{ FontSize: 11, FontWeight: core.FontWeightSemibold, - Color: specTextMuted, + Color: pal.TextFaint, Padding: core.Edges{Top: 6}, }, }) @@ -1014,21 +1067,21 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co Height: core.Pt(32), Padding: core.Symmetric(0, 10), CornerRadius: 8, - Background: specRaised, + Background: pal.Raised, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: pal.LineRaised, }, Children: []core.Node{ core.Icon{ SVG: lucide.Flag(), - Style: core.Style{Width: core.Pt(12), Height: core.Pt(12), Color: specTextSecondary}, + Style: core.Style{Width: core.Pt(12), Height: core.Pt(12), Color: pal.TextMuted}, }, core.Text{ Content: m.TimeLabel, Style: core.Style{ FontSize: 11, FontVariant: core.FontTabularNums, - Color: specTextStrong, + Color: pal.TextPrimary, }, }, core.Text{ @@ -1036,7 +1089,7 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co Style: core.Style{ FontSize: 11, FontVariant: core.FontTabularNums, - Color: specTextMuted, + Color: pal.TextFaint, FlexGrow: 1, }, }, @@ -1044,7 +1097,7 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co Content: statusText, Style: core.Style{ FontSize: 10.5, - Color: specTextMuted, + Color: pal.TextFaint, }, }, }, @@ -1053,7 +1106,7 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co children = append(children, core.Text{ Content: "When you stop, all marks go to the agent as one thread.", - Style: core.Style{FontSize: 11, Color: specTextMuted}, + Style: core.Style{FontSize: 11, Color: pal.TextFaint}, }, ui.Button{ TestID: "play-send-marks-btn", @@ -1063,15 +1116,19 @@ func playAgentPanelView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co Disabled: func() bool { return unsentCount == 0 }, - Color: func() core.Color { return specRaised }, + Color: func() core.Color { return pal.Raised }, TextStyle: core.Style{ FontSize: 12, - Color: specText, + Color: pal.TextSecondary, }, Style: core.Style{ Height: core.Pt(30), Padding: core.Symmetric(0, 12), CornerRadius: 8, + Background: pal.Raised, + BorderWidth: 1, + BorderColor: pal.LineRaised, + Hover: &core.Style{Background: pal.LineRaised}, }, OnPress: func() { ed.SendPlayMarks() @@ -1094,6 +1151,7 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa if p == nil { return nil } + pal := ed.SpecPalette(cx) gameFrames := p.GameFrames() rtFrames := p.RuntimeFrames() @@ -1120,7 +1178,7 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Content: frame.Function, Style: core.Style{ FontSize: 11.5, - Color: specText, + Color: pal.TextSecondary, FlexGrow: 1, }, }, @@ -1132,7 +1190,7 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Variant: ui.ButtonGhost, TextStyle: core.Style{ FontSize: 11.5, - Color: specAccent, + Color: pal.Accent.Fg, }, Style: core.Style{ Height: core.Pt(20), @@ -1173,7 +1231,7 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Content: foldText, Style: core.Style{ FontSize: 11.5, - Color: specTextMuted, + Color: pal.TextFaint, FlexGrow: 1, }, }, @@ -1185,7 +1243,7 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Variant: ui.ButtonGhost, TextStyle: core.Style{ FontSize: 11.5, - Color: specAccent, + Color: pal.Accent.Fg, }, Style: core.Style{ Height: core.Pt(20), @@ -1212,11 +1270,11 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Children: []core.Node{ core.Text{ Content: f.Function, - Style: core.Style{FontSize: 11, Color: specTextMuted, FlexGrow: 1}, + Style: core.Style{FontSize: 11, Color: pal.TextFaint, FlexGrow: 1}, }, core.Text{ Content: loc, - Style: core.Style{FontSize: 11, Color: specTextMuted}, + Style: core.Style{FontSize: 11, Color: pal.TextFaint}, }, }, }) @@ -1234,9 +1292,9 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Padding: core.All(10), Gap: 6, CornerRadius: 10, - Background: specPanicCardBg, + Background: playPanicCardBg(pal), BorderWidth: 1, - BorderColor: specProblemEdge, + BorderColor: specAlpha(pal.Removed.Edge, 0.50), }, Children: []core.Node{ // Title row @@ -1249,17 +1307,17 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Children: []core.Node{ core.Icon{ SVG: lucide.TriangleAlert(), - Style: core.Style{Width: core.Pt(14), Height: core.Pt(14), Color: specProblem}, + Style: core.Style{Width: core.Pt(14), Height: core.Pt(14), Color: pal.Removed.Fg}, }, core.Text{ TestID: "output-panic-title", Content: runLabel, - Style: core.Style{FontSize: 12.5, FontWeight: core.FontWeightSemibold, Color: specTextStrong}, + Style: core.Style{FontSize: 12.5, FontWeight: core.FontWeightSemibold, Color: pal.TextPrimary}, }, core.Text{ TestID: "output-panic-meta", Content: headerMeta, - Style: core.Style{FontSize: 11.5, FontVariant: core.FontTabularNums, Color: specTextMuted}, + Style: core.Style{FontSize: 11.5, FontVariant: core.FontTabularNums, Color: pal.TextFaint}, }, }, }, @@ -1269,7 +1327,7 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Content: strings.TrimSpace(p.Message), Style: core.Style{ FontSize: 11.5, - Color: specProblem, + Color: pal.Removed.Fg, }, }, // Stack frames @@ -1291,16 +1349,19 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Text: "Ask the agent to fix", Size: ui.SizeSmall, Variant: ui.ButtonGhost, - Color: func() core.Color { return specAccent }, + Color: func() core.Color { return pal.Accent.Fg }, TextStyle: core.Style{ FontSize: 12, FontWeight: core.FontWeightSemibold, - Color: specBg, + Color: pal.Accent.OnFill, }, Style: core.Style{ Height: core.Pt(28), Padding: core.Symmetric(0, 12), CornerRadius: 8, + Background: pal.Accent.Fg, + Hover: &core.Style{Background: pal.AccentHover}, + Active: &core.Style{Background: pal.AccentPressed}, }, OnPress: func() { ed.report(ed.AskAgentToFixPanic()) @@ -1314,15 +1375,19 @@ func outputPanicCardView(cx *core.Scope, ed *Editor, p *PanicReport, runtimeExpa Disabled: func() bool { return !canReplay }, - Color: func() core.Color { return specRaised }, + Color: func() core.Color { return pal.Raised }, TextStyle: core.Style{ FontSize: 12, - Color: specText, + Color: pal.TextSecondary, }, Style: core.Style{ Height: core.Pt(28), Padding: core.Symmetric(0, 12), CornerRadius: 8, + Background: pal.Raised, + BorderWidth: 1, + BorderColor: pal.LineRaised, + Hover: &core.Style{Background: pal.LineRaised}, }, OnPress: func() { ed.report(ed.ReplayUpToPanic()) diff --git a/packages/game/editor/spec_panel_ui.go b/packages/game/editor/spec_panel_ui.go index 64b7f19f4..12f6835c0 100644 --- a/packages/game/editor/spec_panel_ui.go +++ b/packages/game/editor/spec_panel_ui.go @@ -378,8 +378,8 @@ func specButtonColors(p SpecPalette, v specButtonVariant) (bg, hover, active, fg // Spec contrast table: 18.75:1 AAA in Dark (#101216 on #FFFFFF) and Light (#FFFFFF on #101216). return p.TextPrimary, specPrimaryHover(p), p.TextSecondary, p.OnTextPrimary, p.TextPrimary case specBtnAccent: - // Spec contrast table: OnFill ink on Accent fill meets WCAG AA in both Dark and Light. - return p.Accent.Fg, p.Accent.Fg, p.Accent.Fg, p.Accent.OnFill, p.Accent.Fg + // Spec contrast table: OnFill ink on Accent fill (and hover/pressed) meets WCAG AA in both Dark and Light. + return p.Accent.Fg, p.AccentHover, p.AccentPressed, p.Accent.OnFill, p.Accent.Fg case specBtnSecondary: return p.LineRaised, hov.Over(p.LineRaised), act.Over(p.LineRaised), p.TextSecondary, p.LineRaised case specBtnGhost: diff --git a/packages/game/editor/spec_theme.go b/packages/game/editor/spec_theme.go index 903928015..72a776c8f 100644 --- a/packages/game/editor/spec_theme.go +++ b/packages/game/editor/spec_theme.go @@ -104,8 +104,6 @@ func loadSpecTheme() (*core.Theme, SpecPalette, SpecPalette) { } dark := extractSpecPalette(&th.Dark, true) light := extractSpecPalette(&th.Light, false) - th.Dark.SetColor("ring", dark.Accent.Edge) - th.Light.SetColor("ring", light.Accent.Edge) return th, dark, light } @@ -161,6 +159,8 @@ type SpecPalette struct { HoverOverlay core.Color // Subtle hover wash over surfaces (`surfaceHover`). ActiveOverlay core.Color // Subtle pressed wash over surfaces (`surfacePressed`). PrimaryHover core.Color // Hover fill for solid TextPrimary buttons (`specPrimaryHover`). + AccentHover core.Color // Hover fill for solid Accent buttons (`accentHover`). + AccentPressed core.Color // Pressed fill for solid Accent buttons (`accentPressed`). Viewport3DGround core.Color // 3D viewport ground plane (`specViewport3DGround`). Viewport3DGrid core.Color // 3D viewport grid line (`specViewport3DGrid`). AxisX core.Color // 3D X axis token (`specAxisX`, #FF6B6B dark / #C92A2A light). @@ -253,6 +253,8 @@ func extractSpecPalette(p *core.Palette, dark bool) SpecPalette { OnFill: mustPaletteColor(p, prefix+"OnFill"), } } + // Ensure ring focus token is declared directly in spec_theme.yaml. + _ = mustPaletteColor(p, "ring") return SpecPalette{ Dark: dark, Bg: mustPaletteColor(p, "specBg"), @@ -278,6 +280,8 @@ func extractSpecPalette(p *core.Palette, dark bool) SpecPalette { HoverOverlay: p.SurfaceHover, ActiveOverlay: p.SurfacePressed, PrimaryHover: mustPaletteColor(p, "specPrimaryHover"), + AccentHover: p.AccentHover, + AccentPressed: p.AccentPressed, Viewport3DGround: mustPaletteColor(p, "specViewport3DGround"), Viewport3DGrid: mustPaletteColor(p, "specViewport3DGrid"), AxisX: mustPaletteColor(p, "specAxisX"), @@ -371,8 +375,14 @@ func SpecContrastTable(p SpecPalette) []SpecContrastPair { // Filled primary and accent buttons & tags. {Name: "onAccent on accent", Foreground: p.Accent.OnFill, Background: p.Accent.Fg, MinRatio: 4.5, Usage: "Keep button, Allow once, selection name tag; weight 600"}, + {Name: "onAccent on accentHover", Foreground: p.Accent.OnFill, Background: p.AccentHover, MinRatio: 4.5, Usage: "Hovered accent button fill"}, + {Name: "onAccent on accentPressed", Foreground: p.Accent.OnFill, Background: p.AccentPressed, MinRatio: 4.5, Usage: "Pressed accent button fill"}, {Name: "onTextStrong on text strong", Foreground: p.OnTextPrimary, Background: p.TextPrimary, MinRatio: 4.5, Usage: "Primary buttons: Play, Send, Create"}, + {Name: "onTextStrong on primaryHover", Foreground: p.OnTextPrimary, Background: p.PrimaryHover, MinRatio: 4.5, Usage: "Hovered primary button fill"}, {Name: "onAgent on agent", Foreground: p.Agent.OnFill, Background: p.Agent.Fg, MinRatio: 4.5, Usage: "Text on solid agent fill"}, + {Name: "onAdded on added", Foreground: p.Added.OnFill, Background: p.Added.Fg, MinRatio: 4.5, Usage: "Text on solid added fill"}, + {Name: "onChanged on changed", Foreground: p.Changed.OnFill, Background: p.Changed.Fg, MinRatio: 4.5, Usage: "Text on solid changed fill"}, + {Name: "onWarning on warning", Foreground: p.Warning.OnFill, Background: p.Warning.Fg, MinRatio: 4.5, Usage: "Text on solid warning fill"}, {Name: "onProblem on problem", Foreground: p.Removed.OnFill, Background: p.Removed.Fg, MinRatio: 4.5, Usage: "Problem filled pill on live object"}, // Warning card & toast surface. diff --git a/packages/game/editor/spec_theme.yaml b/packages/game/editor/spec_theme.yaml index 8cf4eb0c9..b929bd131 100644 --- a/packages/game/editor/spec_theme.yaml +++ b/packages/game/editor/spec_theme.yaml @@ -16,6 +16,7 @@ dark: success: "#4FD38A" selection: "rgba(59, 123, 255, 0.24)" focus: "#3B7BFF" + ring: "#3B7BFF" scrollbar: "rgba(139, 146, 160, 0.45)" inset: "#0E1014" raised: "#171A21" @@ -92,6 +93,7 @@ light: success: "#0D7A43" selection: "rgba(29, 92, 230, 0.16)" focus: "#1D5CE6" + ring: "#1D5CE6" scrollbar: "rgba(83, 92, 110, 0.35)" inset: "#E5E9F0" raised: "#FFFFFF" diff --git a/packages/game/editor/spec_theme_test.go b/packages/game/editor/spec_theme_test.go index 98069df46..9ad6ad6ca 100644 --- a/packages/game/editor/spec_theme_test.go +++ b/packages/game/editor/spec_theme_test.go @@ -124,6 +124,15 @@ func TestSpecThemeParsesAndMapsAllRoles(t *testing.T) { if tc.p.Focus != tc.spec.Accent.Edge { t.Errorf("%s Palette.Focus = #%08X, want #%08X", tc.name, uint32(tc.p.Focus), uint32(tc.spec.Accent.Edge)) } + if ring, ok := tc.p.Color("ring"); !ok || ring != tc.spec.Accent.Edge { + t.Errorf("%s Palette.Color(ring) = #%08X (ok=%v), want #%08X (declared in spec_theme.yaml)", tc.name, uint32(ring), ok, uint32(tc.spec.Accent.Edge)) + } + if tc.spec.AccentHover == 0 || tc.spec.AccentHover != tc.p.AccentHover { + t.Errorf("%s SpecPalette.AccentHover = #%08X, want #%08X", tc.name, uint32(tc.spec.AccentHover), uint32(tc.p.AccentHover)) + } + if tc.spec.AccentPressed == 0 || tc.spec.AccentPressed != tc.p.AccentPressed { + t.Errorf("%s SpecPalette.AccentPressed = #%08X, want #%08X", tc.name, uint32(tc.spec.AccentPressed), uint32(tc.p.AccentPressed)) + } } } @@ -721,29 +730,321 @@ func TestSpecContrastTableRejectsRetiredMutedColor(t *testing.T) { } } -// #1002 Acceptance 2: Every non-test Go file in packages/game/editor outside spec_theme.go -// must use Spec theme tokens instead of core.RGB, core.RGBA, or hardcoded UI hex color literals. -// Scene content defaults (such as scene.BackgroundColor, sky/fog/light defaults, and hex input -// placeholders) stay scene data and are explicitly allowlisted below. -func TestSpecNoHardcodedColorLiteralsInEditor(t *testing.T) { - hexStringRe := regexp.MustCompile(`^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$`) +var ( + specHexColorStringRe = regexp.MustCompile(`^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$`) + specRGBColorStringRe = regexp.MustCompile(`(?i)^rgba?\s*\(\s*[0-9.+%\s,-]+\)$`) +) + +func isSpecColorStringLiteral(s string) bool { + return specHexColorStringRe.MatchString(s) || specRGBColorStringRe.MatchString(s) +} + +func exprTypeName(expr ast.Expr) string { + switch t := expr.(type) { + case *ast.Ident: + return t.Name + case *ast.SelectorExpr: + if pkg, ok := t.X.(*ast.Ident); ok { + return pkg.Name + "." + t.Sel.Name + } + return t.Sel.Name + case *ast.StarExpr: + return exprTypeName(t.X) + } + return "" +} + +// evalConstInt evaluates constant integer expressions (including hex/decimal literals, +// unary ops, integer casts like uint32(...), and constant arithmetic/bitwise ops). +func evalConstInt(expr ast.Expr) (uint64, bool) { + switch e := expr.(type) { + case *ast.ParenExpr: + return evalConstInt(e.X) + case *ast.BasicLit: + if e.Kind != token.INT { + return 0, false + } + v, err := strconv.ParseUint(strings.ReplaceAll(e.Value, "_", ""), 0, 64) + if err != nil { + return 0, false + } + return v, true + case *ast.UnaryExpr: + v, ok := evalConstInt(e.X) + if !ok { + return 0, false + } + switch e.Op { + case token.ADD: + return v, true + case token.SUB: + return uint64(-int64(v)), true + case token.XOR: + return ^v, true + } + return 0, false + case *ast.BinaryExpr: + lv, lok := evalConstInt(e.X) + rv, rok := evalConstInt(e.Y) + if !lok || !rok { + return 0, false + } + switch e.Op { + case token.OR: + return lv | rv, true + case token.AND: + return lv & rv, true + case token.XOR: + return lv ^ rv, true + case token.SHL: + return lv << rv, true + case token.SHR: + return lv >> rv, true + case token.ADD: + return lv + rv, true + case token.SUB: + return lv - rv, true + case token.MUL: + return lv * rv, true + case token.QUO: + if rv == 0 { + return 0, false + } + return lv / rv, true + } + return 0, false + case *ast.CallExpr: + if len(e.Args) == 1 { + if id, ok := e.Fun.(*ast.Ident); ok { + switch id.Name { + case "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "int", "int8", "int16", "int32", "int64", "byte": + return evalConstInt(e.Args[0]) + } + } + } + return 0, false + } + return 0, false +} - // Explicit minimal allowlist for scene-content data defaults & hex input placeholders (never UI chrome). - allowedHexStringFiles := map[string]bool{ - "demo.go": true, // default demo scene BackgroundColor - "environment_panel.go": true, // default 3D sky/fog/directional-light scene data and hex placeholders - "first_run.go": true, // first-run starter scene BackgroundColor - "inspector_room.go": true, // room transition tint hex field placeholder - "inspector_scene.go": true, // scene BackgroundColor hex field placeholder - "materials_ui.go": true, // material albedo/emissive hex field placeholders - "scene3d_edit.go": true, // default 3D light scene data colors - "state.go": true, // default new scene BackgroundColor +// isConstNumericExpr reports whether expr is composed strictly of numeric literals, +// numeric casts, and constant arithmetic/bitwise operators (no runtime variables or calls). +func isConstNumericExpr(expr ast.Expr) bool { + switch e := expr.(type) { + case *ast.ParenExpr: + return isConstNumericExpr(e.X) + case *ast.BasicLit: + return e.Kind == token.INT || e.Kind == token.FLOAT + case *ast.UnaryExpr: + return isConstNumericExpr(e.X) + case *ast.BinaryExpr: + return isConstNumericExpr(e.X) && isConstNumericExpr(e.Y) + case *ast.CallExpr: + if len(e.Args) == 1 { + if id, ok := e.Fun.(*ast.Ident); ok { + switch id.Name { + case "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "int", "int8", "int16", "int32", "int64", "float32", "float64", "byte": + return isConstNumericExpr(e.Args[0]) + } + } + } + return false } - allowedCoreColorHexFiles := map[string]bool{ - "particles.go": true, // default particle emitter ramp stop data - "particles_ui.go": true, // default new particle color stop data + return false +} + +// allowedColorStringInContext returns true only for the explicitly narrowed scene-content +// data defaults and hex input placeholders (never UI chrome like core.Style). +func allowedColorStringInContext(relPath string, stack []ast.Node) bool { + if len(stack) < 2 { + return false + } + // Check immediate parent. + parent := stack[len(stack)-2] + if kv, ok := parent.(*ast.KeyValueExpr); ok { + keyIdent, ok := kv.Key.(*ast.Ident) + if !ok { + return false + } + key := keyIdent.Name + var structType string + if len(stack) >= 3 { + if cl, ok := stack[len(stack)-3].(*ast.CompositeLit); ok { + structType = exprTypeName(cl.Type) + } + } + switch relPath { + case "demo.go", "first_run.go", "state.go": + return key == "BackgroundColor" && structType == "sceneformat.SceneDoc" + case "inspector_room.go", "inspector_scene.go": + return key == "Placeholder" && structType == "ui.Input" + case "environment_panel.go": + if key == "Placeholder" && structType == "ui.Input" { + return true + } + switch structType { + case "sceneformat.SkyDoc": + return key == "Color" || key == "Zenith" || key == "Horizon" || key == "Ground" + case "sceneformat.FogDoc", "sceneformat.LightDoc": + return key == "Color" + } + case "scene3d_edit.go": + return key == "Color" && structType == "sceneformat.LightDoc" + } + return false } + // materials_ui.go passes "#ffffff" / "#000000" as the placeholder argument to colorControl(...). + if relPath == "materials_ui.go" { + if call, ok := parent.(*ast.CallExpr); ok { + if id, ok := call.Fun.(*ast.Ident); ok && id.Name == "colorControl" { + return true + } + } + } + return false +} +// allowedCoreColorConstInContext returns true only for particle data default ramp/trail stops. +func allowedCoreColorConstInContext(relPath string, stack []ast.Node) bool { + switch relPath { + case "particles.go": + // Allowed only inside particles.ColorCurve or particles.TrailConfig Color field. + if len(stack) >= 3 { + if kv, ok := stack[len(stack)-2].(*ast.KeyValueExpr); ok { + if keyIdent, ok := kv.Key.(*ast.Ident); ok && keyIdent.Name == "Color" { + if cl, ok := stack[len(stack)-3].(*ast.CompositeLit); ok { + st := exprTypeName(cl.Type) + if st == "particles.TrailConfig" { + return true + } + if st == "" && len(stack) >= 4 { + if outer, ok := stack[len(stack)-4].(*ast.CompositeLit); ok && exprTypeName(outer.Type) == "particles.ColorCurve" { + return true + } + } + } + } + } + } + case "particles_ui.go": + for i := len(stack) - 1; i >= 0; i-- { + if fn, ok := stack[i].(*ast.FuncDecl); ok { + return fn.Name.Name == "particleCurveWidgetView" + } + } + } + return false +} + +func checkSpecColorLiteralsInFile(fset *token.FileSet, relPath string, file *ast.File) []string { + coreAliases := map[string]bool{} + coreDotImported := false + for _, imp := range file.Imports { + importPath, err := strconv.Unquote(imp.Path.Value) + if err != nil || importPath != "github.com/nsgo-dev/nsgo/core" { + continue + } + if imp.Name == nil { + coreAliases["core"] = true + } else if imp.Name.Name == "." { + coreDotImported = true + } else if imp.Name.Name != "_" { + coreAliases[imp.Name.Name] = true + } + } + + var violations []string + var stack []ast.Node + + var walk func(ast.Node) + walk = func(n ast.Node) { + if n == nil { + return + } + stack = append(stack, n) + defer func() { stack = stack[:len(stack)-1] }() + + switch node := n.(type) { + case *ast.CallExpr: + var coreFunc string + switch fn := node.Fun.(type) { + case *ast.SelectorExpr: + if ident, ok := fn.X.(*ast.Ident); ok && coreAliases[ident.Name] { + coreFunc = fn.Sel.Name + } + case *ast.Ident: + if coreDotImported { + switch fn.Name { + case "RGB", "RGBA", "ParseColor", "Color": + coreFunc = fn.Name + } + } + if fn.Name == "colorFromRGBA8" && len(node.Args) > 0 { + allConst := true + for _, arg := range node.Args { + if !isConstNumericExpr(arg) { + allConst = false + break + } + } + if allConst { + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden colorFromRGBA8 call with all-constant arguments outside spec_theme.go") + } + } + } + + switch coreFunc { + case "RGB", "RGBA": + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden core."+coreFunc+" call outside spec_theme.go") + case "ParseColor": + if len(node.Args) == 1 { + if lit, ok := node.Args[0].(*ast.BasicLit); ok && lit.Kind == token.STRING { + if s, err := strconv.Unquote(lit.Value); err == nil && isSpecColorStringLiteral(s) { + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden core.ParseColor("+lit.Value+") literal outside spec_theme.go") + } + } + } + case "Color": + if len(node.Args) == 1 { + if val, ok := evalConstInt(node.Args[0]); ok && val != 0 && !allowedCoreColorConstInContext(relPath, stack) { + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden non-zero constant core.Color(...) literal outside spec_theme.go") + } + } + } + + case *ast.BasicLit: + if node.Kind == token.STRING { + if s, err := strconv.Unquote(node.Value); err == nil && isSpecColorStringLiteral(s) { + if !allowedColorStringInContext(relPath, stack) { + pos := fset.Position(node.Pos()) + violations = append(violations, pos.String()+": forbidden color string literal "+node.Value+" outside spec_theme.go") + } + } + } + } + + ast.Inspect(n, func(child ast.Node) bool { + if child == n || child == nil { + return child == n + } + walk(child) + return false + }) + } + walk(file) + return violations +} + +// #1002 Acceptance 2: Every non-test Go file in packages/game/editor outside spec_theme.go +// must use Spec theme tokens instead of core.RGB, core.RGBA, constant core.Color/colorFromRGBA8, +// or hardcoded UI hex/rgb/rgba color literals. Scene content defaults (such as scene.BackgroundColor, +// sky/fog/light defaults, and hex input placeholders) stay scene data and are narrowed by exact +// struct field / call site context. +func TestSpecNoHardcodedColorLiteralsInEditor(t *testing.T) { fset := token.NewFileSet() var violations []string @@ -761,7 +1062,8 @@ func TestSpecNoHardcodedColorLiteralsInEditor(t *testing.T) { if !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") { return nil } - if filepath.Clean(path) == "spec_theme.go" { + rel := filepath.ToSlash(filepath.Clean(path)) + if rel == "spec_theme.go" { return nil } @@ -770,45 +1072,7 @@ func TestSpecNoHardcodedColorLiteralsInEditor(t *testing.T) { t.Errorf("parse %s: %v", path, parseErr) return nil } - - ast.Inspect(file, func(n ast.Node) bool { - switch node := n.(type) { - case *ast.CallExpr: - if sel, ok := node.Fun.(*ast.SelectorExpr); ok { - if ident, ok := sel.X.(*ast.Ident); ok && ident.Name == "core" { - switch sel.Sel.Name { - case "RGB", "RGBA": - pos := fset.Position(node.Pos()) - violations = append(violations, pos.String()+": forbidden core."+sel.Sel.Name+" call outside spec_theme.go") - case "ParseColor": - if len(node.Args) == 1 { - if lit, ok := node.Args[0].(*ast.BasicLit); ok && lit.Kind == token.STRING { - if s, err := strconv.Unquote(lit.Value); err == nil && hexStringRe.MatchString(s) { - pos := fset.Position(node.Pos()) - violations = append(violations, pos.String()+": forbidden core.ParseColor("+lit.Value+") literal outside spec_theme.go") - } - } - } - case "Color": - if !allowedCoreColorHexFiles[filepath.ToSlash(path)] && len(node.Args) == 1 { - if lit, ok := node.Args[0].(*ast.BasicLit); ok && lit.Kind == token.INT && strings.HasPrefix(strings.ToLower(lit.Value), "0x") && lit.Value != "0x0" { - pos := fset.Position(node.Pos()) - violations = append(violations, pos.String()+": forbidden core.Color("+lit.Value+") literal outside spec_theme.go") - } - } - } - } - } - case *ast.BasicLit: - if node.Kind == token.STRING && !allowedHexStringFiles[filepath.ToSlash(path)] { - if s, err := strconv.Unquote(node.Value); err == nil && hexStringRe.MatchString(s) { - pos := fset.Position(node.Pos()) - violations = append(violations, pos.String()+": forbidden hex color literal "+node.Value+" outside spec_theme.go") - } - } - } - return true - }) + violations = append(violations, checkSpecColorLiteralsInFile(fset, rel, file)...) return nil }) if err != nil { @@ -819,6 +1083,143 @@ func TestSpecNoHardcodedColorLiteralsInEditor(t *testing.T) { } } +func TestSpecColorLiteralASTGuardrailCatchesPatterns(t *testing.T) { + parseAndCheck := func(relPath, src string) []string { + t.Helper() + fset := token.NewFileSet() + file, err := parser.ParseFile(fset, relPath, src, 0) + if err != nil { + t.Fatalf("parse %s: %v", relPath, err) + } + return checkSpecColorLiteralsInFile(fset, relPath, file) + } + + mustReject := []struct { + name string + relPath string + src string + }{ + { + name: "3-digit hex string", + relPath: "panel.go", + src: `package editor; var s = "#fff"`, + }, + { + name: "4-digit hex string", + relPath: "panel.go", + src: `package editor; var s = "#1234"`, + }, + { + name: "6-digit hex in UI style inside allowlisted file", + relPath: "environment_panel.go", + src: `package editor; import "github.com/nsgo-dev/nsgo/core"; var s = core.Style{Color: "#112233"}`, + }, + { + name: "rgb string literal", + relPath: "panel.go", + src: `package editor; var s = "rgb(255, 128, 0)"`, + }, + { + name: "rgba string literal outside ui.Input Placeholder", + relPath: "inspector_scene.go", + src: `package editor; var s = "rgba(12, 16, 30, 0.85)"`, + }, + { + name: "decimal core.Color literal", + relPath: "panel.go", + src: `package editor; import "github.com/nsgo-dev/nsgo/core"; var c = core.Color(123456)`, + }, + { + name: "core.Color(uint32(hex)) literal", + relPath: "panel.go", + src: `package editor; import "github.com/nsgo-dev/nsgo/core"; var c = core.Color(uint32(0x112233ff))`, + }, + { + name: "core.Color(uint32(decimal)) literal", + relPath: "panel.go", + src: `package editor; import "github.com/nsgo-dev/nsgo/core"; var c = core.Color(uint32(987654))`, + }, + { + name: "aliased core import RGB", + relPath: "panel.go", + src: `package editor; import c "github.com/nsgo-dev/nsgo/core"; var col = c.RGB(0x112233)`, + }, + { + name: "aliased core import RGBA", + relPath: "panel.go", + src: `package editor; import c "github.com/nsgo-dev/nsgo/core"; var col = c.RGBA(0x112233, 0.5)`, + }, + { + name: "aliased core import ParseColor 3-digit hex", + relPath: "panel.go", + src: `package editor; import c "github.com/nsgo-dev/nsgo/core"; var col, _ = c.ParseColor("#abc")`, + }, + { + name: "aliased core import Color constant", + relPath: "panel.go", + src: `package editor; import c "github.com/nsgo-dev/nsgo/core"; var col = c.Color(uint32(0xff0000ff))`, + }, + { + name: "colorFromRGBA8 with all-constant arguments", + relPath: "panel.go", + src: `package editor; var col = colorFromRGBA8(255, 255, 255, 255)`, + }, + { + name: "colorFromRGBA8 with constant hex expressions", + relPath: "panel.go", + src: `package editor; var col = colorFromRGBA8(0x10, 0x20, 0x30, uint8(0xff))`, + }, + } + + for _, tc := range mustReject { + t.Run("reject/"+tc.name, func(t *testing.T) { + if got := parseAndCheck(tc.relPath, tc.src); len(got) == 0 { + t.Fatalf("expected AST guardrail to reject %q, but got 0 violations", tc.name) + } + }) + } + + mustAllow := []struct { + name string + relPath string + src string + }{ + { + name: "transparent core.Color(0)", + relPath: "panel.go", + src: `package editor; import "github.com/nsgo-dev/nsgo/core"; var col = core.Color(0)`, + }, + { + name: "dynamic colorFromRGBA8 raster pixel", + relPath: "terrain.go", + src: `package editor; func f(r, g, b uint8) { _ = colorFromRGBA8(r, g, b, 255) }`, + }, + { + name: "dynamic core.Color(uint32(v))", + relPath: "particles.go", + src: `package editor; import "github.com/nsgo-dev/nsgo/core"; func f(v uint32) { _ = core.Color(uint32(v)) }`, + }, + { + name: "allowlisted ui.Input Placeholder", + relPath: "inspector_scene.go", + src: `package editor; import "github.com/nsgo-dev/nsgo/ui"; var _ = ui.Input{Placeholder: "rgba(12, 16, 30, 0.85)"}`, + }, + { + name: "allowlisted sceneformat.LightDoc Color", + relPath: "scene3d_edit.go", + src: `package editor; var _ = sceneformat.LightDoc{Color: "#ffffff"}`, + }, + } + + for _, tc := range mustAllow { + t.Run("allow/"+tc.name, func(t *testing.T) { + if got := parseAndCheck(tc.relPath, tc.src); len(got) > 0 { + t.Fatalf("expected AST guardrail to allow %q, got violations: %v", tc.name, got) + } + }) + } +} + // #1002 Acceptance 3: Toolbar, panels, inspector, viewport surround, and status bar render in // Spec bg, panel, raised, and line tokens, toolbar title is 14/600, and the selection outline is accent. func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { @@ -904,3 +1305,150 @@ func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { }) verifyMode("light", editor.LightSpecPalette()) } + +func TestSpecLightModePlayUIAndTilePaletteContrast(t *testing.T) { + ed := newTestEditor(t) + light := editor.LightSpecPalette() + + app := nsgotest.Start(t, func(cx *core.Scope) core.Node { + return editor.EditorView(cx, ed) + }, nsgotest.Size(1280, 800), nsgotest.Environment(core.Environment{ + OS: core.OSMacOS, + Idiom: core.IdiomDesktop, + Dark: false, + Locale: "en-US", + })) + + // 1. Enter Play mode in Light appearance and verify Play bar, Inspector|Agent tabs, and Agent panel use Spec Light tokens. + app.Post(func() { + if err := ed.Play(); err != nil { + t.Errorf("Play: %v", err) + } + }) + app.Settle() + + tabs := app.Find("id:play-inspector-tabs").Style + if tabs.Background != light.Panel || tabs.BorderColor != light.Line { + t.Fatalf("light play-inspector-tabs bg=#%06X border=#%06X, want Panel=#%06X Line=#%06X", + uint32(tabs.Background)>>8, uint32(tabs.BorderColor)>>8, uint32(light.Panel)>>8, uint32(light.Line)>>8) + } + var findTextViews func(v *nsgotest.View, text string) []*nsgotest.View + findTextViews = func(v *nsgotest.View, text string) []*nsgotest.View { + if v == nil { + return nil + } + var out []*nsgotest.View + if v.Text == text { + out = append(out, v) + } + for _, ch := range v.Children { + out = append(out, findTextViews(ch, text)...) + } + return out + } + + tabInsp := app.Find("id:play-tab-inspector") + foundLightTabText := false + for _, n := range findTextViews(tabInsp, "Inspector") { + if n.TextStyle.Color != light.TextPrimary { + t.Fatalf("light play-tab-inspector text = #%06X, want TextPrimary #%06X", + uint32(n.TextStyle.Color)>>8, uint32(light.TextPrimary)>>8) + } + if r := editor.ContrastRatio(n.TextStyle.Color, light.Panel); r < 4.5 { + t.Fatalf("light play-tab-inspector contrast = %.2f:1, want >= 4.5:1", r) + } + foundLightTabText = true + } + if !foundLightTabText { + t.Fatal("could not find Inspector text node inside play-tab-inspector") + } + + stopBtn := app.Find("id:play-stop-btn") + if stopBtn.Style.Background != light.TextPrimary { + t.Fatalf("light play-stop-btn bg = #%06X, want TextPrimary #%06X", + uint32(stopBtn.Style.Background)>>8, uint32(light.TextPrimary)>>8) + } + foundStopText := false + for _, n := range findTextViews(stopBtn, "Stop") { + if n.TextStyle.Color != light.OnTextPrimary { + t.Fatalf("light play-stop-btn text = #%06X, want OnTextPrimary #%06X", + uint32(n.TextStyle.Color)>>8, uint32(light.OnTextPrimary)>>8) + } + foundStopText = true + } + if !foundStopText { + t.Fatal("could not find Stop text node inside play-stop-btn") + } + + app.Press("id:play-tab-agent") + marksHdr := app.Find("id:play-marks-header") + if marksHdr.TextStyle.Color != light.TextFaint { + t.Fatalf("light play-marks-header color = #%06X, want TextFaint #%06X", + uint32(marksHdr.TextStyle.Color)>>8, uint32(light.TextFaint)>>8) + } + + app.Post(func() { + _ = ed.Stop() + }) + app.Settle() + + // 2. Open TilePaletteView in Light appearance and verify selected tile card uses Spec Light tokens. + app.Post(func() { + ed.SetActiveLayer("floor") + ed.SetTool(editor.ToolPaintTile) + }) + app.Settle() + + selCard := app.Find("id:tile-palette-selected").Style + if selCard.Background != light.Raised || selCard.BorderColor != light.LineRaised { + t.Fatalf("light tile-palette-selected bg=#%06X border=#%06X, want Raised=#%06X LineRaised=#%06X", + uint32(selCard.Background)>>8, uint32(selCard.BorderColor)>>8, uint32(light.Raised)>>8, uint32(light.LineRaised)>>8) + } + selName := app.Find("id:tile-palette-selected-name") + if selName.TextStyle.Color != light.TextPrimary { + t.Fatalf("light tile-palette-selected-name color = #%06X, want TextPrimary #%06X", + uint32(selName.TextStyle.Color)>>8, uint32(light.TextPrimary)>>8) + } + selMeta := app.Find("id:tile-palette-selected-meta") + if selMeta.TextStyle.Color != light.TextFaint { + t.Fatalf("light tile-palette-selected-meta color = #%06X, want TextFaint #%06X", + uint32(selMeta.TextStyle.Color)>>8, uint32(light.TextFaint)>>8) + } +} + +func TestSpecViewport3DGridUsesActiveSpecPalette(t *testing.T) { + ed := newTestEditor(t) + ed.SetViewMode(editor.ViewMode3D) + + for _, tc := range []struct { + name string + appearance editor.Appearance + want editor.SpecPalette + }{ + {"dark", editor.AppearanceDark, editor.DarkSpecPalette()}, + {"light", editor.AppearanceLight, editor.LightSpecPalette()}, + } { + if err := ed.SetAppearance(tc.appearance); err != nil { + t.Fatalf("SetAppearance(%s): %v", tc.name, err) + } + d := &core.Drawing{} + ed.DrawViewport3D(d, core.Size{Width: 640, Height: 360}) + + wantGround := ui.Alpha(tc.want.Viewport3DGround, 0.55) + foundGrid, foundGround := false, false + for _, op := range d.Ops { + if op.Kind == core.DrawStrokeColor && op.Color == tc.want.Viewport3DGrid { + foundGrid = true + } + if op.Kind == core.DrawFillColor && op.Color == wantGround { + foundGround = true + } + } + if !foundGrid { + t.Errorf("%s: DrawViewport3D did not stroke grid with Viewport3DGrid #%06X", tc.name, uint32(tc.want.Viewport3DGrid)>>8) + } + if !foundGround { + t.Errorf("%s: DrawViewport3D did not fill ground plane with Viewport3DGround #%06X", tc.name, uint32(tc.want.Viewport3DGround)>>8) + } + } +} diff --git a/packages/game/editor/terrain.go b/packages/game/editor/terrain.go index 779167eef..0130e0761 100644 --- a/packages/game/editor/terrain.go +++ b/packages/game/editor/terrain.go @@ -1584,15 +1584,17 @@ func (e *Editor) ClearTerrainHover() { // terrainLayerPreviewColors gives distinct visual tints from spec_theme.yaml for up to 8 terrain layers // in the 3D viewport wireframe when a layer has no explicit RGB tint. -var terrainLayerPreviewColors = [8]core.Color{ - specAlpha(darkSpecPalette.Added.Fg, 0.85), - specAlpha(darkSpecPalette.Changed.Fg, 0.85), - specAlpha(darkSpecPalette.TextFaint, 0.85), - specAlpha(darkSpecPalette.TextPrimary, 0.90), - specAlpha(darkSpecPalette.Warning.Fg, 0.85), - specAlpha(darkSpecPalette.TextMuted, 0.85), - specAlpha(darkSpecPalette.Agent.Fg, 0.85), - specAlpha(darkSpecPalette.Accent.Fg, 0.85), +func terrainLayerPreviewColors(spec SpecPalette) [8]core.Color { + return [8]core.Color{ + specAlpha(spec.Added.Fg, 0.85), + specAlpha(spec.Changed.Fg, 0.85), + specAlpha(spec.TextFaint, 0.85), + specAlpha(spec.TextPrimary, 0.90), + specAlpha(spec.Warning.Fg, 0.85), + specAlpha(spec.TextMuted, 0.85), + specAlpha(spec.Agent.Fg, 0.85), + specAlpha(spec.Accent.Fg, 0.85), + } } func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { @@ -1600,6 +1602,7 @@ func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { return } spec := e.activeSpecPalette() + previewColors := terrainLayerPreviewColors(spec) t := e.terrain hm := t.hm if hm.Cols < 2 || hm.Rows < 2 { @@ -1618,7 +1621,7 @@ func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { b := uint8(clamp01f32(l.Color[2]) * 255) layerColors[i] = specAlpha(colorFromRGBA8(r, g, b, 255), 0.85) } else { - layerColors[i] = terrainLayerPreviewColors[i%len(terrainLayerPreviewColors)] + layerColors[i] = previewColors[i%len(previewColors)] } } @@ -1635,7 +1638,7 @@ func (e *Editor) drawTerrain3D(d *core.Drawing, w, h float32) { for c := 0; c < hm.Cols; c += stepC { nextC := min(c+stepC, hm.Cols-1) p0 := samplePos(c, r) - col := terrainLayerPreviewColors[0] + col := previewColors[0] if len(layerColors) > 0 { if sample, ok := hm.LayerAt(p0[0], p0[2]); ok && sample.Dominant < len(layerColors) { col = layerColors[sample.Dominant] diff --git a/packages/game/editor/tilebrush.go b/packages/game/editor/tilebrush.go index 999ca2de8..3e77ca858 100644 --- a/packages/game/editor/tilebrush.go +++ b/packages/game/editor/tilebrush.go @@ -948,12 +948,6 @@ func (e *Editor) TilePreview() []TilePreviewCell { return out } -// Spec token colors for brush preview and selection overlays. -var ( - previewAccentColor = darkSpecPalette.Accent.Fg - previewEraseColor = darkSpecPalette.Removed.Fg -) - // drawTileSelectionOverlay draws a dashed marquee around the active TileSelection (or in-progress region select stroke). func (e *Editor) drawTileSelectionOverlay(d *core.Drawing) { var rect TileRect @@ -1046,6 +1040,7 @@ func (e *Editor) drawStampHoverOverlay(d *core.Drawing, tm *sceneformat.TilemapD p := e.TilePalette() pal = &p } + spec := e.activeSpecPalette() hasFlips := len(stamp.Flips) == len(stamp.Tiles) for dy := range stamp.Height { mr := row + dy @@ -1063,7 +1058,7 @@ func (e *Editor) drawStampHoverOverlay(d *core.Drawing, tm *sceneformat.TilemapD } x, y := float32(mc)*tw, float32(mr)*th if tid == 0 { - d.SetFillColor(specAlpha(e.activeSpecPalette().Removed.Fg, 0.18)).FillRect(x, y, tw, th) + d.SetFillColor(specAlpha(spec.Removed.Fg, 0.18)).FillRect(x, y, tw, th) } else { e.drawGhostTileID(d, tm, tid, flip, x, y, pal) } @@ -1071,7 +1066,7 @@ func (e *Editor) drawStampHoverOverlay(d *core.Drawing, tm *sceneformat.TilemapD } // Outline the clamped stamp footprint. if r, ok := clampTileRect(TileRect{Col0: col, Row0: row, Col1: col + stamp.Width - 1, Row1: row + stamp.Height - 1}, tm.Width, tm.Height); ok { - d.SetStrokeColor(hoverPaintColor).SetLineWidth(lw).StrokeRect( + d.SetStrokeColor(spec.Accent.Fg).SetLineWidth(lw).StrokeRect( float32(r.Col0)*tw, float32(r.Row0)*th, float32(r.Width())*tw, float32(r.Height())*th, ) diff --git a/packages/game/editor/tilepalette.go b/packages/game/editor/tilepalette.go index 430d5575a..7580a68cd 100644 --- a/packages/game/editor/tilepalette.go +++ b/packages/game/editor/tilepalette.go @@ -568,7 +568,7 @@ func tilePalettePanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core }, tileBrushBar(ed, rev), core.Dynamic(func(cx *core.Scope) core.Node { - return tileLayerControls(ed, rev, palette.Get()) + return tileLayerControls(cx, ed, rev, palette.Get()) }), core.Dynamic(func(cx *core.Scope) core.Node { switch brushMode.Get() { @@ -584,7 +584,7 @@ func tilePalettePanel(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core Style: core.Style{FlexGrow: 1}, Children: []core.Node{grid}, }, - tilePaletteSelectedCard(cx, palette, active), + tilePaletteSelectedCard(cx, ed, palette, active), }, } } @@ -840,10 +840,11 @@ func tileRandomControls(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) co } // tileLayerControls returns the controls a YAML-tileset grid's palette shows above its tiles: a toggle per tile layer (for layered grids), the flips tile brushes place tiles with, the terrain selector for ToolTerrain, an Edit Tileset button, and the palette note from Tiles.dc.html. A legacy atlas single grid has none, and gets an empty view. -func tileLayerControls(ed *Editor, rev *core.Signal[uint64], p TilePalette) core.Node { +func tileLayerControls(cx *core.Scope, ed *Editor, rev *core.Signal[uint64], p TilePalette) core.Node { if len(p.TileLayers) == 0 && !isTilesetFile(p.Tileset) { return core.View{} } + spec := ed.SpecPalette(cx) var children []core.Node if len(p.TileLayers) > 0 { layers := make([]core.Node, 0, len(p.TileLayers)) @@ -940,13 +941,13 @@ func tileLayerControls(ed *Editor, rev *core.Signal[uint64], p TilePalette) core children = append(children, core.Text{ TestID: "tile-terrain-empty", Content: "No terrain sets defined. Press Edit Tileset to add one.", - Style: core.Style{FontSize: 11, Color: specTextMuted}, + Style: core.Style{FontSize: 11, Color: spec.TextFaint}, }) } children = append(children, core.Text{ TestID: "tile-palette-rules-note", Content: "Rules for collision, terrain and variants live in the tileset file.", - Style: core.Style{FontSize: 11, Color: specTextMuted}, + Style: core.Style{FontSize: 11, Color: spec.TextFaint}, }) return core.View{ TestID: "tile-layer-controls", @@ -956,13 +957,14 @@ func tileLayerControls(ed *Editor, rev *core.Signal[uint64], p TilePalette) core } // tilePaletteSelectedCard renders the picked tile's swatch, name, atlas cell coordinates, and rules at the bottom of the tile palette. -func tilePaletteSelectedCard(cx *core.Scope, palette *core.Memo[TilePalette], active *core.Memo[int]) core.Node { +func tilePaletteSelectedCard(cx *core.Scope, ed *Editor, palette *core.Memo[TilePalette], active *core.Memo[int]) core.Node { return core.Dynamic(func(cx *core.Scope) core.Node { p := palette.Get() tile, ok := p.Tile(active.Get()) if !ok { return core.View{} } + spec := ed.SpecPalette(cx) name := tile.Name if name == "" { name = fmt.Sprintf("Tile %d", tile.Number) @@ -985,9 +987,9 @@ func tilePaletteSelectedCard(cx *core.Scope, palette *core.Memo[TilePalette], ac Gap: 10, Padding: core.All(8), CornerRadius: 10, - Background: specRaised, + Background: spec.Raised, BorderWidth: 1, - BorderColor: specLineRaised, + BorderColor: spec.LineRaised, }, Children: []core.Node{ core.Canvas{ @@ -997,7 +999,7 @@ func tilePaletteSelectedCard(cx *core.Scope, palette *core.Memo[TilePalette], ac Height: core.Pt(28), FlexShrink: 0, CornerRadius: 6, - Background: specPanel, + Background: spec.Panel, }, Draw: func(d *core.Drawing, size core.Size) { drawPaletteTile(d, tile, float32(size.Width), float32(size.Height)) @@ -1009,12 +1011,12 @@ func tilePaletteSelectedCard(cx *core.Scope, palette *core.Memo[TilePalette], ac core.Text{ TestID: "tile-palette-selected-name", Content: name, - Style: core.Style{FontSize: 11.5, FontWeight: 500, Color: specTextStrong}, + Style: core.Style{FontSize: 11.5, FontWeight: 500, Color: spec.TextPrimary}, }, core.Text{ TestID: "tile-palette-selected-meta", Content: meta, - Style: core.Style{FontSize: 11, Color: specTextMuted}, + Style: core.Style{FontSize: 11, Color: spec.TextFaint}, }, }, }, diff --git a/packages/game/editor/tilestroke.go b/packages/game/editor/tilestroke.go index 4b1cccb9e..7838ca0d8 100644 --- a/packages/game/editor/tilestroke.go +++ b/packages/game/editor/tilestroke.go @@ -892,14 +892,6 @@ func (e *Editor) toolStrokeMode(secondary, alt bool) (TileStrokeMode, bool) { return 0, false } -// The hover outline's colors from spec_theme.yaml: accent for painting and filling, added for terrain, removed for erasing, warning for picking. -var ( - hoverPaintColor = darkSpecPalette.Accent.Fg - hoverTerrainColor = darkSpecPalette.Added.Fg - hoverEraseColor = darkSpecPalette.Removed.Fg - hoverPickColor = darkSpecPalette.Warning.Fg -) - // drawTileHoverOverlay draws the active tile selection marquee, any live brush preview under way, // or the hover outline for the cell under the mouse (HoveredTile) on the active layer. func (e *Editor) drawTileHoverOverlay(d *core.Drawing) { diff --git a/packages/game/editor/viewport3d.go b/packages/game/editor/viewport3d.go index d6028c70c..c4d6f0613 100644 --- a/packages/game/editor/viewport3d.go +++ b/packages/game/editor/viewport3d.go @@ -2351,8 +2351,36 @@ func (e *Editor) drawGrid3D(d *core.Drawing, w, h float32) { step, half := e.gridStep3D() extent := step * float32(half) vc := e.activeView3DCam(w, h) + spec := e.activeSpecPalette() + + if !e.gpu3D { + corners := [4][3]float32{ + {-extent, 0, -extent}, + {extent, 0, -extent}, + {extent, 0, extent}, + {-extent, 0, extent}, + } + var sx, sy [4]float32 + allVis := true + for i, c := range corners { + px, py, _, vis := vc.project(c, w, h) + if !vis { + allVis = false + break + } + sx[i], sy[i] = px, py + } + if allVis { + d.Save().SetFillColor(specAlpha(spec.Viewport3DGround, 0.55)).BeginPath(). + MoveTo(sx[0], sy[0]). + LineTo(sx[1], sy[1]). + LineTo(sx[2], sy[2]). + LineTo(sx[3], sy[3]). + ClosePath().Fill().Restore() + } + } - d.Save().SetStrokeColor(specAlpha(e.activeSpecPalette().TextFaint, 0.25)).SetLineWidth(1).BeginPath() + d.Save().SetStrokeColor(spec.Viewport3DGrid).SetLineWidth(1).BeginPath() hasSegments := false for i := -half; i <= half; i++ { coord := float32(i) * step From 6a695d1761fb40cfd4fcb7ffb11a5c76bf9ee297 Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 04:28:09 +0900 Subject: [PATCH 7/9] test(editor): isolate Spec overlay motion check from navigation overlay --- packages/game/editor/viewport_overlay_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/game/editor/viewport_overlay_test.go b/packages/game/editor/viewport_overlay_test.go index b047a53e7..d2bff0816 100644 --- a/packages/game/editor/viewport_overlay_test.go +++ b/packages/game/editor/viewport_overlay_test.go @@ -414,6 +414,11 @@ func TestViewportOverlayMotionAndReduceMotion(t *testing.T) { // 3. Live Editor DrawViewport with deterministic clock and ReduceMotion toggle. ed := newOverlaysTestEditor(t) _ = ed.SetAppearance(editor.AppearanceDark) + // Turn off unrelated scene inspection overlays (such as Navigation, which uses Spec Added.Fg + // for walkable navregion2d polygons) so stroke assertions measure only the Spec scene overlays. + if err := ed.SetViewportOverlays(nil); err != nil { + t.Fatalf("SetViewportOverlays(nil): %v", err) + } baseTime := time.Date(2026, 11, 26, 12, 0, 0, 0, time.UTC) now := baseTime ed.SetOverlayClock(func() time.Time { return now }) From 4c4d0a5993a69491e39b3ccb49df336b2f80a0f4 Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 04:50:50 +0900 Subject: [PATCH 8/9] test(editor): align parallax physics debug palette and chrome region assertions with main layout --- packages/game/editor/parallax_test.go | 2 +- packages/game/editor/spec_theme_test.go | 48 ++++++++++++++++--------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/game/editor/parallax_test.go b/packages/game/editor/parallax_test.go index c47ac7462..9b0089f6f 100644 --- a/packages/game/editor/parallax_test.go +++ b/packages/game/editor/parallax_test.go @@ -305,7 +305,7 @@ func TestEditorParallaxAlignsGizmoTileHoverAndPhysicsDebug(t *testing.T) { defer ed.SetShowPhysicsDebug(false) d := &core.Drawing{} ed.DrawViewport(d, size) - x, y, ok := findStrokedRectCanvasPos(d.Ops, ui.Alpha(editor.DarkSpecPalette().Accent.Fg, 0.9), 16, 16) + x, y, ok := findStrokedRectCanvasPos(d.Ops, ui.Alpha(ed.SpecPalette(nil).Accent.Fg, 0.9), 16, 16) if !ok { t.Fatal("physics debug StrokeRect not found") } diff --git a/packages/game/editor/spec_theme_test.go b/packages/game/editor/spec_theme_test.go index 9ad6ad6ca..b521fe042 100644 --- a/packages/game/editor/spec_theme_test.go +++ b/packages/game/editor/spec_theme_test.go @@ -1220,11 +1220,14 @@ func TestSpecColorLiteralASTGuardrailCatchesPatterns(t *testing.T) { } } -// #1002 Acceptance 3: Toolbar, panels, inspector, viewport surround, and status bar render in -// Spec bg, panel, raised, and line tokens, toolbar title is 14/600, and the selection outline is accent. +// #1002 Acceptance 3: Header, left rail, panels, inspector, viewport surround, and status bar render in +// Spec bg, panel, viewport, and line tokens, section headings use Spec 11/600 typography, and the +// selection outline strokes in Spec Accent.Edge. func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { ed := newTestEditor(t) ed.SelectObject("hero") + ed.SetLayersPanelOpen(true) + ed.SetAssetBrowserOpen(true) app := nsgotest.Start(t, func(cx *core.Scope) core.Node { return editor.EditorView(cx, ed) @@ -1240,23 +1243,36 @@ func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { if got := app.Find("id:scene-editor").Style.Background; got != want.Bg { t.Errorf("%s: root bg = #%06X, want Bg #%06X", label, uint32(got)>>8, uint32(want.Bg)>>8) } - tb := app.Find("id:editor-toolbar").Style - if tb.Background != want.Raised || tb.BorderColors.Bottom != want.Line { - t.Errorf("%s: toolbar bg=#%06X bottomBorder=#%06X, want Raised=#%06X Line=#%06X", - label, uint32(tb.Background)>>8, uint32(tb.BorderColors.Bottom)>>8, uint32(want.Raised)>>8, uint32(want.Line)>>8) + tbView := app.Find("id:editor-toolbar") + tb := tbView.Style + if tb.Background != want.Bg || tb.BorderColors.Bottom != want.Line { + t.Errorf("%s: header bg=#%06X bottomBorder=#%06X, want Bg=#%06X Line=#%06X", + label, uint32(tb.Background)>>8, uint32(tb.BorderColors.Bottom)>>8, uint32(want.Bg)>>8, uint32(want.Line)>>8) } - title := app.Find("id:toolbar-scene-name").TextStyle - if title.Font.Size != editor.SpecFontTitleSize || title.Font.Weight != editor.SpecFontTitleWeight || title.Color != want.TextPrimary { - t.Errorf("%s: toolbar title = %v/%v/#%06X, want 14/600/#%06X", - label, title.Font.Size, title.Font.Weight, uint32(title.Color)>>8, uint32(want.TextPrimary)>>8) + if h := tbView.Bounds().Size.Height; h != editor.SpecHeaderHeight { + t.Errorf("%s: header height = %v, want SpecHeaderHeight %v", label, h, editor.SpecHeaderHeight) + } + if got := app.Find("id:header-brand-mark").Style.Background; got != want.Accent.Fg { + t.Errorf("%s: header-brand-mark bg = #%06X, want Accent.Fg #%06X", label, uint32(got)>>8, uint32(want.Accent.Fg)>>8) + } + sectionTitle := app.Find("id:scene-rail-title").TextStyle + if sectionTitle.Font.Size != editor.SpecFontSectionSize || sectionTitle.Font.Weight != editor.SpecFontSectionWeight || sectionTitle.Color != want.TextFaint { + t.Errorf("%s: scene-rail-title = %v/%v/#%06X, want %v/%v/#%06X", + label, sectionTitle.Font.Size, sectionTitle.Font.Weight, uint32(sectionTitle.Color)>>8, + editor.SpecFontSectionSize, editor.SpecFontSectionWeight, uint32(want.TextFaint)>>8) } if got := app.Find("id:editor-viewport-container").Style.Background; got != want.Viewport { t.Errorf("%s: viewport surround = #%06X, want Viewport #%06X", label, uint32(got)>>8, uint32(want.Viewport)>>8) } + col := app.Find("id:editor-scene-column").Style + if col.Background != want.Bg || col.BorderColors.Right != want.Line { + t.Errorf("%s: editor-scene-column bg=#%06X rightBorder=#%06X, want Bg=#%06X Line=#%06X", + label, uint32(col.Background)>>8, uint32(col.BorderColors.Right)>>8, uint32(want.Bg)>>8, uint32(want.Line)>>8) + } st := app.Find("id:scene-tree-panel").Style - if st.Background != want.Panel || st.BorderColors.Right != want.Line { - t.Errorf("%s: scene-tree-panel bg=#%06X rightBorder=#%06X, want Panel=#%06X Line=#%06X", - label, uint32(st.Background)>>8, uint32(st.BorderColors.Right)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + if st.Background != want.Bg { + t.Errorf("%s: scene-tree-panel bg=#%06X, want Bg=#%06X", + label, uint32(st.Background)>>8, uint32(want.Bg)>>8) } lp := app.Find("id:layers-panel").Style if lp.Background != want.Panel || lp.BorderColors.Top != want.Line || lp.BorderColors.Right != want.Line { @@ -1274,9 +1290,9 @@ func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { label, uint32(insp.Background)>>8, uint32(insp.BorderColors.Left)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) } sb := app.Find("id:editor-status").Style - if sb.Background != want.Raised || sb.BorderColors.Top != want.Line { - t.Errorf("%s: status bar bg=#%06X topBorder=#%06X, want Raised=#%06X Line=#%06X", - label, uint32(sb.Background)>>8, uint32(sb.BorderColors.Top)>>8, uint32(want.Raised)>>8, uint32(want.Line)>>8) + if sb.Background != want.Bg || sb.BorderColors.Top != want.Line { + t.Errorf("%s: status bar bg=#%06X topBorder=#%06X, want Bg=#%06X Line=#%06X", + label, uint32(sb.Background)>>8, uint32(sb.BorderColors.Top)>>8, uint32(want.Bg)>>8, uint32(want.Line)>>8) } // Verify the 2D selection outline strokes in Spec Accent.Edge. From d649d927a32245affc622bfb02bf759b8adcbf7d Mon Sep 17 00:00:00 2001 From: Evan Hu Date: Fri, 27 Nov 2026 05:24:41 +0900 Subject: [PATCH 9/9] fix(editor): align dock split handle dividers and chrome region test with Spec Line token --- packages/game/editor/dock_ui.go | 3 ++ packages/game/editor/spec_theme_test.go | 54 +++++++++++++++++++------ 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/packages/game/editor/dock_ui.go b/packages/game/editor/dock_ui.go index b0ef0a204..d99d374aa 100644 --- a/packages/game/editor/dock_ui.go +++ b/packages/game/editor/dock_ui.go @@ -78,6 +78,9 @@ func editorDockView(cx *core.Scope, ed *Editor, rev *core.Signal[uint64]) core.N PanelViewport: {NoClose: true}, }, HandleLabel: "Resize panel", + HandleStyleFunc: func() core.Style { + return core.Style{Background: ed.SpecPalette(cx).Line} + }, Style: core.Style{ FlexGrow: 1, FlexBasis: core.Pt(0), diff --git a/packages/game/editor/spec_theme_test.go b/packages/game/editor/spec_theme_test.go index b521fe042..95db81643 100644 --- a/packages/game/editor/spec_theme_test.go +++ b/packages/game/editor/spec_theme_test.go @@ -1264,10 +1264,40 @@ func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { if got := app.Find("id:editor-viewport-container").Style.Background; got != want.Viewport { t.Errorf("%s: viewport surround = #%06X, want Viewport #%06X", label, uint32(got)>>8, uint32(want.Viewport)>>8) } + dockArea := app.Find("id:editor-dock-area") + if got := dockArea.Style.Background; got != want.Bg { + t.Errorf("%s: editor-dock-area bg=#%06X, want Bg=#%06X", + label, uint32(got)>>8, uint32(want.Bg)>>8) + } + var dockHandles int + var walkDockHandles func(v *nsgotest.View) + walkDockHandles = func(v *nsgotest.View) { + if v == nil { + return + } + if v.Props.Label == "Resize panel" { + dockHandles++ + if len(v.Children) == 0 || v.Children[0].Style.Background != want.Line { + var got core.Color + if len(v.Children) > 0 { + got = v.Children[0].Style.Background + } + t.Errorf("%s: dock split handle line bg=#%06X, want Line=#%06X", + label, uint32(got)>>8, uint32(want.Line)>>8) + } + } + for _, ch := range v.Children { + walkDockHandles(ch) + } + } + walkDockHandles(dockArea) + if dockHandles == 0 { + t.Errorf("%s: expected dock split handles inside editor-dock-area", label) + } col := app.Find("id:editor-scene-column").Style - if col.Background != want.Bg || col.BorderColors.Right != want.Line { - t.Errorf("%s: editor-scene-column bg=#%06X rightBorder=#%06X, want Bg=#%06X Line=#%06X", - label, uint32(col.Background)>>8, uint32(col.BorderColors.Right)>>8, uint32(want.Bg)>>8, uint32(want.Line)>>8) + if col.Background != want.Bg { + t.Errorf("%s: editor-scene-column bg=#%06X, want Bg=#%06X", + label, uint32(col.Background)>>8, uint32(want.Bg)>>8) } st := app.Find("id:scene-tree-panel").Style if st.Background != want.Bg { @@ -1275,19 +1305,19 @@ func TestSpecEditorChromeRegionsAndSelectionOutline(t *testing.T) { label, uint32(st.Background)>>8, uint32(want.Bg)>>8) } lp := app.Find("id:layers-panel").Style - if lp.Background != want.Panel || lp.BorderColors.Top != want.Line || lp.BorderColors.Right != want.Line { - t.Errorf("%s: layers-panel bg=#%06X topBorder=#%06X rightBorder=#%06X, want Panel=#%06X Line=#%06X", - label, uint32(lp.Background)>>8, uint32(lp.BorderColors.Top)>>8, uint32(lp.BorderColors.Right)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + if lp.Background != want.Panel { + t.Errorf("%s: layers-panel bg=#%06X, want Panel=#%06X", + label, uint32(lp.Background)>>8, uint32(want.Panel)>>8) } ab := app.Find("id:asset-browser").Style - if ab.Background != want.Panel || ab.BorderColors.Right != want.Line { - t.Errorf("%s: asset-browser bg=#%06X rightBorder=#%06X, want Panel=#%06X Line=#%06X", - label, uint32(ab.Background)>>8, uint32(ab.BorderColors.Right)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + if ab.Background != want.Panel { + t.Errorf("%s: asset-browser bg=#%06X, want Panel=#%06X", + label, uint32(ab.Background)>>8, uint32(want.Panel)>>8) } insp := app.Find("id:editor-inspector").Style - if insp.Background != want.Panel || insp.BorderColors.Left != want.Line { - t.Errorf("%s: editor-inspector bg=#%06X leftBorder=#%06X, want Panel=#%06X Line=#%06X", - label, uint32(insp.Background)>>8, uint32(insp.BorderColors.Left)>>8, uint32(want.Panel)>>8, uint32(want.Line)>>8) + if insp.Background != want.Panel { + t.Errorf("%s: editor-inspector bg=#%06X, want Panel=#%06X", + label, uint32(insp.Background)>>8, uint32(want.Panel)>>8) } sb := app.Find("id:editor-status").Style if sb.Background != want.Bg || sb.BorderColors.Top != want.Line {