2025-10-14 22:53:26 +08:00
|
|
|
|
import { invoke } from '@tauri-apps/api/core';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Tauri IPC 通信层
|
|
|
|
|
|
*/
|
|
|
|
|
|
export class TauriAPI {
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-14 22:53:26 +08:00
|
|
|
|
* 打招呼(测试命令)
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async greet(name: string): Promise<string> {
|
|
|
|
|
|
return await invoke<string>('greet', { name });
|
|
|
|
|
|
}
|
2025-10-14 22:53:26 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async openProjectDialog(): Promise<string | null> {
|
|
|
|
|
|
return await invoke<string | null>('open_project_dialog');
|
|
|
|
|
|
}
|
2025-10-15 00:23:19 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async openProject(path: string): Promise<string> {
|
|
|
|
|
|
return await invoke<string>('open_project', { path });
|
|
|
|
|
|
}
|
2025-10-14 22:53:26 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-14 22:53:26 +08:00
|
|
|
|
* 保存项目
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async saveProject(path: string, data: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('save_project', { path, data });
|
|
|
|
|
|
}
|
2025-10-14 22:53:26 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-14 22:53:26 +08:00
|
|
|
|
* 导出二进制数据
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async exportBinary(data: Uint8Array, outputPath: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('export_binary', {
|
|
|
|
|
|
data: Array.from(data),
|
|
|
|
|
|
outputPath
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-10-15 00:40:27 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-15 00:40:27 +08:00
|
|
|
|
* 扫描目录查找匹配模式的文件
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async scanDirectory(path: string, pattern: string): Promise<string[]> {
|
|
|
|
|
|
return await invoke<string[]>('scan_directory', { path, pattern });
|
|
|
|
|
|
}
|
2025-10-15 00:40:27 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-15 00:40:27 +08:00
|
|
|
|
* 读取文件内容
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async readFileContent(path: string): Promise<string> {
|
|
|
|
|
|
return await invoke<string>('read_file_content', { path });
|
|
|
|
|
|
}
|
2025-10-15 09:43:48 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-15 09:43:48 +08:00
|
|
|
|
* 列出目录内容
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async listDirectory(path: string): Promise<DirectoryEntry[]> {
|
|
|
|
|
|
return await invoke<DirectoryEntry[]>('list_directory', { path });
|
|
|
|
|
|
}
|
2025-10-15 17:15:05 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-15 17:15:05 +08:00
|
|
|
|
* 设置项目基础路径,用于 Custom Protocol
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async setProjectBasePath(path: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('set_project_base_path', { path });
|
|
|
|
|
|
}
|
2025-10-15 20:23:55 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-15 20:23:55 +08:00
|
|
|
|
* 切换开发者工具(仅在debug模式下可用)
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async toggleDevtools(): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('toggle_devtools');
|
|
|
|
|
|
}
|
2025-10-17 18:13:31 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-17 18:13:31 +08:00
|
|
|
|
* 打开保存场景对话框
|
|
|
|
|
|
* @param defaultName 默认文件名(可选)
|
|
|
|
|
|
* @returns 用户选择的文件路径,取消则返回 null
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async saveSceneDialog(defaultName?: string): Promise<string | null> {
|
|
|
|
|
|
return await invoke<string | null>('save_scene_dialog', { defaultName });
|
|
|
|
|
|
}
|
2025-10-17 18:13:31 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-17 18:13:31 +08:00
|
|
|
|
* 打开场景文件选择对话框
|
|
|
|
|
|
* @returns 用户选择的文件路径,取消则返回 null
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async openSceneDialog(): Promise<string | null> {
|
|
|
|
|
|
return await invoke<string | null>('open_scene_dialog');
|
|
|
|
|
|
}
|
2025-10-17 18:13:31 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-17 18:13:31 +08:00
|
|
|
|
* 创建目录
|
|
|
|
|
|
* @param path 目录路径
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async createDirectory(path: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('create_directory', { path });
|
|
|
|
|
|
}
|
2025-10-17 18:13:31 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-17 18:13:31 +08:00
|
|
|
|
* 写入文件内容
|
|
|
|
|
|
* @param path 文件路径
|
|
|
|
|
|
* @param content 文件内容
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async writeFileContent(path: string, content: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('write_file_content', { path, content });
|
|
|
|
|
|
}
|
2025-10-17 18:13:31 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-17 18:13:31 +08:00
|
|
|
|
* 检查路径是否存在
|
|
|
|
|
|
* @param path 文件或目录路径
|
|
|
|
|
|
* @returns 路径是否存在
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async pathExists(path: string): Promise<boolean> {
|
|
|
|
|
|
return await invoke<boolean>('path_exists', { path });
|
|
|
|
|
|
}
|
2025-10-27 09:29:11 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-27 09:29:11 +08:00
|
|
|
|
* 使用系统默认程序打开文件
|
|
|
|
|
|
* @param path 文件路径
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async openFileWithSystemApp(path: string): Promise<void> {
|
|
|
|
|
|
await invoke('open_file_with_default_app', { filePath: path });
|
|
|
|
|
|
}
|
2025-10-27 09:29:11 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-27 09:29:11 +08:00
|
|
|
|
* 在文件管理器中显示文件
|
|
|
|
|
|
* @param path 文件路径
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async showInFolder(path: string): Promise<void> {
|
|
|
|
|
|
await invoke('show_in_folder', { filePath: path });
|
|
|
|
|
|
}
|
2025-10-27 09:29:11 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-27 09:29:11 +08:00
|
|
|
|
* 打开行为树文件选择对话框
|
|
|
|
|
|
* @returns 用户选择的文件路径,取消则返回 null
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async openBehaviorTreeDialog(): Promise<string | null> {
|
|
|
|
|
|
return await invoke<string | null>('open_behavior_tree_dialog');
|
|
|
|
|
|
}
|
2025-10-27 09:29:11 +08:00
|
|
|
|
|
2025-11-02 23:50:41 +08:00
|
|
|
|
/**
|
2025-10-27 09:29:11 +08:00
|
|
|
|
* 扫描项目中的所有行为树文件
|
|
|
|
|
|
* @param projectPath 项目路径
|
|
|
|
|
|
* @returns 行为树资产ID列表(相对于 .ecs/behaviors 的路径,不含扩展名)
|
|
|
|
|
|
*/
|
2025-11-02 23:50:41 +08:00
|
|
|
|
static async scanBehaviorTrees(projectPath: string): Promise<string[]> {
|
|
|
|
|
|
return await invoke<string[]>('scan_behavior_trees', { projectPath });
|
|
|
|
|
|
}
|
2025-11-04 18:29:28 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 重命名文件或文件夹
|
|
|
|
|
|
* @param oldPath 原路径
|
|
|
|
|
|
* @param newPath 新路径
|
|
|
|
|
|
*/
|
|
|
|
|
|
static async renameFileOrFolder(oldPath: string, newPath: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('rename_file_or_folder', { oldPath, newPath });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除文件
|
|
|
|
|
|
* @param path 文件路径
|
|
|
|
|
|
*/
|
|
|
|
|
|
static async deleteFile(path: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('delete_file', { path });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除文件夹
|
|
|
|
|
|
* @param path 文件夹路径
|
|
|
|
|
|
*/
|
|
|
|
|
|
static async deleteFolder(path: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('delete_folder', { path });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 创建文件
|
|
|
|
|
|
* @param path 文件路径
|
|
|
|
|
|
*/
|
|
|
|
|
|
static async createFile(path: string): Promise<void> {
|
|
|
|
|
|
return await invoke<void>('create_file', { path });
|
|
|
|
|
|
}
|
2025-10-15 09:43:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface DirectoryEntry {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
path: string;
|
|
|
|
|
|
is_dir: boolean;
|
2025-10-27 09:29:11 +08:00
|
|
|
|
size?: number;
|
|
|
|
|
|
modified?: number;
|
2025-10-14 22:53:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 项目信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface ProjectInfo {
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
path: string;
|
|
|
|
|
|
version: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 编辑器配置
|
|
|
|
|
|
*/
|
|
|
|
|
|
export interface EditorConfig {
|
|
|
|
|
|
theme: string;
|
|
|
|
|
|
autoSave: boolean;
|
|
|
|
|
|
recentProjects: string[];
|
|
|
|
|
|
}
|