Feature/runtime cdn and plugin loader (#240)
* feat(ui): 完善 UI 布局系统和编辑器可视化工具 * refactor: 移除 ModuleRegistry,统一使用 PluginManager 插件系统 * fix: 修复 CodeQL 警告并提升测试覆盖率 * refactor: 分离运行时入口点,解决 runtime bundle 包含 React 的问题 * fix(ci): 添加 editor-core 和 editor-runtime 到 CI 依赖构建步骤 * docs: 完善 ServiceContainer 文档,新增 Symbol.for 模式和 @InjectProperty 说明 * fix(ci): 修复 type-check 失败问题 * fix(ci): 修复类型检查失败问题 * fix(ci): 修复类型检查失败问题 * fix(ci): behavior-tree 构建添加 @tauri-apps 外部依赖 * fix(ci): behavior-tree 添加 @tauri-apps/plugin-fs 类型依赖 * fix(ci): platform-web 添加缺失的 behavior-tree 依赖 * fix(lint): 移除正则表达式中不必要的转义字符
This commit is contained in:
@@ -1,97 +0,0 @@
|
||||
import {
|
||||
singleton,
|
||||
type IService,
|
||||
createLogger,
|
||||
MessageHub,
|
||||
IMessageHub,
|
||||
} from '@esengine/editor-runtime';
|
||||
import { useBehaviorTreeDataStore } from '../application/state/BehaviorTreeDataStore';
|
||||
import type { BehaviorTree } from '../domain/models/BehaviorTree';
|
||||
import { FileSystemService } from './FileSystemService';
|
||||
import { PluginContext } from '../PluginContext';
|
||||
|
||||
const logger = createLogger('BehaviorTreeService');
|
||||
|
||||
@singleton()
|
||||
export class BehaviorTreeService implements IService {
|
||||
async createNew(): Promise<void> {
|
||||
useBehaviorTreeDataStore.getState().reset();
|
||||
}
|
||||
|
||||
async loadFromFile(filePath: string): Promise<void> {
|
||||
try {
|
||||
const services = PluginContext.getServices();
|
||||
|
||||
// 运行时解析 FileSystemService
|
||||
const fileSystem = services.resolve(FileSystemService);
|
||||
if (!fileSystem) {
|
||||
throw new Error('FileSystemService not found. Please ensure the BehaviorTreePlugin is properly installed.');
|
||||
}
|
||||
|
||||
const content = await fileSystem.readBehaviorTreeFile(filePath);
|
||||
const fileName = filePath.split(/[\\/]/).pop()?.replace('.btree', '') || 'Untitled';
|
||||
|
||||
const store = useBehaviorTreeDataStore.getState();
|
||||
store.importFromJSON(content);
|
||||
// 在 store 中保存文件信息,Panel 挂载时读取
|
||||
store.setCurrentFile(filePath, fileName);
|
||||
|
||||
const messageHub = services.resolve<MessageHub>(IMessageHub);
|
||||
if (messageHub) {
|
||||
messageHub.publish('dynamic-panel:open', {
|
||||
panelId: 'behavior-tree-editor',
|
||||
title: `Behavior Tree - ${filePath.split(/[\\/]/).pop()}`
|
||||
});
|
||||
|
||||
// 保留事件发布,以防 Panel 已挂载
|
||||
messageHub.publish('behavior-tree:file-opened', {
|
||||
filePath,
|
||||
fileName
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('Failed to load tree:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async saveToFile(filePath: string, metadata?: { name: string; description: string }): Promise<void> {
|
||||
try {
|
||||
const services = PluginContext.getServices();
|
||||
|
||||
// 运行时解析 FileSystemService
|
||||
const fileSystem = services.resolve(FileSystemService);
|
||||
if (!fileSystem) {
|
||||
throw new Error('FileSystemService not found. Please ensure the BehaviorTreePlugin is properly installed.');
|
||||
}
|
||||
|
||||
const store = useBehaviorTreeDataStore.getState();
|
||||
|
||||
// 如果没有提供元数据,使用文件名作为默认名称
|
||||
const defaultMetadata = {
|
||||
name: metadata?.name || filePath.split(/[\\/]/).pop()?.replace('.btree', '') || 'Untitled',
|
||||
description: metadata?.description || ''
|
||||
};
|
||||
|
||||
const content = store.exportToJSON(defaultMetadata);
|
||||
await fileSystem.writeBehaviorTreeFile(filePath, content);
|
||||
|
||||
logger.info('Tree saved successfully:', filePath);
|
||||
} catch (error) {
|
||||
logger.error('Failed to save tree:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentTree(): BehaviorTree {
|
||||
return useBehaviorTreeDataStore.getState().tree;
|
||||
}
|
||||
|
||||
setTree(tree: BehaviorTree): void {
|
||||
useBehaviorTreeDataStore.getState().setTree(tree);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
useBehaviorTreeDataStore.getState().reset();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user