A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(editor): five surfaces that showed the wrong thing
esengine31c7965b94c6
diff --git a/desktop/src/components/AddComponentMenu.tsx b/desktop/src/components/AddComponentMenu.tsxindex 8a9184934..caf77b15b 100644--- a/desktop/src/components/AddComponentMenu.tsx+++ b/desktop/src/components/AddComponentMenu.tsx@@ -12,6 +12,7 @@ import { createPortal } from 'react-dom';import { ComponentIcon } from '@/components/icons';import { SearchField } from '@/components/SearchField';import { useDialogFocus } from '@/components/dialogFocus';+import { useHoverSelect } from '@/components/hoverSelect';import { usePanelWindow } from '@/components/PanelWindow';import { CATEGORY_ORDER } from '@/engine/schema';import { t } from '@/i18n';@@ -59,6 +60,7 @@ export function AddComponentMenu({const activeRef = useRef<HTMLButtonElement>(null);const shellRef = useRef<HTMLDivElement>(null);useDialogFocus(shellRef);+ const hoverSelect = useHoverSelect();// Focus the search on open (type-to-filter immediately).useEffect(() => {@@ -157,7 +159,7 @@ export function AddComponentMenu({ref={isActive ? activeRef : undefined}type="button"className={`ac-item${isActive ? ' sel' : ''}`}- onMouseEnter={() => setActive(idx)}+ {...hoverSelect(() => setActive(idx))}onClick={() => commit(it.name)}><span className="ai">diff --git a/desktop/src/components/AgentDrawer.tsx b/desktop/src/components/AgentDrawer.tsxindex 6d3438b09..86db97f4d 100644--- a/desktop/src/components/AgentDrawer.tsx+++ b/desktop/src/components/AgentDrawer.tsx@@ -46,6 +46,7 @@ import { secretStatus, subscribeSecrets, secretRevision } from '@/store/SecretStimport { useSettings } from '@/store/settingsStore';import { MarkdownView } from '@/components/MarkdownView';import { AgentMark } from '@/components/AgentMark';+import { useHoverSelect } from '@/components/hoverSelect';import { OverlayDrawer } from '@/components/OverlayDrawer';import { readImageItems } from '@/agent/attachments';import { dockApi } from '@/layout/dockApi';@@ -1073,6 +1074,7 @@ function Compose({ autoFocus }: { autoFocus?: boolean }) {// menu that picks something other than what was highlighted.const [mention, setMention] = useState<{ query: string; items: Mention[]; at: number } | null>(null);const [mentionIdx, setMentionIdx] = useState(0);+ const hoverSelect = useHoverSelect();const selected = useSelection((s) => s.selectedId);const selectedName = selected == null ? null : EditorControlSurface.getEntity(selected)?.name ?? null;@@ -1151,7 +1153,7 @@ function Compose({ autoFocus }: { autoFocus?: boolean }) {type="button"key={item.key}className={`ag-mention-i${i === mentionIdx ? ' on' : ''}`}- onMouseEnter={() => { setMentionIdx(i); peekEntities(item.entity === null ? [] : [item.entity]); }}+ {...hoverSelect(() => { setMentionIdx(i); peekEntities(item.entity === null ? [] : [item.entity]); })}onMouseLeave={() => peekEntities([])}onMouseDown={(e) => { e.preventDefault(); insertMention(item.insert); }}>diff --git a/desktop/src/components/CommandPalette.tsx b/desktop/src/components/CommandPalette.tsxindex 11329241a..c26e0f371 100644--- a/desktop/src/components/CommandPalette.tsx+++ b/desktop/src/components/CommandPalette.tsx@@ -12,6 +12,7 @@ import { createPortal } from 'react-dom';import { Sparkles } from 'lucide-react';import { SearchField } from '@/components/SearchField';import { useDialogFocus } from '@/components/dialogFocus';+import { useHoverSelect } from '@/components/hoverSelect';import { usePanelWindow } from '@/components/PanelWindow';import { commands, formatKeybinding } from '@/commands';import { filterPalette, paletteItems, readsAsSentence, type PaletteItem } from '@/commands/palette';@@ -27,6 +28,7 @@ export function CommandPalette({ onClose }: { onClose: () => void }) {const activeRef = useRef<HTMLButtonElement>(null);const shellRef = useRef<HTMLDivElement>(null);useDialogFocus(shellRef);+ const hoverSelect = useHoverSelect();// Enablement is resolved once at open — the palette is a snapshot of what is// runnable now, and predicates read live store state (cheap but not reactive).@@ -135,7 +137,7 @@ export function CommandPalette({ onClose }: { onClose: () => void }) {<buttontype="button"className={`ac-item cp-item cp-agent${active < 0 ? ' sel' : ''}`}- onMouseEnter={() => setActive(-1)}+ {...hoverSelect(() => setActive(-1))}onClick={handOff}><span className="at">@@ -162,7 +164,7 @@ export function CommandPalette({ onClose }: { onClose: () => void }) {type="button"className={`ac-item cp-item${isActive ? ' sel' : ''}${item.enabled ? '' : ' is-disabled'}`}aria-disabled={!item.enabled}- onMouseEnter={() => setActive(idx)}+ {...hoverSelect(() => setActive(idx))}onClick={() => run(item)}><span className="at">diff --git a/desktop/src/components/CreatePopover.tsx b/desktop/src/components/CreatePopover.tsxindex b3e3219d5..b49c47a61 100644--- a/desktop/src/components/CreatePopover.tsx+++ b/desktop/src/components/CreatePopover.tsx@@ -15,6 +15,7 @@ import { createPortal } from 'react-dom';import { allEntitySources, matchSources, CREATE_CATEGORY_ORDER, type EntitySource } from '@/engine/entitySources';import { SearchField } from '@/components/SearchField';import { useDialogFocus } from '@/components/dialogFocus';+import { useHoverSelect } from '@/components/hoverSelect';import { usePanelWindow } from '@/components/PanelWindow';import { t } from '@/i18n';@@ -51,6 +52,7 @@ export function CreatePopover({const activeRef = useRef<HTMLButtonElement>(null);const shellRef = useRef<HTMLDivElement>(null);useDialogFocus(shellRef);+ const hoverSelect = useHoverSelect();// Static builtins + the project's own components + its prefab assets. Computed// once per open, which is once per mount — the popover is unmounted when closed.@@ -120,7 +122,7 @@ export function CreatePopover({ref={isActive ? activeRef : undefined}type="button"className={`ac-item${isActive ? ' sel' : ''}`}- onMouseEnter={() => setActive(idx)}+ {...hoverSelect(() => setActive(idx))}onClick={() => commit(it)}><span className="ai"><Icon size={16} /></span>diff --git a/desktop/src/components/hoverSelect.ts b/desktop/src/components/hoverSelect.tsnew file mode 100644index 000000000..ac1506931--- /dev/null+++ b/desktop/src/components/hoverSelect.ts@@ -0,0 +1,39 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file hoverSelect.ts+ * @brief Shared hover-selection for keyboard-first pickers (command palette,+ * Add Component, Create, @-mention): the row under the pointer takes+ * the selection, but only once the pointer has actually moved.+ */+import { useCallback, useRef } from 'react';++/**+ * A gate that answers "did the pointer MOVE here", not "is it here".+ *+ * `mouseenter` also fires for content appearing (or scrolling) beneath a still+ * pointer, which hands an arbitrary row the keyboard's selection. The first+ * position only arms the gate, so an event at the resting spot never passes.+ */+export function makeMoveGate(): (x: number, y: number) => boolean {+ let at: { x: number; y: number } | null = null;+ return (x, y) => {+ const prev = at;+ at = { x, y };+ return prev != null && (prev.x !== x || prev.y !== y);+ };+}++/** Row props that give the active selection to whatever the pointer moves over. */+export function useHoverSelect(): (select: () => void) => { onMouseMove: (e: { clientX: number; clientY: number }) => void } {+ const moved = useRef<((x: number, y: number) => boolean) | null>(null);+ moved.current ??= makeMoveGate();+ return useCallback(+ (select: () => void) => ({+ onMouseMove: (e: { clientX: number; clientY: number }) => {+ if (moved.current!(e.clientX, e.clientY)) select();+ },+ }),+ [],+ );+}diff --git a/desktop/src/engine/ViewportController.ts b/desktop/src/engine/ViewportController.tsindex c4eb7813a..fc4b112c7 100644--- a/desktop/src/engine/ViewportController.ts+++ b/desktop/src/engine/ViewportController.ts@@ -160,8 +160,10 @@ export type TilePiece = TileCollisionPiece & { planeZ?: number };/** World AABB union of the scene's content — the extent the minimap fits into. */export interface MinimapBounds { minX: number; minY: number; maxX: number; maxY: number; }-/** One schematic box in the minimap: an entity's world AABB + a coarse kind for colour. */-export interface MinimapBox { x0: number; y0: number; x1: number; y1: number; kind: 'sprite' | 'tile' | 'icon'; }+/** One schematic box in the minimap: an entity's world AABB + a coarse kind for colour.+ * `src` is the SOURCE id selection speaks in (null for runtime-only projections), so+ * the map can mark what's selected without recollecting every box. */+export interface MinimapBox { src: EntityId | null; x0: number; y0: number; x1: number; y1: number; kind: 'sprite' | 'tile' | 'icon'; }// Above this many boxes the minimap stops collecting (bounds still cover everything// collected) — a schematic overview needs the layout, not thousands of rects/rebuild.@@ -604,8 +606,8 @@ export const ViewportController = {const world = EngineHost.world;const boxes: MinimapBox[] = [];let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;- const add = (x0: number, y0: number, x1: number, y1: number, kind: MinimapBox['kind']) => {- if (boxes.length < MINIMAP_BOX_CAP) boxes.push({ x0, y0, x1, y1, kind });+ const add = (e: EntityId, x0: number, y0: number, x1: number, y1: number, kind: MinimapBox['kind']) => {+ if (boxes.length < MINIMAP_BOX_CAP) boxes.push({ src: SceneModel.sourceFor(e) ?? null, x0, y0, x1, y1, kind });minX = Math.min(minX, x0); minY = Math.min(minY, y0);maxX = Math.max(maxX, x1); maxY = Math.max(maxY, y1);};@@ -614,7 +616,7 @@ export const ViewportController = {if (!world.valid(e) || !world.has(e, Transform) || world.has(e, UINode)) continue;if (world.has(e, TilemapLayer)) {const tb = this.tilemapWorldAABB(e);- if (tb) { add(tb.x0, tb.y0, tb.x1, tb.y1, 'tile'); continue; }+ if (tb) { add(e, tb.x0, tb.y0, tb.x1, tb.y1, 'tile'); continue; }}const b = this.entityBounds(e);if (!b) continue;@@ -623,7 +625,7 @@ export const ViewportController = {x0 = Math.min(x0, wx); y0 = Math.min(y0, wy);x1 = Math.max(x1, wx); y1 = Math.max(y1, wy);}- add(x0, y0, x1, y1, world.has(e, Sprite) ? 'sprite' : 'icon');+ add(e, x0, y0, x1, y1, world.has(e, Sprite) ? 'sprite' : 'icon');}}const bounds = Number.isFinite(minX) ? { minX, minY, maxX, maxY } : null;diff --git a/desktop/src/engine/minimapFit.ts b/desktop/src/engine/minimapFit.tsnew file mode 100644index 000000000..34b0dfee8--- /dev/null+++ b/desktop/src/engine/minimapFit.ts@@ -0,0 +1,81 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file minimapFit.ts+ * @brief Projection between world space and the viewport minimap's fixed+ * coordinate box: the letterbox fit, world→map rects, and map→world+ * for click-to-navigate.+ */+import type { MinimapBounds } from './ViewportController';++/** Scale + centring offsets that fit `bounds` into a `w × h` map, aspect preserved. */+export interface MinimapFit {+ b: MinimapBounds;+ scale: number;+ offX: number;+ offY: number;+}++export function minimapFit(+ bounds: MinimapBounds | null, w: number, h: number, pad: number,+): MinimapFit | null {+ if (!bounds) return null;+ const worldW = Math.max(bounds.maxX - bounds.minX, 1e-3);+ const worldH = Math.max(bounds.maxY - bounds.minY, 1e-3);+ const scale = Math.min((w - 2 * pad) / worldW, (h - 2 * pad) / worldH);+ return { b: bounds, scale, offX: (w - worldW * scale) / 2, offY: (h - worldH * scale) / 2 };+}++/** A world AABB in map coordinates (y flips: world +y is up, map +y is down). */+export function minimapBox(+ fit: MinimapFit, x0: number, y0: number, x1: number, y1: number,+): { x: number; y: number; w: number; h: number } {+ return {+ x: fit.offX + (x0 - fit.b.minX) * fit.scale,+ y: fit.offY + (fit.b.maxY - y1) * fit.scale,+ w: Math.max(1, (x1 - x0) * fit.scale),+ h: Math.max(1, (y1 - y0) * fit.scale),+ };+}++/** Thinnest camera frame that still reads as a frame. */+const CAM_MIN = 2;++/** `[lo, hi]` of `v`, then a `CAM_MIN`-wide span that cannot leave `[0, size]` —+ * a view panned clean off the scene pins to the edge it left by. */+function span(lo: number, hi: number, size: number): [number, number] {+ const a = Math.min(Math.max(lo, 0), size);+ const b = Math.min(Math.max(hi, 0), size);+ return [Math.min(a, Math.max(0, size - CAM_MIN)), Math.max(CAM_MIN, b - a)];+}++/**+ * The camera's world rect as a map rect CLAMPED to the map.+ *+ * A view wider than the scene projects past the map, and the SVG clips whatever+ * leaves it — leaving two stray lines where a frame should be. Clamped, the same+ * state says what it means: the frame covers the map because you see everything.+ */+export function minimapCamRect(+ fit: MinimapFit, view: { cx: number; cy: number; halfW: number; halfH: number }, w: number, h: number,+): { x: number; y: number; w: number; h: number } {+ const [x, width] = span(+ fit.offX + (view.cx - view.halfW - fit.b.minX) * fit.scale,+ fit.offX + (view.cx + view.halfW - fit.b.minX) * fit.scale,+ w,+ );+ const [y, height] = span(+ fit.offY + (fit.b.maxY - (view.cy + view.halfH)) * fit.scale,+ fit.offY + (fit.b.maxY - (view.cy - view.halfH)) * fit.scale,+ h,+ );+ return { x, y, w: width, h: height };+}++/** Map coordinates back to world — the click/drag navigation door. */+export function minimapToWorld(fit: MinimapFit, mx: number, my: number): { x: number; y: number } {+ return {+ x: fit.b.minX + (mx - fit.offX) / fit.scale,+ y: fit.b.maxY - (my - fit.offY) / fit.scale,+ };+}diff --git a/desktop/src/launcher/Launcher.tsx b/desktop/src/launcher/Launcher.tsxindex 3be45a314..2668876c2 100644--- a/desktop/src/launcher/Launcher.tsx+++ b/desktop/src/launcher/Launcher.tsx@@ -47,6 +47,23 @@ function Constellation() {);}+/**+ * A recent project's path with the folder name always legible: the leading+ * directories ellipsise, the last segment never does. Clipping the tail instead+ * renders same-named projects in different folders as the same string.+ */+function ProjectPath({ root, className }: { root: string; className: string }) {+ const cut = Math.max(root.lastIndexOf('/'), root.lastIndexOf('\\'));+ const head = cut > 0 ? root.slice(0, cut) : '';+ const tail = cut > 0 ? root.slice(cut) : root;+ return (+ <span className={`${className} mono`} title={root}>+ <span className="pp-head">{head}</span>+ <span className="pp-tail">{tail}</span>+ </span>+ );+}+/** Project tile — the real thumbnail if present, else a star-chart placeholder. */function Thumb({ label, src }: { label: string; src?: string }) {return (@@ -156,7 +173,7 @@ function RecentView({<div className="proj-card__body"><span className="proj-card__name">{p.name}</span><span className="proj-card__meta mono">{relTime(p.openedAt)}</span>- <span className="proj-card__path mono">{p.root}</span>+ <ProjectPath root={p.root} className="proj-card__path" /></div>{p.build && <span className="proj-card__build mono">{p.build}</span>}<button@@ -189,7 +206,7 @@ function RecentView({><span className="proj-row__main"><span className="proj-row__name">{p.name}</span>- <span className="proj-row__path mono">{p.root}</span>+ <ProjectPath root={p.root} className="proj-row__path" /></span><span className="proj-row__col mono">{relTime(p.openedAt)}</span><span className="proj-row__col">{p.build && <span className="lc-badge mono">{p.build}</span>}</span>diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsxindex 973523d71..c687a0e2e 100644--- a/desktop/src/panels/ContentBrowser.tsx+++ b/desktop/src/panels/ContentBrowser.tsx@@ -202,9 +202,13 @@ interface Row {}const parentOf = (p: string) => (p.includes('/') ? p.slice(0, p.lastIndexOf('/')) : '');+// Where a project's content lives. The browser opens here, not at the project+// root — whose listing is the same boilerplate for every project ever opened.+const CONTENT_ROOT = 'assets';+// Folder navigation with a back/forward history (the breadcrumb nav arrows).function useNav() {- const [nav, setNav] = useState<{ hist: string[]; i: number }>({ hist: [''], i: 0 });+ const [nav, setNav] = useState<{ hist: string[]; i: number }>({ hist: [CONTENT_ROOT], i: 0 });const cwd = nav.hist[nav.i];const go = useCallback((p: string) => setNav((n) => (p === n.hist[n.i] ? n : { hist: [...n.hist.slice(0, n.i + 1), p], i: n.i + 1 })),@@ -213,7 +217,7 @@ function useNav() {const back = useCallback(() => setNav((n) => ({ ...n, i: Math.max(0, n.i - 1) })), []);const forward = useCallback(() => setNav((n) => ({ ...n, i: Math.min(n.hist.length - 1, n.i + 1) })), []);const up = useCallback(() => go(parentOf(cwd)), [go, cwd]);- const reset = useCallback(() => setNav({ hist: [''], i: 0 }), []);+ const reset = useCallback((to: string = CONTENT_ROOT) => setNav({ hist: [to], i: 0 }), []);return { cwd, go, back, forward, up, reset, canBack: nav.i > 0, canForward: nav.i < nav.hist.length - 1, canUp: cwd !== '' };}@@ -384,10 +388,21 @@ export function ContentBrowser() {// Reset navigation + selection + search/filter when the open project changes —// project A's query/type-filter must not carry into project B's browser.useEffect(() => {+ let alive = true;reset();selectAsset(null);setQuery('');setFilters(new Set());+ // A project laid out some other way has no assets/ — land on its root rather+ // than on a folder that isn't there. Asked of the ROOT listing, which always+ // reads, instead of probing the missing folder itself.+ void window.estella?.fs+ ?.readDir('')+ .then((e) => {+ if (alive && !e.some((d) => d.isDir && d.name === CONTENT_ROOT)) reset('');+ })+ .catch(() => {});+ return () => { alive = false; };}, [project?.name, reset, selectAsset]);// Selection doesn't survive a folder change.useEffect(() => selectAsset(null), [cwd, selectAsset]);diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex 2d79175b1..e3a02c8da 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -26,6 +26,7 @@ import { MOD_LABEL } from '@/commands/keybinding';import { EngineHost } from '@/engine/EngineHost';import { PlayRealm } from '@/engine/PlayRealm';import { ViewportController, type JointGizmoType, type ColliderPointHandle, type MinimapBounds, type MinimapBox } from '@/engine/ViewportController';+import { minimapFit, minimapBox, minimapCamRect, minimapToWorld } from '@/engine/minimapFit';import { ProjectStore } from '@/project/ProjectStore';import { createFromSource, sourceById, SOURCE_DND_MIME } from '@/engine/entitySources';import { resizeUINodeAxis, type ResizeSide, type AxisResizeWrites } from '@/engine/uiResize';@@ -597,19 +598,33 @@ const MINIMAP_W = 200;const MINIMAP_H = 128;const MINIMAP_PAD = 8;-const ViewportMinimap = memo(function ViewportMinimap({ data }: { data: { bounds: MinimapBounds | null; boxes: MinimapBox[] } }) {+/**+ * A counter that bumps two frames after any of `deps` changes — the point at which+ * the engine has ticked and composed world transforms are readable. Anything derived+ * from world-space geometry has to wait for it; reading on the change itself sees the+ * pre-tick identity pose.+ */+function useComposedRev(...deps: unknown[]): number {+ const [rev, setRev] = useState(0);+ useEffect(() => {+ let inner = 0;+ const outer = requestAnimationFrame(() => {+ inner = requestAnimationFrame(() => setRev((r) => r + 1));+ });+ return () => { cancelAnimationFrame(outer); cancelAnimationFrame(inner); };+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, deps);+ return rev;+}++const ViewportMinimap = memo(function ViewportMinimap(+ { data, selected }: { data: { bounds: MinimapBounds | null; boxes: MinimapBox[] }; selected: ReadonlySet<EntityId> },+) {const win = usePanelWindow();const camRef = useRef<SVGRectElement>(null);// Fit the world bounds into the panel (preserve aspect, letterbox). Recomputed only// when the bounds change; the projection below closes over it.- const fit = useMemo(() => {- const b = data.bounds;- if (!b) return null;- const worldW = Math.max(b.maxX - b.minX, 1e-3);- const worldH = Math.max(b.maxY - b.minY, 1e-3);- const scale = Math.min((MINIMAP_W - 2 * MINIMAP_PAD) / worldW, (MINIMAP_H - 2 * MINIMAP_PAD) / worldH);- return { b, scale, offX: (MINIMAP_W - worldW * scale) / 2, offY: (MINIMAP_H - worldH * scale) / 2 };- }, [data.bounds]);+ const fit = useMemo(() => minimapFit(data.bounds, MINIMAP_W, MINIMAP_H, MINIMAP_PAD), [data.bounds]);// Overlay the editor camera's world rect on the minimap every frame (it tracks// pan/zoom). Its own tiny rAF keeps this off the gizmo-heavy main viewport tick.@@ -622,10 +637,11 @@ const ViewportMinimap = memo(function ViewportMinimap({ data }: { data: { boundsif (!rect) return;const v = ViewportController.editorViewRect();if (!v) { rect.style.opacity = '0'; return; }- rect.setAttribute('x', String(fit.offX + (v.cx - v.halfW - fit.b.minX) * fit.scale));- rect.setAttribute('y', String(fit.offY + (fit.b.maxY - (v.cy + v.halfH)) * fit.scale));- rect.setAttribute('width', String(Math.max(2, v.halfW * 2 * fit.scale)));- rect.setAttribute('height', String(Math.max(2, v.halfH * 2 * fit.scale)));+ const r = minimapCamRect(fit, v, MINIMAP_W, MINIMAP_H);+ rect.setAttribute('x', String(r.x));+ rect.setAttribute('y', String(r.y));+ rect.setAttribute('width', String(r.w));+ rect.setAttribute('height', String(r.h));rect.style.opacity = '1';};raf = requestAnimationFrame(tick);@@ -633,21 +649,24 @@ const ViewportMinimap = memo(function ViewportMinimap({ data }: { data: { bounds}, [fit, win]);// Minimap px → world, then recenter the camera there (click + drag, zoom untouched).+ // The SVG is sized by CSS over a fixed viewBox, so client px scale by the rendered+ // width — aiming at raw client offsets would land short on a shrunk map.const navTo = (e: ReactPointerEvent) => {if (!fit) return;const r = (e.currentTarget as SVGSVGElement).getBoundingClientRect();- ViewportController.centerViewOn(- fit.b.minX + (e.clientX - r.left - fit.offX) / fit.scale,- fit.b.maxY - (e.clientY - r.top - fit.offY) / fit.scale,- );+ const k = r.width > 0 ? MINIMAP_W / r.width : 1;+ const p = minimapToWorld(fit, (e.clientX - r.left) * k, (e.clientY - r.top) * k);+ ViewportController.centerViewOn(p.x, p.y);};- if (!fit || data.boxes.length === 0) return null;+ // One box is not a map — a UI-only scene leaves just the camera icon, and a+ // panel-sized overlay of it only hides the scene behind it.+ if (!fit || data.boxes.length < 2) return null;return (<div className="viewport__minimap" title={t('vp.minimap')}><svg- width={MINIMAP_W}- height={MINIMAP_H}+ viewBox={`0 0 ${MINIMAP_W} ${MINIMAP_H}`}+ preserveAspectRatio="none"onPointerDown={(e) => {if (e.button !== 0) return;(e.currentTarget as SVGSVGElement).setPointerCapture(e.pointerId);@@ -655,16 +674,19 @@ const ViewportMinimap = memo(function ViewportMinimap({ data }: { data: { bounds}}onPointerMove={(e) => { if (e.buttons & 1) navTo(e); }}>- {data.boxes.map((bx, i) => (- <rect- key={i}- className={`mm-box mm-${bx.kind}`}- x={fit.offX + (bx.x0 - fit.b.minX) * fit.scale}- y={fit.offY + (fit.b.maxY - bx.y1) * fit.scale}- width={Math.max(1, (bx.x1 - bx.x0) * fit.scale)}- height={Math.max(1, (bx.y1 - bx.y0) * fit.scale)}- />- ))}+ {data.boxes.map((bx, i) => {+ const r = minimapBox(fit, bx.x0, bx.y0, bx.x1, bx.y1);+ return (+ <rect+ key={i}+ className={`mm-box mm-${bx.kind}${bx.src != null && selected.has(bx.src) ? ' mm-sel' : ''}`}+ x={r.x}+ y={r.y}+ width={r.w}+ height={r.h}+ />+ );+ })}<rect ref={camRef} className="mm-cam" /></svg></div>@@ -920,9 +942,13 @@ export function Viewport() {);// Minimap overview boxes + scene bounds — recomputed on structural / data change (the// camera rect updates live inside the minimap). dataRev catches entity moves on commit.+ // `composedRev` is the third input because the boxes are COMPOSED world AABBs,+ // which read (0,0) until the engine has ticked — and a scene adopt bumps structRev+ // before that tick, with no further structural change coming to correct it.+ const composedRev = useComposedRev(structRev, dataRev, engine.status);const minimap = useMemo(() => (engine.status === 'ready' ? ViewportController.minimapBoxes() : { bounds: null, boxes: [] }),- [structRev, dataRev, engine.status],+ [structRev, dataRev, composedRev, engine.status],);// Mount the live engine canvas into the stage; it survives panel re-docking.@@ -2560,7 +2586,7 @@ export function Viewport() {tool={tool}paintHint={inTilePaint && paintTool ? TILE_HINT[paintTool] : null}/>- {engine.status === 'ready' && showMinimap && <ViewportMinimap data={minimap} />}+ {engine.status === 'ready' && showMinimap && <ViewportMinimap data={minimap} selected={selectedIds} />}{/* Contributed gizmos. Gated on `showGizmos` with the built-in ones — a pluginoverlay is a gizmo, so the same toggle has to silence it. */}{engine.status === 'ready' && showGizmos && !isPlaying && <PluginOverlays />}diff --git a/desktop/src/theme/launcher.css b/desktop/src/theme/launcher.cssindex 41898109d..eb7cbc341 100644--- a/desktop/src/theme/launcher.css+++ b/desktop/src/theme/launcher.css@@ -291,7 +291,6 @@color: var(--text-faint);white-space: nowrap;overflow: hidden;- text-overflow: ellipsis;}.proj-card__desc {font-size: var(--fs-xs);@@ -445,8 +444,13 @@color: var(--text-faint);white-space: nowrap;overflow: hidden;- text-overflow: ellipsis;}+/* Only the leading directories give way; the folder name is what tells two+ same-named projects apart, so it never shrinks (see ProjectPath). */+.proj-card__path,+.proj-row__path { display: flex; }+.pp-head { overflow: hidden; text-overflow: ellipsis; min-width: 0; }+.pp-tail { flex: 0 0 auto; }.proj-row__col {font-size: var(--fs-xs);color: var(--text-dim);diff --git a/desktop/src/theme/settings.css b/desktop/src/theme/settings.cssindex 9d3d4e93a..5dffebe73 100644--- a/desktop/src/theme/settings.css+++ b/desktop/src/theme/settings.css@@ -276,9 +276,14 @@color: var(--text);font-size: var(--fs-sm);}+/* Wraps rather than scrolling sideways. The panel docks wide and short, so an+ overflowing row put "Add Bus" — and every bus past the fold — behind a horizontal+ scrollbar macOS only draws while scrolling: the button simply looked cut off.+ Stretch so a bus without a ducking row doesn't leave the row ragged. */.mix-strips {display: flex;- align-items: flex-start;+ flex-wrap: wrap;+ align-items: stretch;gap: 8px;padding: 10px;}diff --git a/desktop/src/theme/viewport.css b/desktop/src/theme/viewport.cssindex b04293567..a7b8679ab 100644--- a/desktop/src/theme/viewport.css+++ b/desktop/src/theme/viewport.css@@ -230,13 +230,31 @@box-shadow: var(--shadow-2);line-height: 0;}-.viewport__minimap svg { display: block; cursor: crosshair; border-radius: var(--r-sm); background: rgba(0, 0, 0, 0.25); }+/* Sized against the viewport rather than fixed: at 200px the map covered a third of a+ squeezed dock, hiding the very content it summarises. The SVG keeps a fixed viewBox,+ so only the rendered box shrinks. */+.viewport__minimap svg {+ display: block;+ width: clamp(112px, 16cqw, 200px);+ aspect-ratio: 200 / 128;+ height: auto;+ cursor: crosshair;+ border-radius: var(--r-sm);+ background: rgba(0, 0, 0, 0.25);+}+/* Too little room left to summarise anything — the map would be pure occlusion. */+@container (max-width: 520px) {+ .viewport__minimap { display: none; }+}/* Wireframe outlines (matching the reference's schematic look) — reads clean even whena big background sprite spans the level; tilemaps get a faint filled region. */.viewport__minimap .mm-box { fill: none; stroke-width: 1; }.viewport__minimap .mm-sprite { stroke: var(--text-dim); opacity: 0.85; }.viewport__minimap .mm-tile { fill: color-mix(in srgb, var(--acc) 16%, transparent); stroke: color-mix(in srgb, var(--acc) 45%, transparent); opacity: 0.9; }.viewport__minimap .mm-icon { stroke: var(--text-mute); opacity: 0.45; }+/* Selection reads over everything else — finding where the selected entity sits in a+ level too big to see at once is what the map is for. */+.viewport__minimap .mm-sel { stroke: var(--sel); stroke-width: 1.5; opacity: 1; }.viewport__minimap .mm-cam { fill: color-mix(in srgb, var(--acc) 10%, transparent); stroke: var(--acc); stroke-width: 1.5; }/* coord readout (bottom-left) */diff --git a/desktop/tests/hover-select.test.ts b/desktop/tests/hover-select.test.tsnew file mode 100644index 000000000..8dd3b4d7f--- /dev/null+++ b/desktop/tests/hover-select.test.ts@@ -0,0 +1,46 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file The move gate behind picker hover-selection. A palette opens under+ * wherever the cursor rests, so "the pointer is over this row" must not+ * be mistaken for "the user pointed at this row" — Enter runs the active+ * row, and Close Project is one of them.+ */+import { describe, it, expect } from 'vitest';+import { makeMoveGate } from '@/components/hoverSelect';++describe('makeMoveGate', () => {+ it('refuses the first position — a picker opening under a still cursor', () => {+ const moved = makeMoveGate();+ expect(moved(400, 300)).toBe(false);+ });++ it('refuses repeats at the resting position (scroll-driven boundary events)', () => {+ const moved = makeMoveGate();+ moved(400, 300);+ expect(moved(400, 300)).toBe(false);+ expect(moved(400, 300)).toBe(false);+ });++ it('passes a real move, on either axis', () => {+ const moved = makeMoveGate();+ moved(400, 300);+ expect(moved(401, 300)).toBe(true);+ expect(moved(401, 301)).toBe(true);+ });++ it('keeps refusing once the pointer settles again', () => {+ const moved = makeMoveGate();+ moved(400, 300);+ expect(moved(420, 340)).toBe(true);+ expect(moved(420, 340)).toBe(false);+ });++ it('gates each picker independently', () => {+ const a = makeMoveGate();+ const b = makeMoveGate();+ a(10, 10);+ expect(a(11, 10)).toBe(true);+ expect(b(11, 10)).toBe(false);+ });+});diff --git a/desktop/tests/minimap-fit.test.ts b/desktop/tests/minimap-fit.test.tsnew file mode 100644index 000000000..70a75dbc9--- /dev/null+++ b/desktop/tests/minimap-fit.test.ts@@ -0,0 +1,95 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file The viewport minimap's world↔map projection. The camera frame is the+ * part that has to stay inside the map: what leaves it is clipped away by+ * the SVG, and a frame reduced to its top and bottom edges reads as two+ * stray lines rather than as "you are looking at all of this".+ */+import { describe, it, expect } from 'vitest';+import { minimapFit, minimapBox, minimapCamRect, minimapToWorld } from '@/engine/minimapFit';++const W = 200, H = 128, PAD = 8;+// 800 × 700 of world — wider than the map's aspect, so height is the binding axis.+const BOUNDS = { minX: -400, minY: -350, maxX: 400, maxY: 350 };+const fit = minimapFit(BOUNDS, W, H, PAD)!;++describe('minimapFit', () => {+ it('has no fit without bounds', () => {+ expect(minimapFit(null, W, H, PAD)).toBeNull();+ });++ it('letterboxes on the binding axis and centres the other', () => {+ expect(fit.scale).toBeCloseTo((H - 2 * PAD) / 700);+ expect(fit.offY).toBeCloseTo(PAD);+ expect(fit.offX).toBeGreaterThan(PAD);+ });++ it('survives a degenerate (zero-extent) scene', () => {+ const f = minimapFit({ minX: 5, minY: 5, maxX: 5, maxY: 5 }, W, H, PAD)!;+ expect(Number.isFinite(f.scale)).toBe(true);+ expect(Number.isFinite(f.offX)).toBe(true);+ });+});++describe('minimapBox', () => {+ it('places distinct world heights at distinct map heights', () => {+ const low = minimapBox(fit, -80, -132, 80, -108);+ const high = minimapBox(fit, -80, 168, 80, 192);+ expect(high.y).toBeLessThan(low.y); // world +y is up, map +y is down+ expect(high.y).not.toBeCloseTo(low.y);+ });++ it('keeps a hairline entity visible instead of collapsing it', () => {+ expect(minimapBox(fit, 0, 0, 0.01, 0.01).w).toBeGreaterThanOrEqual(1);+ });++ it('maps the full bounds onto the padded box', () => {+ const all = minimapBox(fit, BOUNDS.minX, BOUNDS.minY, BOUNDS.maxX, BOUNDS.maxY);+ expect(all.y).toBeCloseTo(PAD);+ expect(all.h).toBeCloseTo(H - 2 * PAD);+ });+});++describe('minimapCamRect', () => {+ const inside = (r: { x: number; y: number; w: number; h: number }) =>+ r.x >= 0 && r.y >= 0 && r.x + r.w <= W + 1e-6 && r.y + r.h <= H + 1e-6;++ it('stays inside the map when the view is far wider than the scene', () => {+ const r = minimapCamRect(fit, { cx: 0, cy: 0, halfW: 4000, halfH: 350 }, W, H);+ expect(inside(r)).toBe(true);+ });++ it('stays inside the map when the view is panned right off the scene', () => {+ const r = minimapCamRect(fit, { cx: 9000, cy: 0, halfW: 500, halfH: 300 }, W, H);+ expect(inside(r)).toBe(true);+ });++ it('stays inside the map when the view is panned above the scene', () => {+ const r = minimapCamRect(fit, { cx: 0, cy: 9000, halfW: 500, halfH: 300 }, W, H);+ expect(inside(r)).toBe(true);+ });++ it('tracks a sub-view rather than always filling the map', () => {+ const r = minimapCamRect(fit, { cx: 0, cy: 0, halfW: 100, halfH: 75 }, W, H);+ expect(inside(r)).toBe(true);+ expect(r.w).toBeLessThan(W / 2);+ expect(r.x).toBeGreaterThan(0);+ });++ it('moves with the camera', () => {+ const v = { halfW: 100, halfH: 75 };+ const left = minimapCamRect(fit, { cx: -200, cy: 0, ...v }, W, H);+ const right = minimapCamRect(fit, { cx: 200, cy: 0, ...v }, W, H);+ expect(right.x).toBeGreaterThan(left.x);+ });+});++describe('minimapToWorld', () => {+ it('inverts the box projection', () => {+ const r = minimapBox(fit, -80, -132, 80, -108);+ const p = minimapToWorld(fit, r.x, r.y);+ expect(p.x).toBeCloseTo(-80);+ expect(p.y).toBeCloseTo(-108);+ });+});