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
feat(editor): a scene with no camera says so, before Play goes black
yhhd29e98273bf4
diff --git a/desktop/src/engine/EditorControlSurface.ts b/desktop/src/engine/EditorControlSurface.tsindex b5ca47835..535e9e660 100644--- a/desktop/src/engine/EditorControlSurface.ts+++ b/desktop/src/engine/EditorControlSurface.ts@@ -664,7 +664,25 @@ export class EditorControlSurfaceImpl {if (node.children?.length) visit(node.children);}};- visit(this.s.query.readSceneTree());+ const tree = this.s.query.readSceneTree();+ visit(tree);++ // Scene-level: a scene with content and no camera renders NOTHING when the+ // game runs. The editor has an eye of its own, so the viewport looks right+ // and Play is black — the sharpest way the editor can lie to you, and one an+ // author (or an agent) has no way to attribute. Only worth saying when there+ // is something to look at: an empty scene is a scene being started.+ const hasContent = (nodes: SceneNode[]): boolean =>+ nodes.some((n) => n.kind !== 'camera' || (n.children?.length ? hasContent(n.children) : false));+ const hasCamera = (nodes: SceneNode[]): boolean =>+ nodes.some((n) => n.kind === 'camera' || (n.children?.length ? hasCamera(n.children) : false));+ if (tree.length > 0 && hasContent(tree) && !hasCamera(tree)) {+ issues.push({+ entity: -1, entityName: '', component: 'Camera', problem: 'notice',+ detail: 'this scene has no Camera — it draws in the editor (which has its own view) and '+ + 'renders NOTHING when the game runs. Add a Camera entity.',+ });+ }return issues;}/** The lossless JSON-first scene truth (deep clone), or null if none loaded. */diff --git a/desktop/tests/scene-camera-diagnostic.test.ts b/desktop/tests/scene-camera-diagnostic.test.tsnew file mode 100644index 000000000..e723d5342--- /dev/null+++ b/desktop/tests/scene-camera-diagnostic.test.ts@@ -0,0 +1,61 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file A scene with content and no camera is a black game.+ *+ * The editor renders through a view of its own, so a cameraless scene looks+ * finished in the viewport and draws nothing the moment Play starts. From a+ * dogfood run: an agent built a 116-entity chess board, ran it, and got a black+ * frame with no error — the diagnostics sweep had nothing to say about the one+ * thing that was wrong.+ */+import { describe, it, expect, vi, beforeEach } from 'vitest';+import type { SceneNode } from '@/types';++const h = { tree: [] as SceneNode[] };++vi.mock('../src/engine/EngineHost', () => ({ EngineHost: {} }));++const node = (id: number, name: string, kind: string, children: SceneNode[] = []): SceneNode =>+ ({ id, name, kind, visible: true, locked: false, children } as SceneNode);++const surface = {+ s: {+ query: {+ readSceneTree: () => h.tree,+ readInspector: () => [],+ },+ },+};++// The sweep under test, bound to the stub session.+const { EditorControlSurfaceImpl } = await import('@/engine/EditorControlSurface');+const getDiagnostics = (): Array<{ component: string; detail: string }> =>+ EditorControlSurfaceImpl.prototype.getDiagnostics.call(surface as never);++beforeEach(() => { h.tree = []; });++describe('the camera a scene needs to be seen at all', () => {+ it('says so when content has no camera anywhere', () => {+ h.tree = [node(1, 'Board', 'group', [node(2, 'a1', 'sprite')])];+ const found = getDiagnostics().filter((d: { component: string }) => d.component === 'Camera');+ expect(found).toHaveLength(1);+ expect(found[0].detail).toContain('renders NOTHING');+ });++ it('says nothing when a camera is there, however deep', () => {+ h.tree = [node(1, 'Board', 'group', [node(2, 'a1', 'sprite'), node(3, 'Cam', 'camera')])];+ expect(getDiagnostics().filter((d: { component: string }) => d.component === 'Camera')).toHaveLength(0);+ });++ // An empty scene is a scene being started, not a mistake to nag about.+ it('says nothing about an empty scene', () => {+ h.tree = [];+ expect(getDiagnostics()).toHaveLength(0);+ });++ it('says nothing about a scene that is only a camera', () => {+ h.tree = [node(1, 'Cam', 'camera')];+ expect(getDiagnostics().filter((d: { component: string }) => d.component === 'Camera')).toHaveLength(0);+ });+});