Skip to content

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.

feat(editor): New Scene command (File ▸ New Scene / Cmd+N)

esengine666cea487323
diff --git a/desktop/src/commands/editorCommands.ts b/desktop/src/commands/editorCommands.ts
index 9442d4357..11a6f53db 100644
--- a/desktop/src/commands/editorCommands.ts
+++ b/desktop/src/commands/editorCommands.ts
@@ -23,6 +23,18 @@ const sel = () => useSelection.getState();
const tool = (mode: ToolMode) => () => editor().setTool(mode);
// — File / project —
+commands.register({
+ id: 'scene.new',
+ label: 'New Scene',
+ category: 'File',
+ keybinding: 'mod+n',
+ isEnabled: () => !!ProjectStore.getSnapshot(),
+ run: () => {
+ // Discard guard: history is the editor's unsaved-changes proxy (no dirty flag).
+ if (EditorHistory.canUndo() && !window.confirm('New scene? Unsaved changes will be lost.')) return;
+ void ProjectStore.newScene().then(() => sel().select(null));
+ },
+});
commands.register({
id: 'project.open',
label: 'Open Project…',
diff --git a/desktop/src/layout/MenuBar.tsx b/desktop/src/layout/MenuBar.tsx
index 2401535d5..91100e77b 100644
--- a/desktop/src/layout/MenuBar.tsx
+++ b/desktop/src/layout/MenuBar.tsx
@@ -75,6 +75,8 @@ export function MenuBar() {
{
title: 'File',
items: [
+ cmdItem('scene.new'),
+ { sep: true },
cmdItem('project.open'),
{ sep: true },
cmdItem('project.save'),
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index b0f588f08..8880d4d35 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -258,6 +258,46 @@ class ProjectStoreImpl {
this.store.setState({ project: { ...st, currentScene: rel } });
}
+ /** A fresh, untitled scene document: a single orthographic Camera at the origin. */
+ private blankScene(): SceneData {
+ return {
+ version: '1.0',
+ name: 'Untitled',
+ entities: [
+ {
+ id: 0,
+ name: 'Camera',
+ parent: null,
+ children: [],
+ components: [
+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 10 } } },
+ { type: 'Camera', data: { projectionType: 1, orthoSize: 300, isActive: true, priority: 0 } },
+ ],
+ visible: true,
+ },
+ ],
+ } as unknown as SceneData;
+ }
+
+ /**
+ * Start a fresh, UNTITLED scene (the UE/Unity "New Scene"): a blank document with
+ * just a default Camera, adopted into the model. `currentScene` is null so the file
+ * is created on first Save (which routes to Save-As). Clears history + selection like
+ * a load, so undo can't reach the previous scene's entities. No disk write yet.
+ */
+ async newScene(): Promise<void> {
+ const st = this.state;
+ if (!st) return;
+ const blank = this.blankScene();
+ await this.buildAssetRegistry(); // keep the uuid→path registry current for new refs
+ EditorHistory.clear();
+ useSelection.getState().select(null);
+ Reconciler.setAssetResolver((uuid) => this.handleForUuid(uuid));
+ Reconciler.adopt(blank, blank); // no @uuid: refs → resolved === raw
+ EngineHost.syncEditorViewToScene();
+ this.store.setState({ project: { ...st, currentScene: null } });
+ }
+
/**
* Load the project's asset index (the main-process AssetDatabase scan,
* REARCH_ASSETS.md A2) into a uuid→path registry, then point the engine
diff --git a/desktop/tests/commands.test.ts b/desktop/tests/commands.test.ts
index 475a0d16e..dd949dc81 100644
--- a/desktop/tests/commands.test.ts
+++ b/desktop/tests/commands.test.ts
@@ -70,4 +70,10 @@ describe('command registry', () => {
expect(commands.get('entity.delete')?.label).toBe('Delete');
expect(commands.get('entity.delete')?.keybinding).toEqual(['delete', 'backspace']);
});
+
+ it('registers New Scene (mod+n)', () => {
+ const cmd = commands.get('scene.new');
+ expect(cmd?.label).toBe('New Scene');
+ expect(cmd?.keybinding).toBe('mod+n');
+ });
});