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): disable Play in Prefab Mode; keep user quats an angle
esengineae9a53a3089d
diff --git a/desktop/src/App.tsx b/desktop/src/App.tsxindex 701d667e2..102f78ac4 100644--- a/desktop/src/App.tsx+++ b/desktop/src/App.tsx@@ -172,6 +172,13 @@ export function App() {const isPaused = useEditorStore((s) => s.isPaused);useEffect(() => {if (isPlaying) {+ // Prefab Mode holds a prefab tree, not a playable scene (no camera → a black+ // frame). Refuse Play here so it can't start from the button, F5 or a command.+ if (ProjectStore.getSnapshot()?.prefabEdit) {+ Toasts.push(t('layout.toast.noPlayInPrefab'), 'warn');+ useEditorStore.getState().stop();+ return;+ }const payload = ProjectStore.playPayload();if (!payload) {Toasts.push(t('layout.toast.openSceneFirst'), 'error');diff --git a/desktop/src/engine/schema.ts b/desktop/src/engine/schema.tsindex 6721c44b2..702301a96 100644--- a/desktop/src/engine/schema.ts+++ b/desktop/src/engine/schema.ts@@ -161,7 +161,11 @@ const quatToAngleZ = (q: { z: number; w: number }) =>Math.round(Math.atan2(q.z, q.w) * 2 * RAD2DEG * 100) / 100;export const angleZToQuat = (deg: number) => {const h = (deg * DEG2RAD) / 2;- return { x: 0, y: 0, z: Math.sin(h), w: Math.cos(h) };+ // w-FIRST key order on purpose: the quaternion discriminator treats a w-first+ // layout as a rotation, so a USER component's quaternion field (not named+ // rotation/worldRotation) keeps its angle control after an edit instead of+ // flipping to four vec4 boxes. The engine reads x/y/z/w by name — order is free.+ return { w: Math.cos(h), x: 0, y: 0, z: Math.sin(h) };};// A rotation quaternion and a vec4 (Camera viewport rect, a 9-slice border) share thediff --git a/desktop/src/i18n/messages/layout.ts b/desktop/src/i18n/messages/layout.tsindex aa9154781..2469fdc57 100644--- a/desktop/src/i18n/messages/layout.ts+++ b/desktop/src/i18n/messages/layout.ts@@ -91,4 +91,5 @@ export const layoutMessages = defineMessages({// — App shell toasts —'layout.toast.openSceneFirst': { en: 'Open a scene before playing', zh: '请先打开场景再运行' },+ 'layout.toast.noPlayInPrefab': { en: 'Exit Prefab Mode before playing — a prefab has no scene to run.', zh: '请先退出预制体编辑再运行——预制体没有可运行的场景。' },});diff --git a/desktop/src/layout/Toolbar.tsx b/desktop/src/layout/Toolbar.tsxindex 1b95d87e6..b9b162b7e 100644--- a/desktop/src/layout/Toolbar.tsx+++ b/desktop/src/layout/Toolbar.tsx@@ -18,6 +18,7 @@ import { useEditorStore } from '@/store/editorStore';import { IconButton } from '@/components/IconButton';import { ContextMenu } from '@/components/Menu';import { EditorHistory } from '@/engine/EditorHistory';+import { ProjectStore } from '@/project/ProjectStore';import { commands, formatKeybinding } from '@/commands';import { t } from '@/i18n';@@ -63,6 +64,12 @@ export function Toolbar() {const [modeMenu, setModeMenu] = useState<{ x: number; y: number } | null>(null);const { isPlaying, isPaused, togglePause, stop } = useEditorStore();+ // Play is unavailable in Prefab Mode — a prefab has no scene to run.+ const inPrefabMode = useSyncExternalStore(+ ProjectStore.subscribe,+ () => !!ProjectStore.getSnapshot()?.prefabEdit,+ );+// Re-render on history changes to refresh undo/redo enabled state + labels.useSyncExternalStore(EditorHistory.subscribe, EditorHistory.getVersion);const undoLabel = EditorHistory.undoLabel();@@ -102,7 +109,14 @@ export function Toolbar() {<buttontype="button"className="play-main"- title={isPlaying ? t('layout.restart') : `${t('cmd.play.toggle')}${hint('play.toggle')}`}+ disabled={inPrefabMode}+ title={+ inPrefabMode+ ? t('layout.toast.noPlayInPrefab')+ : isPlaying+ ? t('layout.restart')+ : `${t('cmd.play.toggle')}${hint('play.toggle')}`+ }onClick={() => commands.run('play.toggle')}><Play size={15} strokeWidth={1.9} fill="currentColor" />diff --git a/desktop/tests/inspector-vec4-quat.test.ts b/desktop/tests/inspector-vec4-quat.test.tsindex 872349429..3b357cb1f 100644--- a/desktop/tests/inspector-vec4-quat.test.ts+++ b/desktop/tests/inspector-vec4-quat.test.ts@@ -7,7 +7,7 @@* (atan2(z=1, w=1)·2 = 90°).*/import { describe, it, expect } from 'vitest';-import { inferField, inspectorFields } from '@/engine/schema';+import { inferField, inspectorFields, angleZToQuat } from '@/engine/schema';describe('quaternion vs vec4 inference', () => {it('a rotation quaternion (w-first) reads as an angle', () => {@@ -32,6 +32,14 @@ describe('quaternion vs vec4 inference', () => {expect(viewport!.value).toEqual([0, 0, 1, 1]);});+ it('a user quaternion stays an angle after an angle EDIT (angleZToQuat is w-first)', () => {+ // Editing the angle rewrites the field via angleZToQuat; if it emitted x-first,+ // the next inference would mis-classify the field as a vec4 and drop the control.+ const edited = angleZToQuat(45);+ expect(Object.keys(edited)[0]).toBe('w'); // w-first layout preserved+ expect(inferField('orient', edited, false)!.type).toBe('angle');+ });+it("end-to-end: the Transform's rotation stays an angle", () => {const data = { position: { x: 0, y: 0, z: 0 }, rotation: { w: 1, x: 0, y: 0, z: 0 }, scale: { x: 1, y: 1, z: 1 } };const rot = inspectorFields('Transform', data).find((f) => f.key === 'rotation')!;