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: restore last opened scene per project on startup

esengineb535309f5285
diff --git a/editor/src/Editor.ts b/editor/src/Editor.ts
index cf4b1f8bc..0a7eb8838 100644
--- a/editor/src/Editor.ts
+++ b/editor/src/Editor.ts
@@ -77,7 +77,7 @@ import {
setSettingsValue,
onSettingsChange,
} from './settings';
-import { loadProjectConfig } from './launcher/ProjectService';
+import { loadProjectConfig, loadEditorLocalSettings, saveEditorLocalSetting } from './launcher/ProjectService';
import type { SpineVersion } from './types/ProjectTypes';
// =============================================================================
@@ -153,6 +153,7 @@ export class Editor {
this.initializeAllScripts();
this.syncProjectSettings();
this.previewService_ = new PreviewService({ projectPath: this.projectPath_ });
+ this.restoreLastScene();
}
}
@@ -322,6 +323,7 @@ export class Editor {
await saveSceneToPath(scene, scenePath);
}
this.store_.loadScene(scene, scenePath);
+ this.saveLastOpenedScene(scenePath);
console.log('Scene loaded:', scenePath);
}
}
@@ -434,6 +436,20 @@ export class Editor {
});
}
+ private async restoreLastScene(): Promise<void> {
+ if (!this.projectPath_) return;
+ const settings = await loadEditorLocalSettings(this.projectPath_);
+ const lastScene = settings?.lastOpenedScene as string | undefined;
+ if (lastScene) {
+ await this.openSceneFromPath(lastScene);
+ }
+ }
+
+ private saveLastOpenedScene(scenePath: string): void {
+ if (!this.projectPath_) return;
+ saveEditorLocalSetting(this.projectPath_, 'lastOpenedScene', scenePath);
+ }
+
private async saveProjectField(projectPath: string): Promise<void> {
const config = await loadProjectConfig(projectPath);
if (!config) return;
diff --git a/editor/src/launcher/ProjectService.ts b/editor/src/launcher/ProjectService.ts
index 5a2d62093..16265b873 100644
--- a/editor/src/launcher/ProjectService.ts
+++ b/editor/src/launcher/ProjectService.ts
@@ -237,6 +237,41 @@ export async function openProject(
}
}
+export async function loadEditorLocalSettings(projectPath: string): Promise<Record<string, unknown> | null> {
+ const fs = getNativeFS();
+ if (!fs) return null;
+
+ const projectDir = projectPath.replace(/\/[^/]+\.esproject$/, '');
+ const settingsPath = joinPath(projectDir, '.esengine/settings.json');
+ const content = await fs.readFile(settingsPath);
+ if (!content) return null;
+
+ try {
+ return JSON.parse(content);
+ } catch {
+ return null;
+ }
+}
+
+export async function saveEditorLocalSetting(projectPath: string, key: string, value: unknown): Promise<void> {
+ const fs = getNativeFS();
+ if (!fs) return;
+
+ const projectDir = projectPath.replace(/\/[^/]+\.esproject$/, '');
+ const settingsPath = joinPath(projectDir, '.esengine/settings.json');
+
+ let settings: Record<string, unknown> = {};
+ const content = await fs.readFile(settingsPath);
+ if (content) {
+ try {
+ settings = JSON.parse(content);
+ } catch {}
+ }
+
+ settings[key] = value;
+ await fs.writeFile(settingsPath, JSON.stringify(settings, null, 2));
+}
+
export async function loadProjectConfig(
projectPath: string
): Promise<ProjectConfig | null> {