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): an asset can be deleted by name, not by selection
yhh570db2f63a17
diff --git a/desktop/scripts/editor-checks/material-authoring.mjs b/desktop/scripts/editor-checks/material-authoring.mjsindex e63e93f8b..ab4380126 100644--- a/desktop/scripts/editor-checks/material-authoring.mjs+++ b/desktop/scripts/editor-checks/material-authoring.mjs@@ -108,5 +108,14 @@ export async function run(ed) {const paths = (assets?.assets ?? []).map((a) => a.path);check(paths.includes(graphPath), `the graph is not in the registry (${paths.join(', ')})`);+ // And what a driver creates, a driver can take back. The Content Browser's own+ // Delete acts on its SELECTION, which is not a thing a tool call can see; this+ // takes the path, and the registry follows.+ const deleted = await ed.json('delete_asset', { path: shaderPath }, 60000);+ check(deleted?.restoreToken != null, `delete_asset returned ${JSON.stringify(deleted)}`);+ const left = await ed.json('list_assets', { match: 'Fire' });+ const stillThere = (left?.assets ?? []).map((a) => a.path);+ check(!stillThere.includes(shaderPath), `${shaderPath} is still registered after delete_asset`);+return check.failures;}diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjsindex 1e771d2d5..b8b837fe4 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -314,6 +314,12 @@ export const TOOLS = [}, ['destDir', 'baseName', 'content', 'type']),js: (i) => `window.estella.project.createAsset(${JSON.stringify(i.destDir)}, ${JSON.stringify(i.baseName)}, ${JSON.stringify(i.content)}, ${JSON.stringify(i.type)}).then((p) => window.__estellaEditor.refreshAssets().then(() => p))` },+ { name: 'delete_asset', effect: 'irreversible',+ description: 'Delete a project file (or folder) to the OS trash — its `.meta` goes with it and the registry is re-scanned, so nothing is left half-removed. '+ + 'This is how you take back an asset you created by mistake: the editor command behind the Content Browser\'s Delete acts on whatever is SELECTED there, which a driver cannot see. '+ + 'Returns { path, type, restoreToken, usages } — `usages` is what still REFERENCES the asset (scenes, prefabs, materials); a non-empty list means you just left those refs dangling, and get_diagnostics will now report them. Recoverable from the OS trash.',+ schema: obj({ path: { type: 'string' } }, ['path']),+ js: (i) => `window.__estellaEditor.deleteAsset(${JSON.stringify(i.path)})`, root: 'editor' },{ name: 'import_assets', effect: 'irreversible',description: 'Import files into the asset registry (textures, audio, fonts, spine, tilemaps...). External absolute paths are copied into project-relative destDir; paths already INSIDE the project are registered in place (no copy, no rename). Returns { imported, skipped }; imported paths are immediately referenceable (the registry refresh happens before this resolves).',schema: obj({ destDir: { type: 'string' }, sources: { type: 'object', description: 'array of absolute file paths' } },diff --git a/desktop/src/main.tsx b/desktop/src/main.tsxindex 3195a9d6c..660b094da 100644--- a/desktop/src/main.tsx+++ b/desktop/src/main.tsx@@ -66,6 +66,8 @@ import { LogStore } from './store/LogStore';import { initFsWatch } from './project/fsWatch';import { initPlugins } from './plugins/init';import { openAssetOfType, opensInEditor } from './project/assetOpen';+import { deleteAssets } from './project/deleteAssets';+import { findAssetUsages } from './project/assetUsages';import { DirtyRegistry } from './document/DirtyRegistry';import { initBackgroundThrottle } from './engine/backgroundThrottle';import { mcpStatus, subscribeMcp } from './store/McpStore';@@ -448,6 +450,23 @@ function buildEditorAutomation(): unknown {editAssetDocument: (changes: AssetDocumentChange[], docId?: string, label?: string) =>editAssetDocument(changes, docId, label),saveAssetDocument: (docId?: string) => saveAssetDocument(docId),++ /**+ * Delete an asset to the OS trash, sidecar and registry entry with it.+ *+ * What the Content Browser's Delete does, minus its two pieces of UI: the confirm dialog+ * (a modal with nobody to answer it hangs a driver for good) and the Undo toast. What the+ * dialog SHOWS is not dropped, though — the usages come back in the result, because the+ * thing an automated caller most needs to know about a delete is what still points at it.+ */+ deleteAsset: async (path: string) => {+ const type = ProjectStore.assetTypeAt(path);+ // Best-effort: a scan failure must not stop the delete the caller asked for.+ const usages = await findAssetUsages(path).catch(() => []);+ const [result] = await deleteAssets([path]);+ if (result.token === null) throw new Error(`could not delete ${path}: ${result.error ?? 'unknown error'}`);+ return { path, type, restoreToken: result.token, usages };+ },/** Leave Prefab Mode — the banner's "Back to Scene". Refuses on unsaved prefab* changes unless `discardChanges` (see openAsset). */exitPrefabMode: async (discardChanges = false) => {diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsxindex 450dd424f..8fc6423cb 100644--- a/desktop/src/panels/ContentBrowser.tsx+++ b/desktop/src/panels/ContentBrowser.tsx@@ -20,6 +20,7 @@ import { assetTypeRegistry } from '@/project/assetTypes';import { contributedContextRows } from '@/plugins/contextMenus';import { syncAssetPaths } from '@/project/assetPathSync';import { findAssetUsages, type AssetUsage } from '@/project/assetUsages';+import { deleteAssets } from '@/project/deleteAssets';import { FindUsagesDialog } from '@/components/FindUsagesDialog';import { NewTilesetDialog } from '@/components/NewTilesetDialog';import { parseAssetQuery, filterAndSortAssets, type AssetSort } from '@/project/assetFilter';@@ -569,13 +570,11 @@ export function ContentBrowser() {setConfirmDel(null);if (!target) return;// Trash each; remember (path, token) pairs so one Undo restores the whole batch.+ const results = await deleteAssets(target.paths);const trashed: { path: string; token: string }[] = [];- for (const path of target.paths) {- try {- trashed.push({ path, token: await window.estella.fs.trash(path) });- } catch (e) {- Toasts.push(t('cb.deleteFailed', { error: errMsg(e) }), 'error');- }+ for (const r of results) {+ if (r.token !== null) trashed.push({ path: r.path, token: r.token });+ else Toasts.push(t('cb.deleteFailed', { error: r.error ?? '' }), 'error');}refreshFs();selectAsset(null);diff --git a/desktop/src/project/deleteAssets.ts b/desktop/src/project/deleteAssets.tsnew file mode 100644index 000000000..bd02595bf--- /dev/null+++ b/desktop/src/project/deleteAssets.ts@@ -0,0 +1,44 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file deleteAssets.ts+ * @brief Removing project files — the one door, for the Content Browser and for a driver.+ *+ * Deleting is two steps that must not come apart: the file (and its `.meta`) goes to the OS+ * trash, and the asset registry is re-scanned. Skip the second and every `@uuid:` ref to the+ * dead asset keeps resolving out of a stale index until something reloads — the file is gone+ * and the editor still believes in it.+ *+ * Batch-shaped because both callers are: the panel deletes a selection, and one re-scan for+ * the whole batch is the difference between a delete and a freeze on a folder of sprites. A+ * failure on one path is reported in its own row rather than aborting the rest — a permission+ * error on the third file must not leave the first two deleted and unaccounted for.+ */+import { ProjectStore } from './ProjectStore';++export interface TrashedAsset {+ path: string;+ /** Restore token for `window.estella.fs.restoreTrashed` — null when the delete failed. */+ token: string | null;+ /** Why this one did not go, when it did not. */+ error?: string;+}++/**+ * Trash `paths` (files or folders, project-relative) and re-scan the registry once.+ *+ * The trash is the OS one: recoverable by hand, and by `restoreTrashed` with the returned+ * token for as long as the pre-trash snapshot lives.+ */+export async function deleteAssets(paths: readonly string[]): Promise<TrashedAsset[]> {+ const results: TrashedAsset[] = [];+ for (const path of paths) {+ try {+ results.push({ path, token: await window.estella.fs.trash(path) });+ } catch (err) {+ results.push({ path, token: null, error: err instanceof Error ? err.message : String(err) });+ }+ }+ if (results.some((r) => r.token !== null)) await ProjectStore.refreshAssets();+ return results;+}diff --git a/desktop/tests/editor-mcp-tools.test.ts b/desktop/tests/editor-mcp-tools.test.tsindex 23bb449f4..642396bb6 100644--- a/desktop/tests/editor-mcp-tools.test.ts+++ b/desktop/tests/editor-mcp-tools.test.ts@@ -239,6 +239,15 @@ describe('editor MCP tool registry', () => {expect(driver.js).toHaveBeenLastCalledWith(expect.stringContaining('saveAssetDocument(null ?? undefined)'));});+ it('deleting an asset names the path, because the UI command reads a selection', async () => {+ const driver = vi.fn() as unknown as { js: ReturnType<typeof vi.fn> } & ((...a: unknown[]) => unknown);+ driver.js = vi.fn(async () => ({ path: 'assets/fx/old.esshader', type: 'shader', restoreToken: 't', usages: [] }));+ const del = toolNamed('delete_asset');+ expect([!!del, irreversible(del)]).toEqual([true, true]);+ await runTool(del, driver, { path: 'assets/fx/old.esshader' });+ expect(driver.js).toHaveBeenCalledWith(expect.stringContaining('deleteAsset("assets/fx/old.esshader")'));+ });+it('every resource maps to a surface method with a JSON mime', () => {for (const r of RESOURCES as Array<{ uri: string; method: string; mimeType: string }>) {expect(r.uri.startsWith('editor://')).toBe(true);