Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Agent Note: Spec viewport overlays, toggle legend, and object-level problem attribution

Status: implemented

## Problem

Viewport overlays in the 2D and 3D scene editors previously used ad-hoc colors and line styles (such as a hardcoded `0x38BDF8` selection polygon, separate 3D selection/wireframe colors, and inline drawing code for agent tasks and problems), with no single Spec-compliant drawing helper for the seven semantic overlay kinds in `docs/design/editor/Spec.dc.html`, no shared top-left toggle legend persisted per person, no reduced-motion handling for change fades and agent pulses, and no object ID on `assetcheck.Problem` when scene diagnostics reported only a file and line (#1006).

## Decision

Centralize every Spec semantic viewport overlay behind `DrawObjectOverlay`, expose a shared top-left toggle legend persisted in per-user `EditorSettings`, attach `Object` directly to `assetcheck.Problem`, and migrate non-semantic viewport guides (camera frame, camera bounds, tile grid, snap grid) to neutral `SpecPalette` hairline/dotted tokens.

### Single Spec overlay helper and live API (`packages/game/editor/viewport_overlay.go`)
- `DrawObjectOverlay(d, SpecPalette, ObjectOverlay)` renders all seven `OverlayKind` values exclusively from `SpecPalette` tokens at the Spec's exact widths and non-color second cues:
- `OverlayKindSelection`: `Accent`, 1.5 px solid, four 8×8 corner handles, and accent name tag (person's selection only).
- `OverlayKindAgent`: `Agent`, 1.5 px solid, no handles, 1.6 s pulse between 100% and 45% (`OverlayAgentPulseAlpha`), dark pill with 4-point sparkle glyph or numbered task badge (`Holding` variant uses 45% dashed outline + clock glyph).
- `OverlayKindAdded`: `Added`, 1.5 px dashed (`5, 3`), dark pill with `"+ <name>"`.
- `OverlayKindChanged`: `Changed`, 1.5 px dashed (`5, 3`), dark pill with `"field old → new"`.
- `OverlayKindRemoved`: `Removed`, 1.5 px solid around a 25% grey ghost (`TextFaint` at 25%), dark pill with struck-through name + `"removed"`.
- `OverlayKindProblem`: `Problem`, 2 px solid on the live object, filled `Problem.Fg`/`Problem.OnFill` pill with alert triangle glyph and message (never resembling a removed ghost).
- `OverlayKindFocusedChange`: renders its base `ChangeKind` color and dash at 2.5 px with a full-opacity outlined pill, never `Accent`.
- When `PairedWithSelection` is set on `OverlayKindAgent`, the agent outline expands an extra `OverlaySelectionAgentGap` (3 px) outside Selection's outline so Selection keeps its corner handles unobstructed and the agent pill stacks above.
- Change overlays fade in over 240 ms (`OverlayFadeAlpha`); when `ReduceMotion` is active (`Scope.Env().ReduceMotion()` or `Editor.SetReduceMotion(true)`), fades resolve immediately to 100%, agent outlines stay solid at 100%, and `viewport.go` skips scheduling the 33 ms `overlayAnimRev` timer.
- `SceneOverlayEntry` and `Editor.SetSceneOverlays` / `AddSceneOverlay` / `RemoveSceneOverlay` / `ClearSceneOverlays` provide the live scene API for agent edits, reviews, and plans in both 2D (`drawSceneOverlays2D`) and 3D (`drawSceneOverlays3D`).

### Shared top-left toggle legend and per-user persistence (`spec_feedback_ui.go`, `settings.go`, `apps/website/public/schemas/editor-settings.v1.json`)
- `viewportOverlayLegendView` mounts in the top-left corner of the shared viewport container (`viewport.go`) for both 2D and 3D edit modes, rendering six `core.RoleSwitch` rows (`legend-selection`, `legend-agent`, `legend-added`, `legend-changed`, `legend-removed`, `legend-problem`) with drawn line-style + second-cue swatches.
- `EditorSettings.OverlayLegend` (`*[]string`, `yaml:"overlayLegend,omitempty"`) follows the same pointer-to-slice persistence pattern as `ViewportOverlays` in [2026-11-26-editor-viewport-overlays.md](./2026-11-26-editor-viewport-overlays.md): `nil` omits the key and enables all six kinds by default, while `&[]string{}` serializes `overlayLegend: []` so turning all six rows off survives restart without mutating project or scene files. Unknown or duplicate values are refused by `ParseEditorSettings`.
- `OverlayKindProblem` stays synchronized with `Editor.ProblemOverlayVisible()` (see [2026-11-26-editor-live-problems-agent-fix.md](./2026-11-26-editor-live-problems-agent-fix.md)), and `SpecOverlayLegendView` (see [2026-11-26-editor-spec-light-theme.md](./2026-11-26-editor-spec-light-theme.md)) draws every card through `DrawObjectOverlay`.

### Object-level problem attribution and neutral guides (`tooling/assetcheck/assetcheck.go`, `scene.go`, `viewport.go`, `viewport3d.go`, `overlays.go`, `snap.go`)
- `assetcheck.Problem` adds `Object string` (and `editormcp.Problem` exposes `object`), populated by `sceneChecker.withObject` during scene/component/asset traversal and by `yamlFieldErrorObject` for `sceneformat.FieldError` paths (including `layers[*].objects[*]`, `overrides.<id>`, and `connections[*]` live endpoints). `Editor.attributeProblemObject` checks `p.Object` first before falling back to message regex and line spans.
- Camera frame, camera bounds, camera tether, tile grid, snap grid, and 3D grid/wireframe use neutral `SpecPalette` `TextMuted`/`TextFaint` 1 px hairlines and `2, 4` dotted strokes so no guide shares a color or dash style with the semantic legend.
- `gametest.RenderOps` (`gametest/golden.go`, `golden_shapes.go`) adds `DrawRoundRect`, `DrawArc`, `DrawEllipse`, `DrawLineDash`, scaled dash/line widths, and deterministic 5×7 bitmap text rendering so 1x and 2x golden-image tests verify every Spec overlay primitive headlessly.

## Alternatives considered

1. **Keeping separate 2D and 3D overlay drawing code paths**: 3D already drew wireframe bounding boxes and dots directly in `viewport3d.go`. Rejected because Selection, Agent, Problem, and diff overlays would drift in stroke width, pill layout, reduced-motion behavior, and legend toggles across 2D and 3D. Projecting 3D object corners to canvas bounds and calling `DrawObjectOverlay` keeps both viewports identical.
2. **Storing legend toggles inside `ViewportOverlays` (`SHOW IN VIEWPORT` popover)**: Combining semantic overlay kinds with scene-inspection overlays (`collision_shapes`, `connections`, `navigation`) would avoid a new `EditorSettings` field, but `Spec.dc.html` and `Main.dc.html` place the six semantic kinds in a dedicated top-left legend with explicit line-style swatches separate from the bottom-center inspection bar. Separate `overlayLegend` persistence keeps both independent and backward compatible.
3. **Inferring Problem object IDs solely in `editor` by re-parsing YAML**: Avoiding a field on `assetcheck.Problem` would keep `assetcheck` untouched, but `assetcheck` already walks every scene object, override, and `FieldError` path during validation; emitting `Problem.Object` at the source eliminates fragile regex heuristics and makes object attribution available to `editormcp`'s `game_check` too.

## Consequences

- **Benefits**: One Spec-compliant overlay renderer across 2D and 3D viewports, greyscale-distinguishable semantic cues, instant reduced-motion compliance, persistent per-user legend switches outside project files, exact object-level Problem overlays, and 1x/2x golden-image + native macOS screenshot coverage.
- **Costs**: `gametest.RenderOps` now maintains software rasterizers for rounded rects, arcs, dashed strokes, and 5×7 bitmap glyphs for golden comparisons (so changes to overlay geometry or styling require intentional `-update-golden` updates to `viewport_overlays_1x.png` and `viewport_overlays_2x.png`).
- **Verification**: `packages/game/editor/viewport_overlay_test.go` verifies 1x and 2x golden images, pairwise greyscale distinguishability, Selection+Agent 3 px offset, 240 ms fade / 1.6 s pulse / reduced-motion static rendering, 2D+3D legend toggles and restart persistence (including `[]` and invalid YAML refusal), live Problems panel integration in 2D and 3D, neutral camera/grid tokens, and native macOS Dark/Light `nsgotest` screenshots; `packages/game/tooling/assetcheck/assetcheck_test.go` and `connections_test.go` verify `Problem.Object`.
7 changes: 7 additions & 0 deletions apps/website/public/schemas/editor-settings.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
"type": "string"
}
},
"overlayLegend": {
"description": "OverlayLegend lists the enabled Spec viewport overlay legend kinds (\"selection\", \"agent\", \"added\", \"changed\", \"removed\", \"problem\") in canonical sorted order. When omitted, all six legend kinds are enabled by default; an empty list hides all six kinds.",
"type": "array",
"items": {
"type": "string"
}
},
"shortcuts": {
"description": "Shortcuts overrides default command shortcuts keyed by command ID (for example \"view.frame\": \"g\"). An empty string explicitly unbinds a command.",
"type": "object",
Expand Down
9 changes: 9 additions & 0 deletions changelog.d/editor-viewport-overlays-1006.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Added

- `game/editor`: unified Spec viewport overlay renderer (`DrawObjectOverlay`) and live overlay API (`SceneOverlayEntry`, `SetSceneOverlays`) supporting all seven Spec overlay kinds (Selection, Agent working, Added, Changed, Removed, Problem, Focused change in Review) with non-color second cues, Selection+Agent 3 px outer pairing, 240 ms change fade-in, 1.6 s Agent pulse, and reduced-motion static rendering (#1006).
- `game/editor`: shared top-left viewport overlay legend (`viewport-overlay-legend`) across 2D and 3D viewports with six `role="switch"` toggles persisted per user under `overlayLegend` in `EditorSettings` (`editor-settings.v1.json`) (#1006).
- `game/tooling/assetcheck`: populate `Problem.Object` on scene object, component, override, and connection diagnostics (and expose `object` in `editormcp`'s `game_check`) so live Problem overlays attach directly to objects in the open scene (#1006).

### Changed

- `game/editor`: switch 2D and 3D selection outlines to the Spec style (1.5 px solid accent, four corner handles, name tag) and move camera frame, camera bounds, tile grid, and snap grid to neutral `SpecPalette` hairline/dotted tokens distinct from all legend kinds (#1006).
21 changes: 20 additions & 1 deletion docs/en/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ The Particle Emitter Editor (`ParticleEditorPanelView`), opened from the toolbar

The editor UI is localized in English (`en`) and Simplified Chinese (`zh`) through embedded versioned `l10n` YAML string tables (`editor/locales/en.yaml`, `editor/locales/zh.yaml`), and per-user preferences are stored outside any project as deterministic versioned YAML:

- **Per-user settings file (`EditorSettings`, `SettingsVersion = 1`, #921, #1005, #1028)**: stored at `DefaultSettingsPath()` (under `os.UserConfigDir()` as `nsgo-game/editor.yaml`, outside every game project) and loaded/saved with `ParseEditorSettings`, `EncodeEditorSettings`, `LoadEditorSettings`, `SaveEditorSettings`, `Editor.LoadSettings`, `Editor.LoadUserSettings`, and `Editor.SaveSettings`. It stores `version`, `language`, `appearance`, optional `autoSave` (defaults to `true` when omitted), optional `interfaceSize` (`compact`, `default`, or `large`), optional `snap` (per-person defaults for `grid`, `gridSize`, `pixel`, `rotation`, `rotationStepDeg`, `scale`, `scaleStep`, and `showGrid`, used when a project does not override snap in `.game/editor.yaml`), optional `showAgentChanges` (defaults to `true` when omitted), optional `navigation3D` (`default`, `blender`, or `maya`), optional `viewportOverlays` (canonical sorted list of enabled 2D viewport overlay IDs; omitted for defaults, `[]` for all off), optional `shortcuts`, optional `seenTips`, and optional `agent` preferences (task routing, MCP tool toggles, external MCP servers, weekly request limit, outbound privacy switches, and local usage counters; secrets such as API keys are never stored in `editor.yaml`). Unknown keys, YAML anchors/aliases/merge keys, trailing documents, negative/non-finite snap steps, and invalid enum values are refused with `*loaderr.Error`. Output is deterministic 2-space YAML prefixed with `SettingsSchemaComment` so a load-save round trip changes nothing byte-for-byte. Its published JSON Schema is `https://game.nsgo.dev/schemas/editor-settings.v1.json` (`SettingsSchemaURL`).
- **Per-user settings file (`EditorSettings`, `SettingsVersion = 1`, #921, #1005, #1006, #1028)**: stored at `DefaultSettingsPath()` (under `os.UserConfigDir()` as `nsgo-game/editor.yaml`, outside every game project) and loaded/saved with `ParseEditorSettings`, `EncodeEditorSettings`, `LoadEditorSettings`, `SaveEditorSettings`, `Editor.LoadSettings`, `Editor.LoadUserSettings`, and `Editor.SaveSettings`. It stores `version`, `language`, `appearance`, optional `autoSave` (defaults to `true` when omitted), optional `interfaceSize` (`compact`, `default`, or `large`), optional `snap` (per-person defaults for `grid`, `gridSize`, `pixel`, `rotation`, `rotationStepDeg`, `scale`, `scaleStep`, and `showGrid`, used when a project does not override snap in `.game/editor.yaml`), optional `showAgentChanges` (defaults to `true` when omitted), optional `navigation3D` (`default`, `blender`, or `maya`), optional `viewportOverlays` (canonical sorted list of enabled 2D viewport overlay IDs; omitted for defaults, `[]` for all off), optional `overlayLegend` (canonical sorted list of enabled Spec viewport overlay legend kinds: `selection`, `agent`, `added`, `changed`, `removed`, `problem`; omitted enables all six, `[]` hides all six), optional `shortcuts`, optional `seenTips`, and optional `agent` preferences (task routing, MCP tool toggles, external MCP servers, weekly request limit, outbound privacy switches, and local usage counters; secrets such as API keys are never stored in `editor.yaml`). Unknown keys, YAML anchors/aliases/merge keys, trailing documents, negative/non-finite snap steps, and invalid enum values are refused with `*loaderr.Error`. Output is deterministic 2-space YAML prefixed with `SettingsSchemaComment` so a load-save round trip changes nothing byte-for-byte. Its published JSON Schema is `https://game.nsgo.dev/schemas/editor-settings.v1.json` (`SettingsSchemaURL`).
```yaml
# yaml-language-server: $schema=https://game.nsgo.dev/schemas/editor-settings.v1.json
version: 1
Expand Down Expand Up @@ -1575,3 +1575,22 @@ 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:

| Kind (`OverlayKind`) | Token & line style | Second cue |
| --- | --- | --- |
| **Selection** (`selection`) | `Accent`, 1.5 px solid | Four 8×8 corner handles and an accent name tag (person's selection only) |
| **Agent working** (`agent`) | `Agent`, 1.5 px solid, no handles | Pulsing 1.6 s between 100% and 45%, dark pill with 4-point agent glyph (or numbered task badge) saying what the agent is doing |
| **Added** (`added`) | `Added`, 1.5 px dashed | Dark pill labelled `"+ <name>"` |
| **Changed** (`changed`) | `Changed`, 1.5 px dashed | Dark pill showing field, old, and new value (for example `"z 10 → 12"`) |
| **Removed** (`removed`) | `Removed`, 1.5 px solid | 25% grey ghost fill and dark pill with struck-through object name + `"removed"` |
| **Problem** (`problem`) | `Problem`, 2 px solid on the live object | Filled pill (`Problem.Fg` / `Problem.OnFill`) with alert triangle icon and message; never resembles a removed ghost |
| **Focused change in Review** (`focused`) | Base change kind's own color and dash at 2.5 px (never `Accent`) | Bright outlined pill matching the change kind |

- **Pairing, motion, and reduced motion**: When **Selection** and **Agent working** sit on the same object (`PairedWithSelection`), Selection keeps its four corner handles and the Agent outline sits 3 px further out (`OverlaySelectionAgentGap`) with its pill stacked above. Added, Changed, and Removed overlays fade in over 240 ms (`OverlayChangeFadeDuration` / `OverlayFadeAlpha`), and active Agent working outlines pulse on a 1.6 s cycle (`OverlayAgentPulsePeriod` / `OverlayAgentPulseAlpha`). With reduced motion enabled (`core.Environment.ReduceMotion` or `Editor.SetReduceMotion(true)`), change overlays appear immediately at 100% and Agent outlines stay solid at 100% with no animation timer running.
- **Top-left toggle legend (`viewport-overlay-legend`)**: Every edit-mode viewport (both 2D and 3D) mounts the same top-left legend card (`viewportOverlayLegendView`) with six accessible `role="switch"` rows (**Selection**, **Agent working**, **Added**, **Changed**, **Removed**, **Problem**), each showing its drawn line style and second cue. Toggling any row (`Editor.ToggleOverlayKind`, `Editor.SetOverlayKindVisible`, `Editor.SetOverlayLegendKinds`) hides or shows that kind across all viewports immediately and persists `overlayLegend` in the per-user `EditorSettings` YAML file (`Editor.SettingsPath`, outside the project, never modifying project or scene files).
- **Live scene overlay API and Problems object attribution**: Live agent edits, reviews, and plans attach overlays to objects (or removed ghost bounds) via `Editor.SetSceneOverlays`, `AddSceneOverlay`, `RemoveSceneOverlay`, and `ClearSceneOverlays` (`SceneOverlayEntry`). `assetcheck.Problem` now carries `Object` (also returned by `editormcp`'s `game_check`) for scene object, component, override, and connection diagnostics so Problems naming a live object in the open scene automatically draw the Spec **Problem** overlay on that object in both 2D and 3D viewports.
- **Neutral viewport guides**: The camera frame, camera bounds, camera tether, tile grid, and snap grid use neutral `SpecPalette` tokens (`TextMuted` / `TextFaint` 1 px hairline and `2, 4` dotted lines) that no semantic legend kind uses.
7 changes: 7 additions & 0 deletions docs/en/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ viewportOverlays:
- connections
- navigation
- triggers
overlayLegend:
- added
- agent
- changed
- problem
- removed
- selection
shortcuts:
view.frame: g
seenTips:
Expand Down
Loading
Loading