refactor(editor): 重构编辑器架构并增强行为树执行可视化

This commit is contained in:
YHH
2025-11-04 18:29:28 +08:00
parent adfc7e91b3
commit f9afa22406
44 changed files with 4942 additions and 546 deletions

View File

@@ -0,0 +1,110 @@
import { IService } from '@esengine/ecs-framework';
import { FileActionHandler, FileCreationTemplate } from '../Plugins/IEditorPlugin';
/**
* 文件操作注册表服务
*
* 管理插件注册的文件操作处理器和文件创建模板
*/
export class FileActionRegistry implements IService {
private actionHandlers: Map<string, FileActionHandler[]> = new Map();
private creationTemplates: FileCreationTemplate[] = [];
/**
* 注册文件操作处理器
*/
registerActionHandler(handler: FileActionHandler): void {
for (const ext of handler.extensions) {
const handlers = this.actionHandlers.get(ext) || [];
handlers.push(handler);
this.actionHandlers.set(ext, handlers);
}
}
/**
* 注册文件创建模板
*/
registerCreationTemplate(template: FileCreationTemplate): void {
this.creationTemplates.push(template);
}
/**
* 获取文件扩展名的处理器
*/
getHandlersForExtension(extension: string): FileActionHandler[] {
return this.actionHandlers.get(extension) || [];
}
/**
* 获取文件的处理器
*/
getHandlersForFile(filePath: string): FileActionHandler[] {
const extension = this.getFileExtension(filePath);
return extension ? this.getHandlersForExtension(extension) : [];
}
/**
* 获取所有文件创建模板
*/
getCreationTemplates(): FileCreationTemplate[] {
return this.creationTemplates;
}
/**
* 处理文件双击
*/
async handleDoubleClick(filePath: string): Promise<boolean> {
const extension = this.getFileExtension(filePath);
console.log('[FileActionRegistry] handleDoubleClick:', filePath);
console.log('[FileActionRegistry] Extension:', extension);
console.log('[FileActionRegistry] Total handlers:', this.actionHandlers.size);
console.log('[FileActionRegistry] Registered extensions:', Array.from(this.actionHandlers.keys()));
const handlers = this.getHandlersForFile(filePath);
console.log('[FileActionRegistry] Found handlers:', handlers.length);
for (const handler of handlers) {
if (handler.onDoubleClick) {
console.log('[FileActionRegistry] Calling handler for extensions:', handler.extensions);
await handler.onDoubleClick(filePath);
return true;
}
}
return false;
}
/**
* 处理文件打开
*/
async handleOpen(filePath: string): Promise<boolean> {
const handlers = this.getHandlersForFile(filePath);
for (const handler of handlers) {
if (handler.onOpen) {
await handler.onOpen(filePath);
return true;
}
}
return false;
}
/**
* 清空所有注册
*/
clear(): void {
this.actionHandlers.clear();
this.creationTemplates = [];
}
/**
* 释放资源
*/
dispose(): void {
this.clear();
}
private getFileExtension(filePath: string): string | null {
const lastDot = filePath.lastIndexOf('.');
if (lastDot === -1) return null;
return filePath.substring(lastDot + 1).toLowerCase();
}
}

View File

@@ -0,0 +1,180 @@
import { IService } from '@esengine/ecs-framework';
import { ComponentType } from 'react';
/**
* 窗口描述符
*/
export interface WindowDescriptor {
/**
* 窗口唯一标识
*/
id: string;
/**
* 窗口组件
*/
component: ComponentType<any>;
/**
* 窗口标题
*/
title?: string;
/**
* 默认宽度
*/
defaultWidth?: number;
/**
* 默认高度
*/
defaultHeight?: number;
}
/**
* 窗口实例
*/
export interface WindowInstance {
/**
* 窗口描述符
*/
descriptor: WindowDescriptor;
/**
* 是否打开
*/
isOpen: boolean;
/**
* 窗口参数
*/
params?: Record<string, any>;
}
/**
* 窗口注册表服务
*
* 管理插件注册的窗口组件
*/
export class WindowRegistry implements IService {
private windows: Map<string, WindowDescriptor> = new Map();
private openWindows: Map<string, WindowInstance> = new Map();
private listeners: Set<() => void> = new Set();
/**
* 注册窗口
*/
registerWindow(descriptor: WindowDescriptor): void {
if (this.windows.has(descriptor.id)) {
console.warn(`Window ${descriptor.id} is already registered`);
return;
}
this.windows.set(descriptor.id, descriptor);
console.log(`[WindowRegistry] Registered window: ${descriptor.id}`);
}
/**
* 取消注册窗口
*/
unregisterWindow(windowId: string): void {
this.windows.delete(windowId);
this.openWindows.delete(windowId);
this.notifyListeners();
}
/**
* 获取窗口描述符
*/
getWindow(windowId: string): WindowDescriptor | undefined {
return this.windows.get(windowId);
}
/**
* 获取所有窗口描述符
*/
getAllWindows(): WindowDescriptor[] {
return Array.from(this.windows.values());
}
/**
* 打开窗口
*/
openWindow(windowId: string, params?: Record<string, any>): void {
const descriptor = this.windows.get(windowId);
if (!descriptor) {
console.warn(`Window ${windowId} is not registered`);
return;
}
console.log(`[WindowRegistry] Opening window: ${windowId}`, params);
this.openWindows.set(windowId, {
descriptor,
isOpen: true,
params
});
this.notifyListeners();
}
/**
* 关闭窗口
*/
closeWindow(windowId: string): void {
console.log(`[WindowRegistry] Closing window: ${windowId}`);
this.openWindows.delete(windowId);
this.notifyListeners();
}
/**
* 获取打开的窗口实例
*/
getOpenWindow(windowId: string): WindowInstance | undefined {
return this.openWindows.get(windowId);
}
/**
* 获取所有打开的窗口
*/
getAllOpenWindows(): WindowInstance[] {
return Array.from(this.openWindows.values());
}
/**
* 检查窗口是否打开
*/
isWindowOpen(windowId: string): boolean {
return this.openWindows.has(windowId);
}
/**
* 添加变化监听器
*/
addListener(listener: () => void): () => void {
this.listeners.add(listener);
return () => {
this.listeners.delete(listener);
};
}
/**
* 通知所有监听器
*/
private notifyListeners(): void {
this.listeners.forEach(listener => listener());
}
/**
* 清空所有窗口
*/
clear(): void {
this.windows.clear();
this.openWindows.clear();
this.listeners.clear();
}
/**
* 释放资源
*/
dispose(): void {
this.clear();
}
}