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): trackpad pan, real Restart, self-teaching HUD on by default
esengine94bdf0adaf55
diff --git a/desktop/src/components/NodeGraphCanvas.tsx b/desktop/src/components/NodeGraphCanvas.tsxindex c774ca1f0..b3b1a2b3d 100644--- a/desktop/src/components/NodeGraphCanvas.tsx+++ b/desktop/src/components/NodeGraphCanvas.tsx@@ -133,6 +133,8 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(prop// world coords inside a transformed container, so there are no scrollbars.const [vp, setVp] = useState({ x: 0, y: 0, zoom: 1 });const pan = useRef<{ sx: number; sy: number; vx: number; vy: number } | null>(null);+ const spaceHeld = useRef(false);+ const [spacePan, setSpacePan] = useState(false); // Space+drag pan for trackpad usersconst openMenu = (e: ReactMouseEvent, target: ContextTarget) => {if (!menuItems) return;@@ -231,6 +233,28 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(prop// eslint-disable-next-line react-hooks/exhaustive-deps}, [nodes, vp, win]);+ // Space = pan-drag mode (no middle button needed — the trackpad/laptop path).+ useEffect(() => {+ const typing = (el: EventTarget | null): boolean => {+ const n = el as HTMLElement | null;+ return !!n && (n.tagName === 'INPUT' || n.tagName === 'TEXTAREA' || n.isContentEditable);+ };+ const down = (e: KeyboardEvent) => {+ if (e.code !== 'Space' || e.repeat || typing(e.target)) return;+ spaceHeld.current = true;+ setSpacePan(true);+ };+ const up = (e: KeyboardEvent) => {+ if (e.code === 'Space') { spaceHeld.current = false; setSpacePan(false); }+ };+ win.addEventListener('keydown', down);+ win.addEventListener('keyup', up);+ return () => {+ win.removeEventListener('keydown', down);+ win.removeEventListener('keyup', up);+ };+ }, [win]);+// Keyboard, scoped to the focused canvas (the canvas div carries tabIndex, so// clicking a node lands focus here) — a window listener would make two open// graph editors both react to one Delete.@@ -335,9 +359,10 @@ export function NodeGraphCanvas<N extends CanvasNode, E extends CanvasEdge>(propreturn (<div className="panel ng-root" onKeyDown={onKeyDown}>{toolbar && <div className="ng-bar">{toolbar}</div>}- <div className="ng-canvas" tabIndex={0} style={{ backgroundSize: `${20 * vp.zoom}px ${20 * vp.zoom}px`, backgroundPosition: `${vp.x}px ${vp.y}px` }} ref={canvasRef}+ <div className="ng-canvas" tabIndex={0} style={{ backgroundSize: `${20 * vp.zoom}px ${20 * vp.zoom}px`, backgroundPosition: `${vp.x}px ${vp.y}px`, ...(spacePan ? { cursor: 'grab' } : null) }} ref={canvasRef}onPointerDown={e => {- if (e.button === 1) { e.preventDefault(); pan.current = { sx: e.clientX, sy: e.clientY, vx: vp.x, vy: vp.y }; return; }+ // Middle-drag, or Space+left-drag (trackpad), pans; a plain left-click deselects.+ if (e.button === 1 || (e.button === 0 && spaceHeld.current)) { e.preventDefault(); pan.current = { sx: e.clientX, sy: e.clientY, vx: vp.x, vy: vp.y }; return; }onSelectNode(null); onSelectEdge(null);}}onWheel={e => {diff --git a/desktop/src/i18n/messages/sequencer.ts b/desktop/src/i18n/messages/sequencer.tsindex 219598c1c..2a76c50b6 100644--- a/desktop/src/i18n/messages/sequencer.ts+++ b/desktop/src/i18n/messages/sequencer.ts@@ -9,8 +9,8 @@ export const sequencerMessages = defineMessages({// — empty state —'seq.empty.title': { en: 'No animation open', zh: '未打开动画' },'seq.empty.hint': {- en: 'Create a new animation, or double-click an existing .esanim in the Content Browser.',- zh: '新建一个动画,或在内容浏览器中双击已有的 .esanim 文件。',+ en: 'Create a new animation, or double-click an existing .estimeline in the Content Browser.',+ zh: '新建一个动画,或在内容浏览器中双击已有的 .estimeline 文件。',},'seq.empty.new': { en: 'New animation', zh: '新建动画' },'seq.empty.step1': {diff --git a/desktop/src/layout/Toolbar.tsx b/desktop/src/layout/Toolbar.tsxindex b9b162b7e..96a3d5775 100644--- a/desktop/src/layout/Toolbar.tsx+++ b/desktop/src/layout/Toolbar.tsx@@ -117,7 +117,7 @@ export function Toolbar() {? t('layout.restart'): `${t('cmd.play.toggle')}${hint('play.toggle')}`}- onClick={() => commands.run('play.toggle')}+ onClick={() => (isPlaying ? useEditorStore.getState().restart() : commands.run('play.toggle'))}><Play size={15} strokeWidth={1.9} fill="currentColor" />{isPlaying ? t('layout.restart') : t('cmd.play.toggle')}diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex f01c6aad6..1453e7b95 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -823,8 +823,11 @@ export function Viewport() {// whose shaped-cell paths (grid + selection + gesture + hover) replace the square// engine grid and the axis-aligned div ghost, which only fit an orthogonal grid.const tileGridRef = useRef<SVGSVGElement | null>(null);- // Camera pan (middle/right drag) is built-in navigation, separate from tools.+ // Camera pan (middle/right drag, or Space+left drag for trackpad users) is+ // built-in navigation, separate from tools.const panRef = useRef<{ px: number; py: number } | null>(null);+ const spaceHeld = useRef(false);+ const [spacePan, setSpacePan] = useState(false); // drives the grab cursor// The tool that owns the in-progress left-button stroke (move/up route to it).const activeToolRef = useRef<EditorTool | null>(null);// Host services handed to tools during a stroke; stable across renders.@@ -1735,12 +1738,37 @@ export function Viewport() {return () => win.removeEventListener('keydown', onKey, true);}, [toolCtx, win]);+ // Space-held = pan-drag mode (the trackpad/laptop pan gesture; no middle button+ // needed). Ignored while typing so a Space in a field doesn't arm it.+ useEffect(() => {+ const typing = (el: EventTarget | null): boolean => {+ const n = el as HTMLElement | null;+ return !!n && (n.tagName === 'INPUT' || n.tagName === 'TEXTAREA' || n.isContentEditable);+ };+ const down = (e: KeyboardEvent) => {+ if (e.code !== 'Space' || e.repeat || typing(e.target)) return;+ spaceHeld.current = true;+ setSpacePan(true);+ };+ const up = (e: KeyboardEvent) => {+ if (e.code !== 'Space') return;+ spaceHeld.current = false;+ setSpacePan(false);+ };+ win.addEventListener('keydown', down);+ win.addEventListener('keyup', up);+ return () => {+ win.removeEventListener('keydown', down);+ win.removeEventListener('keyup', up);+ };+ }, [win]);+const onPointerDown = (e: ReactPointerEvent) => {if (engine.status !== 'ready') return;- // Middle / right drag = pan the view (camera navigation, always available- // regardless of the active tool).- if (e.button === 1 || e.button === 2) {+ // Middle / right drag, or Space + left drag = pan the view (camera navigation,+ // always available regardless of the active tool; Space-drag is the trackpad path).+ if (e.button === 1 || e.button === 2 || (e.button === 0 && spaceHeld.current)) {e.preventDefault();panRef.current = { px: e.clientX, py: e.clientY };stageRef.current?.setPointerCapture(e.pointerId);@@ -2073,6 +2101,7 @@ export function Viewport() {ref={stageRef}className="viewport__stage"data-engine="esengine.wasm"+ style={spacePan ? { cursor: 'grab' } : undefined}onPointerDown={onPointerDown}onPointerMove={onPointerMove}onPointerUp={endDrag}diff --git a/desktop/src/store/editorStore.ts b/desktop/src/store/editorStore.tsindex f6f9f0aa5..7b1c68bda 100644--- a/desktop/src/store/editorStore.ts+++ b/desktop/src/store/editorStore.ts@@ -18,6 +18,7 @@ interface EditorState {togglePlay: () => void;togglePause: () => void;stop: () => void;+ restart: () => void;// Where Play runs: in the Viewport (UE5 PIE, default) or a separate Game tab.playTarget: 'viewport' | 'window';setPlayTarget: (t: 'viewport' | 'window') => void;@@ -120,6 +121,13 @@ export const useEditorStore = create<EditorState>((set) => ({set((s) => ({ isPlaying: !s.isPlaying, isPaused: false })),togglePause: () => set((s) => ({ isPaused: !s.isPaused })),stop: () => set({ isPlaying: false, isPaused: false }),+ // A real restart: end the running session, then re-enter Play next frame so the+ // play effect sees a false→true transition and boots a FRESH game (warm re-play+ // is fast). The button labelled "Restart" used to just stop.+ restart: () => {+ set({ isPlaying: false, isPaused: false });+ requestAnimationFrame(() => set({ isPlaying: true, isPaused: false }));+ },// Guarded: this store is imported in pure-node tests where localStorage is absent.playTarget:(typeof localStorage !== 'undefined'@@ -148,7 +156,10 @@ export const useEditorStore = create<EditorState>((set) => ({showTileCollision: true,previewFx: true,showStats: false,- showCoords: false,+ // On by default: this strip carries the active-tool hint line (Alt-duplicate,+ // brush flip/rotate, eyedropper…) + the cursor world coord / tile-cell readout —+ // the editor's cheapest self-teaching surface. FPS/entity stats stay opt-in.+ showCoords: true,showMinimap: true,snapping: false,snapStep: 32,