Feature/editor optimization (#251)
* refactor: 编辑器/运行时架构拆分与构建系统升级 * feat(core): 层级系统重构与UI变换矩阵修复 * refactor: 移除 ecs-components 聚合包并修复跨包组件查找问题 * fix(physics): 修复跨包组件类引用问题 * feat: 统一运行时架构与浏览器运行支持 * feat(asset): 实现浏览器运行时资产加载系统 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题和CI类型检查错误 * fix: 修复文档、CodeQL安全问题、CI类型检查和测试错误 * test: 补齐核心模块测试用例,修复CI构建配置 * fix: 修复测试用例中的类型错误和断言问题 * fix: 修复 turbo build:npm 任务的依赖顺序问题 * fix: 修复 CI 构建错误并优化构建性能
This commit is contained in:
126
packages/blueprint-editor/src/BlueprintPlugin.ts
Normal file
126
packages/blueprint-editor/src/BlueprintPlugin.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Blueprint Editor Plugin
|
||||
* 蓝图编辑器插件
|
||||
*/
|
||||
|
||||
import { Core, type ServiceContainer } from '@esengine/ecs-framework';
|
||||
import type { IPlugin, PluginDescriptor } from '@esengine/engine-core';
|
||||
import type { IEditorModuleLoader, PanelDescriptor, FileActionHandler, FileCreationTemplate } from '@esengine/editor-core';
|
||||
import { MessageHub, PanelPosition } from '@esengine/editor-core';
|
||||
|
||||
// Re-export from @esengine/blueprint for runtime module
|
||||
import { NodeRegistry, BlueprintVM, createBlueprintSystem } from '@esengine/blueprint';
|
||||
|
||||
// Store for pending file path
|
||||
import { useBlueprintEditorStore } from './stores/blueprintEditorStore';
|
||||
|
||||
// Direct import of panel component (not dynamic import)
|
||||
import { BlueprintEditorPanel } from './components/BlueprintEditorPanel';
|
||||
|
||||
/**
|
||||
* Blueprint Editor Module Implementation
|
||||
* 蓝图编辑器模块实现
|
||||
*/
|
||||
class BlueprintEditorModuleImpl implements IEditorModuleLoader {
|
||||
async install(_services: ServiceContainer): Promise<void> {
|
||||
// Editor module installation
|
||||
}
|
||||
|
||||
async uninstall(): Promise<void> {
|
||||
// Cleanup
|
||||
}
|
||||
|
||||
getPanels(): PanelDescriptor[] {
|
||||
return [
|
||||
{
|
||||
id: 'blueprint-editor',
|
||||
title: 'Blueprint Editor',
|
||||
position: PanelPosition.Center,
|
||||
icon: 'Workflow',
|
||||
closable: true,
|
||||
resizable: true,
|
||||
order: 50,
|
||||
component: BlueprintEditorPanel,
|
||||
isDynamic: true
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
getFileActionHandlers(): FileActionHandler[] {
|
||||
return [
|
||||
{
|
||||
// 扩展名不带点号,与 FileActionRegistry.getFileExtension() 保持一致
|
||||
// Extensions without dot prefix, consistent with FileActionRegistry.getFileExtension()
|
||||
extensions: ['blueprint', 'bp'],
|
||||
onDoubleClick: (filePath: string) => {
|
||||
// 设置待加载的文件路径到 store
|
||||
// Set pending file path to store
|
||||
useBlueprintEditorStore.getState().setPendingFilePath(filePath);
|
||||
|
||||
// 通过 MessageHub 打开蓝图编辑器面板
|
||||
// Open blueprint editor panel via MessageHub
|
||||
const messageHub = Core.services.resolve(MessageHub);
|
||||
if (messageHub) {
|
||||
messageHub.publish('dynamic-panel:open', {
|
||||
panelId: 'blueprint-editor',
|
||||
title: `Blueprint - ${filePath.split(/[\\/]/).pop()}`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
getFileCreationTemplates(): FileCreationTemplate[] {
|
||||
return [
|
||||
{
|
||||
id: 'blueprint',
|
||||
label: 'Blueprint',
|
||||
// 扩展名不带点号,FileTree 会自动添加点号
|
||||
// Extension without dot, FileTree will add the dot automatically
|
||||
extension: 'blueprint',
|
||||
icon: 'Workflow',
|
||||
getContent: (fileName: string) => {
|
||||
const name = fileName.replace(/\.blueprint$/i, '') || 'NewBlueprint';
|
||||
return JSON.stringify({
|
||||
version: '1.0.0',
|
||||
name,
|
||||
nodes: [],
|
||||
connections: [],
|
||||
variables: []
|
||||
}, null, 2);
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
const descriptor: PluginDescriptor = {
|
||||
id: '@esengine/blueprint',
|
||||
name: 'Blueprint',
|
||||
version: '1.0.0',
|
||||
description: 'Visual scripting system for ECS Framework',
|
||||
category: 'scripting',
|
||||
enabledByDefault: false,
|
||||
isEnginePlugin: true,
|
||||
canContainContent: true,
|
||||
modules: [
|
||||
{ name: 'Runtime', type: 'runtime', loadingPhase: 'default' },
|
||||
{ name: 'Editor', type: 'editor', loadingPhase: 'postDefault' }
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* Complete Blueprint plugin with both runtime and editor modules
|
||||
* 完整的蓝图插件,包含运行时和编辑器模块
|
||||
*/
|
||||
export const BlueprintPlugin: IPlugin = {
|
||||
descriptor,
|
||||
editorModule: new BlueprintEditorModuleImpl()
|
||||
};
|
||||
|
||||
// Also export the editor module instance for direct use
|
||||
export const BlueprintEditorModule = new BlueprintEditorModuleImpl();
|
||||
|
||||
// Re-export useful items
|
||||
export { NodeRegistry, BlueprintVM, createBlueprintSystem };
|
||||
Reference in New Issue
Block a user