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: resolve playable build and editor panel issues
esengine53dfd67aadc0
diff --git a/desktop/public/wasm/esengine.single.js b/desktop/public/wasm/esengine.single.jsindex 694bc7307..f58ca3be7 100644Binary files a/desktop/public/wasm/esengine.single.js and b/desktop/public/wasm/esengine.single.js differdiff --git a/desktop/src/native-fs.ts b/desktop/src/native-fs.tsindex 5d4ae6e8c..998959766 100644--- a/desktop/src/native-fs.ts+++ b/desktop/src/native-fs.ts@@ -130,8 +130,7 @@ export const nativeFS: NativeFS = {try {await mkdir(path, { recursive: true });return true;- } catch (err) {- console.error('Failed to create directory:', err);+ } catch {return false;}},@@ -167,8 +166,7 @@ export const nativeFS: NativeFS = {async readFile(path: string) {try {return await readTextFile(path);- } catch (err) {- console.error('Failed to read file:', err);+ } catch {return null;}},@@ -176,8 +174,7 @@ export const nativeFS: NativeFS = {async readBinaryFile(path: string) {try {return await readFile(path);- } catch (err) {- console.error('Failed to read binary file:', err);+ } catch {return null;}},diff --git a/desktop/vite.config.ts b/desktop/vite.config.tsindex f94131734..2370ca57e 100644--- a/desktop/vite.config.ts+++ b/desktop/vite.config.ts@@ -2,19 +2,29 @@ import { defineConfig, type Plugin } from 'vite';const host = process.env.TAURI_DEV_HOST;-function removeCrossorigin(): Plugin {+function tauriHtmlFixes(): Plugin {return {- name: 'remove-crossorigin',+ name: 'tauri-html-fixes',enforce: 'post',transformIndexHtml(html) {- return html.replace(/ crossorigin/g, '');+ let result = html.replace(/ crossorigin/g, '');++ const linkMatch = result.match(/<link rel="stylesheet"[^>]*>/);+ const scriptMatch = result.match(/<script type="module"[^>]*><\/script>/);+ if (linkMatch && scriptMatch) {+ const linkTag = linkMatch[0];+ const scriptTag = scriptMatch[0];+ result = result.replace(linkTag, '').replace(scriptTag, `${linkTag}\n ${scriptTag}`);+ }++ return result;},};}export default defineConfig({clearScreen: false,- plugins: [removeCrossorigin()],+ plugins: [tauriHtmlFixes()],server: {port: 5173,strictPort: true,diff --git a/editor/src/Editor.ts b/editor/src/Editor.tsindex 9f2d8c20e..5f03f7828 100644--- a/editor/src/Editor.ts+++ b/editor/src/Editor.ts@@ -768,6 +768,7 @@ export class Editor {`;this.instantiatePanels();+ this.updateBottomPanelVisibility();setEditorInstance(this);@@ -807,10 +808,9 @@ export class Editor {private buildBottomPanelsHTML(): string {const panels = getPanelsByPosition('bottom');- return panels.map(p => {- const display = p.id === this.activeBottomPanelId_ ? '' : 'display: none;';- return `<div class="es-panel-container" data-panel-id="${p.id}" style="${display}"></div>`;- }).join('');+ return panels.map(p =>+ `<div class="es-panel-container" data-panel-id="${p.id}" style="display: none;"></div>`+ ).join('');}private buildStatusBarHTML(): string {diff --git a/editor/src/asset/AssetLibrary.ts b/editor/src/asset/AssetLibrary.tsindex 367c44433..52ed24712 100644--- a/editor/src/asset/AssetLibrary.ts+++ b/editor/src/asset/AssetLibrary.ts@@ -223,6 +223,14 @@ export class AssetLibrary {}}+ unregister(relativePath: string): void {+ const uuid = this.pathToUuid_.get(relativePath);+ if (uuid) {+ this.uuidToPath_.delete(uuid);+ }+ this.pathToUuid_.delete(relativePath);+ }+private register(uuid: string, relativePath: string): void {this.uuidToPath_.set(uuid, relativePath);this.pathToUuid_.set(relativePath, uuid);diff --git a/editor/src/builder/BuildCache.ts b/editor/src/builder/BuildCache.tsindex 389026e9e..ae77d2976 100644--- a/editor/src/builder/BuildCache.ts+++ b/editor/src/builder/BuildCache.ts@@ -37,7 +37,7 @@ export interface FileChangeResult {// Constants// =============================================================================-const CACHE_VERSION = '1.0';+const CACHE_VERSION = '1.1';const CACHE_DIR = '.esengine/build-cache';// =============================================================================diff --git a/editor/src/builder/BuildService.ts b/editor/src/builder/BuildService.tsindex 91f3636c0..11512e022 100644--- a/editor/src/builder/BuildService.ts+++ b/editor/src/builder/BuildService.ts@@ -9,6 +9,7 @@ import { WeChatBuilder } from './WeChatBuilder';import { BuildCache } from './BuildCache';import { BuildProgressReporter, formatDuration } from './BuildProgress';import { BuildHistory } from './BuildHistory';+import { getProjectDir } from '../utils/path';// =============================================================================// Types@@ -46,7 +47,7 @@ export class BuildService {constructor(projectPath: string, history?: BuildHistory) {this.projectPath_ = projectPath;- this.cache_ = new BuildCache(projectPath);+ this.cache_ = new BuildCache(getProjectDir(projectPath));this.history_ = history || null;}diff --git a/editor/src/builder/PlayableBuilder.ts b/editor/src/builder/PlayableBuilder.tsindex c48c6143a..40396d1f0 100644--- a/editor/src/builder/PlayableBuilder.ts+++ b/editor/src/builder/PlayableBuilder.ts@@ -464,6 +464,9 @@ export class PlayableBuilder {private async loadSdk(): Promise<string | null> {try {+ if (this.fs_?.getEngineSingleJs) {+ return await this.fs_.getEngineSingleJs();+ }const response = await fetch('/wasm/esengine.single.js');if (!response.ok) return null;return await response.text();@@ -488,18 +491,14 @@ export class PlayableBuilder {private async compileUserScripts(): Promise<string> {const scriptsPath = joinPath(this.projectDir_, 'src');+ const hasSrcDir = await this.fs_!.exists(scriptsPath);- if (!await this.fs_!.exists(scriptsPath)) {- return this.createMinimalGameCode();+ let imports = '';+ if (hasSrcDir) {+ const scripts = await findTsFiles(this.fs_!, scriptsPath, EDITOR_ONLY_DIRS);+ imports = scripts.map(p => `import "${p}";`).join('\n');}- const scripts = await findTsFiles(this.fs_!, scriptsPath, EDITOR_ONLY_DIRS);-- if (scripts.length === 0) {- return this.createMinimalGameCode();- }-- const imports = scripts.map(p => `import "${p}";`).join('\n');const entryContent = `import * as esengine from 'esengine';(window as any).esengine = esengine;@@ -522,7 +521,7 @@ ${imports}stdin: {contents: entryContent,loader: 'ts',- resolveDir: scriptsPath,+ resolveDir: hasSrcDir ? scriptsPath : this.projectDir_,},bundle: true,format: 'iife',@@ -534,15 +533,11 @@ ${imports}plugins: [this.createVirtualFsPlugin()],});- return result.outputFiles?.[0]?.text ?? this.createMinimalGameCode();- }-- private createMinimalGameCode(): string {- return `-(function(){- var esengine = window.esengine || {};-})();-`;+ const output = result.outputFiles?.[0]?.text;+ if (!output) {+ throw new Error('esbuild produced no output');+ }+ return output;}private async initializeEsbuild(): Promise<void> {@@ -569,6 +564,13 @@ ${imports}return { path: args.path, namespace: 'virtual' };}+ if (args.path === 'esengine') {+ return { path: 'esengine', namespace: 'esengine-sdk' };+ }+ if (args.path === 'esengine/wasm') {+ return { path: 'esengine/wasm', namespace: 'esengine-sdk' };+ }+let resolvedPath = args.path;if (isAbsolutePath(args.path)) {@@ -577,34 +579,28 @@ ${imports}const baseDir = args.importer ? getParentDir(args.importer) : args.resolveDir;resolvedPath = joinPath(baseDir, args.path);} else {- if (args.path === 'esengine') {- resolvedPath = joinPath(projectDir, '.esengine/sdk/index.js');- } else if (args.path === 'esengine/wasm') {- resolvedPath = joinPath(projectDir, '.esengine/sdk/wasm.js');- } else {- const pkgPath = joinPath(projectDir, 'node_modules', args.path, 'package.json');- const pkgContent = await fs.readFile(pkgPath);- if (pkgContent) {- try {- const pkg = JSON.parse(pkgContent);- let entry = pkg.module || pkg.main || 'index.js';- if (pkg.exports) {- const root = pkg.exports['.'];- if (typeof root === 'string') {- entry = root;- } else if (root?.import) {- entry = root.import;- } else if (root?.default) {- entry = root.default;- }+ const pkgPath = joinPath(projectDir, 'node_modules', args.path, 'package.json');+ const pkgContent = await fs.readFile(pkgPath);+ if (pkgContent) {+ try {+ const pkg = JSON.parse(pkgContent);+ let entry = pkg.module || pkg.main || 'index.js';+ if (pkg.exports) {+ const root = pkg.exports['.'];+ if (typeof root === 'string') {+ entry = root;+ } else if (root?.import) {+ entry = root.import;+ } else if (root?.default) {+ entry = root.default;}- resolvedPath = joinPath(projectDir, 'node_modules', args.path, entry);- } catch {- throw new Error(`Failed to parse package.json for: ${args.path}`);}- } else {- throw new Error(`Module not found: ${args.path}. Please install it with npm.`);+ resolvedPath = joinPath(projectDir, 'node_modules', args.path, entry);+ } catch {+ throw new Error(`Failed to parse package.json for: ${args.path}`);}+ } else {+ throw new Error(`Module not found: ${args.path}. Please install it with npm.`);}}@@ -625,6 +621,16 @@ ${imports}return { path: resolvedPath, namespace: 'virtual' };});+ build.onLoad({ filter: /.*/, namespace: 'esengine-sdk' }, async (args) => {+ if (args.path === 'esengine') {+ return { contents: await fs.getSdkEsmJs(), loader: 'js' };+ }+ if (args.path === 'esengine/wasm') {+ return { contents: await fs.getSdkWasmJs(), loader: 'js' };+ }+ return { contents: '', loader: 'js' };+ });+build.onLoad({ filter: /.*/, namespace: 'virtual' }, async (args) => {const content = await fs.readFile(args.path);if (content === null) {diff --git a/editor/src/extension/ExtensionLoader.ts b/editor/src/extension/ExtensionLoader.tsindex a1085e205..f125bd679 100644--- a/editor/src/extension/ExtensionLoader.ts+++ b/editor/src/extension/ExtensionLoader.ts@@ -188,6 +188,7 @@ export class ExtensionLoader {this.onCleanup_?.();}if (!compiled) return false;+ if (!this.lastCompiled_) return true;this.currentContext_ = new ExtensionContext();setEditorAPI(this.currentContext_.createAPI(this.baseAPI_));const executed = await this.execute();@@ -207,6 +208,8 @@ export class ExtensionLoader {this.unwatch();const srcPath = joinPath(this.projectDir_, 'src');+ if (!await fs.exists(srcPath)) return;+this.unwatchFn_ = await fs.watchDirectory(srcPath,(event) => {diff --git a/editor/src/panels/ContentBrowserPanel.ts b/editor/src/panels/ContentBrowserPanel.tsindex fd29cca05..eb6749c59 100644--- a/editor/src/panels/ContentBrowserPanel.ts+++ b/editor/src/panels/ContentBrowserPanel.ts@@ -11,6 +11,7 @@ import { showInputDialog, showConfirmDialog } from '../ui/dialog';import { getEditorContext } from '../context/EditorContext';import { joinPath, getParentDir } from '../utils/path';import type { NativeFS, DirectoryEntry } from '../types/NativeFS';+import { getAssetLibrary } from '../asset/AssetLibrary';// =============================================================================// Types@@ -519,6 +520,18 @@ export class ContentBrowserPanel {try {const platform = getPlatformAdapter();await platform.remove(path);++ const metaPath = `${path}.meta`;+ try { await platform.remove(metaPath); } catch { /* no .meta file */ }++ if (this.rootFolder_) {+ const projectDir = this.rootFolder_.path;+ const prefix = projectDir.endsWith('/') ? projectDir : projectDir + '/';+ if (path.startsWith(prefix)) {+ getAssetLibrary().unregister(path.substring(prefix.length));+ }+ }+this.refresh();} catch (err) {console.error('Failed to delete asset:', err);diff --git a/editor/src/scripting/ScriptLoader.ts b/editor/src/scripting/ScriptLoader.tsindex 9341e56d2..af967fb83 100644--- a/editor/src/scripting/ScriptLoader.ts+++ b/editor/src/scripting/ScriptLoader.ts@@ -159,6 +159,8 @@ export class ScriptLoader {this.unwatch();const srcPath = joinPath(this.projectDir_, 'src');+ if (!await fs.exists(srcPath)) return;+this.unwatchFn_ = await fs.watchDirectory(srcPath,(event) => {diff --git a/editor/src/utils/icons.ts b/editor/src/utils/icons.tsindex c0230f0c6..e48f5083b 100644--- a/editor/src/utils/icons.ts+++ b/editor/src/utils/icons.ts@@ -64,24 +64,29 @@ type IconNode = [string, Record<string, string | number>][];const DEFAULT_SIZE = 14;-const ES_LOGO_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">+let logoIdCounter = 0;++function createLogoSvg(size = 64): string {+ const uid = `es-logo-${++logoIdCounter}`;+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="${size}" height="${size}"><defs>- <linearGradient id="bgGrad" x1="0%" y1="0%" x2="100%" y2="100%">- <stop offset="0%" style="stop-color:#2d2d2d"/>- <stop offset="100%" style="stop-color:#1a1a1a"/>+ <linearGradient id="${uid}-bg" x1="0%" y1="0%" x2="100%" y2="100%">+ <stop offset="0%" stop-color="#2d2d2d"/>+ <stop offset="100%" stop-color="#1a1a1a"/></linearGradient>- <linearGradient id="textGrad" x1="0%" y1="0%" x2="0%" y2="100%">- <stop offset="0%" style="stop-color:#e5c07b"/>- <stop offset="100%" style="stop-color:#d19a66"/>+ <linearGradient id="${uid}-text" x1="0%" y1="0%" x2="0%" y2="100%">+ <stop offset="0%" stop-color="#e5c07b"/>+ <stop offset="100%" stop-color="#d19a66"/></linearGradient></defs>- <rect width="512" height="512" rx="64" fill="url(#bgGrad)"/>+ <rect width="512" height="512" rx="64" fill="url(#${uid}-bg)"/><g>- <polygon points="72,120 72,392 240,392 240,340 140,340 140,282 220,282 220,230 140,230 140,172 240,172 240,120" fill="url(#textGrad)"/>- <path d="M 280 172 Q 280 120 340 120 L 420 120 Q 450 120 450 160 L 450 186 L 398 186 L 398 168 Q 398 158 384 158 L 350 158 Q 320 158 320 188 Q 320 218 350 218 L 400 218 Q 450 218 450 274 L 450 332 Q 450 392 390 392 L 310 392 Q 270 392 270 340 L 270 314 L 322 314 L 322 340 Q 322 354 340 354 L 384 354 Q 404 354 404 324 L 404 290 Q 404 260 380 260 L 330 260 Q 280 260 280 208 Z" fill="url(#textGrad)"/>+ <polygon points="72,120 72,392 240,392 240,340 140,340 140,282 220,282 220,230 140,230 140,172 240,172 240,120" fill="url(#${uid}-text)"/>+ <path d="M 280 172 Q 280 120 340 120 L 420 120 Q 450 120 450 160 L 450 186 L 398 186 L 398 168 Q 398 158 384 158 L 350 158 Q 320 158 320 188 Q 320 218 350 218 L 400 218 Q 450 218 450 274 L 450 332 Q 450 392 390 392 L 310 392 Q 270 392 270 340 L 270 314 L 322 314 L 322 340 Q 322 354 340 354 L 384 354 Q 404 354 404 324 L 404 290 Q 404 260 380 260 L 330 260 Q 280 260 280 208 Z" fill="url(#${uid}-text)"/></g><rect x="72" y="424" width="368" height="4" fill="#d19a66" opacity="0.6"/></svg>`;+}function renderIcon(iconNode: IconNode, size = DEFAULT_SIZE): string {const children = iconNode@@ -101,7 +106,7 @@ function renderIcon(iconNode: IconNode, size = DEFAULT_SIZE): string {// =============================================================================export const icons = {- logo: (size = 64) => ES_LOGO_SVG.replace('viewBox="0 0 512 512"', `viewBox="0 0 512 512" width="${size}" height="${size}"`),+ logo: (size = 64) => createLogoSvg(size),menu: (size?: number) => renderIcon(Menu as IconNode, size),plus: (size?: number) => renderIcon(Plus as IconNode, size),copy: (size?: number) => renderIcon(Copy as IconNode, size),