* feat: 添加 Tilemap 编辑器插件和组件生命周期支持 * feat(editor-core): 添加声明式插件注册 API * feat(editor-core): 改进tiledmap结构合并tileset进tiledmapeditor * feat: 添加 editor-runtime SDK 和插件系统改进 * fix(ci): 修复SceneResourceManager里变量未使用问题
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
import { singleton } from 'tsyringe';
|
|
import { invoke, convertFileSrc } from '@tauri-apps/api/core';
|
|
import type { IFileSystem, FileEntry } from '@esengine/editor-core';
|
|
|
|
@singleton()
|
|
export class TauriFileSystemService implements IFileSystem {
|
|
dispose(): void {
|
|
// No cleanup needed
|
|
}
|
|
|
|
async readFile(path: string): Promise<string> {
|
|
return await invoke<string>('read_file_content', { path });
|
|
}
|
|
|
|
async writeFile(path: string, content: string): Promise<void> {
|
|
await invoke('write_file_content', { path, content });
|
|
}
|
|
|
|
async writeBinary(path: string, data: Uint8Array): Promise<void> {
|
|
await invoke('write_binary_file', { filePath: path, content: Array.from(data) });
|
|
}
|
|
|
|
async exists(path: string): Promise<boolean> {
|
|
try {
|
|
await invoke('read_file_content', { path });
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async createDirectory(path: string): Promise<void> {
|
|
await invoke('create_directory', { path });
|
|
}
|
|
|
|
async listDirectory(path: string): Promise<FileEntry[]> {
|
|
const entries = await invoke<Array<{ name: string; path: string; is_dir: boolean }>>('list_directory', { path });
|
|
return entries.map((entry) => ({
|
|
name: entry.name,
|
|
isDirectory: entry.is_dir,
|
|
path: entry.path
|
|
}));
|
|
}
|
|
|
|
async deleteFile(path: string): Promise<void> {
|
|
await invoke('delete_file', { path });
|
|
}
|
|
|
|
async deleteDirectory(path: string): Promise<void> {
|
|
await invoke('delete_directory', { path });
|
|
}
|
|
|
|
async scanFiles(basePath: string, pattern: string): Promise<string[]> {
|
|
return await invoke<string[]>('scan_files', { basePath, pattern });
|
|
}
|
|
|
|
convertToAssetUrl(filePath: string): string {
|
|
return convertFileSrc(filePath);
|
|
}
|
|
}
|